For example my transmitter send stream of 28bytes at 1kHZ, rarely its not capable to transmitt so its buffered with FIFO and then there is sequence of 250,250,32,28,28 bytes, in this case my receiver receive only 250,28,28 seqence so there are 2 missing pockets. Also its begin missing only when "Serial.write(data,len);" is active. Im wonder how even OnDataRecv might be missing as it is called from higher prio task than my SerialNow_USB_passthru.
Code: Select all
// transmitter
xTaskCreatePinnedToCore(SerialNowTaskTX,"SerialNowTaskTX",XT_STACK_MIN_SIZE*3,NULL,4,&taskHandleTX,0);
static void OnDataSent(const uint8_t *MAC, esp_now_send_status_t status) {
if(status==ESP_NOW_SEND_FAIL){
Serial.printf("something went wrong on sending data\n");
}
xSemaphoreGive(esp_now_send_mutex);
}
static void SerialNowTaskTX(void *p){
uint8_t dataToSend[ESP_NOW_MAX_DATA_LEN];
size_t dataMaxLen = sizeof(dataToSend);
while(1){
size_t len = bufTX.available();
if( len>=dataMaxLen ){
len = len>dataMaxLen ? dataMaxLen : len;
bufTX.pop(dataToSend,len);
xSemaphoreTake(esp_now_send_mutex,portMAX_DELAY);
esp_err_t result = esp_now_send(NULL, dataToSend, len);
} else {
delay(1);
}
}
vTaskDelete(NULL);
}
Code: Select all
// receiver
static IRAM_ATTR int OnDataRecv(const uint8_t *MAC, const uint8_t *incomingData, int len) {
for(int i=0;i<4;i++){
if(compareMAC(MAC,myDev[i].mac)){
client[i].fifo.push(incomingData,len);
xTaskNotifyGive( SerialNow_USB_passthru_task );
}
}
}
Code: Select all
// retransmission
xTaskCreatePinnedToCore(SerialNow_USB_passthru,"SerialNow_USB_passthru",4096,NULL,3,&SerialNow_USB_passthru_task,0);
void IRAM_ATTR SerialNow_USB_passthru(void *p){
const size_t dataLen = 4096;
static uint8_t data[dataLen];
while(1){
size_t len;
ulTaskNotifyTake(pdTRUE,pdMS_TO_TICKS(1));
for(int i=0;i<4;i++){
if((len=client[i].fifo.available())>0){
len = len>dataLen?dataLen:len;
client[i].fifo.pop(data,len); // internally guearded by semaphore\
Serial.printf("FACE:FIFO %u %u %u %u %u\n",myDevId,i,len,checkSum(data,len));
Serial.write(data,len); // retransmission to USB 1M baud rate
}
}
}
vTaskDelete(NULL);
}