Recent

Author Topic: SOLVED :For java users :This small NMEA chechsum Java snippet to pascal  (Read 5284 times)

yanes19

  • New Member
  • *
  • Posts: 36
Hi all ,
Since I have 0% experience with Java programming language , and I'm writing a GUI utility to read
and send NMEA (Data exchange sentences between nautical navigation systems  ) sentences to serial ports  for linux systems.
theses systems requires a check sum to garantee sentences integrity , I found  it in java so I need some help to
translate it to pascal
Can any one help please ?
Code: [Select]
function decimalToHex(d, padding) {
    var hex = Number(d).toString(16);
    padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;

    while (hex.length < padding) {
        hex = "0" + hex;
    }

    return hex;
}

// Program begins here,

var checksum = 0;
var stringToCalculateTheChecksumOver = 'GPGLL,3330.033167,N,01107.984167,E,044632.000,A';

for(var i = 0; i < stringToCalculateTheChecksumOver.length; i++) {
  checksum = checksum ^ stringToCalculateTheChecksumOver.charCodeAt(i);
}
there is a fuction to convert decimal to hex I dont think that 's too hard  for me to write it in pascal , (But doing it'll be appreciated ;)  )

PS: I'm not sure this is the right place for a similar post , if not I'm really sorry Mods  :-[

thanks in advance  :)
« Last Edit: May 15, 2014, 10:00:54 pm by yanes19 »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: For java users :This small Java snippet to pascal
« Reply #1 on: May 14, 2014, 10:03:20 pm »
fpc already has a one it is called IntToHEx.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

yanes19

  • New Member
  • *
  • Posts: 36
Re: For java users :This small Java snippet to pascal
« Reply #2 on: May 14, 2014, 10:25:17 pm »
Thanks for reply ,
The problem here is in the main progarm body (The Checksum calculations )not in the IntToHEx ,

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: For java users :This small Java snippet to pascal
« Reply #3 on: May 14, 2014, 10:30:52 pm »
Code: [Select]
var
  checksum : word =0;//??
  stringToCalculateTheChecksumOver :String = 'GPGLL,3330.033167,N,01107.984167,E,044632.000,A';
  I : itneger;
begin
  for i := 1 to length(stringToCalculateTheChecksumOver) do begin
    checksum := checksum xor ord(stringToCalculateTheChecksumOver[i])
  end;
end;

Thats the most of it I have no idea what ^ does in java so you need to find that out.

Erm http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
« Last Edit: May 14, 2014, 10:34:39 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: For java users :This small Java snippet to pascal
« Reply #4 on: May 14, 2014, 11:27:44 pm »
hello yanes,
don't reinvent the wheel. In my component LazSerial, you have already an example with a simulator , reader of NMEA sentences (and with a function to calculate checksum) :
Quote
Demo : a simulator of serial port gps + serial port receiver :
you can send NMEA frames ( GGA GLL RMC) to the opened serial port
(start gps simulator). You can change speed and heading.
In the memo you can see what is received from  the opened serial port.
In the status bar you can see the status events.

look at  :o  here

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

yanes19

  • New Member
  • *
  • Posts: 36
Re: For java users :This small Java snippet to pascal
« Reply #5 on: May 15, 2014, 09:57:58 pm »
very nice work buddy :)  , you saved me ,
I have already written a tool to send a pre-collected  data (Any valid sentences from GPS ,  EchoSounder ,Heading ....)
to test with opencpn , maxsea and many other nautical programs Under win32 and ubuntu 32 & 64 bit.
but I used a multi-threaded app using Synaser , your tool will be a great reference example , thank you ,
I liked the FRENCH comments and Var names ;)      .
I will publish my tools soon , Voulez vous que je vous que je vous informe quand ils seront publiés   ;)?
Of course I need some help from open source and  linux community .
« Last Edit: May 16, 2014, 02:55:22 am by yanes19 »

yanes19

  • New Member
  • *
  • Posts: 36
Thread title and solved flag added to allow more users to find this using forum  internal or external search engines .
Thank you guys

 

TinyPortal © 2005-2018