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@29:a0800d3da787, 2013-04-17 (annotated)
- Committer:
- IngesupMbed01
- Date:
- Wed Apr 17 10:16:19 2013 +0000
- Revision:
- 29:a0800d3da787
- Parent:
- 28:8b5ccd2f837e
- Child:
- 30:119e060b45b3
Define et structures ajout?s.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IngesupMbed01 | 18:0bfd3ad421e5 | 1 | /* Copyright (c) 2012 - 2013 AUTHEUR |
IngesupMbed01 | 18:0bfd3ad421e5 | 2 | * |
IngesupMbed01 | 18:0bfd3ad421e5 | 3 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED |
IngesupMbed01 | 18:0bfd3ad421e5 | 4 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
IngesupMbed01 | 18:0bfd3ad421e5 | 5 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
IngesupMbed01 | 18:0bfd3ad421e5 | 6 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
IngesupMbed01 | 18:0bfd3ad421e5 | 7 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
IngesupMbed01 | 18:0bfd3ad421e5 | 8 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
IngesupMbed01 | 18:0bfd3ad421e5 | 9 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
IngesupMbed01 | 18:0bfd3ad421e5 | 10 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
IngesupMbed01 | 18:0bfd3ad421e5 | 11 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
IngesupMbed01 | 18:0bfd3ad421e5 | 12 | */ |
IngesupMbed01 | 18:0bfd3ad421e5 | 13 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 14 | /* |
IngesupMbed01 | 18:0bfd3ad421e5 | 15 | * Description : Cette classe contient les fonctionnalités du module communication. |
IngesupMbed01 | 18:0bfd3ad421e5 | 16 | Le module communication gère la communication entre les modules présents sur le drône et le PC. |
IngesupMbed01 | 18:0bfd3ad421e5 | 17 | * Input |
IngesupMbed01 | 18:0bfd3ad421e5 | 18 | * Output |
IngesupMbed01 | 18:0bfd3ad421e5 | 19 | */ |
IngesupMbed01 | 18:0bfd3ad421e5 | 20 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 21 | #include "Module_Communication.h" |
IngesupMbed01 | 18:0bfd3ad421e5 | 22 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 23 | // Pointeur sur la classe systeme d'exploitation instancié dans le main |
IngesupMbed01 | 18:0bfd3ad421e5 | 24 | extern mbos *os; |
IngesupMbed01 | 18:0bfd3ad421e5 | 25 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 26 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 27 | /* CONSRTRUCTEUR(S) */ |
IngesupMbed01 | 18:0bfd3ad421e5 | 28 | C_ModuleCommunication::C_ModuleCommunication() |
IngesupMbed01 | 18:0bfd3ad421e5 | 29 | { |
IngesupMbed01 | 18:0bfd3ad421e5 | 30 | m_xbee = new xbee(p9, p10, p11); |
IngesupMbed01 | 24:3462a304f9a0 | 31 | m_trameRxBuffer = C_FrameBuffer(); |
IngesupMbed01 | 24:3462a304f9a0 | 32 | m_trameTxBuffer = C_FrameBuffer(); |
IngesupMbed01 | 24:3462a304f9a0 | 33 | m_charRxBuffer = new char[9]; |
IngesupMbed01 | 24:3462a304f9a0 | 34 | m_charTxBuffer = new char[9]; |
IngesupMbed01 | 18:0bfd3ad421e5 | 35 | } |
IngesupMbed01 | 18:0bfd3ad421e5 | 36 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 37 | /* DESTRUCTEUR */ |
IngesupMbed01 | 18:0bfd3ad421e5 | 38 | C_ModuleCommunication::~C_ModuleCommunication() |
IngesupMbed01 | 18:0bfd3ad421e5 | 39 | { |
IngesupMbed01 | 24:3462a304f9a0 | 40 | delete [] m_charRxBuffer; |
IngesupMbed01 | 24:3462a304f9a0 | 41 | delete [] m_charTxBuffer; |
IngesupMbed01 | 24:3462a304f9a0 | 42 | delete m_xbee; |
IngesupMbed01 | 18:0bfd3ad421e5 | 43 | } |
IngesupMbed01 | 18:0bfd3ad421e5 | 44 | |
IngesupMbed01 | 18:0bfd3ad421e5 | 45 | /* Point d'entrée de la tache Module Video */ |
IngesupMbed01 | 24:3462a304f9a0 | 46 | void C_ModuleCommunication::moduleCommunicationTask(void) |
IngesupMbed01 | 18:0bfd3ad421e5 | 47 | { |
IngesupMbed01 | 18:0bfd3ad421e5 | 48 | while(1){ |
IngesupMbed01 | 18:0bfd3ad421e5 | 49 | // Code |
IngesupMbed01 | 18:0bfd3ad421e5 | 50 | } |
IngesupMbed01 | 18:0bfd3ad421e5 | 51 | } |
IngesupMbed01 | 18:0bfd3ad421e5 | 52 | |
IngesupMbed01 | 24:3462a304f9a0 | 53 | void C_ModuleCommunication::envoiDeTrame(void) |
IngesupMbed01 | 24:3462a304f9a0 | 54 | { |
IngesupMbed01 | 24:3462a304f9a0 | 55 | m_xbee->SendData(m_charTxBuffer); |
IngesupMbed01 | 24:3462a304f9a0 | 56 | /* |
IngesupMbed01 | 24:3462a304f9a0 | 57 | frame newFrame = m_trameTxBuffer->frameBuffer(); |
IngesupMbed01 | 24:3462a304f9a0 | 58 | m_charTxBuffer[0] = newFrame.identifier; |
IngesupMbed01 | 24:3462a304f9a0 | 59 | |
IngesupMbed01 | 24:3462a304f9a0 | 60 | for(int i = 0; i < 8; i++) { |
IngesupMbed01 | 24:3462a304f9a0 | 61 | m_charTxBuffer[i+1] = newFrame.data[i]; |
IngesupMbed01 | 24:3462a304f9a0 | 62 | } |
IngesupMbed01 | 24:3462a304f9a0 | 63 | |
IngesupMbed01 | 24:3462a304f9a0 | 64 | m_xbee->SendData(m_charTxBuffer); |
IngesupMbed01 | 24:3462a304f9a0 | 65 | */ |
IngesupMbed01 | 24:3462a304f9a0 | 66 | } |
IngesupMbed01 | 24:3462a304f9a0 | 67 | |
IngesupMbed01 | 24:3462a304f9a0 | 68 | void C_ModuleCommunication::receptionDeTrame(void) |
IngesupMbed01 | 24:3462a304f9a0 | 69 | { |
IngesupMbed01 | 29:a0800d3da787 | 70 | Serial pc(USBTX, USBRX); |
IngesupMbed01 | 24:3462a304f9a0 | 71 | m_xbee->RecieveData(m_charRxBuffer, 0); |
IngesupMbed01 | 29:a0800d3da787 | 72 | pc.printf("You said:%s \n",m_charRxBuffer); |
IngesupMbed01 | 24:3462a304f9a0 | 73 | /* |
IngesupMbed01 | 24:3462a304f9a0 | 74 | frame newFrame; |
IngesupMbed01 | 24:3462a304f9a0 | 75 | newFrame.identifier = m_charRxBuffer[0]; |
IngesupMbed01 | 24:3462a304f9a0 | 76 | |
IngesupMbed01 | 24:3462a304f9a0 | 77 | for(int i = 0; i < 8; i++) { |
IngesupMbed01 | 29:a0800d3da787 | 78 | newFrame.data[i] = m_charRxBuffer[i+1]; |
IngesupMbed01 | 24:3462a304f9a0 | 79 | } |
IngesupMbed01 | 24:3462a304f9a0 | 80 | |
IngesupMbed01 | 24:3462a304f9a0 | 81 | m_trameRxBuffer->frameBuffer(newFrame); |
IngesupMbed01 | 24:3462a304f9a0 | 82 | */ |
IngesupMbed01 | 28:8b5ccd2f837e | 83 | } |
IngesupMbed01 | 28:8b5ccd2f837e | 84 | |
IngesupMbed01 | 28:8b5ccd2f837e | 85 | void C_ModuleCommunication::traitementTrame(void) |
IngesupMbed01 | 28:8b5ccd2f837e | 86 | { |
IngesupMbed01 | 28:8b5ccd2f837e | 87 | if(m_trameRxBuffer.numberMessage() <= 0) return; |
IngesupMbed01 | 28:8b5ccd2f837e | 88 | |
IngesupMbed01 | 28:8b5ccd2f837e | 89 | frame newFrame = m_trameRxBuffer.frameBuffer(); |
IngesupMbed01 | 28:8b5ccd2f837e | 90 | |
IngesupMbed01 | 28:8b5ccd2f837e | 91 | switch(newFrame.identifier) { |
IngesupMbed01 | 28:8b5ccd2f837e | 92 | case 0x31 : |
IngesupMbed01 | 28:8b5ccd2f837e | 93 | break; |
IngesupMbed01 | 28:8b5ccd2f837e | 94 | case 0x32 : |
IngesupMbed01 | 28:8b5ccd2f837e | 95 | break; |
IngesupMbed01 | 28:8b5ccd2f837e | 96 | |
IngesupMbed01 | 28:8b5ccd2f837e | 97 | } |
IngesupMbed01 | 24:3462a304f9a0 | 98 | } |