mirror of
https://github.com/peterantypas/maiana.git
synced 2025-05-31 23:00:16 -07:00
Can detect DFU mode upon connecting
This commit is contained in:
parent
e536b5b597
commit
83b4f5946c
@ -3,8 +3,14 @@ import sys
|
|||||||
import glob
|
import glob
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class MaianaStatus(Enum):
|
||||||
|
UNKNOWN = 0
|
||||||
|
RUNNING = 1
|
||||||
|
DFU = 2
|
||||||
|
|
||||||
class MaianaClient:
|
class MaianaClient:
|
||||||
VESSEL_TYPES = [30, 34, 36, 37]
|
VESSEL_TYPES = [30, 34, 36, 37]
|
||||||
|
|
||||||
@ -38,6 +44,23 @@ class MaianaClient:
|
|||||||
pass
|
pass
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def determineStatus(port):
|
||||||
|
port.flushInput()
|
||||||
|
port.flushOutput()
|
||||||
|
s = port.readline().strip()
|
||||||
|
port.write(b'\r\n')
|
||||||
|
for i in range(5):
|
||||||
|
s = port.readline().strip()
|
||||||
|
if s.find(b"bootloader") > -1:
|
||||||
|
return MaianaStatus.DFU
|
||||||
|
else:
|
||||||
|
tokens = s.decode('utf-8').split(',')
|
||||||
|
if (tokens[0][0] == '$' or tokens[0][0] == '!') and len(tokens) >= 2:
|
||||||
|
return MaianaStatus.RUNNING
|
||||||
|
|
||||||
|
return MaianaStatus.UNKNOWN
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sendCmdWithResponse(port, cmd, resp):
|
def sendCmdWithResponse(port, cmd, resp):
|
||||||
port.flushInput()
|
port.flushInput()
|
@ -1,5 +1,5 @@
|
|||||||
from mainframe import MainFrame
|
from mainframe import MainFrame
|
||||||
from model import MaianaClient
|
from maianaclient import MaianaClient, MaianaStatus
|
||||||
import serial
|
import serial
|
||||||
import wx
|
import wx
|
||||||
from fwUpdateThread import *
|
from fwUpdateThread import *
|
||||||
@ -24,13 +24,23 @@ class MainWindow(MainFrame):
|
|||||||
wx.MessageBox(b'Unable to open port, it may be in use', 'Error', wx.OK | wx.ICON_ERROR)
|
wx.MessageBox(b'Unable to open port, it may be in use', 'Error', wx.OK | wx.ICON_ERROR)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.port.flushInput()
|
status = MaianaClient.determineStatus(self.port)
|
||||||
self.port.flushOutput()
|
|
||||||
self.m_SerialBtn.SetLabel(b'Disconnect')
|
if status == MaianaStatus.UNKNOWN:
|
||||||
self.enableUI()
|
pass
|
||||||
if self.refreshSys():
|
elif status == MaianaStatus.DFU:
|
||||||
self.refreshStation()
|
wx.MessageBox(b'MAIANA is currently in firmware update mode. This is the only task you can perform.',
|
||||||
|
'DFU warning', wx.OK)
|
||||||
|
self.enableUI()
|
||||||
|
self.m_SerialBtn.SetLabel(b'Disconnect')
|
||||||
self.m_StationSaveBtn.Disable()
|
self.m_StationSaveBtn.Disable()
|
||||||
|
else:
|
||||||
|
#Assuming status is RUNNING
|
||||||
|
self.m_SerialBtn.SetLabel(b'Disconnect')
|
||||||
|
self.enableUI()
|
||||||
|
if self.refreshSys():
|
||||||
|
self.refreshStation()
|
||||||
|
self.m_StationSaveBtn.Disable()
|
||||||
else:
|
else:
|
||||||
self.port.close()
|
self.port.close()
|
||||||
self.port = None
|
self.port = None
|
||||||
@ -78,6 +88,7 @@ class MainWindow(MainFrame):
|
|||||||
self.m_FWProgress.SetValue(0)
|
self.m_FWProgress.SetValue(0)
|
||||||
self.m_FWUpdateStatusLbl.SetLabel("Transfer completed")
|
self.m_FWUpdateStatusLbl.SetLabel("Transfer completed")
|
||||||
self.refreshSys()
|
self.refreshSys()
|
||||||
|
self.refreshStation()
|
||||||
elif evt.eventType == EventType.ERROR:
|
elif evt.eventType == EventType.ERROR:
|
||||||
self.m_FWUpdateStatusLbl.SetLabel(evt.data)
|
self.m_FWUpdateStatusLbl.SetLabel(evt.data)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user