Exemplo n.º 1
0
def encode(params, validate=False):
    '''Create a b_staticdata

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 19 (field automatically set to "19")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
          - FIX... add the rest
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

    bvList = []
    bvList.append(binary.setBitVectorSize(BitVector(intVal=19), 6))
    if 'RepeatIndicator' in params:
        bvList.append(
            binary.setBitVectorSize(
                BitVector(intVal=params['RepeatIndicator']), 2))
    else:
        bvList.append(binary.setBitVectorSize(BitVector(intVal=0), 2))
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['UserID']), 30))

    assert False

    return binary.joinBV(bvList)
Exemplo n.º 2
0
def encode(params, validate=False):
	'''Create a b_staticdata

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 19 (field automatically set to "19")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
          - FIX... add the rest
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=19),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))

        assert False

	return binary.joinBV(bvList)
Exemplo n.º 3
0
def encode(params, validate=False):
	'''Create a asrm binary message payload to pack into an AIS Msg asrm.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 6 (field automatically set to "6")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI).  Also known as the Source ID
	  - SeqNum(uint): Sequence number as described in 5.3.1.  Assigned to each station
	  - DestinationID(uint): Unique ship identification number (MMSI).
	  - RetransmitFlag(bool): Should the message be restransmitted?
	  - Spare(uint): Must be 0 (field automatically set to "0")
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=6),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SeqNum']),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestinationID']),30))
	if params["RetransmitFlag"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),1))

	return binary.joinBV(bvList)
Exemplo n.º 4
0
def encode(params, validate=False):
	'''Create a bin_broadcast binary message payload to pack into an AIS Msg bin_broadcast.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 8 (field automatically set to "8")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Spare(uint): Reserved for definition by a regional authority. (field automatically set to "0")
	  - dac(uint): Appid designated area code (country)
	  - fi(uint): Appid functional identifier
	  - BinaryData(binary): Bits for a binary broadcast message
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=8),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['dac']),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['fi']),6))
	bvList.append(params['BinaryData'])

	return binary.joinBV(bvList)
Exemplo n.º 5
0
def waterlevelEncode(*aDict, **params):
	'''Serializer for the waterlevel binary message
	
	Keywords and types:

	  - dac:  uint
	  - unavail_uint:  uint
	  - uint:  uint
	FIX: generate CORRECT doctest string that does all the defaults

	The default message:

	>>> print waterlevelEncode()
	1011011101100

	@param aDict: for passing in a dictionary of keyword and values.
	@param params: keyword dictionary or if a dict is passed, it will use that dict
	@note: only use one of aDict or params
	'''

	if len(aDict) > 1:
		assert(False and 'Illegal call to with more than one param')
	if len(aDict) == 1:
		if not isinstance(dict,aDict):
			assert(False and 'a single parameter must be a dictionary of key values')
		if len(params)>0:
			assert(False and 'Must not specify both a lookup table and keyvalues')
		params=aDict

	bvList = []
	

	### FIELD: dac (type=uint)   REQUIRED CONSTANT FIELD
	bvList.append(binary.setBitVectorSize(BitVector(intVal=366)))

	### FIELD: unavail_uint (type=uint)
	if 'unavail_uint' in params: 		bvList.append(binary.setBitVectorSize(BitVector(intVal=param[unavail_uint]),2))
	else: bvList.append(binary.setBitVectorSize(BitVector(intVal=3),2))

	### FIELD: uint (type=uint)
	if 'uint' in params: 		bvList.append(binary.setBitVectorSize(BitVector(intVal=param[uint]),2))
	else: bvList.append(BitVector(size=2))
	return binary.joinBV(bvList)
Exemplo n.º 6
0
def encode(params, validate=False):
	'''Create a alltypesmsg binary message payload to pack into an AIS Msg alltypesmsg.

	Fields in params:
	  - dac(uint): Designated Area Code (field automatically set to "366")
	  - reqDecimal(decimal): required decimal value... FIX: scale or no? (field automatically set to "122")
	  - unavail_uint(uint): Unavailable unsigned integer
	  - anUInt(uint): NO unavailable unsigned integer
	  - anInt(int): NO unavailable signed integer
	  - aBool(bool): Simple bool
	  - aStr(aisstr6): An ais string of 5 characters
	  - anUDecimal(udecimal): An unsigned decimal.  Allow smaller numbers
	  - aDecimal(decimal): A decimal
	  - aFloat(float): An IEEE floating point number
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=366),16))
	bvList.append(binary.bvFromSignedInt(122,8))
	if 'unavail_uint' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['unavail_uint']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=3),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['anUInt']),2))
	bvList.append(binary.bvFromSignedInt(params['anInt'],3))
	if params["aBool"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	bvList.append(aisstring.encode(params['aStr'],30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['anUDecimal'])*Decimal('10')))),16))
	bvList.append(binary.bvFromSignedInt(int(Decimal(params['aDecimal'])*Decimal('10')),16))
	bvList.append(binary.float2bitvec(params['aFloat']))

	return binary.joinBV(bvList)
Exemplo n.º 7
0
def encode(params, validate=False):
	'''Create a gnss_correction binary message payload to pack into an AIS Msg gnss_correction.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 17 (field automatically set to "17")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Base station identification number (MMSI)
	  - Spare(uint): Reserved for definition by a regional authority. (field automatically set to "0")
	  - x(decimal): East West location
	  - y(decimal): North South location
	  - Spare2(uint): Reserved for definition by a regional authority. (field automatically set to "0")
	  - BinaryData(binary): GNSS Differential correction data
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=17),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	if 'x' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['x'])*Decimal('600')),18))
	else:
		bvList.append(binary.bvFromSignedInt(108600,18))
	if 'y' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['y'])*Decimal('600')),17))
	else:
		bvList.append(binary.bvFromSignedInt(54600,17))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),5))
	bvList.append(params['BinaryData'])

	return binary.joinBV(bvList)
Exemplo n.º 8
0
def unsigned_decimal_enc(val,bitSize):
    '''@rtype: BitVector'''
    # FIX: make sure there is no remainder
    bv = BitVector(intVal=int(val))
    return binary.setBitVectorSize(bv,bitSize)
Exemplo n.º 9
0
def encode(params, validate=False):
	'''Create a imo_fairway_closed binary message payload to pack into an AIS Msg imo_fairway_closed.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 8 (field automatically set to "8")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): MMSI number of transmitter broadcasting the message
	  - Spare(uint): Reserved for definition by a regional authority. (field automatically set to "0")
	  - dac(uint): Designated Area Code - part 1 of the IAI (field automatically set to "1")
	  - fid(uint): Functional Identifier - part 2 of the IAI (field automatically set to "11")
	  - reason(aisstr6): Reason for closing
	  - from(aisstr6): Location of closing from
	  - to(aisstr6): Location of closing To
	  - radius(uint): Extention of closed area
	  - unit(uint): Unit of extension value for range field
	  - closingday(uint): Closing from day
	  - closingmonth(uint): Closing from month
	  - fromhour(uint): From LT hour (appr)
	  - frommin(uint): From LT minute (appr)
	  - today(uint): To day
	  - tomonth(uint): To month
	  - tohour(uint): To LT hour (appr)
	  - tomin(uint): To LT minute (appr)
	  - spare2(uint): Padding out the slot (field automatically set to "0")
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=8),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=1),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=11),6))
	if 'reason' in params:
		bvList.append(aisstring.encode(params['reason'],120))
	else:
		bvList.append(aisstring.encode('@@@@@@@@@@@@@@@@@@@@',120))
	if 'from' in params:
		bvList.append(aisstring.encode(params['from'],120))
	else:
		bvList.append(aisstring.encode('@@@@@@@@@@@@@@@@@@@@',120))
	if 'to' in params:
		bvList.append(aisstring.encode(params['to'],120))
	else:
		bvList.append(aisstring.encode('@@@@@@@@@@@@@@@@@@@@',120))
	if 'radius' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['radius']),10))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=1001),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['unit']),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['closingday']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['closingmonth']),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['fromhour']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['frommin']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['today']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tomonth']),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tohour']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['tomin']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4))

	return binary.joinBV(bvList)
Exemplo n.º 10
0
def encode(params, validate=False):
	'''Create a whalenotice binary message payload to pack into an AIS Msg whalenotice.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 8 (field automatically set to "8")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Spare(uint): Reserved for definition by a regional authority. (field automatically set to "0")
	  - dac(uint): Designated Area Code - 366 for the United States (field automatically set to "366")
	  - fid(uint): Functional IDentifier - 63 for the Whale Notice (field automatically set to "63")
	  - day(uint): Time of most recent whale detection.  UTC day of the month 1..31
	  - hour(uint): Time of most recent whale detection.  UTC hours 0..23
	  - min(uint): Time of most recent whale detection.  UTC minutes
	  - stationid(uint): Identifier of the station that recorded the whale.  Usually a number.
	  - longitude(decimal): Center of the detection zone.  East West location
	  - latitude(decimal): Center of the detection zone.  North South location
	  - timetoexpire(uint): Minutes from the detection time until the notice expires
	  - radius(uint): Distance from center of detection zone (lat/lon above)
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=8),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=366),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=63),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['day']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['hour']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['min']),6))
	if 'stationid' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['stationid']),8))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),8))
	if 'longitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['longitude'])*Decimal('600000')),28))
	else:
		bvList.append(binary.bvFromSignedInt(108600000,28))
	if 'latitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['latitude'])*Decimal('600000')),27))
	else:
		bvList.append(binary.bvFromSignedInt(54600000,27))
	if 'timetoexpire' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['timetoexpire']),16))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),16))
	if 'radius' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['radius']),16))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=65535),16))

	return binary.joinBV(bvList)
Exemplo n.º 11
0
def encode(params, validate=False):
	'''Create a interrogation binary message payload to pack into an AIS Msg interrogation.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 15 (field automatically set to "15")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): MMSI number of interrogating station
	  - DestID(uint): MMSI number of interrogated station
	  - MessageID1(uint): requested message type from interrogated station
	  - SlotOffset(uint): requested message type from interrogated station
	  - Spare(uint): Not used.  Should be set to zero. Researved for future use. (field automatically set to "0")
	  - MessageID12(uint): requested message type from interrogated station
	  - SlotOffset12(uint): requested message type from interrogated station
	  - Spare2(uint): Not used.  Should be set to zero. Researved for future use. (field automatically set to "0")
	  - DestID2(uint): MMSI number of interrogated station
	  - MessageID2(uint): requested message type from interrogated station
	  - SlotOffset2(uint): requested message type from interrogated station
	  - Spare3(uint): Not used.  Should be set to zero. Researved for future use. (field automatically set to "0")
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=15),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['MessageID1']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SlotOffset']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['MessageID12']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SlotOffset12']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestID2']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['MessageID2']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SlotOffset2']),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))

	return binary.joinBV(bvList)
Exemplo n.º 12
0
def encode(params, validate=False):
	'''Create a ChanMngmt binary message payload to pack into an AIS Msg ChanMngmt.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 23 (field automatically set to "23")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Spare(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - corner1_lon(decimal): north-east corner of area for assignment  longitude of corner
	  - corner1_lat(decimal): north-east corner of area for assignment  latitude of corner
	  - corner2_lon(decimal): south-west corner of area for assignment  longitude of corner
	  - corner2_lat(decimal): south-west corner of area for assignment  latitude of corner
	  - StationType(uint): TODO
	  - shipandcargo(uint): what
	  - Spare2(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - TxRxMode(uint): TODO
	  - ReportingInterval(uint): Command the stations to report as given in table 17
	  - QuietTime(uint): How long to be quiet
	  - Spare3(uint): Not used.  Should be set to zero. (field automatically set to "0")
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=23),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	if 'corner1_lon' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner1_lon'])*Decimal('600')),18))
	else:
		bvList.append(binary.bvFromSignedInt(108600,18))
	if 'corner1_lat' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner1_lat'])*Decimal('600')),17))
	else:
		bvList.append(binary.bvFromSignedInt(108600,17))
	if 'corner2_lon' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner2_lon'])*Decimal('600')),18))
	else:
		bvList.append(binary.bvFromSignedInt(108600,18))
	if 'corner2_lat' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner2_lat'])*Decimal('600')),17))
	else:
		bvList.append(binary.bvFromSignedInt(108600,17))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['StationType']),4))
	if 'shipandcargo' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['shipandcargo']),8))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),8))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),22))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TxRxMode']),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['ReportingInterval']),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['QuietTime']),22))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),6))

	return binary.joinBV(bvList)
Exemplo n.º 13
0
def encode(params, validate=False):
	'''Create a positionb binary message payload to pack into an AIS Msg positionb.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 18 (field automatically set to "18")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Reserved1(uint): Reseverd for definition by a compentent regional or local authority.  Should be set to zero. (field automatically set to "0")
	  - SOG(udecimal): Speed over ground
	  - PositionAccuracy(uint): Accuracy of positioning fixes
	  - longitude(decimal): Location of the vessel  East West location
	  - 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
	  - Spare(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - cs_unit(bool): Does this unit do Carrier Sense?
	  - display_flag(bool): Does this class B unit have an integrated display?
	  - dsc_flag(bool): Does it have dedicated or time-shared DSC radio function?
	  - band_flag(bool): How flexible is the freq handling of the unit?
	  - msg22_flag(bool): Can the unit handle msg 22?
	  - mode_flag(bool): Assigned mode wrt to VDL slots
	  - RAIM(bool): Receiver autonomous integrity monitoring flag
	  - CommStateSelector(uint): SOTDMA or ITDMA
	  - CommState(uint): Not decoded by this software yet
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=18),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),8))
	if 'SOG' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['SOG'])*Decimal('10')))),10))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int(1023)),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['PositionAccuracy']),1))
	if 'longitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['longitude'])*Decimal('600000')),28))
	else:
		bvList.append(binary.bvFromSignedInt(108600000,28))
	if 'latitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['latitude'])*Decimal('600000')),27))
	else:
		bvList.append(binary.bvFromSignedInt(54600000,27))
	if 'COG' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['COG'])*Decimal('10')))),12))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int(3600)),12))
	if 'TrueHeading' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TrueHeading']),9))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=511),9))
	if 'TimeStamp' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TimeStamp']),6))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	if params["cs_unit"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	if params["display_flag"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	if params["dsc_flag"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	if params["band_flag"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	if params["msg22_flag"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	if params["mode_flag"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	if params["RAIM"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['CommStateSelector']),1))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['CommState']),19))

	return binary.joinBV(bvList)
Exemplo n.º 14
0
 def AddUInt(self, val, num_bits):
   """Add an unsigned integer."""
   bits = binary.setBitVectorSize(BitVector(intVal=val), num_bits)
   assert num_bits == len(bits)
   self.bits_expected += num_bits
   self.bv_list.append(bits)
Exemplo n.º 15
0
  def get_bits(self, include_bin_hdr=False, include_dac_fi=True):
    bv_list = []
    if include_bin_hdr:
      # Messages ID
      bv_list.append(binary.setBitVectorSize(BitVector(intVal=8), 6))
      # Repeat Indicator
      bv_list.append(binary.setBitVectorSize(BitVector(intVal=0), 2))
      bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.mmsi), 30))

    if include_bin_hdr or include_dac_fi:
      bv_list.append(BitVector(bitstring='00'))
      bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.dac), 10))
      bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.fi), 6))

    version = 1
    bv_list.append(binary.setBitVectorSize(BitVector(intVal=version), 6))
    bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.link_id), 10))
    bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.area_type), 7))

    bv_list.append(
        binary.setBitVectorSize(BitVector(intVal=self.when.month), 4))
    bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.when.day), 5))
    bv_list.append(binary.setBitVectorSize(BitVector(intVal=self.when.hour), 5))
    bv_list.append(
        binary.setBitVectorSize(BitVector(intVal=self.when.minute), 6))
    bv_list.append(
        binary.setBitVectorSize(BitVector(intVal=self.duration_min), 18))
    bv_list.append(binary.setBitVectorSize(BitVector(intVal=0), 3))  # spare

    for i, area in enumerate(self.areas):
      bv_list.append(area.get_bits())
    bv = binary.joinBV(bv_list)
    if len(bv) > 984:
      raise AisPackingException(
          'Message to large:  %d > %d' % (len(bv), self.max_bits))
    return bv
Exemplo n.º 16
0
    '6': 54,
    '7': 55,
    '8': 56,
    '9': 57,
    ':': 58,
    ';': 59,
    '<': 60,
    '=': 61,
    '>': 62,
    '?': 63
}
'''Fast lookup for the AIS int code for a character '''
# The above illustrates the inline ways of documenting module variables

characterBits = {}
characterBits['@'] = binary.setBitVectorSize(BitVector(intVal=0), 6)
characterBits['A'] = binary.setBitVectorSize(BitVector(intVal=1), 6)
characterBits['B'] = binary.setBitVectorSize(BitVector(intVal=2), 6)
characterBits['C'] = binary.setBitVectorSize(BitVector(intVal=3), 6)
characterBits['D'] = binary.setBitVectorSize(BitVector(intVal=4), 6)
characterBits['E'] = binary.setBitVectorSize(BitVector(intVal=5), 6)
characterBits['F'] = binary.setBitVectorSize(BitVector(intVal=6), 6)
characterBits['G'] = binary.setBitVectorSize(BitVector(intVal=7), 6)
characterBits['H'] = binary.setBitVectorSize(BitVector(intVal=8), 6)
characterBits['I'] = binary.setBitVectorSize(BitVector(intVal=9), 6)
characterBits['J'] = binary.setBitVectorSize(BitVector(intVal=10), 6)
characterBits['K'] = binary.setBitVectorSize(BitVector(intVal=11), 6)
characterBits['L'] = binary.setBitVectorSize(BitVector(intVal=12), 6)
characterBits['M'] = binary.setBitVectorSize(BitVector(intVal=13), 6)
characterBits['N'] = binary.setBitVectorSize(BitVector(intVal=14), 6)
characterBits['O'] = binary.setBitVectorSize(BitVector(intVal=15), 6)
Exemplo n.º 17
0
def encode(params, validate=False):
    '''Create a binack binary message payload to pack into an AIS Msg binack.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 7 (field automatically set to "7")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI).  Also known as the Source ID
	  - Spare(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - DestID1(uint): MMSI destication to ACK
	  - SeqID1(uint): Sequence ID of the message to be acknowledged
	  - DestID2(uint): MMSI destication to ACK
	  - SeqID2(uint): Sequence ID of the message to be acknowledged
	  - DestID3(uint): MMSI destication to ACK
	  - SeqID3(uint): Sequence ID of the message to be acknowledged
	  - DestID4(uint): MMSI destication to ACK
	  - SeqID4(uint): Sequence ID of the message to be acknowledged
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

    bvList = []
    bvList.append(binary.setBitVectorSize(BitVector(intVal=7), 6))
    if 'RepeatIndicator' in params:
        bvList.append(
            binary.setBitVectorSize(
                BitVector(intVal=params['RepeatIndicator']), 2))
    else:
        bvList.append(binary.setBitVectorSize(BitVector(intVal=0), 2))
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['UserID']), 30))
    bvList.append(binary.setBitVectorSize(BitVector(intVal=0), 2))

    # Can have 1 to 4 acks in a packet

    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['DestID1']), 30))
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['SeqID1']), 2))

    if 'DestID2' not in params: return binary.joinBV(bvList)
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['DestID2']), 30))
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['SeqID2']), 2))

    if 'DestID3' not in params: return binary.joinBV(bvList)
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['DestID3']), 30))
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['SeqID3']), 2))

    if 'DestID4' not in params: return binary.joinBV(bvList)
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['DestID4']), 30))
    bvList.append(
        binary.setBitVectorSize(BitVector(intVal=params['SeqID4']), 2))

    return binary.joinBV(bvList)
Exemplo n.º 18
0
def encode(params, validate=False):
	'''Create a binack binary message payload to pack into an AIS Msg binack.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 7 (field automatically set to "7")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI).  Also known as the Source ID
	  - Spare(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - DestID1(uint): MMSI destication to ACK
	  - SeqID1(uint): Sequence ID of the message to be acknowledged
	  - DestID2(uint): MMSI destication to ACK
	  - SeqID2(uint): Sequence ID of the message to be acknowledged
	  - DestID3(uint): MMSI destication to ACK
	  - SeqID3(uint): Sequence ID of the message to be acknowledged
	  - DestID4(uint): MMSI destication to ACK
	  - SeqID4(uint): Sequence ID of the message to be acknowledged
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=7),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))

        # Can have 1 to 4 acks in a packet

	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestID1']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SeqID1']),2))

        if 'DestID2' not in params: return binary.joinBV(bvList)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestID2']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SeqID2']),2))

        if 'DestID3' not in params: return binary.joinBV(bvList)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestID3']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SeqID3']),2))

        if 'DestID4' not in params: return binary.joinBV(bvList)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['DestID4']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['SeqID4']),2))

	return binary.joinBV(bvList)
Exemplo n.º 19
0
def unsigned_int_enc(val,bitSize):
    '''@rtype: BitVector'''
    bv = BitVector(intVal=val)
    return binary.setBitVectorSize(bv,bitSize)
Exemplo n.º 20
0
def float_enc(val,bitSize):
    '''@rtype: BitVector'''
    bv = binary.bvFromSignedInt(int(val),bitSize)
    return binary.setBitVectorSize(bv,bitSize)
Exemplo n.º 21
0
def encode(params, validate=False):
	'''Create a ChanMngmt binary message payload to pack into an AIS Msg ChanMngmt.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 22 (field automatically set to "22")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Spare(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - ChanA(uint): Channel number from ITU-R M.1084 Annex 4
	  - ChanB(uint): Channel number from ITU-R M.1084 Annex 4
	  - TxRxMode(uint): FIX: find the description
	  - power(uint): FIX: put in a description
	  - corner1_lon(decimal): north-east corner of area for assignment  longitude of corner
	  - corner1_lat(decimal): north-east corner of area for assignment  latitude of corner
	  - corner2_lon(decimal): south-west corner of area for assignment  longitude of corner
	  - corner2_lat(decimal): south-west corner of area for assignment  latitude of corner
	  - IndicatorType(uint): FIX: put in a description
	  - ChanABandwidth(uint): FIX: put in a description
	  - ChanBBandwidth(uint): FIX: put in a description
	  - TransZoneSize(uint): FIX: put in a description
	  - Spare2(uint): Not used.  Should be set to zero. (field automatically set to "0")
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=22),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['ChanA']),12))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['ChanB']),12))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TxRxMode']),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['power']),1))
	if 'corner1_lon' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner1_lon'])*Decimal('600')),18))
	else:
		bvList.append(binary.bvFromSignedInt(108600,18))
	if 'corner1_lat' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner1_lat'])*Decimal('600')),17))
	else:
		bvList.append(binary.bvFromSignedInt(108600,17))
	if 'corner2_lon' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner2_lon'])*Decimal('600')),18))
	else:
		bvList.append(binary.bvFromSignedInt(108600,18))
	if 'corner2_lat' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['corner2_lat'])*Decimal('600')),17))
	else:
		bvList.append(binary.bvFromSignedInt(108600,17))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['IndicatorType']),1))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['ChanABandwidth']),1))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['ChanBBandwidth']),1))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TransZoneSize']),3))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),23))

	return binary.joinBV(bvList)
Exemplo n.º 22
0
    "7": 55,
    "8": 56,
    "9": 57,
    ":": 58,
    ";": 59,
    "<": 60,
    "=": 61,
    ">": 62,
    "?": 63,
}
"""Fast lookup for the AIS int code for a character """
# The above illustrates the inline ways of documenting module variables


characterBits = {}
characterBits["@"] = binary.setBitVectorSize(BitVector(intVal=0), 6)
characterBits["A"] = binary.setBitVectorSize(BitVector(intVal=1), 6)
characterBits["B"] = binary.setBitVectorSize(BitVector(intVal=2), 6)
characterBits["C"] = binary.setBitVectorSize(BitVector(intVal=3), 6)
characterBits["D"] = binary.setBitVectorSize(BitVector(intVal=4), 6)
characterBits["E"] = binary.setBitVectorSize(BitVector(intVal=5), 6)
characterBits["F"] = binary.setBitVectorSize(BitVector(intVal=6), 6)
characterBits["G"] = binary.setBitVectorSize(BitVector(intVal=7), 6)
characterBits["H"] = binary.setBitVectorSize(BitVector(intVal=8), 6)
characterBits["I"] = binary.setBitVectorSize(BitVector(intVal=9), 6)
characterBits["J"] = binary.setBitVectorSize(BitVector(intVal=10), 6)
characterBits["K"] = binary.setBitVectorSize(BitVector(intVal=11), 6)
characterBits["L"] = binary.setBitVectorSize(BitVector(intVal=12), 6)
characterBits["M"] = binary.setBitVectorSize(BitVector(intVal=13), 6)
characterBits["N"] = binary.setBitVectorSize(BitVector(intVal=14), 6)
characterBits["O"] = binary.setBitVectorSize(BitVector(intVal=15), 6)
Exemplo n.º 23
0
def encode(params, validate=False):
	'''Create a bsreport binary message payload to pack into an AIS Msg bsreport.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 4 (field automatically set to "11")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Time_year(uint): Current time stamp  year 1-9999
	  - Time_month(uint): Current time stamp  month 1..12
	  - Time_day(uint): Current time stamp  day of the month 1..31
	  - Time_hour(uint): Current time stamp  UTC hours 0..23
	  - Time_min(uint): Current time stamp  minutes
	  - Time_sec(uint): Current time stamp  seconds
	  - PositionAccuracy(uint): Accuracy of positioning fixes
	  - Position_longitude(decimal): Location of base station  East West location
	  - Position_latitude(decimal): Location of base station  North South location
	  - fixtype(uint): Method used for positioning
	  - Spare(uint): Not used.  Should be set to zero. (field automatically set to "0")
	  - RAIM(bool): Receiver autonomous integrity monitoring flag
	  - state_syncstate(uint): Communications State - SOTDMA  Sycronization state
	  - state_slottimeout(uint): Communications State - SOTDMA  Frames remaining until a new slot is selected
	  - state_slotoffset(uint): Communications State - SOTDMA  In what slot will the next transmission occur. BROKEN
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=11),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	if 'Time_year' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['Time_year']),14))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),14))
	if 'Time_month' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['Time_month']),4))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4))
	if 'Time_day' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['Time_day']),5))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),5))
	if 'Time_hour' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['Time_hour']),5))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=24),5))
	if 'Time_min' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['Time_min']),6))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
	if 'Time_sec' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['Time_sec']),6))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['PositionAccuracy']),1))
	if 'Position_longitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['Position_longitude'])*Decimal('600000')),28))
	else:
		bvList.append(binary.bvFromSignedInt(108600000,28))
	if 'Position_latitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['Position_latitude'])*Decimal('600000')),27))
	else:
		bvList.append(binary.bvFromSignedInt(54600000,27))
	if 'fixtype' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['fixtype']),4))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),10))
	if params["RAIM"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['state_syncstate']),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['state_slottimeout']),3))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['state_slotoffset']),14))

	return binary.joinBV(bvList)
Exemplo n.º 24
0
def encode(params, validate=False):
	'''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
	  - longitude(decimal): Location of the vessel  East West location
	  - 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
	  - state_syncstate(uint): Communications State - SOTDMA  Sycronization state
	  - state_slottimeout(uint): Communications State - SOTDMA  Frames remaining until a new slot is selected
	  - state_slotoffset(uint): Communications State - SOTDMA  In what slot will the next transmission occur. BROKEN
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=1),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	if 'NavigationStatus' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['NavigationStatus']),4))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=15),4))
	if 'ROT' in params:
		bvList.append(binary.bvFromSignedInt(params['ROT'],8))
	else:
		bvList.append(binary.bvFromSignedInt(-128,8))
	if 'SOG' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['SOG'])*Decimal('10')))),10))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int(1023)),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['PositionAccuracy']),1))
	if 'longitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['longitude'])*Decimal('600000')),28))
	else:
		bvList.append(binary.bvFromSignedInt(108600000,28))
	if 'latitude' in params:
		bvList.append(binary.bvFromSignedInt(int(Decimal(params['latitude'])*Decimal('600000')),27))
	else:
		bvList.append(binary.bvFromSignedInt(54600000,27))
	if 'COG' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int((Decimal(params['COG'])*Decimal('10')))),12))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=int(3600)),12))
	if 'TrueHeading' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TrueHeading']),9))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=511),9))
	if 'TimeStamp' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['TimeStamp']),6))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=60),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),1))
	if params["RAIM"]: bvList.append(TrueBV)
	else: bvList.append(FalseBV)
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['state_syncstate']),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['state_slottimeout']),3))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['state_slotoffset']),14))

	return binary.joinBV(bvList)
Exemplo n.º 25
0
# TODO(schwehr): Remove duplicate character entry without breaking things.
# pylint: disable=duplicate-key
character_dict = {
    '@': 0, 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7,
    'H': 8, 'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13, 'N': 14, 'O': 15,
    'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22,
    'W': 23, 'X': 24, 'Y': 25, 'Z': 26, '[': 27, '\\': 28, ']': 29,
    '^': 30, '-': 31, ' ': 32, '!': 33, '"': 34, '#': 35, '$': 36,
    '%': 37, '&': 38, '`': 39, '(': 40, ')': 41, '*': 42, '+': 43,
    ',': 44, '-': 45, '.': 46, '/': 47, '0': 48, '1': 49, '2': 50,
    '3': 51, '4': 52, '5': 53, '6': 54, '7': 55, '8': 56, '9': 57,
    ':': 58, ';': 59, '<': 60, '=': 61, '>': 62, '?': 63
}

character_bits = {}
character_bits['@'] = binary.setBitVectorSize(BitVector(intVal=0), 6)
character_bits['A'] = binary.setBitVectorSize(BitVector(intVal=1), 6)
character_bits['B'] = binary.setBitVectorSize(BitVector(intVal=2), 6)
character_bits['C'] = binary.setBitVectorSize(BitVector(intVal=3), 6)
character_bits['D'] = binary.setBitVectorSize(BitVector(intVal=4), 6)
character_bits['E'] = binary.setBitVectorSize(BitVector(intVal=5), 6)
character_bits['F'] = binary.setBitVectorSize(BitVector(intVal=6), 6)
character_bits['G'] = binary.setBitVectorSize(BitVector(intVal=7), 6)
character_bits['H'] = binary.setBitVectorSize(BitVector(intVal=8), 6)
character_bits['I'] = binary.setBitVectorSize(BitVector(intVal=9), 6)
character_bits['J'] = binary.setBitVectorSize(BitVector(intVal=10), 6)
character_bits['K'] = binary.setBitVectorSize(BitVector(intVal=11), 6)
character_bits['L'] = binary.setBitVectorSize(BitVector(intVal=12), 6)
character_bits['M'] = binary.setBitVectorSize(BitVector(intVal=13), 6)
character_bits['N'] = binary.setBitVectorSize(BitVector(intVal=14), 6)
character_bits['O'] = binary.setBitVectorSize(BitVector(intVal=15), 6)
Exemplo n.º 26
0
def encode(params, validate=False):
	'''Create a waterlevel binary message payload to pack into an AIS Msg waterlevel.

	Fields in params:
	  - MessageID(uint): AIS message number.  Must be 8 (field automatically set to "8")
	  - RepeatIndicator(uint): Indicated how many times a message has been repeated
	  - UserID(uint): Unique ship identification number (MMSI)
	  - Spare(uint): Reserved for definition by a regional authority. (field automatically set to "0")
	  - dac(uint): Designated Area Code (field automatically set to "366")
	  - fid(uint): Functional Identifier (field automatically set to "63")
	  - month(uint): Time the measurement represents  month 1..12
	  - day(uint): Time the measurement represents  day of the month 1..31
	  - hour(uint): Time the measurement represents  UTC hours 0..23
	  - min(uint): Time the measurement represents  minutes
	  - stationid(aisstr6): Character identifier of the station.  Usually a number.
	  - waterlevel(int): Water level in centimeters
	  - datum(uint): What reference datum applies to the value
	  - sigma(uint): Standard deviation of 1 second samples used to compute the water level height.  FIX: is this the correct description of sigma?
	  - source(uint): How the water level was derived
	@param params: Dictionary of field names/values.  Throws a ValueError exception if required is missing
	@param validate: Set to true to cause checking to occur.  Runs slower.  FIX: not implemented.
	@rtype: BitVector
	@return: 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.
	'''

	bvList = []
	bvList.append(binary.setBitVectorSize(BitVector(intVal=8),6))
	if 'RepeatIndicator' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['RepeatIndicator']),2))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['UserID']),30))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=0),2))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=366),10))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=63),6))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['month']),4))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['day']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['hour']),5))
	bvList.append(binary.setBitVectorSize(BitVector(intVal=params['min']),6))
	if 'stationid' in params:
		bvList.append(aisstring.encode(params['stationid'],42))
	else:
		bvList.append(aisstring.encode('@@@@@@@',42))
	if 'waterlevel' in params:
		bvList.append(binary.bvFromSignedInt(params['waterlevel'],16))
	else:
		bvList.append(binary.bvFromSignedInt(-32768,16))
	if 'datum' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['datum']),5))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=31),5))
	if 'sigma' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['sigma']),7))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=127),7))
	if 'source' in params:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=params['source']),3))
	else:
		bvList.append(binary.setBitVectorSize(BitVector(intVal=0),3))

	return binary.joinBV(bvList)