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
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 @@
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;
+}