Projet Drone de surveillance du labo TRSE (INGESUP)

Dependencies:   mbed PID ADXL345 Camera_LS_Y201 ITG3200 RangeFinder mbos xbee_lib Motor Servo

Module_Communication/Module_Communication.cpp

Committer:
IngesupMbed01
Date:
2013-04-17
Revision:
30:119e060b45b3
Parent:
29:a0800d3da787
Child:
31:ec7d635636bf

File content as of revision 30:119e060b45b3:

 /* Copyright (c) 2012 - 2013 AUTHEUR
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 /*
 * Description : Cette classe contient les fonctionnalités du module communication.
                 Le module communication gère la communication entre les modules présents sur le drône et le PC.
 * Input
 * Output
 */
 
 #include "Module_Communication.h"
 
 // Pointeur sur la classe systeme d'exploitation instancié dans le main
 extern mbos *os;
 
 
 /* CONSRTRUCTEUR(S) */
 C_ModuleCommunication::C_ModuleCommunication()
 {
    m_xbee = new xbee(p9, p10, p11);
    m_trameRxBuffer = C_FrameBuffer();
    m_trameTxBuffer = C_FrameBuffer();
    m_charRxBuffer = new char[17];
    m_charTxBuffer = new char[17];
 }
 
 /* DESTRUCTEUR */
 C_ModuleCommunication::~C_ModuleCommunication()
 {
    delete [] m_charRxBuffer;
    delete [] m_charTxBuffer;
    delete m_xbee;
 }
 
 /* Point d'entrée de la tache Module Video */
 void C_ModuleCommunication::moduleCommunicationTask(void)
 {
    while(1){
    // Code
    }
 }
 
 void C_ModuleCommunication::envoiDeTrame(void)
 {
    frame newFrame = m_trameTxBuffer.frameBuffer();
    m_charTxBuffer[0] = 0x02;
    m_charTxBuffer[1] = newFrame.systemIdentifier;
    m_charTxBuffer[2] = newFrame.moduleIdentifier;
    m_charTxBuffer[3] = newFrame.messageIdentifier;
    m_charTxBuffer[16] = 0x03;
    
    for(int i = 0; i < 12; i++) {
        m_charTxBuffer[i+4] = newFrame.data[i];
    }
    
    m_xbee->SendData(m_charTxBuffer);
 }
 
 void C_ModuleCommunication::receptionDeTrame(void)
 {
    Serial pc(USBTX, USBRX);
    m_xbee->RecieveData(m_charRxBuffer, 0);
    pc.printf("You said:%s \n",m_charRxBuffer);
    
    
    frame newFrame;
    newFrame.systemIdentifier = m_charRxBuffer[1];
    newFrame.moduleIdentifier = m_charRxBuffer[2];
    newFrame.messageIdentifier = m_charRxBuffer[3];
    
    for(int i = 0; i < 12; i++) {
        newFrame.data[i] = m_charRxBuffer[i+4];
    }
    
    m_trameRxBuffer.frameBuffer(newFrame);
 }
 
 void C_ModuleCommunication::traitementTrame(void)
 {
    if(m_trameRxBuffer.numberMessage() <= 0) return;
    
    frame newFrame = m_trameRxBuffer.frameBuffer();
    
    switch(newFrame.moduleIdentifier) {
        case 0x31 : 
                    break;
        case 0x32 : 
                    break;
                    
    }
 }