Reception de deux CDC
This commit is contained in:
parent
30d00993a0
commit
57f6bf657d
32
cdc_app.c
32
cdc_app.c
@ -61,6 +61,16 @@ void cdc_app_task(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint8_t idx = 0; idx < CFG_TUH_CDC; idx++) {
|
||||
if (tuh_cdc_mounted(idx)) {
|
||||
char chaine[1024];
|
||||
log_get(idx, chaine);
|
||||
if(strlen(chaine)> 0){
|
||||
printf("%s", chaine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -73,33 +83,16 @@ void tuh_cdc_rx_cb(uint8_t idx) {
|
||||
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;
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
|
||||
log_analyse_input_string(idx, buf, count);
|
||||
in_transfert_cb = 0;
|
||||
}
|
||||
|
||||
@ -111,6 +104,7 @@ void tuh_cdc_mount_cb(uint8_t idx) {
|
||||
|
||||
printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr,
|
||||
itf_info.desc.bInterfaceNumber);
|
||||
log_create(idx);
|
||||
|
||||
#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
|
||||
// If CFG_TUH_CDC_LINE_CODING_ON_ENUM is defined, line coding will be set by tinyusb stack
|
||||
@ -134,4 +128,6 @@ void tuh_cdc_umount_cb(uint8_t idx) {
|
||||
|
||||
printf("CDC Interface is unmounted: address = %u, itf_num = %u\r\n", itf_info.daddr,
|
||||
itf_info.desc.bInterfaceNumber);
|
||||
|
||||
log_destroy(idx);
|
||||
}
|
||||
|
||||
90
log_usb.c
90
log_usb.c
@ -1,27 +1,76 @@
|
||||
#include <string.h>
|
||||
#include "pico/platform/panic.h"
|
||||
|
||||
char tampon[1020];
|
||||
char log_dispo[1020]={'\0'};
|
||||
unsigned int index_tampon=0;
|
||||
#define NB_MAX_CDC_CONNEXION 10
|
||||
#define INVALID_ID ((char)-1)
|
||||
|
||||
void log_analyse_input_string(const char * input_data, unsigned int str_len){
|
||||
struct log_buffer_t{
|
||||
char idx;
|
||||
char copy_active;
|
||||
char tampon[1020];
|
||||
char log_dispo[1020];
|
||||
unsigned int index_tampon;
|
||||
}log_buffer[10];
|
||||
|
||||
static struct log_buffer_t * get_buffer(const char idx);
|
||||
|
||||
static struct log_buffer_t * get_buffer(const char idx){
|
||||
for (int i=0; i<NB_MAX_CDC_CONNEXION; i++){
|
||||
if(log_buffer[i].idx == idx){
|
||||
return &(log_buffer[i]);
|
||||
}
|
||||
}
|
||||
/// TODO: panic ?
|
||||
panic("Buffer IDX not found: %d\n", idx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/// @brief Initialisation des structure de reception des données USB-CDC
|
||||
void log_init(){
|
||||
for (int i=0; i<NB_MAX_CDC_CONNEXION; i++){
|
||||
log_buffer[i].log_dispo[0] = '\0';
|
||||
log_buffer[i].index_tampon = 0;
|
||||
log_buffer[i].copy_active = 0;
|
||||
log_buffer[i].idx = INVALID_ID;
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Affectation des tampons de reception à une liaison USB-CDC
|
||||
/// @param idx :
|
||||
void log_create(const char idx){
|
||||
for (int i=0; i<NB_MAX_CDC_CONNEXION; i++){
|
||||
if(log_buffer[i].idx == INVALID_ID){
|
||||
log_buffer[i].idx = idx;
|
||||
return;
|
||||
}
|
||||
}
|
||||
panic("Creation impossible: idx: %d\n", idx);
|
||||
}
|
||||
|
||||
void log_destroy(const char idx){
|
||||
struct log_buffer_t * p_log_bufffer;
|
||||
p_log_bufffer = get_buffer(idx);
|
||||
p_log_bufffer->idx = INVALID_ID;
|
||||
}
|
||||
|
||||
void log_analyse_input_string(const char idx, 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;
|
||||
struct log_buffer_t * p_log_bufffer;
|
||||
p_log_bufffer = get_buffer(idx);
|
||||
for(int i=0; i< str_len; i++){
|
||||
if(input_data[i] == '>'){
|
||||
copy = 1;
|
||||
p_log_bufffer->copy_active = 1;
|
||||
}
|
||||
if(copy == 1){
|
||||
tampon[index_tampon] = input_data[i];
|
||||
index_tampon++;
|
||||
|
||||
if(p_log_bufffer->copy_active == 1){
|
||||
p_log_bufffer->tampon[p_log_bufffer->index_tampon] = input_data[i];
|
||||
p_log_bufffer->index_tampon++;
|
||||
|
||||
if(input_data[i] == '\n'){
|
||||
copy = 0;
|
||||
tampon[index_tampon] = '\0';
|
||||
strcat(log_dispo, tampon);
|
||||
index_tampon=0;
|
||||
p_log_bufffer->copy_active = 0;
|
||||
p_log_bufffer->tampon[p_log_bufffer->index_tampon] = '\0';
|
||||
strcat(p_log_bufffer->log_dispo, p_log_bufffer->tampon);
|
||||
p_log_bufffer->index_tampon=0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,9 +78,16 @@ void log_analyse_input_string(const char * input_data, unsigned int str_len){
|
||||
}
|
||||
|
||||
// On renvoi la chaine et on remet log_dispo à 0;
|
||||
void log_get(char * chaine){
|
||||
strcpy(chaine, log_dispo);
|
||||
log_dispo[0] = '\0';
|
||||
void log_get(const char idx, char * chaine){
|
||||
struct log_buffer_t * p_log_bufffer;
|
||||
p_log_bufffer = get_buffer(idx);
|
||||
if(p_log_bufffer == NULL){
|
||||
chaine[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(chaine, p_log_bufffer->log_dispo);
|
||||
p_log_bufffer->log_dispo[0] = '\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,2 +1,6 @@
|
||||
void log_analyse_input_string(char * input_data, unsigned int str_len);
|
||||
void log_get(char * chaine);
|
||||
|
||||
void log_init(void);
|
||||
void log_create(const char idx);
|
||||
void log_destroy(const char idx);
|
||||
void log_analyse_input_string(const char idx, char * input_data, unsigned int str_len);
|
||||
void log_get(const char idx, char * chaine);
|
||||
3
main.c
3
main.c
@ -32,6 +32,7 @@
|
||||
#include "tusb.h"
|
||||
#include "ff.h"
|
||||
#include "f_util.h"
|
||||
#include "log_usb.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
@ -109,6 +110,8 @@ int main(void) {
|
||||
printf("TinyUSB Host CDC MSC HID Example - test comparatif\r\n");
|
||||
|
||||
// init host stack on configured roothub port
|
||||
// à mettre avant tuh_init
|
||||
log_init();
|
||||
tuh_init(BOARD_TUH_RHPORT);
|
||||
|
||||
if (board_init_after_tusb) {
|
||||
|
||||
@ -102,7 +102,7 @@
|
||||
#define CFG_TUH_ENUMERATION_BUFSIZE 256
|
||||
|
||||
#define CFG_TUH_HUB 1 // number of supported hubs
|
||||
#define CFG_TUH_CDC 1 // CDC ACM
|
||||
#define CFG_TUH_CDC 3 // CDC ACM
|
||||
#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
|
||||
#define CFG_TUH_CDC_CH34X 1 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
|
||||
|
||||
Loading…
Reference in New Issue
Block a user