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
Allow NMEA 0183 file input/output
#6
(2017-05-31, 12:09 AM)abarrow Wrote: Thanks!

OK, getting somewhere Cool

To strip the "$" off the front of the message and the "*" and chcksum from the end try a function like:-



Code:
var nmeaFull=msg.payload;

var nmeaStripped=nmeaFull.substring(1, nmeaFull.indexOf("*"));     //cut of the leading "$" and the bad checksum
msg.payload = nmeaStripped;
return msg;



Then to calculate a new checksum try a function like :-
Seems to work OK checking against http://www.hhhh.org/wiml/proj/nmeaxor.html


Code:
var nmea = msg.payload;
var checksum = 0; 

for(var i = 0; i < nmea.length; i++) { 
  checksum = checksum ^ nmea.charCodeAt(i); 
}
checksum = checksum.toString(16);    //convert to hex
nmea = '$' + nmea + '*' + checksum;  //make the full nmea sentence again

message = 'Full message =' + nmea + '\r\n' + 'Checksum = ' + checksum;
msg.payload = message;

return msg;




And the node-red code :-


Code:
[
    {
        "id": "a91ed12.b0a903",
        "type": "inject",
        "z": "d26052b1.ec666",
        "name": "",
        "topic": "",
        "payload": "$WIMDA,30,I,1.02,B,10.1,C,,C,,,,C,158.69,T,,M,3.89 ,N,2,M*37",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 150,
        "y": 720,
        "wires": [
            [
                "51fc3a3c.0d9534"
            ]
        ]
    },
    {
        "id": "51fc3a3c.0d9534",
        "type": "function",
        "z": "d26052b1.ec666",
        "name": "Strip front and back",
        "func": "var nmeaFull=msg.payload;\n\nvar nmeaStripped=nmeaFull.substring(1, nmeaFull.indexOf(\"*\"));     //cut of the leading \"$\" and the bad checksum\nmsg.payload = nmeaStripped;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 340,
        "y": 720,
        "wires": [
            [
                "6a1166f7.40d818",
                "f4310649.47dad8"
            ]
        ]
    },
    {
        "id": "6a1166f7.40d818",
        "type": "debug",
        "z": "d26052b1.ec666",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 570,
        "y": 600,
        "wires": []
    },
    {
        "id": "f4310649.47dad8",
        "type": "function",
        "z": "d26052b1.ec666",
        "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;\nmsg.payload = message;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 560,
        "y": 720,
        "wires": [
            [
                "6a1166f7.40d818"
            ]
        ]
    }
]



That was fun over morning coffee :Smile  Sooooooo,,, how on earth do we get that into kplex!!! 

PS - I'm not a programmer but tend use CNP (cut and paste from google Wink ) so - if any of you clever people want to point out beter ways of any tips or tricks please, please take a moment to spread the wisdom, these forums are a great place to learn, thanks Cool

YAY!!! At last, so simple - Doh!   All that was missing was a line feed. This works from node red showing up in the nmea diagnostic. Note, I had to manually edit the kplex file to create a UDP input with no address:


Code:
[udp]
name=nodered
direction=in
optional=yes
port=10108

And the node-red function needs a carriage return/ line feed added like :-

msg.payload = msg.payload+"\r\n"
But it works at last! Cool 

[Image: CpJFsbO.png]
Reply


Messages In This Thread
Allow NMEA 0183 file input/output - by abarrow - 2017-05-30, 10:12 PM
RE: Allow NMEA 0183 file input/output - by PaddyB - 2017-05-30, 10:18 PM
RE: Allow NMEA 0183 file input/output - by PaddyB - 2017-05-30, 11:59 PM
RE: Allow NMEA 0183 file input/output - by PaddyB - 2017-05-31, 10:32 AM
RE: Allow NMEA 0183 file input/output - by PaddyB - 2017-05-31, 11:59 AM
RE: Allow NMEA 0183 file input/output - by MatsA - 2017-08-13, 09:11 PM
RE: Allow NMEA 0183 file input/output - by PaddyB - 2017-08-14, 12:46 PM
RE: Allow NMEA 0183 file input/output - by MatsA - 2017-08-15, 09:14 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)