From b90d422352de8a1cc563023952753579a25088be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mart=C3=ADn=20Ra=C3=BAl=20Villalba?= Date: Mon, 19 Sep 2011 15:57:55 -0300 Subject: [PATCH] Fix assorted errors (#7) --- src/ant/core/message.py | 68 +++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/src/ant/core/message.py b/src/ant/core/message.py index 6a9b9d8..3d59bfc 100644 --- a/src/ant/core/message.py +++ b/src/ant/core/message.py @@ -122,13 +122,14 @@ class AssignChannelMessage(ChannelMessage): return ord(self.getPayload()[1]) def setChannelType(self, type): - self.payload[1] = chr(type) + self.getPayload()[1] = chr(type) def getNetworkNumber(self): return ord(self.getPayload()[2]) def setNetworkNumber(self): - self.payload[2] = chr(type) + self.setPayload(self.getPayload()[0:2] + chr(type) + + self.getPayload()[3:]) class ChannelIDMessage(ChannelMessage): def __init__(self, number=0x00, device_number=0x00, device_type=0x00, @@ -138,24 +139,26 @@ class ChannelIDMessage(ChannelMessage): payload=payload, number=number) def getDeviceNumber(self): - return struct.unpack(' 0xFF) or (message_id < 0x00): - raise MessageError('Could not set channel number ' \ + raise MessageError('Could not set message ID ' \ '(out of range).') self.setPayload(self.getPayload()[0] + @@ -292,11 +294,11 @@ class ChannelEventMessage(ChannelMessage): number=number) def getMessageID(self): - return ord(self.payload[1]) + return ord(self.getPayload()[1]) def setMessageID(self, message_id): if (message_id > 0xFF) or (message_id < 0x00): - raise MessageError('Could not set channel number ' \ + raise MessageError('Could not set message ID ' \ '(out of range).') self.setPayload(self.getPayload()[0] + @@ -304,11 +306,11 @@ class ChannelEventMessage(ChannelMessage): self.getPayload()[2:]) def getMessageCode(self): - return ord(self.payload[2]) + return ord(self.getPayload()[2]) def setMessageCode(self, message_code): if (message_code > 0xFF) or (message_code < 0x00): - raise MessageError('Could not set channel number ' \ + raise MessageError('Could not set message code ' \ '(out of range).') self.setPayload(self.getPayload()[0:2] + @@ -322,7 +324,7 @@ class ChannelStatusMessage(ChannelMessage): payload=chr(status), number=number) def getStatus(self): - return ord(self.payload[1]) + return ord(self.getPayload()[1]) def setStatus(self, status): if (status > 0xFF) or (status < 0x00): @@ -344,7 +346,7 @@ class VersionMessage(Message): def setVersion(self, version): if (len(version) != 9): raise MessageError('Could not set ANT version ' \ - '(expected 9 bytes).')i + '(expected 9 bytes).') self.setPayload(version) -- 2.11.4.GIT