test program

Dependencies:   LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P

Fork of DUMP_TRUCK_SPR2017 by Terrabots

Revision:
12:502cf4fc6d98
Parent:
11:87f30625b213
Child:
13:112b6543909a
--- a/DumpTruck.cpp	Tue Mar 14 20:10:27 2017 +0000
+++ b/DumpTruck.cpp	Thu Mar 30 17:27:21 2017 +0000
@@ -9,9 +9,61 @@
         //turnMotor = new Motor(p22, p29);
         //bedMotor = new Motor(p23, p28);
     //bed = new IMU(@@@@@@@);
-    //nrf = new Transceiver(@@@@@@);
     srf = new SRF05(p15, p16); //trigger, echo.
     tooClose = false;
+    
+    nrf = new nRF24L01P(p5, p6, p7, p8, p9, p10); // transceiver
+    //transceiver set up, similar to one on base station code
+    txDataCnt = 0;
+    rxDataCnt = 0;
+}
+
+void DumpTruck::startComms() {
+    nrf->powerUp();
+    printf( "nRF24L01+ Frequency    : %d MHz\r\n",  nrf->getRfFrequency() );
+    printf( "nRF24L01+ Output power : %d dBm\r\n",  nrf->getRfOutputPower() );
+    printf( "nRF24L01+ Data Rate    : %d kbps\r\n", nrf->getAirDataRate() );
+    printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", nrf->getTxAddress() );
+    printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", nrf->getRxAddress() );
+    nrf->setTransferSize( TRANSFER_SIZE );
+    nrf->setReceiveMode();
+    nrf->enable();
+    received = false;
+}
+
+void DumpTruck::getCommand() {
+    received = false;
+    //called at the end of each executable command
+    //print statement saying dump truck is ready to receive
+        //have print statement appear in base station code
+    //dump truck transceiver sends a code to base station, opening the channel
+        //code is all 0's
+            for(int i = 0; i < TRANSFER_SIZE; i++) {
+                txData[i] = 0;
+            }
+            nrf->write(NRF24L01P_PIPE_P0, txData, TRANSFER_SIZE);
+        //possibly implement kill switch/stop current action
+    //...
+    //code for receiving
+    while(!received) {
+        if (nrf->readable() ) {
+            rxDataCnt = nrf->read(NRF24L01P_PIPE_P0, rxData, sizeof(rxData));
+            /*
+            either go char by char to determine command or switch statement
+            for ( int j = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
+
+                pc.putc( rxData[j] );
+            }*/
+        }
+        //received = true after receiving command
+    }
+    //switch statement, sorting all commands
+    
+}
+
+void DumpTruck::reportData() {
+    //should run last in main thread
+
 }
 
 void DumpTruck::driveDistance(float speed, float distance) {