diff --git a/src/bt_client.c b/src/bt_client.c index 9f65c57..979a9f8 100644 --- a/src/bt_client.c +++ b/src/bt_client.c @@ -346,24 +346,13 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ } case ESP_GATTC_NOTIFY_EVT: if (p_data->notify.is_notify) { -#if defined(DEBUG_TIMERS) - //static int64_t ctime = 0; - logBTFrame((const char *)p_data->notify.value, p_data->notify.value_len); - - // printf("Update(%lld), curtime %lld\n", esp_timer_get_time() - ctime, esp_timer_get_time()); - //ctime = esp_timer_get_time(); - /*if(ctime < esp_timer_get_time()) { - printf("Updates in %dus %dHz\n",20000, updates); - ctime = esp_timer_get_time() + 20000; - updates = 0; - } - updates ++;*/ + // TODO, verify what characteristic is being notified +#ifdef DEBUG_TIMERS + processFrame(p_data->notify.value,p_data->notify.value_len); // Used to decode the channel data for debugging #endif + uart_write_bytes(uart_num, (void*)p_data->notify.value, p_data->notify.value_len); // Write the received data to the UART port - // TODO, verify what characteristic is sending. - // // if(p_data->notify.handle == bt_datahandle) // If notify coming from the data handle, send it to the UART port - uart_write_bytes(uart_num, (void*)p_data->notify.value, p_data->notify.value_len); // else // ESP_LOGI(GATTC_TAG, "ESP_GATTC_NOTIFY_EVT, receive unknown notify value:"); } else { @@ -565,7 +554,7 @@ void btc_connect(esp_bd_addr_t addr) char saddr[13]; memcpy(rmtbtaddress, addr, sizeof(esp_bd_addr_t)); printf("Connecting to %s\r\n", btaddrtostr(saddr,addr)); // TODO FIX ME - //esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, addr, BLE_ADDR_TYPE_RANDOM, true); + esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, addr, BLE_ADDR_TYPE_RANDOM, true); } void btc_disconnect() @@ -614,5 +603,5 @@ void btcInit() // Try to connect to saved address on startup esp_bd_addr_t addr; strtobtaddr(addr, settings.rmtbtaddr); - btc_connect(addr); + //btc_connect(addr); } \ No newline at end of file diff --git a/src/frskybt.c b/src/frskybt.c index ad51e73..ee43cdb 100644 --- a/src/frskybt.c +++ b/src/frskybt.c @@ -123,7 +123,7 @@ void processTrainerFrame(const uint8_t * otxbuffer) channeldata[channel+1] = ((otxbuffer[i+1] & 0x0f) << 4) + ((otxbuffer[i+2] & 0xf0) >> 4) + ((otxbuffer[i+2] & 0x0f) << 8); } - // If the data came from the radio, send it out over bluetooth. Use the buffer that has START_STOP as first char + // If the data came from the radio, send it out over bluetooth. Send same data but add the START_STOP if(settings.role == ROLE_BLE_PERIPHERAL) { btp_sendChannelData(_otxbuffer, otxbufferIndex+1); } @@ -204,4 +204,11 @@ void frSkyProcessByte(uint8_t data) } dataState = STATE_DATA_IDLE; } +} + +void processFrame(const uint8_t *frame, uint8_t len) +{ + for(int i=0;i < len; i++) { + frSkyProcessByte(frame[i]); + } } \ No newline at end of file diff --git a/src/frskybt.h b/src/frskybt.h index a630e39..0efbec1 100644 --- a/src/frskybt.h +++ b/src/frskybt.h @@ -17,3 +17,4 @@ enum { int setTrainer(uint8_t *addr, uint16_t chan_vals[BT_CHANNELS]); void frSkyProcessByte(uint8_t data); +void processFrame(const uint8_t *frame, uint8_t len); \ No newline at end of file