mirror of
https://github.com/peterantypas/maiana.git
synced 2025-05-27 21:00:24 -07:00
Checkpoint 2
This commit is contained in:
parent
c36c89e604
commit
97e00780bc
@ -122,7 +122,7 @@
|
||||
<object class="notebookpage" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="label">Status</property>
|
||||
<property name="select">1</property>
|
||||
<property name="select">0</property>
|
||||
<object class="wxPanel" expanded="1">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
@ -765,7 +765,7 @@
|
||||
<object class="notebookpage" expanded="1">
|
||||
<property name="bitmap"></property>
|
||||
<property name="label">Station Data</property>
|
||||
<property name="select">0</property>
|
||||
<property name="select">1</property>
|
||||
<object class="wxPanel" expanded="1">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
@ -948,6 +948,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1073,6 +1074,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1198,6 +1200,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1323,6 +1326,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnChoice">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1448,6 +1452,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1573,6 +1578,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1698,6 +1704,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -1823,6 +1830,7 @@
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnText">onStationEdit</event>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="0">
|
||||
@ -2038,7 +2046,7 @@
|
||||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="enabled">0</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="focus"></property>
|
||||
|
@ -180,6 +180,8 @@ class MainFrame ( wx.Frame ):
|
||||
gSizer2.Add( self.m_staticText20, 0, wx.ALL, 5 )
|
||||
|
||||
self.m_StationSaveBtn = wx.Button( self.m_StationPnl, wx.ID_ANY, u"Save", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.m_StationSaveBtn.Enable( False )
|
||||
|
||||
gSizer2.Add( self.m_StationSaveBtn, 0, wx.ALL|wx.ALIGN_BOTTOM, 5 )
|
||||
|
||||
|
||||
@ -240,6 +242,14 @@ class MainFrame ( wx.Frame ):
|
||||
# Connect Events
|
||||
self.m_SerialPortChoice.Bind( wx.EVT_CHOICE, self.onSerialPortSelection )
|
||||
self.m_SerialBtn.Bind( wx.EVT_BUTTON, self.onSerialBtnClick )
|
||||
self.m_MMSIText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_CallsignText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_NameText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_VesselTypeChoice.Bind( wx.EVT_CHOICE, self.onStationEdit )
|
||||
self.m_LengthText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_BeamText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_PortOffsetText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_BowOffsetText.Bind( wx.EVT_TEXT, self.onStationEdit )
|
||||
self.m_StationSaveBtn.Bind( wx.EVT_BUTTON, self.onStationSaveBtnClick )
|
||||
self.m_FWBinaryPicker.Bind( wx.EVT_FILEPICKER_CHANGED, self.onFWBinarySelection )
|
||||
self.m_FWUpdateBtn.Bind( wx.EVT_BUTTON, self.onFWUpdateBtnClick )
|
||||
@ -255,6 +265,16 @@ class MainFrame ( wx.Frame ):
|
||||
def onSerialBtnClick( self, event ):
|
||||
event.Skip()
|
||||
|
||||
def onStationEdit( self, event ):
|
||||
event.Skip()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def onStationSaveBtnClick( self, event ):
|
||||
event.Skip()
|
||||
|
||||
|
@ -15,14 +15,19 @@ class MainWindow(MainFrame):
|
||||
|
||||
def onSerialBtnClick(self, event):
|
||||
if self.port is None:
|
||||
self.port = serial.Serial(self.m_SerialPortChoice.GetString(self.m_SerialPortChoice.GetSelection()), 38400, timeout=2)
|
||||
if self.port is None:
|
||||
wx.MessageBox(b'Unable to open port, it may be in use', 'Info', wx.OK | wx.ICON_ERROR)
|
||||
else:
|
||||
self.m_SerialBtn.SetLabel(b'Disconnect')
|
||||
self.enableUI()
|
||||
self.refreshSys()
|
||||
try:
|
||||
self.port = serial.Serial(self.m_SerialPortChoice.GetString(self.m_SerialPortChoice.GetSelection()), 38400, timeout=1)
|
||||
except:
|
||||
wx.MessageBox(b'Unable to open port, it may be in use', 'Error', wx.OK | wx.ICON_ERROR)
|
||||
return
|
||||
|
||||
self.port.flushInput()
|
||||
self.port.flushOutput()
|
||||
self.m_SerialBtn.SetLabel(b'Disconnect')
|
||||
self.enableUI()
|
||||
if self.refreshSys():
|
||||
self.refreshStation()
|
||||
self.m_StationSaveBtn.Disable()
|
||||
else:
|
||||
self.port.close()
|
||||
self.port = None
|
||||
@ -42,10 +47,11 @@ class MainWindow(MainFrame):
|
||||
'portoffset': int(self.m_PortOffsetText.Value),
|
||||
'bowoffset': int(self.m_BowOffsetText.Value),
|
||||
'type': MaianaClient.VESSEL_TYPES[self.m_VesselTypeChoice.Selection]}
|
||||
print(newdata)
|
||||
#print(newdata)
|
||||
|
||||
if MaianaClient.setStationData(self.port, newdata):
|
||||
self.stationdata = newdata
|
||||
self.m_StationSaveBtn.Disable()
|
||||
|
||||
|
||||
def onFWBinarySelection(self, event):
|
||||
@ -64,18 +70,29 @@ class MainWindow(MainFrame):
|
||||
|
||||
def refreshSys(self):
|
||||
self.sysdata = MaianaClient.loadSys(self.port)
|
||||
self.renderSys()
|
||||
return self.renderSys()
|
||||
|
||||
def refreshStation(self):
|
||||
self.stationdata = MaianaClient.loadStation(self.port)
|
||||
self.renderStation()
|
||||
return self.renderStation()
|
||||
|
||||
def renderSys(self):
|
||||
if not 'hw' in self.sysdata:
|
||||
wx.MessageDialog(self, b'There was no response from MAIANA. Please check connections and try again.',
|
||||
'Timeout', wx.OK | wx.STAY_ON_TOP|wx.CENTRE).ShowModal()
|
||||
return False
|
||||
|
||||
self.m_HWRevLbl.SetLabel(self.sysdata['hw'])
|
||||
self.m_FWRevLbl.SetLabel(self.sysdata['fw'])
|
||||
self.m_CPULbl.SetLabel(self.sysdata['cpu'])
|
||||
return True
|
||||
|
||||
def renderStation(self):
|
||||
if not 'mmsi' in self.stationdata:
|
||||
wx.MessageDialog(self, b'There was no response from MAIANA. Please check connections and try again.',
|
||||
'Timeout', wx.OK | wx.STAY_ON_TOP|wx.CENTRE).ShowModal()
|
||||
return False
|
||||
|
||||
self.m_MMSIText.SetValue('{}'.format(self.stationdata['mmsi']))
|
||||
self.m_NameText.SetValue(self.stationdata['name'])
|
||||
self.m_CallsignText.SetValue(self.stationdata['callsign'])
|
||||
@ -87,8 +104,11 @@ class MainWindow(MainFrame):
|
||||
t = self.stationdata['type']
|
||||
i = MaianaClient.VESSEL_TYPES.index(t)
|
||||
self.m_VesselTypeChoice.SetSelection(i)
|
||||
return True
|
||||
|
||||
def validateStationInputs(self):
|
||||
return True
|
||||
|
||||
|
||||
def onStationEdit( self, event ):
|
||||
self.m_StationSaveBtn.Enable()
|
||||
event.Skip()
|
||||
|
@ -40,36 +40,51 @@ class MaianaClient:
|
||||
|
||||
@staticmethod
|
||||
def sendCmdWithResponse(port, cmd, resp):
|
||||
port.flushInput()
|
||||
port.flushOutput()
|
||||
port.write(cmd + b'\r\n')
|
||||
for i in range(10):
|
||||
for i in range(25):
|
||||
s = port.readline().strip()
|
||||
#print(s)
|
||||
if s == b'':
|
||||
break
|
||||
if resp in s:
|
||||
return s
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def loadSys(port):
|
||||
sysline = MaianaClient.sendCmdWithResponse(port, b'sys?', b'$PAISYS')
|
||||
if sysline is None:
|
||||
return {}
|
||||
for i in range(2):
|
||||
try:
|
||||
sysline = MaianaClient.sendCmdWithResponse(port, b'sys?', b'$PAISYS')
|
||||
if sysline is None:
|
||||
return {}
|
||||
|
||||
systokens = re.split(',|\\*', sysline.decode('utf-8'))
|
||||
sysd = {'fw': systokens[2], 'hw': systokens[1], 'cpu': systokens[4]}
|
||||
systokens = re.split(',|\\*', sysline.decode('utf-8'))
|
||||
sysd = {'fw': systokens[2], 'hw': systokens[1], 'cpu': systokens[4]}
|
||||
return sysd
|
||||
finally:
|
||||
pass
|
||||
|
||||
return sysd
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def loadStation(port):
|
||||
stationline = MaianaClient.sendCmdWithResponse(port, b'station?', b'$PAISTN')
|
||||
if stationline is None:
|
||||
return {}
|
||||
for i in range(2):
|
||||
try:
|
||||
stationline = MaianaClient.sendCmdWithResponse(port, b'station?', b'$PAISTN')
|
||||
if stationline is None:
|
||||
return {}
|
||||
|
||||
stationtokens = re.split(',|\\*', stationline.decode('utf-8'))
|
||||
stad = {'mmsi': int(stationtokens[1]), 'name': stationtokens[2], 'callsign': stationtokens[3],
|
||||
'type': int(stationtokens[4]), 'len': int(stationtokens[5]), 'beam': int(stationtokens[6]),
|
||||
'portoffset': int(stationtokens[7]), 'bowoffset': int(stationtokens[8])}
|
||||
stationtokens = re.split(',|\\*', stationline.decode('utf-8'))
|
||||
stad = {'mmsi': int(stationtokens[1]), 'name': stationtokens[2], 'callsign': stationtokens[3],
|
||||
'type': int(stationtokens[4]), 'len': int(stationtokens[5]), 'beam': int(stationtokens[6]),
|
||||
'portoffset': int(stationtokens[7]), 'bowoffset': int(stationtokens[8])}
|
||||
|
||||
return stad
|
||||
return stad
|
||||
finally:
|
||||
pass
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def setStationData(port, data):
|
||||
@ -85,7 +100,10 @@ class MaianaClient:
|
||||
)
|
||||
|
||||
resp = MaianaClient.sendCmdWithResponse(port, line.encode('utf-8'), b'$PAISTN')
|
||||
#print(resp)
|
||||
if resp:
|
||||
return MaianaClient.sendCmdWithResponse(port, b'reboot', b'$PAISTN')
|
||||
resp = MaianaClient.sendCmdWithResponse(port, b'reboot', b'$PAISTN')
|
||||
#print(resp)
|
||||
return not resp is None
|
||||
|
||||
return False
|
Loading…
x
Reference in New Issue
Block a user