From a014a47e71bb785422f3ef91acbcb132a86612a0 Mon Sep 17 00:00:00 2001 From: Arturo Rinaldi Date: Tue, 16 Mar 2021 11:57:15 +0100 Subject: [PATCH 1/9] enabling tarball publishing to platformIO registry just for stable tags --- .gitlab-ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 215a5d8..ac51e5d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -121,7 +121,7 @@ package_release: #- DATE="$(cat tmp/date.tmp)" # packaging for PlatformIO - jq --arg tag_ver ${CI_COMMIT_TAG} '.version = $tag_ver' library.json|sponge library.json - # - pio package pack -o /tmp + - pio package pack -o /tmp # standard packaging as ZIP archive - sed -i "s/version=.*/version=${CI_COMMIT_TAG}/g" library.properties - PKG_NAME=$CI_PROJECT_NAME-$CI_COMMIT_TAG @@ -173,7 +173,10 @@ upload: # Upload to Artifactory - curl -u $REPO_USR:$REPO_PWD -T tmp/$PKG_NAME.zip "${REPO_BASE_URL}/artifactory/${REPO_NAME}/${TARGET_PATH}/${PKG_NAME}.zip" # publishing to PlatformIO - # - pio package publish --owner smartme-io /tmp/Arancino-${CI_COMMIT_TAG}.tar.gz + - > + if [[ ${PRE_RELEASE} == "" ]]; then + pio package publish --owner smartme-io /tmp/Arancino-${CI_COMMIT_TAG}.tar.gz + fi ################################# ####### CLEANUP ####### From 53158d709a7520b0c21ac0afd7bfcc5c64f062c8 Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 31 Mar 2021 12:06:04 +0200 Subject: [PATCH 2/9] fix docs internal link --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 380e150..ef5518e 100644 --- a/README.md +++ b/README.md @@ -201,8 +201,8 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response`: `NULL`; -###### Note: [2](###notes) -###### Note: [5](###notes) +###### Note: [2](#notes), [5](#notes) + ___ ### get ##### *char* get(char* key)* @@ -227,7 +227,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.string`: `char*` pointer that can contain the value of selected *key* or `NULL` if the *key* doesn't exist. -###### Note: [1](###notes), [4](###notes) +###### Note: [1](#notes), [4](#notes) ___ @@ -247,7 +247,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `responseType`: `VOID`; * `response`: `NULL`; -###### Note: [3](###notes) +###### Note: [3](#notes) ### mget ##### *char** mget(char** keys, char** values, uint len)* @@ -273,7 +273,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.stringarray`: `char**` pointer that points to the start of the returned array of strings. -###### Note: [1](###notes), [4](###notes) +###### Note: [1](#notes), [4](#notes) ### del ##### *int del(char* key )* @@ -296,7 +296,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.integer`: The number of keys that were removed. -###### Note: [1](###notes) +###### Note: [1](#notes) ___ ### keys @@ -352,7 +352,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response`: `NULL`; -###### Note: [2](###notes) +###### Note: [2](#notes) ___ ### hget @@ -378,7 +378,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.string`: `char*` pointer that can contain the *value* if a value is stored in *field* at *key* or `NULL` if there isn't a value stored. -###### Note: [1](###notes), [4](###notes) +###### Note: [1](#notes), [4](#notes) ___ ### hgetall @@ -401,7 +401,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `responseType`: `STRING_ARRAY`; * `response.stringArray`: `char**` pointer that can contain the string array of field and value matching *key* -###### Note: [1](###notes), [4](###notes) +###### Note: [1](#notes), [4](#notes) ___ ### hkeys @@ -425,7 +425,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.stringArray`: `char**` pointer to the string array of *fields* matching *key*. -###### Note: [1](###notes), [4](###notes) +###### Note: [1](#notes), [4](#notes) ___ ### hvals @@ -448,7 +448,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.stringArray`: `char**` pointer to the string array of *values* matching *key*. -###### Note: [1](###notes), [4](###notes) +###### Note: [1](#notes), [4](#notes) ___ ### hdel @@ -475,7 +475,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: * `response.integer`: 1 if the *field* is removed from hash or 0 if the *field* or the *key* does not exist in the hash. -###### Note: [1](###notes) +###### Note: [1](#notes) ___ ### flush From 17675bc93debe0dc964736bd1df741a2ed516b0b Mon Sep 17 00:00:00 2001 From: andrea-83 Date: Fri, 2 Apr 2021 10:26:25 +0200 Subject: [PATCH 3/9] Fix: fixed bug on the float type #CU-g71qk9 --- CHANGELOG.md | 3 + README.md | 27 +++-- examples/Arancino/00-BEGIN/00-BEGIN.ino | 10 +- src/Arancino.cpp | 149 ++++++++++++++---------- src/Arancino.h | 40 ++++--- src/ArancinoConfig.h | 6 +- 6 files changed, 139 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e5d483..c7b5a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +#### v 1.4.1 - 2021.04.02 +* Fix: Fixed bug with float's and double's types in `set` function. [#g71qk9](https://app.clickup.com/t/g71qk9) + #### v 1.4.0 - 2021.03.15 * Upd: Metadata structure is now mandatory to the `begin` function. [#aex3e4](https://app.clickup.com/t/aex3e4) * Add: New `ArancinoConfig` Class used to pass configuration at `begin`. [#fd4ped](https://app.clickup.com/t/fd4ped) diff --git a/README.md b/README.md index ef5518e..079c476 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ typedef struct { ```c++ bool _USEID = false; int _TIMEOUT = TIMEOUT; // 100 ms for samd21 + int DECIMAL_DIGITS = 4; ``` @@ -101,7 +102,7 @@ typedef struct { ## API -> Note: when you get a value using api like `get`, `hget`, etc. please keep in mind to free memory each time using the `free` api. +> Note: when you get a value using api like `get`, `hget`, etc. please keep in mind to free memory each time using the `free` api. > > To prevent memory leak, code like this must be avoided: > ```c++ @@ -132,15 +133,15 @@ Stores the metadata to use later during the `START` command in `begin` API. ArancinoMetadata amdata = { .fwname = "Arancino Firmware", .fwversion = "1.0.0", - .tzoffset = "+1000" + .tzoffset = "+1000" }; void setup() { - + // deprecated: do not use the .metadata function directly. Use the mandatory metadata argument in the begin function instead. // This will be removed in the next major relase //Arancino.metadata(meta); - + // Arancino.begin(amdata); } @@ -163,8 +164,9 @@ From version - ArancinoConfig: is class composed only by attributes: - `_TIMEOUT`: (see the following paragraph: `timeout`) - `_USEID`: (see the following paragraph: `useid`) + - `DECIMAL_DIGITS`: (see the following paragraph: `decimal_digits`) -The convenience of using class X is to be able to increase the number of parameters without necessarily having to change the prototypes. +The convenience of using class X is to be able to increase the number of parameters without necessarily having to change the prototypes. The use of the following is deprecated and will be remove in the next major release. @@ -176,7 +178,10 @@ The use of the following is deprecated and will be remove in the next major rele It's useful when you connect multiple microntroller with the same firmware (using the same keys) to one Arancino Module; By this way, at the application level, you can distinguish keys by microntroller id. - +- **`decimal_digits`**: Default `4`. Represents the number to the right of the decimal point for the float and double data types. + With float data type is possible to represent 7 decimal digits of precision, while with double data type + has up to 15 digits. The decimal digits of precision is the total number of digits, not the number to the right of the decimal point. + There is a check to verify the number of digits and if the number exceed the maximum allowed for the type(float or double), the decimal part will be truncate (rounded up or rounded down). ___ ### set @@ -253,7 +258,7 @@ ArancinoPacket reply: [ArancinoPacket](#arancinopacket) containing: ##### *char** mget(char** keys, char** values, uint len)* ##### *ArancinoPacket mget\(char** keys, uint len)* -Retrieves multiple keys from redis. +Retrieves multiple keys from redis. ##### Parameters * **`keys`**: array containing keys to retrieve; @@ -638,9 +643,9 @@ void setup() { void loop() { char* str = "Test"; - if(isValidUTF8(str)) + if(isValidUTF8(str)) Arancino.set("key3", str); - + } ``` ### Notes @@ -661,9 +666,9 @@ void loop() { 5. When using `set`-type functions, make sure that the value is correctly formatted with *utf-8* standard. Is recommended to use the internal function `isValidUTF8` before the `set` to avoid decoding errors on Arancino Module. Example: ```c++ char* value="test"; - if(isValidUTF8(value)) + if(isValidUTF8(value)) Arancino.set("key3", value); - + ``` ## Cortex Protocol diff --git a/examples/Arancino/00-BEGIN/00-BEGIN.ino b/examples/Arancino/00-BEGIN/00-BEGIN.ino index 817ed90..c6aa430 100644 --- a/examples/Arancino/00-BEGIN/00-BEGIN.ino +++ b/examples/Arancino/00-BEGIN/00-BEGIN.ino @@ -32,8 +32,8 @@ Parameters: - _TIMEOUT: (see the following paragraph) - _USEID: (see the following paragraph) - The convenience of using class X is to be able to increase the number of parameters - without necessarily having to change the prototypes. + The convenience of using class X is to be able to increase the number of parameters + without necessarily having to change the prototypes. the use of the following is deprecated and will be remove in the next major release. @@ -54,7 +54,7 @@ the use of the following is deprecated and will be remove in the next major rele ArancinoMetadata amdata = { .fwname = "00.1 - Begin Example", .fwversion = "1.0.0", - .tzoffset = "+1000" + .tzoffset = "+1000" }; void setup() { @@ -62,10 +62,10 @@ void setup() { // Arancino Configuration ArancinoConfig acfg; acfg._TIMEOUT = 200; - + acfg.DECIMAL_DIGITS=4; //calls begin w/o paramenter: it is assumed 100ms timeout by default - Arancino.begin(amdata); + Arancino.begin(amdata, acfg); //calls begin w/ 200ms timeout trough Arancino Config //Arancino.begin(amdata, acfg); diff --git a/src/Arancino.cpp b/src/Arancino.cpp index ef6afe6..36364e3 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -19,6 +19,7 @@ under the License */ #include "Arancino.h" +#include #define DEBUG 0 @@ -81,13 +82,13 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { // arancino_id_prefix = false; arancino_id_prefix = _acfg._USEID; SERIAL_PORT.setTimeout(_acfg._TIMEOUT); - - + decimal_digits=_acfg.DECIMAL_DIGITS; + _metadata = _amdata; - Serial.begin(115200); + /*Serial.begin(115200); Serial.println(_acfg._USEID); - Serial.println(_acfg._TIMEOUT); + Serial.println(_acfg._TIMEOUT);*/ int fwnameLength = strlen(_metadata.fwname); int fwversionLength = strlen(_metadata.fwversion); @@ -104,7 +105,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { int commandLength = strlen(START_COMMAND); int argLength = strlen(LIB_VERSION); int strLength = commandLength + 1 + argLength + 1 + fwnameLength + 1 + fwversionLength + 1 + dateLength + 1 + timeLength + 1 + localtoffsetLength + arancinocoreversionLength + 1 + 1; - + char* str = (char *)calloc(strLength, sizeof(char)); //reserved Key @@ -119,7 +120,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { Serial.begin(115200); } #endif - + strcpy(str, START_COMMAND); strcat(str, dataSplitStr); @@ -137,13 +138,13 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { strcat(str, " "); strcat(str, _metadata.tzoffset); strcat(str, dataSplitStr); - + #ifdef ARANCINO_CORE_VERSION strcat(str, ARANCINO_CORE_VERSION); #endif strcat(str, endTXStr); - + ArancinoPacket packet; // Start communication with serial module on CPU do{ @@ -155,18 +156,18 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { Serial.print(SENT_STRING); } #endif - - + + _sendArancinoCommand(str); char* message = _receiveArancinoResponse(END_TX_CHAR); - + if (message != NULL) { //ArancinoPacket temp = {false, _getResponseCode(message), STRING, {.string = _parse(message)}}; ArancinoPacket temp = {false, _getResponseCode(message), STRING_ARRAY, {.stringArray = _parseArray(_parse(message))}}; packet = temp; - + if(packet.responseCode == RSP_OK){ //store arancino serial port id idSize = strlen(packet.response.stringArray[0]); @@ -184,7 +185,7 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { { packet = communicationErrorPacket; } - + }while (packet.isError == true || packet.responseCode != RSP_OK); std::free(str); @@ -201,7 +202,7 @@ TaskHandle_t commTaskHandle; void ArancinoClass::startScheduler() { vSetErrorLed(LED_BUILTIN, HIGH); - + /* * Uncomment this if you want run loop() as a dedicated task. * If loop() doesn't run as dedicated task, should not contain blocking code. @@ -232,7 +233,7 @@ ArancinoPacket ArancinoClass::mset(char** keys, char** values, uint len) { for (uint i = 0; i < len; i ++) { char* key = keys[i]; char* value = values[i]; - + uint keyLength = strlen(key); // if arancino_id has to be prepended we take into account its length and _ char @@ -272,17 +273,17 @@ ArancinoPacket ArancinoClass::mset(char** keys, char** values, uint len) { } strcat(keysPointer, key); - + if (i == len - 1) { // If it's the last key we have to use #(\4) instead of %(\16) strcat(keysPointer, dataSplitStr); } else { strcat(keysPointer, arraySplitStr); } - // We use memcpy rather than strcat here because it would append \0, + // We use memcpy rather than strcat here because it would append \0, // thus terminating the string prematurely valuesPointer -= strlen(value) + 1; - + memcpy(valuesPointer, value, strlen(value)); if (i == 0) { @@ -304,7 +305,7 @@ ArancinoPacket ArancinoClass::mset(char** keys, char** values, uint len) { vTaskSuspendAll(); } #endif - + _sendArancinoCommand(str); char* message = _receiveArancinoResponse(END_TX_CHAR); #if defined(__SAMD21G18A__) && defined(USEFREERTOS) @@ -338,7 +339,7 @@ template<> ArancinoPacket ArancinoClass::mget(char** keys, uint // Calculating Cortex Protocol command length for (uint i = 0; i < len; i ++) { char* key = keys[i]; - + uint keyLength = strlen(key); // if arancino_id has to be prepended we take into account its length and _ char @@ -368,7 +369,7 @@ template<> ArancinoPacket ArancinoClass::mget(char** keys, uint } strcat(str, endTXStr); - + #if defined(__SAMD21G18A__) if(!digitalRead(DBG_PIN)){ Serial.print(SENT_STRING); @@ -381,7 +382,7 @@ template<> ArancinoPacket ArancinoClass::mget(char** keys, uint vTaskSuspendAll(); } #endif - + _sendArancinoCommand(str); char* message = _receiveArancinoResponse(END_TX_CHAR); #if defined(__SAMD21G18A__) && defined(USEFREERTOS) @@ -431,10 +432,15 @@ ArancinoPacket ArancinoClass::set( char* key, long value, bool isPersistent) { return set(key, str, isPersistent); } +ArancinoPacket ArancinoClass::set( char* key, float value, bool isPersistent) { + char str[20] = ""; + _floatToString(value, decimal_digits, str); + return set(key, str, isPersistent); +} ArancinoPacket ArancinoClass::set( char* key, double value, bool isPersistent) { char str[20] = ""; - _doubleToString(value, 4, str); + _doubleToString(value, decimal_digits, str); return set(key, str, isPersistent); } @@ -707,9 +713,15 @@ ArancinoPacket ArancinoClass::hset( char* key, char* field, int value ) { return hset(key, field, str); } +ArancinoPacket ArancinoClass::hset( char* key, char* field, float value ) { + char str[20] = ""; + _floatToString(value, decimal_digits, str); + return hset(key, field, str); +} + ArancinoPacket ArancinoClass::hset( char* key, char* field, double value ) { char str[20] = ""; - _doubleToString(value, 4, str); + _doubleToString(value, decimal_digits, str); return hset(key, field, str); } @@ -1292,7 +1304,7 @@ template<> ArancinoPacket ArancinoClass::keys (char* pattern){ } } else{ - packet = invalidCommandErrorPacket; + packet = invalidCommandErrorPacket; } return packet; @@ -1396,7 +1408,7 @@ ArancinoPacket ArancinoClass::__publish(char* channel, char* msg) { ArancinoPacket ArancinoClass::publish(char* channel, double msg){ char str[20] = ""; - _doubleToString(msg, 4, str); + _doubleToString(msg, decimal_digits, str); return __publish(channel, str); } @@ -1514,25 +1526,25 @@ bool ArancinoClass::isValidUTF8(const char * string) //From: https://stackoverfl { if ((*bytes & 0x80) == 0x00) { - // U+0000 to U+007F + // U+0000 to U+007F cp = (*bytes & 0x7F); num = 1; } else if ((*bytes & 0xE0) == 0xC0) { - // U+0080 to U+07FF + // U+0080 to U+07FF cp = (*bytes & 0x1F); num = 2; } else if ((*bytes & 0xF0) == 0xE0) { - // U+0800 to U+FFFF + // U+0800 to U+FFFF cp = (*bytes & 0x0F); num = 3; } else if ((*bytes & 0xF8) == 0xF0) { - // U+10000 to U+10FFFF + // U+10000 to U+10FFFF cp = (*bytes & 0x07); num = 4; } @@ -1575,9 +1587,15 @@ void ArancinoClass::print(int value) { print(str); } +/*void ArancinoClass::print(float value) { + char str[20] = ""; + _floatToString(value, decimal_digits, str); + print(str); +}*/ + void ArancinoClass::print(double value) { char str[20] = ""; - _doubleToString(value, 4, str); + _doubleToString(value, decimal_digits, str); print(str); } @@ -1592,9 +1610,16 @@ void ArancinoClass::println(int value) { print("\n"); } +/*void ArancinoClass::println(float value) { + char str[20] = ""; + _floatToString(value, decimal_digits, str); + print(str); + print("\n"); +}*/ + void ArancinoClass::println(double value) { char str[20] = ""; - _doubleToString(value, 4, str); + _doubleToString(value, decimal_digits, str); print(str); print("\n"); } @@ -1618,7 +1643,7 @@ int ArancinoClass::getArraySize(String* _array) { void ArancinoClass::_sendArancinoCommand(char* command) { //check communication timeout with arancino module if (comm_timeout){ - /* + /* Flush data on serial communication to avoid of lost synchronization between arancino library and arancino module. By this way I prevent to receive reposonse of a previous sent command. @@ -1661,7 +1686,7 @@ char* ArancinoClass::_receiveArancinoResponse(char terminator) { if( str == ""){ //enable timeout check comm_timeout = true; - } + } else { int responseLength = strlen(str.begin()); if (responseLength > 0) @@ -1685,32 +1710,36 @@ bool ArancinoClass::_isReservedKey(char* key) { return false; } -void ArancinoClass::_doubleToString(double value, unsigned int _nDecimal, char* str) {//truncation! - uint8_t sign = (value < 0); - uint8_t dot = (_nDecimal > 0); - long integer = ( sign ? ceil(value) : floor(value) ); - double _decimal = (value - integer); //without integer part - integer = abs(integer); - - for (int i = 0; i < _nDecimal; i++) - _decimal *= 10; - - long decimal = (_decimal < 0) ? ceil(_decimal - 0.5) : floor(_decimal + 0.5); - decimal = abs(decimal); - - int integerDigit = integer != 0 ? _getDigit(integer) : 1; - int decimalDigit = _nDecimal; +void ArancinoClass::_doubleToString(double value, unsigned int _nDecimal, char* str) { + char val[20]=""; + sprintf(val, "%d", int(value)); + int valueLength=strlen(val); + Serial.println(val); + Serial.println(valueLength); + Serial.println(_nDecimal); + if(valueLength+_nDecimal>15){ //The double data type has 15 decimal digits of precision + _nDecimal=15-valueLength; + if(_nDecimal<0){ + _nDecimal=0; + } + } + dtostrf(value, valueLength, _nDecimal, str); +} - str[0] = '-'; - ltoa(integer, &str[sign], 10); - if (dot) - { - str[sign + integerDigit] = '.'; - ltoa(decimal, &str[sign + integerDigit + 1], 10); - for (int i = 1; decimal == 0 && i < decimalDigit; i++) - ltoa(decimal, &str[sign + integerDigit + i + 1], 10); - } - str[sign + integerDigit + dot + decimalDigit] = '\0'; +void ArancinoClass::_floatToString(float value, unsigned int _nDecimal, char* str) { + char val[20]=""; + sprintf(val, "%d", int(value)); + int valueLength=strlen(val); + Serial.println(val); + Serial.println(valueLength); + Serial.println(_nDecimal); + if(valueLength+_nDecimal>7){ //The float data type has 7 decimal digits of precision + _nDecimal=7-valueLength; + if(_nDecimal<0){ + _nDecimal=0; + } + } + dtostrf(value, valueLength, _nDecimal, str); } int ArancinoClass::_getDigit(long value) { @@ -1879,7 +1908,7 @@ char** ArancinoClass::_parseArray(char* data) { DSCIndex = strchr(previousDSCIndex + 1, DATA_SPLIT_CHAR); if (DSCIndex != NULL) - { + { if (strncmp(previousDSCIndex, nullStr, DSCIndex - previousDSCIndex) == 0){ arrayParsed[i] = NULL; } else { diff --git a/src/Arancino.h b/src/Arancino.h index 82a6f08..8041960 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -32,7 +32,7 @@ under the License //#define USEFREERTOS #if defined(__SAMD21G18A__) && defined(USEFREERTOS) - + // #if !defined(__MEM_WRAP__) // #error You are using Arancino Library, please select Menu -> Tools -> Using Arancino Library?: Yes // #endif @@ -42,7 +42,7 @@ extern "C" { } #endif - + @@ -104,14 +104,14 @@ class ArancinoClass { //Serial port id char *id; - + //START SCHEDULER void startScheduler(); - + //SET RESERVED COMMUNICATION MODE void setReservedCommunicationMode(int mode); - + /***** API BASIC *****/ void metadata(ArancinoMetadata amdata); @@ -124,7 +124,7 @@ class ArancinoClass { //MSET ArancinoPacket mset(char** keys, char** values, uint len); - //SET + //SET // ArancinoPacket set(char* key, int value); // ArancinoPacket set(char* key, double value); // ArancinoPacket set(char* key, uint32_t value); @@ -132,10 +132,11 @@ class ArancinoClass { ArancinoPacket set(char* key, int value, bool isPersistent = false); ArancinoPacket set(char* key, double value, bool isPersistent = false); + ArancinoPacket set(char* key, float value, bool isPersistent = false); ArancinoPacket set(char* key, long value, bool isPersistent = false); - ArancinoPacket set(char* key, char* value, bool isPersistent = false); - ArancinoPacket set(char* key, uint32_t value, bool isPersistent = false); - + ArancinoPacket set(char* key, char* value, bool isPersistent = false); + ArancinoPacket set(char* key, uint32_t value, bool isPersistent = false); + //GET //ArancinoPacket getPacket(char* key); //char* get(char* key); @@ -152,13 +153,14 @@ class ArancinoClass { //HSET ArancinoPacket hset(char* key, char* field, char* value); ArancinoPacket hset(char* key, char* field, int value); + ArancinoPacket hset(char* key, char* field, float value); ArancinoPacket hset(char* key, char* field, double value); ArancinoPacket hset(char* key, char* field, uint32_t value); ArancinoPacket hset(char* key, char* field, long value); //MGET template T mget(char** keys, uint len); - + //HGET // ArancinoPacket hgetPacket(char* key, char* field); // char* hget(char* key, char* field); @@ -195,13 +197,13 @@ class ArancinoClass { //KEYS W TEMPALTE template T keys(char* pattern="*"); - //PUBLISH + //PUBLISH ArancinoPacket publish(char* channel, char* msg); ArancinoPacket publish(char* channel, double msg); ArancinoPacket publish(char* channel, int msg); ArancinoPacket publish(char* channel, uint32_t msg); ArancinoPacket publish(char* channel, long msg); - + //FLUSH ArancinoPacket flush(void); @@ -237,9 +239,10 @@ class ArancinoClass { bool started; bool comm_timeout = false; bool arancino_id_prefix; + int decimal_digits; int idSize; char *timestamp; - + char reservedKey[RESERVED_KEY_ARRAY_SIZE][RESERVED_KEY_MAX_LENGTH]; //max 10 char for key int COMM_MODE = SYNCH; const char dataSplitStr[2] = {DATA_SPLIT_CHAR, '\0'}; @@ -256,7 +259,7 @@ class ArancinoClass { //API WRAPPED void _freeArray(char** _array); void _freePacket(ArancinoPacket packet); - + ArancinoPacket __set(char* key, char* value, bool isPersistent); ArancinoPacket __publish(char* channel, char* msg); @@ -266,17 +269,18 @@ class ArancinoClass { void _sendArancinoCommand(char command); char* _receiveArancinoResponse(char terminator); - + //bool _isReservedKey(String key); bool _isReservedKey(char* key); void _doubleToString(double value, unsigned int _nDecimal, char* str); //truncation! + void _floatToString(float value, unsigned int _nDecimal, char* str); int _getDigit(long value); - + // ArancinoPacket _sendViaCOMM_MODE(char* key, char* value); ArancinoPacket _sendViaCOMM_MODE(char* key, char* value, bool isPersistent = false); int _getResponseCode(char* data); - + char* _parse(char* message); char** _parseArray(char* message); @@ -286,7 +290,7 @@ class ArancinoClass { // ArancinoPacket _delPacket(char* key); // int _del(char* key); - + // ArancinoPacket _hgetPacket(char* key, char* field); // char* _hget(char* key, char* field); diff --git a/src/ArancinoConfig.h b/src/ArancinoConfig.h index 1579670..879b324 100644 --- a/src/ArancinoConfig.h +++ b/src/ArancinoConfig.h @@ -24,5 +24,7 @@ class ArancinoConfig{ public: bool _USEID = false; int _TIMEOUT = TIMEOUT; - -}; \ No newline at end of file + bool USE_ID = false; + int SERIAL_TIMEOUT = 100; //timeout 100 ms + int DECIMAL_DIGITS = 4; //4 decimal digits (float and double type) +}; From 6ad7928a65e377ac2aa9568df82e1dc9b6aea45e Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 2 Apr 2021 11:17:02 +0200 Subject: [PATCH 4/9] update doc --- README.md | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 079c476..fa2c23d 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,25 @@ typedef struct { ### ArancinoConfig `ArancinoConfig` is class composed only by attributes used to configure the Arancino Library behaviour. It replaces the use of direct configuration arguments of the `begin` function. ```c++ - bool _USEID = false; - int _TIMEOUT = TIMEOUT; // 100 ms for samd21 - int DECIMAL_DIGITS = 4; + int _TIMEOUT = 100 ; // *DEPRECATED* Use SERIAL_TIMEOUT + bool _USEID; // *DEPRECATED* Use USE_PORT_ID_PREFIX_KEY + int DECIMAL_DIGITS = 4; + int SERIAL_TIMEOUT = 100; + bool USE_PORT_ID_PREFIX_KEY = false; + ``` +- **`SERIAL_TIMEOUT`**: Represents the time that each command sent (via API call) will wait + for a response. Otherwise the delayed command will be skipped. When the + `begin` function is called w/o `timeout` it is assumed `100ms` as + default value of timeout. +- **`USE_PORT_ID_PREFIX_KEY`**: Default `false`. If `true` each key setted up is prefixed with ID of the microntroller. + It's useful when you connect multiple microntroller with the same firmware (using the same keys) to + one Arancino Module; By this way, at the application level, you can distinguish keys by + microntroller id. +- **`DECIMAL_DIGITS`**: Default `4`. Represents the number to the right of the decimal point for the float and double data types. + Float data type has 7 digits, while double data type has up to 15 digits, including decimal digits. + If the digits exceed the maximum allowed for the type(float or double), the decimal part will be truncated and rounded up or rounded down. ##### Variables * `isError`: indicates the outcome of an API call. Its value is `False` (0) when everything is OK or `True` (1) when an error occurs. Both in positive and negative cases is possible to check `responseCode` for more details; @@ -161,27 +175,15 @@ From version `1.4.0` the `ArancinoMetadata` argument became mandatory, becouse t From version ##### Parameters -- ArancinoConfig: is class composed only by attributes: - - `_TIMEOUT`: (see the following paragraph: `timeout`) - - `_USEID`: (see the following paragraph: `useid`) - - `DECIMAL_DIGITS`: (see the following paragraph: `decimal_digits`) - -The convenience of using class X is to be able to increase the number of parameters without necessarily having to change the prototypes. - - -The use of the following is deprecated and will be remove in the next major release. -- **`timeout`**: Represents the time that each command sent (via API call) will wait - for a response. Otherwise the delayed command will be skipped. When the - `begin` function is called w/o `timeout` it is assumed `100ms` as - default value of timeout. -- **`useid`**: Default `false`. If `true` each key setted up is prefixed with ID of the microntroller. - It's useful when you connect multiple microntroller with the same firmware (using the same keys) to - one Arancino Module; By this way, at the application level, you can distinguish keys by - microntroller id. -- **`decimal_digits`**: Default `4`. Represents the number to the right of the decimal point for the float and double data types. - With float data type is possible to represent 7 decimal digits of precision, while with double data type - has up to 15 digits. The decimal digits of precision is the total number of digits, not the number to the right of the decimal point. - There is a check to verify the number of digits and if the number exceed the maximum allowed for the type(float or double), the decimal part will be truncate (rounded up or rounded down). +- ArancinoConfig: is class composed only by attributes (see the following paragraph: [`Arancino Config`](#ArancinoConfig)): + - `DECIMAL_DIGITS` + - `SERIAL_TIMEOUT` + - `PORT_ID_PREFIX_KEY` + +The convenience of using class ArancinoConfig is to be able to increase the number of parameters without necessarily having to change the prototypes. +The use of the following arguments in the `begin` function is deprecated and will be removed in the next major release. +- **`timeout`** +- **`useid`** ___ ### set From ca8047059a7792eea5ec98fb4615c464340874f4 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 2 Apr 2021 11:24:04 +0200 Subject: [PATCH 5/9] update version number --- library.json | 2 +- library.properties | 2 +- src/ArancinoDefinitions.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index 2e49651..02ac1e8 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/smartmeio/arancino-library.git" }, - "version": "1.4.0", + "version": "1.4.1", "authors": { "name": "smartme.IO", "url": "https://www.arancino.cc" diff --git a/library.properties b/library.properties index 812fb82..ccd6165 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arancino -version=1.4.0 +version=1.4.1 author=smartme.IO maintainer=smartme.IO sentence=Enables communication between microcontroller and Arancino Module running mainly in Arancino boards. diff --git a/src/ArancinoDefinitions.h b/src/ArancinoDefinitions.h index ae81ec1..4b48d60 100644 --- a/src/ArancinoDefinitions.h +++ b/src/ArancinoDefinitions.h @@ -78,7 +78,7 @@ under the License #define LIBVERS_KEY "___LIBVERS___" #define MODVERS_KEY "___MODVERS___" #define POWER_KEY "___POWER___" -#define LIB_VERSION "1.4.0" //library version +#define LIB_VERSION "1.4.1" //library version //RESPONSE CODE #define INVALID_VALUE_ERROR -4 From bacb9574d81593e692bafc45c54640a3dee0508e Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 2 Apr 2021 11:24:50 +0200 Subject: [PATCH 6/9] fix println --- src/Arancino.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 36364e3..7d6489f 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -1606,8 +1606,7 @@ void ArancinoClass::println(String value) { } void ArancinoClass::println(int value) { - print(String(value)); - print("\n"); + print(String(value) + String('\n')) ; } /*void ArancinoClass::println(float value) { From f83b69901caedc13aab59a536d800ef810b54b7e Mon Sep 17 00:00:00 2001 From: andrea-83 Date: Tue, 6 Apr 2021 11:33:06 +0200 Subject: [PATCH 7/9] upd: updated arancinoConfig parameter --- CHANGELOG.md | 1 + examples/Arancino/00-BEGIN/00-BEGIN.ino | 2 +- src/Arancino.cpp | 30 ++++++++----------------- src/Arancino.h | 2 ++ src/ArancinoConfig.h | 2 +- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7b5a62..aa67d1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog #### v 1.4.1 - 2021.04.02 +* Fix: Fixed bug with `println` function. [#gk5z1y](https://app.clickup.com/t/gk5z1y) * Fix: Fixed bug with float's and double's types in `set` function. [#g71qk9](https://app.clickup.com/t/g71qk9) #### v 1.4.0 - 2021.03.15 diff --git a/examples/Arancino/00-BEGIN/00-BEGIN.ino b/examples/Arancino/00-BEGIN/00-BEGIN.ino index c6aa430..6c75b4a 100644 --- a/examples/Arancino/00-BEGIN/00-BEGIN.ino +++ b/examples/Arancino/00-BEGIN/00-BEGIN.ino @@ -61,7 +61,7 @@ void setup() { // Arancino Configuration ArancinoConfig acfg; - acfg._TIMEOUT = 200; + acfg.SERIAL_TIMEOUT = 200; acfg.DECIMAL_DIGITS=4; //calls begin w/o paramenter: it is assumed 100ms timeout by default diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 7d6489f..a5d5d1c 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -80,16 +80,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { SERIAL_PORT.begin(BAUDRATE); // SERIAL_PORT.setTimeout(TIMEOUT); // arancino_id_prefix = false; - arancino_id_prefix = _acfg._USEID; - SERIAL_PORT.setTimeout(_acfg._TIMEOUT); + arancino_id_prefix = _acfg.USE_PORT_ID_PREFIX_KEY; + SERIAL_PORT.setTimeout(_acfg.SERIAL_TIMEOUT); decimal_digits=_acfg.DECIMAL_DIGITS; _metadata = _amdata; - /*Serial.begin(115200); - Serial.println(_acfg._USEID); - Serial.println(_acfg._TIMEOUT);*/ - int fwnameLength = strlen(_metadata.fwname); int fwversionLength = strlen(_metadata.fwversion); int localtoffsetLength = strlen(_metadata.tzoffset); @@ -1587,11 +1583,11 @@ void ArancinoClass::print(int value) { print(str); } -/*void ArancinoClass::print(float value) { +void ArancinoClass::print(float value) { char str[20] = ""; _floatToString(value, decimal_digits, str); print(str); -}*/ +} void ArancinoClass::print(double value) { char str[20] = ""; @@ -1606,21 +1602,19 @@ void ArancinoClass::println(String value) { } void ArancinoClass::println(int value) { - print(String(value) + String('\n')) ; + print(String(value)+String('\n')); } -/*void ArancinoClass::println(float value) { +void ArancinoClass::println(float value) { char str[20] = ""; _floatToString(value, decimal_digits, str); - print(str); - print("\n"); -}*/ + print(str+String('\n')); +} void ArancinoClass::println(double value) { char str[20] = ""; _doubleToString(value, decimal_digits, str); - print(str); - print("\n"); + print(str+String('\n')); } // ???? @@ -1713,9 +1707,6 @@ void ArancinoClass::_doubleToString(double value, unsigned int _nDecimal, char* char val[20]=""; sprintf(val, "%d", int(value)); int valueLength=strlen(val); - Serial.println(val); - Serial.println(valueLength); - Serial.println(_nDecimal); if(valueLength+_nDecimal>15){ //The double data type has 15 decimal digits of precision _nDecimal=15-valueLength; if(_nDecimal<0){ @@ -1729,9 +1720,6 @@ void ArancinoClass::_floatToString(float value, unsigned int _nDecimal, char* st char val[20]=""; sprintf(val, "%d", int(value)); int valueLength=strlen(val); - Serial.println(val); - Serial.println(valueLength); - Serial.println(_nDecimal); if(valueLength+_nDecimal>7){ //The float data type has 7 decimal digits of precision _nDecimal=7-valueLength; if(_nDecimal<0){ diff --git a/src/Arancino.h b/src/Arancino.h index 8041960..a11f335 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -217,10 +217,12 @@ class ArancinoClass { void print(String value); void print(char* value); void print(int value); + void print(float value); void print(double value); void println(String value); void println(int value); void println(double value); + void println(float value); //GET ARRAY SIZE int getArraySize(char** _array); diff --git a/src/ArancinoConfig.h b/src/ArancinoConfig.h index 879b324..ba9f622 100644 --- a/src/ArancinoConfig.h +++ b/src/ArancinoConfig.h @@ -24,7 +24,7 @@ class ArancinoConfig{ public: bool _USEID = false; int _TIMEOUT = TIMEOUT; - bool USE_ID = false; + bool USE_PORT_ID_PREFIX_KEY = false; int SERIAL_TIMEOUT = 100; //timeout 100 ms int DECIMAL_DIGITS = 4; //4 decimal digits (float and double type) }; From a36f0434d3d36df517de30ff148eb2d84a0dbfaf Mon Sep 17 00:00:00 2001 From: andrea-83 Date: Tue, 6 Apr 2021 11:33:06 +0200 Subject: [PATCH 8/9] fix: add float in println and updated arancinoConfig parameter #CU-gk5z1y --- CHANGELOG.md | 1 + examples/Arancino/00-BEGIN/00-BEGIN.ino | 2 +- src/Arancino.cpp | 30 ++++++++----------------- src/Arancino.h | 2 ++ src/ArancinoConfig.h | 2 +- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7b5a62..aa67d1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog #### v 1.4.1 - 2021.04.02 +* Fix: Fixed bug with `println` function. [#gk5z1y](https://app.clickup.com/t/gk5z1y) * Fix: Fixed bug with float's and double's types in `set` function. [#g71qk9](https://app.clickup.com/t/g71qk9) #### v 1.4.0 - 2021.03.15 diff --git a/examples/Arancino/00-BEGIN/00-BEGIN.ino b/examples/Arancino/00-BEGIN/00-BEGIN.ino index c6aa430..6c75b4a 100644 --- a/examples/Arancino/00-BEGIN/00-BEGIN.ino +++ b/examples/Arancino/00-BEGIN/00-BEGIN.ino @@ -61,7 +61,7 @@ void setup() { // Arancino Configuration ArancinoConfig acfg; - acfg._TIMEOUT = 200; + acfg.SERIAL_TIMEOUT = 200; acfg.DECIMAL_DIGITS=4; //calls begin w/o paramenter: it is assumed 100ms timeout by default diff --git a/src/Arancino.cpp b/src/Arancino.cpp index 7d6489f..a5d5d1c 100644 --- a/src/Arancino.cpp +++ b/src/Arancino.cpp @@ -80,16 +80,12 @@ void ArancinoClass::begin(ArancinoMetadata _amdata, ArancinoConfig _acfg) { SERIAL_PORT.begin(BAUDRATE); // SERIAL_PORT.setTimeout(TIMEOUT); // arancino_id_prefix = false; - arancino_id_prefix = _acfg._USEID; - SERIAL_PORT.setTimeout(_acfg._TIMEOUT); + arancino_id_prefix = _acfg.USE_PORT_ID_PREFIX_KEY; + SERIAL_PORT.setTimeout(_acfg.SERIAL_TIMEOUT); decimal_digits=_acfg.DECIMAL_DIGITS; _metadata = _amdata; - /*Serial.begin(115200); - Serial.println(_acfg._USEID); - Serial.println(_acfg._TIMEOUT);*/ - int fwnameLength = strlen(_metadata.fwname); int fwversionLength = strlen(_metadata.fwversion); int localtoffsetLength = strlen(_metadata.tzoffset); @@ -1587,11 +1583,11 @@ void ArancinoClass::print(int value) { print(str); } -/*void ArancinoClass::print(float value) { +void ArancinoClass::print(float value) { char str[20] = ""; _floatToString(value, decimal_digits, str); print(str); -}*/ +} void ArancinoClass::print(double value) { char str[20] = ""; @@ -1606,21 +1602,19 @@ void ArancinoClass::println(String value) { } void ArancinoClass::println(int value) { - print(String(value) + String('\n')) ; + print(String(value)+String('\n')); } -/*void ArancinoClass::println(float value) { +void ArancinoClass::println(float value) { char str[20] = ""; _floatToString(value, decimal_digits, str); - print(str); - print("\n"); -}*/ + print(str+String('\n')); +} void ArancinoClass::println(double value) { char str[20] = ""; _doubleToString(value, decimal_digits, str); - print(str); - print("\n"); + print(str+String('\n')); } // ???? @@ -1713,9 +1707,6 @@ void ArancinoClass::_doubleToString(double value, unsigned int _nDecimal, char* char val[20]=""; sprintf(val, "%d", int(value)); int valueLength=strlen(val); - Serial.println(val); - Serial.println(valueLength); - Serial.println(_nDecimal); if(valueLength+_nDecimal>15){ //The double data type has 15 decimal digits of precision _nDecimal=15-valueLength; if(_nDecimal<0){ @@ -1729,9 +1720,6 @@ void ArancinoClass::_floatToString(float value, unsigned int _nDecimal, char* st char val[20]=""; sprintf(val, "%d", int(value)); int valueLength=strlen(val); - Serial.println(val); - Serial.println(valueLength); - Serial.println(_nDecimal); if(valueLength+_nDecimal>7){ //The float data type has 7 decimal digits of precision _nDecimal=7-valueLength; if(_nDecimal<0){ diff --git a/src/Arancino.h b/src/Arancino.h index 8041960..a11f335 100644 --- a/src/Arancino.h +++ b/src/Arancino.h @@ -217,10 +217,12 @@ class ArancinoClass { void print(String value); void print(char* value); void print(int value); + void print(float value); void print(double value); void println(String value); void println(int value); void println(double value); + void println(float value); //GET ARRAY SIZE int getArraySize(char** _array); diff --git a/src/ArancinoConfig.h b/src/ArancinoConfig.h index 879b324..ba9f622 100644 --- a/src/ArancinoConfig.h +++ b/src/ArancinoConfig.h @@ -24,7 +24,7 @@ class ArancinoConfig{ public: bool _USEID = false; int _TIMEOUT = TIMEOUT; - bool USE_ID = false; + bool USE_PORT_ID_PREFIX_KEY = false; int SERIAL_TIMEOUT = 100; //timeout 100 ms int DECIMAL_DIGITS = 4; //4 decimal digits (float and double type) }; From 4b8944be97e4a204191866892fdd07759209880f Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 6 Apr 2021 16:23:58 +0200 Subject: [PATCH 9/9] upd release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa67d1b..72ba244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -#### v 1.4.1 - 2021.04.02 +#### v 1.4.1 - 2021.04.06 * Fix: Fixed bug with `println` function. [#gk5z1y](https://app.clickup.com/t/gk5z1y) * Fix: Fixed bug with float's and double's types in `set` function. [#g71qk9](https://app.clickup.com/t/g71qk9)