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

SPGT-10-add-timestamp-to-console #13

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions project/controller/serialcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def chunk_and_handle_packets(self, big_buff:bytearray)->bytearray:
big_buff = big_buff[self.PACKET_LENGTH:]
if self.controller and self.controller.handle_packet:
convhex = " ".join(["{:02x}".format(bytes) for bytes in small_buff])
self.controller.handle_packet(f'[RX - {datetime.now()}]: {convhex.upper()}')
self.controller.handle_packet(f'{convhex.upper()}')
while len(big_buff)>=len(small_buff):
small_buff = big_buff[:self.PACKET_LENGTH]
big_buff = big_buff[self.PACKET_LENGTH:]
if self.controller and self.controller.handle_packet:
convhex = " ".join(["{:02x}".format(bytes) for bytes in small_buff])
self.controller.handle_packet(f'[RX - {datetime.now()}]: {convhex.upper()}')
self.controller.handle_packet(f'{convhex.upper()}')
return big_buff

def data_received(self, data):
Expand Down
14 changes: 8 additions & 6 deletions project/view/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import PySimpleGUI as gui
from project.controller.serialcontroller import SerialController
from project.controller.maincontroller import MainController
Expand Down Expand Up @@ -34,7 +35,8 @@ class MainUI:
'&Encoding',['bytes','string']], ],
['&Help', EV_MENU_ABOUT], ]

APPEND_TX_MSG = "[TX]: "
APPEND_TX_MSG = "[TX -"
APPEND_RX_MSG = "[RX -"

LEFT_COLUMN_WIDTH = 40
RIGHT_COLUMN_WIDTH = 80
Expand Down Expand Up @@ -129,16 +131,16 @@ def update_send_msg_input(self, msg):
def send_msg(self, msg:str):
if len(msg) > 0:
self._controller.send_packet(bytearray.fromhex(msg))
self.update_console(self.APPEND_TX_MSG + msg)
self.update_console(msg, True)
else:
gui.popup_error("Message is empty! No can do", title="Yuck",
auto_close=True, auto_close_duration=3, no_titlebar=True)

def update_console(self, msg):
if self.APPEND_TX_MSG in msg:
gui.cprint(msg, t='green')
def update_console(self, msg, isTX=False):
if isTX:
gui.cprint(f'{self.APPEND_TX_MSG} {datetime.now()}]: {msg}', t='green')
else:
gui.cprint(msg, t='red')
gui.cprint(f'{self.APPEND_RX_MSG} {datetime.now()}]: {msg}', t='red')

def about_popup(self):
gui.popup('Serial Port Gui Tool', 'Sahil Khanna', 'https://github.com/sahilkhanna/sp-ui-tool',
Expand Down