From 8764fe66f0a1cd2670cede003e80776b90319df1 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 6 Oct 2023 10:40:09 -0500 Subject: [PATCH 1/2] [adamnet][network] still not fast enough. shit. --- lib/device/adamnet/network.cpp | 73 ++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/lib/device/adamnet/network.cpp b/lib/device/adamnet/network.cpp index 417f3eb9f..e648a59e2 100755 --- a/lib/device/adamnet/network.cpp +++ b/lib/device/adamnet/network.cpp @@ -173,6 +173,10 @@ void adamNetwork::open(unsigned short s) // Associate channel mode json.setProtocol(protocol); + + // Clear response + memset(response, 0, sizeof(response)); + response_len = 0; } /** @@ -208,6 +212,9 @@ void adamNetwork::close() // Delete the protocol object delete protocol; protocol = nullptr; + + memset(response, 0, sizeof(response)); + response_len = 0; } /** @@ -387,6 +394,9 @@ void adamNetwork::set_prefix(unsigned short s) } Debug_printf("Prefix now: %s\n", prefix.c_str()); + + response_len = 0; + memset(response, 0, sizeof(response)); } /** @@ -449,6 +459,9 @@ void adamNetwork::del(uint16_t s) statusByte.bits.client_error = true; return; } + + memset(response, 0, sizeof(response)); + response_len = 0; } void adamNetwork::rename(uint16_t s) @@ -472,6 +485,9 @@ void adamNetwork::rename(uint16_t s) statusByte.bits.client_error = true; return; } + + memset(response, 0, sizeof(response)); + response_len = 0; } void adamNetwork::mkdir(uint16_t s) @@ -495,6 +511,9 @@ void adamNetwork::mkdir(uint16_t s) statusByte.bits.client_error = true; return; } + + memset(response, 0, sizeof(response)); + response_len = 0; } void adamNetwork::channel_mode() @@ -521,25 +540,24 @@ void adamNetwork::channel_mode() } Debug_printf("adamNetwork::channel_mode(%u)\n", m); - AdamNet.start_time = esp_timer_get_time(); - adamnet_response_ack(); + memset(response, 0, sizeof(response)); + response_len = 0; } void adamNetwork::json_query(unsigned short s) { - uint8_t *c = (uint8_t *)malloc(s); + memset(response, 0, sizeof(response)); + response_len = 0; - adamnet_recv_buffer(c, s); + adamnet_recv_buffer(response, s); adamnet_recv(); // CK AdamNet.start_time = esp_timer_get_time(); adamnet_response_ack(); - json.setReadQuery(std::string((char *)c, s), cmdFrame.aux2); + json.setReadQuery(std::string((char *)response, s), cmdFrame.aux2); - Debug_printv("adamNetwork::json_query(%s)\n", c); - - free(c); + Debug_printv("adamNetwork::json_query(%s)\n", response); } void adamNetwork::json_parse() @@ -548,6 +566,8 @@ void adamNetwork::json_parse() AdamNet.start_time = esp_timer_get_time(); adamnet_response_ack(); json.parse(); + memset(response, 0, sizeof(response)); + response_len = 0; } /** @@ -621,11 +641,16 @@ void adamNetwork::adamnet_special_00(unsigned short s) cmdFrame.aux1 = adamnet_recv(); cmdFrame.aux2 = adamnet_recv(); + adamnet_recv(); // CK + AdamNet.start_time = esp_timer_get_time(); adamnet_response_ack(); protocol->special_00(&cmdFrame); inq_dstats = 0xff; + + response_len = 0; + memset(response, 0, sizeof(response)); } /** @@ -639,12 +664,17 @@ void adamNetwork::adamnet_special_40(unsigned short s) cmdFrame.aux1 = adamnet_recv(); cmdFrame.aux2 = adamnet_recv(); + adamnet_recv(); // CK + if (protocol->special_40(response, 1024, &cmdFrame) == false) adamnet_response_ack(); else adamnet_response_nack(); inq_dstats = 0xff; + + response_len = 0; + memset(response, 0, sizeof(response)); } /** @@ -666,12 +696,17 @@ void adamNetwork::adamnet_special_80(unsigned short s) Debug_printf("adamNetwork::adamnet_special_80() - %s\n", spData); + adamnet_recv(); // CK + // Do protocol action and return if (protocol->special_80(spData, SPECIAL_BUFFER_SIZE, &cmdFrame) == false) adamnet_response_ack(); else adamnet_response_nack(); inq_dstats = 0xff; + + memset(response, 0, sizeof(response)); + response_len = 0; } void adamNetwork::adamnet_response_status() @@ -724,7 +759,7 @@ void adamNetwork::adamnet_control_send() case '0': get_prefix(); break; - case 'E': + case 'E': get_error(); break; case 'O': @@ -818,11 +853,9 @@ void adamNetwork::adamnet_control_receive_channel_protocol() { NetworkStatus ns; - AdamNet.start_time = esp_timer_get_time(); - if ((protocol == nullptr) || (receiveBuffer == nullptr)) { - // adamnet_response_nack(); + adamnet_response_nack(); return; // Punch out. } @@ -830,7 +863,16 @@ void adamNetwork::adamnet_control_receive_channel_protocol() protocol->status(&ns); if (!ns.rxBytesWaiting) + { + AdamNet.start_time = esp_timer_get_time(); + adamnet_response_nack(); return; + } + else + { + AdamNet.start_time = esp_timer_get_time(); + adamnet_response_ack(); + } // Truncate bytes waiting to response size ns.rxBytesWaiting = (ns.rxBytesWaiting > 1024) ? 1024 : ns.rxBytesWaiting; @@ -840,6 +882,7 @@ void adamNetwork::adamnet_control_receive_channel_protocol() { statusByte.bits.client_error = true; err = protocol->error; + adamnet_response_nack(); return; } else // everything ok @@ -861,10 +904,6 @@ void adamNetwork::adamnet_control_receive() adamnet_response_ack(); return; } - else if ((response_len == 0) && (channelMode == PROTOCOL)) // this is hacky as hell - { - adamnet_response_nack(); - } switch (channelMode) { @@ -890,7 +929,7 @@ void adamNetwork::adamnet_response_send() } else adamnet_send(0xC0 | _devnum); // NAK! - + memset(response, 0, response_len); response_len = 0; } From 606f8b08c6d6be2e6ada56ac64583d211f0bf52c Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 6 Oct 2023 11:24:35 -0500 Subject: [PATCH 2/2] [adamnet][network] fix network device. --- lib/bus/adamnet/adamnet.cpp | 19 ++++++++++++------- lib/bus/adamnet/adamnet.h | 6 ++++-- lib/device/adamnet/network.cpp | 10 +++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/bus/adamnet/adamnet.cpp b/lib/bus/adamnet/adamnet.cpp index e705cf06c..1dd2329c0 100755 --- a/lib/bus/adamnet/adamnet.cpp +++ b/lib/bus/adamnet/adamnet.cpp @@ -61,7 +61,7 @@ static void adamnet_reset_intr_task(void *arg) } b->reset(); - vTaskDelay(1); + vTaskDelay(1/portTICK_PERIOD_MS); } } @@ -160,27 +160,32 @@ void virtualDevice::reset() Debug_printf("No Reset implemented for device %u\n", _devnum); } -void virtualDevice::adamnet_response_ack() +void virtualDevice::adamnet_response_ack(bool doNotWaitForIdle) { int64_t t = esp_timer_get_time() - AdamNet.start_time; - if (t < 300) + if (!doNotWaitForIdle) { AdamNet.wait_for_idle(); - adamnet_send(0x90 | _devnum); } - else + + if (t < 300) { + adamnet_send(0x90 | _devnum); } } -void virtualDevice::adamnet_response_nack() +void virtualDevice::adamnet_response_nack(bool doNotWaitForIdle) { int64_t t = esp_timer_get_time() - AdamNet.start_time; - if (t < 300) + if (!doNotWaitForIdle) { AdamNet.wait_for_idle(); + } + + if (t < 300) + { adamnet_send(0xC0 | _devnum); } } diff --git a/lib/bus/adamnet/adamnet.h b/lib/bus/adamnet/adamnet.h index 961a4432c..f0094865d 100755 --- a/lib/bus/adamnet/adamnet.h +++ b/lib/bus/adamnet/adamnet.h @@ -146,13 +146,15 @@ class virtualDevice /** * @brief acknowledge, but not if cmd took too long. + * @param doNotWaitForIdle do not wait for idle if true. */ - virtual void adamnet_response_ack(); + virtual void adamnet_response_ack(bool doNotWaitForIdle=false); /** * @brief non-acknowledge, but not if cmd took too long + * param doNotWaitForIdle do not wait for idle if true. */ - virtual void adamnet_response_nack(); + virtual void adamnet_response_nack(bool doNotWaitForIdle=false); /** * @brief acknowledge if device is ready, but not if cmd took too long. diff --git a/lib/device/adamnet/network.cpp b/lib/device/adamnet/network.cpp index e648a59e2..d08a34d63 100755 --- a/lib/device/adamnet/network.cpp +++ b/lib/device/adamnet/network.cpp @@ -849,13 +849,13 @@ void adamNetwork::adamnet_control_receive_channel_json() } } -void adamNetwork::adamnet_control_receive_channel_protocol() +inline void adamNetwork::adamnet_control_receive_channel_protocol() { NetworkStatus ns; if ((protocol == nullptr) || (receiveBuffer == nullptr)) { - adamnet_response_nack(); + adamnet_response_nack(true); return; // Punch out. } @@ -865,13 +865,13 @@ void adamNetwork::adamnet_control_receive_channel_protocol() if (!ns.rxBytesWaiting) { AdamNet.start_time = esp_timer_get_time(); - adamnet_response_nack(); + adamnet_response_nack(true); return; } else { AdamNet.start_time = esp_timer_get_time(); - adamnet_response_ack(); + adamnet_response_ack(true); } // Truncate bytes waiting to response size @@ -894,7 +894,7 @@ void adamNetwork::adamnet_control_receive_channel_protocol() } } -void adamNetwork::adamnet_control_receive() +inline void adamNetwork::adamnet_control_receive() { AdamNet.start_time = esp_timer_get_time();