forked from M-Labs/thermostat
main: fix handling of incomplete data received (#55)
Reviewed-on: M-Labs/thermostat#55 Co-Authored-By: topquark12 <aw@m-labs.hk> Co-Committed-By: topquark12 <aw@m-labs.hk>
This commit is contained in:
parent
7cb0ed70be
commit
a5d8661b10
@ -243,11 +243,8 @@ def main():
|
||||
lookback, noiseband, ch['interval'])
|
||||
|
||||
for data in tec.report_mode():
|
||||
try:
|
||||
|
||||
ch = data[channel]
|
||||
# Workaround for report_mode may yeild empty object
|
||||
except KeyError:
|
||||
continue
|
||||
|
||||
temperature = ch['temperature']
|
||||
|
||||
|
@ -213,9 +213,11 @@ fn main() -> ! {
|
||||
socket.close()
|
||||
} else if socket.can_send() && socket.can_recv() {
|
||||
match socket.recv(|buf| session.feed(buf)) {
|
||||
Ok(SessionInput::Nothing) => {
|
||||
send_line(&mut socket, b"{}");
|
||||
}
|
||||
// SessionInput::Nothing happens when the line reader parses a string of characters that is not
|
||||
// followed by a newline character. Could be due to partial commands not terminated with newline,
|
||||
// socket RX ring buffer wraps around, or when the command is sent as seperate TCP packets etc.
|
||||
// Do nothing and feed more data to the line reader in the next loop cycle.
|
||||
Ok(SessionInput::Nothing) => {}
|
||||
Ok(SessionInput::Command(command)) => match command {
|
||||
Command::Quit =>
|
||||
socket.close(),
|
||||
|
Loading…
Reference in New Issue
Block a user