this is using the mbed os version 5-13-1
Diff: source/main-https.cpp
- Revision:
- 81:637a87eb8170
- Parent:
- 80:e8f0e92e3ac9
- Child:
- 82:10072c1794d3
--- a/source/main-https.cpp Thu Mar 21 22:17:28 2019 +0000
+++ b/source/main-https.cpp Sat Mar 23 16:28:34 2019 +0000
@@ -53,21 +53,21 @@
LEDService *ledServicePtr;
/* Queue and memory pool for AT to Wifi commands */
-MemoryPool<wifi_cmd_message_t, 16> aT2WiFimPool;
-Queue<wifi_cmd_message_t, 16> aT2WiFiCmdQueue;
+static MemoryPool<wifi_cmd_message_t, 16> aT2WiFimPool;
+static Queue<wifi_cmd_message_t, 16> aT2WiFiCmdQueue;
/* Queue and memory pool for WiFi to AT commands */
-MemoryPool<wifi_cmd_message_t, 16> wiFi2ATmPool;
-Queue<wifi_cmd_message_t, 16> wiFi2ATCmdQueue;
+static MemoryPool<at_resp_message_t, 16> wiFi2ATmPool;
+static Queue<at_resp_message_t, 16> wiFi2ATCmdQueue;
/* Queue and memory pool for AT to WiFi data */
-MemoryPool<wifi_data_msg_t, 4> aT2WiFiDatamPool;
-Queue<wifi_data_msg_t, 4> aT2WiFiDataQueue;
+static MemoryPool<wifi_data_msg_t, 4> aT2WiFiDatamPool;
+static Queue<wifi_data_msg_t, 4> aT2WiFiDataQueue;
/* Queue and memory pool for WiFi to AT data */
-MemoryPool<wifi_data_msg_t, 4> wiFi2ATDatamPool;
-Queue<wifi_data_msg_t, 4> wiFi2ATDataQueue;
+static MemoryPool<at_data_msg_t, 4> wiFi2ATDatamPool;
+static Queue<at_data_msg_t, 4> wiFi2ATDataQueue;
@@ -77,22 +77,22 @@
//unsigned char hp_stk[1024];
//unsigned char lp_stk[1024];
unsigned char btle_stk[1024];
-unsigned char wifi_stk[1024];
-unsigned char atcmd_stk[1024];
+unsigned char wifi_stk[4*1024];
+unsigned char atcmd_stk[4*1024];
/* creates three tread objects with different priorities */
//Thread real_time_thread(osPriorityRealtime, 1024, &rt_stk[0]);
//Thread high_prio_thread(osPriorityHigh, 1024, &hp_stk[0]);
//Thread low_prio_thread(osPriorityNormal, 1024, &lp_stk[0]);
Thread btle_thread(BTLE_THREAD_PRIORITY, 1024, &btle_stk[0]);
-Thread wifi_thread(WIFI_THREAD_PRIORITY, 1024, &wifi_stk[0]);
-Thread atcmd_thread(ATCMD_THREAD_PRIORITY, 1024, &atcmd_stk[0]);
+Thread wifi_thread(WIFI_THREAD_PRIORITY, 4*1024, &wifi_stk[0]);
+Thread atcmd_thread(ATCMD_THREAD_PRIORITY, 4*1024, &atcmd_stk[0]);
/* create a semaphore to synchronize the threads */
Semaphore sync_sema;
-Thread t;
+Thread evt_thread;
#include "network-helper.h"
/* List of trusted root CA certificates
@@ -388,13 +388,14 @@
//#define DISABLE_WIFI
#define DISABLE_WIFI_DEMO
+#define SKIP_WIFI_SCAN_DEMO
+#define BLE_STOP_START_ADV_SCAN_DEMO
+#define SKIP_WIFI_CONNECT_DEMO
int main() {
reset_counter++;
- //performFreeMemoryCheck();
print_memory_info();
printf("\r\n ++++++ PROGRAM STARTING -- reset count = %d ++++++ \r\n", reset_counter);
device = new RawSerial(USBTX, USBRX, DEFAULT_BAUD_RATE);
- //ble_security_main();
setupDefaultWiFiConfig();
setupDefaultBleConfig();
BLE& _ble = BLE::Instance();
@@ -408,24 +409,14 @@
#endif
print_memory_info();
printf("\r\n PERIPHERAL \r\n\r\n");
- //SMDevicePeripheral peripheral(ble, queue, peer_address);
peripheral = new SMDevicePeripheral(_ble, queue, peer_address, ble_config);
print_memory_info();
peripheral->run();
btle_thread.start(callback(&queue, &EventQueue::dispatch_forever));
- //btle_thread.start(callback(peripheral, &SMDevicePeripheral::run));
- //performFreeMemoryCheck();
- //reportGapState();
print_memory_info();
printWaitAbortKeyPress(120);
- //reportGapState();
peripheral->stopAdvertising();
- //queue.break_dispatch();
- //reportGapState();
- //btle_thread.join();
- //performFreeMemoryCheck();
- printf("\r\n BTLE THREAD HAS RETURNED \r\n\r\n");
#ifndef DISABLE_WIFI // comment out wifi part
int start = Kernel::get_ms_count();
@@ -445,26 +436,25 @@
int stop = Kernel::get_ms_count();
device->printf("\n The Wifi Network scan took %d ms or %4.1f seconds\n", (stop - start), (float)((stop - start)/1000.0));
// run on separate thread;
- t.start(callback(wifi_demo, network));
- t.join();
+ evt_thread.start(callback(wifi_demo, network));
+ evt_thread.join();
network->disconnect();
delete network;
device->printf("\n Wifi-Demo completed - restarting BLE \n\n");
-#endif
+#endif /// endif DISABLE_WIFI_DEMO
+
#else
device->printf("\n Wifi Demo disabled so just waiting it out... \n\n");
printWait(2); // lets wait for a minute before turning BLE back on
device->printf("\n ++++++ restarting BLE ++++++ \n\n");
-#endif
+#endif /// endif DISABLE_WIFI
+ printWaitAbortKeyPress(60);
peripheral->startAdvertising();
- printWait(2);
#ifdef ENABLE_UART_BACKGRND_DEMO
for(int i=0;i<255;i++)
{
device->putc(i);
}
- //int n;
- //ReadUartBytes(RxBuffer, RX_BUFFER_LEN, 4);
reportGapState();
device->printf("\n\n\nEnter # of expected bytes: ");
ReadUartBytes(RxBuffer, RX_BUFFER_LEN, 4, true);
@@ -482,7 +472,7 @@
device->printf("\r\n++++++ Press key for Wifi demo test ++++++ \r\n");
printWaitAbortKeyPress(120);
-#ifdef SKIP_WIFI_SCAN_DEMO
+#ifndef SKIP_WIFI_SCAN_DEMO
device->printf("\r\n++++++ Test WiFi Manager Network Scan ++++++ \r\n");
int count;
count = wiFiManager->scanNetworks();
@@ -493,6 +483,8 @@
device->printf("\r\n++++++ Test WiFi Scan found %d networks ++++++ \r\n ++++ SUCCESS ++++\r\n", count);
}
#endif
+
+#ifndef SKIP_WIFI_CONNECT_DEMO
device->printf("\r\n++++++ Test WiFi Manager Network connect ++++++ \r\n");
nsapi_error_t werror;
werror = wiFiManager->connect();
@@ -513,7 +505,7 @@
device->printf("\r\n++++++ Test WiFi disconnect SUCCESSFUL ++++++ \r\n");
}
}
-
+#endif
//wiFiManager->runMain();
device->printf("\r\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n");
device->printf("\r\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n");
@@ -522,13 +514,9 @@
device->printf("\r\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n");
device->printf("\r\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n");
device->printf("\r\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n");
- t.start(callback(wiFiManager, &WiFiManager::runMain));
- /* disconnect in 2 s */
- //_event_queue.call_in(
- // 2000, &_ble.gap(),
- // &Gap::disconnect, _handle, Gap::REMOTE_USER_TERMINATED_CONNECTION
- //eventQueue.dispatch_forever();
- wifi_thread.start(callback(&eventQueue, &EventQueue::dispatch_forever));
+ wifi_thread.start(callback(wiFiManager, &WiFiManager::runMain));
+ // dispatch event queue on event thread
+ evt_thread.start(callback(&eventQueue, &EventQueue::dispatch_forever));
device->printf("\r\n++++++ Starting ATCmdmanager ++++++ \r\n");
ATCmdManager *aTCmdManager = new ATCmdManager(USBTX, USBRX, peripheral,
eventQueue, wiFiManager,
@@ -537,8 +525,8 @@
&aT2WiFiDatamPool, &aT2WiFiDataQueue,
&wiFi2ATDatamPool, &wiFi2ATDataQueue,
true);
- aTCmdManager->runMain();
- //atcmd_thread.start(callback(aTCmdManager, &ATCmdManager::runMain));
+ //aTCmdManager->runMain();
+ atcmd_thread.start(callback(aTCmdManager, &ATCmdManager::runMain));
while(1) wait(0.1);
//performFreeMemoryCheck();