From 755680ca7246b232c45e3b519e9d8a95ea97375f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 27 May 2019 15:20:01 +0300 Subject: Device: partial implementation of line scrolling logic. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/device/screen.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device/screen.h | 22 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 src/device/screen.c create mode 100755 src/device/screen.h (limited to 'src') diff --git a/src/device/screen.c b/src/device/screen.c new file mode 100755 index 0000000..6ad9a87 --- /dev/null +++ b/src/device/screen.c @@ -0,0 +1,52 @@ +#include +#include +#include "screen.h" + +void draw_lines(struct display_status *status); +void update_lines(struct display_status *status); +char * get_line(struct display_status *status, size_t rline); + +void display_update_scroll(struct display_status *status) +{ + time_t crr_time = time(NULL); + if (status->last_scroll_time - crr_time > status->delta) { + status->last_scroll_time += status->delta; + status->line_cursor++; + update_lines(status); + } + draw_lines(status); +} + +void draw_lines(struct display_status *status) +{ + +} + +void update_lines(struct display_status *status) +{ + status->first_line = get_line(status, status->line_cursor); + status->second_line = get_line(status, status->line_cursor + 1); +} + +/** + * Returns a pointer to the first charachter of requested line. If line does not + * exist --- a null is returned. + */ +char * get_line(struct display_status *status, size_t rline) +{ + size_t i; + size_t line_idx = 0; + + for (i = 0; i < status->message_len; i++) { + if (rline == line_idx) { + return status->message + i; + } + if (status->message[i] == '\0') { + line_idx++; + } + } + /* The fact that we are here means that end of the message was reached. + * In that case --- return null; + */ + return NULL; +} \ No newline at end of file diff --git a/src/device/screen.h b/src/device/screen.h new file mode 100755 index 0000000..ec30cd5 --- /dev/null +++ b/src/device/screen.h @@ -0,0 +1,22 @@ +#ifndef DEVICE_SCREEN_H +#define DEVICE_SCREEN_H + +#include + +/** + * Struct that keeps track of the lines on the screen. + */ +struct display_status { + time_t delta; /* Seconds/Line */ + time_t last_scroll_time; /* Last second the line was scrolled */ + char *message; /* Entire message to be shown */ + char *first_line; /* First line on display */ + char *second_line; /* Second line on display */ + size_t message_len; /* Length of the message */ + size_t line_cursor; /* Index of the first line being displayed. */ +}; + +void display_update_scroll(struct display_status *status); +void display_status_init(struct display_status *status, char *msg); + +#endif /* DEVICE_SCREEN_H */ \ No newline at end of file -- cgit v1.2.3 From e37b3eacefef04258a6dc6e8714da249d2ff9c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 27 May 2019 15:44:38 +0300 Subject: Screen: More implementation details. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only a single function is a stub now --- the actual drawing. Signed-off-by: Ramūnas Mažeikis --- src/device/screen.c | 62 ++++++++++++++++++++++++++++++++--------------------- src/device/screen.h | 8 +++++++ 2 files changed, 45 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/device/screen.c b/src/device/screen.c index 6ad9a87..ac42076 100755 --- a/src/device/screen.c +++ b/src/device/screen.c @@ -1,10 +1,45 @@ #include #include +#include #include "screen.h" void draw_lines(struct display_status *status); void update_lines(struct display_status *status); -char * get_line(struct display_status *status, size_t rline); +void init_msg(char *msg, size_t size); + +void display_status_init(struct display_status *status, char *msg) +{ + status->delta = 2; /* Currently default */ + init_msg(msg, strlen(msg)); + status->message = msg; + status->line_cursor = 0; + status->last_scroll_time = time(NULL); + update_lines(status); +} + +/** + * Turns all whitespace into literal spaces to save screen real-estate. + */ +void init_msg(char *msg, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) { + switch (msg[i]) { + case '\n': + case '\t': + case '\r': + msg[i] = ' '; + break; + case '\0': + goto end; + default: + break; + } + } +end: + return; +} void display_update_scroll(struct display_status *status) { @@ -19,34 +54,11 @@ void display_update_scroll(struct display_status *status) void draw_lines(struct display_status *status) { - + /* TODO */ } void update_lines(struct display_status *status) { status->first_line = get_line(status, status->line_cursor); status->second_line = get_line(status, status->line_cursor + 1); -} - -/** - * Returns a pointer to the first charachter of requested line. If line does not - * exist --- a null is returned. - */ -char * get_line(struct display_status *status, size_t rline) -{ - size_t i; - size_t line_idx = 0; - - for (i = 0; i < status->message_len; i++) { - if (rline == line_idx) { - return status->message + i; - } - if (status->message[i] == '\0') { - line_idx++; - } - } - /* The fact that we are here means that end of the message was reached. - * In that case --- return null; - */ - return NULL; } \ No newline at end of file diff --git a/src/device/screen.h b/src/device/screen.h index ec30cd5..7763bd2 100755 --- a/src/device/screen.h +++ b/src/device/screen.h @@ -3,6 +3,10 @@ #include +#define SCREEN_WIDTH (64) +#define FONT_WIDTH (8) +#define SCREEN_MAX_CHARS (SCREEN_WIDTH / FONT_WIDTH) + /** * Struct that keeps track of the lines on the screen. */ @@ -16,7 +20,11 @@ struct display_status { size_t line_cursor; /* Index of the first line being displayed. */ }; +/** + * Displays scrolling text on the screen. + */ void display_update_scroll(struct display_status *status); + void display_status_init(struct display_status *status, char *msg); #endif /* DEVICE_SCREEN_H */ \ No newline at end of file -- cgit v1.2.3 From bf8b16d036e60eec56a42cbfcf012390c143e699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 27 May 2019 23:12:42 +0300 Subject: Screen: implementation of drawing and trivial docs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/device/device_network.h | 0 src/device/screen.c | 64 ----------------------------------------- src/device/screen.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++ src/device/screen.h | 23 +++++++++++++-- 4 files changed, 91 insertions(+), 66 deletions(-) mode change 100755 => 100644 src/device/device_network.h delete mode 100755 src/device/screen.c create mode 100644 src/device/screen.cpp mode change 100755 => 100644 src/device/screen.h (limited to 'src') diff --git a/src/device/device_network.h b/src/device/device_network.h old mode 100755 new mode 100644 diff --git a/src/device/screen.c b/src/device/screen.c deleted file mode 100755 index ac42076..0000000 --- a/src/device/screen.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include "screen.h" - -void draw_lines(struct display_status *status); -void update_lines(struct display_status *status); -void init_msg(char *msg, size_t size); - -void display_status_init(struct display_status *status, char *msg) -{ - status->delta = 2; /* Currently default */ - init_msg(msg, strlen(msg)); - status->message = msg; - status->line_cursor = 0; - status->last_scroll_time = time(NULL); - update_lines(status); -} - -/** - * Turns all whitespace into literal spaces to save screen real-estate. - */ -void init_msg(char *msg, size_t size) -{ - size_t i; - - for (i = 0; i < size; i++) { - switch (msg[i]) { - case '\n': - case '\t': - case '\r': - msg[i] = ' '; - break; - case '\0': - goto end; - default: - break; - } - } -end: - return; -} - -void display_update_scroll(struct display_status *status) -{ - time_t crr_time = time(NULL); - if (status->last_scroll_time - crr_time > status->delta) { - status->last_scroll_time += status->delta; - status->line_cursor++; - update_lines(status); - } - draw_lines(status); -} - -void draw_lines(struct display_status *status) -{ - /* TODO */ -} - -void update_lines(struct display_status *status) -{ - status->first_line = get_line(status, status->line_cursor); - status->second_line = get_line(status, status->line_cursor + 1); -} \ No newline at end of file diff --git a/src/device/screen.cpp b/src/device/screen.cpp new file mode 100644 index 0000000..cfabcc5 --- /dev/null +++ b/src/device/screen.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include "screen.h" + +void draw_lines(struct display_status *status); +void update_lines(struct display_status *status); +void init_msg(char *msg, size_t size); + +void display_status_init(struct display_status *status, char *msg) +{ + status->delta = 2; /* Currently default */ + init_msg(msg, strlen(msg)); + status->message = msg; + status->line_cursor = 0; + status->last_scroll_time = time(NULL); + update_lines(status); +} + +/** + * Turns all whitespace into literal spaces to save screen real-estate and + * possible misinterpretation. + */ +void init_msg(char *msg, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) { + switch (msg[i]) { + case '\n': + case '\t': + case '\r': + msg[i] = ' '; + break; + case '\0': + goto end; + default: + break; + } + } +end: + return; +} + +void display_update_scroll(struct display_status *status) +{ + time_t crr_time = time(NULL); + /* Only scroll lines once a delta, because --- duh! */ + if (status->last_scroll_time - crr_time > status->delta) { + status->last_scroll_time += status->delta; + status->line_cursor++; + update_lines(status); + draw_lines(status); + } +} + +void draw_lines(SSD1306Brzo *screen, struct display_status *status) +{ + screen->clear(); + screen->drawString(0, 0, status->first_line); + screen->drawString(0, SCREEN_HEIGHT / 2, status->second_line); +} + +void update_lines(struct display_status *status) +{ + status->first_line = get_line(status, status->line_cursor); + status->second_line = get_line(status, status->line_cursor + 1); +} \ No newline at end of file diff --git a/src/device/screen.h b/src/device/screen.h old mode 100755 new mode 100644 index 7763bd2..54734e5 --- a/src/device/screen.h +++ b/src/device/screen.h @@ -1,9 +1,17 @@ +/** + * Simple API for scrolling lines. Keeps things simple by not even assuming + * which screen is being drawn on. + */ + #ifndef DEVICE_SCREEN_H #define DEVICE_SCREEN_H #include +#include +#include -#define SCREEN_WIDTH (64) +#define SCREEN_WIDTH (128) +#define SCREEN_HEIGHT (32) #define FONT_WIDTH (8) #define SCREEN_MAX_CHARS (SCREEN_WIDTH / FONT_WIDTH) @@ -11,6 +19,7 @@ * Struct that keeps track of the lines on the screen. */ struct display_status { + SSD1306Brzo *screen; /* Screen to draw on. */ time_t delta; /* Seconds/Line */ time_t last_scroll_time; /* Last second the line was scrolled */ char *message; /* Entire message to be shown */ @@ -25,6 +34,16 @@ struct display_status { */ void display_update_scroll(struct display_status *status); -void display_status_init(struct display_status *status, char *msg); +/** + * Initialises display_status structure so it can be used for + * display_update_scroll. + * + * screen - screen to draw on + * + * status - structure to Initialise + * + * msg - message to scroll on the screen + */ +void display_status_init(SSD1306Brzo *screen, struct display_status *status, char *msg); #endif /* DEVICE_SCREEN_H */ \ No newline at end of file -- cgit v1.2.3 From f267021479ab1f020c7956378d5bf23405ee3e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 20:00:23 +0300 Subject: Screen: adjustments, bug fixes and abstraction. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Line drawing code no longer assumes a particular screen as long as it's interface includes OLEDDisplay. Signed-off-by: Ramūnas Mažeikis --- src/device/screen.cpp | 22 +++++++++++++++++----- src/device/screen.h | 9 +++++---- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/device/screen.cpp b/src/device/screen.cpp index cfabcc5..c923b99 100644 --- a/src/device/screen.cpp +++ b/src/device/screen.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include "screen.h" @@ -9,6 +9,9 @@ void draw_lines(struct display_status *status); void update_lines(struct display_status *status); void init_msg(char *msg, size_t size); +/* Effectively const. For type safety reasons. */ +static char NOTHING[] = {'\0'}; + void display_status_init(struct display_status *status, char *msg) { status->delta = 2; /* Currently default */ @@ -44,7 +47,7 @@ end: return; } -void display_update_scroll(struct display_status *status) +int display_update_scroll(struct display_status *status) { time_t crr_time = time(NULL); /* Only scroll lines once a delta, because --- duh! */ @@ -54,9 +57,14 @@ void display_update_scroll(struct display_status *status) update_lines(status); draw_lines(status); } + if (status->first_line == NOTHING && status->second_line == NOTHING) { + return END_OF_MESSAGE; + } else { + return 0; + } } -void draw_lines(SSD1306Brzo *screen, struct display_status *status) +void draw_lines(OLEDDisplay *screen, struct display_status *status) { screen->clear(); screen->drawString(0, 0, status->first_line); @@ -65,6 +73,10 @@ void draw_lines(SSD1306Brzo *screen, struct display_status *status) void update_lines(struct display_status *status) { - status->first_line = get_line(status, status->line_cursor); - status->second_line = get_line(status, status->line_cursor + 1); + status->first_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len) + ? status->message + status->line_cursor * SCREEN_MAX_CHARS + : NOTHING; + status->second_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len) + ? status->message + (status->line_cursor + 1) * SCREEN_MAX_CHARS + : NOTHING; } \ No newline at end of file diff --git a/src/device/screen.h b/src/device/screen.h index 54734e5..5d0e3b3 100644 --- a/src/device/screen.h +++ b/src/device/screen.h @@ -7,7 +7,7 @@ #define DEVICE_SCREEN_H #include -#include +#include #include #define SCREEN_WIDTH (128) @@ -19,7 +19,7 @@ * Struct that keeps track of the lines on the screen. */ struct display_status { - SSD1306Brzo *screen; /* Screen to draw on. */ + OLEDDisplay *screen; /* Screen to draw on. */ time_t delta; /* Seconds/Line */ time_t last_scroll_time; /* Last second the line was scrolled */ char *message; /* Entire message to be shown */ @@ -32,8 +32,9 @@ struct display_status { /** * Displays scrolling text on the screen. */ -void display_update_scroll(struct display_status *status); +int display_update_scroll(struct display_status *status); +#define END_OF_MESSAGE (1 << 0) /** * Initialises display_status structure so it can be used for * display_update_scroll. @@ -44,6 +45,6 @@ void display_update_scroll(struct display_status *status); * * msg - message to scroll on the screen */ -void display_status_init(SSD1306Brzo *screen, struct display_status *status, char *msg); +void display_status_init(OLEDDisplay *screen, struct display_status *status, char *msg); #endif /* DEVICE_SCREEN_H */ \ No newline at end of file -- cgit v1.2.3 From 9f6e34103aeb44fafdcd8d4878281c783b7c9ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 20:36:14 +0300 Subject: Protocol: new functions and associated docs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header declares new functions: * tlv_init() * tlv_destroy() * tlv_push() * tlv_get_raw() * tlv_raw_size() Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') diff --git a/src/common/protocol.c b/src/common/protocol.c index b2e0d40..edaf491 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -131,3 +131,35 @@ size_t tlv_data_size(struct tlv_parser *parser) } return size; } + +void tlv_destroy(struct tlv *t) +{ + free(t->data); + t->length = 0; +} + +size_t tlv_raw_size(struct tlv *t) +{ + return sizeof(*t) + t->length; +} + +int tlv_push(struct tlv *t, const char *data, size_t size) +{ + int ret = 0; + size_t final_size = tlv_raw_size(t) + size; + if (final_size > TLV_SZ_MAX_RAW) { + ret = E_TLV_OVERFLOW; + } else { + t->data = realloc(t->data, final_size); + memcpy(t->data + t->length, data, size); + t->length = final_size; + } + return ret; +} + +void tlv_init(struct tlv *t) +{ + t->type = TEXT; + t->length = 0; + t->data = NULL; +} \ No newline at end of file -- cgit v1.2.3 From 2b2eb7556424c2b85668f44c49602370bb6014ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 20:58:44 +0300 Subject: Protocol: renamed functions to fit the "namespace". MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/common/protocol.c b/src/common/protocol.c index edaf491..3f7bd24 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -32,7 +32,8 @@ #include "net.h" #include "utils.h" -int push_tlv(struct tlv_packet *packet, enum tlv_type type, char *data) +#if 0 +int tlv_push(struct tlv_packet *packet, enum tlv_type type, char *data) { int ret = 0; size_t size; @@ -64,7 +65,9 @@ int push_tlv(struct tlv_packet *packet, enum tlv_type type, char *data) return ret; } -void clear_data(struct tlv_packet *packet) +#endif + +void tlv_clear_data(struct tlv_packet *packet) { packet->offset = 0; packet->type = 0; @@ -98,7 +101,7 @@ static int push_tlv_header(struct tlv_packet *packet, enum tlv_type type, size_t return ret; } -int get_tlv(struct tlv_parser *parser, struct tlv *ret) +int tlv_get(struct tlv_parser *parser, struct tlv *ret) { int ret = 0; @@ -157,9 +160,9 @@ int tlv_push(struct tlv *t, const char *data, size_t size) return ret; } -void tlv_init(struct tlv *t) +void tlv_init(struct tlv *t, enum tlv_type type) { - t->type = TEXT; + t->type = type; t->length = 0; t->data = NULL; } \ No newline at end of file -- cgit v1.2.3 From 77c5d53360058b85ab1df84961b23f40a78fe3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 21:01:52 +0300 Subject: Protocol: fixed a stupid. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Had a local variable with the same name as argument. Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/common/protocol.c b/src/common/protocol.c index 3f7bd24..ed636d2 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -103,24 +103,24 @@ static int push_tlv_header(struct tlv_packet *packet, enum tlv_type type, size_t int tlv_get(struct tlv_parser *parser, struct tlv *ret) { - int ret = 0; + int retval = 0; if (parser->offset + sizeof(ret->type) + sizeof(ret->length) >= parser->size) { - ret = E_TLV_OVERFLOW; + retval = E_TLV_OVERFLOW; } else if (parser -> offset == parser->size) { - ret = END_OF_PACKET; + retval = END_OF_PACKET; } else { ret->type = memcpy(&ret->type, parser->data + parser->offset, sizeof(ret->type)); parser->size += sizeof(ret->type); ret->length = memcpy(&ret->length, parser->data + parser->offset, sizeof(ret->length)); parser->offset += sizeof(ret->length); if (parser->offset + ret->length >= parser->size) { - ret = E_TLV_OVERFLOW; + retval = E_TLV_OVERFLOW; } else { memcpy(ret->data, parser->data, ret->length); } } - return ret; + return retval; } size_t tlv_data_size(struct tlv_parser *parser) -- cgit v1.2.3 From 078a767c5a878fc5fb7b851a5a4b68590a78bca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 21:05:30 +0300 Subject: Device: accidentally broke code by renaming function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/device/main.ino | 69 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/device/main.ino b/src/device/main.ino index 66e52e8..d83f3e1 100644 --- a/src/device/main.ino +++ b/src/device/main.ino @@ -27,6 +27,9 @@ #include "SSD1306Wire.h" #include "DejaVu_Sans_Mono_13.h" #include "device_network.h" +#include "screen.h" +#include "net.h" +#include "protocol.h" static const unsigned int internal_led = 2; static unsigned int led_state = 0; @@ -36,6 +39,16 @@ static void init_OLED(void); unsigned int toggle_led(const int pin); static int wifi_connect(const char * const ssid, const char * const password, const char doblink, const int ledpin); static void blink_led(const int pin, const int ontime, const int offtime); +void handle_tlv(const struct tlv *data); + +static struct progstate_t { + int ip_print_count = 5; + struct display_status ds = {0}; + struct tlv_parser parser = {0}; + struct tlv crr_data; + size_t bytes_read = 0; + char in_packet_buf[MTU]; +} progstate; void setup(void) { @@ -64,27 +77,55 @@ void loop(void) static String prefix; static IPAddress ip_to_print; static IPAddress *daemon_ip = NULL; - static int print_dev_ip = 0; static unsigned int delta = 2000; /* sleep length to use (ms) */ - /* static int dot_idx = 0; */ delay(delta); - udp_init_packet(com_port); - udp_push(clientmagic, sizeof(clientmagic)); - udp_flush(); + /* Initial display of ip's. */ + if (progstate.ip_print_count > 0) { + udp_init_packet(com_port); + udp_push(clientmagic, sizeof(clientmagic)); + udp_flush(); + + if (!daemon_ip) { + daemon_ip = get_daemon_address(); + } - if (!daemon_ip) { - daemon_ip = get_daemon_address(); + prefix = (progstate.ip_print_count % 2) ? devstr : daemonstr; + ip_to_print = (progstate.ip_print_count) ? WiFi.localIP() : *daemon_ip; + display.clear(); + display.drawString(0, 0, prefix); + display.drawString(0, 16, ip_to_print.toString()); + display.display(); + progstate.ip_print_count--; + } else { /* Dealing with tlv's one at a time. */ + progstate.bytes_read = udp_get_data(progstate.in_packet_buf, sizeof(progstate.in_packet_buf)); + if (progstate.bytes_read > 0) { + progstate.parser.data = progstate.in_packet_buf; + progstate.parser.offset = 0; + progstate.parser.size = progstate.bytes_read; + /* Ignore errors for now. */ + while (tlv_get(&progstate.parser, &progstate.crr_data) == 0) { + handle_tlv(&progstate.crr_data); + } + } + display_update_scroll(&progstate.ds); } +} - prefix = (print_dev_ip) ? devstr : daemonstr; - ip_to_print = (print_dev_ip) ? WiFi.localIP() : *daemon_ip; - display.clear(); - display.drawString(0, 0, prefix); - display.drawString(0, 16, ip_to_print.toString()); - display.display(); - print_dev_ip = !print_dev_ip; +void handle_tlv(const struct tlv *t) +{ + /* Currently just dealing with text. + * */ + switch (t->type) { + case TEXT: + display_status_init(&display, &progstate.ds, (char *)t->data); + break; + default: + display.clear(); + display.drawString(0, 0, "Fugg :DDD"); + break; + } } static void init_OLED(void) -- cgit v1.2.3 From b4855908d867e86de77dbda29a39a625111249ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 21:42:53 +0300 Subject: Screen: very shoddy implementation of message code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/device/device_network.cpp | 14 ++++++++++++-- src/device/device_network.h | 1 + src/device/main.ino | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/device/device_network.cpp b/src/device/device_network.cpp index d7781a0..f2456d9 100644 --- a/src/device/device_network.cpp +++ b/src/device/device_network.cpp @@ -26,7 +26,7 @@ static struct netstate { WiFiUDP udp; - char udppacketbuffer[1500]; + char udppacketbuffer[MTU]; char *udppacketcursor; IPAddress daemon_ip; bool acquired; @@ -59,6 +59,17 @@ int udp_flush(void) return state.udp.endPacket(); } +size_t udp_get_data(char *buf, size_t size) +{ + size_t ret; + if (state.udp.available() != 0) { + ret = state.udp.read(buf, size); + } else { + ret = 0; + } + return ret; +} + void discover_client(const int port) { IPAddress bcastip(255, 255, 255, 255); @@ -100,4 +111,3 @@ static void udp_init_packet_expaddr(IPAddress ip, const int port) memset(state.udppacketbuffer, 0, sizeof(state.udppacketbuffer)); state.udppacketcursor = state.udppacketbuffer; } - diff --git a/src/device/device_network.h b/src/device/device_network.h index d8f41a1..92af429 100644 --- a/src/device/device_network.h +++ b/src/device/device_network.h @@ -31,6 +31,7 @@ void udp_init(const int port); void udp_init_packet(const int port); void udp_push(const void * const data, const size_t size); int udp_flush(void); +size_t udp_get_data(char *buf, size_t size); void discover_client(const int port); IPAddress *get_daemon_address(void); diff --git a/src/device/main.ino b/src/device/main.ino index d83f3e1..8f2c1a6 100644 --- a/src/device/main.ino +++ b/src/device/main.ino @@ -81,7 +81,7 @@ void loop(void) static unsigned int delta = 2000; /* sleep length to use (ms) */ delay(delta); - /* Initial display of ip's. */ + /* Initial display of ip's. */ if (progstate.ip_print_count > 0) { udp_init_packet(com_port); udp_push(clientmagic, sizeof(clientmagic)); -- cgit v1.2.3 From fbecca4da87b47da4d72ea2ec4571d6c9287961d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 12:32:04 +0300 Subject: Protocol: more code and a tutorial. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 91 +++++++++++---------------------------------------- 1 file changed, 20 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/common/protocol.c b/src/common/protocol.c index ed636d2..90dfc92 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -32,75 +32,6 @@ #include "net.h" #include "utils.h" -#if 0 -int tlv_push(struct tlv_packet *packet, enum tlv_type type, char *data) -{ - int ret = 0; - size_t size; - - switch (type) { - case TEXT: - size = strlen(data) + 1; - break; - case FPI1: - size = sizeof(fpi1_t); - break; - case TIMESTAMP: - size = sizeof(time_t); - break; - case REQUEST: - size = sizeof(msg_idx_t); - break; - case REPLY: - size = sizeof(msg_idx_t) + strlen(data + sizeof(msg_idx_t)); - break; - case UUID: - size = sizeof(uuid_t); - break; - default: - ret = E_UNKNOWN_TYPE; - } - ret |= push_tlv_header(packet, type, size); - ret |= push_bytes(packet, data, size); - return ret; -} - -#endif - -void tlv_clear_data(struct tlv_packet *packet) -{ - packet->offset = 0; - packet->type = 0; - memset(packet->data, 0, packet->size); -} - -static int push_bytes(struct tlv_packet *packet, char *data, size_t size) -{ - int ret = 0; - - if (packet->offset + size >= packet->size) { - ret = E_TLV_OVERFLOW; - } else { - memcpy(packet->data + packet->offset, data, size); - packet->offset += size; - } -} - -static int push_tlv_header(struct tlv_packet *packet, enum tlv_type type, size_t size) -{ - int ret = 0; - - if (packet->offset + sizeof(type) + sizeof(size) >= packet->size) { - ret = E_TLV_OVERFLOW; - } else { - memcpy(packet->data + packet->size, type, sizeof(type)); - packet->offset += sizeof(type); - memcpy(packet->data + packet->offset, size, sizeof(size)); - packet->offset += sizeof(size); - } - return ret; -} - int tlv_get(struct tlv_parser *parser, struct tlv *ret) { int retval = 0; @@ -141,12 +72,12 @@ void tlv_destroy(struct tlv *t) t->length = 0; } -size_t tlv_raw_size(struct tlv *t) +size_t tlv_raw_size(const struct tlv *t) { return sizeof(*t) + t->length; } -int tlv_push(struct tlv *t, const char *data, size_t size) +int tlv_push_data(struct tlv *t, const char *data, size_t size) { int ret = 0; size_t final_size = tlv_raw_size(t) + size; @@ -165,4 +96,22 @@ void tlv_init(struct tlv *t, enum tlv_type type) t->type = type; t->length = 0; t->data = NULL; +} + +int tlv_push_tlv(struct tlv *t, const struct tlv *other) +{ + int ret = 0; + size_t other_size; + size_t final_size; + + other_size = tlv_raw_size(other); + final_size = tlv_raw_size(t) + other_size; + if (final_size > TLV_SZ_MAX_RAW) { + ret = E_TLV_OVERFLOW; + } else { + tlv_get_raw(other, t->data + t->length); + t->length = final_size; + } + + return ret; } \ No newline at end of file -- cgit v1.2.3 From 1b9c085c208d92254f146741f8b8c012a600f73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 13:50:07 +0300 Subject: Protocol: new and improved tlv_destroy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/common/protocol.c b/src/common/protocol.c index 90dfc92..0002a96 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -68,8 +68,24 @@ size_t tlv_data_size(struct tlv_parser *parser) void tlv_destroy(struct tlv *t) { - free(t->data); - t->length = 0; + size_t i = 0; + size_t tlv_count; + struct tlv *arr; + switch (t->type) + { + case REGURAL: + case HEARTBEAT: + case DISCOVERY: + tlv_count = t->length / sizeof(struct tlv); + arr = t->data; + for (i = 0; i < tlv_count; i++) { + tlv_destroy(&arr[i]); + } + default: + free(t->data); + t->length = 0; + break; + } } size_t tlv_raw_size(const struct tlv *t) -- cgit v1.2.3 From 743f4857ede9f48def462c1ea2cee8be71356fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 13:53:50 +0300 Subject: Protocol: renamed some files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/protocol.c | 133 ------------------------------------------ src/common/protocol_private.h | 48 --------------- src/common/tlv.c | 133 ++++++++++++++++++++++++++++++++++++++++++ src/common/tlv_private.h | 48 +++++++++++++++ 4 files changed, 181 insertions(+), 181 deletions(-) delete mode 100644 src/common/protocol.c delete mode 100644 src/common/protocol_private.h create mode 100644 src/common/tlv.c create mode 100644 src/common/tlv_private.h (limited to 'src') diff --git a/src/common/protocol.c b/src/common/protocol.c deleted file mode 100644 index 0002a96..0000000 --- a/src/common/protocol.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Usurpataion --- clinet-server protocol implementation. - * - * Copyright (C) 2019 Ramūnas Mažeikis - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; version 2.1 - * of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * Common parts of protocol implementation. Handling of anything that actually - * deals with connection descriptor has to be implemented by device and daemon - * separately. - */ - -#include -#include -#include -#include "protocol.h" -#include "protocol_private.h" -#include "net.h" -#include "utils.h" - -int tlv_get(struct tlv_parser *parser, struct tlv *ret) -{ - int retval = 0; - - if (parser->offset + sizeof(ret->type) + sizeof(ret->length) >= parser->size) { - retval = E_TLV_OVERFLOW; - } else if (parser -> offset == parser->size) { - retval = END_OF_PACKET; - } else { - ret->type = memcpy(&ret->type, parser->data + parser->offset, sizeof(ret->type)); - parser->size += sizeof(ret->type); - ret->length = memcpy(&ret->length, parser->data + parser->offset, sizeof(ret->length)); - parser->offset += sizeof(ret->length); - if (parser->offset + ret->length >= parser->size) { - retval = E_TLV_OVERFLOW; - } else { - memcpy(ret->data, parser->data, ret->length); - } - } - return retval; -} - -size_t tlv_data_size(struct tlv_parser *parser) -{ - size_t size; - - if (parser->offset + sizeof(enum tlv_type) + sizeof(size_t) >= parser->size) { - size = 0; - } else { - memcpy(&size, parser->data + parser->offset + sizeof(enum tlv_type), sizeof(size_t)); - } - return size; -} - -void tlv_destroy(struct tlv *t) -{ - size_t i = 0; - size_t tlv_count; - struct tlv *arr; - switch (t->type) - { - case REGURAL: - case HEARTBEAT: - case DISCOVERY: - tlv_count = t->length / sizeof(struct tlv); - arr = t->data; - for (i = 0; i < tlv_count; i++) { - tlv_destroy(&arr[i]); - } - default: - free(t->data); - t->length = 0; - break; - } -} - -size_t tlv_raw_size(const struct tlv *t) -{ - return sizeof(*t) + t->length; -} - -int tlv_push_data(struct tlv *t, const char *data, size_t size) -{ - int ret = 0; - size_t final_size = tlv_raw_size(t) + size; - if (final_size > TLV_SZ_MAX_RAW) { - ret = E_TLV_OVERFLOW; - } else { - t->data = realloc(t->data, final_size); - memcpy(t->data + t->length, data, size); - t->length = final_size; - } - return ret; -} - -void tlv_init(struct tlv *t, enum tlv_type type) -{ - t->type = type; - t->length = 0; - t->data = NULL; -} - -int tlv_push_tlv(struct tlv *t, const struct tlv *other) -{ - int ret = 0; - size_t other_size; - size_t final_size; - - other_size = tlv_raw_size(other); - final_size = tlv_raw_size(t) + other_size; - if (final_size > TLV_SZ_MAX_RAW) { - ret = E_TLV_OVERFLOW; - } else { - tlv_get_raw(other, t->data + t->length); - t->length = final_size; - } - - return ret; -} \ No newline at end of file diff --git a/src/common/protocol_private.h b/src/common/protocol_private.h deleted file mode 100644 index 51d5431..0000000 --- a/src/common/protocol_private.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Usurpataion --- clinet-server protocol implementation. - * - * Copyright (C) 2019 Ramūnas Mažeikis - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; version 2.1 - * of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * Common parts of protocol implementation. Handling of anything that actually - * deals with connection descriptor has to be implemented by device and daemon - * separately. - */ - -#ifndef PROTOCOL_PRIVATE_H -#define PROTOCOL_PRIVATE_H - -#include "protocol_private.h" - -/** - * Convenience function that pushes bytes to the end of a packet and reports - * potential overflow. - * - * In case of detected overflow nothing is done to the packet. - */ -int push_bytes(struct tlv_packet *packet, char *data, size_t size); - -/** - * Convenience function that forms a tlv header at the end of a packet. Reports - * potential overflow. - * - * In case of detected overflow nothing is done to the packet. - */ -int push_tlv_header(struct tlv_packet *packet, enum tlv_type type, size_t size); - -#endif /* PROTOCOL_PRIVATE_H */ diff --git a/src/common/tlv.c b/src/common/tlv.c new file mode 100644 index 0000000..0002a96 --- /dev/null +++ b/src/common/tlv.c @@ -0,0 +1,133 @@ +/* + * Usurpataion --- clinet-server protocol implementation. + * + * Copyright (C) 2019 Ramūnas Mažeikis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * Common parts of protocol implementation. Handling of anything that actually + * deals with connection descriptor has to be implemented by device and daemon + * separately. + */ + +#include +#include +#include +#include "protocol.h" +#include "protocol_private.h" +#include "net.h" +#include "utils.h" + +int tlv_get(struct tlv_parser *parser, struct tlv *ret) +{ + int retval = 0; + + if (parser->offset + sizeof(ret->type) + sizeof(ret->length) >= parser->size) { + retval = E_TLV_OVERFLOW; + } else if (parser -> offset == parser->size) { + retval = END_OF_PACKET; + } else { + ret->type = memcpy(&ret->type, parser->data + parser->offset, sizeof(ret->type)); + parser->size += sizeof(ret->type); + ret->length = memcpy(&ret->length, parser->data + parser->offset, sizeof(ret->length)); + parser->offset += sizeof(ret->length); + if (parser->offset + ret->length >= parser->size) { + retval = E_TLV_OVERFLOW; + } else { + memcpy(ret->data, parser->data, ret->length); + } + } + return retval; +} + +size_t tlv_data_size(struct tlv_parser *parser) +{ + size_t size; + + if (parser->offset + sizeof(enum tlv_type) + sizeof(size_t) >= parser->size) { + size = 0; + } else { + memcpy(&size, parser->data + parser->offset + sizeof(enum tlv_type), sizeof(size_t)); + } + return size; +} + +void tlv_destroy(struct tlv *t) +{ + size_t i = 0; + size_t tlv_count; + struct tlv *arr; + switch (t->type) + { + case REGURAL: + case HEARTBEAT: + case DISCOVERY: + tlv_count = t->length / sizeof(struct tlv); + arr = t->data; + for (i = 0; i < tlv_count; i++) { + tlv_destroy(&arr[i]); + } + default: + free(t->data); + t->length = 0; + break; + } +} + +size_t tlv_raw_size(const struct tlv *t) +{ + return sizeof(*t) + t->length; +} + +int tlv_push_data(struct tlv *t, const char *data, size_t size) +{ + int ret = 0; + size_t final_size = tlv_raw_size(t) + size; + if (final_size > TLV_SZ_MAX_RAW) { + ret = E_TLV_OVERFLOW; + } else { + t->data = realloc(t->data, final_size); + memcpy(t->data + t->length, data, size); + t->length = final_size; + } + return ret; +} + +void tlv_init(struct tlv *t, enum tlv_type type) +{ + t->type = type; + t->length = 0; + t->data = NULL; +} + +int tlv_push_tlv(struct tlv *t, const struct tlv *other) +{ + int ret = 0; + size_t other_size; + size_t final_size; + + other_size = tlv_raw_size(other); + final_size = tlv_raw_size(t) + other_size; + if (final_size > TLV_SZ_MAX_RAW) { + ret = E_TLV_OVERFLOW; + } else { + tlv_get_raw(other, t->data + t->length); + t->length = final_size; + } + + return ret; +} \ No newline at end of file diff --git a/src/common/tlv_private.h b/src/common/tlv_private.h new file mode 100644 index 0000000..51d5431 --- /dev/null +++ b/src/common/tlv_private.h @@ -0,0 +1,48 @@ +/* + * Usurpataion --- clinet-server protocol implementation. + * + * Copyright (C) 2019 Ramūnas Mažeikis + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * Common parts of protocol implementation. Handling of anything that actually + * deals with connection descriptor has to be implemented by device and daemon + * separately. + */ + +#ifndef PROTOCOL_PRIVATE_H +#define PROTOCOL_PRIVATE_H + +#include "protocol_private.h" + +/** + * Convenience function that pushes bytes to the end of a packet and reports + * potential overflow. + * + * In case of detected overflow nothing is done to the packet. + */ +int push_bytes(struct tlv_packet *packet, char *data, size_t size); + +/** + * Convenience function that forms a tlv header at the end of a packet. Reports + * potential overflow. + * + * In case of detected overflow nothing is done to the packet. + */ +int push_tlv_header(struct tlv_packet *packet, enum tlv_type type, size_t size); + +#endif /* PROTOCOL_PRIVATE_H */ -- cgit v1.2.3 From 755117d64899833a959ed61777be27cb2ba1fa98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 14:00:38 +0300 Subject: Protocol: now renamed things properly and updated build files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/meson.build | 2 ++ src/common/tlv.c | 4 ++-- src/common/tlv_private.h | 48 ------------------------------------------------ src/device/main.ino | 2 +- 4 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 src/common/tlv_private.h (limited to 'src') diff --git a/src/common/meson.build b/src/common/meson.build index b0f0c82..82ebaa7 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -1,4 +1,6 @@ common_filenames = [ + 'tlv_private.h', + 'tlv.c' ] common_sources = files(common_filenames) diff --git a/src/common/tlv.c b/src/common/tlv.c index 0002a96..748d3fb 100644 --- a/src/common/tlv.c +++ b/src/common/tlv.c @@ -27,8 +27,8 @@ #include #include #include -#include "protocol.h" -#include "protocol_private.h" +#include "tlv.h" +#include "tlv_private.h" #include "net.h" #include "utils.h" diff --git a/src/common/tlv_private.h b/src/common/tlv_private.h deleted file mode 100644 index 51d5431..0000000 --- a/src/common/tlv_private.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Usurpataion --- clinet-server protocol implementation. - * - * Copyright (C) 2019 Ramūnas Mažeikis - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; version 2.1 - * of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * Common parts of protocol implementation. Handling of anything that actually - * deals with connection descriptor has to be implemented by device and daemon - * separately. - */ - -#ifndef PROTOCOL_PRIVATE_H -#define PROTOCOL_PRIVATE_H - -#include "protocol_private.h" - -/** - * Convenience function that pushes bytes to the end of a packet and reports - * potential overflow. - * - * In case of detected overflow nothing is done to the packet. - */ -int push_bytes(struct tlv_packet *packet, char *data, size_t size); - -/** - * Convenience function that forms a tlv header at the end of a packet. Reports - * potential overflow. - * - * In case of detected overflow nothing is done to the packet. - */ -int push_tlv_header(struct tlv_packet *packet, enum tlv_type type, size_t size); - -#endif /* PROTOCOL_PRIVATE_H */ diff --git a/src/device/main.ino b/src/device/main.ino index 8f2c1a6..24cfb9c 100644 --- a/src/device/main.ino +++ b/src/device/main.ino @@ -29,7 +29,7 @@ #include "device_network.h" #include "screen.h" #include "net.h" -#include "protocol.h" +#include "tlv.h" static const unsigned int internal_led = 2; static unsigned int led_state = 0; -- cgit v1.2.3 From a23ca7681b3dad7b63fd7b38e05fdfc2e0d75b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 14:17:05 +0300 Subject: Removed tlv_private.h from ./src/common/. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/meson.build | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/common/meson.build b/src/common/meson.build index 82ebaa7..da8b656 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -1,5 +1,4 @@ common_filenames = [ - 'tlv_private.h', 'tlv.c' ] -- cgit v1.2.3 From 227a0e12ee262dbabdd8d988fec194273cf90029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Wed, 29 May 2019 14:33:16 +0300 Subject: Tweaked function declarations and build files to make it build. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/common/tlv.c | 5 ++--- src/device/meson.build | 8 ++++++-- src/device/screen.cpp | 9 +++++---- src/meson.build | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/common/tlv.c b/src/common/tlv.c index 748d3fb..c25f008 100644 --- a/src/common/tlv.c +++ b/src/common/tlv.c @@ -28,7 +28,6 @@ #include #include #include "tlv.h" -#include "tlv_private.h" #include "net.h" #include "utils.h" @@ -41,7 +40,7 @@ int tlv_get(struct tlv_parser *parser, struct tlv *ret) } else if (parser -> offset == parser->size) { retval = END_OF_PACKET; } else { - ret->type = memcpy(&ret->type, parser->data + parser->offset, sizeof(ret->type)); + memcpy(&ret->type, parser->data + parser->offset, sizeof(ret->type)); parser->size += sizeof(ret->type); ret->length = memcpy(&ret->length, parser->data + parser->offset, sizeof(ret->length)); parser->offset += sizeof(ret->length); @@ -130,4 +129,4 @@ int tlv_push_tlv(struct tlv *t, const struct tlv *other) } return ret; -} \ No newline at end of file +} diff --git a/src/device/meson.build b/src/device/meson.build index d2e3c6e..8e4aa90 100644 --- a/src/device/meson.build +++ b/src/device/meson.build @@ -17,10 +17,14 @@ if get_option('fwbuild') cat = find_program('cat') cp = find_program('cp') - fw_filenames = ['main.ino', + fw_filenames = [ + 'main.ino', 'DejaVu_Sans_Mono_13.h', 'device_network.cpp', - 'device_network.h'] + 'device_network.h', + 'screen.cpp', + 'screen.h' + ] fw_true_sources += files(fw_filenames) fw_filenames += oledlibnames fw_true_sources += oledlib diff --git a/src/device/screen.cpp b/src/device/screen.cpp index c923b99..2857161 100644 --- a/src/device/screen.cpp +++ b/src/device/screen.cpp @@ -5,16 +5,17 @@ #include #include "screen.h" -void draw_lines(struct display_status *status); +void draw_lines(OLEDDisplay *screen, struct display_status *status); void update_lines(struct display_status *status); void init_msg(char *msg, size_t size); /* Effectively const. For type safety reasons. */ static char NOTHING[] = {'\0'}; -void display_status_init(struct display_status *status, char *msg) +void display_status_init(OLEDDisplay *screen, struct display_status *status, char *msg) { status->delta = 2; /* Currently default */ + status->screen = screen; init_msg(msg, strlen(msg)); status->message = msg; status->line_cursor = 0; @@ -55,7 +56,7 @@ int display_update_scroll(struct display_status *status) status->last_scroll_time += status->delta; status->line_cursor++; update_lines(status); - draw_lines(status); + draw_lines(status->screen, status); } if (status->first_line == NOTHING && status->second_line == NOTHING) { return END_OF_MESSAGE; @@ -79,4 +80,4 @@ void update_lines(struct display_status *status) status->second_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len) ? status->message + (status->line_cursor + 1) * SCREEN_MAX_CHARS : NOTHING; -} \ No newline at end of file +} diff --git a/src/meson.build b/src/meson.build index 12b583a..38a1f57 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,6 +1,6 @@ -#subdir('common') +subdir('common') -fw_true_sources = [fw_headers] +fw_true_sources = [fw_headers, common_sources] subdir('daemon') subdir('device') -- cgit v1.2.3