Skip to content

Commit

Permalink
avoid codal message Q overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jul 28, 2022
1 parent 457a0d6 commit e7d6d12
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ static inline void raiseEvent(int src, int val) {
#endif
}


#define MAX_RX 10
#define MAX_TX 10

static LinkedFrame *volatile rxQ;
static LinkedFrame *volatile txQ;
static LinkedFrame *superFrameRX;
static bool data_ready_rised;

extern "C" REAL_TIME_FUNC
jd_frame_t *app_pull_frame() {
extern "C" REAL_TIME_FUNC jd_frame_t *app_pull_frame() {
target_disable_irq();
jd_frame_t *res = NULL;
if (txQ) {
Expand Down Expand Up @@ -100,7 +99,10 @@ extern "C" int app_handle_frame(jd_frame_t *frame) {
if (copyAndAppend(&rxQ, frame, MAX_RX) < 0) {
return -1;
} else {
raiseEvent(DEVICE_ID, EVT_DATA_READY);
if (!data_ready_rised) {
data_ready_rised = true;
raiseEvent(DEVICE_ID, EVT_DATA_READY);
}
return 0;
}
}
Expand Down Expand Up @@ -161,19 +163,22 @@ Buffer __physGetPacket() {
superFrameRX = NULL;
}

if (!superFrameRX && rxQ) {
if (!superFrameRX) {
target_disable_irq();
if ((superFrameRX = rxQ) != NULL)
rxQ = rxQ->next;
if (!superFrameRX)
data_ready_rised = false;
target_enable_irq();

if (!superFrameRX)
return NULL;

if (pxt::logJDFrame && !(superFrameRX->frame.flags & FRAME_EXT_FLAG) &&
!isFloodPingReport((jd_packet_t *)&superFrameRX->frame))
pxt::logJDFrame((uint8_t *)&superFrameRX->frame);
}

if (!superFrameRX)
return NULL;

auto pkt = (jd_packet_t *)&superFrameRX->frame;
return mkBuffer(pkt, JD_SERIAL_FULL_HEADER_SIZE + pkt->service_size);
}
Expand Down

0 comments on commit e7d6d12

Please sign in to comment.