Skip to content

Commit

Permalink
feat: add odrone id component
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Mar 3, 2025
1 parent 34f3e5b commit a247dc1
Show file tree
Hide file tree
Showing 19 changed files with 5,269 additions and 0 deletions.
23 changes: 23 additions & 0 deletions firmware/components/odrone_id/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
file(GLOB_RECURSE ALL_SOURCE_FILES "./*.c" "./*.cpp")

set(modules_src "")

foreach(file ${ALL_SOURCE_FILES})
list(APPEND modules_src ${file})
endforeach()

file(GLOB_RECURSE ALL_INCLUDE_PATHS "./*.h")
set(headers_dirs "")

foreach(path ${ALL_INCLUDE_PATHS})
get_filename_component(parentDir ${path} DIRECTORY)

if(IS_DIRECTORY ${parentDir})
list(APPEND headers_dirs ${parentDir})
endif()
endforeach()


idf_component_register(SRCS "${modules_src}"
INCLUDE_DIRS "${headers_dirs}"
PRIV_REQUIRES esp_wifi nvs_flash bt)
104 changes: 104 additions & 0 deletions firmware/components/odrone_id/alt_unix_time/alt_unix_time.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* -*- tab-width: 2; mode: c; -*-
*
* Seconds since 1/1/1970 for systems that don't have the unix time() function.
*
* The Julian day algorithm is from Jean Meeus's Astronomical Algorithms
* as are the two test dates.
*
*/

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <math.h>

uint64_t alt_unix_secs(int, int, int, int, int, int);
static double julian_day(int, int, float, int);

/*
*
*/

#ifndef ARDUINO

int main(int argc, char* argv[]) {
uint64_t alt_secs;
time_t unix_secs;
struct tm* gmt;

time(&unix_secs);

gmt = gmtime(&unix_secs);

alt_secs = alt_unix_secs(1900 + gmt->tm_year, 1 + gmt->tm_mon, gmt->tm_mday,
gmt->tm_hour, gmt->tm_min, gmt->tm_sec);

printf("\nunix: %10lu\n", (unsigned long int) unix_secs);
printf("alt: %10lu\n", (unsigned long int) alt_secs);
printf(" %10d\n", (int) ((int64_t) unix_secs - (int64_t) alt_secs));

printf("\nJD 27/1/333: %10.2f\n", julian_day(333, 1, 27.5, 0));
printf("JD Sputnik: %10.2f\n", julian_day(1957, 10, 4.81, 1));

return 0;
}

#endif

/*
*
*/

uint64_t alt_unix_secs(int year,
int month,
int mday,
int hour,
int minute,
int second) {
uint64_t secs = 0;
static uint64_t jd_1970 = 0;

if (!jd_1970) {
jd_1970 = (uint64_t) julian_day(1970, 1, 1, 1) * (uint64_t) 86400;
}

secs = (uint64_t) julian_day(year, month, mday, 1) * (uint64_t) 86400;
secs += (uint64_t) (((uint32_t) hour * 3600) + ((uint32_t) minute * 60) +
((uint32_t) second));
secs -= jd_1970;

return secs;
}

/*
*
*/

double julian_day(int year, int month, float mday, int gregorian) {
int a;
double y, m, d, jday = 0.0, b = 0.0;

if (month < 3) {
--year;
month += 12;
}

if (gregorian) {
a = year / 100;
b = 2.0 - (double) a + (double) (a / 4);
}

y = (double) (year + 4716);
m = (double) (month + 1);
d = (double) mday;

jday = floor(365.25 * y) + floor(30.6001 * m) + d + b - 1524.5;

return jday;
}

/*
*
*/
26 changes: 26 additions & 0 deletions firmware/components/odrone_id/alt_unix_time/alt_unix_time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef ALT_TIME_H
#define ALT_TIME_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// Declaración de la función que calcula los segundos desde 1/1/1970 (Unix
// timestamp alternativo)
uint64_t alt_unix_secs(int year,
int month,
int mday,
int hour,
int minute,
int second);

// Declaración de la función que calcula el día juliano para una fecha dada
double julian_day(int year, int month, float mday, int gregorian);

#ifdef __cplusplus
}
#endif

#endif // ALT_TIME_H
Loading

0 comments on commit a247dc1

Please sign in to comment.