summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-04-10 17:24:10 +0200
committerMichael Buesch <mb@bu3sch.de>2009-04-10 17:24:10 +0200
commitc5b64ff2f10046b5c82b55e12a13b7bdad62c5c1 (patch)
tree8ef111c0ff769bfeb5ce643a9e1ab3ed6539514e
parent75a29d4d986e32bd82bc6468bba11567932a5349 (diff)
downloadcnc-c5b64ff2f10046b5c82b55e12a13b7bdad62c5c1.tar.xz
cnc-c5b64ff2f10046b5c82b55e12a13b7bdad62c5c1.zip
pressure_control: Refetch the state, if the device rebooted.
Signed-off-by: Michael Buesch <mb@bu3sch.de>
-rw-r--r--pressure_control/firmware/main.c2
-rw-r--r--pressure_control/firmware/remote.c9
-rw-r--r--pressure_control/firmware/remote.h2
-rwxr-xr-xpressure_control/remote/pctl-remote30
4 files changed, 33 insertions, 10 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index 7cf98f4..c5f8498 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -181,6 +181,8 @@ int main(void)
sei();
print("Monitoring...\n");
+ remote_work();
+ remote_notify_restart();
while (1) {
mb();
if (state.sensor_trigger_cnt == 0) {
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index cb646a7..d51a58b 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -384,6 +384,15 @@ void remote_pressure_change_notification(uint16_t mbar)
send_message(&msg);
}
+void remote_notify_restart(void)
+{
+ struct remote_message msg;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.id = MSG_RESTARTED;
+ send_message(&msg);
+}
+
#if USE_2X
# define UBRR_FACTOR 2
#else
diff --git a/pressure_control/firmware/remote.h b/pressure_control/firmware/remote.h
index 14c4110..ed739eb 100644
--- a/pressure_control/firmware/remote.h
+++ b/pressure_control/firmware/remote.h
@@ -24,6 +24,7 @@ enum remote_message_id {
MSG_CONFIG_FLAGS,
MSG_SET_CONFIG_FLAGS,
MSG_SET_VALVE,
+ MSG_RESTARTED,
};
enum remote_message_error {
@@ -79,6 +80,7 @@ void print_dec_signed(int16_t number);
void print_hex(uint8_t number);
void remote_pressure_change_notification(uint16_t mbar);
+void remote_notify_restart(void);
void remote_work(void);
void remote_1khz_work(void);
diff --git a/pressure_control/remote/pctl-remote b/pressure_control/remote/pctl-remote
index 3013870..397c286 100755
--- a/pressure_control/remote/pctl-remote
+++ b/pressure_control/remote/pctl-remote
@@ -55,6 +55,7 @@ MSG_GET_CONFIG_FLAGS = 13
MSG_CONFIG_FLAGS = 14
MSG_SET_CONFIG_FLAGS = 15
MSG_SET_VALVE = 16
+MSG_RESTARTED = 17
# Message error codes
MSG_ERR_NONE = 0 # No error
MSG_ERR_CHKSUM = 1 # Checksum error
@@ -121,6 +122,8 @@ class RemoteProtocol(QObject):
CONFIG_STOPBITS)
self.serial.flushInput()
+ self.devRestarted = False
+
self.pollTimer = QTimer(self)
self.connect(self.pollTimer, SIGNAL("timeout()"), self.poll)
self.pollTimer.start(50)
@@ -133,9 +136,12 @@ class RemoteProtocol(QObject):
mainwnd.centralWidget().log.addText("PING->PONG success. Device is alife.\n")
def poll(self):
- if self.serial.inWaiting() < MSG_SIZE:
- return
- self.parseMessage(self.serial.read(MSG_SIZE))
+ if self.serial.inWaiting() >= MSG_SIZE:
+ self.parseMessage(self.serial.read(MSG_SIZE))
+ if self.devRestarted:
+ if mainwnd.centralWidget().fetchState():
+ mainwnd.centralWidget().log.addText(self.tr("Device rebooted\n"))
+ self.devRestarted = False
def checksumMessage(self, msg):
calc_crc = self.__crc16_update_buffer(0xFFFF, msg[0:-2])
@@ -158,7 +164,8 @@ class RemoteProtocol(QObject):
mainwnd.centralWidget().log.addText(str)
if (id == MSG_CURRENT_PRESSURE):
mainwnd.centralWidget().parseCurrentPressureMsg(msg)
- #TODO
+ if (id == MSG_RESTARTED):
+ self.devRestarted = True
def getPayload(self, msg):
return msg[2:-2]
@@ -351,16 +358,17 @@ class MainWidget(QWidget):
def initializeState(self):
if not opt_nofetch:
- self.__fetchState()
+ if not self.fetchState():
+ sys.exit(1)
self.initialized = True
- def __fetchState(self):
+ def fetchState(self):
# Get the current pressure
reply = remote.sendMessageSyncReply(MSG_GET_CURRENT_PRESSURE, 0, "",
MSG_CURRENT_PRESSURE)
if not reply:
print "Failed to fetch current pressure. No reply."
- sys.exit(1)
+ return False
self.parseCurrentPressureMsg(reply)
# Get the desired pressure
@@ -368,7 +376,7 @@ class MainWidget(QWidget):
MSG_DESIRED_PRESSURE)
if not reply:
print "Failed to fetch desired pressure. No reply."
- sys.exit(1)
+ return False
reply = remote.getPayload(reply)
mbar = ord(reply[0]) | (ord(reply[1]) << 8)
self.pressureSpin.setValue(float(mbar) / 1000)
@@ -378,7 +386,7 @@ class MainWidget(QWidget):
MSG_HYSTERESIS)
if not reply:
print "Failed to fetch hysteresis. No reply."
- sys.exit(1)
+ return False
reply = remote.getPayload(reply)
mbar = ord(reply[0]) | (ord(reply[1]) << 8)
self.hystSpin.setValue(float(mbar) / 1000)
@@ -387,10 +395,12 @@ class MainWidget(QWidget):
flags = remote.configFlagsFetch()
if flags == None:
print "Failed to fetch config flags. No reply."
- sys.exit(1)
+ return False
if flags & (1 << CFG_FLAG_AUTOADJUST_ENABLE):
self.autoCheckbox.setCheckState(Qt.Checked)
+ return True
+
def parseCurrentPressureMsg(self, msg):
msg = remote.getPayload(msg)
mbar = ord(msg[0]) | (ord(msg[1]) << 8)
bues.ch cgit interface