Skip to content

Commit e2ce823

Browse files
committed
version revision and build added
1 parent a281380 commit e2ce823

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

podcomm/definitions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323

2424
API_VERSION_MAJOR = 1
2525
API_VERSION_MINOR = 3
26+
API_VERSION_REVISION = 4
27+
API_VERSION_BUILD = 90420
2628

2729
REST_URL_PING = "/omnipy/ping"
2830
REST_URL_OMNIPY_SHUTDOWN = "/omnipy/shutdown"
2931
REST_URL_OMNIPY_RESTART = "/omnipy/restart"
32+
REST_URL_OMNIPY_UPDATE = "/pdm/updatesw"
3033

3134
REST_URL_TOKEN = "/omnipy/token"
3235
REST_URL_CHECK_PASSWORD = "/omnipy/pwcheck"
@@ -53,6 +56,7 @@
5356
logger = None
5457
packet_logger = None
5558

59+
5660
def ensure_log_dir():
5761
if not os.path.isdir(DATA_PATH):
5862
os.mkdir(DATA_PATH)
@@ -80,6 +84,7 @@ def getLogger(with_console=False):
8084

8185
return logger
8286

87+
8388
def get_packet_logger(with_console=False):
8489
global packet_logger
8590

@@ -102,12 +107,15 @@ def get_packet_logger(with_console=False):
102107

103108
return packet_logger
104109

110+
105111
def configureLogging():
106112
pass
107113

114+
108115
class RequestType(IntEnum):
109116
pass
110117

118+
111119
class BolusState(IntEnum):
112120
NotRunning = 0
113121
Extended = 1

podcomm/protocol_radio.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ def send_message_get_message(self, message,
107107

108108
if self.pod_message is None:
109109
self.current_exchange.successful = False
110+
self.stats.append(self.current_exchange)
110111
raise self.response_exception
112+
111113
self.current_exchange.successful = True
114+
self.stats.append(self.current_exchange)
112115
return self.pod_message
113116

114117
def get_packet(self, timeout=30000):
@@ -220,7 +223,6 @@ def _send_and_get(self, pdm_message, pdm_message_address, ack_address_override=N
220223
try:
221224
if tx_power is not None:
222225
self.packet_radio.set_tx_power(tx_power)
223-
self._awaken()
224226
except PacketRadioError:
225227
if not self._radio_init(3):
226228
raise
@@ -501,7 +503,3 @@ def _get_packet(self, data):
501503
except:
502504
getLogger().exception("RECEIVED DATA: %s RSSI: %d" % (binascii.hexlify(data[2:]), rssi))
503505
return None, rssi
504-
505-
def _awaken(self):
506-
#self.packet_radio.send_packet(bytes(), 0, 0, 250)
507-
pass

restapi.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
app = Flask(__name__, static_url_path="/")
3030
configureLogging()
31-
logger = getLogger()
31+
logger = getLogger(with_console=False)
32+
get_packet_logger(with_console=False)
3233

3334

3435
class RestApiException(Exception):
@@ -99,8 +100,9 @@ def _archive_pod():
99100
archive_suffix = datetime.utcnow().strftime("_%Y%m%d_%H%M%S")
100101

101102
if os.path.isfile(DATA_PATH + POD_FILE + POD_FILE_SUFFIX):
102-
archive_name = os.rename(DATA_PATH + POD_FILE + POD_FILE_SUFFIX,
103-
DATA_PATH + POD_FILE + archive_suffix + POD_FILE_SUFFIX)
103+
archive_name = DATA_PATH + POD_FILE + archive_suffix + POD_FILE_SUFFIX
104+
os.rename(DATA_PATH + POD_FILE + POD_FILE_SUFFIX,
105+
archive_name)
104106
if os.path.isfile(DATA_PATH + POD_FILE + POD_DB_SUFFIX):
105107
os.rename(DATA_PATH + POD_FILE + POD_DB_SUFFIX,
106108
DATA_PATH + POD_FILE + archive_suffix + POD_DB_SUFFIX)
@@ -148,6 +150,7 @@ def _save_activated_pod_address(addr):
148150
except:
149151
logger.exception("Error while storing activated radio address")
150152

153+
151154
def _create_response(success, response, pod_status=None):
152155

153156
if pod_status is None:
@@ -164,7 +167,8 @@ def _create_response(success, response, pod_status=None):
164167
"response": response,
165168
"status": pod_status,
166169
"datetime": time.time(),
167-
"api": {"version_major": API_VERSION_MAJOR, "version_minor": API_VERSION_MINOR}
170+
"api": {"version_major": API_VERSION_MAJOR, "version_minor": API_VERSION_MINOR,
171+
"version_revision": API_VERSION_REVISION, "version_build": API_VERSION_BUILD}
168172
}, indent=4, sort_keys=True)
169173

170174

@@ -197,6 +201,7 @@ def _verify_auth(request_obj):
197201
logger.exception("Error during verify_auth")
198202
raise
199203

204+
200205
def _adjust_time(adjustment):
201206
logger.info("Adjusting local time by %d ms" % adjustment)
202207
pdm = _get_pdm()
@@ -242,10 +247,9 @@ def _api_result(result_lambda, generic_err_message):
242247
def _get_pdm_address(timeout):
243248
packet = None
244249
with PdmLock():
245-
radio = _get_pdm().get_radio()
246-
radio.stop()
247-
248250
try:
251+
radio = _get_pdm().get_radio()
252+
radio.stop()
249253
packet = radio.get_packet(timeout)
250254
finally:
251255
radio.disconnect()
@@ -277,6 +281,7 @@ def create_token():
277281
def check_password():
278282
_verify_auth(request)
279283

284+
280285
def get_pdm_address():
281286
_verify_auth(request)
282287

@@ -290,6 +295,7 @@ def get_pdm_address():
290295

291296
return {"radio_address": address, "radio_address_hex": "%8X" % address}
292297

298+
293299
def new_pod():
294300
_verify_auth(request)
295301

@@ -310,6 +316,7 @@ def new_pod():
310316
_archive_pod()
311317
_set_pod(pod)
312318

319+
313320
def activate_pod():
314321
_verify_auth(request)
315322

@@ -326,6 +333,7 @@ def activate_pod():
326333
pdm.activate_pod(req_address, utc_offset=utc_offset)
327334
_save_activated_pod_address(req_address)
328335

336+
329337
def start_pod():
330338
_verify_auth(request)
331339

@@ -339,12 +347,14 @@ def start_pod():
339347

340348
pdm.inject_and_start(schedule)
341349

350+
342351
def _int_parameter(obj, parameter):
343352
if request.args.get(parameter) is not None:
344353
obj.__dict__[parameter] = int(request.args.get(parameter))
345354
return True
346355
return False
347356

357+
348358
def _float_parameter(obj, parameter):
349359
if request.args.get(parameter) is not None:
350360
obj.__dict__[parameter] = float(request.args.get(parameter))
@@ -403,6 +413,7 @@ def get_rl_info():
403413
r = RileyLink()
404414
return r.get_info()
405415

416+
406417
def get_status():
407418
_verify_auth(request)
408419
t = request.args.get('type')
@@ -415,13 +426,15 @@ def get_status():
415426
id = pdm.update_status(req_type)
416427
return {"row_id":id}
417428

429+
418430
def deactivate_pod():
419431
_verify_auth(request)
420432
pdm = _get_pdm()
421433
id = pdm.deactivate_pod()
422434
_archive_pod()
423435
return {"row_id":id}
424436

437+
425438
def bolus():
426439
_verify_auth(request)
427440

@@ -478,6 +491,7 @@ def is_pdm_busy():
478491
pdm = _get_pdm()
479492
return {"busy": pdm.is_busy()}
480493

494+
481495
def acknowledge_alerts():
482496
_verify_auth(request)
483497

@@ -499,6 +513,7 @@ def shutdown():
499513
os.system("sudo shutdown -h")
500514
return {"shutdown": time.time()}
501515

516+
502517
def restart():
503518
global g_deny
504519
_verify_auth(request)
@@ -511,14 +526,26 @@ def restart():
511526
os.system("sudo shutdown -r")
512527
return {"restart": time.time()}
513528

529+
530+
def update_omnipy():
531+
global g_deny
532+
_verify_auth(request)
533+
534+
g_deny = True
535+
pdm = _get_pdm()
536+
while pdm.is_busy():
537+
time.sleep(1)
538+
os.system("/bin/bash /home/pi/omnipy/scripts/pi-update.sh")
539+
return {"update started": time.time()}
540+
541+
514542
@app.route("/")
515543
def main_page():
516544
try:
517545
return app.send_static_file("omnipy.html")
518546
except:
519547
logger.exception("Error while serving root file")
520548

521-
522549
@app.route('/content/<path:path>')
523550
def send_content(path):
524551
try:
@@ -610,12 +637,18 @@ def a19():
610637
def a20():
611638
return _api_result(lambda: archive_pod(), "Failure while archiving pod")
612639

640+
@app.route(REST_URL_OMNIPY_UPDATE)
641+
def a20():
642+
return _api_result(lambda: update_omnipy(), "Failure while archiving pod")
643+
644+
613645
def _run_flask():
614646
try:
615647
app.run(host='0.0.0.0', port=4444, debug=True, use_reloader=False)
616648
except:
617649
logger.exception("Error while running rest api, exiting")
618650

651+
619652
def _exit_with_grace():
620653
try:
621654
global g_deny
@@ -630,6 +663,7 @@ def _exit_with_grace():
630663

631664
exit(0)
632665

666+
633667
if __name__ == '__main__':
634668
logger.info("Rest api is starting")
635669

version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/python3
2+
from podcomm.definitions import API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_REVISION, API_VERSION_BUILD
3+
4+
5+
print("%d.%d.%d.%d" % (API_VERSION_MAJOR, API_VERSION_MINOR, API_VERSION_REVISION, API_VERSION_BUILD))

0 commit comments

Comments
 (0)