Change in osmo-pcu[master]: MCS: add mcs_is_*() helpers

Max gerrit-no-reply at lists.osmocom.org
Tue Mar 12 14:53:08 UTC 2019


Max has uploaded this change for review. ( https://gerrit.osmocom.org/13214


Change subject: MCS: add mcs_is_*() helpers
......................................................................

MCS: add mcs_is_*() helpers

In preparation for Channel Coding Command encoder in follow-up patches
let's add necessary helpers. Those are similar to previously used
helpers from GprsCodingScheme class but without CamelCase and with less
typo chances between Gprs and Egprs cases.

Change-Id: I6699cbc8d7ae766fa4d2b3d37e5f9ff1cf158b7e
---
M src/coding_scheme.c
M src/coding_scheme.h
M src/decoding.cpp
M src/encoding.cpp
M src/gprs_coding_scheme.cpp
M src/gprs_coding_scheme.h
M src/gprs_ms.cpp
M src/pdch.cpp
M src/tbf.cpp
M src/tbf_dl.cpp
M src/tbf_ul.cpp
M tests/edge/EdgeTest.cpp
12 files changed, 65 insertions(+), 45 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/14/13214/1

diff --git a/src/coding_scheme.c b/src/coding_scheme.c
index 9e9df6f..28bd4fb 100644
--- a/src/coding_scheme.c
+++ b/src/coding_scheme.c
@@ -46,6 +46,24 @@
 	return get_value_string(mcs_names, val);
 }
 
+bool mcs_is_gprs(enum CodingScheme cs)
+{
+	return CS1 <= cs && cs <= CS4;
+}
+
+bool mcs_is_edge(enum CodingScheme cs)
+{
+	return MCS1 <= cs && cs <= MCS9;
+}
+
+bool mcs_is_edge_gmsk(enum CodingScheme cs)
+{
+	if (mcs_is_edge(cs))
+		return cs <= MCS4;
+
+	return false;
+}
+
 static struct {
 	struct {
 		uint8_t data_header_bits;
diff --git a/src/coding_scheme.h b/src/coding_scheme.h
index 2f56aec..561e2a4 100644
--- a/src/coding_scheme.h
+++ b/src/coding_scheme.h
@@ -33,6 +33,10 @@
 extern const struct value_string mcs_names[];
 const char *mcs_name(enum CodingScheme val);
 
+bool mcs_is_gprs(enum CodingScheme cs);
+bool mcs_is_edge(enum CodingScheme cs);
+bool mcs_is_edge_gmsk(enum CodingScheme cs);
+
 enum HeaderType {
 	HEADER_INVALID,
 	HEADER_GPRS_CONTROL,
diff --git a/src/decoding.cpp b/src/decoding.cpp
index 1473ff7..d439e30 100644
--- a/src/decoding.cpp
+++ b/src/decoding.cpp
@@ -215,7 +215,7 @@
 				"but no more chunks possible\n");
 			return -ENOSPC;
 		}
-	} else if (cs.isEgprs()) {
+	} else if (mcs_is_edge(cs)) {
 		/* if E is not set (LI follows), EGPRS */
 		num_chunks = parse_extensions_egprs(data, data_len, &offs,
 			is_last_block,
@@ -240,7 +240,7 @@
 		}
 
 		memcpy(&tlli_enc, data + offs, sizeof(tlli_enc));
-		if (cs.isGprs())
+		if (mcs_is_gprs(cs))
 			/* The TLLI is encoded in big endian for GPRS (see
 			 * TS 44.060, figure 10.2.2.1, note) */
 			*tlli = be32toh(tlli_enc);
diff --git a/src/encoding.cpp b/src/encoding.cpp
index ad53b0b..c2502b6 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -1605,12 +1605,12 @@
 	gprs_llc *llc, int *offset, int *num_chunks,
 	uint8_t *data_block, bool is_final, int *count_payload)
 {
-	if (cs.isGprs())
+	if (mcs_is_gprs(cs))
 		return rlc_data_to_dl_append_gprs(rdbi,
 			llc, offset, num_chunks, data_block, is_final,
 			count_payload);
 
-	if (cs.isEgprs())
+	if (mcs_is_edge(cs))
 		return rlc_data_to_dl_append_egprs(rdbi,
 			llc, offset, num_chunks, data_block, is_final,
 			count_payload);
diff --git a/src/gprs_coding_scheme.cpp b/src/gprs_coding_scheme.cpp
index e94b4d8..e316097 100644
--- a/src/gprs_coding_scheme.cpp
+++ b/src/gprs_coding_scheme.cpp
@@ -228,10 +228,10 @@
 
 void GprsCodingScheme::inc()
 {
-	if (isGprs() && m_scheme == CS4)
+	if (mcs_is_gprs(m_scheme) && m_scheme == CS4)
 		return;
 
-	if (isEgprs() && m_scheme == MCS9)
+	if (mcs_is_edge(m_scheme) && m_scheme == MCS9)
 		return;
 
 	if (!isValid())
@@ -242,10 +242,10 @@
 
 void GprsCodingScheme::dec()
 {
-	if (isGprs() && m_scheme == CS1)
+	if (mcs_is_gprs(m_scheme) && m_scheme == CS1)
 		return;
 
-	if (isEgprs() && m_scheme == MCS1)
+	if (mcs_is_edge(m_scheme) && m_scheme == MCS1)
 		return;
 
 	if (!isValid())
diff --git a/src/gprs_coding_scheme.h b/src/gprs_coding_scheme.h
index b65bf01..d6c0045 100644
--- a/src/gprs_coding_scheme.h
+++ b/src/gprs_coding_scheme.h
@@ -45,9 +45,7 @@
 	GprsCodingScheme& operator =(GprsCodingScheme o);
 
 	bool isValid()   const {return UNKNOWN <= m_scheme && m_scheme <= MCS9;}
-	bool isGprs()   const {return CS1 <= m_scheme && m_scheme <= CS4;}
-	bool isEgprs()  const {return m_scheme >= MCS1;}
-	bool isEgprsGmsk()  const {return isEgprs() && m_scheme <= MCS4;}
+
 	bool isCompatible(enum Mode mode) const;
 	bool isCompatible(GprsCodingScheme o) const;
 	bool isFamilyCompatible(GprsCodingScheme o) const;
@@ -86,10 +84,10 @@
 
 inline uint8_t GprsCodingScheme::to_num() const
 {
-	if (isGprs())
+	if (mcs_is_gprs(m_scheme))
 		return (m_scheme - CS1) + 1;
 
-	if (isEgprs())
+	if (mcs_is_edge(m_scheme))
 		return (m_scheme - MCS1) + 1;
 
 	return 0;
@@ -98,9 +96,9 @@
 inline bool GprsCodingScheme::isCompatible(enum Mode mode) const
 {
 	switch (mode) {
-	case GPRS: return isGprs();
-	case EGPRS_GMSK: return isEgprsGmsk();
-	case EGPRS: return isEgprs();
+	case GPRS: return mcs_is_gprs(m_scheme);
+	case EGPRS_GMSK: return mcs_is_edge_gmsk(m_scheme);
+	case EGPRS: return mcs_is_edge(m_scheme);
 	}
 
 	return false;
@@ -108,7 +106,7 @@
 
 inline bool GprsCodingScheme::isCompatible(GprsCodingScheme o) const
 {
-	return (isGprs() && o.isGprs()) || (isEgprs() && o.isEgprs());
+	return (mcs_is_gprs(m_scheme) && mcs_is_gprs(o)) || (mcs_is_edge(m_scheme) && mcs_is_edge(o));
 }
 
 inline GprsCodingScheme::GprsCodingScheme(CodingScheme s)
diff --git a/src/gprs_ms.cpp b/src/gprs_ms.cpp
index 0383680..08b94be 100644
--- a/src/gprs_ms.cpp
+++ b/src/gprs_ms.cpp
@@ -222,13 +222,13 @@
 
 	switch (m_mode) {
 	case GPRS:
-		if (!m_current_cs_ul.isGprs()) {
+		if (!mcs_is_gprs(m_current_cs_ul)) {
 			m_current_cs_ul = GprsCodingScheme::getGprsByNum(
 				m_bts->bts_data()->initial_cs_ul);
 			if (!m_current_cs_ul.isValid())
 				m_current_cs_ul = CS1;
 		}
-		if (!m_current_cs_dl.isGprs()) {
+		if (!mcs_is_gprs(m_current_cs_dl)) {
 			m_current_cs_dl = GprsCodingScheme::getGprsByNum(
 				m_bts->bts_data()->initial_cs_dl);
 			if (!m_current_cs_dl.isValid())
@@ -238,13 +238,13 @@
 
 	case EGPRS_GMSK:
 	case EGPRS:
-		if (!m_current_cs_ul.isEgprs()) {
+		if (!mcs_is_edge(m_current_cs_ul)) {
 			m_current_cs_ul = GprsCodingScheme::getEgprsByNum(
 				m_bts->bts_data()->initial_mcs_ul);
 			if (!m_current_cs_ul.isValid())
 				m_current_cs_ul = MCS1;
 		}
-		if (!m_current_cs_dl.isEgprs()) {
+		if (!mcs_is_edge(m_current_cs_dl)) {
 			m_current_cs_dl = GprsCodingScheme::getEgprsByNum(
 				m_bts->bts_data()->initial_mcs_dl);
 			if (!m_current_cs_dl.isValid())
@@ -564,14 +564,14 @@
 	OSMO_ASSERT(m_bts != NULL);
 	bts_data = m_bts->bts_data();
 
-	if (m_current_cs_ul.isGprs()) {
+	if (mcs_is_gprs(m_current_cs_ul)) {
 		if (!bts_data->max_cs_ul)
 			return GprsCodingScheme(CS4);
 
 		return GprsCodingScheme::getGprsByNum(bts_data->max_cs_ul);
 	}
 
-	if (!m_current_cs_ul.isEgprs())
+	if (!mcs_is_edge(m_current_cs_ul))
 		return GprsCodingScheme(); /* UNKNOWN */
 
 	if (bts_data->max_mcs_ul)
@@ -594,14 +594,14 @@
 	OSMO_ASSERT(m_bts != NULL);
 	bts_data = m_bts->bts_data();
 
-	if (m_current_cs_dl.isGprs()) {
+	if (mcs_is_gprs(m_current_cs_dl)) {
 		if (!bts_data->max_cs_dl)
 			return GprsCodingScheme(CS4);
 
 		return GprsCodingScheme::getGprsByNum(bts_data->max_cs_dl);
 	}
 
-	if (!m_current_cs_dl.isEgprs())
+	if (!mcs_is_edge(m_current_cs_dl))
 		return GprsCodingScheme(); /* UNKNOWN */
 
 	if (bts_data->max_mcs_dl)
@@ -650,12 +650,12 @@
 
 	old_link_qual = meas->link_qual;
 
-	if (m_current_cs_ul.isGprs()) {
+	if (mcs_is_gprs(m_current_cs_ul)) {
 		if (current_cs_num > MAX_GPRS_CS)
 			current_cs_num = MAX_GPRS_CS;
 		low  = bts_data->cs_lqual_ranges[current_cs_num-1].low;
 		high = bts_data->cs_lqual_ranges[current_cs_num-1].high;
-	} else if (m_current_cs_ul.isEgprs()) {
+	} else if (mcs_is_edge(m_current_cs_ul)) {
 		if (current_cs_num > MAX_EDGE_MCS)
 			current_cs_num = MAX_EDGE_MCS;
 		low  = bts_data->mcs_lqual_ranges[current_cs_num-1].low;
diff --git a/src/pdch.cpp b/src/pdch.cpp
index c6c677c..8003105 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -741,10 +741,10 @@
 	LOGP(DRLCMACUL, LOGL_DEBUG, "Got RLC block, coding scheme: %s, "
 		"length: %d (%d))\n", mcs_name(cs), len, cs.usedSizeUL());
 
-	if (cs.isGprs())
+	if (mcs_is_gprs(cs))
 		return rcv_block_gprs(data, len, fn, meas, cs);
 
-	if (cs.isEgprs())
+	if (mcs_is_edge(cs))
 		return rcv_data_block(data, len, fn, meas, cs);
 
 	bts()->decode_error();
@@ -765,7 +765,7 @@
 	/* These are always data blocks, since EGPRS still uses CS-1 for
 	 * control blocks (see 44.060, section 10.3, 1st par.)
 	 */
-	if (cs.isEgprs()) {
+	if (mcs_is_edge(cs)) {
 		if (!bts()->bts_data()->egprs_enabled) {
 			LOGP(DRLCMACUL, LOGL_ERROR,
 				"Got %s RLC block but EGPRS is not enabled\n",
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 3d9b5c4..dc90dbb 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -952,8 +952,8 @@
 
 static void setup_egprs_mode(gprs_rlcmac_bts *bts, GprsMs *ms)
 {
-	if (GprsCodingScheme::getEgprsByNum(bts->max_mcs_ul).isEgprsGmsk() &&
-		GprsCodingScheme::getEgprsByNum(bts->max_mcs_dl).isEgprsGmsk() &&
+	if (mcs_is_edge_gmsk(GprsCodingScheme::getEgprsByNum(bts->max_mcs_ul)) &&
+		mcs_is_edge_gmsk(GprsCodingScheme::getEgprsByNum(bts->max_mcs_dl)) &&
 		ms->mode() != EGPRS)
 	{
 		ms->set_mode(EGPRS_GMSK);
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index b621be0..00a4dec 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -363,7 +363,7 @@
 
 	if (previous_bsn >= 0) {
 		force_cs = m_rlc.block(previous_bsn)->cs_current_trans;
-		if (!force_cs.isEgprs())
+		if (!mcs_is_edge(force_cs))
 			return -1;
 		force_data_len = m_rlc.block(previous_bsn)->len;
 	}
@@ -765,7 +765,7 @@
 			m_rlc.block(bsn)->next_ps,
 			m_rlc.block(bsn)->cs_last, cs, spb);
 
-		if (cs.isEgprs()) {
+		if (mcs_is_edge(cs)) {
 			OSMO_ASSERT(m_rlc.block(bsn)->next_ps >= EGPRS_PS_1);
 			OSMO_ASSERT(m_rlc.block(bsn)->next_ps <= EGPRS_PS_3);
 		}
@@ -812,7 +812,7 @@
 	}
 
 	/* Calculate CPS only for EGPRS case */
-	if (cs.isEgprs())
+	if (mcs_is_edge(cs))
 		rlc.cps = gprs_rlc_mcs_cps(cs, punct[0], punct[1], need_padding);
 
 	/* If the TBF has just started, relate frames_since_last_poll to the
@@ -1369,7 +1369,7 @@
 	uint8_t coding_scheme = 0;
 
 	coding_scheme = CodingScheme(cs);
-	if (cs.isGprs()) {
+	if (mcs_is_gprs(cs)) {
 		switch (coding_scheme) {
 		case CS1 :
 			bts->gprs_dl_cs1();
diff --git a/src/tbf_ul.cpp b/src/tbf_ul.cpp
index 0bf5765..f40ec3d 100644
--- a/src/tbf_ul.cpp
+++ b/src/tbf_ul.cpp
@@ -530,7 +530,7 @@
 	uint8_t coding_scheme = 0;
 
 	coding_scheme = CodingScheme(cs);
-	if (cs.isGprs()) {
+	if (mcs_is_gprs(cs)) {
 		switch (coding_scheme) {
 		case CS1 :
 			bts->gprs_ul_cs1();
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index 7b301c9..723fe1e 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -59,14 +59,14 @@
 
 	/* Check static getBySizeUL() */
 	expected_size = cs.usedSizeUL();
-	if (cs.spareBitsUL() > 0 && cs.isGprs())
+	if (cs.spareBitsUL() > 0 && mcs_is_gprs(cs))
 		expected_size += 1;
 	OSMO_ASSERT(expected_size == cs.sizeUL());
 	OSMO_ASSERT(cs == GprsCodingScheme::getBySizeUL(expected_size));
 
 	/* Check static sizeUL() */
 	expected_size = cs.usedSizeDL();
-	if (cs.spareBitsDL() > 0 && cs.isGprs())
+	if (cs.spareBitsDL() > 0 && mcs_is_gprs(cs))
 		expected_size += 1;
 	OSMO_ASSERT(expected_size == cs.sizeDL());
 
@@ -157,9 +157,9 @@
 
 	for (i = 0; i < ARRAY_SIZE(gprs_schemes); i++) {
 		GprsCodingScheme current_cs(gprs_schemes[i]);
-		OSMO_ASSERT(current_cs.isGprs());
-		OSMO_ASSERT(!current_cs.isEgprs());
-		OSMO_ASSERT(!current_cs.isEgprsGmsk());
+		OSMO_ASSERT(mcs_is_gprs(current_cs));
+		OSMO_ASSERT(!mcs_is_edge(current_cs));
+		OSMO_ASSERT(!mcs_is_edge_gmsk(current_cs));
 		OSMO_ASSERT(CodingScheme(current_cs) == gprs_schemes[i]);
 		OSMO_ASSERT(current_cs == GprsCodingScheme(gprs_schemes[i]));
 
@@ -179,9 +179,9 @@
 
 	for (i = 0; i < ARRAY_SIZE(egprs_schemes); i++) {
 		GprsCodingScheme current_cs(egprs_schemes[i].s);
-		OSMO_ASSERT(!current_cs.isGprs());
-		OSMO_ASSERT(current_cs.isEgprs());
-		OSMO_ASSERT(!!current_cs.isEgprsGmsk() == !!egprs_schemes[i].is_gmsk);
+		OSMO_ASSERT(!mcs_is_gprs(current_cs));
+		OSMO_ASSERT(mcs_is_edge(current_cs));
+		OSMO_ASSERT(mcs_is_edge_gmsk(current_cs) == !!egprs_schemes[i].is_gmsk);
 		OSMO_ASSERT(CodingScheme(current_cs) == egprs_schemes[i].s);
 		OSMO_ASSERT(current_cs == GprsCodingScheme(egprs_schemes[i].s));
 

-- 
To view, visit https://gerrit.osmocom.org/13214
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6699cbc8d7ae766fa4d2b3d37e5f9ff1cf158b7e
Gerrit-Change-Number: 13214
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190312/77fccb78/attachment.html>


More information about the gerrit-log mailing list