7 kyu

Compose protocol packet

86 of 131AlexPuts

Description:

There is a spaceship waiting on launchpad. In order to fuel it you are assigned to do some work.

Your task is to compose simple packet for a protocol.
In other words you should populate a byte array with data in order determined by a specification.

Fields:

Start flag ID number State Scenario mask Volume Status End flag CRC
1 byte 4 bytes 2 bytes 12 bytes 6 bytes 4 bytes 1 byte 1 byte
HEX HEX ASCII HEX ASCII HEX ASCII DEC ASCII HEX ASCII HEX HEX
0x2 "0000"..."FFFF" "00"..."7F" "000000000000"..."FFFFFFFFFFFF" "000000"..."999999" "00FF"..."FFFF" 0x3 0..FF

Flag fields used to identify start and end of message are constant:
Start flag = 0x2
End flag = 0x3

Function return value is:
Success : 1
Failure : -1
Function should return failure (-1) if data was out of range specified in table.
If function returns failure (-1) no data should be written to the passed pointer.

Note:
CRC is calculated only considering data between Start and End flags.
To calculate CRC you should use provided function (already implemented):

unsigned char crc8(const unsigned char *pc_block, unsigned int len);
/* 
const unsigned char *pc_block - const pointer at the beginning of array crc is calculated for.
unsigned int len - amount of bytes to calculate crc for, starting from pc_block pointer.
*/
Arrays
Fundamentals

Stats:

CreatedMay 9, 2018
PublishedMay 12, 2018
Warriors Trained487
Total Skips54
Total Code Submissions1092
Total Times Completed131
C Completions86
C++ Completions50
Total Stars19
% of votes with a positive feedback rating80% of 41
Total "Very Satisfied" Votes28
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes3
Total Rank Assessments3
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • AlexPuts Avatar
  • kazk Avatar
  • Voile Avatar
Ad