Skip to content

Commit

Permalink
add sitl restart callback
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Jun 17, 2024
1 parent 04a927e commit 65b12b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions Src/platform/ubuntu/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static inline uint32_t HAL_GetUIDw2() {return 0;}

uint32_t HAL_GetTick();
void HAL_NVIC_SystemReset();
void uavcanRestartNode();

uint32_t uavcanGetTimeMs();

Expand Down
21 changes: 20 additions & 1 deletion Src/platform/ubuntu/platform_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

#include <string.h>
#include <unistd.h>
#include <chrono> // NOLINT [build/c++11]
#include <cstdlib>
#include <iostream>
#include "main.h"
#include "application.hpp"
Expand All @@ -23,7 +25,24 @@ void uavcanReadUniqueID(uint8_t out_uid[4]) {
}

void uavcanRestartNode() {
// do nothing
std::cout << "Restarting application..." << std::endl;

// Get the current executable path
char path[1024];
ssize_t count = readlink("/proc/self/exe", path, sizeof(path));
if (count == -1) {
std::cerr << "Error getting executable path." << std::endl;
exit(1);
}

path[count] = '\0';

// Execute a new instance of the current application
execl(path, path, (char *)NULL);

// If execl returns, an error occurred
std::cerr << "Error restarting application." << std::endl;
exit(1);
}

uint32_t uavcanGetTimeMs() {
Expand Down

0 comments on commit 65b12b3

Please sign in to comment.