Home > Back-end > Excuse me each bosses, variable length data domain protocol frame parsing problem
Excuse me each bosses, variable length data domain protocol frame parsing problem
Time:03-19
Suppose there is such a protocol consists of the following:
1. 2 bytes of data frames a start bit AA DD 2. The data frame length 2 bytes 00 XX 3. Data domain variable length per 4 bytes for a group of such as 0 0 0 65, 0 f E E represents temperature 0 f c 4. Check digit 2 bytes
4 bytes data domain as a set, assuming that there are 5 groups, but can you tell me how to resolve it? Such as 0 0 f e 00 00 0 c 65 03 02 00 0 a 23 such format
Thank you for your attention
CodePudding user response:
Do you have the data frame length, so is, in fact, you ask?
CodePudding user response:
| start | Command | Data CRC | | | 0 xaa | 0 XDD | part of the need to parse | | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Means how to frame_datafield [] element in the array according to four a set of a set of extracted respectively
CodePudding user response:
Uint8_t * frame=... ;//take the lead in full frame first address Uint8_t (* data) [4]=(uint8_t * [4]) (frame + 4); Short int len=(* (short) int * (frame + 2) - (4)/4.//assume that the frame length including calibration head does not include the tail int i; for(i=0; i{ Do_someting_on data [I]; }
CodePudding user response:
Thank you for your ideas
CodePudding user response:
2 bytes of data frame length must pay attention to the high and low byte sequence, typically using socket function conversion to each other: Htons (), ntohs ()