0

I want to send a message to the server as per the AIS 140 standard. Please explain how to calculate the checksum. Find below the sample message format.

$Header,iTriangle,KA01I2000,861693034634154,1_37T02B0164MAIS,AIS140,12.976545,N,77.5497 59,E*50 

1 Answer 1

0

As per AIS140 Standard Checksum is calculated by performing xor to all bytes received from packet.

Note: You have to remove '$'.

Caution: Use data from device to verify this code (Example provided from doc doesnt have valid checksum)

This Javascript code will help your job done.

function checksum(packet) {
  const charArray = packet.split('');
  let xor = 0;
  const n = charArray.length;
  for (let i = 1; i < n - 3; i++) {
    xor = xor ^ charArray[i].charCodeAt(0);
  }
  const cs = parseInt("0x" + charArray[n - 2] + charArray[n - 1]);
  return xor === cs;
}
checksum('$Header,iTriangle,KA01I2000,861693034634154,1_37T02B0164MAIS,AIS140,12.976545,N,77.549759,E*50')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.