General testings

Dependencies:   mbed

Fork of BEACON_CODE_NEW by Mohamed Azad

Files at this revision

API Documentation at this revision

Comitter:
shekhar
Date:
Mon Oct 05 13:42:38 2015 +0000
Parent:
11:b341766c14b5
Child:
13:1c5cd2fa4b56
Commit message:
Long_beacon and short_beacon functions updated;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
tx.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 05 12:13:59 2015 +0000
+++ b/main.cpp	Mon Oct 05 13:42:38 2015 +0000
@@ -1,16 +1,6 @@
 #include "tx.h"
 #include <stdio.h>
 
-//STATES
-#define BCN_RF_SILENCE 0 
-#define BCN_TX_DISABLED 1
-#define BCN_TX_STANDBY 2
-#define BCN_TX_FAILURE 3
-//#define BCN_TX_SB_SI_SUCCESS 4
-//#define BCN_TX_SB_LI_SUCCESS 5
-#define BCN_TX_SUCCESS 4
-
-
 Ticker loop;
 Serial pc(USBTX, USBRX);        //tx,rx
 SPI spi(D11, D12, D13);              // mosi, miso, sclk
@@ -115,7 +105,7 @@
 void SHORT_BCN_TX()
 {
     writereg(RF22_REG_6E_TX_DATA_RATE,0x01);
-    writereg(RF22_REG_6F_TX_DATA_RATE,0x06);
+    writereg(RF22_REG_6F_TX_DATA_RATE,0x4F);//160bps
     writereg(RF22_REG_3E_PACKET_LENGTH,SHORT_TX_DATA); //short packet length
     /*
     init();
@@ -145,96 +135,46 @@
     pc.printf("%d %d %d %d %d %d %d %d %d %d %d %d",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9],data[10],data[11],data[12]);*/
     
     //setModeIdle();
-    writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode    
+    //writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode       ??    
     clearTxBuf();     
     //writing data first time
+    int byte = 0;
     cs = 0;
     spi.write(0xFF);   
-    for(i=7; i>0;i--)
+    
+    for (int byte_counter = 0; byte_counter <15 ; i++)
     {
-        //pc.printf("i=%d \n",i);        
-        if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
+        for(int j = 3; j >= 0 ; j--)
         {
-            i--;
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
+            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,(j*2+1)))!= pow(2.0,(j*2+1)))
             {
-                spi.write(0x00);
-                //pc.printf("0x00\n");
+                byte=0x00;
             }
             else
+            { 
+                byte=0xF0;
+            }  
+            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,j*2))!= pow(2.0,j*2))
             {
-                spi.write(0x0F);
-                //pc.printf("0x0F\n");
-            }
-        }
-        else
-        {
-            i--;
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-            {
-                spi.write(0xF0);
-                //pc.printf("0xF0\n");                
+                byte=byte | 0x00;
             }
             else
-            {
-                spi.write(0xFF);
-                //pc.printf("0xFF\n");                
+            { 
+               byte=byte | 0x0F;
             }
-        }
-    }
+            spi.write(byte);
+         }
+    }   
+    
     cs = 1;
-    byte_counter++;
-    //Check for fifoThresh
-    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
-        //pc.printf("fifothresh1?\n");
     
     //Set to Tx mode
     writereg(RF22_REG_07_OPERATING_MODE1,0x09);
-    
-    while(byte_counter!=15)
-    {
-        //pc.printf("%d\n",byte_counter);
-        cs = 0;
-        spi.write(0xFF);   
-        for(i=7; i>0;i--)
-        {
-            //pc.printf("i=%d \n",i);        
-            if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-            {
-                i--;
-                if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-                {
-                    spi.write(0x00);
-                    //pc.printf("0x00\n");
-                }
-                else
-                {
-                    spi.write(0x0F);
-                    //pc.printf("0x0F\n");
-                }
-            }
-            else
-            {
-                i--;
-                if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-                {
-                    spi.write(0xF0);
-                    //pc.printf("0xF0\n");                
-                }
-                else
-                {
-                    spi.write(0xFF);
-                    //pc.printf("0xFF\n");                
-                }
-            }
-        }
-        cs = 1;
-        byte_counter++;
-        wait(0.01);
-        //Check for fifoThresh
-        while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20 && (byte_counter<15));
-            //pc.printf("fifothresh2?\n");      
-    }  
+      
+    //Check for fifoThresh
+    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
+    //pc.printf("fifothresh1?\n");
+
     //rf22.waitPacketSent();
     while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04);
         //pc.printf(" chk pkt sent!\r\n");     
@@ -249,18 +189,14 @@
     int i=0;
     //extract values from long_beacon[]
     uint8_t byte_counter = 0;
-    struct Long_beacon
+    
+    //uint8_t Long_beacon[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,Longbeacon.Voltage[0],Longbeacon.AngularSpeed[0], Longbeacon.AngularSpeed[1],Longbeacon.SubsystemStatus[0],Longbeacon.Temp[0],Longbeacon.Temp[1],Longbeacon.Temp[2],Longbeacon.ErrorFlag[0]};
+    
+    uint8_t Long_beacon[75];
+    for(int i = 0;i<75;i++)
     {
-        uint8_t Voltage[1];
-        uint8_t AngularSpeed[2];
-        uint8_t SubsystemStatus[1];
-        uint8_t Temp[3];
-        uint8_t ErrorFlag[1];
-    }Longbeacon = { {0x88}, {0x99, 0xAA} , {0xAA},{0xAA,0xDD,0xEE}, {0x00} };
-    
-    //filling hk data
-    //uint8_t long_beacon[] = { 0xAB, 0x8A, 0xE2, 0xBB, 0xB8, 0xA2, 0x8E,Longbeacon.Voltage[0],Longbeacon.AngularSpeed[0], Longbeacon.AngularSpeed[1],Longbeacon.SubsystemStatus[0],Longbeacon.Temp[0],Longbeacon.Temp[1],Longbeacon.Temp[2],Longbeacon.ErrorFlag[0]};
-    uint8_t Long_beacon[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,Longbeacon.Voltage[0],Longbeacon.AngularSpeed[0], Longbeacon.AngularSpeed[1],Longbeacon.SubsystemStatus[0],Longbeacon.Temp[0],Longbeacon.Temp[1],Longbeacon.Temp[2],Longbeacon.ErrorFlag[0]};
+        Long_beacon[i] = 0xA0;
+    }
     
     //setModeIdle();
     writereg(RF22_REG_07_OPERATING_MODE1,0x01);        //ready mode    
@@ -268,91 +204,30 @@
     //writing data first time
     cs = 0;
     spi.write(0xFF);   
-    for(i=7; i>0;i--)
+    for(int i=0; i<60;i++)
     {
-        //pc.printf("i=%d \n",i);        
-        if((Long_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-        {
-            i--;
-            if((Long_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-            {
-                spi.write(0x00);
-                //pc.printf("0x00\n");
-            }
-            else
-            {
-                spi.write(0x0F);
-                //pc.printf("0x0F\n");
-            }
-        }
-        else
-        {
-            i--;
-            if((Long_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-            {
-                spi.write(0xF0);
-                //pc.printf("0xF0\n");                
-            }
-            else
-            {
-                spi.write(0xFF);
-                //pc.printf("0xFF\n");                
-            }
-        }
+        spi.write(Long_beacon[i]);
     }
     cs = 1;
-    byte_counter++;
-    //Check for fifoThresh
-    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
-        //pc.printf("fifothresh1?\n");
     
     //Set to Tx mode
     writereg(RF22_REG_07_OPERATING_MODE1,0x09);
-    
-    while(byte_counter!=15)
+
+    //Check for fifoThresh
+    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
+    //pc.printf("fifothresh1?\n");
+    //writing data first time
+    cs = 0;
+    spi.write(0xFF);   
+    for(int i=60; i<75;i++)
     {
-        //pc.printf("%d\n",byte_counter);
-        cs = 0;
-        spi.write(0xFF);   
-        for(i=7; i>0;i--)
-        {
-            //pc.printf("i=%d \n",i);        
-            if((Long_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-            {
-                i--;
-                if((Long_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-                {
-                    spi.write(0x00);
-                    //pc.printf("0x00\n");
-                }
-                else
-                {
-                    spi.write(0x0F);
-                    //pc.printf("0x0F\n");
-                }
-            }
-            else
-            {
-                i--;
-                if((Long_beacon[byte_counter] & (uint8_t) pow(2.0,i))!= pow(2.0,i))
-                {
-                    spi.write(0xF0);
-                    //pc.printf("0xF0\n");                
-                }
-                else
-                {
-                    spi.write(0xFF);
-                    //pc.printf("0xFF\n");                
-                }
-            }
-        }
-        cs = 1;
-        byte_counter++;
-        wait(0.01);
-        //Check for fifoThresh
-        while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
-            //pc.printf("fifothresh2?\n");      
-    }  
+        spi.write(Long_beacon[i]);
+    }
+    cs = 1;
+    wait(0.01);
+    //Check for fifoThresh
+    while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20);
+    //pc.printf("fifothresh2?\n");      
     //rf22.waitPacketSent();
     while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04);
         //pc.printf(" chk pkt sent!]\r\n");     
--- a/tx.h	Mon Oct 05 12:13:59 2015 +0000
+++ b/tx.h	Mon Oct 05 13:42:38 2015 +0000
@@ -6,13 +6,11 @@
 #define BCN_TX_DISABLED 1
 #define BCN_TX_STANDBY 2
 #define BCN_TX_FAILURE 3
-//#define BCN_TX_SB_SI_SUCCESS 4
-//#define BCN_TX_SB_LI_SUCCESS 5
 #define BCN_TX_SUCCESS 4
 
 //Size of tx data
 #define SHORT_TX_DATA 60    //in bytes
-#define LONG_TX_DATA 180    //in bytes      
+#define LONG_TX_DATA 75    //in bytes      
 
 //#define RF_SILENCE_TIME 5   //in seconds   //shouldn't this be 35 mins in actual scenario
 #define RF_SILENCE_TIME 35*60
@@ -48,8 +46,7 @@
 #define RF22_MAX_MESSAGE_LEN 255
 
 //These values we set for FIFO thresholds
-#define RF22_TXFFAEM_THRESHOLD 4
-#define RF22_RXFFAFULL_THRESHOLD 55
+#define RF22_TXFFAEM_THRESHOLD 40
 
 //Registers
 #define RF22_REG_00_DEVICE_TYPE                         0x00