I’m not very good at C++, can you help me in finding what is wrong:
char filename[13];
sprintf(filename, "HELLO%d.MP3", random(8));
Serial.print("Play `");
Serial.print(filename);
Serial.println("`");
player.singlePlayName(filename);
In the module
void Garan::singlePlayName(char *name) {
Serial.print("Here goes ");
Serial.print(strlen(name));
Serial.println(name);
strcpy((char *)&_commandBuff[3], name);
buildHead(strlen(name) + 2, 4);
sendCommand(_commandBuff);
//_serial.begin(9600);
}
And sendCommand
void Garan::sendCommand(uint8_t command[]) {
uint8_t checksum = 0;
_serial.write(0x24);
Serial.write(0x24);
for (uint16_t i = 0; i <= command[0]; i++) {
_serial.write(command[i]);
Serial.write(command[i]);
checksum ^= command[i];
}
_serial.write(checksum);
Serial.write(checksum);
}
I’ve added Serial prints for debugging
Name is passed to singlePlayName command, it’s length is 10, but it is not getting copied to command and is not sent to serial
Red box here should contain filename, but it does not http://screenshots.ryotsuke.ru/scr_58b766061e58.png
Command send should be 0x24 0x0C 0x04 filename 0xchecksum
Apparantly strcpy is doing something not right
Can you help me spotting the issue?