Skip to content

Commit

Permalink
Switch to using l2cap_request_can_send_now_event()
Browse files Browse the repository at this point in the history
  • Loading branch information
shermp committed Jul 13, 2024
1 parent 8d85e69 commit 3959ef5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
18 changes: 8 additions & 10 deletions src/asha_bt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,9 @@ extern "C" void bt_main()
//LOG_INFO("Audio index: %hu\n", ha.audio_index);
if (ha.audio_index < audio_write_index) {
ha.set_audio_packet(audio_buff.get_g_buff(ha.audio_index));
ha.send_audio_packet();
l2cap_request_can_send_now_event(ha.cid);
}
break;
case AudioPacketSending:
//LOG_INFO("Sending audio packet\n");
ha.send_audio_packet();
break;
default:
break;
}
Expand Down Expand Up @@ -388,15 +384,17 @@ static void l2cap_cbm_event_handler (uint8_t packet_type, uint16_t channel, uint
}
break;
}
case L2CAP_EVENT_CAN_SEND_NOW:
{
LOG_AUDIO("L2CAP_EVENT_CAN_SEND_NOW\n");
HA& ha = ha_mgr.get_by_cid(l2cap_event_can_send_now_get_local_cid(packet));
ha.on_can_send_audio_packet_now();
}
case L2CAP_EVENT_PACKET_SENT:
{
LOG_AUDIO("L2CAP_EVENT_PACKET_SENT\n");
HA& ha = ha_mgr.get_by_cid(l2cap_event_packet_sent_get_local_cid(packet));
if (ha) {
ha.on_audio_packet_sent();
} else {
LOG_ERROR("L2CAP_EVENT_PACKET_SENT: unable to get hearing aid.\n");
}
ha.on_audio_packet_sent();
break;
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/hearing_aid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,15 @@ void HA::set_audio_packet(AudioBuffer::G722Buff& packet)
}
}

void HA::send_audio_packet()
void HA::on_can_send_audio_packet_now()
{
if (state == State::AudioPacketSending) {
if (l2cap_can_send_packet_now(cid)) {
LOG_AUDIO("%s: Sending audio packet. Seq Num: %d\n", side_str, (int)audio_packet[0]);
LOG_AUDIO("%s: Setting AudioPacketSent state\n", side_str);
state = State::AudioPacketSent;
uint8_t res = l2cap_send(cid, audio_packet, sdu_size_bytes);
if (res != ERROR_CODE_SUCCESS) {
LOG_ERROR("%s: Error sending audio packet with error code: 0x%02x\n", side_str, (unsigned int)res);
state = State::AudioPacketReady;
}
LOG_AUDIO("%s: Sending audio packet. Seq Num: %d\n", side_str, (int)audio_packet[0]);
state = State::AudioPacketSent;
uint8_t res = l2cap_send(cid, audio_packet, sdu_size_bytes);
if (res != ERROR_CODE_SUCCESS) {
LOG_ERROR("%s: Error sending audio packet with error code: 0x%02x\n", side_str, (unsigned int)res);
state = State::AudioPacketReady;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hearing_aid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class HA
void write_volume();

void set_audio_packet(AudioBuffer::G722Buff& packet);
void send_audio_packet();
void on_can_send_audio_packet_now();
void on_audio_packet_sent();

bool is_creating_l2cap_channel();
Expand Down

0 comments on commit 3959ef5

Please sign in to comment.