Skip to content

Commit 8e14697

Browse files
committed
packets: fix the string encoding and decoding in some packets
Signed-off-by: Diego Escalona <diego.escalona@digi.com>
1 parent 5a2299b commit 8e14697

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

digi/xbee/packets/common.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def create_packet(raw, operating_mode):
9696
if raw[3] != ApiFrameType.AT_COMMAND.code:
9797
raise InvalidPacketException("This packet is not an AT command packet.")
9898

99-
return ATCommPacket(raw[4], str(raw[5:7]), raw[7:-1])
99+
return ATCommPacket(raw[4], raw[5:7].decode("utf8"), raw[7:-1])
100100

101101
def needs_id(self):
102102
"""
@@ -115,8 +115,8 @@ def _get_api_packet_spec_data(self):
115115
| :meth:`.XBeeAPIPacket._get_api_packet_spec_data`
116116
"""
117117
if self.__parameter is not None:
118-
return bytearray(self.__command, 'utf8') + self.__parameter
119-
return bytearray(self.__command, 'utf8')
118+
return bytearray(self.__command, "utf8") + self.__parameter
119+
return bytearray(self.__command, "utf8")
120120

121121
def _get_api_packet_spec_data_dict(self):
122122
"""
@@ -259,7 +259,7 @@ def create_packet(raw, operating_mode):
259259
if ATCommandStatus.get(raw[7]) is None:
260260
raise InvalidPacketException("Invalid command status.")
261261

262-
return ATCommResponsePacket(raw[4], raw[5:7].decode(), ATCommandStatus.get(raw[7]), raw[8:-1])
262+
return ATCommResponsePacket(raw[4], raw[5:7].decode("utf8"), ATCommandStatus.get(raw[7]), raw[8:-1])
263263

264264
def needs_id(self):
265265
"""
@@ -277,7 +277,7 @@ def _get_api_packet_spec_data(self):
277277
.. seealso::
278278
| :meth:`.XBeeAPIPacket._get_api_packet_spec_data`
279279
"""
280-
ret = bytearray(self.__command)
280+
ret = bytearray(self.__command, "utf8")
281281
ret.append(self.__response_status.code)
282282
if self.__comm_value is not None:
283283
ret += self.__comm_value
@@ -680,10 +680,10 @@ def create_packet(raw, operating_mode):
680680

681681
return RemoteATCommandPacket(
682682
raw[4],
683-
XBee64BitAddress(raw[5:12]),
683+
XBee64BitAddress(raw[5:13]),
684684
XBee16BitAddress(raw[13:15]),
685685
raw[15],
686-
str(raw[16:18]),
686+
raw[16:18].decode("utf8"),
687687
raw[18:-1]
688688
)
689689

@@ -706,7 +706,7 @@ def _get_api_packet_spec_data(self):
706706
ret = self.__x64bit_addr.address
707707
ret += self.__x16bit_addr.address
708708
ret.append(self.__transmit_options)
709-
ret += bytearray(self.__command, 'utf8')
709+
ret += bytearray(self.__command, "utf8")
710710
return ret if self.__parameter is None else ret + self.__parameter
711711

712712
def _get_api_packet_spec_data_dict(self):
@@ -936,7 +936,7 @@ def create_packet(raw, operating_mode):
936936
raise InvalidPacketException("This packet is not a remote AT command response packet.")
937937

938938
return RemoteATCommandResponsePacket(raw[4], XBee64BitAddress(raw[5:13]),
939-
XBee16BitAddress(raw[13:15]), str(raw[15:17].decode()),
939+
XBee16BitAddress(raw[13:15]), raw[15:17].decode("utf8"),
940940
ATCommandStatus.get(raw[17]), raw[18:-1])
941941

942942
def needs_id(self):
@@ -957,7 +957,7 @@ def _get_api_packet_spec_data(self):
957957
"""
958958
ret = self.__x64bit_addr.address
959959
ret += self.__x16bit_addr.address
960-
ret += bytearray(self.__command)
960+
ret += bytearray(self.__command, "utf8")
961961
ret.append(self.__response_status.code)
962962
if self.__comm_value is not None:
963963
ret += self.__comm_value
@@ -1810,7 +1810,7 @@ def _get_api_packet_spec_data(self):
18101810
"""
18111811
ret = self.__x64bit_addr.address
18121812
ret += self.__x16bit_addr.address
1813-
ret.append(self.__receive_options.code)
1813+
ret.append(self.__receive_options)
18141814
if self.__rf_data is not None:
18151815
ret += self.__rf_data
18161816
return ret

digi/xbee/packets/devicecloud.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def create_packet(raw, operating_mode):
9696
raise InvalidPacketException("This packet is not a device request packet.")
9797

9898
target_length = raw[7]
99-
return DeviceRequestPacket(raw[4], str(raw[8:8 + target_length]), raw[8 + target_length:-1])
99+
return DeviceRequestPacket(raw[4], raw[8:8 + target_length].decode("utf8"), raw[8 + target_length:-1])
100100

101101
def needs_id(self):
102102
"""
@@ -119,7 +119,7 @@ def _get_api_packet_spec_data(self):
119119
ret += utils.int_to_bytes(self.__flags, num_bytes=1)
120120
if self.__target is not None:
121121
ret += utils.int_to_bytes(len(self.__target), num_bytes=1)
122-
ret += bytearray(self.__target, 'utf8')
122+
ret += bytearray(self.__target, "utf8")
123123
else:
124124
ret += utils.int_to_bytes(0x00, num_bytes=1)
125125
if self.__request_data is not None:
@@ -723,8 +723,8 @@ def create_packet(raw, operating_mode):
723723
path_length = raw[5]
724724
content_type_length = raw[6 + path_length]
725725
return SendDataRequestPacket(raw[4],
726-
str(raw[6:6 + path_length]),
727-
str(raw[6 + path_length + 1:6 + path_length + 1 + content_type_length]),
726+
raw[6:6 + path_length].decode("utf8"),
727+
raw[6 + path_length + 1:6 + path_length + 1 + content_type_length].decode("utf8"),
728728
SendDataRequestOptions.get(raw[6 + path_length + 2 + content_type_length]),
729729
raw[6 + path_length + 3 + content_type_length:-1])
730730

digi/xbee/packets/wifi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def _get_api_packet_spec_data(self):
407407
"""
408408
ret = bytearray(self.__dest_address.packed)
409409
ret += utils.int_to_bytes(self.__transmit_options, num_bytes=1)
410-
ret += bytearray(self.__command, 'utf8')
410+
ret += bytearray(self.__command, "utf8")
411411
if self.__parameter is not None:
412412
ret += self.__parameter
413413
return ret

0 commit comments

Comments
 (0)