V0.5 library for the Pi Swarm robot

Files at this revision

API Documentation at this revision

Comitter:
jah128
Date:
Mon Feb 03 12:59:51 2014 +0000
Parent:
7:b51aae999f5e
Commit message:
Minor comments added

Changed in this revision

alpha433.cpp Show annotated file Show diff for this revision Revisions of this file
alpha433.h Show annotated file Show diff for this revision Revisions of this file
--- a/alpha433.cpp	Sun Feb 02 22:49:19 2014 +0000
+++ b/alpha433.cpp	Mon Feb 03 12:59:51 2014 +0000
@@ -1,6 +1,6 @@
 /*******************************************************************************************
  *
- * University of York Robot Lab Pi Swarm Library: 433MHz Alpha Transceiver
+ * University of York Robot Lab Pi Swarm Library: 433MHz Alpha Transceiver Driver
  *
  * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York
  *
@@ -15,10 +15,8 @@
 
 // Variables
 
-DigitalOut rf_led(LED1);
 Timeout reset_timeout;
 
-
 char cRFStatus = 0;
 
 signed short ssTransmitCount = 0;
@@ -41,45 +39,39 @@
 
 }
 
-
-
-
-// RF Send Data
-//
-//  Eg:
-//  unsigned char message[32];
-//  unsigned char count;
-//  count = snprintf(message, 32, "Hello: %i", 42);
-//  sendString(count, message);
+// Send data on the Alpha 433 transceiver, cCount = string length, cBuffer = data string
 unsigned long Alpha433::sendString(char cCount, char* cBuffer)
 {
-    // pc.printf("SendString called");
     unsigned char i = 0;
-    if(cRFStatus == ALPHA433_MODE_TRANSMITTING) {// RF already transmitting
+    if(cRFStatus == ALPHA433_MODE_TRANSMITTING) {
+        // RF already transmitting
         if(RF_VERBOSE == 1)pc.printf("RF Error: Already transmitting\n");
         return 1; // Error
 
     }
 
-    if(cCount > 62) {// Amount of data to high
+    if(cCount > 62) {
+        // Amount of data to high
         if(RF_VERBOSE == 1)pc.printf("RF Error: Too much tx data\n");
         return 2; // Error
 
     }
-    if(cCount == 0) {// No Data
+    if(cCount == 0) {
+        // No Data
         if(RF_VERBOSE == 1)pc.printf("RF Error: No tx data\n");
         return 3; // Error
     }
     cTXBuffer[i] = cCount;
-
     unsigned char checksum_byte = 0;
-    for(i=0; i<cCount; i++)   {// make a copy
+    for(i=0; i<cCount; i++)   {
+        // make a copy
         cTXBuffer[i+1] = cBuffer[i];
         checksum_byte ^= cBuffer[i];
     }
     cTXBuffer[cCount+1] = checksum_byte;
     if(RF_VERBOSE == 1)pc.printf("RF Message: \"%s\" Checksum: %2X\n",cBuffer,checksum_byte);
-    ssTransmitCount = cCount+3; // add count and checksum
+    ssTransmitCount = cCount+3; 
+    // add count and checksum
     ssTransmitPointer = -6;
     cRFStatus = ALPHA433_MODE_SWITCHING;
     disableReceiver();
@@ -106,13 +98,36 @@
     return 0;
 }
 
+// Handle new RF Data
+void Alpha433::dataAvailable(char cCount, char* cBuffer)
+{
+    char rstring [cCount+1];
+    char checksum = 0;
+    int i;
+    for(i=0; i<cCount; i++) {
+        rstring[i]=cBuffer[i];
+        checksum ^= rstring[i];
+    }
+    rstring[cCount]=0;
+    if (cBuffer[cCount] != checksum) {
+        if(RF_VERBOSE == 1)pc.printf("RF Received [%d] \"%s\" (checksum failed: expected %02X, received %02X)%02X %02X\n",cCount,rstring,checksum,cBuffer[cCount],cBuffer[cCount-1],cBuffer[cCount+1]);
+    } else {
+        if(RF_VERBOSE == 1)pc.printf("RF Received [%d] \"%s\" (checksum passed)\n",cCount,rstring);
+        if(USE_COMMUNICATION_STACK == 1) {
+            processRadioData(rstring, cCount);
+        } else {
+            processRawRFData(rstring, cCount);
+        }
+    }
+}
+
+
 // Enable RF Transmitter
 void Alpha433::enableTransmitter(void)
 {
     if(RF_VERBOSE == 1)pc.printf("RF Enable TX\n");
     //RFCommand(0x8229);
     _write(0x8229);
-    rf_led = 1;
 }
 
 // Disable RF Transmitter
@@ -121,7 +136,6 @@
     if(RF_VERBOSE == 1)pc.printf("RF Disable TX\n");
     //RFCommand(0x8209);
     _write(0x8209);
-    rf_led = 0;
 }
 
 
@@ -131,7 +145,6 @@
     if(RF_VERBOSE == 1)pc.printf("RF Enable RX\n");
     //RFCommand(0x8288);
     _write(0x8288);
-    //rx_led = 1;
     enableFifoFill();
 }
 
@@ -168,6 +181,7 @@
 
 }
 
+// Timeout interrupt routine - reset chip
 void Alpha433::timeout(void)
 {
     if(RF_VERBOSE == 1)pc.printf("RF Error on read; resetting chip\n");
@@ -196,11 +210,10 @@
 }
 
 
-// RF Interrupt
+// RF Interrupt Called - handle received data
 void Alpha433::interrupt(void)
 {
     if(cRFStatus == ALPHA433_MODE_RECEIVING) {
-        rf_led=1;
         //Add reset timeout
         reset_timeout.detach();
         reset_timeout.attach(this,&Alpha433::timeout,0.5);
@@ -278,8 +291,6 @@
     _write(0xA000 | ulRateCmd);
 }
 
-
-
 // Enable RF Receiver FiFo fill
 void Alpha433::enableFifoFill(void)
 {
@@ -293,29 +304,6 @@
     _write(0xCA00 | ALPHA433_FIFO_LEVEL | ALPHA433_FIFO_FILL | ALPHA433_HI_SENS_RESET);
 }
 
-// Handle new RF Data
-void Alpha433::dataAvailable(char cCount, char* cBuffer)
-{
-    char rstring [cCount+1];
-    char checksum = 0;
-    int i;
-    for(i=0; i<cCount; i++) {
-        rstring[i]=cBuffer[i];
-        checksum ^= rstring[i];
-    }
-    rstring[cCount]=0;
-    if (cBuffer[cCount] != checksum) {
-        if(RF_VERBOSE == 1)pc.printf("RF Received [%d] \"%s\" (checksum failed: expected %02X, received %02X)%02X %02X\n",cCount,rstring,checksum,cBuffer[cCount],cBuffer[cCount-1],cBuffer[cCount+1]);
-    } else {
-        if(RF_VERBOSE == 1)pc.printf("RF Received [%d] \"%s\" (checksum passed)\n",cCount,rstring);
-        if(USE_COMMUNICATION_STACK == 1) {
-            processRadioData(rstring, cCount);
-        } else {
-            processRawRFData(rstring, cCount);
-        }
-    }
-}
-
 
 int Alpha433::readStatusByte()
 {
--- a/alpha433.h	Sun Feb 02 22:49:19 2014 +0000
+++ b/alpha433.h	Mon Feb 03 12:59:51 2014 +0000
@@ -1,6 +1,6 @@
 /*******************************************************************************************
  *
- * University of York Robot Lab Pi Swarm Library: 433MHz Alpha Transceiver
+ * University of York Robot Lab Pi Swarm Library: 433MHz Alpha Transceiver Driver
  *
  * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York
  *