NerfUS / NerfUSXbee

Dependents:   NerfUS-Coord NerfUSTarget

Fork of APP3_xbee by Team APP

Files at this revision

API Documentation at this revision

Comitter:
GaiSensei
Date:
Wed Mar 29 17:00:14 2017 +0000
Parent:
14:cc65f603e659
Child:
16:f4df01448b59
Commit message:
Transmitter done, receiver coded but not tested

Changed in this revision

include/RealXbeeReceiver.hpp Show annotated file Show diff for this revision Revisions of this file
include/XbeeReceiverInterface.hpp Show annotated file Show diff for this revision Revisions of this file
include/XbeeTransmitterInterface.hpp Show annotated file Show diff for this revision Revisions of this file
include/xbee.h Show annotated file Show diff for this revision Revisions of this file
source/XbeeReceiver.cpp Show annotated file Show diff for this revision Revisions of this file
source/xbee.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/RealXbeeReceiver.hpp	Wed Mar 29 17:00:14 2017 +0000
@@ -0,0 +1,18 @@
+#ifndef REAL_XBEE_RECEIVER_HPP
+#define REAL_XBEE_RECEIVER_HPP
+
+#include <xbee.h>
+#include <XbeeReceiverInterface.hpp>
+
+class RealXbeeReceiver : public XbeeReceiverInterface
+{
+    public:
+        RealXbeeReceiver();
+        virtual void start();
+        
+    private:
+        const static Thread message_reader_thread;
+        const static Thread message_handler_thread;
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/XbeeReceiverInterface.hpp	Wed Mar 29 17:00:14 2017 +0000
@@ -0,0 +1,12 @@
+#ifndef XBEE_RECEIVER_INTERFACE_HPP
+#define XBEE_RECEIVER_INTERFACE_HPP
+
+#include <vector>
+
+class XbeeReceiverInterface
+{
+    public:
+        virtual void start() = 0; 
+};
+
+#endif
\ No newline at end of file
--- a/include/XbeeTransmitterInterface.hpp	Wed Mar 29 15:56:01 2017 +0000
+++ b/include/XbeeTransmitterInterface.hpp	Wed Mar 29 17:00:14 2017 +0000
@@ -1,7 +1,6 @@
 #ifndef XBEE_TRANSMITTER_INTERFACE_HPP
 #define XBEE_TRANSMITTER_INTERFACE_HPP
 
-#include <stdint.h>
 #include <vector>
 
 class XbeeTransmitterInterface
--- a/include/xbee.h	Wed Mar 29 15:56:01 2017 +0000
+++ b/include/xbee.h	Wed Mar 29 17:00:14 2017 +0000
@@ -36,9 +36,6 @@
 const char AT_COMMAND_RESPONSE_STATUS_OK = 0x00;
 const char REMOTE_COMMAND_RESPONSE_COMMAND_STATUS_OK = 0x00;
 
-const char EVENT_TYPE_BUTTON = 0x00;
-const char EVENT_TYPE_ACCELEROMETER = 0x01;
-
 const char BUTTON_PRESSED = 0x00;
 const char BUTTON_RELEASED = 0x01;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/XbeeReceiver.cpp	Wed Mar 29 17:00:14 2017 +0000
@@ -0,0 +1,12 @@
+#include "RealXbeeReceiver.hpp"
+
+RealXbeeReceiver::RealXbeeReceiver()
+{
+    
+}
+
+void RealXbeeReceiver::start()
+{
+    message_handler_thread.start(handle_parsed_frames_from_mailbox);
+    message_reader_thread.start(read_frame);
+}
\ No newline at end of file
--- a/source/xbee.cpp	Wed Mar 29 15:56:01 2017 +0000
+++ b/source/xbee.cpp	Wed Mar 29 17:00:14 2017 +0000
@@ -221,10 +221,7 @@
         switch(parsed_frame_type)
         {
             case FRAME_TYPE_RECEIVE_PACKET:
-                char parsed_frame_string[40];
-                parsed_frame_to_string(ingoing_value_to_vector(*parsed_frame), parsed_frame_string);
-                
-                printf("Handling receive packet: %s\r\n", parsed_frame_string);
+                parse_nerfus_message(ingoing_value_to_vector(*parsed_frame));
                 break;
             
             case FRAME_TYPE_REMOTE_COMMAND_RESPONSE:                
@@ -316,25 +313,44 @@
     return parsed_frame;
 }
 
-void parsed_frame_to_string(const vector<char>& parsed_frame, char* readable_string_output)
+void parse_nerfus_message(const vector<char>& parsed_frame)
 {
+    vector<uint8_t> message;
+    message.push_back(0x97);
+    
     const char event_type = parsed_frame[1];
     switch(event_type)
     {
-        case EVENT_TYPE_BUTTON:
-            parsed_button_event_frame_to_string(parsed_frame, readable_string_output);
+        case EVENT_TYPE_COORDINATOR_TO_ROUTER
+            parse_coordinator_command(message);
             break;
             
-        case EVENT_TYPE_ACCELEROMETER:
-            parsed_accelerometer_event_frame_to_string(parsed_frame, readable_string_output);
-            break;
-            
-        default:
-            strcpy(readable_string_output, "Invalid event type");
+        case EVENT_TYPE_ROUTOR_TO_COORDINATOR:
+            parse_routor_message(message);
             break;
     }
 }
 
+void parse_coordinator_command(vector<uint8_t> coordinator_command)
+{
+    coordinator_command.push_back(parsed_frame[2]);
+    coordinator_command.push_back(parsed_frame[3]);
+    coordinator_command.push_back(parsed_frame[4]);
+    coordinator_command.push_back(parsed_frame[5]);
+    
+    //Appeler fonction Max
+}
+
+void parse_routor_message(vector<uint8_t> routor_message)
+{
+    coordinator_command.push_back(parsed_frame[2]);
+    coordinator_command.push_back(parsed_frame[3]);
+    coordinator_command.push_back(parsed_frame[4]);
+    coordinator_command.push_back(parsed_frame[5]);   
+    
+    //Appeler fonction Ismaël
+}
+
 void parsed_button_event_frame_to_string(const vector<char>& parsed_frame, char* readable_string_output)
 {
     const char button_state = parsed_frame[2];