Skip to content

Commit 2fc0d64

Browse files
authored
fix disconnect state (#47)
* fix disconnect handling to clear authentication state * bump to 4.1.3 * tests(vehicle): enhance vehicle connection state tests
1 parent 1770263 commit 2fc0d64

5 files changed

Lines changed: 322 additions & 176 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ else()
110110

111111
include(FetchContent)
112112
project(TeslaBLE
113-
VERSION 4.1.2
113+
VERSION 4.1.3
114114
DESCRIPTION "CPP Tesla BLE Library"
115115
LANGUAGES CXX C
116116
)

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "4.1.2"
1+
version: "4.1.3"
22
description: "C++ library for Tesla BLE API communication"
33
url: "https://github.com/yoziru/tesla-ble"
44
dependencies:

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "TeslaBLE",
3-
"version": "4.1.2",
3+
"version": "4.1.3",
44
"description": "This CPP library facilitates direct communication with Tesla vehicles via the BLE API. It offers fundamental features such as unlocking/locking, opening the trunk, and more. The library's capabilities are contingent on the range of actions implemented by Tesla, which is the only limitation at present.",
55
"keywords": "tesla, ble",
66
"repository": {

src/vehicle.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,26 @@ void Vehicle::set_connected(bool connected) {
5151
is_connected_ = connected;
5252
if (!connected) {
5353
LOG_INFO("Disconnected from vehicle");
54-
// Clear auth states?
55-
// Usually session persists, but connection state is used for something?
54+
55+
// Clear authentication state flags on disconnect
56+
// Session data persists (stored in NVS), but authentication must be
57+
// re-established on reconnect as the vehicle may have started a new
58+
// ephemeral session or the counters may be stale
59+
is_vcsec_authenticated_ = false;
60+
is_infotainment_authenticated_ = false;
61+
62+
// Clear command queue to prevent stale commands from blocking
63+
// New commands will be enqueued after reconnection
64+
while (!command_queue_.empty()) {
65+
auto cmd = command_queue_.front();
66+
if (cmd->on_complete) {
67+
cmd->on_complete(false); // Notify failure
68+
}
69+
command_queue_.pop();
70+
}
71+
72+
// Clear RX buffer for clean slate
73+
rx_buffer_.clear();
5674
} else {
5775
LOG_INFO("Connected to vehicle");
5876
}

0 commit comments

Comments
 (0)