Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Ikubimu
Copy link
Contributor

@Ikubimu Ikubimu commented Jan 5, 2025

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

@Ikubimu Ikubimu requested review from jmaralo and oganigl January 5, 2025 13:51
self._recv_thread = threading.Thread(target=self._receive, daemon=True)
self._recv_thread.start()

def _receive(self):
Copy link
Contributor

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

Copy link
Member

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
Copy link
Contributor

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)"}

src/services/communications/Decoder_Data.py Outdated Show resolved Hide resolved
src/services/communications/Decoder_Data.py Outdated Show resolved Hide resolved
if 'enum' in type:
value_data = struct.unpack('<B', buffer[:1])[0]
buffer = buffer[1:]
valores = (re.search(r'\((.*?)\)', type)).group(1).split('-')
Copy link
Contributor

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

Comment on lines +10 to +12
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

src/vmcu/services/communications/Decoder_Data.py Outdated Show resolved Hide resolved
src/vmcu/services/communications/Decoder_Data.py Outdated Show resolved Hide resolved
src/vmcu/services/communications/Decoder_Data.py Outdated Show resolved Hide resolved
src/vmcu/services/communications/Decoder_Data.py Outdated Show resolved Hide resolved
Comment on lines 60 to 66
if bytes_count == bytes_size:
self.deserialize(buff, id_packet)

buff.clear()
bytes_count = 0
bytes_size = 0
wait_new_packet = True
Copy link
Member

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:

  1. Get the ID and the packet size
  2. If the buffer has enough bytes to deserialize the packet do that
  3. Remove the processed data from the buffer
  4. Wait for more data

Comment on lines 122 to 135
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
Copy link
Member

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

Copy link
Member

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/...

Copy link
Member

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/...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants