summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-12-09 04:38:07 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-12-12 00:43:18 +0700
commit810b696b8d5d0b8a2c8bb0a596d34e43f4de764c (patch)
tree5c57fbeefddd390604c74962c3775196e407f151 /src
parent1dcc45beff210037311d7862cdf4e1ec1cd730a5 (diff)
trx_toolkit/data_if.py: add message parsing methods
This change extends DATAInterface class with new methods: - recv_raw_data() - read raw data from socket; - recv_l12trx_msg() - read raw data and parse as L12TRX; - recv_trx2l1_msg() - read raw data and parse as TRX2L1; which would simplify the further usage of this class. Change-Id: I761c4e63864622d3882b8f9c80ea43b58f092cb1
Diffstat (limited to 'src')
-rw-r--r--src/target/trx_toolkit/data_if.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/target/trx_toolkit/data_if.py b/src/target/trx_toolkit/data_if.py
index f4431a4..45114ed 100644
--- a/src/target/trx_toolkit/data_if.py
+++ b/src/target/trx_toolkit/data_if.py
@@ -26,6 +26,39 @@ from udp_link import UDPLink
from data_msg import *
class DATAInterface(UDPLink):
+ def recv_raw_data(self):
+ data, _ = self.sock.recvfrom(512)
+ return data
+
+ def recv_l12trx_msg(self):
+ # Read raw data from socket
+ data = self.recv_raw_data()
+
+ # Attempt to parse as a L12TRX message
+ try:
+ msg = DATAMSG_L12TRX()
+ msg.parse_msg(bytearray(data))
+ except:
+ log.error("Failed to parse a L12TRX message "
+ "from R:%s:%u" % (self.remote_addr, self.remote_port))
+ return None
+
+ return msg
+
+ def recv_trx2l1_msg(self):
+ # Read raw data from socket
+ data = self.recv_raw_data()
+
+ # Attempt to parse as a L12TRX message
+ try:
+ msg = DATAMSG_TRX2L1()
+ msg.parse_msg(bytearray(data))
+ except:
+ log.error("Failed to parse a TRX2L1 message "
+ "from R:%s:%u" % (self.remote_addr, self.remote_port))
+ return None
+
+ return msg
def send_msg(self, msg):
# Validate a message