36template <
class FlightPhases,
class SimulatorData,
class ActuatorData>
66 miosix::Lock<miosix::FastMutex> l(
mutex);
87template <
class FlightPhases,
class SimulatorData,
class ActuatorData>
98 ActuatorData>* hilPhasesManager)
100 hilPhasesManager(hilPhasesManager)
113 miosix::Lock<miosix::FastMutex> l(
mutex);
119 this->actuatorData = actuatorData;
134 SimulatorData simulatorData;
135 ActuatorData actuatorData;
136 HILPhasesManager<FlightPhases, SimulatorData, ActuatorData>*
150template <
class FlightPhases,
class SimulatorData,
class ActuatorData>
151void HILTransceiver<FlightPhases, SimulatorData, ActuatorData>::run()
153 LOG_INFO(logger,
"HIL Transceiver started");
154 hilSerial.clearQueue();
157 hilSerial.write(&actuatorData,
sizeof(ActuatorData));
160 while (!shouldStop())
164 SimulatorData tempData;
168 if (!hilSerial.readBlocking(&tempData,
sizeof(SimulatorData),
171 LOG_ERR(logger,
"Failed serial read");
174 assert(nRead ==
sizeof(SimulatorData) &&
175 "Read less then SimulatorData bytes");
177 hilSerial.clearQueue();
180 miosix::PauseKernelLock kLock;
181 simulatorData = tempData;
182 timestampSimulatorData = miosix::getTime();
187 if (!receivedFirstPacket)
189 receivedFirstPacket =
true;
190 hilPhasesManager->simulationStarted();
194 hilPhasesManager->processFlags(simulatorData);
196 if (nLostUpdates > 0)
201 LOG_WARN(logger,
"%d Lost updates", nLostUpdates);
206 hilSerial.write(&actuatorData,
sizeof(ActuatorData));
#define LOG_WARN(logger,...)
#define LOG_INFO(logger,...)
#define LOG_ERR(logger,...)
Singleton object that manages all the phases of the simulation. After his instantiation we need to se...
miosix::ConditionVariable condVar
void waitActuatorData()
Waits for the control algorithm(s) to update actuatorData.
int getLostUpdates() const
Returns the number of lost updates.
int64_t timestampSimulatorData
HILTransceiverBase(USART &hilSerial)
Construct a serial connection attached to a control algorithm.
int64_t getTimestampSimulatorData() const
Returns the value in ns of the timestamp of the last received simulatorData.
HILTransceiver is a Singleton and provides an easy interface for the control algorithms to send and r...
HILTransceiver(USART &hilSerial, HILPhasesManager< FlightPhases, SimulatorData, ActuatorData > *hilPhasesManager)
Construct a serial connection attached to a control algorithm.
const SimulatorData * getSensorData() const
returns the reference of the SimulatorData
void setActuatorData(ActuatorData actuatorData)
sets the actuator data and then wakes up the MatlabTransceiver thread in order to send the data back ...
static PrintLogger getLogger(const string &name)
Driver for STM32F4 low level USART/UART peripheral.
This file includes all the types the logdecoder script will decode.