aboutsummaryrefslogtreecommitdiffstats
path: root/src/simulator
diff options
context:
space:
mode:
authorMaximilien Cuony <maximilien@theglu.org>2016-06-02 22:00:22 +0200
committerMaximilien Cuony <maximilien@theglu.org>2016-06-02 22:00:22 +0200
commitbbe4080e94308149b74dd9ccefddf95878eec5d0 (patch)
treedb97785a48ff7267e263b9a55bed27b354e65925 /src/simulator
parent9069fc127e4f73041fbd1f66e4506fcf12418315 (diff)
downloadglutte-o-matic-bbe4080e94308149b74dd9ccefddf95878eec5d0.tar.gz
glutte-o-matic-bbe4080e94308149b74dd9ccefddf95878eec5d0.tar.bz2
glutte-o-matic-bbe4080e94308149b74dd9ccefddf95878eec5d0.zip
Simulator: UART, Leds, begining of GPS
Diffstat (limited to 'src/simulator')
-rw-r--r--src/simulator/Makefile2
-rw-r--r--src/simulator/src/Core/main.c19
-rw-r--r--src/simulator/src/Core/usart.c190
-rw-r--r--src/simulator/src/GPIO/leds.c44
-rw-r--r--src/simulator/src/GPIO/usart.c97
-rw-r--r--src/simulator/src/GPS/gps.c11
-rw-r--r--src/simulator/src/GPS/minema.c1
-rw-r--r--src/simulator/src/Gui/gui.c (renamed from src/simulator/src/Gui/test.c)163
-rw-r--r--src/simulator/vc.h2
9 files changed, 311 insertions, 218 deletions
diff --git a/src/simulator/Makefile b/src/simulator/Makefile
index 4e74498..511b6e6 100644
--- a/src/simulator/Makefile
+++ b/src/simulator/Makefile
@@ -16,6 +16,8 @@ VPATH += $(SRCROOT)/Source
VPATH += $(SRCROOT)/Source/portable/MemMang
VPATH += $(SRCROOT)/Source/portable/GCC/POSIX
VPATH += $(SRCROOT)/src/Core
+VPATH += $(SRCROOT)/src/GPIO
+VPATH += $(SRCROOT)/src/GPS
# FreeRTOS Objects
C_FILES += croutine.c
diff --git a/src/simulator/src/Core/main.c b/src/simulator/src/Core/main.c
index 7e93176..a326dbf 100644
--- a/src/simulator/src/Core/main.c
+++ b/src/simulator/src/Core/main.c
@@ -27,11 +27,22 @@
#include <pthread.h>
-void *threadFunc(void *arg) {
- main2();
+static void thread_gui(void *arg) {
+ main_gui();
}
void init() {
- pthread_t pth;
- pthread_create(&pth, NULL, threadFunc, "processing...");
+
+ /* pthread_t pth; */
+ /* pthread_create(&pth, NULL, thread_gui, "processing..."); */
+
+ TaskHandle_t task_handle;
+ xTaskCreate(
+ thread_gui,
+ "Thread GUI",
+ configMINIMAL_STACK_SIZE,
+ (void*) NULL,
+ tskIDLE_PRIORITY + 2UL,
+ &task_handle);
+
}
diff --git a/src/simulator/src/Core/usart.c b/src/simulator/src/Core/usart.c
deleted file mode 100644
index bd91428..0000000
--- a/src/simulator/src/Core/usart.c
+++ /dev/null
@@ -1,190 +0,0 @@
-
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2016 Matthias P. Braendli
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
-*/
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <inttypes.h>
-#include "Core/common.h"
-#include "Core/usart.h"
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-
-// The ISR writes into this buffer
-static char nmea_sentence[MAX_NMEA_SENTENCE_LEN];
-static int nmea_sentence_last_written = 0;
-
-// Once a completed NMEA sentence is received in the ISR,
-// it is appended to this queue
-static QueueHandle_t usart_nmea_queue;
-
-#define USART_TypeDef void
-
-int _USART2 = 2;
-int _USART3 = 3;
-
-#define USART2 &_USART2
-#define USART3 &_USART3
-
-void usart_init() {
-}
-
-void usart_gps_init() {
- usart_nmea_queue = xQueueCreate(15, MAX_NMEA_SENTENCE_LEN);
- if (usart_nmea_queue == 0) {
- while(1); /* fatal error */
- }
-
-}
-
-// Make sure Tasks are suspended when this is called!
-static void usart_puts(USART_TypeDef* USART, const char* str)
-{
- while(*str) {
- // TODO
- putchar(*str);
- str++;
- }
-}
-
-void usart_gps_puts(const char* str)
-{
- vTaskSuspendAll();
- return usart_puts(USART3, str);
- xTaskResumeAll();
-}
-
-#define MAX_MSG_LEN 80
-static char usart_debug_message[MAX_MSG_LEN];
-
-void usart_debug_timestamp() {
- // Don't call printf here, to reduce stack usage
- uint64_t now = timestamp_now();
- if (now == 0) {
- usart_puts(USART2, "[0] ");
- }
- else {
- char ts_str[64];
- int i = 63;
-
- ts_str[i--] = '\0';
- ts_str[i--] = ' ';
- ts_str[i--] = ']';
-
- while (now > 0 && i >= 0) {
- ts_str[i--] = '0' + (now % 10);
- now /= 10;
- }
- ts_str[i] = '[';
-
- usart_puts(USART2, &ts_str[i]);
- }
-}
-
-void usart_debug(const char *format, ...)
-{
- va_list list;
- va_start(list, format);
- vsnprintf(usart_debug_message, MAX_MSG_LEN-1, format, list);
-
- vTaskSuspendAll();
- usart_debug_timestamp();
- usart_puts(USART2, usart_debug_message);
- xTaskResumeAll();
-
- va_end(list);
-}
-
-void usart_debug_puts(const char* str)
-{
- vTaskSuspendAll();
- usart_debug_timestamp();
- usart_puts(USART2, str);
- xTaskResumeAll();
-}
-
-int usart_get_nmea_sentence(char* nmea)
-{
- return xQueueReceive(usart_nmea_queue, nmea, portMAX_DELAY);
-}
-
-
-static void usart_clear_nmea_buffer(void)
-{
- for (int i = 0; i < MAX_NMEA_SENTENCE_LEN; i++) {
- nmea_sentence[i] = '\0';
- }
- nmea_sentence_last_written = 0;
-}
-
-/* void USART3_IRQHandler(void) */
-/* { */
-/* if (USART_GetITStatus(USART3, USART_IT_RXNE)) { */
-/* char t = USART3->DR; */
-/* */
-/* if (nmea_sentence_last_written == 0) { */
-/* if (t == '$') { */
-/* // Likely new start of sentence */
-/* nmea_sentence[nmea_sentence_last_written] = t; */
-/* nmea_sentence_last_written++; */
-/* } */
-/* } */
-/* else if (nmea_sentence_last_written < MAX_NMEA_SENTENCE_LEN) { */
-/* nmea_sentence[nmea_sentence_last_written] = t; */
-/* nmea_sentence_last_written++; */
-/* */
-/* if (t == '\n') { */
-/* int success = xQueueSendToBackFromISR( */
-/* usart_nmea_queue, */
-/* nmea_sentence, */
-/* NULL); */
-/* */
-/* if (success == pdFALSE) { */
-/* trigger_fault(FAULT_SOURCE_USART); */
-/* } */
-/* */
-/* usart_clear_nmea_buffer(); */
-/* } */
-/* } */
-/* else { */
-/* // Buffer overrun without a meaningful NMEA message. */
-/* usart_clear_nmea_buffer(); */
-/* } */
-/* } */
-/* } */
-/* */
-/* void USART2_IRQHandler(void) */
-/* { */
-/* if (USART_GetITStatus(USART2, USART_IT_RXNE)) { */
-/* char t = USART2->DR; */
-/* if (t == 'h') { */
-/* usart_debug_puts("help: no commands supported yet!\r\n"); */
-/* } */
-/* else { */
-/* usart_debug("Unknown command %c\r\n", t); */
-/* } */
-/* } */
-/* } */
diff --git a/src/simulator/src/GPIO/leds.c b/src/simulator/src/GPIO/leds.c
new file mode 100644
index 0000000..874cc19
--- /dev/null
+++ b/src/simulator/src/GPIO/leds.c
@@ -0,0 +1,44 @@
+#include "../../../common/src/GPIO/leds.c"
+
+
+extern char led_blue;
+extern char led_green;
+extern char led_orange;
+extern char led_red;
+
+void leds_turn_on(int l) {
+
+ switch (l) {
+ case LED_GREEN:
+ led_green = 1;
+ break;
+ case LED_ORANGE:
+ led_orange = 1;
+ break;
+ case LED_RED:
+ led_red = 1;
+ break;
+ case LED_BLUE:
+ led_blue = 1;
+ break;
+
+ }
+}
+
+void leds_turn_off(int l) {
+
+ switch (l) {
+ case LED_GREEN:
+ led_green = 0;
+ break;
+ case LED_ORANGE:
+ led_orange = 0;
+ break;
+ case LED_RED:
+ led_red = 0;
+ break;
+ case LED_BLUE:
+ led_blue = 0;
+ break;
+ }
+}
diff --git a/src/simulator/src/GPIO/usart.c b/src/simulator/src/GPIO/usart.c
new file mode 100644
index 0000000..650602a
--- /dev/null
+++ b/src/simulator/src/GPIO/usart.c
@@ -0,0 +1,97 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Maximilien Cuony
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+*/
+
+
+#define USART_TypeDef int
+
+int _USART2 = 2;
+int _USART3 = 3;
+
+#define USART2 &_USART2
+#define USART3 &_USART3
+
+static void usart_puts(USART_TypeDef*, const char*);
+
+#include "../../../common/includes/GPIO/usart.h"
+#include "../../../common/src/GPIO/usart.c"
+
+
+extern char uart_recv_txt[4096];
+int uart_recv_pointer = 0;
+
+
+void usart_move_buffer_up();
+
+
+void usart_init() {
+
+ // Zero buffer
+ for (int i = 0; i < 4096; i++) {
+ uart_recv_txt[i] = '\0';
+ }
+
+}
+
+void usart_gps_specific_init() {
+}
+
+void usart_move_buffer_up() {
+
+ for (int i = 0; i <= 4010; i++) {
+ uart_recv_txt[i] = uart_recv_txt[i + 10];
+ uart_recv_txt[i + 1] = '\0';
+ }
+
+ uart_recv_pointer -= 10;
+
+}
+
+// Make sure Tasks are suspended when this is called!
+static void usart_puts(USART_TypeDef* USART, const char* str) {
+
+ if (*USART == _USART2) {
+ while(*str) {
+ if (*str != '\r') {
+ uart_recv_txt[uart_recv_pointer+1] = '\0';
+ uart_recv_txt[uart_recv_pointer] = *str;
+ uart_recv_pointer++;
+
+ if (uart_recv_pointer >= 4000) {
+ usart_move_buffer_up();
+ }
+ }
+ str++;
+ }
+ }
+}
+
+void gui_usart_send(char * string) {
+
+ while(*string) {
+ usart_process_char(*string);
+
+ string++;
+ }
+
+}
diff --git a/src/simulator/src/GPS/gps.c b/src/simulator/src/GPS/gps.c
new file mode 100644
index 0000000..0ca20f3
--- /dev/null
+++ b/src/simulator/src/GPS/gps.c
@@ -0,0 +1,11 @@
+#include "../../../common/src/GPS/gps.c"
+
+void gps_usart_send(char * string) {
+
+ while(*string) {
+ usart_gps_process_char(*string);
+
+ string++;
+ }
+
+}
diff --git a/src/simulator/src/GPS/minema.c b/src/simulator/src/GPS/minema.c
new file mode 100644
index 0000000..10df198
--- /dev/null
+++ b/src/simulator/src/GPS/minema.c
@@ -0,0 +1 @@
+#include "../../../common/src/GPS/minmea.c"
diff --git a/src/simulator/src/Gui/test.c b/src/simulator/src/Gui/gui.c
index f742fe8..81c80b6 100644
--- a/src/simulator/src/Gui/test.c
+++ b/src/simulator/src/Gui/gui.c
@@ -1,3 +1,7 @@
+#include "FreeRTOS.h"
+#include "FreeRTOSConfig.h"
+#include "task.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -33,6 +37,22 @@
#define LEN(a) (sizeof(a)/sizeof(a)[0])
+/**
+ * USART
+ **/
+char uart_recv_txt[4096];
+static char uart_send_txt[512];
+static int uart_send_txt_len;
+void gui_usart_send(char*);
+
+/**
+ * Leds
+ **/
+char led_blue = 0;
+char led_green = 0;
+char led_orange = 0;
+char led_red = 0;
+
struct XWindow {
Display *dpy;
Window win;
@@ -81,7 +101,8 @@ static int has_extension(const char *string, const char *ext) {
return FALSE;
}
-int main2() {
+
+int main_gui() {
/* Platform */
int running = 1;
struct XWindow win;
@@ -132,7 +153,9 @@ int main2() {
{
/* pick framebuffer with most samples per pixel */
int i;
- int fb_best = -1, best_num_samples = -1;
+ int fb_best = -1;
+ int best_num_samples = -1;
+
for (i = 0; i < fb_count; ++i) {
XVisualInfo *vi = glXGetVisualFromFBConfig(win.dpy, fbc[i]);
if (vi) {
@@ -217,11 +240,12 @@ int main2() {
background = nk_rgb(28,48,62);
- static char box_buffer[512];
- static int box_len;
-
while (running)
{
+ taskYIELD();
+
+ vTaskSuspendAll();
+
/* Input */
XEvent evt;
nk_input_begin(ctx);
@@ -232,33 +256,124 @@ int main2() {
nk_input_end(ctx);
/* GUI */
- {struct nk_panel layout;
- if (nk_begin(ctx, &layout, "UART", nk_rect(50, 50, 400, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
+ {
+
+ struct nk_panel layout;
+
+ if (nk_begin(ctx, &layout, "UART", nk_rect(50, 50, 400, 300), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
+
+
+ nk_menubar_begin(ctx);
+ nk_layout_row_begin(ctx, NK_STATIC, 25, 2);
+ nk_layout_row_push(ctx, 280);
+
+ int active = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, uart_send_txt, &uart_send_txt_len, 512, nk_filter_default);
+
+ nk_layout_row_push(ctx, 70);
+ if (nk_button_label(ctx, "Send", NK_BUTTON_DEFAULT) || (active & NK_EDIT_COMMITED)) {
+
+ uart_send_txt[uart_send_txt_len] = '\0';
+
+ gui_usart_send(uart_send_txt);
+
+ uart_send_txt[0] = '\0';
+ uart_send_txt_len = 0;
+ }
+
+ nk_menubar_end(ctx);
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, "UART Output:", NK_TEXT_LEFT);
- nk_layout_row_dynamic(ctx, 75, 1);
- nk_edit_string(ctx, NK_EDIT_BOX, box_buffer, &box_len, 512, nk_filter_default);
+ nk_layout_row_dynamic(ctx, 16, 1);
+
+ char * current_pointer = uart_recv_txt;
+ int l = 0;
- /* #<{(| nk_layout_row(ctx, NK_STATIC, 25, 2, ratio); |)}># */
- /* active = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, text[7], &text_len[7], 64, nk_filter_ascii); */
- /* if (nk_button_label(ctx, "Submit", NK_BUTTON_DEFAULT) || */
- /* (active & NK_EDIT_COMMITED)) */
- /* { */
- /* text[7][text_len[7]] = '\n'; */
- /* text_len[7]++; */
- /* memcpy(&box_buffer[box_len], &text[7], (nk_size)text_len[7]); */
- /* box_len += text_len[7]; */
- /* text_len[7] = 0; */
- /* } */
- nk_layout_row_end(ctx);
+ while (*current_pointer != 0) {
- /* nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); */
+ if (*current_pointer == '\n') {
+ if (l > 1) {
+ nk_text(ctx, current_pointer - l, l, NK_TEXT_LEFT);
+ }
+ current_pointer++;
+ l = 0;
+ }
+ current_pointer++;
+ l++;
+ }
+
+ if (l > 1) {
+ nk_text(ctx, current_pointer - l, l, NK_TEXT_LEFT);
+ }
+
+ /* nk_layout_row_end(ctx); */
+
+ nk_end(ctx);
}
- nk_end(ctx);}
+
+
+ if (nk_begin(ctx, &layout, "LEDs", nk_rect(460, 50, 100, 155), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
+
+ nk_layout_row_static(ctx, 20, 20, 3);
+
+ struct nk_color color;
+
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ color.r = 255; color.g = 0; color.b = 0;
+
+ if (led_red == 1) {
+ color.a = 255;
+ } else {
+ color.a = 30;
+ }
+ nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ color.r = 0; color.g = 255; color.b = 0;
+
+ if (led_green == 1) {
+ color.a = 255;
+ } else {
+ color.a = 30;
+ }
+ nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ color.r = 255; color.g = 165; color.b = 0;
+
+ if (led_orange == 1) {
+ color.a = 255;
+ } else {
+ color.a = 30;
+ }
+ nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ color.r = 0; color.g = 0; color.b = 255;
+
+ if (led_blue == 1) {
+ color.a = 255;
+ } else {
+ color.a = 30;
+ }
+ nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ nk_end(ctx);
+
+ }
+
+
+ }
/* if (nk_window_is_closed(ctx, "Demo")) break; */
{
@@ -271,6 +386,8 @@ int main2() {
nk_x11_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
glXSwapBuffers(win.dpy, win.win);
}
+
+ xTaskResumeAll();
}
nk_x11_shutdown();
diff --git a/src/simulator/vc.h b/src/simulator/vc.h
index d8d7797..fa3f184 100644
--- a/src/simulator/vc.h
+++ b/src/simulator/vc.h
@@ -1,4 +1,4 @@
// This file is generated by Makefile.
// Do not edit this file!
-#define GIT_VERSION "4803231"
+#define GIT_VERSION "9069fc1"