def decode(bv, validate=False): '''Unpack a imo_fairway_closed message. 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") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['MessageID'] = 8 r['RepeatIndicator'] = int(bv[6:8]) r['UserID'] = int(bv[8:38]) r['Spare'] = 0 r['dac'] = 1 r['fid'] = 11 r['reason'] = aisstring.decode(bv[56:176]) r['from'] = aisstring.decode(bv[176:296]) r['to'] = aisstring.decode(bv[296:416]) r['radius'] = int(bv[416:426]) r['unit'] = int(bv[426:428]) r['closingday'] = int(bv[428:433]) r['closingmonth'] = int(bv[433:437]) r['fromhour'] = int(bv[437:442]) r['frommin'] = int(bv[442:448]) r['today'] = int(bv[448:453]) r['tomonth'] = int(bv[453:457]) r['tohour'] = int(bv[457:462]) r['tomin'] = int(bv[462:468]) r['spare2'] = 0 return r
def decode(bv, validate=False): '''Unpack a imo_fairway_closed message. 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") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['MessageID']=8 r['RepeatIndicator']=int(bv[6:8]) r['UserID']=int(bv[8:38]) r['Spare']=0 r['dac']=1 r['fid']=11 r['reason']=aisstring.decode(bv[56:176]) r['from']=aisstring.decode(bv[176:296]) r['to']=aisstring.decode(bv[296:416]) r['radius']=int(bv[416:426]) r['unit']=int(bv[426:428]) r['closingday']=int(bv[428:433]) r['closingmonth']=int(bv[433:437]) r['fromhour']=int(bv[437:442]) r['frommin']=int(bv[442:448]) r['today']=int(bv[448:453]) r['tomonth']=int(bv[453:457]) r['tohour']=int(bv[457:462]) r['tomin']=int(bv[462:468]) r['spare2']=0 return r
def decode(bv, validate=False): '''Unpack a sls_wind message. Fields in params: - time_month(uint): Time tag of measurement month 1..12 - time_day(uint): Time tag of measurement day of the month 1..31 - time_hour(uint): Time tag of measurement UTC hours 0..23 - time_min(uint): Time tag of measurement minutes - stationid(aisstr6): Character identifier of the station - pos_longitude(decimal): Location of measurement East West location - pos_latitude(decimal): Location of measurement North South location - flow(uint): Water flow - reserved(uint): Reserved bits for future use (field automatically set to "0") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['time_month']=int(bv[0:4]) r['time_day']=int(bv[4:9]) r['time_hour']=int(bv[9:14]) r['time_min']=int(bv[14:20]) r['stationid']=aisstring.decode(bv[20:62]) r['pos_longitude']=Decimal(binary.signedIntFromBV(bv[62:87]))/Decimal('60000') r['pos_latitude']=Decimal(binary.signedIntFromBV(bv[87:111]))/Decimal('60000') r['flow']=int(bv[111:121]) r['reserved']=0 return r
def decode(bv, validate=False): '''Unpack a sls_lockschedule message. Fields in params: - vessel(aisstr6): Vessel Name - direction(bool): Up bound/Down bound - ETA_month(uint): Estimated time of arrival month 1..12 - ETA_day(uint): Estimated time of arrival day of the month 1..31 - ETA_hour(uint): Estimated time of arrival UTC hours 0..23 - ETA_min(uint): Estimated time of arrival minutes - reserved(uint): Reserved bits for future use (field automatically set to "0") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['vessel'] = aisstring.decode(bv[0:90]) r['direction'] = bool(int(bv[90:91])) r['ETA_month'] = int(bv[91:95]) r['ETA_day'] = int(bv[95:100]) r['ETA_hour'] = int(bv[100:105]) r['ETA_min'] = int(bv[105:111]) r['reserved'] = 0 return r
def decode(bv, validate=False): '''Unpack a sls_lockorder message. Fields in params: - vessel(aisstr6): Vessel Name - direction(bool): Up bound/Down bound - ETA_month(uint): Estimated time of arrival month 1..12 - ETA_day(uint): Estimated time of arrival day of the month 1..31 - ETA_hour(uint): Estimated time of arrival UTC hours 0..23 - ETA_min(uint): Estimated time of arrival minutes - reserved(uint): Reserved bits for future use (field automatically set to "0") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['vessel']=aisstring.decode(bv[0:90]) r['direction']=bool(int(bv[90:91])) r['ETA_month']=int(bv[91:95]) r['ETA_day']=int(bv[95:100]) r['ETA_hour']=int(bv[100:105]) r['ETA_min']=int(bv[105:111]) r['reserved']=0 return r
def decode(bv, validate=False): '''Unpack 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 of the fields @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' if len(bv) not in (160,162,168): # 162 is 160 with 2 bits padding print 'warning... len is not 160 or 168. Found',len(bv) r = {} r['MessageID']=24 r['RepeatIndicator']=int(bv[6:8]) r['UserID']=int(bv[8:38]) r['partnum']=int(bv[38:40]) if 0 == r['partnum']: # Part A message r['name']=aisstring.decode(bv[40:160]).rstrip(' @') elif 1 == r['partnum']: # Part B message r['shipandcargo']=int(bv[40:48]) r['vendorid']=aisstring.decode(bv[48:90]).rstrip(' @') r['callsign']=aisstring.decode(bv[90:132]).rstrip(' @') r['dimA']=int(bv[132:141]) r['dimB']=int(bv[141:150]) r['dimC']=int(bv[150:156]) r['dimD']=int(bv[156:162]) r['mothership']=int(bv[132:162]) r['spare']=int(bv[162:168]) elif 2 == r['partnum']: # Part C message - no such thing logging.info('Msg 24 with invalid part C.') r['bits'] = str(bv[40:]) elif 3 == r['partnum']: # Part D message - no such thing logging.info('Msg 24 with invalid part D.') r['bits'] = str(bv[40:]) return r
def decode(bv, validate=False): '''Unpack 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 of the fields @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' if len(bv) not in (160, 162, 168): # 162 is 160 with 2 bits padding print 'warning... len is not 160 or 168. Found', len(bv) r = {} r['MessageID'] = 24 r['RepeatIndicator'] = int(bv[6:8]) r['UserID'] = int(bv[8:38]) r['partnum'] = int(bv[38:40]) if 0 == r['partnum']: # Part A message r['name'] = aisstring.decode(bv[40:160]).rstrip(' @') elif 1 == r['partnum']: # Part B message r['shipandcargo'] = int(bv[40:48]) r['vendorid'] = aisstring.decode(bv[48:90]).rstrip(' @') r['callsign'] = aisstring.decode(bv[90:132]).rstrip(' @') r['dimA'] = int(bv[132:141]) r['dimB'] = int(bv[141:150]) r['dimC'] = int(bv[150:156]) r['dimD'] = int(bv[156:162]) r['mothership'] = int(bv[132:162]) r['spare'] = int(bv[162:168]) elif 2 == r['partnum']: # Part C message - no such thing logging.info('Msg 24 with invalid part C.') r['bits'] = str(bv[40:]) elif 3 == r['partnum']: # Part D message - no such thing logging.info('Msg 24 with invalid part D.') r['bits'] = str(bv[40:]) return r
def decode(bv, validate=False): '''Unpack a whalenotice message. 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") - efid(uint): Extended Functional IDentifier. 1 for the Whale Notice (dac+fid+efid defines the exact message type) (field automatically set to "1") - month(uint): Time of most recent whale detection. UTC month 1..12 - 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 - sec(uint): Time of most recent whale detection. UTC seconds - stationid(aisstr6): Identifier of the station that detected the whale. (e.g. which buoy) - longitude(decimal): Center of the detection zone. East West location - latitude(decimal): Center of the detection zone. North South location - timetoexpire(uint): Seconds from the detection time until the notice expires - radius(uint): Distance from center of detection zone (lat/lon above) @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['MessageID'] = 8 r['RepeatIndicator'] = int(bv[6:8]) r['UserID'] = int(bv[8:38]) r['Spare'] = 0 r['dac'] = 366 r['fid'] = 63 r['efid'] = 1 r['month'] = int(bv[68:72]) r['day'] = int(bv[72:77]) r['hour'] = int(bv[77:82]) r['min'] = int(bv[82:88]) r['sec'] = int(bv[88:94]) r['stationid'] = aisstring.decode(bv[94:136]) r['longitude'] = Decimal(binary.signedIntFromBV( bv[136:164])) / Decimal('600000') r['latitude'] = Decimal(binary.signedIntFromBV( bv[164:191])) / Decimal('600000') r['timetoexpire'] = int(bv[191:207]) r['radius'] = int(bv[207:223]) return r
def decode(bv, validate=False): '''Unpack a sls_weatherreport message. Fields in params: - time_month(uint): Time tag of measurement month 1..12 - time_day(uint): Time tag of measurement day of the month 1..31 - time_hour(uint): Time tag of measurement UTC hours 0..23 - time_min(uint): Time tag of measurement minutes - stationid(aisstr6): Character identifier of the station - pos_longitude(decimal): Location of measurement East West location - pos_latitude(decimal): Location of measurement North South location - speed(udecimal): Average wind speed - gust(udecimal): Wind gust - direction(uint): Wind direction - atmpressure(udecimal): Atmospheric pressure - airtemp(decimal): Air temperature - dewpoint(decimal): Dew Point - visibility(udecimal): Visibility - watertemp(decimal): Water Temperature - reserved(uint): Reserved bits for future use (field automatically set to "0") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['time_month'] = int(bv[0:4]) r['time_day'] = int(bv[4:9]) r['time_hour'] = int(bv[9:14]) r['time_min'] = int(bv[14:20]) r['stationid'] = aisstring.decode(bv[20:62]) r['pos_longitude'] = Decimal(binary.signedIntFromBV( bv[62:87])) / Decimal('60000') r['pos_latitude'] = Decimal(binary.signedIntFromBV( bv[87:111])) / Decimal('60000') r['speed'] = Decimal(int(bv[111:121])) / Decimal('10') r['gust'] = Decimal(int(bv[121:131])) / Decimal('10') r['direction'] = int(bv[131:140]) r['atmpressure'] = Decimal(int(bv[140:154])) / Decimal('10') r['airtemp'] = Decimal(binary.signedIntFromBV(bv[154:164])) / Decimal('10') r['dewpoint'] = Decimal(binary.signedIntFromBV( bv[164:174])) / Decimal('10') r['visibility'] = Decimal(int(bv[174:182])) / Decimal('10') r['watertemp'] = Decimal(binary.signedIntFromBV( bv[182:192])) / Decimal('10') r['reserved'] = 0 return r
def decode(bv, validate=False): '''Unpack a whalenotice message. 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") - efid(uint): Extended Functional IDentifier. 1 for the Whale Notice (dac+fid+efid defines the exact message type) (field automatically set to "1") - month(uint): Time of most recent whale detection. UTC month 1..12 - 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 - sec(uint): Time of most recent whale detection. UTC seconds - stationid(aisstr6): Identifier of the station that detected the whale. (e.g. which buoy) - longitude(decimal): Center of the detection zone. East West location - latitude(decimal): Center of the detection zone. North South location - timetoexpire(uint): Seconds from the detection time until the notice expires - radius(uint): Distance from center of detection zone (lat/lon above) @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['MessageID']=8 r['RepeatIndicator']=int(bv[6:8]) r['UserID']=int(bv[8:38]) r['Spare']=0 r['dac']=366 r['fid']=63 r['efid']=1 r['month']=int(bv[68:72]) r['day']=int(bv[72:77]) r['hour']=int(bv[77:82]) r['min']=int(bv[82:88]) r['sec']=int(bv[88:94]) r['stationid']=aisstring.decode(bv[94:136]) r['longitude']=Decimal(binary.signedIntFromBV(bv[136:164]))/Decimal('600000') r['latitude']=Decimal(binary.signedIntFromBV(bv[164:191]))/Decimal('600000') r['timetoexpire']=int(bv[191:207]) r['radius']=int(bv[207:223]) return r
def decode(bv, validate=False): '''Unpack a sls_weatherreport message. Fields in params: - time_month(uint): Time tag of measurement month 1..12 - time_day(uint): Time tag of measurement day of the month 1..31 - time_hour(uint): Time tag of measurement UTC hours 0..23 - time_min(uint): Time tag of measurement minutes - stationid(aisstr6): Character identifier of the station - pos_longitude(decimal): Location of measurement East West location - pos_latitude(decimal): Location of measurement North South location - speed(udecimal): Average wind speed - gust(udecimal): Wind gust - direction(uint): Wind direction - atmpressure(udecimal): Atmospheric pressure - airtemp(decimal): Air temperature - dewpoint(decimal): Dew Point - visibility(udecimal): Visibility - watertemp(decimal): Water Temperature - reserved(uint): Reserved bits for future use (field automatically set to "0") @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['time_month']=int(bv[0:4]) r['time_day']=int(bv[4:9]) r['time_hour']=int(bv[9:14]) r['time_min']=int(bv[14:20]) r['stationid']=aisstring.decode(bv[20:62]) r['pos_longitude']=Decimal(binary.signedIntFromBV(bv[62:87]))/Decimal('60000') r['pos_latitude']=Decimal(binary.signedIntFromBV(bv[87:111]))/Decimal('60000') r['speed']=Decimal(int(bv[111:121]))/Decimal('10') r['gust']=Decimal(int(bv[121:131]))/Decimal('10') r['direction']=int(bv[131:140]) r['atmpressure']=Decimal(int(bv[140:154]))/Decimal('10') r['airtemp']=Decimal(binary.signedIntFromBV(bv[154:164]))/Decimal('10') r['dewpoint']=Decimal(binary.signedIntFromBV(bv[164:174]))/Decimal('10') r['visibility']=Decimal(int(bv[174:182]))/Decimal('10') r['watertemp']=Decimal(binary.signedIntFromBV(bv[182:192]))/Decimal('10') r['reserved']=0 return r
def decode(bv, validate=False): """Unpack a waterlevel message. 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 @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params """ # Would be nice to check the bit count here.. # if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r["MessageID"] = 8 r["RepeatIndicator"] = int(bv[6:8]) r["UserID"] = int(bv[8:38]) r["Spare"] = 0 r["dac"] = 366 r["fid"] = 63 r["month"] = int(bv[56:60]) r["day"] = int(bv[60:65]) r["hour"] = int(bv[65:70]) r["min"] = int(bv[70:76]) r["stationid"] = aisstring.decode(bv[76:118]) r["waterlevel"] = binary.signedIntFromBV(bv[118:134]) r["datum"] = int(bv[134:139]) r["sigma"] = int(bv[139:146]) r["source"] = int(bv[146:149]) return r
def decode(bv, validate=False): '''Unpack a waterlevel message. 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 @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['MessageID'] = 8 r['RepeatIndicator'] = int(bv[6:8]) r['UserID'] = int(bv[8:38]) r['Spare'] = 0 r['dac'] = 366 r['fid'] = 63 r['month'] = int(bv[56:60]) r['day'] = int(bv[60:65]) r['hour'] = int(bv[65:70]) r['min'] = int(bv[70:76]) r['stationid'] = aisstring.decode(bv[76:118]) r['waterlevel'] = binary.signedIntFromBV(bv[118:134]) r['datum'] = int(bv[134:139]) r['sigma'] = int(bv[139:146]) r['source'] = int(bv[146:149]) return r
def decode(bv, validate=False): '''Unpack a alltypesmsg message. 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 @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['dac']=366 r['reqDecimal']=122/Decimal('1') r['unavail_uint']=int(bv[24:26]) r['anUInt']=int(bv[26:28]) r['anInt']=binary.signedIntFromBV(bv[28:31]) r['aBool']=bool(int(bv[31:32])) r['aStr']=aisstring.decode(bv[32:62]) r['anUDecimal']=Decimal(int(bv[62:78]))/Decimal('10') r['aDecimal']=Decimal(binary.signedIntFromBV(bv[78:94]))/Decimal('10') r['aFloat']=binary.bitvec2float(bv[94:126]) return r
def decode(bv, validate=False): '''Unpack a alltypesmsg message. 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 @type bv: BitVector @param bv: Bits defining a message @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. @rtype: dict @return: params ''' #Would be nice to check the bit count here.. #if validate: # assert (len(bv)==FIX: SOME NUMBER) r = {} r['dac'] = 366 r['reqDecimal'] = 122 / Decimal('1') r['unavail_uint'] = int(bv[24:26]) r['anUInt'] = int(bv[26:28]) r['anInt'] = binary.signedIntFromBV(bv[28:31]) r['aBool'] = bool(int(bv[31:32])) r['aStr'] = aisstring.decode(bv[32:62]) r['anUDecimal'] = Decimal(int(bv[62:78])) / Decimal('10') r['aDecimal'] = Decimal(binary.signedIntFromBV(bv[78:94])) / Decimal('10') r['aFloat'] = binary.bitvec2float(bv[94:126]) return r
def decodereason(bv, validate=False): return aisstring.decode(bv[56:176])
def decodestationid(bv, validate=False): return aisstring.decode(bv[76:118])
def decodeaStr(bv, validate=False): return aisstring.decode(bv[32:62])
def decodeto(bv, validate=False): return aisstring.decode(bv[296:416])
def decodevessel(bv, validate=False): return aisstring.decode(bv[0:90])
def decodestationid(bv, validate=False): return aisstring.decode(bv[20:62])
def decodestationid(bv, validate=False): return aisstring.decode(bv[94:136])
#try: match_obj = uscg_ais_nmea_regex.search(line) if match_obj is None: sys.stderr.write(line) continue station = match_obj.group('station') #except: # sys.stderr.write('bad line: %s\n' %line) # continue fields = line.split(',')[:6] if '1'!=fields[2]: # Must be the start of a sequence #if verbose: # print 'skipping based on field 2',line continue if len(fields[5])<39: #if verbose: # print 'skipping',line continue bv = binary.ais6tobitvec(fields[5][:39]) # Hacked for speed #print int(bv[8:38]),aisstring.decode(bv[112:232],True) name = aisstring.decode(bv[112:232],True).strip('@ ') mmsi = str(int(bv[8:38])) imo = str(int(bv[40:70])) #if len(name)<1 or name[0]=='X': print 'TROUBLE with line:',line if len(name)<1: print 'TROUBLE with line:',line o.write (mmsi+' '+imo+' '+station+' '+name+'\n')
#try: match_obj = uscg_ais_nmea_regex.search(line) if match_obj is None: sys.stderr.write(line) continue station = match_obj.group('station') #except: # sys.stderr.write('bad line: %s\n' %line) # continue fields = line.split(',')[:6] if '1' != fields[2]: # Must be the start of a sequence #if verbose: # print 'skipping based on field 2',line continue if len(fields[5]) < 39: #if verbose: # print 'skipping',line continue bv = binary.ais6tobitvec(fields[5][:39]) # Hacked for speed #print int(bv[8:38]),aisstring.decode(bv[112:232],True) name = aisstring.decode(bv[112:232], True).strip('@ ') mmsi = str(int(bv[8:38])) imo = str(int(bv[40:70])) #if len(name)<1 or name[0]=='X': print 'TROUBLE with line:',line if len(name) < 1: print 'TROUBLE with line:', line o.write(mmsi + ' ' + imo + ' ' + station + ' ' + name + '\n')
def decodefrom(bv, validate=False): return aisstring.decode(bv[176:296])
def decodelockid(bv, validate=False): return aisstring.decode(bv[20:62])