Ethernet+BLE prototype
Dependencies: mbed EthernetInterface mbed-rtos
Diff: HttpSend.cpp
- Revision:
- 4:78e96198c879
- Parent:
- 3:d9445b9e7163
- Child:
- 5:9fffeb949e5a
diff -r d9445b9e7163 -r 78e96198c879 HttpSend.cpp --- a/HttpSend.cpp Thu Mar 27 10:17:11 2014 +0000 +++ b/HttpSend.cpp Fri Mar 28 01:10:32 2014 +0000 @@ -1,16 +1,16 @@ #include "config.h" #include "log.h" -#include "EthernetInterface.h" #include "HttpSend.h" #include "mbed.h" -//#include "rtos.h" -#include "cmsis_os.h" -EthernetInterface m_ethernet; MemoryPool<message_t, 64> m_mpool; Queue<message_t, 64> m_queue; +int m_mpCnt=0; + +EthernetInterface* m_ethernet; + osThreadId m_send_thread; void sendData(char* data, size_t length){ @@ -53,37 +53,43 @@ sock.close(); } + +// Thread::wait(3000); void send_thread (void const *argument) { INFO_LOG ("send_thread start\n"); + while (true) { osEvent evt = m_queue.get(); if (evt.status == osEventMessage) { message_t *message = (message_t*)evt.value.p; - DEBUG_LOG("(send_thread)size=%d:%s\n",message->size,message->data); - m_ethernet.connect(); - sendData(message->data, message->size); - m_ethernet.disconnect(); - m_mpool.free(message); - DEBUG_LOG ("*message=0x%08X free \n",message); + if(message!=NULL){ + DEBUG_LOG("(size=%d)(m_mpCnt=%d):%s",message->size,m_mpCnt,message->data); +// m_ethernet->connect(); +// INFO_LOG ("IP Address is %s \n", m_ethernet->getIPAddress()); +// sendData(message->data, message->size); +// m_ethernet->disconnect(); + m_mpool.free(message); + m_mpCnt--; +// DEBUG_LOG ("*message=0x%08X free \n",message); + } } + Thread::wait(100); } + // unreachable INFO_LOG ("send_thread end\n"); } osThreadDef(send_thread, osPriorityNormal, DEFAULT_STACK_SIZE); -void HttpSend::init(){ +void HttpSend::init(EthernetInterface* eth){ INFO_LOG ("HttpSend::init start\n"); - INFO_LOG ("1111111111 \n"); - m_ethernet.init(); - INFO_LOG ("222 \n"); - INFO_LOG ("IP Address is %s \n", m_ethernet.getIPAddress()); - INFO_LOG ("333 \n"); + m_ethernet = eth; m_send_thread = osThreadCreate(osThread(send_thread), NULL); INFO_LOG ("HttpSend::init end\n"); } message_t* HttpSend::getMessageBuffer(){ + m_mpCnt++; return m_mpool.alloc(); }