Hey everyone,
I am currently trying to do a simple bitwise XOR on a msg.payload (ASCII string) coming from a serial port. I tried to approach it like I would C programming, but no cigar. Is this even possible in the function block? Any info helps. Thanks.
//Grab Payload to manipulate
var check_sum_string = msg.payload.toString('utf8');
var check_sum;
//Create global flag to raise in order to halt the flow of data
var check_sum_flag = global.get('CS_valid');
for(i=0; i < msg.payload.length; i++){
check_sum = check_sum_string[i] ^ check_sum_string[i+1];
}
msg.payload = check_sum;
if(check_sum !== 0){
check_sum_flag = 1;
global.set('CS_valid',check_sum_flag);
}
return msg;
I am currently using this to validate a checksum, but my output seems to always be 0x00, even if I fudge the input string. Any suggestions?