As a sailor, I use navigation softs and I would like to display some infos on the sailing softs from a acoustic beacon.
To do so, I get the value from the beacon in the form of PTSAG trames (GPS type trames). After treating theses trames, I get the position in lattitude and longitude coordinates, that I want to use to display the position of the beacon on the navigation soft.
From these information, and some other, I build a TLL trames, readable on most of the softwares by using another soft that I would like to avoid.
To read the position on the softs, I have to translate these informations in a special trame format, AIS trames. Which is the standard communication protocol on sea to avoid obstacles and repair other ships.
AIS i.e : !AIVDM,1,1,,A,14VE:80029hn1qmIe3Pjrj00SF,0*3A
The informations of the MMSI number, position, and etc are converted into binary numbers, and compressed using a 6-bits ASCII tables.
I would like to know a way to convert for instance a MMSI from dec to binary and then to compress it using this ASCII table.
i.e the MMSI is: 228136000, I should be able to convert it in a 30bits binary and to convert it from the ASCII table.
Thanks for your help, don't hesitate if I am not understandable in my descriptions specially for the AIS trame model.
The first step in your quest is to make an array representing the ASCII characters. Unfortunately this isn't a direct 1:1 (+ offset) relationship between the actual ASCII table and the binary values, so a lookup table (LUT) will be needed.
Each character in that string can be represented as a number 0-63, for instance, LUT[4] equals D.
How you then convert your data into 6-bit values to map to that table (and/or back again) depends on a) what format the data is in, and b) what format AIS expects it to be in.
For instance, if you have an unsigned integer value 12345, that is stored internally as 16 bits. If AIS expects that as raw 16-bit data, then it is a case of taking each 6 bits in turn and mapping them. If it expects the individual digits as individual 6-bit values, then you may be better off printing the value to a string, including any leading zeros or padding, and then work on it a character at a time from there.
If your frames are of a fixed format and length, then it may be worth setting up a union / structure to access the 6-bit values. For instance, if you have a frame that is 24 bits in length (4 groups of 6 bits) it may be good to map them as: