Updated base model

master
haddaway 2012-10-20 20:59:50 -07:00
parent bc02e771c7
commit 37783c85b0
2 changed files with 16 additions and 6 deletions

View File

@ -12,8 +12,10 @@ class ToorChatProtocol():
self.device.RFxmit(msg.to_string())
print msg.to_string()
def parse_message(self, raw_message):
@classmethod
def parse_message(cls, raw_message):
message = ToorChatMessage()
message.raw = raw_message
start_index = raw_message.find(ToorChatProtocol.get_packet_start())
end_index = raw_message.find(ToorChatProtocol.get_packet_end())
if start_index == -1 or end_index == -1:
@ -21,8 +23,8 @@ class ToorChatProtocol():
message.start = raw_message[start_index:start_index + 4]
message.xid = raw_message[start_index + 4: start_index + 12]
message.user = raw_message[start_index + 12: start_index + 44]
message.data = raw_message[start_index + 44: end_index - 4]
message.end = raw_message[end_index - 4: end_index]
message.data = raw_message[start_index + 44: end_index]
message.end = raw_message[end_index: end_index+4]
return message
@classmethod
@ -37,12 +39,13 @@ class ToorChatMessage():
''' This is a simple Message object wrapper to make things cleaner '''
def __init__(self, message = "", user = None):
self.raw = None
self.start = ToorChatProtocol.get_packet_start()
self.xid = self.get_random_xid()
if user != None:
self.user = user
else:
self.user = "\x00"*32
self.user = "\xAA"*32
self.data = message
self.end = ToorChatProtocol.get_packet_end()

View File

@ -16,7 +16,9 @@ def thread_run(visual):
while not visual.exit:
try:
msg, timestamp = visual.badge.RFrecv()
visual.message_queue.append(msg)
toor_message = ToorChatProtocol.parse_message(msg)
if toor_message != None:
visual.message_queue.append(toor_message)
except ChipconUsbTimeoutException:
pass
@ -51,7 +53,12 @@ class Visualizer():
while True:
self.screen_max_y, self.screen_max_x = self.screen.getmaxyx()
self.screen.addstr(0, 1, "[S] Send Message ")
self.screen.addstr(3,1,"Count:" + str(len(self.message_queue)))
if len(self.message_queue) > 0:
self.screen.clear()
self.__draw_frame__()
self.screen.refresh()
self.screen.addstr(3,1,"Last Message:" + str(self.message_queue[len(self.message_queue)-1].data))
self.message_queue.pop()
entry = self.screen.getch()
if entry == curses.KEY_RESIZE:
self.__draw_frame__()