33 static SerialSim instance;
39 this->stateMachine = stateMachine;
44 serial->write(
"START\n");
46 if (serial->available() > 0) {
56 int availableBytes = serial->available();
58 while (serial->available() > 0) {
59 char c =
static_cast<char>(serial->read());
64 handleIncomingLine(_partialLine);
74 return serial->available() > 0;
79 timestamp = _timestamp;
83 accel->acceleration.x = accel_x;
84 accel->acceleration.y = accel_y;
85 accel->acceleration.z = accel_z;
89 gyro->gyro.x = gyro_x;
90 gyro->gyro.y = gyro_y;
91 gyro->gyro.z = gyro_z;
95 mag->magnetic.x = magnetic_x;
96 mag->magnetic.y = magnetic_y;
97 mag->magnetic.z = magnetic_z;
109 temp.temperature = _temp;
114 SerialSim(
const SerialSim&) =
delete;
115 SerialSim& operator=(
const SerialSim&) =
delete;
118 void handleIncomingLine(String &line) {
120 if (line.length() < 5) {
126 _timestamp = parseNextFloat(line);
127 accel_x = parseNextFloat(line);
128 accel_y = parseNextFloat(line);
129 accel_z = parseNextFloat(line);
130 _alt = parseNextFloat(line);
147 float parseNextFloat(String &data) {
148 int commaIndex = data.indexOf(
',');
149 if (commaIndex == -1) {
151 float val = data.toFloat();
157 float value = data.substring(0, commaIndex).toFloat();
159 data = data.substring(commaIndex + 1);
165 serial->write(stateMachine->getState());
170 Stream* serial =
nullptr;
171 BaseStateMachine* stateMachine =
nullptr;
175 float _timestamp = 0;
176 float accel_x = 0, accel_y = 0, accel_z = 0;
177 float gyro_x = 0, gyro_y = 0, gyro_z = 0;
178 float magnetic_x = 0, magnetic_y = 0, magnetic_z = 0;