Ethernet+BLE prototype

Dependencies:   mbed EthernetInterface mbed-rtos

Committer:
teruo
Date:
Fri Mar 28 01:10:32 2014 +0000
Revision:
4:78e96198c879
Parent:
3:d9445b9e7163
Child:
5:9fffeb949e5a
??????????????
; Serial.attach & callback ?????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
teruo 0:da21a9dd2303 1 #include "mbed.h"
teruo 0:da21a9dd2303 2 #include "config.h"
teruo 0:da21a9dd2303 3 #include "log.h"
teruo 3:d9445b9e7163 4 #include "HttpSend.h"
teruo 4:78e96198c879 5 #include "cmsis_os.h"
teruo 3:d9445b9e7163 6
teruo 3:d9445b9e7163 7 Serial bleModule(p9,p10);
teruo 3:d9445b9e7163 8
teruo 4:78e96198c879 9 osThreadId m_jm1_receive_thread;
teruo 4:78e96198c879 10
teruo 4:78e96198c879 11
teruo 3:d9445b9e7163 12 HttpSend m_httpsend;
teruo 3:d9445b9e7163 13
teruo 4:78e96198c879 14 void jm1_receive_thread (void const *argument) {
teruo 4:78e96198c879 15 INFO_LOG ("jm1_receive_thread start\n");
teruo 3:d9445b9e7163 16 while (true) {
teruo 3:d9445b9e7163 17 if(bleModule.readable()){
teruo 4:78e96198c879 18 message_t *message = m_httpsend.getMessageBuffer();
teruo 4:78e96198c879 19 memset(message->data,0,SENDBUFFER_SIZE);
teruo 4:78e96198c879 20 // INFO_LOG("(message=0x%08X)\n",message);
teruo 3:d9445b9e7163 21 if(NULL!=bleModule.gets(message->data, SENDBUFFER_SIZE)){
teruo 4:78e96198c879 22 message->size = strlen(message->data);
teruo 3:d9445b9e7163 23 if(message->size!=0){
teruo 4:78e96198c879 24 // INFO_LOG("(size=%d):%s",message->size,message->data);
teruo 3:d9445b9e7163 25 m_httpsend.send(message);
teruo 3:d9445b9e7163 26 }
teruo 3:d9445b9e7163 27 }
teruo 3:d9445b9e7163 28 }
teruo 3:d9445b9e7163 29 }
teruo 4:78e96198c879 30 // unreachable INFO_LOG ("jm1_receive_thread end\n");
teruo 3:d9445b9e7163 31 }
teruo 3:d9445b9e7163 32
teruo 3:d9445b9e7163 33
teruo 3:d9445b9e7163 34 void callback() {
teruo 4:78e96198c879 35 INFO_LOG ("callback\n");
teruo 3:d9445b9e7163 36 if(bleModule.readable()){
teruo 4:78e96198c879 37 message_t *message = m_httpsend.getMessageBuffer();
teruo 4:78e96198c879 38 memset(message->data,0,SENDBUFFER_SIZE);
teruo 4:78e96198c879 39 // INFO_LOG("(message=0x%08X)\n",message);
teruo 3:d9445b9e7163 40 if(NULL!=bleModule.gets(message->data, SENDBUFFER_SIZE)){
teruo 4:78e96198c879 41 message->size = strlen(message->data);
teruo 3:d9445b9e7163 42 if(message->size!=0){
teruo 4:78e96198c879 43 // INFO_LOG("(size=%d):%s",message->size,message->data);
teruo 3:d9445b9e7163 44 m_httpsend.send(message);
teruo 3:d9445b9e7163 45 }
teruo 3:d9445b9e7163 46 }
teruo 3:d9445b9e7163 47 }
teruo 3:d9445b9e7163 48 }
teruo 3:d9445b9e7163 49
teruo 4:78e96198c879 50
teruo 4:78e96198c879 51 //osThreadDef(jm1_receive_thread, osPriorityRealtime, DEFAULT_STACK_SIZE);
teruo 4:78e96198c879 52 osThreadDef(jm1_receive_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
teruo 0:da21a9dd2303 53
teruo 0:da21a9dd2303 54 int main() {
teruo 4:78e96198c879 55 INFO_LOG ("BLE GW main start !!!\n");
teruo 0:da21a9dd2303 56
teruo 3:d9445b9e7163 57 /*************************/
teruo 0:da21a9dd2303 58 // Initialize
teruo 3:d9445b9e7163 59 /*************************/
teruo 4:78e96198c879 60 // EthernetInterface
teruo 4:78e96198c879 61 EthernetInterface eth;
teruo 4:78e96198c879 62 eth.init();
teruo 4:78e96198c879 63
teruo 3:d9445b9e7163 64 // HttpSend
teruo 4:78e96198c879 65 m_httpsend.init(&eth);
teruo 4:78e96198c879 66
teruo 3:d9445b9e7163 67 // Serial
teruo 3:d9445b9e7163 68 bleModule.baud(115200);
teruo 0:da21a9dd2303 69
teruo 4:78e96198c879 70 if(true){
teruo 4:78e96198c879 71 m_jm1_receive_thread = osThreadCreate(osThread(jm1_receive_thread), NULL);
teruo 4:78e96198c879 72 // Thread::wait(3000);
teruo 4:78e96198c879 73 INFO_LOG ("init end\n");
teruo 4:78e96198c879 74 while(true) {
teruo 4:78e96198c879 75 osDelay(osWaitForever);
teruo 4:78e96198c879 76 INFO_LOG ("WaitForever stop \n");
teruo 4:78e96198c879 77 wait(0.5);
teruo 4:78e96198c879 78 }
teruo 4:78e96198c879 79 }else{
teruo 4:78e96198c879 80 DigitalOut led1(LED1);
teruo 3:d9445b9e7163 81
teruo 4:78e96198c879 82 bleModule.attach(&callback);
teruo 4:78e96198c879 83 while(true) {
teruo 4:78e96198c879 84 led1 = !led1;
teruo 4:78e96198c879 85 wait(0.5);
teruo 4:78e96198c879 86 }
teruo 0:da21a9dd2303 87 }
teruo 3:d9445b9e7163 88 // unreachable INFO_LOG ("BLE GW main stop !!!\n");
teruo 0:da21a9dd2303 89 }