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

Module ais_msg_1

source code

Autogenerated python functions to serialize/deserialize binary messages.

Generated by: ./aisxmlbinmsg2py.py

Need to then wrap these functions with the outer AIS packet and then convert the whole binary blob to a NMEA string. Those functions are not currently provided in this file.

serialize: python to ais binary deserialize: ais binary to python

The generated code uses translators.py, binary.py, and aisstring.py which should be packaged with the resulting files.


Requires:

Author: xmlbinmsg

Version: 4791

Status: under development

License: Generated code has no license

To Do: FIX: put in a description of the message here with fields and types.

Classes [hide private]
  Testposition
Use testvalue tag text from each type to build test case the position message

Functions [hide private]
BitVector encode(params, validate=False)
Create a position binary message payload to pack into an AIS Msg position.
dict decode(bv, validate=False)
Unpack a position message
  decodeMessageID(bv, validate=False)
  decodeRepeatIndicator(bv, validate=False)
  decodeUserID(bv, validate=False)
  decodeNavigationStatus(bv, validate=False)
  decodeROT(bv, validate=False)
  decodeSOG(bv, validate=False)
  decodePositionAccuracy(bv, validate=False)
  decodePosition_longitude(bv, validate=False)
  decodePosition_latitude(bv, validate=False)
  decodeCOG(bv, validate=False)
  decodeTrueHeading(bv, validate=False)
  decodeTimeStamp(bv, validate=False)
  decodeRegionalReserved(bv, validate=False)
  decodeSpare(bv, validate=False)
  decodeRAIM(bv, validate=False)
  decodesyncstate(bv, validate=False)
  decodeslottimeout(bv, validate=False)
  decodeslotoffset(bv, validate=False)
  printHtml(params, out=sys.stdout)
  printKml(params, out=sys.stdout)
KML (Keyhole Markup Language) for Google Earth, but without the header/footer
stdout printFields(params, out=sys.stdout, format='std', fieldList=None, dbType='postgres')
Print a slotoffset message to stdout.
str sqlCreateStr(outfile=sys.stdout, fields=None, extraFields=None, addCoastGuardFields=True, dbType='postgres')
Return the SQL CREATE command for this message type
sqlhelp.create sqlCreate(fields=None, extraFields=None, addCoastGuardFields=True, dbType='postgres')
Return the sqlhelp object to create the table.
str sqlInsertStr(params, outfile=sys.stdout, extraParams=None, dbType='postgres')
Return the SQL INSERT command for this message type
sqlhelp.insert sqlInsert(params, extraParams=None, dbType='postgres')
Give the SQL INSERT statement
dict testParams()
Return a params file base on the testvalue tags.
  addMsgOptions(parser)

Variables [hide private]
  __date__ = '2007-02-16'
Date of last svn commit
  TrueBV = <ais.BitVector.BitVector object at 0x2094450>
Why always rebuild the True bit? This should speed things up a bunch
  FalseBV = <ais.BitVector.BitVector object at 0x2094550>
Why always rebuild the False bit? This should speed things up a bunch
  fieldList = ('MessageID', 'RepeatIndicator', 'UserID', 'Navigati...
  fieldListPostgres = ('MessageID', 'RepeatIndicator', 'UserID', 'Navigati...
  toPgFields = {'Position_longitude': 'Position', 'Position_latitud...
Go to the Postgis field names from the straight field name
  fromPgFields = {'Position': ('Position_longitude', 'Position_latitu...
Go from the Postgis field names to the straight field name
  pgTypes = {'Position': 'POINT'}
Lookup table for each postgis field name to get its type.
  RepeatIndicatorEncodeLut = {'default': '0', 'do not repeat any more': '3'}
  RepeatIndicatorDecodeLut = {'0': 'default', '3': 'do not repeat any more'}
  NavigationStatusEncodeLut = {'engaged in fishing': '7', 'moored': '5', 'not defi...
  NavigationStatusDecodeLut = {'11': 'reserved for future use', '10': 'reserved fo...
  SOGEncodeLut = {'102.2 knots or higher': '102.2'}
  SOGDecodeLut = {'102.2': '102.2 knots or higher'}
  PositionAccuracyEncodeLut = {'low (greater than 10 m)': '0', 'high (less than 10...
  PositionAccuracyDecodeLut = {'1': 'high (less than 10 m)', '0': 'low (greater th...
  TimeStampEncodeLut = {'dead reckoning': '62', 'inoperative': '63', 'not a...
  TimeStampDecodeLut = {'60': 'not available/default', '61': 'manual input'...
  RAIMEncodeLut = {'in use': 'True', 'not in use': 'False'}
  RAIMDecodeLut = {'True': 'in use', 'False': 'not in use'}
  syncstateEncodeLut = {'UTC indirect': '1', 'UTC direct': '0', 'synchroniz...
  syncstateDecodeLut = {'1': 'UTC indirect', '0': 'UTC direct', '3': 'synch...
  slottimeoutEncodeLut = {'Last frame in this slot': '0', '4 frames left': '4...
  slottimeoutDecodeLut = {'1': '1 frames left', '0': 'Last frame in this slot...
  typeChoices = 'binary', 'nmeapayload', 'nmea'
  outputChoices = 'std', 'html', 'csv', 'sql', 'kml', 'kml-full'
  dbChoices = 'sqlite', 'postgres'
  outfile = file(options.outputFileName, 'w')
  msgDict = {'MessageID': '1', 'RepeatIndicator': options.Repeat...
  bitLen = len(bits)
  bits = bits+ BitVector(size= (6-(bitLen % 6)))
  buf = StringIO.StringIO()
  result = buf.getvalue()

Function Details [hide private]

encode(params, validate=False)

source code 

Create a position binary message payload to pack into an AIS Msg position.

Fields in params:
  • MessageID(uint): AIS message number. Must be 1 (field automatically set to "1")
  • RepeatIndicator(uint): Indicated how many times a message has been repeated
  • UserID(uint): Unique ship identification number (MMSI)
  • NavigationStatus(uint): What is the vessel doing
  • ROT(int): RateOfTurn
  • SOG(udecimal): Speed over ground
  • PositionAccuracy(uint): Accuracy of positioning fixes
  • Position_longitude(decimal): Location of the vessel East West location
  • Position_latitude(decimal): Location of the vessel North South location
  • COG(udecimal): Course over ground
  • TrueHeading(uint): True heading (relative to true North)
  • TimeStamp(uint): UTC second when the report was generated
  • RegionalReserved(uint): Reserved for definition by a regional authority. (field automatically set to "0")
  • Spare(uint): Not used. Should be set to zero. (field automatically set to "0")
  • RAIM(bool): Receiver autonomous integrity monitoring flag
  • syncstate(uint): Sycronization state
  • slottimeout(uint): Frames remaining until a new slot is selected
  • slotoffset(uint): In what slot will the next transmission occur. BROKEN
Parameters:
  • params - Dictionary of field names/values. Throws a ValueError exception if required is missing
  • validate - Set to true to cause checking to occur. Runs slower. FIX: not implemented.
Returns: BitVector
encoded binary message (for binary messages, this needs to be wrapped in a msg 8

Note: The returned bits may not be 6 bit aligned. It is up to you to pad out the bits.

decode(bv, validate=False)

source code 

Unpack a position message

Fields in params:
  • MessageID(uint): AIS message number. Must be 1 (field automatically set to "1")
  • RepeatIndicator(uint): Indicated how many times a message has been repeated
  • UserID(uint): Unique ship identification number (MMSI)
  • NavigationStatus(uint): What is the vessel doing
  • ROT(int): RateOfTurn
  • SOG(udecimal): Speed over ground
  • PositionAccuracy(uint): Accuracy of positioning fixes
  • Position_longitude(decimal): Location of the vessel East West location
  • Position_latitude(decimal): Location of the vessel North South location
  • COG(udecimal): Course over ground
  • TrueHeading(uint): True heading (relative to true North)
  • TimeStamp(uint): UTC second when the report was generated
  • RegionalReserved(uint): Reserved for definition by a regional authority. (field automatically set to "0")
  • Spare(uint): Not used. Should be set to zero. (field automatically set to "0")
  • RAIM(bool): Receiver autonomous integrity monitoring flag
  • syncstate(uint): Sycronization state
  • slottimeout(uint): Frames remaining until a new slot is selected
  • slotoffset(uint): In what slot will the next transmission occur. BROKEN
Parameters:
  • bv (BitVector) - Bits defining a message
  • validate - Set to true to cause checking to occur. Runs slower. FIX: not implemented.
Returns: dict
params

decodeMessageID(bv, validate=False)

source code 
None

decodeRepeatIndicator(bv, validate=False)

source code 
None

decodeUserID(bv, validate=False)

source code 
None

decodeNavigationStatus(bv, validate=False)

source code 
None

decodeROT(bv, validate=False)

source code 
None

decodeSOG(bv, validate=False)

source code 
None

decodePositionAccuracy(bv, validate=False)

source code 
None

decodePosition_longitude(bv, validate=False)

source code 
None

decodePosition_latitude(bv, validate=False)

source code 
None

decodeCOG(bv, validate=False)

source code 
None

decodeTrueHeading(bv, validate=False)

source code 
None

decodeTimeStamp(bv, validate=False)

source code 
None

decodeRegionalReserved(bv, validate=False)

source code 
None

decodeSpare(bv, validate=False)

source code 
None

decodeRAIM(bv, validate=False)

source code 
None

decodesyncstate(bv, validate=False)

source code 
None

decodeslottimeout(bv, validate=False)

source code 
None

decodeslotoffset(bv, validate=False)

source code 
None

printHtml(params, out=sys.stdout)

source code 
None

printKml(params, out=sys.stdout)

source code 
KML (Keyhole Markup Language) for Google Earth, but without the header/footer

printFields(params, out=sys.stdout, format='std', fieldList=None, dbType='postgres')

source code 

Print a slotoffset message to stdout.

Fields in params:
  • MessageID(uint): AIS message number. Must be 1 (field automatically set to "1")
  • RepeatIndicator(uint): Indicated how many times a message has been repeated
  • UserID(uint): Unique ship identification number (MMSI)
  • NavigationStatus(uint): What is the vessel doing
  • ROT(int): RateOfTurn
  • SOG(udecimal): Speed over ground
  • PositionAccuracy(uint): Accuracy of positioning fixes
  • Position_longitude(decimal): Location of the vessel East West location
  • Position_latitude(decimal): Location of the vessel North South location
  • COG(udecimal): Course over ground
  • TrueHeading(uint): True heading (relative to true North)
  • TimeStamp(uint): UTC second when the report was generated
  • RegionalReserved(uint): Reserved for definition by a regional authority. (field automatically set to "0")
  • Spare(uint): Not used. Should be set to zero. (field automatically set to "0")
  • RAIM(bool): Receiver autonomous integrity monitoring flag
  • syncstate(uint): Sycronization state
  • slottimeout(uint): Frames remaining until a new slot is selected
  • slotoffset(uint): In what slot will the next transmission occur. BROKEN
Parameters:
  • params - Dictionary of field names/values.
  • out - File like object to write to
Returns: stdout
text to out

sqlCreateStr(outfile=sys.stdout, fields=None, extraFields=None, addCoastGuardFields=True, dbType='postgres')

source code 
Return the SQL CREATE command for this message type
Parameters:
  • outfile - file like object to print to.
  • fields - which fields to put in the create. Defaults to all.
  • extraFields - A sequence of tuples containing (name,sql type) for additional fields
  • addCoastGuardFields (bool) - Add the extra fields that come after the NMEA check some from the USCG N-AIS format
  • dbType - Which flavor of database we are using so that the create is tailored ('sqlite' or 'postgres')
Returns: str
sql create string

See Also: sqlCreate

sqlCreate(fields=None, extraFields=None, addCoastGuardFields=True, dbType='postgres')

source code 
Return the sqlhelp object to create the table.
Parameters:
  • fields - which fields to put in the create. Defaults to all.
  • extraFields - A sequence of tuples containing (name,sql type) for additional fields
  • addCoastGuardFields (bool) - Add the extra fields that come after the NMEA check some from the USCG N-AIS format
  • dbType - Which flavor of database we are using so that the create is tailored ('sqlite' or 'postgres')
Returns: sqlhelp.create
An object that can be used to generate a return

sqlInsertStr(params, outfile=sys.stdout, extraParams=None, dbType='postgres')

source code 
Return the SQL INSERT command for this message type
Parameters:
  • params - dictionary of values keyed by field name
  • outfile - file like object to print to.
  • extraParams - A sequence of tuples containing (name,sql type) for additional fields
Returns: str
sql create string

See Also: sqlCreate

sqlInsert(params, extraParams=None, dbType='postgres')

source code 
Give the SQL INSERT statement
Parameters:
  • params - dict keyed by field name of values
  • extraParams - any extra fields that you have created beyond the normal ais message fields
Returns: sqlhelp.insert
insert class instance

To Do: allow optional type checking of params?

Warning: this will take invalid keys happily and do what???

testParams()

source code 
Return a params file base on the testvalue tags.
Returns: dict
params based on testvalue tags

addMsgOptions(parser)

source code 
None

Variables Details [hide private]

__date__

Date of last svn commit
Value:
'2007-02-16'                                                           
      

TrueBV

Why always rebuild the True bit? This should speed things up a bunch
Value:
<ais.BitVector.BitVector object at 0x2094450>                          
      

FalseBV

Why always rebuild the False bit? This should speed things up a bunch
Value:
<ais.BitVector.BitVector object at 0x2094550>                          
      

fieldList

None
Value:
('MessageID',
 'RepeatIndicator',
 'UserID',
 'NavigationStatus',
 'ROT',
 'SOG',
 'PositionAccuracy',
 'Position_longitude',
...                                                                    
      

fieldListPostgres

None
Value:
('MessageID',
 'RepeatIndicator',
 'UserID',
 'NavigationStatus',
 'ROT',
 'SOG',
 'PositionAccuracy',
 'Position',
...                                                                    
      

toPgFields

Go to the Postgis field names from the straight field name
Value:
{'Position_longitude': 'Position', 'Position_latitude': 'Position'}    
      

fromPgFields

Go from the Postgis field names to the straight field name
Value:
{'Position': ('Position_longitude', 'Position_latitude')}              
      

pgTypes

Lookup table for each postgis field name to get its type.
Value:
{'Position': 'POINT'}                                                  
      

RepeatIndicatorEncodeLut

None
Value:
{'default': '0', 'do not repeat any more': '3'}                        
      

RepeatIndicatorDecodeLut

None
Value:
{'0': 'default', '3': 'do not repeat any more'}                        
      

NavigationStatusEncodeLut

None
Value:
{'aground': '6',
 'at anchor': '1',
 'constrained by her draught': '4',
 'engaged in fishing': '7',
 'moored': '5',
 'not defined = default': '15',
 'not under command': '2',
 'reserved for future use': '14',
...                                                                    
      

NavigationStatusDecodeLut

None
Value:
{'0': 'under way using engine',
 '1': 'at anchor',
 '10': 'reserved for future use',
 '11': 'reserved for future use',
 '12': 'reserved for future use',
 '13': 'reserved for future use',
 '14': 'reserved for future use',
 '15': 'not defined = default',
...                                                                    
      

SOGEncodeLut

None
Value:
{'102.2 knots or higher': '102.2'}                                     
      

SOGDecodeLut

None
Value:
{'102.2': '102.2 knots or higher'}                                     
      

PositionAccuracyEncodeLut

None
Value:
{'low (greater than 10 m)': '0', 'high (less than 10 m)': '1'}         
      

PositionAccuracyDecodeLut

None
Value:
{'1': 'high (less than 10 m)', '0': 'low (greater than 10 m)'}         
      

TimeStampEncodeLut

None
Value:
{'dead reckoning': '62',
 'inoperative': '63',
 'manual input': '61',
 'not available/default': '60'}                                        
      

TimeStampDecodeLut

None
Value:
{'60': 'not available/default',
 '61': 'manual input',
 '62': 'dead reckoning',
 '63': 'inoperative'}                                                  
      

RAIMEncodeLut

None
Value:
{'in use': 'True', 'not in use': 'False'}                              
      

RAIMDecodeLut

None
Value:
{'True': 'in use', 'False': 'not in use'}                              
      

syncstateEncodeLut

None
Value:
{'UTC direct': '0',
 'UTC indirect': '1',
 'synchronized to a base station': '2',
 'synchronized to another station': '3'}                               
      

syncstateDecodeLut

None
Value:
{'0': 'UTC direct',
 '1': 'UTC indirect',
 '2': 'synchronized to a base station',
 '3': 'synchronized to another station'}                               
      

slottimeoutEncodeLut

None
Value:
{'1 frames left': '1',
 '2 frames left': '2',
 '3 frames left': '3',
 '4 frames left': '4',
 '5 frames left': '5',
 '6 frames left': '6',
 '7 frames left': '7',
 'Last frame in this slot': '0'}                                       
      

slottimeoutDecodeLut

None
Value:
{'0': 'Last frame in this slot',
 '1': '1 frames left',
 '2': '2 frames left',
 '3': '3 frames left',
 '4': '4 frames left',
 '5': '5 frames left',
 '6': '6 frames left',
 '7': '7 frames left'}                                                 
      

typeChoices

None
Value:
'binary', 'nmeapayload', 'nmea'                                        
      

outputChoices

None
Value:
'std', 'html', 'csv', 'sql', 'kml', 'kml-full'                         
      

dbChoices

None
Value:
'sqlite', 'postgres'                                                   
      

outfile

None
Value:
file(options.outputFileName, 'w')                                      
      

msgDict

None
Value:
{'MessageID': '1', 'RepeatIndicator': options.RepeatIndicatorField, 'U
serID': options.UserIDField, 'NavigationStatus': options.NavigationSta
tusField, 'ROT': options.ROTField, 'SOG': options.SOGField, 'PositionA
ccuracy': options.PositionAccuracyField, 'Position_longitude': options
.Position_longitudeField, 'Position_latitude': options.Position_latitu
deField, 'COG': options.COGField, 'TrueHeading': options.TrueHeadingFi
eld, 'TimeStamp': options.TimeStampField, 'RegionalReserved': '0', 'Sp
are': '0', 'RAIM': options.RAIMField, 'syncstate': options.syncstateFi
...                                                                    
      

bitLen

None
Value:
len(bits)                                                              
      

bits

None
Value:
bits+ BitVector(size= (6-(bitLen % 6)))                                
      

buf

None
Value:
StringIO.StringIO()                                                    
      

result

None
Value:
buf.getvalue()