Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvh4 committed Sep 10, 2018
1 parent 95c0100 commit b7c8d7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
21 changes: 4 additions & 17 deletions RoveComm_Python.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
print (bytes, address)
print (struct.unpack('L', test_byte))
'''

ROVECOMM_PORT = 11000
ROVECOMM_VERSION = 1 #ToDo: Change in RC2
ROVECOMM_HEADER_FORMAT = ">BHBHH"
Expand All @@ -35,14 +36,14 @@ def __init__(self, port=ROVECOMM_PORT):
self.RoveCommSocket = socket.socket(type = socket.SOCK_DGRAM)
self.RoveCommSocket.bind(("", self.rove_comm_port))

def write( self, data_id, data_size, data): #RC2: add data_type, data_count
def write(self, data_id, data_size, data): #RC2: add data_type, data_count
if not isinstance(data, bytes):
raise ValueError('Must pass data as a packed struct, Data: ' + str(data))

rovecomm_packet = struct.pack(ROVECOMM_HEADER_FORMAT, ROVECOMM_VERSION, ROVCOMM_SEQ_NUM, ROVECOMM_FLAGS, data_id, data_size) + data #Todo: Debug

for subscriber in self.subscribers:
RoveCommSocket.sendto(rovecomm_packet, (subscriber, 11000))
self.RoveCommSocket.sendto(rovecomm_packet, (subscriber))

def writeTo(self, data_id, data_size, data, ip_address, port=ROVECOMM_PORT): #RC2: add data_type, data_count
if not isinstance(data, bytes):
Expand All @@ -56,7 +57,7 @@ def read(self):
packet, remote_ip = self.RoveCommSocket.recvfrom(1024)
header_size = struct.calcsize(ROVECOMM_HEADER_FORMAT)

rovecomm_version, seq_num, flags, data_id, data_size = struct.unpact(ROVECOMM_HEADER_FORMAT, packet[0:header_size])
rovecomm_version, seq_num, flags, data_id, data_size = struct.unpack(ROVECOMM_HEADER_FORMAT, packet[0:header_size])
data = packet[header_size:]

if(data_id == ROVECOMM_SUBSCRIBE_REQUEST):
Expand All @@ -68,18 +69,4 @@ def read(self):

return (data_id, data_size, data)


#def readFrom ToDo: Change to getLastIp for C++ and Python

'''
local_host_ip = "127.0.0.1"
RoveComm = RoveCommEthernetUdp()
RoveComm.writeTo(5, 6, struct.pack('>L', 7), local_host_ip)
my_data_id, my_data_size, my_data = RoveComm.read()
print(my_data_id, my_datpythoa_size)
print(struct.unpack('>L', my_data))
'''


16 changes: 16 additions & 0 deletions RoveComm_Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from RoveComm_Python import RoveCommEthernetUdp
import struct
local_host_ip = "127.0.0.1"
RoveComm = RoveCommEthernetUdp()
RoveComm.writeTo(10, 11, struct.pack('L', 7), local_host_ip)
data_id, data_size, data = RoveComm.read()

print(data_id, data_size, struct.unpack('L', data))

RoveComm.write(4, 11, struct.pack('L', 7))
data_id, data_size, data = RoveComm.read()
print(data_id, data_size, struct.unpack('L', data))
print(RoveComm.subscribers)

RoveComm.writeTo(10, 11, struct.pack('L', 7), local_host_ip)

0 comments on commit b7c8d7d

Please sign in to comment.