V03 config RTC+envoie 1 donnée/seconde
Dependencies: mbed LoRaWAN-lib SX1272Lib
Diff: app/unixtimestamp.cpp
- Revision:
- 10:1a85ff06be1a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/unixtimestamp.cpp Wed Jan 23 16:28:51 2019 +0000 @@ -0,0 +1,68 @@ +#include "unixtimestamp.h" + +int unix_timestamp (int date[6]) +{ + int seconde = 0; + int bi; + bi = bissextile (date[5]); + seconde = + date[2] + (60 * date[1]) + (3600 * date[0]) + (86400 * (date[3] - 1)); + seconde += an_to_s (date[5]) + mois_to_s (date[4], bi); + return seconde; +} + +int bissextile (int an) +{ + int bi = 0; + if (((an % 4 == 0) && (an % 100 != 0)) || (an % 400 == 0)) { + bi = 1; + } + return bi; +} + +int mois_to_s (int tab, int bi) +{ + int sec; + int jour = 0; + for (int i = 1; i <= tab - 1; i++) { + if (i == 2 && bi) { + jour += 29; + } else if (i == 2) { + jour += 28; + } else if ((i == 1) || (i == 3) || (i == 5) || (i == 7) || (i == 8) + || (i == 10) || (i == 12)) { + jour += 31; + } else { + jour += 30; + } + } + sec = jour * 86400; + return sec; +} + +int an_to_s (int an) +{ + int seco = 0; + + for (int i = 1970; i <= an - 1; i++) { + if (bissextile (i)) { + seco += 366 * 86400; + } else { + seco += 365 * 86400; + } + } + return seco; +} + +void Whex_buffer(int deb,int tab[8]) +{ + unsigned int mask=0x0000000F; + for (int j =0;j<=7;j++) + { + int i=(deb&mask) ; + tab[7-j]=i; + //printf("%X\n",i); + deb>>=4; + } + +}