asd

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
manl2003
Date:
Mon Feb 08 16:13:38 2016 +0000
Commit message:
asdad

Changed in this revision

CoordCommands.cpp Show annotated file Show diff for this revision Revisions of this file
CoordCommands.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CoordCommands.cpp	Mon Feb 08 16:13:38 2016 +0000
@@ -0,0 +1,67 @@
+#include "CoordCommands.h"
+
+CoordinatorCommands::CoordinatorCommands(Serial* _serialXB, Serial* _pc, char* panID, int panIDLength) :
+m_InFrame(false)
+{
+    m_Xbee = _serialXB;
+    m_PC = _pc;
+    SetPanID(panID, panIDLength);
+}
+void CoordinatorCommands::SetPanID(char* panID, int panIDLength)
+{
+    //7E 00 09 09 3D 49 44 C0 FF EE BA BE 07
+    SendCommand( 0x00, 0x09, 0x09, 0x40, 0x49, 0x44, panID, panIDLength);   
+}
+
+void CoordinatorCommands::SendCommand(char lengthMSB, char lengthLSB, char frameType, char frameID, char aTCommandMSB, char aTCommandLSB, char* parameterValue, int paramLength)
+{
+    char cmd[100]; 
+    int cmdLength;
+    cmd[0] = START_DELIMITER;
+    cmd[1] = lengthMSB;
+    cmd[2] = lengthLSB; 
+    cmd[3] = frameType;
+    cmd[4] = frameID;
+    cmd[5] = aTCommandMSB;
+    cmd[6] = aTCommandLSB;
+    
+    cmdLength = 6; 
+    for(int i = 0 ; i < paramLength ; i++)
+    {   
+        cmdLength++;
+        cmd[cmdLength] = parameterValue[i];
+    }
+    
+    uint8_t checksum = 0;
+    for(int i = 3 ; i <= cmdLength ; i++ )
+    {
+        checksum += cmd[i];
+    }
+    
+    cmdLength++;
+    cmd[cmdLength] = 0xFF - checksum;
+    
+    if(m_Xbee->writeable())
+    {
+        for(int i = 0 ; i <= cmdLength ; i++)
+        {
+            m_Xbee->putc(cmd[i]);
+            m_PC->printf("%X", cmd[i]);
+        }
+    }    
+}
+
+void CoordinatorCommands::LectureDeTrame()
+{
+    if(m_Xbee->readable())
+    {
+        char currentChar = m_Xbee->getc();
+        
+        if(m_InFrame)
+        {
+                
+        }
+            
+    }
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CoordCommands.h	Mon Feb 08 16:13:38 2016 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+
+class CoordinatorCommands
+{   
+    
+public:
+    CoordinatorCommands(Serial* _serialXB, Serial* _pc, char* panID, int panIDLength);
+    void SendCommand(char lengthMSB, char lengthLSB, char frameType, char frameID, char aTCommandMSB, char aTCommandLSB, char* parameterValue, int paramLength);
+    void SetPanID(char* panID, int panIDLength);
+    void LectureDeTrame();
+    
+private:
+    Serial* m_Xbee;
+    Serial* m_PC;
+    bool m_InFrame;
+    static const char START_DELIMITER = 0x7E;        
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 08 16:13:38 2016 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "CoordCommands.h"
+
+DigitalOut reset(p8);
+Serial pc(USBTX,USBRX);
+Serial xbee(p13, p14);
+
+
+int main() {
+ 
+     
+    reset = 0;
+    wait(0.4);
+    reset = 1;
+
+    wait(1);
+    
+    while(xbee.readable())
+    {
+        char dompe = xbee.getc();  
+    }
+
+    //Temp
+    char panID[5];
+    panID[0] = 0xC0;
+    panID[1] = 0xFF;
+    panID[2] = 0xEE;
+    panID[3] = 0xBA;
+    panID[4] = 0xBE;
+    
+    CoordinatorCommands coord(&xbee, &pc, panID, 5);    
+    
+    while(1) {
+        if(pc.readable()) 
+        {
+            xbee.putc(pc.getc());
+        }
+        if(xbee.readable()) 
+        {
+            pc.putc(xbee.getc());
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 08 16:13:38 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file