From 77f35359197e04b3e39eed82c2642f5636e4ee6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=B3nal=20Murray?= <donal.murray@cern.ch> Date: Sun, 19 Apr 2020 18:15:46 +0100 Subject: [PATCH] Add updated hevserver readme and fix enumchecker regex --- raspberry-dataserver/README.md | 23 ++++++++++++++++------- utils/enumcheck.sh | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/raspberry-dataserver/README.md b/raspberry-dataserver/README.md index 418f977d..05f0b38b 100644 --- a/raspberry-dataserver/README.md +++ b/raspberry-dataserver/README.md @@ -126,14 +126,14 @@ where type can be either `"ack"` in response to a valid command or `"nack"` in r ## Example `hevclient.py` Usage ```python -import hevclient - -# create instance of hevclient. Starts connection and polls in the background +# just import hevclient and do something like the following hevclient = HEVClient() +time.sleep(2) +print(hevclient.send_cmd("GENERAL", "START")) # Play with sensor values and alarms -for i in range(30): +for i in range(20): values = hevclient.get_values() # returns a dict or None alarms = hevclient.get_alarms() # returns a list of alarms currently ongoing if values is None: @@ -143,16 +143,25 @@ for i in range(30): print(f"Alarms: {alarms}") time.sleep(1) +# acknowledge the oldest alarm +try: + hevclient.ack_alarm(alarms[0]) # blindly assume we have one after 40s +except: + logging.info("No alarms received") + +time.sleep(1) +print(f"Alarms: {hevclient.get_alarms()}") + # send commands: -print(hevclient.send_cmd("CMD_START")) time.sleep(1) print("This one will fail since foo is not in the command_codes enum:") -print(hevclient.send_cmd("foo")) +print(hevclient.send_cmd("general", "foo")) # print some more values for i in range(10): - print(f"Alarms: {hevclient.get_alarms()}") print(f"Values: {json.dumps(hevclient.get_values(), indent=4)}") print(f"Alarms: {hevclient.get_alarms()}") time.sleep(1) + +print(hevclient.send_cmd("GENERAL", "STOP")) ``` diff --git a/utils/enumcheck.sh b/utils/enumcheck.sh index c7abcd8d..d3f92a6b 100755 --- a/utils/enumcheck.sh +++ b/utils/enumcheck.sh @@ -2,7 +2,7 @@ set -euo pipefail for enum in CMD_TYPE CMD_GENERAL CMD_SET_TIMEOUT CMD_SET_MODE ALARM_TYPE ALARM_CODES; do - sed -e "/enum $enum/,/};/!d" -e '/};/d' -e 's/,$//g' -e 's/,\([[:blank:]]*\)\/\/\(.*\)/\1 #\2/g' -e 's@//@#@g' -e "s/enum \([[:graph:]]*\) .*{/class \1(Enum):/" ../arduino/hev_prototype_v1/src/common.h; + sed -e "/enum $enum/,/};/!d" -e '/};/d' -e 's/,$//g' -e 's/,\([[:blank:]]*\)\/\/\(.*\)/\1 #\2/g' -e 's@//@#@g' -e "s/enum \([a-zA-Z_]*\).*{/class \1(Enum):/" ../arduino/hev_prototype_v1/src/common.h; echo; done -- GitLab