Skip to content

Commit a70d157

Browse files
committed
add isWaiting for AdaMsg
1 parent 2d04696 commit a70d157

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libraries/Bluefruit52Lib/src/utility/AdaMsg.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,21 @@
3636

3737
#include "AdaMsg.h"
3838

39-
AdaMsg::AdaMsg(void)
39+
void AdaMsg::_init(void)
4040
{
4141
_dynamic = true;
42+
_waiting = false;
4243
_sem = NULL;
4344

4445
buffer = NULL;
4546
remaining = xferlen = 0;
4647
}
4748

49+
AdaMsg::AdaMsg(void)
50+
{
51+
_init();
52+
}
53+
4854
// dynamic mean semaphore is malloced and freed only when in action
4955
void AdaMsg::begin(bool dynamic)
5056
{
@@ -58,6 +64,7 @@ void AdaMsg::begin(bool dynamic)
5864
void AdaMsg::stop(void)
5965
{
6066
if (!_dynamic) vSemaphoreDelete(_sem);
67+
_init();
6168
}
6269

6370
void AdaMsg::prepare(void* buf, uint16_t bufsize)
@@ -82,10 +89,12 @@ int32_t AdaMsg::waitUntilComplete(uint32_t ms)
8289

8390
int result = -1;
8491

92+
_waiting = true;
8593
if ( xSemaphoreTake(_sem, ms2tick(ms) ) )
8694
{
8795
result = xferlen;
8896
}
97+
_waiting = false;
8998

9099
if (_dynamic)
91100
{
@@ -96,6 +105,11 @@ int32_t AdaMsg::waitUntilComplete(uint32_t ms)
96105
return result;
97106
}
98107

108+
bool AdaMsg::isWaiting(void)
109+
{
110+
return _waiting;
111+
}
112+
99113
uint16_t AdaMsg::feed(void* data, uint16_t len)
100114
{
101115
len = min16(len, remaining);

libraries/Bluefruit52Lib/src/utility/AdaMsg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ class AdaMsg
4242
{
4343
private:
4444
bool _dynamic;
45+
volatile bool _waiting;
4546
SemaphoreHandle_t _sem;
4647

48+
void _init(void);
49+
4750
public:
4851
uint8_t* buffer;
4952
uint16_t remaining;
@@ -57,6 +60,7 @@ class AdaMsg
5760

5861
void prepare(void* buf, uint16_t bufsize);
5962
int32_t waitUntilComplete(uint32_t ms);
63+
bool isWaiting(void);
6064

6165
uint16_t feed(void* data, uint16_t len);
6266
void complete(void);

0 commit comments

Comments
 (0)