aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2016-02-01 13:26:22 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2016-02-08 00:45:38 +0100
commit4e7424d47bf15b3d7a902fbd020838540117292a (patch)
tree2fc8616a6a67cf2fcc5cf772115aee6b29c3fa13 /src
parent9876a3ba5dd1f51bb56d340d709b0d2db7891a26 (diff)
pcu: Add bitvec_write_field_lh
While the bitvec functions from libosmocore support LH encoding, the C++ wrapper does not. Add a bitvec_write_field_lh function that is similar to bitvec_write_field, but writes L and H instead of ZERO and ONE. Sponsored-by: On-Waves ehf
Diffstat (limited to 'src')
-rw-r--r--src/bitvector.cpp18
-rw-r--r--src/bitvector.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/src/bitvector.cpp b/src/bitvector.cpp
index 43feebc..1028407 100644
--- a/src/bitvector.cpp
+++ b/src/bitvector.cpp
@@ -117,3 +117,21 @@ int bitvec_write_field(struct bitvec *bv, unsigned& write_index, uint64_t val, u
write_index += len;
return 0;
}
+
+int bitvec_write_field_lh(struct bitvec *bv, unsigned& write_index,
+ uint64_t val, unsigned len)
+{
+ unsigned int i;
+ int rc;
+ bv->cur_bit = write_index;
+ for (i = 0; i < len; i++) {
+ bit_value bit = L;
+ if (val & ((uint64_t)1 << (len - i - 1)))
+ bit = H;
+ rc = bitvec_set_bit(bv, bit);
+ if (rc)
+ return rc;
+ }
+ write_index += len;
+ return 0;
+}
diff --git a/src/bitvector.h b/src/bitvector.h
index 36bdbab..b14d204 100644
--- a/src/bitvector.h
+++ b/src/bitvector.h
@@ -39,6 +39,7 @@ unsigned int bitvec_pack(struct bitvec *bv, uint8_t *buffer);
unsigned int bitvec_unpack(struct bitvec *bv, uint8_t *buffer);
uint64_t bitvec_read_field(struct bitvec *bv, unsigned& read_index, unsigned len);
int bitvec_write_field(struct bitvec *bv, unsigned& write_index, uint64_t val, unsigned len);
+int bitvec_write_field_lh(struct bitvec *bv, unsigned& write_index, uint64_t val, unsigned len);
/*! }@ */