Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: View Raw Messages #91

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions link_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def process_response(future: concurrent.futures.Future, args, display_filters: l
write_to_log_file(response['message'], os.path.join(FAIL_DIRECTORY, "FAILED_UPLOADS_{}.txt".format(formatted_time)) if args.log_upload else FAIL_FILE_NAME)
write_to_log_file(fail_msg + '\n', os.path.join(DEBUG_DIRECTORY, "FAILED_UPLOADS_{}.txt".format(formatted_time)) if args.log_upload else DEBUG_FILE_NAME, convert_to_hex=False)
elif response["result"] == "INFLUX_WRITE_FAIL":
fail_msg = f"{ANSI_RED}INFLUX_WRITE_FAIL{ANSI_ESCAPE}: \n" + f"{response['error']}"
print(f"Failed to write measurements for {response['type']} message to InfluxDB!")
print(response)

Expand Down Expand Up @@ -474,6 +475,12 @@ def process_message(message: str, buffer: str = "") -> list:
if len(parts[-1]) != 30 or len(parts[-1]) != 396 or len(parts[-1]) != 44:
buffer = parts.pop()

try:
parts = [part + "0d0a" for part in parts if len(part) == 30 or len(part) == 396 or len(part) == 44]
except ValueError as e:
print(f"{ANSI_RED}Failed to split message: {str([part for part in parts])}{ANSI_ESCAPE}"
f" ERROR: {e}")
return [], buffer
return [bytes.fromhex(part).decode('latin-1') for part in parts] , buffer


Expand Down Expand Up @@ -528,6 +535,12 @@ def main():
source_group.add_argument("--live-off", action="store_true",
help=("Will not stream any data to grafana"))

source_group.add_argument("--raw", action="store_true",
help=("Will enable displaying of raw data coming from serial stream AFTER cutting algorithm"))

source_group.add_argument("--rawest", action="store_true",
help=("Will enable displaying of raw data coming from serial stream in chunk size"))

source_group.add_argument("-l", "--log", nargs='+',
help=("Args create a list of message classes or ID's to pretty log to a file. no args for all, all for all"))

Expand Down Expand Up @@ -705,9 +718,15 @@ def main():
# read in bytes from COM port
chunk = ser.read(CHUNK_SIZE)
chunk = chunk.hex()

if args.rawest:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to make it very clear that the args.rawest prints can have incomplete messages. Can you please add their usage (as well as this warning) in the README

print(chunk)

parts, buffer = process_message(chunk, buffer)

for part in parts:
if args.raw:
print(part.encode('latin-1').hex())
sendToParser(part, live_filters, log_filters, display_filters, args, PARSER_ENDPOINT)

sendToParser(message, live_filters, log_filters, display_filters, args, PARSER_ENDPOINT)
Expand Down
8 changes: 4 additions & 4 deletions parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ def parse_request():

# try extracting measurements
try:
message = create_message(parse_request["message"])
message = create_message(msg)
except Exception as e:
app.logger.warn(
f"Unable to extract measurements for raw message {parse_request['message']}")
f"Unable to extract measurements for raw message {msg}")
curr_response = {
"result": "PARSE_FAIL",
"message": str(parse_request["message"]),
"message": str(msg),
"error": str(e),
}
all_response.append(curr_response)
Expand Down Expand Up @@ -372,7 +372,7 @@ def parse_and_write_request_bucket(bucket):
app.logger.warning("Unable to write measurement to InfluxDB!")
curr_response = {
"result": "INFLUX_WRITE_FAIL",
"message": str(parse_request["message"]),
"message": str(msg),
"error": str(e),
"type": type
}
Expand Down
6 changes: 6 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Memorator Script Usage Guide
* Ensure that canlib is installed correctly. [**See this guide**](https://github.com/UBC-Solar/firmware_v3/tree/master/tools/t_programs/sendRTC).
* Ensure that you have the SD Card with the logged messages from the memorator
* Then plug in the SD Card into your device which is running sunlink
* Now, navigate to the `tools/` directory and then to the `MemoratorUploader.py` script.
* Inside here you will need to change the `LOG_FOLDER` constant to the directory of the SD Card (directory that contains the `LOG000xx.KMF` files)
Loading