![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Versao com problema no socket rx
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
rtpbuf.cpp@0:4d17cd9c8f9d, 2014-09-09 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 09 20:01:24 2014 +0000
- Revision:
- 0:4d17cd9c8f9d
20140726 copy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include <stdlib.h> |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 0:4d17cd9c8f9d | 3 | #include "debug.h" |
klauss | 0:4d17cd9c8f9d | 4 | #include "rtpbuf.h" |
klauss | 0:4d17cd9c8f9d | 5 | |
klauss | 0:4d17cd9c8f9d | 6 | static void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size) { |
klauss | 0:4d17cd9c8f9d | 7 | size >>= 2; |
klauss | 0:4d17cd9c8f9d | 8 | while (size--) *dest++ = *src++; |
klauss | 0:4d17cd9c8f9d | 9 | } |
klauss | 0:4d17cd9c8f9d | 10 | |
klauss | 0:4d17cd9c8f9d | 11 | static void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size) { |
klauss | 0:4d17cd9c8f9d | 12 | while (size--) *dest++ = *src++; |
klauss | 0:4d17cd9c8f9d | 13 | } |
klauss | 0:4d17cd9c8f9d | 14 | |
klauss | 0:4d17cd9c8f9d | 15 | /* |
klauss | 0:4d17cd9c8f9d | 16 | rtpbuf_t * rtpbuf_init(void) { |
klauss | 0:4d17cd9c8f9d | 17 | } |
klauss | 0:4d17cd9c8f9d | 18 | void rtpbuf_destroy(rtpbuf_t ** self) { |
klauss | 0:4d17cd9c8f9d | 19 | free(*self) |
klauss | 0:4d17cd9c8f9d | 20 | *self = NULL; |
klauss | 0:4d17cd9c8f9d | 21 | } |
klauss | 0:4d17cd9c8f9d | 22 | */ |
klauss | 0:4d17cd9c8f9d | 23 | |
klauss | 0:4d17cd9c8f9d | 24 | void rtpbuf_clear (rtpbuf_t * self) { |
klauss | 0:4d17cd9c8f9d | 25 | self->size = 0; |
klauss | 0:4d17cd9c8f9d | 26 | } |
klauss | 0:4d17cd9c8f9d | 27 | |
klauss | 0:4d17cd9c8f9d | 28 | void rtpbuf_put (rtpbuf_t * self, int size, uint8_t * data){ |
klauss | 0:4d17cd9c8f9d | 29 | if ((size + self->size) <= RTPBUF_BUFSIZE){ |
klauss | 0:4d17cd9c8f9d | 30 | xmemcpy((uint8_t*)self->b+self->size,data,size); |
klauss | 0:4d17cd9c8f9d | 31 | self->size += size; |
klauss | 0:4d17cd9c8f9d | 32 | //debug_msg("put %d -> %d",size,self->size); |
klauss | 0:4d17cd9c8f9d | 33 | } else { |
klauss | 0:4d17cd9c8f9d | 34 | //debug_msg("put-failed %d -> %d",size,self->size); |
klauss | 0:4d17cd9c8f9d | 35 | } |
klauss | 0:4d17cd9c8f9d | 36 | } |
klauss | 0:4d17cd9c8f9d | 37 | |
klauss | 0:4d17cd9c8f9d | 38 | uint8_t * rtpbuf_get (rtpbuf_t * self) { |
klauss | 0:4d17cd9c8f9d | 39 | if (self->size < RTPBUF_PKGSIZE) { |
klauss | 0:4d17cd9c8f9d | 40 | //debug_msg("get-failed %d", self->size); |
klauss | 0:4d17cd9c8f9d | 41 | return NULL; |
klauss | 0:4d17cd9c8f9d | 42 | } |
klauss | 0:4d17cd9c8f9d | 43 | //debug_msg("get %d", self->size); |
klauss | 0:4d17cd9c8f9d | 44 | return (uint8_t*) self->b; |
klauss | 0:4d17cd9c8f9d | 45 | } |
klauss | 0:4d17cd9c8f9d | 46 | |
klauss | 0:4d17cd9c8f9d | 47 | void rtpbuf_next (rtpbuf_t * self) { |
klauss | 0:4d17cd9c8f9d | 48 | if (self->size < RTPBUF_PKGSIZE) { |
klauss | 0:4d17cd9c8f9d | 49 | //debug_msg("next-failed %d", self->size); |
klauss | 0:4d17cd9c8f9d | 50 | } else { |
klauss | 0:4d17cd9c8f9d | 51 | //int i; |
klauss | 0:4d17cd9c8f9d | 52 | //i = self->size; |
klauss | 0:4d17cd9c8f9d | 53 | self->size -= RTPBUF_PKGSIZE; |
klauss | 0:4d17cd9c8f9d | 54 | if (self->size > 0) { |
klauss | 0:4d17cd9c8f9d | 55 | xmemcpy32(self->b, (self->b)+(RTPBUF_PKGSIZE>>2), self->size); |
klauss | 0:4d17cd9c8f9d | 56 | //debug_msg("nextA %d -> %d", i, self->size); |
klauss | 0:4d17cd9c8f9d | 57 | } else { |
klauss | 0:4d17cd9c8f9d | 58 | //debug_msg("nextB %d -> %d", i, self->size); |
klauss | 0:4d17cd9c8f9d | 59 | } |
klauss | 0:4d17cd9c8f9d | 60 | } |
klauss | 0:4d17cd9c8f9d | 61 | } |