Skip to content

Commit

Permalink
fix(modem): Test what CMUX on SIM800 does
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Sep 26, 2023
1 parent d61ce9e commit d892fde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
CONFIG_ESP32_PANIC_PRINT_HALT=y
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
CONFIG_EXAMPLE_CLOSE_CMUX_AT_END=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y
# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set
CONFIG_LOG_MAXIMUM_LEVEL=4
# CONFIG_LOG_MASTER_LEVEL is not set
15 changes: 14 additions & 1 deletion components/esp_modem/src/esp_modem_cmux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ struct CMux::CMuxFrame {
bool CMux::data_available(uint8_t *data, size_t len)
{
if (data && (type & FT_UIH) == FT_UIH && len > 0 && dlci > 0) { // valid payload on a virtual term
ESP_LOGW("CMUX", "%d", __LINE__);
int virtual_term = dlci - 1;
if (virtual_term < MAX_TERMINALS_NUM && read_cb[virtual_term]) {
ESP_LOGW("CMUX", "%d", __LINE__);
// Post partial data (or defragment to post on CMUX footer)
#ifdef DEFRAGMENT_CMUX_PAYLOAD
if (payload_start == nullptr) {
Expand All @@ -129,30 +131,40 @@ bool CMux::data_available(uint8_t *data, size_t len)
read_cb[virtual_term](data, len);
#endif
} else {
ESP_LOGW("CMUX", "%d", __LINE__);
return false;
}
} else if (data == nullptr && type == (FT_UA | PF) && len == 0) { // notify the initial SABM command
ESP_LOGW("CMUX", "%d", __LINE__);
Scoped<Lock> l(lock);
sabm_ack = dlci;
} else if (data == nullptr && dlci > 0) {
ESP_LOGW("CMUX", "%d", __LINE__);
int virtual_term = dlci - 1;
if (virtual_term < MAX_TERMINALS_NUM && read_cb[virtual_term]) {
ESP_LOGW("CMUX", "%d", __LINE__);
#ifdef DEFRAGMENT_CMUX_PAYLOAD
read_cb[virtual_term](payload_start, total_payload_size);
#endif
} else {
ESP_LOGW("CMUX", "%d", __LINE__);
return false;
}
} else if ((type & FT_UIH) == FT_UIH && dlci == 0) { // notify the internal DISC command
ESP_LOG_BUFFER_HEXDUMP("type 0xEF", data, len, ESP_LOG_INFO);
if (len > 0 && (data[0] & 0xE1) == 0xE1) {
ESP_LOGW("CMUX", "%d", __LINE__);
// Not a DISC, ignore (MSC frame)
return true;
}
ESP_LOGW("CMUX", "%d", __LINE__);
Scoped<Lock> l(lock);
sabm_ack = dlci;
} else {
ESP_LOGW("CMUX", "%d", __LINE__);
return false;
}
ESP_LOGW("CMUX", "%d", __LINE__);
return true;
}

Expand Down Expand Up @@ -234,6 +246,7 @@ bool CMux::on_header(CMuxFrame &frame)
// since CRC could be evaluated after the frame payload gets received
if (dlci > MAX_TERMINALS_NUM || (frame_header[1] & 0x01) == 0 ||
(((type & FT_UIH) != FT_UIH) && type != (FT_UA | PF) ) ) {
ESP_LOGI("CMUX", "[1]:%02x [2]:%02x [3]:%02x", frame_header[1], frame_header[2], frame_header[3]);
recover_protocol(protocol_mismatch_reason::UNEXPECTED_HEADER);
return true;
}
Expand Down Expand Up @@ -340,7 +353,7 @@ bool CMux::on_cmux_data(uint8_t *data, size_t actual_len)
actual_len = term->read(data, buffer.size);
#endif
}
ESP_LOG_BUFFER_HEXDUMP("CMUX Received", data, actual_len, ESP_LOG_VERBOSE);
ESP_LOG_BUFFER_HEXDUMP("CMUX Received", data, actual_len, ESP_LOG_INFO);
CMuxFrame frame = { .ptr = data, .len = actual_len };
while (frame.len > 0) {
switch (state) {
Expand Down

0 comments on commit d892fde

Please sign in to comment.