First success! CASIC response received and parsed.
var h1=0,h2=0, l1=0,l2=0, cs1=0,cs2=0,cs3=0,cs4=0, protocolType="Unknown", casicPos=-1, payloadPos=0, inCasicMessage=false, casicIsCompleted=false; var casicMsg={}; function parseCASIC(data){ for(var i=0;i<data.length;i++){ c=data.charCodeAt(i); //print("i:",i,"c:",c, "casicPos:",casicPos,"payloadPos:",payloadPos); if(c==0xBA && casicPos<0){ h1=c; protocolType="CASIC"; inCasicMessage=true; casicIsCompleted=false; casicPos=0; payloadPos=0; h2=0; l1=0; l2=0; cs1=0;cs2=0;cs3=0;cs4=0; casicMsg={}; } else if(!inCasicMessage) return; else if(c==0xCE && casicPos==0){ h2=c; casicPos++; casicMsg.hdr = (h1<<8) + h2; } else if(inCasicMessage && casicPos==1){ l1=c; casicPos++; } else if(inCasicMessage && casicPos==2){ l2=c; casicPos++; casicMsg.len = (l2<<8) + l1; } else if(inCasicMessage && casicPos==3){ casicMsg.class = c; casicPos++; } else if(inCasicMessage && casicPos==4){ casicMsg.msgId = c; casicMsg.payload=[]; payloadPos=0; casicPos++; } else if(inCasicMessage && casicPos>4 && payloadPos<casicMsg.len){ casicMsg.payload.push(c); payloadPos++; casicPos++; } else if(inCasicMessage && casicPos==casicMsg.len+5){ cs1 = c; casicPos++; } else if(inCasicMessage && casicPos==casicMsg.len+6){ cs2 = c; casicPos++; } else if(inCasicMessage && casicPos==casicMsg.len+7){ cs3 = c; casicPos++; } else if(inCasicMessage && casicPos==casicMsg.len+8){ cs4 = c; casicMsg.checkSum = (cs1<<24)+(cs2<<16)+(cs3<<8)+cs4; inCasicMessage = false; casicIsCompleted = true; casicPos = -1; protocolType="Unknown"; print(casicMsg); } }//for } D29.write(0); Serial2.removeAllListeners(); Serial2.setup(9600,{rx:D30,tx:D31}); Serial2.on('data', function(data){parseCASIC(data);}); D29.write(1);
some pause
//CFG-PRT query Serial2.write([0xBA,0xCE, 0x00,0x00, 0x06,0x00, 0x00,0x00,0x06,0x00]); =undefined { "hdr": 47822, "len": 8, "class": 6, "msgId": 0, "payload": [ 1, 7, 192, 8, 0, 194, 1, 0 ], "checkSum": 164218632 } { "hdr": 47822, "len": 8, "class": 6, "msgId": 0, "payload": [ 0, 119, 192, 8, 128, 37, 0, 0 ], "checkSum": -2002991608 } { "hdr": 47822, "len": 4, "class": 5, "msgId": 1, "payload": [ 6, 0, 0, 0 ], "checkSum": 167773441 } >
@Mark_M started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
First success! CASIC response received and parsed.
some pause