def noaawaterlevel2aisBits(stationID, mmsi, datum, wl, verbose=False, debug=False): ''' Return an AIS string of the latest waterlevel. @param stationID: which station to query (e.g. '8639348') @type stationID: str @param wl: one entry from a soap query @param verbose: Set to true for print messages @param debug: Do not actually fetch any real data (fast for debugging) @param datum: MSL,MLLW @return: bits for the message payload @rtype: BitVector ''' #wl = None #wl = wl_dap.getWaterLevelNow(stationID,verbose,datum) if verbose: print 'water level dict:', wl # FIX: check for link down state and return a link down packet params = {} # Beginning of AIS message 8 BBM # MessageID params['RepeatIndicator'] = 1 params['UserID'] = int(mmsi) # Spare # Commented params are those that are required by the spec and do not need to be set. # params['dac'] = 366 # params['fid'] = 1 # params['efid'] = 1 yearDummy, monthDummy, dayDummy, hourDummy, minDummy = splitNoaaDateTimeSoap( wl.timeStamp) params['month'] = int(monthDummy) params['day'] = int(dayDummy) params['hour'] = int(hourDummy) params['min'] = int(minDummy) params['sec'] = 0 # No seconds in timestamp params['stationid'] = str(stationID) station = stations.getStation(str(stationID)) params['longitude'] = Decimal(str(station.getLon())) params['latitude'] = Decimal(str(station.getLat())) params['waterlevel'] = int(float(wl.WL) * 100) # Convert to CM if verbose: print params['waterlevel'], wl.WL params['datum'] = int(wl_ais.datumEncodeLut[datum]) params['sigma'] = float(wl.sigma) params['o'] = int(wl.O) if params['o'] < 0: print 'wl.O', wl.O, params[ 'o'], 'FIX: what does this mean? Forcing O to be positive' params['o'] = -params['o'] if bool(wl.L): params['levelinferred'] = True else: params['levelinferred'] = False if bool(wl.F): params['flat_tolerance_exceeded'] = True else: params['flat_tolerance_exceeded'] = False if bool(wl.R): params['rate_tolerance_exceeded'] = True else: params['rate_tolerance_exceeded'] = False params[ 'temp_tolerance_exceeded'] = False # FIX: Where is the code for this??? params[ 'expected_height_exceeded'] = False # FIX: Where is the code for this??? params['link_down'] = False if verbose: wl_ais.printFields(params) print 'params dump:' for item in params.keys(): print ' ', item, params[item] return wl_ais.encode(params)
def noaawaterlevel2aisBits(stationID,mmsi,datum,wl,verbose=False,debug=False): ''' Return an AIS string of the latest waterlevel. @param stationID: which station to query (e.g. '8639348') @type stationID: str @param wl: one entry from a soap query @param verbose: Set to true for print messages @param debug: Do not actually fetch any real data (fast for debugging) @param datum: MSL,MLLW @return: bits for the message payload @rtype: BitVector ''' #wl = None #wl = wl_dap.getWaterLevelNow(stationID,verbose,datum) if verbose: print 'water level dict:',wl # FIX: check for link down state and return a link down packet params = {} # Beginning of AIS message 8 BBM # MessageID params['RepeatIndicator'] = 1 params['UserID'] = int(mmsi) # Spare # Commented params are those that are required by the spec and do not need to be set. # params['dac'] = 366 # params['fid'] = 1 # params['efid'] = 1 yearDummy, monthDummy, dayDummy, hourDummy, minDummy = splitNoaaDateTimeSoap(wl.timeStamp) params['month'] = int(monthDummy) params['day'] = int(dayDummy) params['hour'] = int(hourDummy) params['min'] = int(minDummy) params['sec'] = 0 # No seconds in timestamp params['stationid'] = str(stationID) station = stations.getStation(str(stationID)) params['longitude'] = Decimal(str(station.getLon())) params['latitude'] = Decimal(str(station.getLat())) params['waterlevel'] = int(float(wl.WL)*100) # Convert to CM if verbose: print params['waterlevel'], wl.WL params['datum'] = int(wl_ais.datumEncodeLut[datum]) params['sigma'] = float(wl.sigma) params['o'] = int(wl.O) if params['o']<0: print 'wl.O',wl.O, params['o'],'FIX: what does this mean? Forcing O to be positive' params['o'] = -params['o'] if bool(wl.L): params['levelinferred'] = True else: params['levelinferred'] = False if bool(wl.F): params['flat_tolerance_exceeded'] = True else: params['flat_tolerance_exceeded'] = False if bool(wl.R): params['rate_tolerance_exceeded'] = True else: params['rate_tolerance_exceeded'] = False params['temp_tolerance_exceeded'] = False # FIX: Where is the code for this??? params['expected_height_exceeded'] = False # FIX: Where is the code for this??? params['link_down'] = False if verbose: wl_ais.printFields(params) print 'params dump:' for item in params.keys(): print ' ',item,params[item] return wl_ais.encode(params)
def noaawaterlevel2aisBits(stationID,mmsi,verbose=False,debug=False,datum='MSL'): ''' Return an AIS string of the latest waterlevel. @param stationID: which station to query (e.g. '8639348') @type stationID: str @param verbose: Set to true for print messages @param debug: Do not actually fetch any real data (fast for debugging) @param datum: MSL,MLLW @return: bits for the message payload @rtype: BitVector ''' wl = None if debug: print 'Using a testing dict for waterlevel' wl = { '_STATION_ID': '8639348', '_DATUM': datum, #'MLLW', '_BEGIN_DATE': '20070104 16:24', '_END_DATE': '20070104 16:54', 'DCP': '1', 'SENSOR_ID': 'A1', 'DATE_TIME': 'Jan 4 2007 4:36PM', 'WL_VALUE': 0.674, 'SIGMA': 0.005, 'O': 0, # Samples outside of 3 sigma 'F': 0, # Flat Toler 'R': 0, # Rate toler exceeded 'L': 0, # Level infered } else: wl = wl_dap.getWaterLevelNow(stationID,verbose,datum) if verbose: print 'water level dict:',wl # FIX: check for link down state and return a link down packet params = {} # Beginning of AIS message 8 BBM # MessageID params['RepeatIndicator'] = 1 params['UserID'] = int(mmsi) # Spare # Commented params are those that are required by the spec and do not need to be set. # params['dac'] = 366 # params['fid'] = 1 # params['efid'] = 1 yearDummy, monthDummy, dayDummy, hourDummy, minDummy = splitNoaaDateTime(wl['DATE_TIME']) params['month'] = int(monthDummy) params['day'] = int(dayDummy) params['hour'] = int(hourDummy) params['min'] = int(minDummy) params['sec'] = 0 # No seconds in timestamp params['stationid'] = wl['_STATION_ID'] station = stations.getStation(stationID) params['longitude'] = Decimal(str(station.getLon())) params['latitude'] = Decimal(str(station.getLat())) params['waterlevel'] = int(float(wl['WL_VALUE'])*100) # Convert to CM print params['waterlevel'], wl['WL_VALUE'] params['datum'] = int(wl_ais.datumEncodeLut[wl['_DATUM']]) params['sigma'] = float(wl['SIGMA']) params['o'] = wl['O'] # # FIX: I think I am missing some values in the returned data! # if bool(wl['L']): params['levelinferred'] = True else: params['levelinferred'] = False if bool(wl['F']): params['flat_tolerance_exceeded'] = True else: params['flat_tolerance_exceeded'] = False if bool(wl['R']): params['rate_tolerance_exceeded'] = True else: params['rate_tolerance_exceeded'] = False params['temp_tolerance_exceeded'] = False # FIX: Where is the code for this??? params['expected_height_exceeded'] = False # FIX: Where is the code for this??? params['link_down'] = False # FIX: put in the timeLastMeastured #params['timeLastMeasured_month'] = params['timetag_month'] #params['timeLastMeasured_day'] = params['timetag_day'] #params['timeLastMeasured_hour'] = params['timetag_hour'] #params['timeLastMeasured_min'] = params['timetag_min'] #params['timeLastMeasured_sec'] = 0 if verbose: wl_ais.printFields(params) print 'params dump:' for item in params.keys(): print ' ',item,params[item] return wl_ais.encode(params)