Projet Drone de surveillance du labo TRSE (INGESUP)
Dependencies: mbed PID ADXL345 Camera_LS_Y201 ITG3200 RangeFinder mbos xbee_lib Motor Servo
Service/Buffer_Trame.cpp@36:1bbd2fb7d2c8, 2014-03-19 (annotated)
- Committer:
- Gaetan
- Date:
- Wed Mar 19 11:01:10 2014 +0000
- Revision:
- 36:1bbd2fb7d2c8
- Parent:
- 28:8b5ccd2f837e
Checksum correct pour l'envoi de n'importe quel message Mavlink. Reste ? g?rer la reception de messages
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IngesupMbed01 | 22:d2adbcc3580d | 1 | /* Copyright (c) 2012 - 2013 AUTEUR |
IngesupMbed01 | 22:d2adbcc3580d | 2 | * |
IngesupMbed01 | 22:d2adbcc3580d | 3 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED |
IngesupMbed01 | 22:d2adbcc3580d | 4 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
IngesupMbed01 | 22:d2adbcc3580d | 5 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
IngesupMbed01 | 22:d2adbcc3580d | 6 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
IngesupMbed01 | 22:d2adbcc3580d | 7 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
IngesupMbed01 | 22:d2adbcc3580d | 8 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
IngesupMbed01 | 22:d2adbcc3580d | 9 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
IngesupMbed01 | 22:d2adbcc3580d | 10 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
IngesupMbed01 | 22:d2adbcc3580d | 11 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
IngesupMbed01 | 22:d2adbcc3580d | 12 | */ |
IngesupMbed01 | 22:d2adbcc3580d | 13 | |
IngesupMbed01 | 22:d2adbcc3580d | 14 | /* |
IngesupMbed01 | 22:d2adbcc3580d | 15 | * Description : Cette classe contient les fonctionnalités d'un buffer de trame. |
IngesupMbed01 | 22:d2adbcc3580d | 16 | * Input |
IngesupMbed01 | 22:d2adbcc3580d | 17 | * Output |
IngesupMbed01 | 22:d2adbcc3580d | 18 | */ |
IngesupMbed01 | 22:d2adbcc3580d | 19 | |
IngesupMbed01 | 22:d2adbcc3580d | 20 | #include "Buffer_Trame.h" |
IngesupMbed01 | 22:d2adbcc3580d | 21 | |
IngesupMbed01 | 22:d2adbcc3580d | 22 | /* CONSRTRUCTEUR(S) */ |
IngesupMbed01 | 22:d2adbcc3580d | 23 | C_FrameBuffer::C_FrameBuffer() |
IngesupMbed01 | 22:d2adbcc3580d | 24 | { |
IngesupMbed01 | 24:3462a304f9a0 | 25 | m_frameBuffer = new frame[default_size]; |
IngesupMbed01 | 23:7f5681d8d5b5 | 26 | m_maxSize = default_size; |
IngesupMbed01 | 23:7f5681d8d5b5 | 27 | m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 28 | m_currentWriteIndex = 0; |
IngesupMbed01 | 26:814d9b08aa68 | 29 | m_numberMessage = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 30 | } |
IngesupMbed01 | 22:d2adbcc3580d | 31 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 32 | C_FrameBuffer::C_FrameBuffer(unsigned int size) |
IngesupMbed01 | 23:7f5681d8d5b5 | 33 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 34 | m_maxSize = size; |
IngesupMbed01 | 24:3462a304f9a0 | 35 | m_frameBuffer = new frame[m_maxSize]; |
IngesupMbed01 | 23:7f5681d8d5b5 | 36 | m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 37 | m_currentWriteIndex = 0; |
IngesupMbed01 | 26:814d9b08aa68 | 38 | m_numberMessage = 0; |
IngesupMbed01 | 22:d2adbcc3580d | 39 | } |
IngesupMbed01 | 22:d2adbcc3580d | 40 | |
IngesupMbed01 | 22:d2adbcc3580d | 41 | /* DESTRUCTEUR */ |
IngesupMbed01 | 22:d2adbcc3580d | 42 | C_FrameBuffer::~C_FrameBuffer() |
IngesupMbed01 | 22:d2adbcc3580d | 43 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 44 | delete [] m_frameBuffer; |
IngesupMbed01 | 23:7f5681d8d5b5 | 45 | m_maxSize = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 46 | m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 47 | m_currentWriteIndex = 0; |
IngesupMbed01 | 26:814d9b08aa68 | 48 | m_numberMessage = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 49 | } |
IngesupMbed01 | 22:d2adbcc3580d | 50 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 51 | /* Propriétés */ |
IngesupMbed01 | 23:7f5681d8d5b5 | 52 | void C_FrameBuffer::frameBuffer(frame newFrame) |
IngesupMbed01 | 23:7f5681d8d5b5 | 53 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 54 | m_frameBuffer[m_currentWriteIndex] = newFrame; |
IngesupMbed01 | 23:7f5681d8d5b5 | 55 | m_currentWriteIndex++; |
IngesupMbed01 | 26:814d9b08aa68 | 56 | m_numberMessage++; |
IngesupMbed01 | 23:7f5681d8d5b5 | 57 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 58 | if(m_currentWriteIndex >= m_maxSize) m_currentWriteIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 59 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 60 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 61 | frame C_FrameBuffer::frameBuffer(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 62 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 63 | frame newFrame = m_frameBuffer[m_currentReadIndex]; |
IngesupMbed01 | 23:7f5681d8d5b5 | 64 | m_currentReadIndex++; |
IngesupMbed01 | 26:814d9b08aa68 | 65 | m_numberMessage--; |
IngesupMbed01 | 23:7f5681d8d5b5 | 66 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 67 | if(m_currentReadIndex >= m_maxSize) m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 68 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 69 | return newFrame; |
IngesupMbed01 | 23:7f5681d8d5b5 | 70 | } |
IngesupMbed01 | 28:8b5ccd2f837e | 71 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 72 | unsigned int C_FrameBuffer::maxSize(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 73 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 74 | return m_maxSize; |
IngesupMbed01 | 23:7f5681d8d5b5 | 75 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 76 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 77 | unsigned int C_FrameBuffer::currentReadIndex(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 78 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 79 | return m_currentReadIndex; |
IngesupMbed01 | 23:7f5681d8d5b5 | 80 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 81 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 82 | unsigned int C_FrameBuffer::currentWriteIndex(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 83 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 84 | return m_currentWriteIndex; |
IngesupMbed01 | 23:7f5681d8d5b5 | 85 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 86 | |
IngesupMbed01 | 26:814d9b08aa68 | 87 | unsigned int C_FrameBuffer::numberMessage(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 88 | { |
IngesupMbed01 | 26:814d9b08aa68 | 89 | return m_numberMessage; |
IngesupMbed01 | 22:d2adbcc3580d | 90 | } |