Skip to content

Commit

Permalink
MasterMode Not Receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
dlktdr committed Jun 23, 2022
1 parent 867996b commit f6c66af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
23 changes: 6 additions & 17 deletions src/bt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
9 changes: 8 additions & 1 deletion src/frskybt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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]);
}
}
1 change: 1 addition & 0 deletions src/frskybt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit f6c66af

Please sign in to comment.