Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Revision:
29:e05e35976cfe
Parent:
28:b14b2926e916
Child:
30:2e673a672884
--- a/xDotBridge/src/main.cpp	Wed Jan 04 17:23:12 2017 -0700
+++ b/xDotBridge/src/main.cpp	Mon Jan 09 14:45:42 2017 -0700
@@ -29,7 +29,29 @@
 const float rxSleepTime = 2000; // ms (one second resolution, min 2 seconds)
 const uint8_t maxPayloadSize = 10; // Number of bytes (used for toa calcultion)
 
-DigitalOut led1(LED1);
+DigitalOut led1(GPIO0);
+
+AnalogIn an1(GPIO1);
+AnalogIn an2(GPIO2);
+
+// Inputs
+DigitalIn gpio3(GPIO3);
+DigitalIn wake_DOUT(WAKE);
+DigitalIn i2cOut1(I2C1_SCL);
+DigitalIn i2cOut2(I2C1_SDA);
+
+DigitalIn uartOut1(UART1_CTS);
+DigitalIn uartOut2(UART1_RTS);
+
+// Outputs
+//DigitalOut gpio3(GPIO3);
+////DigitalOut wake_DOUT(WAKE);
+//DigitalOut i2cOut1(I2C1_SCL);
+//DigitalOut i2cOut2(I2C1_SDA);
+//
+//DigitalOut uartOut1(UART1_CTS);
+//DigitalOut uartOut2(UART1_RTS);
+
 mDot* dot = NULL;
 
 Serial pc(USBTX, USBRX);
@@ -134,6 +156,16 @@
 	///////////////////////////////
 	#if BRIDGE_TX_BRUTE
     wakeMode = mDot::INTERRUPT;
+    dot->setTxWait(false);
+    dot->setAck(0);  // Disable Ack
+	#endif
+
+	#if BRIDGE_TX_ACK
+    wakeMode = mDot::INTERRUPT;
+    dot->setTxWait(true);
+    dot->setAck(1);  // Enable Ack
+    dot->setRepeat(1);  // No auto repeats
+    dot->setRxDelay(1);
 	#endif
 
 	////////////////////////////
@@ -141,12 +173,13 @@
 	////////////////////////////
 	#if BRIDGE_RX_BRUTE
     wakeMode = mDot::RTC_ALARM_OR_INTERRUPT;
+    dot->setTxWait(false);
+    dot->setAck(0);  // Disable Ack
 	#endif
 
     // Common Configuration
     dot->setWakePin(WAKE); // Use the wake pin as sleep interrupt
     dot->setClass("C"); // Set class C
-    dot->setAck(0);  // Disable Ack
     dot->setTxPower(20); // 20 dBm
 
     // save changes to configuration
@@ -167,7 +200,7 @@
     uint32_t cDwnLink = dot->getDownLinkCounter();
     while (true) {
         std::vector<uint8_t> data;
-        led1=0;
+//        led1=0; FIXME
 
         // join network if not joined
         if (!dot->getNetworkJoinStatus()) {
@@ -195,6 +228,32 @@
         sleep_restore_io();
 		#endif
 
+		#if BRIDGE_TX_ACK
+        led1=1;
+        data.push_back((seqNum >> 8) & 0xFF);
+        data.push_back(seqNum & 0xFF);
+        logInfo("Starting TX.  Time: %lu, seqNum: %lu", us_ticker_read(), seqNum);
+        uint32_t pktRtn = -1024;
+        for(uint i=0;i<nTimesToTx;++i) {
+        	pktRtn = dot->send(data);
+        	if (pktRtn == mDot::MDOT_OK) {
+				logInfo("Successful TX.  Time: %lu Try: %d", us_ticker_read(), i);
+        		break;
+			}
+        	else {
+				logInfo(" Bad TX.  Time: %lu Try: %d", us_ticker_read(), i);
+        	}
+        }
+        seqNum++;
+        led1=0;
+		logInfo("Finished TX.  Time: %lu", us_ticker_read());
+
+		sleep_save_io();
+		sleep_configure_io();
+        dot->sleep(0, wakeMode, false);  // Go to sleep until wake button
+        sleep_restore_io();
+		#endif
+
     	///////////////////////////////////////
     	// Brute Protocol Receiver main loop //
     	///////////////////////////////////////
@@ -226,6 +285,35 @@
 //        	dot->sleep(0, wakeMode, false);  // Go to sleep until wake button
 //        	//sleep();
 //        }
+        //////////////
+        // I/O Play //
+        //////////////
+
+        // Check Analog
+        logInfo("Read AN1/GPIO1: %f", an1.read());
+        logInfo("Read AN2/GPIO2: %f", an2.read()); // Ranges from 0.0 to 1.0
+
+        // check inputs
+        logInfo("Read GPIO3: %d", gpio3.read());
+        logInfo("Read wake_DOUT: %d", wake_DOUT.read());
+        logInfo("Read i2cOut1: %d", i2cOut1.read()); // Appears to be pulled up
+        logInfo("Read i2cOut2: %d", i2cOut2.read()); // Appears to be pulled up
+        logInfo("Read uartOut1: %d", uartOut1.read());
+        logInfo("Read uartOut2: %d", uartOut2.read());
+
+        // check digital outputs
+//		led1 = !led1;
+//		gpio3 = !gpio3;
+////		wake_DOUT = !wake_DOUT;
+//		i2cOut1 = !i2cOut1;
+//		i2cOut2 = !i2cOut2;
+//
+//		uartOut1 = !uartOut1;
+//		uartOut2 = !uartOut2;
+
+        logInfo("================================");
+
+		wait(1.0);
     }
  
     return 0;