You should check out the C function strtok() for separating the string into its pieces, and atoi() to convert the string pieces to ints. There should be quite a few references to those here on the forum.
struct PacketData {
int first;
int second;
int third;
int fourth;
};
void setup() {
Serial.begin(9600);
}
void loop() {
const char* inString = "%%,8,7135,4563,5687,@";
PacketData newData;
parsePacket(inString, newData);
Serial.println(newData.first);
Serial.println(newData.second);
Serial.println(newData.third);
Serial.println(newData.fourth);
delay(5000);
}
void parsePacket(const char* str, PacketData& data) {
char* ptr = str; // create a pointer pointed to the first position in the string
ptr = strchr(ptr, ','); // move the pointer to the first comma
ptr++; // move the pointer one position
data.first = atoi(ptr); // parse the value as an int
ptr = strchr(ptr, ','); // move the pointer to the next comma, etc
ptr++;
data.second = atoi(ptr);
ptr = strchr(ptr, ',');
ptr++;
data.third = atoi(ptr);
ptr = strchr(ptr, ',');
ptr++;
data.fourth = atoi(ptr);
}
To overcome that you could either declare your function as void parseData(const char* data, uint16_t length) or do a typecast in the call sscanf((const char*)data, ...).
If your string now starts with two dollar signs ($$) you will have to remove the two percent signs in your format string otherwise your string would be expected to start with "%$$....".