Browse Source

Ring buffer index incrementation

Ring buffer functions were not incrementing index, which caused improper work of these functions.
Mateusz Bugdalski 13 năm trước cách đây
mục cha
commit
d2679884fe
1 tập tin đã thay đổi với 3 bổ sung4 xóa
  1. 3 4
      serial.c

+ 3 - 4
serial.c

@@ -221,8 +221,6 @@ void serial_communicate(struct serial_device *port, int infd, int outfd) {
       n = write(port->fd, buf, n);
       ringbuf_move(&port->out_buf, n);
     }
-
-
     
     if(FD_ISSET(infd, &read_set)) {
       bytes = sizeof(port->out_buf.data) - port->out_buf.size;
@@ -271,7 +269,7 @@ int ringbuf_append(struct ring_buf *buf, const char *data, unsigned int len) {
   for(i=0; i<len; i++) {
     if(p>=sizeof(buf->data))
       p -= sizeof(buf->data);
-    buf->data[p] = data[i];
+    buf->data[p++] = data[i];
   }
   buf->size += len;
   return 0;
@@ -288,6 +286,7 @@ int ringbuf_getline(struct ring_buf *buf, char *data, unsigned int len) {
     if(p>=sizeof(buf->data))
       p -= sizeof(buf->data);
     if(buf->data[p]=='\r' || buf->data[p]=='\n') break;
+    p++;
   }
   
   if((len-datap-1)<i) return -1;
@@ -321,7 +320,7 @@ int ringbuf_getdata(struct ring_buf *buf, char *data, unsigned int len) {
   for(i=0; i<len; i++) {
     if(p>=sizeof(buf->data))
       p -= sizeof(buf->data);
-    data[i] = buf->data[p];
+    data[i] = buf->data[p++];
   }
   return len;
 }