The aim of this coding challenge is to prove general development skills and basic understanding of the typical challenges in embedded development.
In this challenge you are required to handle communication over a (simulated) serial interface. Your program must have the following features:
- Receive data via a (simulated) interrupt.
- Parse incoming data for messages defined in the protocol below.
- Send the required responses.
- Print all messages (received and sent) in a human readable format to the console.
Upload your solution as a git repository to one of the public platforms (e.g. GitHub or Bitbucket).
- Messages are encoded as binary TLV (type-length-value) messages.
- The type and length field are encoded as the higher and lower four bits, respectively, of the first byte of each message.
- The value contains the payload with as many bytes as given by the length value.
Type | Length | Name | Payload |
---|---|---|---|
1 | 0 | Empty | None |
2 | 4 | Add | Two 16-bit unsigned integers |
3 | 2 | Result | One 16-bit unsigned integer |
4 | 3 | Delay | 16-bit unsigned integer and opaque data byte |
5 | 1 | Timeout | Opaque data byte |
6 | N | Log | String of N ASCII encoded characters |
- Respond to
Empty
messages with anEmpty
message. - Respond to
Add
message with aResult
message containing the sum of the numbers in theAdd
message. - Respond to
Delay
messages with aTimeout
message. The integer in theDelay
message represents a duration in milliseconds. TheTimeout
message should be send after this duration has elapsed. The payload of theTimeout
message should contain the data byte received with theDelay
message.
- Add your code in
src/challenge.c
, none of the other source file should be modified. - The project is built using CMake and GCC. If you add additional source files they need to be added to the CMakeLists.txt file.
- All data must be encoded in network byte-order, i.e. big-endian.
- This challenge uses FreeRTOS (Posix-Port) to simulate hardware interrupts and preemption on a desktop machine.
- You can also use FreeRTOS features to implement your solution. This is recommended, but not mandatory.
- The test cases don't contain multiple pending delays simultaneously, but you get bonus points if your solution could handle that.
- Install dependencies:
- Windows: Use the Windows-Subsytem for Linux (WSL) and do the same as on Ubuntu.
- Ubuntu:
sudo apt-get install git cmake
- MacOS:
brew install git cmake
- Clone the repository:
git clone ...
- Create a build directory
mkdir build && cd build
- Setup build:
cmake ..
- Build:
make
- Run:
./coding_challenge