V03 config RTC+envoie 1 donnée/seconde

Dependencies:   mbed LoRaWAN-lib SX1272Lib

Committer:
MGstic
Date:
Wed Jan 23 16:28:51 2019 +0000
Revision:
10:1a85ff06be1a
V03

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MGstic 10:1a85ff06be1a 1 #include "unixtimestamp.h"
MGstic 10:1a85ff06be1a 2
MGstic 10:1a85ff06be1a 3 int unix_timestamp (int date[6])
MGstic 10:1a85ff06be1a 4 {
MGstic 10:1a85ff06be1a 5 int seconde = 0;
MGstic 10:1a85ff06be1a 6 int bi;
MGstic 10:1a85ff06be1a 7 bi = bissextile (date[5]);
MGstic 10:1a85ff06be1a 8 seconde =
MGstic 10:1a85ff06be1a 9 date[2] + (60 * date[1]) + (3600 * date[0]) + (86400 * (date[3] - 1));
MGstic 10:1a85ff06be1a 10 seconde += an_to_s (date[5]) + mois_to_s (date[4], bi);
MGstic 10:1a85ff06be1a 11 return seconde;
MGstic 10:1a85ff06be1a 12 }
MGstic 10:1a85ff06be1a 13
MGstic 10:1a85ff06be1a 14 int bissextile (int an)
MGstic 10:1a85ff06be1a 15 {
MGstic 10:1a85ff06be1a 16 int bi = 0;
MGstic 10:1a85ff06be1a 17 if (((an % 4 == 0) && (an % 100 != 0)) || (an % 400 == 0)) {
MGstic 10:1a85ff06be1a 18 bi = 1;
MGstic 10:1a85ff06be1a 19 }
MGstic 10:1a85ff06be1a 20 return bi;
MGstic 10:1a85ff06be1a 21 }
MGstic 10:1a85ff06be1a 22
MGstic 10:1a85ff06be1a 23 int mois_to_s (int tab, int bi)
MGstic 10:1a85ff06be1a 24 {
MGstic 10:1a85ff06be1a 25 int sec;
MGstic 10:1a85ff06be1a 26 int jour = 0;
MGstic 10:1a85ff06be1a 27 for (int i = 1; i <= tab - 1; i++) {
MGstic 10:1a85ff06be1a 28 if (i == 2 && bi) {
MGstic 10:1a85ff06be1a 29 jour += 29;
MGstic 10:1a85ff06be1a 30 } else if (i == 2) {
MGstic 10:1a85ff06be1a 31 jour += 28;
MGstic 10:1a85ff06be1a 32 } else if ((i == 1) || (i == 3) || (i == 5) || (i == 7) || (i == 8)
MGstic 10:1a85ff06be1a 33 || (i == 10) || (i == 12)) {
MGstic 10:1a85ff06be1a 34 jour += 31;
MGstic 10:1a85ff06be1a 35 } else {
MGstic 10:1a85ff06be1a 36 jour += 30;
MGstic 10:1a85ff06be1a 37 }
MGstic 10:1a85ff06be1a 38 }
MGstic 10:1a85ff06be1a 39 sec = jour * 86400;
MGstic 10:1a85ff06be1a 40 return sec;
MGstic 10:1a85ff06be1a 41 }
MGstic 10:1a85ff06be1a 42
MGstic 10:1a85ff06be1a 43 int an_to_s (int an)
MGstic 10:1a85ff06be1a 44 {
MGstic 10:1a85ff06be1a 45 int seco = 0;
MGstic 10:1a85ff06be1a 46
MGstic 10:1a85ff06be1a 47 for (int i = 1970; i <= an - 1; i++) {
MGstic 10:1a85ff06be1a 48 if (bissextile (i)) {
MGstic 10:1a85ff06be1a 49 seco += 366 * 86400;
MGstic 10:1a85ff06be1a 50 } else {
MGstic 10:1a85ff06be1a 51 seco += 365 * 86400;
MGstic 10:1a85ff06be1a 52 }
MGstic 10:1a85ff06be1a 53 }
MGstic 10:1a85ff06be1a 54 return seco;
MGstic 10:1a85ff06be1a 55 }
MGstic 10:1a85ff06be1a 56
MGstic 10:1a85ff06be1a 57 void Whex_buffer(int deb,int tab[8])
MGstic 10:1a85ff06be1a 58 {
MGstic 10:1a85ff06be1a 59 unsigned int mask=0x0000000F;
MGstic 10:1a85ff06be1a 60 for (int j =0;j<=7;j++)
MGstic 10:1a85ff06be1a 61 {
MGstic 10:1a85ff06be1a 62 int i=(deb&mask) ;
MGstic 10:1a85ff06be1a 63 tab[7-j]=i;
MGstic 10:1a85ff06be1a 64 //printf("%X\n",i);
MGstic 10:1a85ff06be1a 65 deb>>=4;
MGstic 10:1a85ff06be1a 66 }
MGstic 10:1a85ff06be1a 67
MGstic 10:1a85ff06be1a 68 }