root 2012-10-20 16:56:26 -07:00
commit 7d7ed2d074
3 changed files with 37 additions and 6 deletions

View File

@ -6,10 +6,11 @@ class ToorChatProtocol():
self.PACKET_END = "\xFF\xBE\xEF\xFF" self.PACKET_END = "\xFF\xBE\xEF\xFF"
self.device = device self.device = device
def send_message(cls, message = "", user = None): def send_message(self, message = "", user = None):
''' This is used to send a simple message over the toorchat protocol ''' ''' This is used to send a simple message over the toorchat protocol '''
msg = ToorChatMessage(message, user) msg = ToorChatMessage(message, user)
self.device.RFxmit(msg) self.device.RFxmit(msg.to_string())
print msg.to_string()
@classmethod @classmethod
def get_packet_start(cls): def get_packet_start(cls):
@ -32,6 +33,9 @@ class ToorChatMessage():
self.data = message self.data = message
self.end = ToorChatProtocol.get_packet_end() self.end = ToorChatProtocol.get_packet_end()
def get_random_xid(self):
return "44444444"
def __str__(self): def __str__(self):
return self.start + self.xid + self.user + self.data + self.end return self.start + self.xid + self.user + self.data + self.end

27
recv_loop.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
import sys
from rflib import *
import rflib.chipcon_nic as rfnic
import atexit
from libtoorchat import *
def banner():
print "******** ToorChat [v 0.1] ********"
def main():
banner()
badge = RfCat(idx=0)
badge.setModeRX()
protocol = ToorChatProtocol(badge)
while True:
try:
print badge.RFrecv()
# print msg
except ChipconUsbTimeoutException:
pass
if __name__ == '__main__':
main()

View File

@ -16,10 +16,10 @@ def main():
protocol = ToorChatProtocol(badge) protocol = ToorChatProtocol(badge)
while True: while True:
try: try:
msg, timestamp = badge.RFrecv() # msg, timestamp = badge.RFrecv()
print "enter a message" # print "enter a message"
# send = input("Enter a message") send = raw_input("Enter a message\n")
# protocol.send_message(send) protocol.send_message(send)
except ChipconUsbTimeoutException: except ChipconUsbTimeoutException:
pass pass