Skip to content
Snippets Groups Projects
Commit 127c17d6 authored by Nicolò Caruso's avatar Nicolò Caruso
Browse files

[ARP] Ethernet spoofing for rocket messages

Now the Hub do take into consideration the messages as MAIN for spoofing.
If received from ethernet is treated as if received from the radio.
Also, the messages are also considered if older than 10seconds, to avoid discarding packets if the main has been reset.
parent 31c2dd8d
No related branches found
No related tags found
No related merge requests found
Pipeline #10725 failed
...@@ -60,6 +60,7 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) ...@@ -60,6 +60,7 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg)
sendNack(msg, 306); sendNack(msg, 306);
} }
// Message for ARP
if (msg.sysid == MAV_SYSID_ARP) if (msg.sysid == MAV_SYSID_ARP)
{ {
switch (msg.msgid) switch (msg.msgid)
...@@ -239,6 +240,18 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg) ...@@ -239,6 +240,18 @@ void Hub::dispatchOutgoingMsg(const mavlink_message_t& msg)
} }
} }
} }
// In case the message is spoofed from ethernet by another groundstation
if (msg.sysid == MAV_SYSID_MAIN)
{
TRACE(
"[info] Hub: A MAIN packet was received from ground packet (not "
"radio)\n");
/* The message received by ethernet (outgoing) in reality is not a
* command but the telemetry spoofed, therefore is then used as incoming
*/
dispatchIncomingMsg(msg);
}
} }
void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) void Hub::dispatchIncomingMsg(const mavlink_message_t& msg)
...@@ -255,6 +268,13 @@ void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) ...@@ -255,6 +268,13 @@ void Hub::dispatchIncomingMsg(const mavlink_message_t& msg)
{ {
mavlink_rocket_flight_tm_t rocketTM; mavlink_rocket_flight_tm_t rocketTM;
mavlink_msg_rocket_flight_tm_decode(&msg, &rocketTM); mavlink_msg_rocket_flight_tm_decode(&msg, &rocketTM);
uint64_t timestamp = mavlink_msg_rocket_flight_tm_get_timestamp(&msg);
/* Messages older and within the discard interval are treated as old
* messages*/
if (timestamp <= lastFlightTMTimestamp &&
lastFlightTMTimestamp > timestamp + DISCARD_MSG_DELAY)
return;
lastFlightTMTimestamp = timestamp;
NASState nasState{ NASState nasState{
mavlink_msg_rocket_flight_tm_get_timestamp(&msg), mavlink_msg_rocket_flight_tm_get_timestamp(&msg),
Eigen::Matrix<float, 13, 1>( Eigen::Matrix<float, 13, 1>(
...@@ -273,6 +293,12 @@ void Hub::dispatchIncomingMsg(const mavlink_message_t& msg) ...@@ -273,6 +293,12 @@ void Hub::dispatchIncomingMsg(const mavlink_message_t& msg)
{ {
mavlink_rocket_stats_tm_t rocketST; mavlink_rocket_stats_tm_t rocketST;
mavlink_msg_rocket_stats_tm_decode(&msg, &rocketST); mavlink_msg_rocket_stats_tm_decode(&msg, &rocketST);
/* Messages older and within the discard interval are treated as old
* messages*/
if (rocketST.timestamp <= lastStatsTMTimestamp &&
lastStatsTMTimestamp > rocketST.timestamp + DISCARD_MSG_DELAY)
return;
lastStatsTMTimestamp = rocketST.timestamp;
GPSData gpsState; GPSData gpsState;
gpsState = getRocketOrigin(); gpsState = getRocketOrigin();
......
...@@ -42,6 +42,13 @@ class BoardStatus; ...@@ -42,6 +42,13 @@ class BoardStatus;
namespace Antennas namespace Antennas
{ {
/* This is used to avoid discarding messages in case the rocket timestamp is
* reset. Therefore if older than the discard msg delay, resets the messages
* last timestamp */
static constexpr uint64_t DISCARD_MSG_DELAY =
10 * 1000000; ///< Maximum time for which the message, if older is
///< discarded. [micros]
/** /**
* @brief Central hub connecting all outgoing and ingoing modules. * @brief Central hub connecting all outgoing and ingoing modules.
*/ */
...@@ -97,6 +104,8 @@ private: ...@@ -97,6 +104,8 @@ private:
miosix::FastMutex coordinatesMutex; miosix::FastMutex coordinatesMutex;
miosix::FastMutex nasStateMutex; miosix::FastMutex nasStateMutex;
bool flagNasSet = false; bool flagNasSet = false;
uint64_t lastFlightTMTimestamp;
uint64_t lastStatsTMTimestamp;
}; };
} // namespace Antennas } // namespace Antennas
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment