8000 CEspControl - added getStationRx/getSoftApRx with buffer as parameter · Networking-for-Arduino/ESPHost@8357b4c · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 8357b4c

Browse files
committed
CEspControl - added getStationRx/getSoftApRx with buffer as parameter
1 parent c0b45e6 commit 8357b4c

File tree

4 files changed

+81
-9
lines changed

4 files changed

+81
-9
lines changed

src/CEspCommunication.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,21 @@ bool CEspCom::getMsgForSoftAp(CMsg &msg) {
156156
}
157157
return false;
158158
}
159+
160+
/* -------------------------------------------------------------------------- */
161+
int CEspCom::peekPayloadLenForStation() {
162+
/* -------------------------------------------------------------------------- */
163+
if(CEspCom::rxStationQueue.size() > 0) {
164+
return CEspCom::rxStationQueue.front().get_payload_len();
165+
}
166+
return 0;
167+
}
168+
169+
/* -------------------------------------------------------------------------- */
170+
int CEspCom::peekPayloadLenForSoftAp() {
171+
/* -------------------------------------------------------------------------- */
172+
if(CEspCom::rxSoftApQueue.size() > 0) {
173+
return CEspCom::rxSoftApQueue.front().get_payload_len();
174+
}
175+
return 0;
176+
}

src/CEspCommunication.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class CEspCom {
6262
static bool getMsgForStation(CMsg &msg);
6363
static int peekMsgSizeForStation();
6464
static bool getMsgForSoftAp(CMsg &msg);
65+
static int peekPayloadLenForStation();
66+
static int peekPayloadLenForSoftAp();
6567

6668
static void clearStationRx();
6769
static void clearSoftApRx();

src/CEspControl.cpp

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020

2121
#include "CEspControl.h"
2222

23-
extern int esp_host_perform_spi_communication();
24-
extern int esp_host_spi_init(void);
25-
26-
2723
/* -------------------------------------------------------------------------- */
2824
/* GET INSTANCE SINGLETONE FUNCTION */
2925
/* -------------------------------------------------------------------------- */
@@ -48,11 +44,6 @@ CEspControl::~CEspControl() {
4844

4945
}
5046

51-
52-
53-
54-
55-
5647
/* process priv messages */
5748
/* -------------------------------------------------------------------------- */
5849
int CEspControl::process_priv_messages(CCtrlMsgWrapper* response) {
@@ -90,6 +81,25 @@ uint8_t *CEspControl::getStationRx(uint8_t &if_num, uint16_t &dim) {
9081
return rv;
9182
}
9283

84+
/* -------------------------------------------------------------------------- */
85+
uint16_t CEspControl::getStationRx(uint8_t &if_num, uint8_t *buff, uint16_t dim) {
86+
/* -------------------------------------------------------------------------- */
87+
CMsg msg;
88+
//__disable_irq();
89+
bool res = CEspCom::getMsgForStation(msg);
90+
if (!res) {
91+
CEspCom::clearStationRx();
92+
return 0;
93+
}
94+
//__enable_irq();
95+
if_num = msg.get_if_num();
96+
uint16_t len = msg.get_protobuf_dim();
97+
if (len > dim)
98+
return -1;
99+
memcpy(buff, msg.data(), len);
100+
return len;
101+
}
102+
93103
/* -------------------------------------------------------------------------- */
94104
uint16_t CEspControl::peekStationRxMsgSize() {
95105
/* -------------------------------------------------------------------------- */
@@ -100,6 +110,16 @@ uint16_t CEspControl::peekStationRxMsgSize() {
100110
return res;
101111
}
102112

113+
/* -------------------------------------------------------------------------- */
114+
uint16_t CEspControl::peekStationRxPayloadLen() {
115+
/* -------------------------------------------------------------------------- */
116+
uint16_t res;
117+
//__disable_irq();
118+
res = CEspCom::peekPayloadLenForStation();
119+
//__enable_irq();
120+
return res;
121+
}
122+
103123
/* -------------------------------------------------------------------------- */
104124
uint8_t *CEspControl::getSoftApRx(uint8_t &if_num, uint16_t &dim) {
105125
/* -------------------------------------------------------------------------- */
@@ -122,6 +142,34 @@ uint8_t *CEspControl::getSoftApRx(uint8_t &if_num, uint16_t &dim) {
122142
return rv;
123143
}
124144

145+
/* -------------------------------------------------------------------------- */
146+
uint16_t CEspControl::getSoftApRx(uint8_t &if_num, uint8_t *buff, uint16_t dim) {
147+
/* -------------------------------------------------------------------------- */
148+
CMsg msg;
149+
//__disable_irq();
150+
bool res = CEspCom::getMsgForSoftAp(msg);
151+
if (!res) {
152+
CEspCom::clearSoftApRx();
153+
return 0;
154+
}
155+
//__enable_irq();
156+
if_num = msg.get_if_num();
157+
uint16_t len = msg.get_protobuf_dim();
158+
if (len > dim)
159+
return -1;
160+
memcpy(buff, msg.data(), len);
161+
return len;
162+
}
163+
164+
/* -------------------------------------------------------------------------- */
165+
uint16_t CEspControl::peekSoftApRxPayloadLen() {
166+
/* -------------------------------------------------------------------------- */
167+
uint16_t res;
168+
//__disable_irq();
169+
res = CEspCom::peekPayloadLenForSoftAp();
170+
//__enable_irq();
171+
return res;
172+
}
125173

126174
/* -------------------------------------------------------------------------- */
127175
/* PROCESS CONTROL MESSAGES */

src/CEspControl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ class CEspControl {
136136
int sendBuffer(ESP_INTERFACE_TYPE type, uint8_t num, uint8_t *buf, uint16_t dim);
137137

138138
uint8_t *getStationRx(uint8_t &if_num, uint16_t &dim);
139+
uint16_t getStationRx(uint8_t &if_num, uint8_t *buff, uint16_t dim);
139140
uint16_t peekStationRxMsgSize();
141+
uint16_t peekStationRxPayloadLen();
140142
uint8_t *getSoftApRx(uint8_t &if_num, uint16_t &dim);
143+
uint16_t getSoftApRx(uint8_t &if_num, uint8_t *buff, uint16_t dim);
144+
uint16_t peekSoftApRxPayloadLen();
141145

142146

143147

0 commit comments

Comments
 (0)
0