Trees | Indices | Help |
---|
|
AIS binary helper functions.
Code to convert AIS messages between binary BitVectors and strings. They are usually encoded an ASCII 6-bit packing within NMEA !AIVDM/!AIVDO messages.Author: Kurt Schwehr
Version: 2075
Copyright: 2006
To Do:
Bugs:
|
|||
BitVector
|
float2bitvec(floatval) Get the IEEE floating point bits for a python float |
||
float
|
bitvec2float(bv) Convert a 32 bit bitvector representing an IEEE float into a python float |
||
|
joinBV(bvSeq) Combined a sequence of bit vectors into one large BitVector |
||
BitVector
|
setBitVectorSize(bv,
size=8) Pad a BitVector with 0's on the left until it is at least the size specified |
||
BitVector
|
addone(bv) Add one bit to a bit vector. |
||
BitVector
|
subone(bv) Subtract one bit from a bit vector |
||
BitVector
|
bvFromSignedInt(intVal,
bitSize=None) Create a twos complement BitVector from a signed integer. |
||
int
|
signedIntFromBV(bv) Interpret a bit vector as an signed integer. |
||
BitVector(6)
|
ais6chartobitvec(char6) Create a 6 bit BitVector for a single character |
||
BitVector
|
ais6tobitvec(str6) Convert an ITU AIS 6 bit string into a bit vector. |
||
str, pad
|
bitvectoais6(bv) Convert bit vector int an ITU AIS 6 bit string. |
|
|||
|
__date__ = '2006-05-03' Date of last svn commit |
||
|
success = False
|
||
|
decode = {'1': <BitVector.BitVector object at 0x11db9f0>, '0'... cache of character to BitVector lookup |
||
|
encode = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: ... cache of ais int value to charcter |
|
|
|
|
|
>>> print addone(BitVector(bitstring='1100')) 1101 >>> print addone(BitVector(bitstring='1111')) 0000
|
>>> print subone(BitVector(bitstring='1111')) 1110 >>> print subone(BitVector(bitstring='0010')) 0001 >>> print subone(BitVector(bitstring='0000')) 1111
|
Create a twos complement BitVector from a signed integer. Positives must have a '0' in the left hand position.>>> print bvFromSignedInt(0,bitSize=4) 0000 >>> print bvFromSignedInt(1,bitSize=4) 0001 >>> print bvFromSignedInt(7,bitSize=4) 0111Negative numbers must have a '1' in the left hand position. >>> print bvFromSignedInt(-1,bitSize=4) 1111 >>> print bvFromSignedInt(-2,bitSize=4) 1110 >>> print bvFromSignedInt(-7,bitSize=4) 1001
|
Interpret a bit vector as an signed integer. int(BitVector) defaults to treating the bits as an unsigned int. Assumes twos complement representation. http://en.wikipedia.org/wiki/Twos_complement Positive values decode like so:>>> signedIntFromBV(BitVector(bitstring='0000')) 0 >>> signedIntFromBV(BitVector(bitstring='0101')) 5Here are some negative integer examples: >>> signedIntFromBV(BitVector(bitstring='1111')) -1 >>> signedIntFromBV(BitVector(bitstring='1110')) -2 >>> signedIntFromBV(BitVector(bitstring='1010')) -6 >>> signedIntFromBV(BitVector(bitstring='1001')) -7 >>> signedIntFromBV(BitVector(bitstring='1000')) -8
|
>>> print int(ais6chartobitvec('0')) 0 >>> print int(ais6chartobitvec('1')) 1 >>> print int(ais6chartobitvec('9')) 9 >>> print int(ais6chartobitvec('<')) 12 >>> print int(ais6chartobitvec('=')) 13 >>> print int(ais6chartobitvec('@')) 16 >>> print int(ais6chartobitvec('A')) 17 >>> print int(ais6chartobitvec('O')) 31 >>> print int(ais6chartobitvec('P')) 32 >>> print int(ais6chartobitvec('Q')) 33 >>> print int(ais6chartobitvec('R')) 34 >>> print int(ais6chartobitvec('Z')) 34 >>> print int(ais6chartobitvec('a')) 41 >>> print int(ais6chartobitvec('w')) 63 >>> print ais6chartobitvec('w') 111111x, y, and z will not appear.
|
|
>>> print bitvectoais6(BitVector(bitstring='000110101010010110001010100010')) ('6bF:Z', 0)
|
|
__date__Date of last svn commit
|
successNone
|
decodecache of character to BitVector lookup
|
encodecache of ais int value to charcter
|
Trees | Indices | Help |
---|
Generated by Epydoc 3.0alpha3 on Thu Nov 30 14:53:50 2006 | http://epydoc.sourceforge.net |