BLE fota Lamp Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_fan_control by
ext_fota/MsgQueue.cpp@9:fcf91f563147, 2015-08-24 (annotated)
- Committer:
- dudnwjs
- Date:
- Mon Aug 24 02:29:16 2015 +0000
- Revision:
- 9:fcf91f563147
- Parent:
- 8:9eec2c246a85
Add comment for form doxygen;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 8:9eec2c246a85 | 1 | /** |
dudnwjs | 8:9eec2c246a85 | 2 | * @file MsgQueue.cpp |
dudnwjs | 8:9eec2c246a85 | 3 | * @brief Ble message queue |
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-19 |
dudnwjs | 8:9eec2c246a85 | 9 | */ |
dudnwjs | 1:5cf3a6c969be | 10 | #include "MsgQueue.h" |
dudnwjs | 0:a1f6b1ba8a1e | 11 | #include "mbed.h" |
dudnwjs | 8:9eec2c246a85 | 12 | /** |
dudnwjs | 8:9eec2c246a85 | 13 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 14 | * @addtogroup ext_fota module |
dudnwjs | 8:9eec2c246a85 | 15 | * @brief Ble message Queue Class Method Definition. |
dudnwjs | 8:9eec2c246a85 | 16 | * |
dudnwjs | 8:9eec2c246a85 | 17 | * @{ |
dudnwjs | 8:9eec2c246a85 | 18 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 19 | */ |
dudnwjs | 0:a1f6b1ba8a1e | 20 | namespace sevencore_fota{ |
dudnwjs | 9:fcf91f563147 | 21 | /** |
dudnwjs | 9:fcf91f563147 | 22 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 23 | * @brief Ble Message Queue Constructor. |
dudnwjs | 9:fcf91f563147 | 24 | * @param[in] Message Queue Size. |
dudnwjs | 9:fcf91f563147 | 25 | * @detail Default size is 512 |
dudnwjs | 9:fcf91f563147 | 26 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 27 | */ |
dudnwjs | 1:5cf3a6c969be | 28 | MsgQueue::MsgQueue(int MaxSize):MaxNum(MaxSize) |
dudnwjs | 0:a1f6b1ba8a1e | 29 | { |
dudnwjs | 0:a1f6b1ba8a1e | 30 | Front = NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 31 | Rear = NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 32 | ElemCnt = 0; |
dudnwjs | 0:a1f6b1ba8a1e | 33 | } |
dudnwjs | 9:fcf91f563147 | 34 | /** |
dudnwjs | 9:fcf91f563147 | 35 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 36 | * @brief Ble Message Queue Destructor. |
dudnwjs | 9:fcf91f563147 | 37 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 38 | */ |
dudnwjs | 1:5cf3a6c969be | 39 | MsgQueue::~MsgQueue(void) |
dudnwjs | 0:a1f6b1ba8a1e | 40 | { |
dudnwjs | 0:a1f6b1ba8a1e | 41 | } |
dudnwjs | 9:fcf91f563147 | 42 | /** |
dudnwjs | 9:fcf91f563147 | 43 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 44 | * @brief Add message in queue. |
dudnwjs | 9:fcf91f563147 | 45 | * @param[in] Ble message void pointer. |
dudnwjs | 9:fcf91f563147 | 46 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 47 | */ |
dudnwjs | 1:5cf3a6c969be | 48 | void MsgQueue::EnQueue(void *vData) |
dudnwjs | 0:a1f6b1ba8a1e | 49 | { |
dudnwjs | 0:a1f6b1ba8a1e | 50 | Element *tmp = new Element; |
dudnwjs | 0:a1f6b1ba8a1e | 51 | tmp->Data = vData; |
dudnwjs | 0:a1f6b1ba8a1e | 52 | tmp->Next = NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 53 | ElemCnt++; |
dudnwjs | 0:a1f6b1ba8a1e | 54 | if( Front == NULL) |
dudnwjs | 0:a1f6b1ba8a1e | 55 | { |
dudnwjs | 0:a1f6b1ba8a1e | 56 | Front = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 57 | Rear = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 58 | }else |
dudnwjs | 0:a1f6b1ba8a1e | 59 | { |
dudnwjs | 0:a1f6b1ba8a1e | 60 | Rear->Next = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 61 | Rear = tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 62 | } |
dudnwjs | 0:a1f6b1ba8a1e | 63 | } |
dudnwjs | 9:fcf91f563147 | 64 | /** |
dudnwjs | 9:fcf91f563147 | 65 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 66 | * @brief Remove message in queue. |
dudnwjs | 9:fcf91f563147 | 67 | * @return void pointer(*void) |
dudnwjs | 9:fcf91f563147 | 68 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 69 | */ |
dudnwjs | 1:5cf3a6c969be | 70 | void *MsgQueue::DeQueue(void) |
dudnwjs | 0:a1f6b1ba8a1e | 71 | { |
dudnwjs | 0:a1f6b1ba8a1e | 72 | void *tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 73 | Element *tmpElem; |
dudnwjs | 0:a1f6b1ba8a1e | 74 | |
dudnwjs | 0:a1f6b1ba8a1e | 75 | if(Front == NULL) |
dudnwjs | 0:a1f6b1ba8a1e | 76 | return NULL; |
dudnwjs | 0:a1f6b1ba8a1e | 77 | |
dudnwjs | 0:a1f6b1ba8a1e | 78 | ElemCnt--; |
dudnwjs | 0:a1f6b1ba8a1e | 79 | tmpElem = Front; |
dudnwjs | 0:a1f6b1ba8a1e | 80 | Front = tmpElem->Next; |
dudnwjs | 0:a1f6b1ba8a1e | 81 | tmp = tmpElem->Data; |
dudnwjs | 0:a1f6b1ba8a1e | 82 | free(tmpElem); |
dudnwjs | 0:a1f6b1ba8a1e | 83 | |
dudnwjs | 0:a1f6b1ba8a1e | 84 | return tmp; |
dudnwjs | 0:a1f6b1ba8a1e | 85 | } |
dudnwjs | 9:fcf91f563147 | 86 | /** |
dudnwjs | 9:fcf91f563147 | 87 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 88 | * @brief Return queue element count. |
dudnwjs | 9:fcf91f563147 | 89 | * @return Integer element count. |
dudnwjs | 9:fcf91f563147 | 90 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 91 | */ |
dudnwjs | 1:5cf3a6c969be | 92 | int MsgQueue::GetElementCount(void) |
dudnwjs | 0:a1f6b1ba8a1e | 93 | { |
dudnwjs | 0:a1f6b1ba8a1e | 94 | return ElemCnt; |
dudnwjs | 0:a1f6b1ba8a1e | 95 | } |
dudnwjs | 9:fcf91f563147 | 96 | /** |
dudnwjs | 9:fcf91f563147 | 97 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 98 | * @brief Boolean that queue is empty. |
dudnwjs | 9:fcf91f563147 | 99 | * @return Boolean. |
dudnwjs | 9:fcf91f563147 | 100 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 101 | */ |
dudnwjs | 1:5cf3a6c969be | 102 | bool MsgQueue::IsEmpty(void) |
dudnwjs | 0:a1f6b1ba8a1e | 103 | { |
dudnwjs | 0:a1f6b1ba8a1e | 104 | if( Front == NULL) |
dudnwjs | 0:a1f6b1ba8a1e | 105 | return false; |
dudnwjs | 0:a1f6b1ba8a1e | 106 | else |
dudnwjs | 0:a1f6b1ba8a1e | 107 | return true; |
dudnwjs | 0:a1f6b1ba8a1e | 108 | } |
dudnwjs | 0:a1f6b1ba8a1e | 109 | |
dudnwjs | 0:a1f6b1ba8a1e | 110 | }//namespace |
dudnwjs | 9:fcf91f563147 | 111 | /// @} ext_fota module |