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

Source Code for Module ais.sls_waterlevel

  1  #!/usr/bin/env python 
  2   
  3  __version__ = '$Revision: 4791 $'.split()[1] 
  4  __date__ = '$Date: 2007-01-05 $'.split()[1] 
  5  __author__ = 'xmlbinmsg' 
  6   
  7  __doc__=''' 
  8   
  9  Autogenerated python functions to serialize/deserialize binary messages. 
 10   
 11  Generated by: ./aisxmlbinmsg2py.py 
 12   
 13  Need to then wrap these functions with the outer AIS packet and then 
 14  convert the whole binary blob to a NMEA string.  Those functions are 
 15  not currently provided in this file. 
 16   
 17  serialize: python to ais binary 
 18  deserialize: ais binary to python 
 19   
 20  The generated code uses translators.py, binary.py, and aisstring.py 
 21  which should be packaged with the resulting files. 
 22   
 23   
 24  @requires: U{epydoc<http://epydoc.sourceforge.net/>} > 3.0alpha3 
 25  @requires: U{BitVector<http://cheeseshop.python.org/pypi/BitVector>} 
 26   
 27  @author: '''+__author__+''' 
 28  @version: ''' + __version__ +''' 
 29  @var __date__: Date of last svn commit 
 30  @undocumented: __version__ __author__ __doc__ parser 
 31  @status: under development 
 32  @license: Generated code has no license 
 33  ''' 
 34   
 35  import sys 
 36  from decimal import Decimal 
 37  from BitVector import BitVector 
 38   
 39  import binary, aisstring 
 40   
 41  # FIX: check to see if these will be needed 
 42  TrueBV  = BitVector(bitstring="1") 
 43  "Why always rebuild the True bit?  This should speed things up a bunch" 
 44  FalseBV = BitVector(bitstring="0") 
 45  "Why always rebuild the False bit?  This should speed things up a bunch" 
 46   
 47   
48 -def encode(params, validate=False):
49 '''Create a sls_waterlevel binary message payload to pack into an AIS Msg sls_waterlevel. 50 51 Fields in params: 52 - time_month(uint): Time tag of measurement month 1..12 53 - time_day(uint): Time tag of measurement day of the month 1..31 54 - time_hour(uint): Time tag of measurement UTC hours 0..23 55 - time_min(uint): Time tag of measurement minutes 56 - stationid(aisstr6): Character identifier of the station. Usually a number. 57 - pos_longitude(decimal): Location of measurement East West location 58 - pos_latitude(decimal): Location of measurement North South location 59 - type(uint): How to interpret the water level 60 - waterlevel(int): Water level in centimeters 61 - datum(uint): What reference datum applies to the value 62 - reserved(uint): Reserved bits for future use (field automatically set to "0") 63 @param params: Dictionary of field names/values. Throws a ValueError exception if required is missing 64 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. 65 @rtype: BitVector 66 @return: encoded binary message (for binary messages, this needs to be wrapped in a msg 8 67 @note: The returned bits may not be 6 bit aligned. It is up to you to pad out the bits. 68 ''' 69 70 bvList = [] 71 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['time_month']),4)) 72 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['time_day']),5)) 73 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['time_hour']),5)) 74 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['time_min']),6)) 75 if 'stationid' in params: 76 bvList.append(aisstring.encode(params['stationid'],42)) 77 else: 78 bvList.append(aisstring.encode('@@@@@@@',42)) 79 if 'pos_longitude' in params: 80 bvList.append(binary.bvFromSignedInt(int(Decimal(params['pos_longitude'])*Decimal('60000')),25)) 81 else: 82 bvList.append(binary.bvFromSignedInt(10860000,25)) 83 if 'pos_latitude' in params: 84 bvList.append(binary.bvFromSignedInt(int(Decimal(params['pos_latitude'])*Decimal('60000')),24)) 85 else: 86 bvList.append(binary.bvFromSignedInt(5460000,24)) 87 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['type']),1)) 88 if 'waterlevel' in params: 89 bvList.append(binary.bvFromSignedInt(params['waterlevel'],16)) 90 else: 91 bvList.append(binary.bvFromSignedInt(-32768,16)) 92 if 'datum' in params: 93 bvList.append(binary.setBitVectorSize(BitVector(intVal=params['datum']),2)) 94 else: 95 bvList.append(binary.setBitVectorSize(BitVector(intVal=31),2)) 96 bvList.append(binary.setBitVectorSize(BitVector(intVal=0),14)) 97 98 return binary.joinBV(bvList)
99
100 -def decode(bv, validate=False):
101 '''Unpack a sls_waterlevel message 102 103 Fields in params: 104 - time_month(uint): Time tag of measurement month 1..12 105 - time_day(uint): Time tag of measurement day of the month 1..31 106 - time_hour(uint): Time tag of measurement UTC hours 0..23 107 - time_min(uint): Time tag of measurement minutes 108 - stationid(aisstr6): Character identifier of the station. Usually a number. 109 - pos_longitude(decimal): Location of measurement East West location 110 - pos_latitude(decimal): Location of measurement North South location 111 - type(uint): How to interpret the water level 112 - waterlevel(int): Water level in centimeters 113 - datum(uint): What reference datum applies to the value 114 - reserved(uint): Reserved bits for future use (field automatically set to "0") 115 @type bv: BitVector 116 @param bv: Bits defining a message 117 @param validate: Set to true to cause checking to occur. Runs slower. FIX: not implemented. 118 @rtype: dict 119 @return: params 120 ''' 121 122 #Would be nice to check the bit count here.. 123 #if validate: 124 # assert (len(bv)==FIX: SOME NUMBER) 125 r = {} 126 r['time_month']=int(bv[0:4]) 127 r['time_day']=int(bv[4:9]) 128 r['time_hour']=int(bv[9:14]) 129 r['time_min']=int(bv[14:20]) 130 r['stationid']=aisstring.decode(bv[20:62]) 131 r['pos_longitude']=Decimal(binary.signedIntFromBV(bv[62:87]))/Decimal('60000') 132 r['pos_latitude']=Decimal(binary.signedIntFromBV(bv[87:111]))/Decimal('60000') 133 r['type']=int(bv[111:112]) 134 r['waterlevel']=binary.signedIntFromBV(bv[112:128]) 135 r['datum']=int(bv[128:130]) 136 r['reserved']=0 137 return r
138
139 -def decodetime_month(bv, validate=False):
140 return int(bv[0:4])
141
142 -def decodetime_day(bv, validate=False):
143 return int(bv[4:9])
144
145 -def decodetime_hour(bv, validate=False):
146 return int(bv[9:14])
147
148 -def decodetime_min(bv, validate=False):
149 return int(bv[14:20])
150
151 -def decodestationid(bv, validate=False):
152 return aisstring.decode(bv[20:62])
153
154 -def decodepos_longitude(bv, validate=False):
155 return Decimal(binary.signedIntFromBV(bv[62:87]))/Decimal('60000')
156
157 -def decodepos_latitude(bv, validate=False):
158 return Decimal(binary.signedIntFromBV(bv[87:111]))/Decimal('60000')
159
160 -def decodetype(bv, validate=False):
161 return int(bv[111:112])
162
163 -def decodewaterlevel(bv, validate=False):
164 return binary.signedIntFromBV(bv[112:128])
165
166 -def decodedatum(bv, validate=False):
167 return int(bv[128:130])
168
169 -def decodereserved(bv, validate=False):
170 return 0
171 172
173 -def printHtml(params, out=sys.stdout):
174 out.write("<h3>sls_waterlevel<h3>\n") 175 out.write("<table border=\"1\">\n") 176 out.write("<tr bgcolor=\"orange\">\n") 177 out.write("<th align=\"left\">Field Name</th>\n") 178 out.write("<th align=\"left\">Type</th>\n") 179 out.write("<th align=\"left\">Value</th>\n") 180 out.write("<th align=\"left\">Value in Lookup Table</th>\n") 181 out.write("\n") 182 out.write("<tr>\n") 183 out.write("<td>time_month</td>\n") 184 out.write("<td>uint</td>\n") 185 if 'time_month' in params: 186 out.write(" <td>"+str(params['time_month'])+"</td>\n") 187 out.write(" <td>"+str(params['time_month'])+"</td>\n") 188 out.write("</tr>\n") 189 out.write("\n") 190 out.write("<tr>\n") 191 out.write("<td>time_day</td>\n") 192 out.write("<td>uint</td>\n") 193 if 'time_day' in params: 194 out.write(" <td>"+str(params['time_day'])+"</td>\n") 195 out.write(" <td>"+str(params['time_day'])+"</td>\n") 196 out.write("</tr>\n") 197 out.write("\n") 198 out.write("<tr>\n") 199 out.write("<td>time_hour</td>\n") 200 out.write("<td>uint</td>\n") 201 if 'time_hour' in params: 202 out.write(" <td>"+str(params['time_hour'])+"</td>\n") 203 out.write(" <td>"+str(params['time_hour'])+"</td>\n") 204 out.write("</tr>\n") 205 out.write("\n") 206 out.write("<tr>\n") 207 out.write("<td>time_min</td>\n") 208 out.write("<td>uint</td>\n") 209 if 'time_min' in params: 210 out.write(" <td>"+str(params['time_min'])+"</td>\n") 211 out.write(" <td>"+str(params['time_min'])+"</td>\n") 212 out.write("</tr>\n") 213 out.write("\n") 214 out.write("<tr>\n") 215 out.write("<td>stationid</td>\n") 216 out.write("<td>aisstr6</td>\n") 217 if 'stationid' in params: 218 out.write(" <td>"+str(params['stationid'])+"</td>\n") 219 out.write(" <td>"+str(params['stationid'])+"</td>\n") 220 out.write("</tr>\n") 221 out.write("\n") 222 out.write("<tr>\n") 223 out.write("<td>pos_longitude</td>\n") 224 out.write("<td>decimal</td>\n") 225 if 'pos_longitude' in params: 226 out.write(" <td>"+str(params['pos_longitude'])+"</td>\n") 227 out.write(" <td>"+str(params['pos_longitude'])+"</td>\n") 228 out.write("</tr>\n") 229 out.write("\n") 230 out.write("<tr>\n") 231 out.write("<td>pos_latitude</td>\n") 232 out.write("<td>decimal</td>\n") 233 if 'pos_latitude' in params: 234 out.write(" <td>"+str(params['pos_latitude'])+"</td>\n") 235 out.write(" <td>"+str(params['pos_latitude'])+"</td>\n") 236 out.write("</tr>\n") 237 out.write("\n") 238 out.write("<tr>\n") 239 out.write("<td>type</td>\n") 240 out.write("<td>uint</td>\n") 241 if 'type' in params: 242 out.write(" <td>"+str(params['type'])+"</td>\n") 243 if str(params['type']) in typeDecodeLut: 244 out.write("<td>"+typeDecodeLut[str(params['type'])]+"</td>") 245 else: 246 out.write("<td><i>Missing LUT entry</i></td>") 247 out.write("</tr>\n") 248 out.write("\n") 249 out.write("<tr>\n") 250 out.write("<td>waterlevel</td>\n") 251 out.write("<td>int</td>\n") 252 if 'waterlevel' in params: 253 out.write(" <td>"+str(params['waterlevel'])+"</td>\n") 254 out.write(" <td>"+str(params['waterlevel'])+"</td>\n") 255 out.write("</tr>\n") 256 out.write("\n") 257 out.write("<tr>\n") 258 out.write("<td>datum</td>\n") 259 out.write("<td>uint</td>\n") 260 if 'datum' in params: 261 out.write(" <td>"+str(params['datum'])+"</td>\n") 262 if str(params['datum']) in datumDecodeLut: 263 out.write("<td>"+datumDecodeLut[str(params['datum'])]+"</td>") 264 else: 265 out.write("<td><i>Missing LUT entry</i></td>") 266 out.write("</tr>\n") 267 out.write("\n") 268 out.write("<tr>\n") 269 out.write("<td>reserved</td>\n") 270 out.write("<td>uint</td>\n") 271 if 'reserved' in params: 272 out.write(" <td>"+str(params['reserved'])+"</td>\n") 273 out.write(" <td>"+str(params['reserved'])+"</td>\n") 274 out.write("</tr>\n") 275 out.write("</table>\n")
276
277 -def printKml(params, out=sys.stdout):
278 '''KML (Keyhole Markup Language) for Google Earth, but without the header/footer''' 279 out.write("\ <Placemark>\n")
280