rlc: Add and use mod_sns(bsn) method
Currently there is only a mod_sns() method which is being used in
expression like bsn_expr & win.mod_sns(). This only works, because
it is known that mod_sns() is (sns() - 1) where sns() in turn is
always 2^n. This is error prone, hard to read, and relies on window
specifics that should be kept inside the respective module.
This commit adds a mod_sns(uint bsn) method to gprs_rlc_ul_window and
gprs_rlc_dl_window, that encapsulates and hides this optimized
computation.
Sponsored-by: On-Waves ehf
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 70194f7..8bac99f 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -703,9 +703,9 @@
return dl_msg;
}
-static uint16_t bitnum_to_bsn(int bitnum, uint16_t ssn, uint16_t mod_sns)
+static uint16_t bitnum_to_bsn(int bitnum, uint16_t ssn)
{
- return (ssn - 1 - bitnum) & mod_sns;
+ return ssn - 1 - bitnum;
}
int gprs_rlcmac_dl_tbf::analyse_errors(char *show_rbb, uint8_t ssn,
@@ -724,9 +724,9 @@
for (int bitpos = 0; bitpos < m_window.ws(); bitpos++) {
bool is_received = show_rbb[m_window.ws() - 1 - bitpos] == 'R';
- bsn = bitnum_to_bsn(bitpos, ssn, m_window.mod_sns());
+ bsn = m_window.mod_sns(bitnum_to_bsn(bitpos, ssn));
- if (bsn == ((m_window.v_a() - 1) & m_window.mod_sns())) {
+ if (bsn == m_window.mod_sns(m_window.v_a() - 1)) {
info[bitpos] = '$';
break;
}
@@ -794,19 +794,18 @@
uint16_t lost = 0, received = 0;
char show_rbb[65];
char show_v_b[RLC_MAX_SNS + 1];
- const uint16_t mod_sns = m_window.mod_sns();
int error_rate;
struct ana_result ana_res;
Decoding::extract_rbb(rbb, show_rbb);
/* show received array in debug (bit 64..1) */
LOGP(DRLCMACDL, LOGL_DEBUG, "- ack: (BSN=%d)\"%s\""
- "(BSN=%d) R=ACK I=NACK\n", (ssn - 64) & mod_sns,
- show_rbb, (ssn - 1) & mod_sns);
+ "(BSN=%d) R=ACK I=NACK\n", m_window.mod_sns(ssn - 64),
+ show_rbb, m_window.mod_sns(ssn - 1));
/* apply received array to receive state (SSN-64..SSN-1) */
/* calculate distance of ssn from V(S) */
- dist = (m_window.v_s() - ssn) & mod_sns;
+ dist = m_window.mod_sns(m_window.v_s() - ssn);
/* check if distance is less than distance V(A)..V(S) */
if (dist >= m_window.distance()) {
/* this might happpen, if the downlink assignment