151 lines
6.3 KiB
Python
151 lines
6.3 KiB
Python
def readNema_fun(fName):
|
|
import pynmea2
|
|
from pynmea2 import TalkerSentence
|
|
from decimal import Decimal
|
|
|
|
class M01(TalkerSentence):
|
|
fields = (
|
|
("Date", "Date", Decimal),
|
|
("Time", "Time", Decimal),
|
|
("Buoy ID", "BuoyID", Decimal),
|
|
("Message ID", "MessageID", Decimal),
|
|
("Latitude", "Lat", Decimal),
|
|
("Longitude", "Lon", Decimal),
|
|
("Average Pressure", "AvePres", Decimal),
|
|
("Air Temperature", "AirTemp", Decimal),
|
|
("Humidity", "Humidity", Decimal),
|
|
("Dew Point", "DewPoint", Decimal),
|
|
("WndYng5m", "WndYng5m", Decimal),
|
|
("WndDirYng", "WndDirYng", Decimal),
|
|
("WndGstYng", "WndGstYng", Decimal),
|
|
("WndGil4m", "WndGil4m", Decimal),
|
|
("WndDirGil", "WndDirGil", Decimal),
|
|
("WndGstGil", "WndGstGil", Decimal),
|
|
)
|
|
|
|
class M02(TalkerSentence):
|
|
fields = (
|
|
("Date", "Date", Decimal),
|
|
("Time", "Time", Decimal),
|
|
("Buoy ID", "BuoyID", Decimal),
|
|
("Message ID", "MessageID", Decimal),
|
|
("Min Voltage", "MinVolt", Decimal),
|
|
("Max Voltage", "AveVolt", Decimal),
|
|
("Average Node Current", "AveNodeCur", Decimal),
|
|
("Max Node Current", "MaxNodeCur", Decimal),
|
|
("Sensor 1 Average Current", "Sen1AveCur", Decimal),
|
|
("Wh_dayEst", "Wh_dayEst", Decimal),
|
|
("unknown1", "unknown1", Decimal),
|
|
("H20 Intrusn", "H20_Intrusn", Decimal),
|
|
("PCB Temperature", "PCBTemp", Decimal),
|
|
("Boot Timestamp", "BootTimestamp", Decimal),
|
|
("Num Resets", "NumResets", Decimal),
|
|
("Shutdown Type", "ShutdownType", Decimal),
|
|
("AveServices_Sec", "AveServices_Sec", Decimal),
|
|
("Log Error Count", "LogErrorCnt", Decimal),
|
|
("Error Count", "ErrorCount", Decimal),
|
|
("Free Space", "FreeSpace", Decimal),
|
|
("Watch Circle Status", "WatchcircleStatus", Decimal),
|
|
("Ave Heading", "AveHeading", Decimal),
|
|
("Ave Pressure", "AvePres", Decimal),
|
|
)
|
|
|
|
class M03(TalkerSentence):
|
|
fields = (
|
|
("Date", "Date", Decimal),
|
|
("Time", "Time", Decimal),
|
|
("Buoy ID", "BuoyID", Decimal),
|
|
("Message ID", "MessageID", Decimal),
|
|
("Hs", "Hs", Decimal),
|
|
("Hmax", "Hmax", Decimal),
|
|
("Tp", "Tp", Decimal),
|
|
("MWD", "MWD", Decimal),
|
|
("MeanSpread", "MeanSpread", Decimal),
|
|
)
|
|
|
|
class M04(TalkerSentence):
|
|
fields = (
|
|
("Date", "Date", Decimal),
|
|
("Time", "Time", Decimal),
|
|
("Buoy ID", "BuoyID", Decimal),
|
|
("Message ID", "MessageID", Decimal),
|
|
("Velocity Cell 1", "Vel_Cell_1", Decimal),
|
|
("True Direction Cell 1", "DirTrue1", Decimal),
|
|
("Velocity Cell 2", "Vel_Cell_2", Decimal),
|
|
("True Direction Cell 2", "DirTrue2", Decimal),
|
|
("Velocity Cell 3", "Vel_Cell_3", Decimal),
|
|
("True Direction Cell 3", "DirTrue3", Decimal),
|
|
("Velocity Cell 4", "Vel_Cell_4", Decimal),
|
|
("True Direction Cell 4", "DirTrue4", Decimal),
|
|
("Velocity Cell 5", "Vel_Cell_5", Decimal),
|
|
("True Direction Cell 5", "DirTrue5", Decimal),
|
|
("Velocity Cell 6", "Vel_Cell_6", Decimal),
|
|
("True Direction Cell 6", "DirTru6", Decimal),
|
|
("Velocity Cell 7", "Vel_Cell_7", Decimal),
|
|
("True Direction Cell 7", "DirTrue7", Decimal),
|
|
("Velocity Cell 8", "Vel_Cell_8", Decimal),
|
|
("True Direction Cell 8", "DirTrue8", Decimal),
|
|
("Velocity Cell 9", "Vel_Cell_9", Decimal),
|
|
("True Direction Cell 9", "DirTrue9", Decimal),
|
|
("Velocity Cell 10", "Vel_Cell_10", Decimal),
|
|
("True Direction Cell 10", "DirTrue10", Decimal),
|
|
("Velocity Cell 11", "Vel_Cell_11", Decimal),
|
|
("True Direction Cell 11", "DirTrue11", Decimal),
|
|
("Velocity Cell 12", "Vel_Cell_12", Decimal),
|
|
("True Direction Cell 12", "DirTrue12", Decimal),
|
|
("Velocity Cell 13", "Vel_Cell_13", Decimal),
|
|
("True Direction Cell 13", "DirTrue13", Decimal),
|
|
("Velocity Cell 14", "Vel_Cell_14", Decimal),
|
|
("True Direction Cell 14", "DirTrue14", Decimal),
|
|
("Velocity Cell 15", "Vel_Cell_15", Decimal),
|
|
("True Direction Cell 15", "DirTrue15", Decimal),
|
|
("Velocity Cell 16", "Vel_Cell_16", Decimal),
|
|
("True Direction Cell 16", "DirTrue16", Decimal),
|
|
("Velocity Cell 17", "Vel_Cell_17", Decimal),
|
|
("True Direction Cell 17", "DirTrue17", Decimal),
|
|
("Velocity Cell 18", "Vel_Cell_18", Decimal),
|
|
("True Direction Cell 18", "DirTrue18", Decimal),
|
|
("Velocity Cell 19", "Vel_Cell_19", Decimal),
|
|
("True Direction Cell 19", "DirTrue19", Decimal),
|
|
("Velocity Cell 20", "Vel_Cell_20", Decimal),
|
|
("True Direction Cell 20", "DirTrue20", Decimal),
|
|
)
|
|
|
|
class M10(TalkerSentence):
|
|
fields = (
|
|
("Date", "Date", Decimal),
|
|
("Time", "Time", Decimal),
|
|
("Buoy ID", "BuoyID", Decimal),
|
|
("Message ID", "MessageID", Decimal),
|
|
("Latitude", "Lat", Decimal),
|
|
("Longitude", "Lon", Decimal),
|
|
("Watchcircle Status", "WatchcircleStatus", Decimal),
|
|
("Ave Volt", "AveVolt", Decimal),
|
|
("H2OIntrusnVolt", "H2OIntrusnVolt", Decimal),
|
|
)
|
|
|
|
f = open(fName, "r")
|
|
parsed = []
|
|
|
|
while True:
|
|
msg = f.readline()
|
|
if not msg:
|
|
break;
|
|
|
|
msgNMEA = msg[23:len(msg) - 4]
|
|
|
|
if msgNMEA[38] == '1':
|
|
msgNMEA = msgNMEA.replace('W5M5A', 'W5M01', 1)
|
|
elif msgNMEA[38] == '2':
|
|
msgNMEA = msgNMEA.replace('W5M5A', 'W5M02', )
|
|
elif msgNMEA[38] == '3':
|
|
msgNMEA = msgNMEA.replace('W5M5A', 'W5M03', 1)
|
|
elif msgNMEA[38] == '4':
|
|
msgNMEA = msgNMEA.replace('W5M5A', 'W5M04', 1)
|
|
msgNMEA = msgNMEA.replace('@&2C', ',')
|
|
elif msgNMEA[38] == '10':
|
|
msgNMEA = msgNMEA.replace('W5M5A', 'W5M10', 1)
|
|
|
|
parsed.append(pynmea2.parse(msgNMEA, check=False))
|
|
f.close()
|
|
return parsed |