This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checksums on incoming NMEA strings
#5
Well, that was fun! Thanks for the help. It looks like I have something that works. 

I'll know when I get a chance to take it down to the boat, but using simulated strings in Node-Red is works great!

Here's the code:
Code:
[{"id":"def155ce.cb8dc8","type":"tab","label":"Flow 2"},{"id":"4fc0cc12.46de24","type":"switch","z":"def155ce.cb8dc8","name":"Filter just DBT and HDM","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^(?=.*IIDBT)","vt":"str","case":false},{"t":"regex","v":"^(?=.*IIHDM)","vt":"str","case":false}],"checkall":"true","outputs":2,"x":443.99993896484375,"y":367.99993896484375,"wires":[["d06bc454.854278"],["142750e6.16540f"]]},{"id":"de39de6.89c9d2","type":"function","z":"def155ce.cb8dc8","name":"calc checksum","func":"var nmea = msg.payload;\nvar checksum = 0; \n\nfor(var i = 0; i < nmea.length; i++) { \n  checksum = checksum ^ nmea.charCodeAt(i); \n}\nchecksum = checksum.toString(16);    //convert to hex\nnmea = '$' + nmea + '*' + checksum;  //make the full nmea sentence again\n\nmessage = 'Full message =' + nmea + '\\r\\n' + 'Checksum = ' + checksum ;\n\nmsg.payload = nmea;\nmsg.payload = msg.payload+\"\\r\\n\";\n\nvar msg1 = {\n     payload: msg.payload\n };\n return msg1;","outputs":1,"noerr":0,"x":1018,"y":423,"wires":[["6fe378e5.112f58","bc1148e9.02e848"]]},{"id":"142750e6.16540f","type":"function","z":"def155ce.cb8dc8","name":"Strip front and back","func":"var nmeaFull=msg.payload;\n\n    \nvar nmeaStripped=nmeaFull.substring(1, 99)\n\nmsg.payload = nmeaStripped;\nreturn msg;","outputs":1,"noerr":0,"x":802.0000610351562,"y":423,"wires":[["de39de6.89c9d2"]]},{"id":"6fe378e5.112f58","type":"udp out","z":"def155ce.cb8dc8","name":"","addr":"127.0.0.1","iface":"","port":"10108","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":1246,"y":204.00003051757812,"wires":[]},{"id":"63c11a8c.9927a4","type":"comment","z":"def155ce.cb8dc8","name":"This takes NMEA Output by SeaTalk and adds checksum","info":"","x":506.9999542236328,"y":180.9999542236328,"wires":[]},{"id":"f6520ef8.395e2","type":"serial in","z":"def155ce.cb8dc8","name":"SeaTalk NMEA Input","serial":"c5d7ff46.19d73","x":104,"y":470,"wires":[["4fc0cc12.46de24"]]},{"id":"c2d153f6.75ee2","type":"inject","z":"def155ce.cb8dc8","name":"Inject SeaTalk DBT String","topic":"","payload":"$IIDBT,0008.4,f,,,,","payloadType":"str","repeat":"1","crontab":"","once":false,"x":178,"y":269,"wires":[["4fc0cc12.46de24"]]},{"id":"427edb50.17af24","type":"inject","z":"def155ce.cb8dc8","name":"Inject SeaTalk HDM String","topic":"","payload":"$IIHDM,268.,M","payloadType":"str","repeat":"1","crontab":"","once":false,"x":176,"y":344,"wires":[["4fc0cc12.46de24"]]},{"id":"bc1148e9.02e848","type":"debug","z":"def155ce.cb8dc8","name":"","active":true,"console":"false","complete":"false","x":1254,"y":423,"wires":[]},{"id":"d06bc454.854278","type":"function","z":"def155ce.cb8dc8","name":"Create full DBT string","func":"var nmeaFull=msg.payload;\n\nvar nmeaSplit=nmeaFull.split(\",\");\n   \nvar nmeaFinal=nmeaSplit[0]+\",\"+nmeaSplit[1]+\",f,\";\nnmeaFinal=nmeaFinal+(nmeaSplit[1]/3.28084).toFixed(2)+\",M,\";\nnmeaFinal=nmeaFinal+(nmeaSplit[1]/20).toFixed(2)+\",F\";\n\nmsg.payload = nmeaFinal;\nreturn msg;","outputs":1,"noerr":0,"x":671,"y":253,"wires":[["142750e6.16540f"]]},{"id":"c5d7ff46.19d73","type":"serial-port","z":"","serialport":"/dev/ttyOP_485","serialbaud":"4800","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false}]
Reply


Messages In This Thread
Checksums on incoming NMEA strings - by abarrow - 2017-06-27, 08:49 PM
RE: Checksums on incoming NMEA strings - by JD1 - 2017-06-28, 03:08 AM
RE: Checksums on incoming NMEA strings - by abarrow - 2017-06-28, 05:46 PM
RE: Checksums on incoming NMEA strings - by JD1 - 2017-06-28, 06:24 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)