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: add a link to generated doc string to bring up the html for the pretty version

Bug: NOT complete

Functions [hide private]
  hasSubtag(et, subtag)
  writeBeginning(o)
Write the doc string header for the message file
  generatePython(infile, outfile)
  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
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
  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
  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

Function Details [hide private]

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

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) - uint, 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

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

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

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

buildMain(o)

source code 
None

Variables Details [hide private]

__date__

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