Here my code...
void rfid_msg(byte opcode, byte* data, int len)
{
byte* msg = new byte[len + 5];
byte response[256];
msg[0] = 0xff;
msg[1] = len;
msg[2] = opcode;
if (len > 0) {
memcpy(&msg[3], data, len);
}
unsigned int tmp = crc(&msg[1], len + 2);
msg[len + 3] = tmp >> 8;
msg[len + 4] = tmp & 0xff;
Serial.write(msg, len + 5);
}
rfid_msg(0x0c, new byte[0], 0);
For this specific 'message' the data to send should be a five byte array with the values
0xff,
0x00,
0x0c,
0x1d,
0x03 (the crc computes that
0x1d,
0x03 thing)...
However the first (and only the first) byte comes as
0x16 - always...
If I change the this line:
byte* msg = new byte[len + 5];
to this:
byte msg[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
(16 bytes is enough for sure)
than everything works perfectly and the first byte comes as
0xff...
Any explanation?