Package ais :: Module aisstring
[hide private]
[frames] | no frames]

Module aisstring

source code

Handle encoding and decoding AIS strings.


Bugs:

Author: Kurt Schwehr

Version: 2068

Copyright: 2006

Functions [hide private]
str decode(bits, dropAfterFirstAt=False)
Decode bits as a string.
BitVector encode(string, bitSize=None)
str unpad(string, removeBlanks=True)
Remove AIS string padding
str pad(string, length)
pad a string out to the proper length with the @ character as required by the ais spec

Variables [hide private]
  __date__ = '2006-05-02'
Date of last svn commit
list characterLUT = ['@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', '...
lookup table for decode to fetch characters faster
  characterDict = {'!': 33, ' ': 32, '#': 35, '"': 34, '%': 37, '$': 3...
Fast lookup for the AIS int code for a character
dict characterBits = {'!': <ais.BitVector.BitVector object at 0x2066ef0>,...
lookup table for going from a single character to a 6 bit BitVector
  success = False

Function Details [hide private]

decode(bits, dropAfterFirstAt=False)

source code 
Decode bits as a string. Does not remove the end space or @@@@. Must be an multiple of 6 bits.
Parameters:
  • bits (BitVector) - n*6 bits that represent a string.
Returns: str
string with pad spaces or @@@@

encode(string, bitSize=None)

source code 
Parameters:
  • string (str) - python ascii string to encode.
  • bitSize (int) - how many bits should this take. must be a multiple of 6
Returns: BitVector
enocded bits for the string

Bugs:

  • force to upper case
  • building this in reverse may be faster
  • check that bitSize is a multple of 6
  • pad with "@" to reach requested bitSize

unpad(string, removeBlanks=True)

source code 
Remove AIS string padding
>>> unpad('@')
''
>>> unpad('A@')
'A'
>>> unpad('ABCDEF1234@@@@@')
'ABCDEF1234'
FIX: is this the correct response?
>>> unpad('A@B')
'A@B'
This is non standard behavior, but some AIS systems space pad the right
>>> unpad(' ')
''
>>> unpad('MY SHIP NAME    ')
'MY SHIP NAME'
The standard implies this behavior with is less fun
>>> unpad('MY SHIP NAME    ',removeBlanks=False)
'MY SHIP NAME    '
Parameters:
  • string (str) - string to cleanup
  • removeBlanks (bool) - set to true to strip spaces on the right
Returns: str
cleaned up string

Bug: use a faster algorithm for truncating the string

pad(string, length)

source code 
pad a string out to the proper length with the @ character as required by the ais spec
>>> pad('',0)
''
>>> pad('',1)
'@'
>>> pad('A',1)
'A'
>>> pad('A',2)
'A@'
>>> pad('MY SHIP NAME',20)
'MY SHIP NAME@@@@@@@@'
Parameters:
  • string (str) - string to pad out
  • length (int) - number of characters that the string must be
Returns: str
str of len length

Bug: Use a list and join to make the string building faster


Variables Details [hide private]

__date__

Date of last svn commit
Value:
'2006-05-02'                                                           
      

characterLUT

lookup table for decode to fetch characters faster
Type:
list
Value:
['@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']                          
      

characterDict

Fast lookup for the AIS int code for a character
Value:
{' ': 32,
 '!': 33,
 '"': 34,
 '#': 35,
 '$': 36,
 '%': 37,
 '&': 38,
 '(': 40,
...                                                                    
      

characterBits

lookup table for going from a single character to a 6 bit BitVector
Type:
dict
Value:
{' ': <ais.BitVector.BitVector object at 0x2066e90>,
 '!': <ais.BitVector.BitVector object at 0x2066ef0>,
 '"': <ais.BitVector.BitVector object at 0x20722b0>,
 '#': <ais.BitVector.BitVector object at 0x2072a90>,
 '$': <ais.BitVector.BitVector object at 0x2072ad0>,
 '%': <ais.BitVector.BitVector object at 0x2072b10>,
 '&': <ais.BitVector.BitVector object at 0x2072b50>,
 '(': <ais.BitVector.BitVector object at 0x2072bd0>,
...                                                                    
      

success

None
Value:
False