16
16
/**
17
17
* Returns the number of devices between the current and last device IDs.
18
18
* @param device_id The current device ID.
19
- * @param last_id The last device ID.
19
+ * @param previous_packet_device_id The previous packet sender device ID.
20
20
* @return The number of devices between the current and last device IDs.
21
21
*/
22
- uint8_t turns_away (const uint8_t device_id , const uint8_t last_id ) {
22
+ uint8_t turns_away (const uint8_t device_id , const uint8_t previous_packet_device_id ) {
23
23
// device 2, last device 0, 2 - 0 = 2
24
- if (device_id > last_id ) {
25
- return device_id - last_id ;
24
+ if (device_id > previous_packet_device_id ) {
25
+ return device_id - previous_packet_device_id ;
26
26
}
27
27
// device 0, last device 2, 3 - 2 + 0 = 1
28
- return TOTAL_DEVICES - last_id + device_id ;
28
+ return CONFIG_TOTAL_DEVICES - previous_packet_device_id + device_id ;
29
29
}
30
30
31
31
void app_main () {
@@ -37,10 +37,12 @@ void app_main() {
37
37
}
38
38
ESP_ERROR_CHECK (ret );
39
39
40
- // Get the device ID from NVS or set the default ID
40
+ #if CONFIG_IS_SET_DEVICE_ID
41
+ store_device_id (CONFIG_DEVICE_ID );
42
+ #endif
43
+
41
44
payload .device_id = get_device_id ();
42
- ESP_LOGI (TAG , "Device ID: %d" , payload .device_id );
43
- last_id = (payload .device_id + TOTAL_DEVICES - 1 ) % TOTAL_DEVICES ;
45
+ prev_packet_device_id = (payload .device_id + CONFIG_TOTAL_DEVICES - 1 ) % CONFIG_TOTAL_DEVICES ;
44
46
45
47
// Initialize the payload length and index
46
48
payload .csi_data_arr_len = 0 ;
@@ -75,10 +77,10 @@ void app_main() {
75
77
76
78
// Determine the multiplier based on the distance between the current and last device IDs
77
79
// This multiplier is used to increase the timeout count for devices further away
78
- const int multiplier = turns_away (payload .device_id , last_id );
80
+ const int multiplier = turns_away (payload .device_id , prev_packet_device_id );
79
81
80
82
// If the timeout count exceeds the timeout threshold, send CSI data
81
- if (timeout_count >= TIMEOUT * multiplier * multiplier ) {
83
+ if (timeout_count >= CONFIG_CYCLE_TIMEOUT * multiplier * multiplier ) {
82
84
ESP_LOGW (TAG , "ESP-NOW Timeout %d" , timeout_count );
83
85
send_csi_data (last_time_index ++ );
84
86
timeout_count = 0 ;
0 commit comments