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

Module aisxmlbinmsg2py

source code

Tools to generate python code to serialize/deserialize messages between python and ais binary. Trying to be as inline as possible, so no XML on the fly like in ais-py.

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: Kurt Schwehr

Version: 4791

Copyright: 2006

Since: 2006-Sep-24

Status: under development

Organization: CCOM

License: Restricted while in development to NOAA and USCG.

To Do:

Bug: NOT complete

Functions [hide private]
  suggestType(name, curType, printout=True)
Try to suggest a type name if one did not work.
  hasSubtag(et, subtag)
  writeBeginning(o)
Write the doc string header for the message file
  generatePython(infile, outfile)
  getMaxFieldNameLen(msgET)
Get the maximum string length of any field name
  padStrRight(aStr, strlen)
Pad a string out to the length requested with spaces out to the right
  buildPrint(o, msgET, verbose=False)
Write a simple in order print for the resulting dictionary.
  encodeBool(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)
Build the encoder for boolean variables
  encodeUInt(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)
Build the encoder for unsigned integer variables
  encodeFloat(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)
Build the encoder for IEEE float variables
  encodeAisstr6(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)
Build the encoder for aisstr6 variables.
  encodeInt(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)
Build the encoder for signed integer variables
  encodeDecimal(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False, scale=None)
Build the encoder for signed decimal variables
  encodeUDecimal(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False, scale=None)
Build the encoder for signed decimal variables
  encodeBinary(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False, scale=None)
Build the encoder for binary variables.
int decodeBool(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)
Build the decoder for boolean variables
int decodeUInt(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)
Build the decoder for unsigned integer variables
int decodeInt(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)
Build the decoder for unsigned integer variables
int decodeFloat(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)
Build the decoder for IEEE float variables
int decodeAisstr6(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)
Build the decoder for aisstr6 variables.
int decodeDecimal(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False, scale=None)
Build the decoder for signed decimal variables
int decodeUDecimal(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False, scale=None)
Build the decoder for unsigned decimal variables
int decodeBinary(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False, scale=None)
Build the decoder for unsigned decimal variables
  buildTestParamFunc(o, msgET, verbose=False)
Scrape the testvalues to make a basic param
  buildUnitTest(o, msgET, verbose=False)
Write the unittests for a message
  buildEncode(o, msgET, verbose=False)
Write the encoder/decoder for a message
  buildDecodeParts(o, msgET, verbose=False, prefixName=True)
Write the decoder for a message
  buildDecode(o, msgET, verbose=False)
Write the decoder for a message
  buildMain(o)

Variables [hide private]
  __date__ = '2006-09-24'
Date of last svn commit
  success = False

Function Details [hide private]

suggestType(name, curType, printout=True)

source code 
Try to suggest a type name if one did not work.
Parameters:
  • printout - if true, write a suggestion to stdout.
    >>> suggestType('myFieldName','unsigned int')
    Recommend switching "unsigned int" to "uint" for field "myFieldName"
    'uint'
    
    >>> suggestType('JohnWarfon','yoyodyne')
    Sorry!  No recommendation available for bad type "yoyodyne" for field "JohnWarfon"
    

hasSubtag(et, subtag)

source code 
Returns:
true if the tag a sub tag with name subtag

writeBeginning(o)

source code 

Write the doc string header for the message file

param o: Open output file to write code to. param msgET: element tree for the ais message definition. Must be pre-expanded with the expandais.py command.

generatePython(infile, outfile)

source code 
Parameters:
  • infile - xml ais binary message definition file
  • outfile - where to dump the python code

getMaxFieldNameLen(msgET)

source code 
Get the maximum string length of any field name

padStrRight(aStr, strlen)

source code 
Pad a string out to the length requested with spaces out to the right

buildPrint(o, msgET, verbose=False)

source code 

Write a simple in order print for the resulting dictionary.

param o: open file where resulting code will be written param msgET: Element Tree starting at a message node

encodeBool(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)

source code 
Build the encoder for boolean variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - bool, etc.
  • numbits (int = 1) - How many bits per unit datum (must be 1 for bools)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many bools will there be? FIX: handle variable
  • unavailable (bool or None) - the default value to use if none given (if not None)
Returns:
None

encodeUInt(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)

source code 
Build the encoder for unsigned integer variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - uint, bool, etc.
  • numbits (int >= 1) - How many bits per unit datum (must be 1..32)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many unsigned ints will there be? FIX: handle variable
  • unavailable (bool or None) - the default value to use if none given (if not None)
Returns:
None

encodeFloat(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)

source code 
Build the encoder for IEEE float variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - uint, bool, etc.
  • numbits (int >= 1) - How many bits per unit datum (must be 1..32)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many unsigned ints will there be? FIX: handle variable
  • unavailable (bool or None) - the default value to use if none given (if not None)
Returns:
None

encodeAisstr6(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)

source code 
Build the encoder for aisstr6 variables. Generally are arrays.
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - uint, bool, etc.
  • numbits (int >= 1) - How many bits per unit datum (must be 1..32)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many unsigned ints will there be? FIX: handle variable
  • unavailable (bool or None) - the default value to use if none given (if not None)
Returns:
None

Bug: do we need to optionally check for a valid string?

encodeInt(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False)

source code 
Build the encoder for signed integer variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - uint, bool, etc.
  • numbits (int >= 1) - How many bits per unit datum (must be 1..32)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many signed ints will there be? FIX: handle variable
  • unavailable (number or None) - the default value to use if none given (if not None)
Returns:
None

encodeDecimal(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False, scale=None)

source code 
Build the encoder for signed decimal variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - decimal
  • numbits (int >= 1) - How many bits per unit datum (must be 1..32)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many decimals will there be? FIX: handle variable
  • unavailable (Decimal or None) - the default value to use if none given (if not None)
Returns:
None

encodeUDecimal(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False, scale=None)

source code 
Build the encoder for signed decimal variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - decimal
  • numbits (int >= 1) - How many bits per unit datum (must be 1..32)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many decimals will there be? FIX: handle variable
  • unavailable (Decimal or None) - the default value to use if none given (if not None)
Returns:
None

encodeBinary(o, name, type, numbits, required=None, arraylen=1, unavailable=None, verbose=False, scale=None)

source code 
Build the encoder for binary variables. This is just a pass through. This is used for the ais binary message wrapper (e.g. msg 8). Do not use it within binary messages.
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - binary
  • numbits (int >= 1) - How many bits per unit datum (must be 1..1024 or so)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many decimals will there be? FIX: handle variable
  • unavailable (Decimal or None) - the default value to use if none given (if not None)
Returns:
None

decodeBool(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)

source code 
Build the decoder for boolean variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - uint, bool, etc.
  • startindex (int) - bit that begins the bool(s)
  • numbits (int = 1) - How many bits per unit datum (must be 1 for bools)
  • required (bool or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many bools will there be? FIX: handle variable
  • unavailable (bool or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

decodeUInt(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)

source code 
Build the decoder for unsigned integer variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - uint, etc.
  • startindex (int) - bit that begins the uint(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (int or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (int or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

decodeInt(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)

source code 
Build the decoder for unsigned integer variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - int
  • startindex (int) - bit that begins the int(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (int or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (int or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

decodeFloat(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)

source code 
Build the decoder for IEEE float variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - int
  • startindex (int) - bit that begins the int(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (float or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (float or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

decodeAisstr6(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False)

source code 
Build the decoder for aisstr6 variables. Generally arrays.
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - 'aisstr6'
  • startindex (int) - bit that begins the int(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (restricted str or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (restricted str or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

Bug: FIX: validate strings??

decodeDecimal(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False, scale=None)

source code 
Build the decoder for signed decimal variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - 'decimal'
  • startindex (int) - bit that begins the int(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (Decimal or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (Decimal or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

decodeUDecimal(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False, scale=None)

source code 
Build the decoder for unsigned decimal variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - 'udecimal'
  • startindex (int) - bit that begins the int(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (Decimal or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (Decimal or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

decodeBinary(o, name, type, startindex, numbits, required=None, arraylen=1, unavailable=None, bv='bv', dataDict='r', verbose=False, scale=None)

source code 
Build the decoder for unsigned decimal variables
Parameters:
  • o (file like obj) - where write the code
  • name (str) - field name
  • type (str) - 'udecimal'
  • startindex (int) - bit that begins the int(s)
  • numbits (int >= 1) - How many bits per unit datum
  • required (Decimal or None) - If not None, then the value must be set to this.
  • arraylen (int >= 1) - many ints will there be? FIX: handle variable
  • unavailable (Decimal or None) - the default value to use if none given (if not None)
  • bv (str) - BitVector containing the incoming data
  • dataDict (str) - dictionary in which to place the results
Returns: int
index one past the end of where this read

buildTestParamFunc(o, msgET, verbose=False)

source code 
Scrape the testvalues to make a basic param

Bug: FIX: make this create a dictionary that sits in the overall namespace and spit out deep copies?

buildUnitTest(o, msgET, verbose=False)

source code 

Write the unittests for a message

param o: open file where resulting code will be written param msgET: Element Tree starting at a message node

buildEncode(o, msgET, verbose=False)

source code 

Write the encoder/decoder for a message

http://jaynes.colorado.edu/PythonIdioms.html

param o: open file where resulting code will be written param msgET: Element Tree starting at a message node

buildDecodeParts(o, msgET, verbose=False, prefixName=True)

source code 

Write the decoder for a message

param o: open file where resulting code will be written type msgET: elementtree param prefixName: if True, put the name of the message on the functions. param msgET: Element Tree starting at a message node return: None

To Do:

  • FIX: check for a dac,fid, or efid. If exists, then this is an AIS Msg 8 payload
  • May want to take a dictionary of already decoded fields to speed things that need prior info for things like variable length arrays

buildDecode(o, msgET, verbose=False)

source code 

Write the decoder for a message

param o: open file where resulting code will be written type msgET: elementtree param msgET: Element Tree starting at a message node return: None

To Do: FIX: check for a dac,fid, or efid. If exists, then this is an AIS Msg 8 payload

buildMain(o)

source code 
None

Variables Details [hide private]

__date__

Date of last svn commit
Value:
'2006-09-24'                                                           
      

success

None
Value:
False