39#define LINUX_UID_FILE ""
48 if (path[0] ==
'\0') {
51 FILE *
f = fopen(path,
"r");
56 if (fgets(line,
sizeof(line),
f) != NULL) {
57 line[strcspn(line,
"\r\n")] =
'\0';
58 len =
Min(strlen(line), max_len);
59 memcpy(uid, line, len);
70 DIR *
dir = opendir(
"/sys/class/net");
74 char best_name[64] =
"";
77 while ((ent = readdir(
dir)) != NULL) {
80 if (ent->d_name[0] ==
'.' || strcmp(ent->d_name,
"lo") == 0 ||
81 strlen(ent->d_name) >=
sizeof(best_name) ||
82 (best_name[0] !=
'\0' && strcmp(ent->d_name, best_name) >= 0)) {
85 snprintf(path,
sizeof(path),
"/sys/class/net/%s/address", ent->d_name);
86 FILE *
f = fopen(path,
"r");
90 int n = fscanf(
f,
"%x:%x:%x:%x:%x:%x", &m[0], &m[1], &m[2], &m[3], &m[4], &m[5]);
92 if (n != 6 || (m[0] | m[1] | m[2] | m[3] | m[4] | m[5]) == 0) {
95 strcpy(best_name, ent->d_name);
96 for (
int i = 0; i < 6; i++) {
101 if (best_name[0] ==
'\0') {
105 memcpy(uid, best_mac, len);
124#include "message_pragmas.h"
139static void sig_handler(
int signo)
141 static int nb_signal = 0;
143 if (signo == SIGINT) {
144 printf(
"Received SIGINT\n");
145 if (nb_signal == 0) {
146 printf(
"Press Ctrl-C again to stop the program\n");
149 printf(
"Leaving now\n");
158 sigemptyset(&sa.sa_mask);
160 sa.sa_handler = &sig_handler;
161 if (sigaction(SIGINT, &sa, NULL) == -1) {
162 printf(
"Can't catch SIGINT\n");
void mcu_arch_init(void)
Initialize the specific archittecture functions.
uint8_t mcu_get_uid(uint8_t *uid, uint8_t max_len)
Get the 96-bit unique device ID of the STM32.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
#define LINUX_UID_FILE
Optional file with a unique board serial number (read as text).
static uint8_t uid_from_file(const char *path, uint8_t *uid, uint8_t max_len)
Read the first line of a text file as unique ID.
static uint8_t uid_from_mac(uint8_t *uid, uint8_t max_len)
Get the MAC address of the first network interface (by name), skipping loopback.
linux arch dependant microcontroller initialisation functions.
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup).