Transceiver52M: Disable filler table retransmissions by default

Burst selection at a particular time works in the following order
of priority.

1. Slot is disabled with channel combination set to NONE (default)
1. Burst exists in priority queue for the current time.
2. Filler table entry is used

This patch sets default behaviour to force all filler table entries
to zero and disallows filler table changes. This effectively means
that only bursts received from upper layers will be transmitted and
nothing will be automatically transmitted in the absence or delay
of incoming burts at a particular time.

New Command line option "Enable C0 filler table" allows reverting
to previous idle burst generation and retransmission behaviour on
TRX0. Retransmission cannot be enabled on non-C0 channels.

Signed-off-by: Thomas Tsou <tom@tsou.cc>
diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index e5ab476..724fe8d 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -43,7 +43,7 @@
 #define NOISE_CNT			20
 
 TransceiverState::TransceiverState()
-  : mNoiseLev(0.0), mNoises(NOISE_CNT)
+  : mRetrans(false), mNoiseLev(0.0), mNoises(NOISE_CNT)
 {
   for (int i = 0; i < 8; i++) {
     chanType[i] = Transceiver::NONE;
@@ -69,10 +69,18 @@
   }
 }
 
-void TransceiverState::init(size_t slot, signalVector *burst)
+void TransceiverState::init(size_t slot, signalVector *burst, bool fill)
 {
-  for (int i = 0; i < 102; i++)
-    fillerTable[i][slot] = new signalVector(*burst);
+  signalVector *filler;
+
+  for (int i = 0; i < 102; i++) {
+    if (fill)
+      filler = new signalVector(*burst);
+    else
+      filler = new signalVector(burst->size());
+
+    fillerTable[i][slot] = filler;
+  }
 }
 
 Transceiver::Transceiver(int wBasePort,
@@ -112,7 +120,7 @@
   }
 }
 
-bool Transceiver::init()
+bool Transceiver::init(bool filler)
 {
   int d_srcport, d_dstport, c_srcport, c_dstport;
   signalVector *burst;
@@ -158,7 +166,7 @@
     for (size_t n = 0; n < 8; n++) {
       burst = modulateBurst(gDummyBurst, 8 + (n % 4 == 0), mSPSTx);
       scaleVector(*burst, txFullScale);
-      mStates[i].init(n, burst);
+      mStates[i].init(n, burst, filler && !i);
       delete burst;
     }
   }
@@ -190,6 +198,19 @@
   mTxPriorityQueues[chan].write(radio_burst);
 }
 
+void Transceiver::updateFillerTable(size_t chan, radioVector *burst)
+{
+  int TN, modFN;
+  TransceiverState *state = &mStates[chan];
+
+  TN = burst->getTime().TN();
+  modFN = burst->getTime().FN() % state->fillerModulus[TN];
+
+  delete state->fillerTable[modFN][TN];
+  state->fillerTable[modFN][TN] = burst->getVector();
+  burst->setVector(NULL);
+}
+
 void Transceiver::pushRadioVector(GSM::Time &nowTime)
 {
   int TN, modFN;
@@ -197,19 +218,15 @@
   TransceiverState *state;
   std::vector<signalVector *> bursts(mChans);
   std::vector<bool> zeros(mChans);
+  std::vector<bool> filler(mChans, true);
 
   for (size_t i = 0; i < mChans; i ++) {
     state = &mStates[i];
 
     while ((burst = mTxPriorityQueues[i].getStaleBurst(nowTime))) {
       LOG(NOTICE) << "dumping STALE burst in TRX->USRP interface";
-
-      TN = burst->getTime().TN();
-      modFN = burst->getTime().FN() % state->fillerModulus[TN];
-
-      delete state->fillerTable[modFN][TN];
-      state->fillerTable[modFN][TN] = burst->getVector();
-      burst->setVector(NULL);
+      if (state->mRetrans)
+        updateFillerTable(i, burst);
       delete burst;
     }
 
@@ -220,17 +237,25 @@
     zeros[i] = state->chanType[TN] == NONE;
 
     if ((burst = mTxPriorityQueues[i].getCurrentBurst(nowTime))) {
-      delete state->fillerTable[modFN][TN];
-      state->fillerTable[modFN][TN] = burst->getVector();
       bursts[i] = burst->getVector();
-      burst->setVector(NULL);
+
+      if (state->mRetrans) {
+        updateFillerTable(i, burst);
+      } else {
+        burst->setVector(NULL);
+        filler[i] = false;
+      }
+
       delete burst;
     }
   }
 
   mRadioInterface->driveTransmitRadio(bursts, zeros);
 
-  return;
+  for (size_t i = 0; i < mChans; i++) {
+    if (!filler[i])
+      delete bursts[i];
+  }
 }
 
 void Transceiver::setModulus(size_t timeslot, size_t chan)
diff --git a/Transceiver52M/Transceiver.h b/Transceiver52M/Transceiver.h
index e6b9e12..df029a6 100644
--- a/Transceiver52M/Transceiver.h
+++ b/Transceiver52M/Transceiver.h
@@ -54,7 +54,7 @@
   ~TransceiverState();
 
   /* Initialize a multiframe slot in the filler table */
-  void init(size_t slot, signalVector *burst);
+  void init(size_t slot, signalVector *burst, bool fill);
 
   int chanType[8];
 
@@ -64,6 +64,7 @@
   /* The filler table */
   signalVector *fillerTable[102][8];
   int fillerModulus[8];
+  bool mRetrans;
 
   /* Most recent channel estimate of all timeslots */
   signalVector *chanResponse[8];
@@ -122,6 +123,9 @@
   void addRadioVector(size_t chan, BitVector &bits,
                       int RSSI, GSM::Time &wTime);
 
+  /** Update filler table */
+  void updateFillerTable(size_t chan, radioVector *burst);
+
   /** Push modulated burst into transmit FIFO corresponding to a particular timestamp */
   void pushRadioVector(GSM::Time &nowTime);
 
@@ -187,7 +191,7 @@
 
   /** start the Transceiver */
   void start();
-  bool init();
+  bool init(bool filler);
 
   /** attach the radioInterface receive FIFO */
   bool receiveFIFO(VectorFIFO *wFIFO, size_t chan)
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 98112bb..bb2c489 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -66,6 +66,7 @@
 	unsigned sps;
 	unsigned chans;
 	bool extref;
+	bool filler;
 	bool diversity;
 };
 
@@ -116,7 +117,7 @@
  */
 bool trx_setup_config(struct trx_config *config)
 {
-	std::string refstr, divstr;
+	std::string refstr, fillstr, divstr;
 
 	if (!testConfig())
 		return false;
@@ -163,6 +164,7 @@
 		config->chans = 2;
 
 	refstr = config->extref ? "Enabled" : "Disabled";
+	fillstr = config->filler ? "Enabled" : "Disabled";
 	divstr = config->diversity ? "Enabled" : "Disabled";
 
 	std::ostringstream ost("");
@@ -174,6 +176,7 @@
 	ost << "   Channels................ " << config->chans << std::endl;
 	ost << "   Samples-per-Symbol...... " << config->sps << std::endl;
 	ost << "   External Reference...... " << refstr << std::endl;
+	ost << "   C0 Filler Table......... " << fillstr << std::endl;
 	ost << "   Diversity............... " << divstr << std::endl;
 	std::cout << ost << std::endl;
 
@@ -231,7 +234,7 @@
 
 	trx = new Transceiver(config->port, config->addr.c_str(), config->sps,
 			      config->chans, GSM::Time(3,0), radio);
-	if (!trx->init()) {
+	if (!trx->init(config->filler)) {
 		LOG(ALERT) << "Failed to initialize transceiver";
 		delete trx;
 		return NULL;
@@ -279,7 +282,8 @@
 		"  -d    Enable dual channel diversity receiver\n"
 		"  -x    Enable external 10 MHz reference\n"
 		"  -s    Samples-per-symbol (1 or 4)\n"
-		"  -c    Number of ARFCN channels (default=1)\n",
+		"  -c    Number of ARFCN channels (default=1)\n"
+		"  -f    Enable C0 filler table\n",
 		"EMERG, ALERT, CRT, ERR, WARNING, NOTICE, INFO, DEBUG");
 }
 
@@ -291,9 +295,10 @@
 	config->sps = 0;
 	config->chans = 0;
 	config->extref = false;
+	config->filler = false;
 	config->diversity = false;
 
-	while ((option = getopt(argc, argv, "ha:l:i:p:c:dxs:")) != -1) {
+	while ((option = getopt(argc, argv, "ha:l:i:p:c:dxfs:")) != -1) {
 		switch (option) {
 		case 'h':
 			print_help();
@@ -320,6 +325,9 @@
 		case 'x':
 			config->extref = true;
 			break;
+		case 'f':
+			config->filler = true;
+			break;
 		case 's':
 			config->sps = atoi(optarg);
 			if ((config->sps != 1) && (config->sps != 4)) {