ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
module_test.cpp
Go to the documentation of this file.
1#include "module_test.hpp"
2
4
6
7void ModuleTest::OnReceive(const Esp32Command &cmd) {
8 if (cmd.command.test_command.state == TestCommand_ChangeState_RECEIVE) {
9 // set state to receive
10 this->state = RECEIVE;
11 } else if (cmd.command.test_command.state ==
12 TestCommand_ChangeState_REQUEST) {
13 // set state to request
14 this->state = REQUEST;
15 // store data in buffer
16 this->Int32ToByteArray(cmd.command.test_command.data, this->buffer);
17 // int32 is 4 bytes
18 this->buffer_len = 4;
19 }
20}
21
22size_t ModuleTest::OnRequest(uint8_t *buffer) {
23 // set state to init
24 this->state = INIT;
25
26 // copy internal buffer to tx buffer
27 memcpy(buffer, this->buffer, buffer_len);
28
29 // return length of buffer
30 return this->buffer_len;
31}
32
33void ModuleTest::Int32ToByteArray(int32_t value, uint8_t *buffer) {
34 // Extract the highest byte
35 buffer[0] = (value >> 24) & 0xFF;
36 // Extract the second highest byte
37 buffer[1] = (value >> 16) & 0xFF;
38 // Extract the second lowest byte
39 buffer[2] = (value >> 8) & 0xFF;
40 // Extract the lowest byte
41 buffer[3] = value & 0xFF;
42}
void OnReceive(const Esp32Command &cmd)
Handles i2c receive messages.
ModuleTest(void)
Construct a new Module Test object.
~ModuleTest(void)
Destroy the Module Test object.
size_t OnRequest(uint8_t *buffer)
Handles i2c request messages.
uint8_t buffer[32]