-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FW-146] Deserialize packets received from DatagramSocket #22
base: main
Are you sure you want to change the base?
Conversation
self._recv_thread = threading.Thread(target=self._receive, daemon=True) | ||
self._recv_thread.start() | ||
|
||
def _receive(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you change DatagramSocket.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because we want DatagramSocket receive method to block on receive
|
||
ds = DatagramSocket('127.0.0.1', 8800, '127.0.0.1', 8801) | ||
|
||
package_data = [(100, "temp:float32,is_active:bool,state:enum(idle-fault)"), (101, "preasure:int32")] #I assume that it's the format, it might change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, however Juan told me that the package will be a dictionary where the key is the id and the values are only the data_types like this:
1: {"uint16","float32","enum(OFF,ON)"}
if 'enum' in type: | ||
value_data = struct.unpack('<B', buffer[:1])[0] | ||
buffer = buffer[1:] | ||
valores = (re.search(r'\((.*?)\)', type)).group(1).split('-') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow !what a way to do it, I like it
self.dict_measurement_types = {} #key string id of each measurament, contains an array from types | ||
self.dict_measurement_names = {} #contains array of names of each variable | ||
self.dict_measurement_value = {} #contains the value of each measurement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.dict_measurement_types = {} #key string id of each measurament, contains an array from types | |
self.dict_measurement_names = {} #contains array of names of each variable | |
self.dict_measurement_value = {} #contains the value of each measurement | |
self.measurement_types = {} #key string id of each measurament, contains an array from types | |
self.measurement_names = [] #contains array of names of each variable | |
self.measurement_values = {} #contains the value of each measurement |
if bytes_count == bytes_size: | ||
self.deserialize(buff, id_packet) | ||
|
||
buff.clear() | ||
bytes_count = 0 | ||
bytes_size = 0 | ||
wait_new_packet = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the bytes_count is greater than the bytes_size? This part looses packets if you have more than one in the buffer. You should add the bytes to the buffer and then do in a loop:
- Get the ID and the packet size
- If the buffer has enough bytes to deserialize the packet do that
- Remove the processed data from the buffer
- Wait for more data
def calculate_byte_size(self, measurements): | ||
|
||
size = 0 | ||
for measure in measurements: | ||
if measure == 'uint8' or measure == 'int8' or measure == 'bool' or 'enum' in measure: | ||
size += 1 | ||
elif measure == 'uint16' or measure == 'int16': | ||
size += 2 | ||
elif measure == 'uint32' or measure == 'int32' or measure == 'float32': | ||
size += 4 | ||
elif measure == 'uint64' or measure == 'int64' or measure == 'float64': | ||
size += 8 | ||
|
||
return size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
precalculate this in the constructor, the decoding function will be called a lot of times and we want to reduce the time it takes to complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this outside the vmcu package, because we don't want to import it later on, should be on src/test_decoder/...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this outside the vmcu package, because we don't want to import it later on, should be on src/test_decoder/...
Class decoder uses DatagramSocket and take packet UDP
includes a thread that checks packets continuously
Class Datagramsocket thread has been removed and only interact with the Decoder thread
I asume a dictionary model that could be different from the final model