/Users/brianlane/projs/aisparser/c/src/sixbit.c File Reference


Detailed Description

6-bit packed ASCII functions

Author:
Copyright 2006-2008 by Brian C. Lane <bcl@brianlane.com>, All Rights Reserved
Version:
1.8
This module's functions are used to extract data from the 6-bit packed ASCII string used by AIVDM/AIVDO AIS messages.

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 }


Function Documentation

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.

Parameters:
ascii character to convert
returns:

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.

Parameters:
value to convert
returns:

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.

Parameters:
state pointer to a sixbit state structure
numbits number of bits to return
This function returns the requested number of bits to the calling function. It pulls the bits from the raw 6-bit ASCII as they are needed.

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:

    sixbit  state;
    unsigned char i;

    init_6bit( &state );
    strcpy( state.bits, "5678901234" );
    i = get_6bit( &state, 6 );

    i == 5

int __stdcall init_6bit ( sixbit state  ) 

Initialize a 6-bit datastream structure.

Parameters:
state state of 6-bit parser
This function initializes the state of the sixbit parser variables and 0 terminates the 6-bit string.

Example:

    sixbit state;
    
    init_6bit( &state );

unsigned int __stdcall sixbit_length ( sixbit state  ) 

Calculate the number of bits remaining in the six_state.

Parameters:
state returns:
  • Number of bits remaining


Variable Documentation

const unsigned char pow2_mask[] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F }


Generated on Tue Aug 26 13:57:50 2008 for AIS Parser by  doxygen 1.5.2