diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7c45674..dc49ebc 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,17 @@ "problemMatcher": [], "group": { "kind": "build", - "isDefault": true + "isDefault": false + } + }, + { + "type": "shell", + "command": "cd build; cmake ../ -DLOG=1; make Flash", + "label": "Flash with LOG=1", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": false } }, { diff --git a/CMakeLists.txt b/CMakeLists.txt index b55ba65..539e3dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ target_sources(host_cdc_msc_hid PUBLIC cdc_app.c diskio_USB.c diskio_SDIO.c + log_usb.c lib/FatFs/source/ff.c lib/FatFs/source/ffsystem.c lib/FatFs/source/diskio.c @@ -75,3 +76,5 @@ add_custom_target(Flash DEPENDS host_cdc_msc_hid COMMAND sudo picotool load -f ${PROJECT_BINARY_DIR}/host_cdc_msc_hid.uf2 ) + +add_definitions(-DPICO_STDIO_ENABLE_CRLF_SUPPORT=0) diff --git a/cdc_app.c b/cdc_app.c index 4a13f8b..fac6649 100644 --- a/cdc_app.c +++ b/cdc_app.c @@ -26,6 +26,10 @@ #include "tusb.h" #include "bsp/board_api.h" +#include "log_usb.h" +#include + +volatile bool in_transfert_cb = 0; size_t get_console_inputs(uint8_t* buf, size_t bufsize) { size_t count = 0; @@ -65,14 +69,38 @@ void cdc_app_task(void) { // Invoked when received new data void tuh_cdc_rx_cb(uint8_t idx) { + if(in_transfert_cb){ + printf("already processing data\n"); + return; + } + + absolute_time_t current_time_us, start_time_us; + + start_time_us = get_absolute_time(); + + in_transfert_cb = 1; uint8_t buf[64 + 1]; // +1 for extra null character + char chaine[1024]; uint32_t const bufsize = sizeof(buf) - 1; // forward cdc interfaces -> console uint32_t count = tuh_cdc_read(idx, buf, bufsize); buf[count] = 0; - printf("%s", (char*) buf); + log_analyse_input_string(buf, count); + log_get(chaine); + + + + current_time_us = get_absolute_time(); + if(strlen(chaine)> 0){ + printf("%s", chaine); + printf(">temp_rec:%d\n", current_time_us); + chaine[0] = '\0'; + } + + + in_transfert_cb = 0; } // Invoked when a device with CDC interface is mounted diff --git a/log_usb.c b/log_usb.c new file mode 100644 index 0000000..4ce009d --- /dev/null +++ b/log_usb.c @@ -0,0 +1,37 @@ +#include + +char tampon[1020]; +char log_dispo[1020]={'\0'}; +unsigned int index_tampon=0; + +void log_analyse_input_string(const char * input_data, unsigned int str_len){ + // On charge les données dans le tampon + // Si on a un message complet, on charge dans log dispo (s'il y a la place) + static int copy = 0; + for(int i=0; i< str_len; i++){ + if(input_data[i] == '>'){ + copy = 1; + } + if(copy == 1){ + tampon[index_tampon] = input_data[i]; + index_tampon++; + + + if(input_data[i] == '\n'){ + copy = 0; + tampon[index_tampon] = '\0'; + strcat(log_dispo, tampon); + index_tampon=0; + } + } + + } +} + +// On renvoi la chaine et on remet log_dispo à 0; +void log_get(char * chaine){ + strcpy(chaine, log_dispo); + log_dispo[0] = '\0'; +} + + diff --git a/log_usb.h b/log_usb.h new file mode 100644 index 0000000..ccdc512 --- /dev/null +++ b/log_usb.h @@ -0,0 +1,2 @@ +void log_analyse_input_string(char * input_data, unsigned int str_len); +void log_get(char * chaine); \ No newline at end of file diff --git a/main.c b/main.c index f72623d..61bfa2d 100644 --- a/main.c +++ b/main.c @@ -161,8 +161,8 @@ int main(void) { led_blinking_task(); cdc_app_task(); hid_app_task(); - log_to_sd(big_big_buffer); - log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB) + //log_to_sd(big_big_buffer); + //log_to_usb(big_big_buffer); // à commenter pour obtenir un test juste sur la carte SD.(ou simplement ne pas brancher de clé USB) } }