[PATCH 2/3] Build a tree of code words

sangamesh sajjan sangamesh.sajjan at radisys.com
Wed Mar 30 13:50:44 UTC 2016


This patch includes the changes to build the tree of code words
to save run length during BTS initialization
---
 src/egprs_rlc_compression.cpp |   51 +++++++++++++++++++++++++++++++++++++++++
 src/egprs_rlc_compression.h   |   37 +++++++++++++++++++++++++++++-
 src/pcu_main.cpp              |    3 +++
 3 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/src/egprs_rlc_compression.cpp b/src/egprs_rlc_compression.cpp
index 55ff595..4c17a17 100644
--- a/src/egprs_rlc_compression.cpp
+++ b/src/egprs_rlc_compression.cpp
@@ -3,6 +3,57 @@
 */
 #include <egprs_rlc_compression.h>
 #include <errno.h>
+#include <decoding.h>
+
+egprs_compress *egprs_compress::s_instance = 0;
+Node *egprs_compress::ones_list = NULL;
+Node *egprs_compress::zeros_list = NULL;
+
+void egprs_compress::build_codeword(Node *root, const char *cdwd[])
+{
+	Node *iter; /* iterate the node on the tree */
+	int  len;    /* length of the code word */
+	int  i;      /* iterater */
+	uint16_t  idx;    /* interate index of the code word table */
+
+	root->left = NULL;
+	root->right = NULL;
+	root->run_length = NULL;
+
+	for (idx = 0; idx < MAX_CDWDTBL_LEN; idx++) {
+		len = strlen((const char *)cdwd[idx]);
+		iter = root;
+		for (i = 0;  i < len;  i++) {
+			if (cdwd[idx][i] == '0') {
+				if (iter->left == NULL) {
+				 iter->left = (Node *)malloc(sizeof(Node));
+				 /* create a clean node */
+				 iter->left->left = NULL;
+				 iter->left->right = NULL;
+				 iter->left->run_length = NULL;
+				}
+				iter = iter->left;
+			} else if (cdwd[idx][i] == '1') {
+				if (iter->right == NULL) {
+				iter->right = (Node *)malloc(sizeof(Node));
+				/* create a clean node */
+				iter->right->left = NULL;
+				iter->right->right = NULL;
+				iter->right->run_length = NULL;
+				}
+				iter = iter->right;
+			}
+		}
+		if (iter != NULL) {
+			iter->run_length = (uint16_t *)malloc(sizeof(uint16_t));
+			*(iter->run_length) = (uint16_t)NULL;
+			if (idx < 64)
+				*(iter->run_length) = idx;
+			else
+				*(iter->run_length) = (idx - 63) * 64;
+		}
+	}
+}
 
 const char *one_run_len_code_list[MAX_CDWDTBL_LEN] = {
 	"00110101",
diff --git a/src/egprs_rlc_compression.h b/src/egprs_rlc_compression.h
index 00d850e..db1f880 100644
--- a/src/egprs_rlc_compression.h
+++ b/src/egprs_rlc_compression.h
@@ -15,7 +15,7 @@ extern "C" {
 #include <string.h>
 
 #define	MAX_CDWDTBL_LEN          79        /* total number of codewords */
-#define	BITS_TO_BYTES(X)      (X ? (X/8):0)+1
+#define	BITS_TO_BYTES(X)      ((X ? (X/8):0)+1)
 #define	MOD8(X)             (((X)+8) & (0x07))
 
 typedef struct node {
@@ -23,3 +23,38 @@ typedef struct node {
 	struct node *right;
 	uint16_t *run_length;
 } Node;
+
+extern const char *one_run_len_code_list[MAX_CDWDTBL_LEN];
+extern const char *zero_run_len_code_list[MAX_CDWDTBL_LEN];
+
+/* Creating singleton class
+ */
+class egprs_compress
+{
+	static egprs_compress *s_instance;
+
+	egprs_compress()
+	{
+		egprs_compress::ones_list = (Node *)malloc(sizeof(Node));
+		egprs_compress::zeros_list = (Node *)malloc(sizeof(Node));
+	}
+	void build_codeword(Node *root, const char *cdwd[]);
+public:
+	static Node *ones_list;
+	static Node *zeros_list;
+
+	void decode_tree_init(void)
+	{
+		egprs_compress::instance()->build_codeword(
+			egprs_compress::ones_list, one_run_len_code_list);
+		egprs_compress::instance()->build_codeword(
+			egprs_compress::zeros_list, zero_run_len_code_list);
+	}
+	static egprs_compress *instance()
+	{
+		if (!s_instance)
+			s_instance = new egprs_compress;
+
+		return s_instance;
+	}
+};
diff --git a/src/pcu_main.cpp b/src/pcu_main.cpp
index f66c631..642ab33 100644
--- a/src/pcu_main.cpp
+++ b/src/pcu_main.cpp
@@ -28,6 +28,7 @@
 #include <signal.h>
 #include <sched.h>
 #include <bts.h>
+#include <egprs_rlc_compression.h>
 extern "C" {
 #include "pcu_vty.h"
 #include <osmocom/vty/telnet_interface.h>
@@ -253,6 +254,8 @@ int main(int argc, char *argv[])
 	if (!bts->alloc_algorithm)
 		bts->alloc_algorithm = alloc_algorithm_dynamic;
 
+	egprs_compress::instance()->decode_tree_init();
+
 	rc = pcu_l1if_open();
 
 	if (rc < 0)
-- 
1.7.9.5




More information about the osmocom-net-gprs mailing list