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@23:7f5681d8d5b5, 2013-04-03 (annotated)
- Committer:
- IngesupMbed01
- Date:
- Wed Apr 03 10:36:21 2013 +0000
- Revision:
- 23:7f5681d8d5b5
- Parent:
- 22:d2adbcc3580d
- Child:
- 24:3462a304f9a0
Buffer Trame fini
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 | 23:7f5681d8d5b5 | 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 | 23:7f5681d8d5b5 | 29 | } |
IngesupMbed01 | 22:d2adbcc3580d | 30 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 31 | C_FrameBuffer::C_FrameBuffer(unsigned int size) |
IngesupMbed01 | 23:7f5681d8d5b5 | 32 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 33 | m_maxSize = size; |
IngesupMbed01 | 23:7f5681d8d5b5 | 34 | m_frameBuffer = new frame [m_maxSize]; |
IngesupMbed01 | 23:7f5681d8d5b5 | 35 | m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 36 | m_currentWriteIndex = 0; |
IngesupMbed01 | 22:d2adbcc3580d | 37 | } |
IngesupMbed01 | 22:d2adbcc3580d | 38 | |
IngesupMbed01 | 22:d2adbcc3580d | 39 | /* DESTRUCTEUR */ |
IngesupMbed01 | 22:d2adbcc3580d | 40 | C_FrameBuffer::~C_FrameBuffer() |
IngesupMbed01 | 22:d2adbcc3580d | 41 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 42 | delete [] m_frameBuffer; |
IngesupMbed01 | 23:7f5681d8d5b5 | 43 | m_maxSize = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 44 | m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 45 | m_currentWriteIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 46 | } |
IngesupMbed01 | 22:d2adbcc3580d | 47 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 48 | /* Propriétés */ |
IngesupMbed01 | 23:7f5681d8d5b5 | 49 | void C_FrameBuffer::frameBuffer(frame newFrame) |
IngesupMbed01 | 23:7f5681d8d5b5 | 50 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 51 | m_frameBuffer[m_currentWriteIndex] = newFrame; |
IngesupMbed01 | 23:7f5681d8d5b5 | 52 | m_currentWriteIndex++; |
IngesupMbed01 | 23:7f5681d8d5b5 | 53 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 54 | if(m_currentWriteIndex >= m_maxSize) m_currentWriteIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 55 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 56 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 57 | frame C_FrameBuffer::frameBuffer(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 58 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 59 | frame newFrame = m_frameBuffer[m_currentReadIndex]; |
IngesupMbed01 | 23:7f5681d8d5b5 | 60 | m_currentReadIndex++; |
IngesupMbed01 | 23:7f5681d8d5b5 | 61 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 62 | if(m_currentReadIndex >= m_maxSize) m_currentReadIndex = 0; |
IngesupMbed01 | 23:7f5681d8d5b5 | 63 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 64 | return newFrame; |
IngesupMbed01 | 23:7f5681d8d5b5 | 65 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 66 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 67 | frame C_FrameBuffer::frameBuffer(unsigned int index) |
IngesupMbed01 | 23:7f5681d8d5b5 | 68 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 69 | if(index >= m_maxSize) index = m_maxSize; |
IngesupMbed01 | 23:7f5681d8d5b5 | 70 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 71 | return m_frameBuffer[index]; |
IngesupMbed01 | 23:7f5681d8d5b5 | 72 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 73 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 74 | unsigned int C_FrameBuffer::maxSize(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 75 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 76 | return m_maxSize; |
IngesupMbed01 | 23:7f5681d8d5b5 | 77 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 78 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 79 | unsigned int C_FrameBuffer::currentReadIndex(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 80 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 81 | return m_currentReadIndex; |
IngesupMbed01 | 23:7f5681d8d5b5 | 82 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 83 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 84 | void C_FrameBuffer::currentReadIndex(unsigned int newIndex) |
IngesupMbed01 | 23:7f5681d8d5b5 | 85 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 86 | if(newIndex >= m_maxSize) newIndex = m_maxSize; |
IngesupMbed01 | 23:7f5681d8d5b5 | 87 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 88 | m_currentReadIndex = newIndex; |
IngesupMbed01 | 23:7f5681d8d5b5 | 89 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 90 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 91 | unsigned int C_FrameBuffer::currentWriteIndex(void) |
IngesupMbed01 | 23:7f5681d8d5b5 | 92 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 93 | return m_currentWriteIndex; |
IngesupMbed01 | 23:7f5681d8d5b5 | 94 | } |
IngesupMbed01 | 23:7f5681d8d5b5 | 95 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 96 | void C_FrameBuffer::currentWriteIndex(unsigned int newIndex) |
IngesupMbed01 | 23:7f5681d8d5b5 | 97 | { |
IngesupMbed01 | 23:7f5681d8d5b5 | 98 | if(newIndex >= m_maxSize) newIndex = m_maxSize; |
IngesupMbed01 | 23:7f5681d8d5b5 | 99 | |
IngesupMbed01 | 23:7f5681d8d5b5 | 100 | m_currentWriteIndex = newIndex; |
IngesupMbed01 | 22:d2adbcc3580d | 101 | } |