Projeto teste do Programa de integracao com biblioteca SGAM_MDW !! Aqui visa um usuario que usa o projeto implementado para a placa NUCLEO F429ZI

Dependencies:   sgam_mdw sgam_mdw_NUCLEOF429ZI_impl Cayenne-LPP

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main_old.cpp Source File

main_old.cpp

00001 // #include "mbed.h"
00002 // #include "sgam_mdw.h"
00003 
00004 // #include "ControlImpl.h"
00005 // #include "Gyroscope.h"
00006 // #include "CayenneLPP.h"
00007 
00008 // #include "LoRaWanComm.h"
00009 // #include "LoRaWANInterface.h"
00010 // #include "lora_radio_helper.h"
00011 
00012 // #define D_LOG(args...)   printf(args) 
00013 
00014 // // LORA WAN CONFIGS 
00015 // #define TX_INTERVAL             10000
00016 // #define MBED_CONF_LORA_APP_PORT 15 //15
00017 
00018 // static uint8_t LORAWAN_DEV_EUI[] = { 0x00, 0x1C, 0x73, 0x4A, 0x55, 0x89, 0xAE, 0xC6 };
00019 // static uint8_t LORAWAN_APP_EUI[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x01, 0xD0, 0x2F };
00020 // static uint8_t LORAWAN_APP_KEY[] = { 0x75, 0xC6, 0xF2, 0xFB, 0xEE, 0xA9, 0x82, 0x6C, 0xA0, 0xBD, 0xB9, 0x0F, 0xC9, 0xEC, 0xF7, 0x10 };
00021 
00022 // // static uint32_t DEVADDR_1 = 0x2601177B;
00023 // // static uint8_t NWKSKEY_1[] = { 0x2A, 0xE9, 0x3F, 0x5E, 0x4C, 0x25, 0xDC, 0x34, 0x16, 0x82, 0x1B, 0xD1, 0x1A, 0x7F, 0xD0, 0xF6 };
00024 // // static uint8_t APPSKEY_1[] = { 0x78, 0x59, 0x61, 0xBB, 0x6B, 0xB7, 0xDE, 0x57, 0x80, 0x74, 0xAF, 0xED, 0x10, 0xD7, 0x47, 0x18 };
00025 
00026 // static void lora_event_handler(lorawan_event_t event);
00027 // static int16_t count_message;
00028 
00029 // EventQueue ev_queue;
00030 // static lorawan_app_callbacks_t callbacks;
00031 
00032 // ControlImpl ctrl;
00033 // Communication<LoraData>* comm = NULL;
00034 
00035 // int test_temperature(Control* control);
00036 // int test_gyroscope(Control* control);
00037 // int test_lorawan(Control* control);
00038 
00039 // int main() {
00040 //     D_LOG("=============== INICIO ===============\r\n");
00041 
00042 //     int ret = 0;
00043 //     Control* control = ctrl.getControler();
00044 //     control->initialize();
00045 
00046 
00047 //     //////////////////////////////////////////////////////////////////////////
00048 //     // 1 - Test Temnperature ...
00049 //     // ret = test_temperature(control);
00050 
00051 //     // 2 - Test Gyroscope ...
00052 //     // ret = test_gyroscope(control);
00053 
00054 //     // 3 - Test LoRaWAN
00055 //     ret = test_lorawan(control);
00056 //     //////////////////////////////////////////////////////////////////////////
00057     
00058 //     control->finalize();
00059 //     D_LOG("=============== FINAL ===============\r\n");
00060 //     return ret;
00061 // }
00062 
00063 // int test_temperature(Control* control) {
00064 //     D_LOG("=============== TEMPERATURE ===============\r\n");
00065 //     Sensor<float>* temp = (Sensor<float>*) control->getSensor("Temperature");
00066 
00067 //     int count = 0;
00068 
00069 //     D_LOG("## GET VALUES ....\r\n");
00070 //     while(count++ < 10) {
00071 //         D_LOG("## Temp -> %f \r\n", *temp->getValue() );
00072 //         wait(1.0); // espera 1 segundo !
00073 //     }
00074 
00075 //     return 1;
00076 // }
00077 
00078 // int test_gyroscope(Control* control) {
00079 //     D_LOG("=============== GYROSCOPE ===============\r\n");
00080 
00081 //     Sensor<GyroscopeData>* gyro = (Sensor<GyroscopeData>*) control->getSensor("Gyroscope");
00082 
00083 //     int count = 0;
00084 
00085 //     D_LOG("## GET VALUES ....\r\n");
00086 //     while(count++ < 10) {
00087 //        GyroscopeData* data = gyro->getValue();
00088 
00089 //         printf("Gyro (X) => %d \r\n", data->gx);
00090 //         printf("Gyro (Y) => %d \r\n", data->gy);
00091 //         printf("Gyro (Z) => %d \r\n", data->gz);
00092 //         printf("***********************************\r\n\r\n");
00093 
00094 //         wait(1); // espera 1 segundo !
00095 //     }
00096 
00097 //     return 1;
00098 // }
00099 
00100 // int test_lorawan(Control* control) {
00101 //     D_LOG("=============== LoRaWAN Comunication ===============\r\n");
00102 
00103 //     comm = (Communication<LoraData>*)control->getCommunication("LoRAWAN");
00104 
00105 //     ////////////////////////////////////////////////////////////////////////////////////////////
00106 //     // 1 - Configura os callbacks do loran WAN e inicializa os dados !!
00107 //     // Dados de Conexão
00108 //     lorawan_connect_t connect_params;
00109 //     connect_params.connect_type = LORAWAN_CONNECTION_OTAA;
00110 
00111 //     connect_params.connection_u.otaa.dev_eui = LORAWAN_DEV_EUI;
00112 //     connect_params.connection_u.otaa.app_eui = LORAWAN_APP_EUI;
00113 //     connect_params.connection_u.otaa.app_key = LORAWAN_APP_KEY;
00114 //     connect_params.connection_u.otaa.nb_trials = 10;
00115 
00116 //     LoraData* data = new LoraData(&connect_params, (LoRaRadio*)&radio, &ev_queue );
00117 //     callbacks.events = mbed::callback(lora_event_handler);
00118 //     data->prepareCallBack(callbacks);
00119 
00120 //     // Flags de leitura !!
00121 //     data->lora_port = MBED_CONF_LORA_APP_PORT;
00122 
00123 //     /////////////////////////////////////////////////////////////////////////////////////////////
00124 //     // 2 - INICIALIZA A CONEXAO
00125 //     if( comm->initialize(data) != TRUE) {
00126 //         D_LOG("Inicialização falhou !!\r\n");
00127 //         return -1;
00128 //     }
00129 
00130 //     ////////////////////////////////////////////////////////////////////////////////////////////
00131 //     // 3 - Tentar conectar 
00132 //     lorawan_status_t retcode = (lorawan_status_t) comm->connect();
00133 //     if (retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
00134 //         printf("Connection - In Progress ...\r\n");
00135 //     } else {
00136 //         printf("Connection error, code = %d \r\n", retcode);
00137 //         return -1;
00138 //     }
00139 
00140 //     // make your event queue dispatching events forever
00141 //     ev_queue.dispatch_forever();
00142 //     return 1;
00143 // }
00144 
00145 // /**
00146 //  * Receive a message from the Network Server
00147 //  */
00148 // static void receive_message()
00149 // {
00150 //     printf("receive_message()\n");
00151     
00152 //     LoraData* data = (LoraData*) comm->getData();
00153 //     data->read_write_flags = MSG_CONFIRMED_FLAG|MSG_UNCONFIRMED_FLAG;
00154 
00155 //     uint8_t rx_buffer[50] = { 0 };
00156 //     int16_t retcode = comm->read( rx_buffer, sizeof(rx_buffer) ); 
00157 //     if (retcode < 0) {
00158 //         printf("receive() - Error code %d \r\n", retcode);
00159 //         return;
00160 //     }
00161 
00162 //     printf("RX Data (%d bytes): ", retcode);
00163 //     for (uint8_t i = 0; i < retcode; i++) {
00164 //         printf("%02x ", rx_buffer[i]);
00165 //     }
00166 
00167 //     printf("\r\n");
00168 // }
00169 
00170 // /**
00171 //  * Sends a message to the Network Server
00172 //  */
00173 // static void send_message() {
00174 //     printf("send_message()\n");
00175         
00176 //     // YOUR CODE HERE
00177 //     int16_t temperature = 10;
00178 //     printf("temperature = (%d)\n", temperature);
00179 
00180 //     CayenneLPP payload(50);
00181 //     payload.addTemperature(1, temperature);
00182 
00183 //     LoraData* data = (LoraData*) comm->getData();
00184 //     data->read_write_flags = MSG_UNCONFIRMED_FLAG;
00185 
00186 //     int16_t retcode = comm->write(payload.getBuffer(), payload.getSize());
00187 //     printf("lorawan.send = retcode [%d]\n",retcode);
00188 
00189 //     if (retcode < 0) {
00190 //         retcode == LORAWAN_STATUS_WOULD_BLOCK 
00191 //                         ? printf("send - Duty cycle violation\r\n")
00192 //                         : printf("send() - Error code %d \r\n", retcode);
00193                 
00194 //         if (retcode == LORAWAN_STATUS_NO_ACTIVE_SESSIONS)
00195 //             printf("\r\n|-1017 - LORAWAN_STATUS_NO_ACTIVE_SESSIONS"); 
00196 
00197 //         if (retcode == LORAWAN_STATUS_WOULD_BLOCK) { //retry in 3 seconds
00198 //             ev_queue.call_in(3000, send_message);
00199 //         } else {
00200 //             ev_queue.call_in(TX_INTERVAL, send_message);
00201 //         }
00202 
00203 //         return;
00204 //     }
00205 
00206 //     ev_queue.call_in(TX_INTERVAL, send_message);
00207 
00208 //     receive_message();
00209 //     printf("%d bytes scheduled for transmission \r\n", retcode);
00210 // }
00211 
00212 // /**
00213 //  * Event handler
00214 //  */
00215 // static void lora_event_handler(lorawan_event_t event) {
00216 //     switch (event) {
00217 //         case CONNECTED:
00218 //             printf("# Connection - Successful \r\n");            
00219 //             if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
00220 //                 send_message();
00221 //             } else {
00222 //                 ev_queue.call_in(TX_INTERVAL, send_message);
00223 //             }
00224 //             break;
00225 
00226 //         case DISCONNECTED:
00227 //             ev_queue.break_dispatch();
00228 //             printf("# Disconnected Successfully \r\n");
00229 //             break;
00230 //         case RX_DONE:
00231 //             printf("# Received message from Network Server \r\n");
00232 //             receive_message();
00233 //             break;
00234 //         case RX_TIMEOUT:
00235 //         case RX_ERROR:
00236 //             printf("# Error in reception - Code = %d \r\n", event);
00237 //             break;
00238 //         case TX_DONE:    
00239 //             count_message++;        
00240 //             printf("# Message Sent to Network Server - Count [%d] \r\n", count_message);
00241 //             break;
00242 //         case TX_TIMEOUT:
00243 //         case TX_ERROR:
00244 //         case TX_CRYPTO_ERROR:
00245 //         case TX_SCHEDULING_ERROR:
00246 //             printf("# Transmission Error - EventCode = %d \r\n", event);
00247 //             break;        
00248 //         case JOIN_FAILURE:
00249 //             printf("# OTAA Failed - Check Keys \r\n");
00250 //             break;
00251 //         case UPLINK_REQUIRED:
00252 //             printf("# Uplink required by NS \r\n");
00253 //             send_message();
00254 //             break;
00255 //         default:
00256 //             printf("# Unknown Event \r\n");
00257 //             // MBED_ASSERT("# Unknown Event");
00258 //     }
00259 // }