From d7c0fbc379951d6107bb2e911fbce4114e8a3e90 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 29 Aug 2016 22:36:18 +0200 Subject: [PATCH] add const where possible (for message parsing) --- firmware/messages.c | 8 ++++---- firmware/messages.h | 10 +++++----- firmware/protob/pb_decode.c | 2 +- firmware/protob/pb_decode.h | 4 ++-- firmware/usb.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/firmware/messages.c b/firmware/messages.c index 9981bc2..c927e53 100644 --- a/firmware/messages.c +++ b/firmware/messages.c @@ -308,7 +308,7 @@ void msg_process(char type, uint16_t msg_id, const pb_field_t *fields, uint8_t * } } -void msg_read_common(char type, uint8_t *buf, int len) +void msg_read_common(char type, const uint8_t *buf, int len) { static char read_state = READSTATE_IDLE; static uint8_t msg_in[MSG_IN_SIZE]; @@ -357,7 +357,7 @@ void msg_read_common(char type, uint8_t *buf, int len) } } -uint8_t *msg_out_data(void) +const uint8_t *msg_out_data(void) { if (msg_out_start == msg_out_end) return 0; uint8_t *data = msg_out + (msg_out_start * 64); @@ -368,7 +368,7 @@ uint8_t *msg_out_data(void) #if DEBUG_LINK -uint8_t *msg_debug_out_data(void) +const uint8_t *msg_debug_out_data(void) { if (msg_debug_out_start == msg_debug_out_end) return 0; uint8_t *data = msg_debug_out + (msg_debug_out_start * 64); @@ -382,7 +382,7 @@ uint8_t *msg_debug_out_data(void) uint8_t msg_tiny[64]; uint16_t msg_tiny_id = 0xFFFF; -void msg_read_tiny(uint8_t *buf, int len) +void msg_read_tiny(const uint8_t *buf, int len) { if (len != 64) return; if (buf[0] != '?' || buf[1] != '#' || buf[2] != '#') { diff --git a/firmware/messages.h b/firmware/messages.h index a32e3ce..ac48110 100644 --- a/firmware/messages.h +++ b/firmware/messages.h @@ -30,7 +30,7 @@ #define msg_read(buf, len) msg_read_common('n', (buf), (len)) #define msg_write(id, ptr) msg_write_common('n', (id), (ptr)) -uint8_t *msg_out_data(void); +const uint8_t *msg_out_data(void); #if DEBUG_LINK @@ -38,15 +38,15 @@ uint8_t *msg_out_data(void); #define msg_debug_read(buf, len) msg_read_common('d', (buf), (len)) #define msg_debug_write(id, ptr) msg_write_common('d', (id), (ptr)) -uint8_t *msg_debug_out_data(void); +const uint8_t *msg_debug_out_data(void); #endif -void msg_read_common(char type, uint8_t *buf, int len); +void msg_read_common(char type, const uint8_t *buf, int len); bool msg_write_common(char type, uint16_t msg_id, const void *msg_ptr); -void msg_read_tiny(uint8_t *buf, int len); -void msg_debug_read_tiny(uint8_t *buf, int len); +void msg_read_tiny(const uint8_t *buf, int len); +void msg_debug_read_tiny(const uint8_t *buf, int len); extern uint8_t msg_tiny[64]; extern uint16_t msg_tiny_id; diff --git a/firmware/protob/pb_decode.c b/firmware/protob/pb_decode.c index c97ffde..307bbc4 100644 --- a/firmware/protob/pb_decode.c +++ b/firmware/protob/pb_decode.c @@ -151,7 +151,7 @@ static bool checkreturn pb_readbyte(pb_istream_t *stream, uint8_t *buf) return true; } -pb_istream_t pb_istream_from_buffer(uint8_t *buf, size_t bufsize) +pb_istream_t pb_istream_from_buffer(const uint8_t *buf, size_t bufsize) { pb_istream_t stream; #ifdef PB_BUFFER_ONLY diff --git a/firmware/protob/pb_decode.h b/firmware/protob/pb_decode.h index 8dc6740..45c0675 100644 --- a/firmware/protob/pb_decode.h +++ b/firmware/protob/pb_decode.h @@ -37,7 +37,7 @@ struct _pb_istream_t bool (*callback)(pb_istream_t *stream, uint8_t *buf, size_t count); #endif - void *state; /* Free field for use by callback implementation */ + const void *state; /* Free field for use by callback implementation */ size_t bytes_left; #ifndef PB_NO_ERRMSG @@ -103,7 +103,7 @@ void pb_release(const pb_field_t fields[], void *dest_struct); * Alternatively, you can use a custom stream that reads directly from e.g. * a file or a network socket. */ -pb_istream_t pb_istream_from_buffer(uint8_t *buf, size_t bufsize); +pb_istream_t pb_istream_from_buffer(const uint8_t *buf, size_t bufsize); /* Function to read from a pb_istream_t. You can use this if you need to * read some custom header data, or to read data in field callbacks. diff --git a/firmware/usb.c b/firmware/usb.c index 4224761..6466f4a 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -391,7 +391,7 @@ void usbInit(void) void usbPoll(void) { - static uint8_t *data; + static const uint8_t *data; // poll read buffer usbd_poll(usbd_dev); // write pending data