![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BLE fota Lamp Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_fan_control by
ext_fota/BleMsgHandler.h@13:e714e2971c49, 2015-10-13 (annotated)
- Committer:
- dudnwjs
- Date:
- Tue Oct 13 06:35:19 2015 +0000
- Revision:
- 13:e714e2971c49
- Parent:
- 8:9eec2c246a85
lamp demo;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 8:9eec2c246a85 | 1 | /** |
dudnwjs | 8:9eec2c246a85 | 2 | * @file BleMsgHandler.h |
dudnwjs | 8:9eec2c246a85 | 3 | * @brief Ble message handler ( Ble message is communication mathod between Mbed and DA14583 ) |
dudnwjs | 8:9eec2c246a85 | 4 | * Copyright 2015 SEVENCORE Co., Ltd. |
dudnwjs | 8:9eec2c246a85 | 5 | * |
dudnwjs | 8:9eec2c246a85 | 6 | * @author HyeongJun Kim |
dudnwjs | 8:9eec2c246a85 | 7 | * @version 1.0.0 |
dudnwjs | 8:9eec2c246a85 | 8 | * @date 2015-08-17 |
dudnwjs | 8:9eec2c246a85 | 9 | */ |
dudnwjs | 8:9eec2c246a85 | 10 | |
dudnwjs | 0:a1f6b1ba8a1e | 11 | #ifndef BLEMSGHANDLER_H |
dudnwjs | 0:a1f6b1ba8a1e | 12 | #define BLEMSGHANDLER_H |
dudnwjs | 0:a1f6b1ba8a1e | 13 | |
dudnwjs | 8:9eec2c246a85 | 14 | /** |
dudnwjs | 8:9eec2c246a85 | 15 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 16 | * @addtogroup ext_fota module |
dudnwjs | 8:9eec2c246a85 | 17 | * @brief Ble message Handler Class Header. |
dudnwjs | 8:9eec2c246a85 | 18 | * |
dudnwjs | 8:9eec2c246a85 | 19 | * @{ |
dudnwjs | 8:9eec2c246a85 | 20 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 21 | */ |
dudnwjs | 8:9eec2c246a85 | 22 | |
dudnwjs | 0:a1f6b1ba8a1e | 23 | #include "mbed.h" |
dudnwjs | 0:a1f6b1ba8a1e | 24 | #include "MsgQueue.h" |
dudnwjs | 2:dba344c91bce | 25 | #include "SerialManager.h" |
dudnwjs | 4:60be78a172c2 | 26 | #include "gapc_task.h" |
dudnwjs | 4:60be78a172c2 | 27 | #include "gapm_task.h" |
dudnwjs | 0:a1f6b1ba8a1e | 28 | |
dudnwjs | 0:a1f6b1ba8a1e | 29 | namespace sevencore_fota{ |
dudnwjs | 6:8dd20294b2aa | 30 | |
dudnwjs | 6:8dd20294b2aa | 31 | #define FIRMWARE_DATA_FRAGMENT_SIZE 1024 |
dudnwjs | 6:8dd20294b2aa | 32 | |
dudnwjs | 3:1e70387e1337 | 33 | typedef struct { |
dudnwjs | 3:1e70387e1337 | 34 | unsigned short bType; |
dudnwjs | 3:1e70387e1337 | 35 | unsigned short bDstid; |
dudnwjs | 3:1e70387e1337 | 36 | unsigned short bSrcid; |
dudnwjs | 3:1e70387e1337 | 37 | unsigned short bLength; |
dudnwjs | 3:1e70387e1337 | 38 | } ble_hdr; |
dudnwjs | 3:1e70387e1337 | 39 | |
dudnwjs | 1:5cf3a6c969be | 40 | class BleMsgHandler |
dudnwjs | 0:a1f6b1ba8a1e | 41 | { |
dudnwjs | 0:a1f6b1ba8a1e | 42 | public: |
dudnwjs | 8:9eec2c246a85 | 43 | /** |
dudnwjs | 8:9eec2c246a85 | 44 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 45 | * @brief Ble message handler constructor only connected Device |
dudnwjs | 8:9eec2c246a85 | 46 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 47 | */ |
dudnwjs | 1:5cf3a6c969be | 48 | BleMsgHandler(Serial* _device); |
dudnwjs | 8:9eec2c246a85 | 49 | /** |
dudnwjs | 8:9eec2c246a85 | 50 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 51 | * @brief Ble message handler constructor with connected Device & HostPC |
dudnwjs | 8:9eec2c246a85 | 52 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 53 | */ |
dudnwjs | 1:5cf3a6c969be | 54 | BleMsgHandler(Serial* _device, Serial* _hostpc); |
dudnwjs | 8:9eec2c246a85 | 55 | /** |
dudnwjs | 8:9eec2c246a85 | 56 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 57 | * @brief Ble message handler destructor |
dudnwjs | 8:9eec2c246a85 | 58 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 59 | */ |
dudnwjs | 1:5cf3a6c969be | 60 | ~BleMsgHandler(void); |
dudnwjs | 8:9eec2c246a85 | 61 | /** |
dudnwjs | 8:9eec2c246a85 | 62 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 63 | * @brief Ble message handler Start title print function |
dudnwjs | 8:9eec2c246a85 | 64 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 65 | */ |
dudnwjs | 0:a1f6b1ba8a1e | 66 | void PrintTitle(void); |
dudnwjs | 8:9eec2c246a85 | 67 | /** |
dudnwjs | 8:9eec2c246a85 | 68 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 69 | * @brief Create ble message |
dudnwjs | 8:9eec2c246a85 | 70 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 71 | */ |
dudnwjs | 3:1e70387e1337 | 72 | void BleMsgAlloc(unsigned short id,unsigned short dest_id,unsigned short src_id,unsigned short data_len,void *pdata,uint8_t *msg); |
dudnwjs | 8:9eec2c246a85 | 73 | /** |
dudnwjs | 8:9eec2c246a85 | 74 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 75 | * @brief Send ble message to device |
dudnwjs | 8:9eec2c246a85 | 76 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 77 | */ |
dudnwjs | 3:1e70387e1337 | 78 | int BleSendMsg(uint8_t *msg, unsigned short size); |
dudnwjs | 8:9eec2c246a85 | 79 | /** |
dudnwjs | 8:9eec2c246a85 | 80 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 81 | * @brief Receive ble message from device |
dudnwjs | 8:9eec2c246a85 | 82 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 83 | */ |
dudnwjs | 3:1e70387e1337 | 84 | void BleReceiveMsg(void); |
dudnwjs | 8:9eec2c246a85 | 85 | /** |
dudnwjs | 8:9eec2c246a85 | 86 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 87 | * @brief Get message from MsgQueue and Execute corresponding function |
dudnwjs | 8:9eec2c246a85 | 88 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 89 | */ |
dudnwjs | 3:1e70387e1337 | 90 | void BleMsgHandle(void); |
dudnwjs | 8:9eec2c246a85 | 91 | /** |
dudnwjs | 8:9eec2c246a85 | 92 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 93 | * @brief Debugging message output to hostpc |
dudnwjs | 8:9eec2c246a85 | 94 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 95 | */ |
dudnwjs | 5:e11b23f9aacc | 96 | void HostPcPrint(char *str); |
dudnwjs | 8:9eec2c246a85 | 97 | /** |
dudnwjs | 8:9eec2c246a85 | 98 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 99 | * @brief Receive test method |
dudnwjs | 8:9eec2c246a85 | 100 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 101 | */ |
dudnwjs | 5:e11b23f9aacc | 102 | void ReceiveToSerialTest(void); |
dudnwjs | 8:9eec2c246a85 | 103 | /** |
dudnwjs | 8:9eec2c246a85 | 104 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 105 | * @brief Receive and Store Da14583 flash data |
dudnwjs | 8:9eec2c246a85 | 106 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 107 | */ |
dudnwjs | 6:8dd20294b2aa | 108 | void FirmwareDataReceive(unsigned short code_size, char *version); |
dudnwjs | 6:8dd20294b2aa | 109 | |
dudnwjs | 0:a1f6b1ba8a1e | 110 | |
dudnwjs | 4:60be78a172c2 | 111 | |
dudnwjs | 0:a1f6b1ba8a1e | 112 | private: |
dudnwjs | 8:9eec2c246a85 | 113 | /** |
dudnwjs | 8:9eec2c246a85 | 114 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 115 | * @brief GAPM Command Event Handler |
dudnwjs | 8:9eec2c246a85 | 116 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 117 | */ |
dudnwjs | 4:60be78a172c2 | 118 | void HandleGapmCmpEvt(unsigned short msgid,struct gapm_cmp_evt *param,unsigned short dest_id,unsigned short src_id); |
dudnwjs | 8:9eec2c246a85 | 119 | /** |
dudnwjs | 8:9eec2c246a85 | 120 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 121 | * @brief GAPC Command Event Handler |
dudnwjs | 8:9eec2c246a85 | 122 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 123 | */ |
dudnwjs | 4:60be78a172c2 | 124 | void HandleGapcCmpEvt(unsigned short msgid,struct gapc_cmp_evt *param,unsigned short dest_id,unsigned short src_id); |
dudnwjs | 8:9eec2c246a85 | 125 | |
dudnwjs | 8:9eec2c246a85 | 126 | |
dudnwjs | 8:9eec2c246a85 | 127 | private: |
dudnwjs | 0:a1f6b1ba8a1e | 128 | bool print_flag; |
dudnwjs | 0:a1f6b1ba8a1e | 129 | Serial* device; |
dudnwjs | 0:a1f6b1ba8a1e | 130 | Serial* hostpc; |
dudnwjs | 2:dba344c91bce | 131 | SerialManager* SerialM; |
dudnwjs | 3:1e70387e1337 | 132 | MsgQueue* MsgQ; |
dudnwjs | 3:1e70387e1337 | 133 | unsigned char recv_msg[512]; |
dudnwjs | 6:8dd20294b2aa | 134 | FILE *fp; |
dudnwjs | 1:5cf3a6c969be | 135 | }; |
dudnwjs | 0:a1f6b1ba8a1e | 136 | |
dudnwjs | 0:a1f6b1ba8a1e | 137 | }//namespace |
dudnwjs | 0:a1f6b1ba8a1e | 138 | |
dudnwjs | 8:9eec2c246a85 | 139 | /// @} ext_fota module |
dudnwjs | 1:5cf3a6c969be | 140 | #endif //BLEMSGHANDLER_H |