From 28a46cf438dd36948e81c24ac513293acf3614c9 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Wed, 3 Aug 2022 10:16:32 +0200 Subject: [PATCH 1/5] Hotfix FreeRTOS mutex method when FreeRTOS is not used --- src/Arancino.cpp | 57 ++++++++++++++++++++++++++++-------------------- src/Arancino.h | 2 ++ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index af99f3d..3452e62 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -91,12 +91,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) char *keys[] = {fw_lib_ver, fw_name, fw_ver, fw_build_time, fw_core_ver, mcu_family, fw_use_freertos}; char *values[] = {LIB_VERSION, _metadata.fwname, _metadata.fwversion, str_build_time, (char *)ARANCINO_CORE_VERSION, (char *)MCU_FAMILY, (char *)useFreeRtos}; -// DEBUG -#if defined(ARDUINO_ARANCINO) - pinMode(DBG_PIN, INPUT); - if (!digitalRead(DBG_PIN)) + //DEBUG + #if defined(ARDUINO_ARANCINO) + pinMode(DBG_PIN,INPUT); + if(!digitalRead(DBG_PIN)) Serial.begin(115200); -#endif + #endif start(keys, values, 7); @@ -885,7 +885,7 @@ template<> void ArancinoClass::mstore(char** keys, char** values, int len,char* char* ts = timestamp; if ((keys == NULL) || (values == NULL) || (len <= 0)) { //return invalidCommandErrorPacket; - + } return executeCommandFast(MSTORE_COMMAND, NULL, keys, values, ts, len, false, STRING_ARRAY); } @@ -1326,12 +1326,16 @@ ArancinoPacket ArancinoClass::executeCommand(char *command, char *param1, char * #endif char *message = NULL; - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) - { + + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif _sendArancinoCommand(str); message = _receiveArancinoResponse(END_TX_CHAR); + #if defined(USEFREERTOS) giveCommMutex(); } + #endif free(str); @@ -1459,11 +1463,14 @@ void ArancinoClass::executeCommandFast(char* command, char* param1, char** param } #endif - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) - { + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif _sendArancinoCommand(str); + #if defined(USEFREERTOS) giveCommMutex(); } + #endif free(str); } @@ -1520,12 +1527,15 @@ ArancinoPacket ArancinoClass::executeCommand(char* command, char* param1, char* strcat(str, endTXStr); char *message = NULL; - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) - { + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif _sendArancinoCommand(str); message = _receiveArancinoResponse(END_TX_CHAR); + #if defined(USEFREERTOS) giveCommMutex(); } + #endif free(str); if (message == NULL) @@ -1583,11 +1593,14 @@ void ArancinoClass::executeCommandFast(char* command, char* param1, char* param2 } strcat(str, endTXStr); - if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) - { + #if defined(USEFREERTOS) + if (takeCommMutex((TickType_t)portMAX_DELAY) != pdFALSE) { + #endif _sendArancinoCommand(str); + #if defined(USEFREERTOS) giveCommMutex(); } + #endif free(str); } @@ -1820,16 +1833,15 @@ char *ArancinoClass::_parse(char *message) value[messageLength - (DSCIndex + 2)] = '\0'; // replace END_TX_CHAR with '\0' } -// DEBUG -#if defined(ARDUINO_ARANCINO) - if (!digitalRead(DBG_PIN)) - { + //DEBUG + #if defined(ARDUINO_ARANCINO) + if(!digitalRead(DBG_PIN)){ Serial.print(RCV_STRING); Serial.print(status); Serial.print(" "); Serial.println(value); } -#endif + #endif free(status); @@ -1921,10 +1933,9 @@ char **ArancinoClass::_parseArray(char *data) return (data != NULL && arrayParsed != NULL) ? &arrayParsed[1] : NULL; } +#if defined(USEFREERTOS) BaseType_t ArancinoClass::takeCommMutex(TickType_t timeout) { -#if defined(USEFREERTOS) - if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) { if (CommMutex != NULL) @@ -1945,10 +1956,8 @@ BaseType_t ArancinoClass::takeCommMutex(TickType_t timeout) */ return pdTRUE; } -#else - return pdTRUE; -#endif } +#endif void ArancinoClass::giveCommMutex() { diff --git a/src/Arancino.h b/src/Arancino.h index 941bf8c..11beb47 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -286,7 +286,9 @@ class ArancinoClass { char* _parse(char* message); char** _parseArray(char* message); + #if defined(USEFREERTOS) //The entire prototype would be ill-formed if freertos is not defined BaseType_t takeCommMutex(TickType_t timeout); + #endif void giveCommMutex(); void taskSuspend(); void taskResume(); From 2258c972b6e49420aed9fd21add6dbbe605949ae Mon Sep 17 00:00:00 2001 From: Dario Gogliandolo Date: Wed, 7 Sep 2022 12:06:08 +0200 Subject: [PATCH 2/5] Increased calloc space in executeCommand/fast https://app.clickup.com/t/2x5jbfq --- src/Arancino.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 3452e62..06f9ef8 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -1243,7 +1243,7 @@ ArancinoPacket ArancinoClass::executeCommand(char *command, char *param1, char * strLength += param4_length + 1; } - char *str = (char *)calloc(strLength, sizeof(char)); + char *str = (char *)calloc(strLength + 1, sizeof(char)); strcpy(str, command); if (param1 != NULL) @@ -1391,7 +1391,7 @@ void ArancinoClass::executeCommandFast(char* command, char* param1, char** param strLength += param4_length + 1; } - char* str = (char*) calloc(strLength, sizeof(char)); + char* str = (char*) calloc(strLength + 1, sizeof(char)); strcpy(str, command); if(param1 != NULL){ From d57ed9cb5ebd3e3d08b170d0b832c1810cb45b8a Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 19 Sep 2022 10:49:11 +0200 Subject: [PATCH 3/5] Fixed minor issues in examples --- examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino | 1 + .../Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino index d95d115..d66b387 100644 --- a/examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino +++ b/examples/Arancino/15-STORE/STORE_Packet/STORE_Packet.ino @@ -74,6 +74,7 @@ void loop(){ SERIAL_DEBUG.println("STORE ERROR"); } + Arancino.free(apckt); delay(2000); } diff --git a/examples/Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino b/examples/Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino index 850bb5b..c7b70fc 100644 --- a/examples/Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino +++ b/examples/Arancino_FreeRTOS/15-STORE/STORE_Packet/STORE_Packet.ino @@ -85,6 +85,7 @@ void loopTask(void *pvParameters) { SERIAL_DEBUG.println("STORE ERROR"); } + Arancino.free(apckt); vTaskDelay(2000); } } From b154f4713fcad3eea5ca1e839b17e06f2be0cd31 Mon Sep 17 00:00:00 2001 From: Calapristi Marco Date: Mon, 19 Sep 2022 08:59:17 +0000 Subject: [PATCH 4/5] Update CHANGELOG.md, library.json, library.properties files --- CHANGELOG.md | 6 +++++- library.json | 2 +- library.properties | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b4f717..0fdd96f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ # Changelog +#### v 2.1.1 - 2022.09.19 +* Fix: fixed an error that occurred when FreeRTOS was not enabled +* Fix: fixed a bug in executeCommandFast function +* Fix: fixed an error in STORE_packet example + #### v 2.1.0 - 2022.07.29 * Upd: ERR_GENERIC was redefined as ERR [#1jz91mu] (https://app.clickup.com/t/1jz91mu) * Upd: ID_PREFIX removed from `store`, `mstore` and `storeTags` commands [#23v2xn3] (https://app.clickup.com/t/23v2xn3) * Add: added executeCommandFast command [#394mek4] (https://app.clickup.com/t/394mek4) * Add: added `mstore` with timestamp argument [#394memb] (https://app.clickup.com/t/394memb) - #### v 2.0.1 - 2022.05.27 * Fix: bug debug for arancino mignon board. [#2g4fxvx] (https://app.clickup.com/t/2g4fxvx) diff --git a/library.json b/library.json index 2d553c0..6c30be5 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/smartmeio/arancino-library.git" }, - "version": "2.1.0", + "version": "2.1.1", "authors": { "name": "smartme.IO", "url": "https://www.arancino.cc" diff --git a/library.properties b/library.properties index d3f6213..9dabd79 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arancino -version=2.1.0 +version=2.1.1 author=smartme.IO maintainer=smartme.IO sentence=Enables communication between microcontroller and Arancino Module running mainly in Arancino boards. From ab38d8c63e2edf6da9fa5ae6f319d23f08c21795 Mon Sep 17 00:00:00 2001 From: Marco Calapristi Date: Mon, 19 Sep 2022 11:16:26 +0200 Subject: [PATCH 5/5] Fixed typo --- src/ArancinoDefinitions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index 19c89a2..9f331f0 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -102,7 +102,7 @@ under the License #define MODLOGLVL_KEY (char*)"___MODLOGLVL___" #define MODENV_KEY (char*)"___MODENV___" #define BLINK_ID_KEY (char*)"___BLINK_ID___" -#define LIB_VERSION (char*)"2.0.0" //library version +#define LIB_VERSION (char*)"2.1.1" //library version //RESPONSE CODE #define INVALID_VALUE_ERROR -4