diff options
author | PikalaxALT <PikalaxALT@users.noreply.github.com> | 2020-04-27 19:11:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-27 19:11:39 -0400 |
commit | 9f8f350da367a81114efe7f0286116e719ec7d8f (patch) | |
tree | f1488a9f07b69d55579bbafd5a2f4089cbee3b3e | |
parent | b9a564621066226c3a43f9a87242e6ecd1d836c0 (diff) | |
parent | 2d0dace7e0ea18aec09d26a3f6a92e337e2d6028 (diff) |
Merge pull request #334 from jiangzhengwenjz/nonmatching
fix remainSize field in librfu
-rw-r--r-- | include/librfu.h | 3 | ||||
-rw-r--r-- | src/librfu_rfu.c | 48 |
2 files changed, 24 insertions, 27 deletions
diff --git a/include/librfu.h b/include/librfu.h index 3c9d776f1..de5cdcdbc 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -376,8 +376,7 @@ struct NIComm u16 state; // Communication state of slot u16 failCounter; // Count of failed transmissions/receptions (Count is increased when transmission/reception of data does not succeed within 1PF=16.7 ms) const u8 *now_p[WINDOW_COUNT]; // Address of current send/receive (The data is divided into WINDOW_COUNT blocks and sent in payloadSize units.) - // remainSize is u32 in SDK. This is a hack to match ASM - s32 remainSize; // Size of remaining communication data + u32 remainSize; // Size of remaining communication data u16 errorCode; // Error code u8 bmSlot; // Expresses the current communication slot in bits // (When sending from the Master, because multiple slaves can be specified with bmSlot, communications are terminated based on the failCounter for each child device) diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 582060f78..aed851e95 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -1,3 +1,4 @@ +#include <limits.h> #include "librfu.h" struct LLSFStruct @@ -1800,7 +1801,7 @@ static u16 rfu_STC_NI_constructLLSF(u8 bm_slot_id, u8 **dest_pp, struct NIComm * } else { - if ((u32)NI_comm->remainSize >= NI_comm->payloadSize) + if (NI_comm->remainSize >= NI_comm->payloadSize) size = NI_comm->payloadSize; else size = NI_comm->remainSize; @@ -2095,34 +2096,31 @@ static void rfu_STC_NI_receive_Sender(u8 NI_slot, u8 bm_flag, const struct RfuLo else NI_comm->now_p[llsf_NI->phase] += NI_comm->payloadSize << 2; NI_comm->remainSize -= NI_comm->payloadSize; - if (NI_comm->remainSize != 0) - if (NI_comm->remainSize >= 0) - goto _081E30AE; - // Above is a hack to avoid optimization over comparison. - // rfu_STC_NI_constructLLSF uses this field as u32. - // It's equivalent to the following condition: - // if (NI_comm->remainSize == 0 || NI_comm->remainSize < 0) + switch (NI_comm->remainSize) + { + default: + case 0: + NI_comm->phase = 0; + if (NI_comm->state == SLOT_STATE_SEND_START) { - NI_comm->phase = 0; - if (NI_comm->state == SLOT_STATE_SEND_START) + for (i = 0; i < WINDOW_COUNT; ++i) { - for (i = 0; i < WINDOW_COUNT; ++i) - { - NI_comm->n[i] = 1; - NI_comm->now_p[i] = NI_comm->src + NI_comm->payloadSize * i; - } - NI_comm->remainSize = NI_comm->dataSize; - NI_comm->state = SLOT_STATE_SENDING; - } - else - { - NI_comm->n[0] = 0; - NI_comm->remainSize = 0; - NI_comm->state = SLOT_STATE_SEND_LAST; + NI_comm->n[i] = 1; + NI_comm->now_p[i] = NI_comm->src + NI_comm->payloadSize * i; } + NI_comm->remainSize = NI_comm->dataSize; + NI_comm->state = SLOT_STATE_SENDING; } - _081E30AE: - ; + else + { + NI_comm->n[0] = 0; + NI_comm->remainSize = 0; + NI_comm->state = SLOT_STATE_SEND_LAST; + } + break; + case 1 ... INT_MAX: + break; + } } else if (NI_comm->state == SLOT_STATE_SEND_LAST) { |