The state of the sixbit machine is held in the sixbit structure so that multiple streams can be processed by maintaining separate instances of sixbit. init_6bit() should be called with a pointer to the sixbit instance, it will setup the structure for parsing. The 6-bit data should then be copied into the sixbit.bits buffer. A maximum of 255 characters are allowed (this is changed by SIXBIT_LEN in sixbit.h)
Up to 32 bits of data are fetched from the string by calling get_6bit()
The size of the packet can be calculated with strlen(state->bits) * 6 but note that due to padding at the end of the string the data may be 1-6 bits longer than the the expected length for the message id.
It is up to the calling function to keep track of how many bits have been fetched. When it reaches the end of the 6-bit string get_6bit() will return 0's.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "portable.h"
#include "sixbit.h"
Functions | |
| unsigned int __stdcall | sixbit_length (sixbit *state) |
| Calculate the number of bits remaining in the six_state. | |
| char __stdcall | binfrom6bit (char ascii) |
| Convert an ascii value to a 6-bit binary value. | |
| char __stdcall | binto6bit (char value) |
| Convert a binary value to a 6-bit ASCII value. | |
| int __stdcall | init_6bit (sixbit *state) |
| Initialize a 6-bit datastream structure. | |
| unsigned long __stdcall | get_6bit (sixbit *state, short numbits) |
| Return 0-32 bits from a 6-bit ASCII stream. | |
Variables | |
| const unsigned char | pow2_mask [] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F } |
| char __stdcall binfrom6bit | ( | char | ascii | ) |
Convert an ascii value to a 6-bit binary value.
This function checks the ASCII value to make sure it can be coverted. If not, it returns a -1. Otherwise it returns the 6-bit binary value.
| ascii | character to convert |
This is used to convert the packed 6-bit value to a binary value. It is not used to convert data from fields such as the name and destination -- Use ais2ascii() instead.
| char __stdcall binto6bit | ( | char | value | ) |
Convert a binary value to a 6-bit ASCII value.
This function checks the binary value to make sure it can be coverted. If not, it returns a -1. Otherwise it returns the 6-bit ASCII value.
| value | to convert |
This is used to convert a 6 bit binary value to the packed 6-bit value It is not used to convert data from fields such as the name and destination -- Use ais2ascii() instead.
| unsigned long __stdcall get_6bit | ( | sixbit * | state, | |
| short | numbits | |||
| ) |
Return 0-32 bits from a 6-bit ASCII stream.
| state | pointer to a sixbit state structure | |
| numbits | number of bits to return |
The full string can be addressed by pointing to state->bits and the length can be calculated by strlen(state->bits) * 6, but note that the string also includes any final padding, so when checking lengths take into account that it will be a multiples of 6 bits.
Example:
| int __stdcall init_6bit | ( | sixbit * | state | ) |
| unsigned int __stdcall sixbit_length | ( | sixbit * | state | ) |
Calculate the number of bits remaining in the six_state.
| state | returns:
|
| const unsigned char pow2_mask[] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F } |
1.5.2