rzbrk / PyVoiceRecognitionV3

Python class (driver) for the Elechouse Voice Recognition Module V3
GNU General Public License v3.0
0 stars 0 forks source link

check_record_train_status() returns wrong value for number of trained records #10

Closed rzbrk closed 2 years ago

rzbrk commented 2 years ago

In the result dictionary of method check_record_train_status() the value of key no_trained_records and the number of records that are trained in train_status do not match

rzbrk commented 2 years ago

Example:

>>> vr = PyVoiceRecognitionV3(device=dev)
>>> res = vr.check_record_train_status()
>>> res["train_status"].count("trained")
6
>>> res["no_trained_records"]
2

The entries in res["train_status] are reasonable but res["no_trained_records"] is wrong.

rzbrk commented 2 years ago

The root cause for this bug is that the method checks the wrong byte in the response message from the module (see here). It should check the 4th byte bjut actually checks the 3rd byte. Because the 3rd byte is the command id (\x02) this explains why the same wrong number 2 is returned.

rzbrk commented 2 years ago

Not related to this bug: There might be a bug in the firmware of the module. When checking the train status of all records the module returns multiple messages. Each individual message should repeat the exact number of number of trained redords. However, the first message returns a wrong value:

>>> vr = PyVoiceRecognitionV3(device=dev)
>>> res = vr.check_record_train_status()
>>> res["train_status"].count("trained")
6
>>> for m in res["raw"]:
...     print(m[3],end=" ")
...
5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6

It seems as the value from the very first message is wrong. The values from the following messages are correct.

rzbrk commented 2 years ago

Effectively, the number of trained records is retrieved from the last message returned by the module. The potential bug in the firmware described above seems to effect only the first message. Therefore, the potential firmware bug has no consequence on the output from method check_record_train_status().