![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
V03 config RTC+envoie 1 donnée/seconde
Dependencies: mbed LoRaWAN-lib SX1272Lib
Revision 10:1a85ff06be1a, committed 2019-01-23
- Comitter:
- MGstic
- Date:
- Wed Jan 23 16:28:51 2019 +0000
- Parent:
- 9:07c94dd6dc51
- Commit message:
- V03
Changed in this revision
--- a/app/SerialDisplay.cpp Wed Dec 12 08:41:45 2018 +0000 +++ b/app/SerialDisplay.cpp Wed Jan 23 16:28:51 2019 +0000 @@ -248,6 +248,29 @@ SerialDisplayUpdateData( 37, NULL, 0 ); } } +void SerialDisplayRTCactive( bool etat ) +{ + if (etat==0) + { + vt.SetCursorPos( 42, 17 ); + SerialPrintCheckBox( !etat, VT100::RED ); + } + else + { + vt.SetCursorPos( 42, 17 ); + SerialPrintCheckBox( etat, VT100::GREEN ); + } +} + +void SerialDisplayTIME( int tab[6] ) +{ + for(int i=0;i<6;i++) + { + vt.SetCursorPos( (44+i), 28 ); + vt.printf( "%2d", tab[i] ); + } + +} void SerialDisplayDrawFirstLine( void ) { @@ -429,6 +452,16 @@ // "¦ ¦ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ¦" ); SerialDisplayDrawLine( " ", " __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ " ); // "+------------+----------------------------------------------------------------+" ); + SerialDisplayDrawTopSeparator( ); + SerialDisplayDrawLine( " ConfigRTC ", " [ ]Active " ); + SerialDisplayDrawLine( " ", " 0. Valider/Quitter " ); + SerialDisplayDrawLine( " ", " 1. Heure [ ] " ); + SerialDisplayDrawLine( " ", " 2. Minute [ ] " ); + SerialDisplayDrawLine( " ", " 3. Seconde [ ] " ); + SerialDisplayDrawLine( " ", " 4. Jour [ ] " ); + SerialDisplayDrawLine( " ", " 5. Mois [ ] " ); + SerialDisplayDrawLine( " ", " 6. Annee [ ] " ); + SerialDisplayDrawLine( " ", " Selection [__] Valeur [ ] " ); SerialDisplayDrawBottomLine( ); vt.printf( "To refresh screen please hit 'r' key.\r\n" ); } @@ -442,3 +475,62 @@ { return vt.GetChar( ); } + + +void saisie_serie(int tab[6]) +{ + int inter=9; + while( inter != 0) { + + scanf("%d",&inter); //lecture saisie clavier + vt.SetCursorPos( 50, 28 ); + vt.printf( "%2d", inter ); + vt.SetCursorPos( 50, 58 ); + vt.printf( " "); + SerialDisplayTIME(tab); + switch (inter) { + case 1: + vt.SetCursorPos( 50, 58 ); + scanf("%d",&tab[0]); + vt.printf( "%2d", tab[0] ); + break; + + case 2: + vt.SetCursorPos( 50, 58 ); + scanf("%d",&tab[1]); + vt.printf( "%2d", tab[1] ); + break; + + case 3: + vt.SetCursorPos( 50, 58 ); + scanf("%d",&tab[2]); + vt.printf( "%2d", tab[2] ); + break; + + case 4: + vt.SetCursorPos( 50, 58 ); + scanf("%d",&tab[3]); + vt.printf( "%2d", tab[3] ); + break; + + case 5: + vt.SetCursorPos( 50, 58 ); + scanf("%d",&tab[4]); + vt.printf( "%2d", tab[4] ); + break; + + case 6: + vt.SetCursorPos( 50, 58 ); + scanf("%d",&tab[5]); + vt.printf( "%2d", tab[5] ); + break; + + default: + vt.SetCursorPos( 50, 58 ); + vt.printf( " "); + break; + } + } + +} +
--- a/app/SerialDisplay.h Wed Dec 12 08:41:45 2018 +0000 +++ b/app/SerialDisplay.h Wed Jan 23 16:28:51 2019 +0000 @@ -35,5 +35,10 @@ void SerialDisplayUpdateDonwlinkRxData( bool state ); bool SerialDisplayReadable( void ); uint8_t SerialDisplayGetChar( void ); +void SerialDisplayRTCactive( bool etat ); +void SerialDisplayTIME( int tab[6] ); +void saisie_serie(int tab[6]); + + #endif // __SERIAL_DISPLAY_H__
--- a/app/main.cpp Wed Dec 12 08:41:45 2018 +0000 +++ b/app/main.cpp Wed Jan 23 16:28:51 2019 +0000 @@ -1,44 +1,22 @@ -/* - / _____) _ | | -( (____ _____ ____ _| |_ _____ ____| |__ - \____ \| ___ | (_ _) ___ |/ ___) _ \ - _____) ) ____| | | || |_| ____( (___| | | | -(______/|_____)_|_|_| \__)_____)\____)_| |_| - (C)2015 Semtech - -Description: LoRaMac classA device implementation - -License: Revised BSD License, see LICENSE.TXT file include in the project - -Maintainer: Miguel Luis and Gregory Cristian -*/ #include "mbed.h" #include "board.h" #include "radio.h" - #include "LoRaMac.h" #include "Commissioning.h" #include "SerialDisplay.h" +#include "unixtimestamp.h" +#include <stdio.h> +#include <time.h> -/*! - * Defines the application data transmission duty cycle. 5s, value in [ms]. - */ -#define APP_TX_DUTYCYCLE 5000 /*! - * Defines a random delay for application data transmission duty cycle. 1s, - * value in [ms]. + * Defines the application data transmission duty cycle. 1s, value in [ms]. */ -#define APP_TX_DUTYCYCLE_RND 1000 +#define APP_TX_DUTYCYCLE 1000 +#define TAB_MAX 10 +#define APP_TX_DUTYCYCLE_RND 250 -/*! - * Default datarate - */ #define LORAWAN_DEFAULT_DATARATE DR_5 - -/*! - * LoRaWAN confirmed messages - */ #define LORAWAN_CONFIRMED_MSG_ON true /*! @@ -48,20 +26,31 @@ */ #define LORAWAN_ADR_ON 1 -#if defined( USE_BAND_868 ) - #include "LoRaMacTest.h" /*! - * LoRaWAN ETSI duty cycle control enable/disable - * - * \remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes + * LoRaWAN ETSI European Telecommunications Standards Institute + * duty cycle control enable/disable + * remark Please note that ETSI mandates duty cycled transmissions. Use only for test purposes */ #define LORAWAN_DUTYCYCLE_ON false #define USE_SEMTECH_DEFAULT_CHANNEL_LINEUP 1 -#if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) +//############INITIALISATION LIAISON SERIE#################### + +void saisie_serie(int tab[6]); +int tabd[6]= {0,0,0,1,1,2018}; + + +InterruptIn bouton(USER_BUTTON); // Déclaration de l'interruption extern activée par le bouton utilisateur bleu +//Serial pc(USBTX, USBRX); // tx, rx//Serial pc(SERIAL_TX, SERIAL_RX); // Déclaration de entrées pour la liaison série +int etat=0; +void interruption_extern_bouton(void) +{ + etat = not(etat); // changement d'etat +} +//############################################################ #define LC4 { 867100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } #define LC5 { 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } @@ -71,10 +60,6 @@ #define LC9 { 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 } #define LC10 { 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 } -#endif - -#endif - /*! * LoRaWAN application port */ @@ -83,20 +68,11 @@ /*! * User application data buffer size */ -#if ( LORAWAN_CONFIRMED_MSG_ON == 1 ) -#define LORAWAN_APP_DATA_SIZE 12 - -#else -#define LORAWAN_APP_DATA_SIZE 1 - -#endif +#define LORAWAN_APP_DATA_SIZE 24 static uint8_t DevEui[] = LORAWAN_DEVICE_EUI; static uint8_t AppEui[] = LORAWAN_APPLICATION_EUI; static uint8_t AppKey[] = LORAWAN_APPLICATION_KEY; - -#if( OVER_THE_AIR_ACTIVATION == 0 ) - static uint8_t NwkSKey[] = LORAWAN_NWKSKEY; static uint8_t AppSKey[] = LORAWAN_APPSKEY; @@ -105,8 +81,6 @@ */ static uint32_t DevAddr = LORAWAN_DEVICE_ADDRESS; -#endif - /*! * Application port */ @@ -142,25 +116,7 @@ */ static TimerEvent_t TxNextPacketTimer; -/*! - * Specifies the state of the application LED - */ -static bool AppLedStateOn = false; -volatile bool Led3StateChanged = false; -/*! - * Timer to handle the state of LED1 - */ -static TimerEvent_t Led1Timer; -volatile bool Led1State = false; -volatile bool Led1StateChanged = false; -/*! - * Timer to handle the state of LED2 - */ -static TimerEvent_t Led2Timer; -volatile bool Led2State = false; -volatile bool Led2StateChanged = false; - -/*! +/* * Indicates if a new packet can be sent */ static bool NextTx = true; @@ -194,10 +150,6 @@ uint8_t NbGateways; }ComplianceTest; -/* - * SerialDisplay managment variables - */ - /*! * Indicates if the MAC layer network join status has changed. */ @@ -239,12 +191,10 @@ SerialDisplayInit( ); SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); -#if( OVER_THE_AIR_ACTIVATION == 0 ) SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); SerialDisplayUpdateDevAddr( DevAddr ); SerialDisplayUpdateKey( 12, NwkSKey ); SerialDisplayUpdateKey( 13, AppSKey ); -#endif SerialDisplayUpdateEui( 5, DevEui ); SerialDisplayUpdateEui( 6, AppEui ); SerialDisplayUpdateKey( 7, AppKey ); @@ -254,14 +204,12 @@ SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); -#if defined( USE_BAND_868 ) SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); -#else - SerialDisplayUpdateDutyCycle( false ); -#endif - SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); - - SerialDisplayUpdateLedState( 3, AppLedStateOn ); + SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); + SerialDisplayRTCactive(etat); + SerialDisplayTIME(tabd); + + //SerialDisplayUpdateLedState( 3, AppLedStateOn ); } void SerialRxProcess( void ) @@ -284,29 +232,57 @@ /*! * \brief Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port,uint8_t jojo )//, 2EME PARAMETRE TABLEAU DONNEE INIT=>APPDATA DANS FONCION + +uint8_t poidstest=34; +uint8_t heuretest=0; + +typedef struct { + uint8_t heure;//[8]; // Augmentation taille prog. Solution : heure = pointeur vers malloc (26 ou sizeof ctime)=1bit + uint8_t masse;//[8]; +} data; +data data_packet[TAB_MAX]; + +//################################### + +void copy_time(int data_packet[8],time_t seconds) { + char temp[32]; + int tempp; + //printf("=>%s\n",ctime(&seconds)); + //printf("%d\r\n",seconds); + sprintf(temp,"%d",(int)seconds);// copie de la valeur de la RTC en cours dans le tableau de structure data_packet + tempp=atoi(temp); + Whex_buffer(tempp,data_packet); +} +//################################## + +static void PrepareTxFrame( uint8_t port,data datat )//, 2EME PARAMETRE TABLEAU DONNEE INIT=>APPDATA DANS FONCION fournir 1 case tableau data_packet +{ + int dpacket[8]; + time_t seconds=time(NULL); switch( port ) { case 15: { - //AppData[0] = AppLedStateOn; - AppData[0] = 0xAA; - AppData[1] = 'j'; - - - //AppData[3] = 150000; - AppData[4] = 0xAA; + //printf("%d\r\n",seconds); + copy_time(dpacket,seconds); + /*for(int k=0;k<8;k++) + { + printf("%X",dpacket[k]); + } + printf("\n\r");*/ + for(int h=0;h<8;h++) + { - - /* if( IsTxConfirmed == true ) - { - AppData[1] = LoRaMacDownlinkStatus.DownlinkCounter >> 8; - AppData[2] = LoRaMacDownlinkStatus.DownlinkCounter; - AppData[3] = LoRaMacDownlinkStatus.Rssi >> 8; - AppData[4] = LoRaMacDownlinkStatus.Rssi; - AppData[5] = LoRaMacDownlinkStatus.Snr; - }*/ + + AppData[h]=dpacket[h]; + //AppData[h]=datat.heure; + //printf(" ||H:%d|\n\r",AppData[0]); + + //printf(" ||P:%d|\n\r",AppData[16]); + } + + AppData[16]=datat.masse; } break; case 224: @@ -424,34 +400,13 @@ } } -/*! - * \brief Function executed on Led 1 Timeout event - */ -static void OnLed1TimerEvent( void ) -{ - TimerStop( &Led1Timer ); - // Switch LED 1 OFF - Led1State = false; - Led1StateChanged = true; -} - -/*! - * \brief Function executed on Led 2 Timeout event - */ -static void OnLed2TimerEvent( void ) -{ - TimerStop( &Led2Timer ); - // Switch LED 2 OFF - Led2State = false; - Led2StateChanged = true; -} - -/*! +/* * \brief MCPS-Confirm event function * * \param [IN] mcpsConfirm - Pointer to the confirm structure, * containing confirm attributes. */ + static void McpsConfirm( McpsConfirm_t *mcpsConfirm ) { if( mcpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK ) @@ -483,10 +438,10 @@ LoRaMacUplinkStatus.Datarate = mcpsConfirm->Datarate; LoRaMacUplinkStatus.UplinkCounter = mcpsConfirm->UpLinkCounter; - // Switch LED 1 ON + /* Switch LED 1 ON Led1State = true; Led1StateChanged = true; - TimerStart( &Led1Timer ); + TimerStart( &Led1Timer );*/ UplinkStatusUpdated = true; } @@ -566,11 +521,11 @@ { case 1: // The application LED can be controlled on port 1 or 2 case 2: - if( mcpsIndication->BufferSize == 1 ) + /*if( mcpsIndication->BufferSize == 1 ) { AppLedStateOn = mcpsIndication->Buffer[0] & 0x01; Led3StateChanged = true; - } + }*/ break; case 224: if( ComplianceTest.Running == false ) @@ -596,10 +551,8 @@ mibReq.Type = MIB_ADR; mibReq.Param.AdrEnable = true; LoRaMacMibSetRequestConfirm( &mibReq ); + LoRaMacTestSetDutyCycleOn( false ); -#if defined( USE_BAND_868 ) - LoRaMacTestSetDutyCycleOn( false ); -#endif } } else @@ -618,9 +571,8 @@ mibReq.Type = MIB_ADR; mibReq.Param.AdrEnable = LORAWAN_ADR_ON; LoRaMacMibSetRequestConfirm( &mibReq ); -#if defined( USE_BAND_868 ) LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); -#endif + break; case 1: // (iii, iv) AppDataSize = 2; @@ -664,17 +616,12 @@ mibReq.Type = MIB_ADR; mibReq.Param.AdrEnable = LORAWAN_ADR_ON; LoRaMacMibSetRequestConfirm( &mibReq ); -#if defined( USE_BAND_868 ) LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); -#endif - mlmeReq.Type = MLME_JOIN; - mlmeReq.Req.Join.DevEui = DevEui; mlmeReq.Req.Join.AppEui = AppEui; mlmeReq.Req.Join.AppKey = AppKey; mlmeReq.Req.Join.NbTrials = 3; - LoRaMacMlmeRequest( &mlmeReq ); DeviceState = DEVICE_STATE_SLEEP; } @@ -711,9 +658,9 @@ } // Switch LED 2 ON for each received downlink - Led2State = true; - Led2StateChanged = true; - TimerStart( &Led2Timer ); + //Led2State = true; + //Led2StateChanged = true; + //TimerStart( &Led2Timer ); DownlinkStatusUpdated = true; } @@ -764,214 +711,226 @@ UplinkStatusUpdated = true; } -/** +/*###################################################################### * Main application entry point. */ - uint8_t jiji=1; + + + int main( void ) { + //####### INITIALISATION MODULE LORA ############ LoRaMacPrimitives_t LoRaMacPrimitives; LoRaMacCallback_t LoRaMacCallbacks; MibRequestConfirm_t mibReq; - BoardInit( ); SerialDisplayInit( ); - SerialDisplayUpdateEui( 5, DevEui ); SerialDisplayUpdateEui( 6, AppEui ); SerialDisplayUpdateKey( 7, AppKey ); - -#if( OVER_THE_AIR_ACTIVATION == 0 ) SerialDisplayUpdateNwkId( LORAWAN_NETWORK_ID ); SerialDisplayUpdateDevAddr( DevAddr ); SerialDisplayUpdateKey( 12, NwkSKey ); SerialDisplayUpdateKey( 13, AppSKey ); -#endif + DeviceState = DEVICE_STATE_INIT; + + //####### LIAISON SERIE ######## + + /*pc.baud(9600);// vitesse liaison série + pc.format(8, SerialBase::None, 1); // format de la liaison*/ + bouton.rise(&interruption_extern_bouton); //initialisation de l'interruption extern sur le bouton user + + //####### RTC INIT ######## + set_time(1514764800); + int config_s=0; - DeviceState = DEVICE_STATE_INIT; + //####### VARIABLES ######## + uint8_t compt=0; + uint8_t c_send=TAB_MAX; while( 1 ) { - SerialRxProcess( ); - if( IsNetworkJoinedStatusUpdate == true ) - { - IsNetworkJoinedStatusUpdate = false; - mibReq.Type = MIB_NETWORK_JOINED; - LoRaMacMibGetRequestConfirm( &mibReq ); - SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); - } - if( Led1StateChanged == true ) - { - Led1StateChanged = false; - SerialDisplayUpdateLedState( 1, Led1State ); - } - if( Led2StateChanged == true ) - { - Led2StateChanged = false; - SerialDisplayUpdateLedState( 2, Led2State ); - } - if( Led3StateChanged == true ) + if(1) { - Led3StateChanged = false; - SerialDisplayUpdateLedState( 3, AppLedStateOn ); - } - if( UplinkStatusUpdated == true ) - { - UplinkStatusUpdated = false; - SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize ); + SerialRxProcess( ); + if( IsNetworkJoinedStatusUpdate == true ) + { + IsNetworkJoinedStatusUpdate = false; + mibReq.Type = MIB_NETWORK_JOINED; + LoRaMacMibGetRequestConfirm( &mibReq ); + SerialDisplayUpdateNetworkIsJoined( mibReq.Param.IsNetworkJoined ); + } + + if( UplinkStatusUpdated == true ) + { + UplinkStatusUpdated = false; + SerialDisplayUpdateUplink( LoRaMacUplinkStatus.Acked, LoRaMacUplinkStatus.Datarate, LoRaMacUplinkStatus.UplinkCounter, LoRaMacUplinkStatus.Port, LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize ); + } + if( DownlinkStatusUpdated == true ) + { + DownlinkStatusUpdated = false; + //SerialDisplayUpdateLedState( 2, Led2State ); + SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize ); + } + } - if( DownlinkStatusUpdated == true ) - { - DownlinkStatusUpdated = false; - SerialDisplayUpdateLedState( 2, Led2State ); - SerialDisplayUpdateDownlink( LoRaMacDownlinkStatus.RxData, LoRaMacDownlinkStatus.Rssi, LoRaMacDownlinkStatus.Snr, LoRaMacDownlinkStatus.DownlinkCounter, LoRaMacDownlinkStatus.Port, LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize ); - } - - switch( DeviceState ) - { - case DEVICE_STATE_INIT: - { - LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm; - LoRaMacPrimitives.MacMcpsIndication = McpsIndication; - LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm; - LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel; - LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks ); + + //time_t seconds = time(NULL); + //sprintf(data_packet[compt].heure,"%s",ctime(&seconds));// copie de la valeur de la RTC en cours dans le tableau de structure data_packet + + data_packet[0].heure=heuretest; + data_packet[0].masse=poidstest; + poidstest++; + heuretest++; + + //printf("%d\r\n",compt); - TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); - - TimerInit( &Led1Timer, OnLed1TimerEvent ); - TimerSetValue( &Led1Timer, 25 ); - - TimerInit( &Led2Timer, OnLed2TimerEvent ); - TimerSetValue( &Led2Timer, 25 ); + wait(1); + switch (etat) + { + + case 0: //bouton non enclenché + { + SerialDisplayRTCactive(etat); + SerialDisplayTIME(tabd); + time_t seconds = time(NULL); + switch( DeviceState ) + { - mibReq.Type = MIB_ADR; - mibReq.Param.AdrEnable = LORAWAN_ADR_ON; - LoRaMacMibSetRequestConfirm( &mibReq ); - - mibReq.Type = MIB_PUBLIC_NETWORK; - mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK; - LoRaMacMibSetRequestConfirm( &mibReq ); - -#if defined( USE_BAND_868 ) - LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); - SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); + case DEVICE_STATE_INIT: + { + LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm; + LoRaMacPrimitives.MacMcpsIndication = McpsIndication; + LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm; + LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel; + LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks ); + TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); -#if( USE_SEMTECH_DEFAULT_CHANNEL_LINEUP == 1 ) - LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 ); - LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 ); - LoRaMacChannelAdd( 5, ( ChannelParams_t )LC6 ); - LoRaMacChannelAdd( 6, ( ChannelParams_t )LC7 ); - LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 ); - LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 ); - LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 ); + mibReq.Type = MIB_ADR; + mibReq.Param.AdrEnable = LORAWAN_ADR_ON; + LoRaMacMibSetRequestConfirm( &mibReq ); + mibReq.Type = MIB_PUBLIC_NETWORK; + mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK; + LoRaMacMibSetRequestConfirm( &mibReq ); + LoRaMacTestSetDutyCycleOn( LORAWAN_DUTYCYCLE_ON ); + SerialDisplayUpdateDutyCycle( LORAWAN_DUTYCYCLE_ON ); + - mibReq.Type = MIB_RX2_DEFAULT_CHANNEL; - mibReq.Param.Rx2DefaultChannel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; - LoRaMacMibSetRequestConfirm( &mibReq ); + LoRaMacChannelAdd( 3, ( ChannelParams_t )LC4 ); + LoRaMacChannelAdd( 4, ( ChannelParams_t )LC5 ); + LoRaMacChannelAdd( 5, ( ChannelParams_t )LC6 ); + LoRaMacChannelAdd( 6, ( ChannelParams_t )LC7 ); + LoRaMacChannelAdd( 7, ( ChannelParams_t )LC8 ); + LoRaMacChannelAdd( 8, ( ChannelParams_t )LC9 ); + LoRaMacChannelAdd( 9, ( ChannelParams_t )LC10 ); - mibReq.Type = MIB_RX2_CHANNEL; - mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; - LoRaMacMibSetRequestConfirm( &mibReq ); -#endif + mibReq.Type = MIB_RX2_DEFAULT_CHANNEL; + mibReq.Param.Rx2DefaultChannel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; + LoRaMacMibSetRequestConfirm( &mibReq ); -#endif - SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); - SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); - SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); + mibReq.Type = MIB_RX2_CHANNEL; + mibReq.Param.Rx2Channel = ( Rx2ChannelParams_t ){ 869525000, DR_3 }; + LoRaMacMibSetRequestConfirm( &mibReq ); - LoRaMacDownlinkStatus.DownlinkCounter = 0; + SerialDisplayUpdateActivationMode( OVER_THE_AIR_ACTIVATION ); + SerialDisplayUpdateAdr( LORAWAN_ADR_ON ); + SerialDisplayUpdatePublicNetwork( LORAWAN_PUBLIC_NETWORK ); + + LoRaMacDownlinkStatus.DownlinkCounter = 0; - DeviceState = DEVICE_STATE_JOIN; - break; - } - case DEVICE_STATE_JOIN: - { -#if( OVER_THE_AIR_ACTIVATION != 0 ) - MlmeReq_t mlmeReq; - - mlmeReq.Type = MLME_JOIN; - - mlmeReq.Req.Join.DevEui = DevEui; - mlmeReq.Req.Join.AppEui = AppEui; - mlmeReq.Req.Join.AppKey = AppKey; + DeviceState = DEVICE_STATE_JOIN; + break; + } + case DEVICE_STATE_JOIN: + { + mibReq.Type = MIB_NET_ID; + mibReq.Param.NetID = LORAWAN_NETWORK_ID; + LoRaMacMibSetRequestConfirm( &mibReq ); - if( NextTx == true ) - { - LoRaMacMlmeRequest( &mlmeReq ); - } - DeviceState = DEVICE_STATE_SLEEP; -#else - mibReq.Type = MIB_NET_ID; - mibReq.Param.NetID = LORAWAN_NETWORK_ID; - LoRaMacMibSetRequestConfirm( &mibReq ); + mibReq.Type = MIB_DEV_ADDR; + mibReq.Param.DevAddr = DevAddr; + LoRaMacMibSetRequestConfirm( &mibReq ); + + mibReq.Type = MIB_NWK_SKEY; + mibReq.Param.NwkSKey = NwkSKey; + LoRaMacMibSetRequestConfirm( &mibReq ); - mibReq.Type = MIB_DEV_ADDR; - mibReq.Param.DevAddr = DevAddr; - LoRaMacMibSetRequestConfirm( &mibReq ); - - mibReq.Type = MIB_NWK_SKEY; - mibReq.Param.NwkSKey = NwkSKey; - LoRaMacMibSetRequestConfirm( &mibReq ); + mibReq.Type = MIB_APP_SKEY; + mibReq.Param.AppSKey = AppSKey; + LoRaMacMibSetRequestConfirm( &mibReq ); - mibReq.Type = MIB_APP_SKEY; - mibReq.Param.AppSKey = AppSKey; - LoRaMacMibSetRequestConfirm( &mibReq ); - - mibReq.Type = MIB_NETWORK_JOINED; - mibReq.Param.IsNetworkJoined = true; - LoRaMacMibSetRequestConfirm( &mibReq ); + mibReq.Type = MIB_NETWORK_JOINED; + mibReq.Param.IsNetworkJoined = true; + LoRaMacMibSetRequestConfirm( &mibReq ); - DeviceState = DEVICE_STATE_SEND; -#endif - IsNetworkJoinedStatusUpdate = true; - break; - } - case DEVICE_STATE_SEND: - { - if( NextTx == true ) - { - jiji++; - SerialDisplayUpdateUplinkAcked( false ); - SerialDisplayUpdateDonwlinkRxData( false ); - PrepareTxFrame( AppPort,jiji ); - - - - NextTx = SendFrame( ); - } - if( ComplianceTest.Running == true ) - { - // Schedule next packet transmission - TxDutyCycleTime = 5000; // 5000 ms + DeviceState = DEVICE_STATE_SEND; + IsNetworkJoinedStatusUpdate = true; + break; + } + case DEVICE_STATE_SEND: + { + if( NextTx == true ) + { + SerialDisplayUpdateUplinkAcked( false ); + SerialDisplayUpdateDonwlinkRxData( false ); + + ///prepare tx + PrepareTxFrame( AppPort,data_packet[0] ); + NextTx = SendFrame( ); + + + } + if( ComplianceTest.Running == true ) + { + // Schedule next packet transmission + TxDutyCycleTime = 1000; // 5000 ms + } + else + { + // Schedule next packet transmission + TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ); + } + DeviceState = DEVICE_STATE_CYCLE; + break; + } + case DEVICE_STATE_CYCLE: + { + DeviceState = DEVICE_STATE_SLEEP; + // Schedule next packet transmission + TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); + TimerStart( &TxNextPacketTimer ); + break; + } + case DEVICE_STATE_SLEEP: + { + + // Wake up through events + break; + } + default: + { + DeviceState = DEVICE_STATE_INIT; + break; + } + + } + break; + } + case 1 : //bouton enclenché + { + SerialDisplayRTCactive(etat); + saisie_serie(tabd); + SerialDisplayTIME(tabd); + config_s=unix_timestamp(tabd); + set_time(config_s); + //printf( "%d\r\n",etat); + etat=0; + break; + } } - else - { - // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND ); - } - DeviceState = DEVICE_STATE_CYCLE; - break; - } - case DEVICE_STATE_CYCLE: - { - DeviceState = DEVICE_STATE_SLEEP; - - // Schedule next packet transmission - TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime ); - TimerStart( &TxNextPacketTimer ); - break; - } - case DEVICE_STATE_SLEEP: - { - // Wake up through events - break; - } - default: - { - DeviceState = DEVICE_STATE_INIT; - break; - } - } + + + } } +
--- /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; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/unixtimestamp.h Wed Jan 23 16:28:51 2019 +0000 @@ -0,0 +1,18 @@ +#ifndef UNIXTIMESTAMP +#define UNIXTIMESTAMP + +#include <stdio.h> +#include "mbed.h" + + +void saisie_serie(int tab[6]); +void interruption_extern_bouton(void); +int unix_timestamp (int date[6]); +int bissextile (int an); +int mois_to_s (int tab, int bi); +int an_to_s (int an); +void Whex_buffer(int deb,int tab[8]); +void saisie_serie(int tab[6]); + + +#endif \ No newline at end of file