Change in ...osmo-trx[master]: Introduce structs to encode TRXD packets

pespin gerrit-no-reply at lists.osmocom.org
Tue Jul 2 13:09:56 UTC 2019


pespin has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/osmo-trx/+/14629 )

Change subject: Introduce structs to encode TRXD packets
......................................................................

Introduce structs to encode TRXD packets

This will ease adding new protocol versions in the future.

Related: OS#4006
Change-Id: I67ffede171eddde436f9057191ed76015a8ea6eb
---
M Transceiver52M/Makefile.am
M Transceiver52M/Transceiver.cpp
A Transceiver52M/proto_trxd.h
3 files changed, 46 insertions(+), 11 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  fixeria: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved



diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am
index 89ab796..4adf474 100644
--- a/Transceiver52M/Makefile.am
+++ b/Transceiver52M/Makefile.am
@@ -25,6 +25,7 @@
 
 AM_CPPFLAGS = -Wall $(STD_DEFINES_AND_INCLUDES) -I${srcdir}/arch/common -I${srcdir}/device/common
 AM_CXXFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS)
+AM_CFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS)
 
 rev2dir = $(datadir)/usrp/rev2
 rev4dir = $(datadir)/usrp/rev4
@@ -66,7 +67,8 @@
 	Resampler.h \
 	ChannelizerBase.h \
 	Channelizer.h \
-	Synthesis.h
+	Synthesis.h \
+	proto_trxd.h
 
 COMMON_LDADD = \
 	libtransceiver_common.la \
diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index 0aa4ff5..5441745 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -29,6 +29,9 @@
 
 extern "C" {
 #include "osmo_signal.h"
+#include "proto_trxd.h"
+
+#include <osmocom/core/bits.h>
 }
 
 #ifdef HAVE_CONFIG_H
@@ -950,22 +953,24 @@
 
   TOAint = (int) (TOA * 256.0 + 0.5); // round to closest integer
 
-  char burstString[nbits + 10];
-  burstString[0] = burstTime.TN();
-  for (int i = 0; i < 4; i++)
-    burstString[1+i] = (burstTime.FN() >> ((3-i)*8)) & 0x0ff;
-  burstString[5] = (int)dBm;
-  burstString[6] = (TOAint >> 8) & 0x0ff;
-  burstString[7] = TOAint & 0x0ff;
+  char burstString[sizeof(struct trxd_hdr_v0) + nbits + 2];
+  struct trxd_hdr_v0* pkt = (struct trxd_hdr_v0*)burstString;
+  pkt->common.version = 0;
+  pkt->common.reserved = 0;
+  pkt->common.tn = burstTime.TN();
+  osmo_store32be(burstTime.FN(), &pkt->common.fn);
+  pkt->v0.rssi = dBm;
+  osmo_store16be(TOAint, &pkt->v0.toa);
   SoftVector::iterator burstItr = rxBurst->begin();
 
   for (unsigned i = 0; i < nbits; i++)
-    burstString[8 + i] = (char) round((*burstItr++) * 255.0);
+    pkt->soft_bits[i] = (char) round((*burstItr++) * 255.0);
 
-  burstString[nbits + 9] = '\0';
+  /* +1: Historical reason. There's an uninitizalied byte in there: pkt->soft_bits[bi.nbits] */
+  pkt->soft_bits[nbits + 1] = '\0';
   delete rxBurst;
 
-  mDataSockets[chan]->write(burstString, nbits + 10);
+  mDataSockets[chan]->write(burstString, sizeof(struct trxd_hdr_v0) + nbits + 2);
 }
 
 void Transceiver::driveTxFIFO()
diff --git a/Transceiver52M/proto_trxd.h b/Transceiver52M/proto_trxd.h
new file mode 100644
index 0000000..9da18db
--- /dev/null
+++ b/Transceiver52M/proto_trxd.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <stdint.h>
+#include <osmocom/core/endian.h>
+
+struct trxd_hdr_common {
+#if OSMO_IS_LITTLE_ENDIAN
+        uint8_t tn:3,
+                reserved:1,
+                version:4;
+#elif OSMO_IS_BIG_ENDIAN
+        uint8_t version:4,
+                reserved:1,
+                tn:3;
+#endif
+        uint32_t fn; /* big endian */
+} __attribute__ ((packed));
+
+struct trxd_hdr_v0_specific {
+        uint8_t rssi;
+        uint16_t toa; /* big endian */
+} __attribute__ ((packed));
+
+struct trxd_hdr_v0 {
+        struct trxd_hdr_common common;
+        struct trxd_hdr_v0_specific v0;
+        uint8_t soft_bits[0];
+} __attribute__ ((packed));

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/14629
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I67ffede171eddde436f9057191ed76015a8ea6eb
Gerrit-Change-Number: 14629
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190702/66fdde8e/attachment.html>


More information about the gerrit-log mailing list