I couldn't find a method to define an unsigned variable. The following syntax always create a variable that is a signed one. let MyExpectedFlag = 0 ; When I execute the SUM, "AND" or "OR" operations, depending of the argument, the result becomes a negative value. When the APP gets an string message, depending of the first argument, a value is assigned to the variable where each bit represents one argument that must be included in the rest of the message. MyExpectedFlag = 0x8006000f - after checking the first argument The APP must find the arguments related to the bits 31,18,17,3,2,1,0 As the arguments are found, I use their pointer to set the related bit. MyGotFlag |= 1 << pointer; or MyGotFlag += 1 << pointer;
1) Case 1 let MyGotFlag = 0x80000000; Expected: 2147483648 Actual: 214748368 - ok MyGotFlag += 0x40000000; Expected: 3221225472 Actual: 3221225472 - ok MyGotFlag &= 0xfff87fff; Expected: 3221225472 Actual: -1073741824 - nok
2) Case 2 let MyGotFlag = 0 ; MyGotFlag |= 0x80000000 ; Expected: 2147483648 Actual: -214748368 - nok
Follows an example code to be tested:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu',
});
const responseStr = [
'amb$', 0x80000000, // AMBIENT ID
'acn$', 0, // ACTION OF SCENE ID
'bot$', 0, // BUTTON ID
'cr$', 0x29df8101, // Connection response
'date$', 0, // Date
'db$', 0, // DIMMER blink ( User )
'dsp$', 0, // DEVICE ID
'dsr$', 0, // Device Status response
'evt$', 0, // EVENT ID
'ib$', 0, // IRED blink ( User )
'ic$', 0, // Icone ID or IRED CODE ID
'ip$', 0, // IRED stop ( User )
'kill$', 0, // Reset CENTRAL setup to factory
'ksr$', 0, // KEYPAD Sensor response
'level$', 0, // RF LEVEL request
'lrn$', 0, // LEARN IRED process
'mod$', 0, // General Module ID
'nok$', 0, // Last Message sent by APP with ERROR
'ok$', 0, // Last Message sent by APP was correct
'pd$', 0xc0078000, // Remote Module Pairing
'rf$', 0, // RF Channel of ATMEL modules
'rb$', 0, // RELAY blink ( User )
'rp$', 0, // Replace Module response
'scan$', 0, // Ongoing Process
'setup$', 0, // Status of CENTRAL or CENTRAL SETUP
'sm$', 0, // HW version - SMART
'sr$', 0x20080000, // Scan Response
'start$', 0, // Started one process by CENTRAL
'status$', 0, // IRED CODE save by CENTRAL
'tkp$', 0, // KEYPAD KEY ID
'uep$', 0, // User ID
'wb$', 0, // RGBW blink ( User )
];
let MsgSintaxRes = false; // Clear variable, Invalid Message recvd
let ArgExpected = 0; // Expected arguments according to responseStr
let ArgPresFlag = 0; // Arguments received flag
let ArgExpected1 = 0;// Expected arguments according to responseStr
let ArgPresFlag1 = 0; // Arguments received flag
let Result = '';
let Result1 = '';
type Props = {};
export default class App extends Component<Props> {
componentWillMount() {
// Message to be checked: "pd$status$nok$" to be checked
//
// Case 1
//
// Simulates that found "pd"
ArgExpected = responseStr[39];// Gets value from array
// ArgExpected should be 0xc0078000 or decimal 3221716992 - OK
// Simulates that found "status"
// Sets bit related to the Argument Identifier
ArgPresFlag |= 0x40000000;
// ArgPresFlag should be 0x40000000 or decimal 1073741824 - OK
// Simulates that found "nok"
// Sets bit related to the Argument Identifier
ArgPresFlag |= 0x80000000;
// Expected to be 0xc0000000 but the result is 0xffffffffc0000000
// dec -1073741824 - ERROR
// Comparison should be OK, but it isn't
if ( ArgExpected &&
ArgExpected === ArgPresFlag ) {// Got all the Arguments???
MsgSintaxRes = true; // Sets flag, Message is valid
}
Result = 'Exp: ' + ArgExpected + ' ' + 'Calc: ' + ArgPresFlag;
//
// Case 2 - Farei um operacao & com ArgExpected, aĆ funciona,
// situacoes, que nao farei o & com ArgExpected
// Simulates that found "pd"
ArgExpected1 = responseStr[39];// Gets value from array
// ArgExpected should be 0xc0078000 or decimal 3221716992 - OK
// Simulates that found "status"
ArgPresFlag1 |= 0x40000000;// Sets bit
// ArgPresFlag should be 0x40000000 or decimal 1073741824 - OK
// Simulates that found "nok"
ArgPresFlag1 |= 0x80000000;// Sets bit
// Expected to be 0xc0000000 but the result is 0xffffffffc0000000
// dec -1073741824 - ERROR
// Clear bits that represents the Module Code
ArgExpected1 &= 0xfff87fff;
// Expected to be 0xc0000000 but the result is 0xffffffffc0000000
// dec -1073741824 - ERROR
// Both value ArgExpected and ArgPresFlag are negative (error)
// Comparison should be OK
if ( ArgExpected1 &&
ArgExpected1 === ArgPresFlag1 ) {// Got all Arguments???
MsgSintaxRes = true; // Sets flag, Message is valid
}
Result1 = 'Exp: ' + ArgExpected1.toString() + ' ' + 'Calc: ' + ArgPresFlag1.toString();
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>{Result}</Text>
<Text style={styles.instructions}>{Result1}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
User contributions licensed under CC BY-SA 3.0