Skip to content

Commit

Permalink
Merge pull request #13 from sahilkhanna/SPGT-10-add-timestamp-to-console
Browse files Browse the repository at this point in the history
SPGT-10-add-timestamp-to-console
  • Loading branch information
sahilkhanna authored Jul 26, 2022
2 parents 5bbe400 + 883b094 commit 19647db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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

0 comments on commit 19647db

Please sign in to comment.