Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki(https://github.com/sevencore/BLEFOTA).

Dependencies:   mbed

Fork of mbed_fota by KIM HyoengJun

Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki.

ext_fota/BleMsgHandler.cpp

Committer:
dudnwjs
Date:
2015-06-23
Revision:
3:1e70387e1337
Parent:
2:dba344c91bce
Child:
4:60be78a172c2

File content as of revision 3:1e70387e1337:

#include "BleMsgHandler.h"
#include "dialog_fota_config.h"

namespace sevencore_fota{

BleMsgHandler::BleMsgHandler(Serial *_device)
{
    print_flag = 0;
    device = _device;
    SerialM = new SerialManager(_device);
    MsgQ = new MsgQueue(512);
    memset(recv_msg,0,512);
}

BleMsgHandler::BleMsgHandler(Serial *_device, Serial *_hostpc)
{
    print_flag = 1;
    device = _device;
    hostpc = _hostpc;
    SerialM = new SerialManager(_device,_hostpc);
    MsgQ = new MsgQueue(512);
    memset(recv_msg,0,512);
}

BleMsgHandler::~BleMsgHandler(void)
{
    free(SerialM);
    free(MsgQ);
}

void BleMsgHandler::PrintTitle(void)
{
    if( print_flag == 1 )
        hostpc->printf("Sevencore Fota : BleMsg Handler Start\n");
}

void BleMsgHandler::BleMsgAlloc( unsigned short id,
                                 unsigned short dest_id,
                                 unsigned short src_id,
                                 unsigned short data_len,
                                 void *pdata,
                                 uint8_t *msg )
{
    memset(msg,0,sizeof(msg));
    msg[0] = 0x05;
    memcpy(&msg[1],&id,sizeof(unsigned short));
    memcpy(&msg[1+1*sizeof(unsigned short)],&dest_id,sizeof(unsigned short));
    memcpy(&msg[1+2*sizeof(unsigned short)],&src_id,sizeof(unsigned short));
    memcpy(&msg[1+3*sizeof(unsigned short)],&data_len,sizeof(unsigned short));
    memcpy(&msg[1+4*sizeof(unsigned short)],pdata,data_len);
}

int BleMsgHandler::BleSendMsg(uint8_t *msg, unsigned short size)
{
   return  SerialM->SendToSerial(msg,size);
}

void BleMsgHandler::BleReceiveMsg(void)
{
    int receive_size = -1;//default
    while(receive_size == -1)
    {
        receive_size = SerialM->ReceiveToSerial(recv_msg);
    }
    
    uint8_t *msg;
    msg = new uint8_t[receive_size];
    memcpy(msg,recv_msg,receive_size);
    memset(recv_msg,0,512);
    MsgQ->EnQueue(msg);
}

void BleMsgHandler::BleMsgHandle(void)
{
    if( print_flag == 1)
        hostpc->printf("Ble-Massage Handle Function!\n");
        
    uint8_t *msg;
    msg = (uint8_t*)MsgQ->DeQueue();
    
    ble_hdr msg_hdr;
    memcpy(&msg_hdr, &msg[1], sizeof(msg_hdr));
    
    if( print_flag == 1 )
        hostpc->printf(" handle msg : id(%d), dst(%d), src(%d), len(%d) !\n",
         msg_hdr.bType, msg_hdr.bDstid, msg_hdr.bSrcid, msg_hdr.bLength);
    
    if (msg_hdr.bDstid != TASK_GTL)
        return;
    
}



 
}//namespace