Skip to content

Bug in response handling semantics #12

@sadfsdfsdaf

Description

@sadfsdfsdaf

When acknowledge enabled some modules may send only response and no acknowledge.
For example "MH2024K-24SS". Library behaves badly in this and similar situations.
The problem code is here:

    case 0x4F:
      _isAvailable = true;
// _handleType=TimeOut-1; // placeholder
      break;

Here _handleType will have previous (uninitialized) value, in case the previous value was TimeOut then the timeout will be received. Problem is generated here:

bool DFRobotDFPlayerMini::waitAvailable(){
  _isSending = true;
  while (!available()){
    delay(0);
  }
  return _handleType != TimeOut;
}

By forcing the standard example to run myDFPlayer.readFileCountsInFolder(1); the code here will return TimeOut two times:

  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }

Result of myDFPlayer.readFileCountsInFolder(1); will be -1.

Correct answer should be number and one TimeOut value.

Here goes the command denoted as "<" and response from MH2024K-24SS denoted as ">" and response from YX5200-24SS denoted as "="

Query number of files in folder 1 (with acknowledge):
< 0x7E 0xFF 0x06 0x4E 0x01 0x00 0x01 0xFE 0xAB 0xEF
> 0x7E 0xFF 0x06 0x4E 0x00 0x00 0x05 0xFE 0xA8 0xEF
= 0x7E 0xFF 0x06 0x41 0x00 0x00 0x00 0xFE 0xBA 0xEF 0x7E 0xFF 0x06 0x4E 0x00 0x00 0x05 0xFE 0xA8 0xEF

The code inside void DFRobotDFPlayerMini::parseStack() should be reanalyzed and rewritten to avoid usage of uninitialized variables. My _handleType=TimeOut-1; is just a placeholder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions