Skip to content

Commit

Permalink
bug fixes(GB) and improve(fit)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishizuka committed Oct 2, 2023
1 parent 64114fe commit de6d5d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions modules/helper/ble_gatt_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import json
import re
import base64
import traceback
import datetime

Expand Down Expand Up @@ -50,6 +51,10 @@ def tx_characteristic(self, options):
def send_message(self, value):
self.tx_characteristic.changed(bytes(value + "\\n\n", "utf-8"))

def atob(self, matchobj):
r = base64.b64decode(matchobj.group(1)).decode()
return f"\"{r}\""

# receive from central
@characteristic(rx_characteristic_uuid, CharFlags.WRITE).setter
def rx_characteristic(self, value, options):
Expand Down Expand Up @@ -90,19 +95,18 @@ def rx_characteristic(self, value, options):
):
# remove emoji
text_mod = re.sub(":\w+:", "", self.value.decode().strip()[5:-2])
# add double quotation
text_mod = re.sub('(\w+):("?\w*"?)', '"\\1":\\2', text_mod)

# decode base64
b64_decode_ptn = re.compile(r"atob\(\"(\S+)\"\)")
text_mod = re.sub(b64_decode_ptn, self.atob, text_mod)

message = {}
try:
message = json.loads("{" + text_mod + "}", strict=False)
except json.JSONDecodeError:
app_logger.exception("failed to load json")
app_logger.debug(self.value.decode().strip()[5:-2])
app_logger.debug(text_mod)
try:
message = json.loads("{" + text_mod + '"}', strict=False)
except json.JSONDecodeError:
app_logger.error("failed to load json (retry)")
app_logger.exception(self.value.decode().strip()[5:-2])
app_logger.exception(text_mod)

if (
"t" in message
Expand Down
2 changes: 1 addition & 1 deletion modules/logger/logger_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def write_log_python(self):
struct.pack(
struct_def,
end_date_epochtime,
int((end_date - start_date).total_seconds()) * 1000,
(int(end_date.timestamp()) - int(start_date.timestamp())) * 1000,
1, # num of sessions: 1(fix)
0, # activity_type: general
26, # event: activity
Expand Down

0 comments on commit de6d5d0

Please sign in to comment.