Hi,
I'm working on a project which transmits serial char array to receiver. I want to convert that char array in to my struct format. Can someone help me to solve this issue
//serial array format => |number of relayIDS|state|configuration|relay IDs|
char bufferData[32] = "5,h,l,1,2,3,4,5";
struct SerialPacket
{
int payloadSize;
char state;
char configuation; // A -> Append, S -> SetRelays, C-> Clear all;
int relayIDS[35];
}m_packet;
m_packet.payloadSize = atol(bufferData);
m_packet.state = bufferData[2];
m_packet.configuation = bufferData[4];
I extracted above values. But I don't know how to extract relayIDS. (1,2,3,4,5). (number of relay IDS may change)
As many creators You're home blind. What are You talking about?
You need to explain the type, the organisation of the source data.
What is the source and data types, and what do You want to convert it to?
Packet format is :
|number of relay ids|relay state(h-high/l-low)|relay settings (which function should the streamer call (C- off all, S - config etc)| relay ids|
Also, it could be simplified a lot if you could reduce the size of relayIDS to 32, you would need a single 32-bits variable where each bit is the state of one relay
Or at least change the type of relayIDS (and payloadSize) to uint8_t
I tried running it on an esp32 and there's definitely something wrong on that platform. It seemed to me like the strtok function returns a null pointer every call for some reason. It might have something to do with all the stuff going on under the hood in the esp32 arduino core.
I'm off for work now and I'm really not all that familiar with the esp32, so I think my investigation is done for now, since you've gotten another snippet of code that seems to work for you.
Maybe because you run the code in loop() indefinitely. After the first call to parsePayload, bufferData has been modified ( , were replaced by \0 ) so the next calls to parsePayload will fail