From ce7c6e8311d917759b41ed3e91da09fa9b7f1728 Mon Sep 17 00:00:00 2001 From: Michael Balzer Date: Thu, 17 Aug 2017 22:59:15 +0200 Subject: [PATCH] - New API calls stateName(), stateName(state) - No out of bounds error messages in TWIZY_DEBUG_LEVEL 0 - Donors update --- API.md | 1 + DONORS.md | 2 + HISTORY.md | 6 +++ examples/BlazejBMS/BlazejBMS.ino | 2 +- examples/BlazejBMS/TwizyVirtualBMS_config.h | 4 +- examples/SimpleBMS/TwizyVirtualBMS_config.h | 4 +- examples/Template/TwizyVirtualBMS_config.h | 4 +- keywords.txt | 1 + library.properties | 2 +- src/TwizyVirtualBMS.h | 42 +++++++++++++-------- 10 files changed, 45 insertions(+), 23 deletions(-) diff --git a/API.md b/API.md index 7ad2339..7b84ceb 100644 --- a/API.md +++ b/API.md @@ -173,6 +173,7 @@ See [protocol documentation](extras/Protocol.ods) for details. __API:__ - `TwizyState state()` -- Query current state + - `FLASHSTRING *stateName([state])` -- Query name of current state / specific state - `bool inState(TwizyState state1 [, … state5])` -- Test for 1-5 states - `void enterState(TwizyState newState)` -- Force a state change - Call `enterState(StopCharge)` to stop a running charge process. Note that `setChargeCurrent(0)` will do so as well. diff --git a/DONORS.md b/DONORS.md index c37d511..fa45cea 100644 --- a/DONORS.md +++ b/DONORS.md @@ -9,6 +9,8 @@ Add a comment to your donation if you want to stay anonymous. *The following people have won our eternal love and respect by kindly supporting this project:* +- Bryce Nash +- Michael Langerhorst - **Andreas Schmidt** - Philip Despriet - **Błażej Błaszczyk** :) diff --git a/HISTORY.md b/HISTORY.md index 320d010..38d12f6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,11 @@ # History +## Version 1.2.1 (2017-08-17) + +- New API calls stateName(), stateName(state) +- No out of bounds error messages in TWIZY_DEBUG_LEVEL 0 + + ## Version 1.2.0 (2017-07-29) - Ticker increments clockCnt on exit (first hook call with clockCnt=0) diff --git a/examples/BlazejBMS/BlazejBMS.ino b/examples/BlazejBMS/BlazejBMS.ino index 815c2bd..e4d0c88 100644 --- a/examples/BlazejBMS/BlazejBMS.ino +++ b/examples/BlazejBMS/BlazejBMS.ino @@ -351,7 +351,7 @@ void bmsTicker(unsigned int clockCnt) { // bmsTicker: Output state to bluetooth port // - bt.print(FS(twizyStateName[twizy.state()])); + bt.print(twizy.stateName()); bt.print(F(" -- ")); bt.print(temp, 1); bt.print(F(" °C -- ")); bt.print(soc, 1); bt.print(F(" %SOC -- ")); diff --git a/examples/BlazejBMS/TwizyVirtualBMS_config.h b/examples/BlazejBMS/TwizyVirtualBMS_config.h index 257dfe0..b488991 100644 --- a/examples/BlazejBMS/TwizyVirtualBMS_config.h +++ b/examples/BlazejBMS/TwizyVirtualBMS_config.h @@ -8,8 +8,8 @@ #define _TwizyVirtualBMS_config_h // Serial debug output: -// Level 0 = none, only output init & error messages -// Level 1 = log state transitions & CAN statistics +// Level 0 = none, only output init message +// Level 1 = log state transitions, errors & CAN statistics // Level 2 = log CAN frame dumps (10 second interval) #define TWIZY_DEBUG_LEVEL 1 diff --git a/examples/SimpleBMS/TwizyVirtualBMS_config.h b/examples/SimpleBMS/TwizyVirtualBMS_config.h index 5953d8a..1d2bc34 100644 --- a/examples/SimpleBMS/TwizyVirtualBMS_config.h +++ b/examples/SimpleBMS/TwizyVirtualBMS_config.h @@ -8,8 +8,8 @@ #define _TwizyVirtualBMS_config_h // Serial debug output: -// Level 0 = none, only output init & error messages -// Level 1 = log state transitions & CAN statistics +// Level 0 = none, only output init message +// Level 1 = log state transitions, errors & CAN statistics // Level 2 = log CAN frame dumps (10 second interval) #define TWIZY_DEBUG_LEVEL 1 diff --git a/examples/Template/TwizyVirtualBMS_config.h b/examples/Template/TwizyVirtualBMS_config.h index 5953d8a..1d2bc34 100644 --- a/examples/Template/TwizyVirtualBMS_config.h +++ b/examples/Template/TwizyVirtualBMS_config.h @@ -8,8 +8,8 @@ #define _TwizyVirtualBMS_config_h // Serial debug output: -// Level 0 = none, only output init & error messages -// Level 1 = log state transitions & CAN statistics +// Level 0 = none, only output init message +// Level 1 = log state transitions, errors & CAN statistics // Level 2 = log CAN frame dumps (10 second interval) #define TWIZY_DEBUG_LEVEL 1 diff --git a/keywords.txt b/keywords.txt index 491b046..3ec3023 100644 --- a/keywords.txt +++ b/keywords.txt @@ -42,6 +42,7 @@ sendMsg KEYWORD2 setCanFilter KEYWORD2 state KEYWORD2 +stateName KEYWORD2 inState KEYWORD2 enterState KEYWORD2 diff --git a/library.properties b/library.properties index db96587..a9992c3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Twizy Virtual BMS -version=1.1.0 +version=1.2.1 author=Michael Balzer maintainer=Michael Balzer sentence=Emulation of Renault Twizy BMS (battery management system) diff --git a/src/TwizyVirtualBMS.h b/src/TwizyVirtualBMS.h index d5f7cae..e459a58 100644 --- a/src/TwizyVirtualBMS.h +++ b/src/TwizyVirtualBMS.h @@ -38,7 +38,7 @@ #ifndef _TwizyVirtualBMS_h #define _TwizyVirtualBMS_h -#define TWIZY_VBMS_VERSION "V1.2.0 (2017-07-29)" +#define TWIZY_VBMS_VERSION "V1.2.1 (2017-08-16)" #ifndef TWIZY_TAG #define TWIZY_TAG "twizy." @@ -93,7 +93,6 @@ enum TwizyState { }; // Twizy state names: -#if TWIZY_DEBUG_LEVEL >= 1 const char twizyStateName[13][13] PROGMEM = { "Off", "Init", @@ -109,7 +108,6 @@ const char twizyStateName[13][13] PROGMEM = { "Trickle", "StopTrickle" }; -#endif // Known error codes for setError(): @@ -139,16 +137,24 @@ typedef void (*TwizyProcessCanMsgCallback)(unsigned long rxId, byte rxLen, byte #define FLASHSTRING const __FlashStringHelper #define FS(x) (__FlashStringHelper*)(x) -// Parameter boundary check with error output: -#define CHECKLIMIT(var, minval, maxval) \ -if (var < minval || var > maxval) { \ - Serial.print(TWIZY_TAG); \ - Serial.print(__func__); \ - Serial.print(F(": ERROR " #var "=")); \ - Serial.print(var); \ - Serial.println(F(" out of bounds [" #minval "," #maxval "]")); \ - return false; \ -} +#if TWIZY_DEBUG_LEVEL >= 1 + // Parameter boundary check with error output: + #define CHECKLIMIT(var, minval, maxval) \ + if (var < minval || var > maxval) { \ + Serial.print(TWIZY_TAG); \ + Serial.print(__func__); \ + Serial.print(F(": ERROR " #var "=")); \ + Serial.print(var); \ + Serial.println(F(" out of bounds [" #minval "," #maxval "]")); \ + return false; \ + } +#else + // Parameter boundary check with quiet error: + #define CHECKLIMIT(var, minval, maxval) \ + if (var < minval || var > maxval) { \ + return false; \ + } +#endif // ----------------------------------------------------- @@ -216,6 +222,12 @@ public: TwizyState state() { return twizyState; } + FLASHSTRING *stateName(TwizyState state) { + return FS(twizyStateName[state]); + } + FLASHSTRING *stateName() { + return FS(twizyStateName[twizyState]); + } bool inState(TwizyState state1) { return (twizyState==state1); } @@ -851,7 +863,7 @@ void TwizyVirtualBMS::debugInfo() { Serial.println(F("\n" TWIZY_TAG "debugInfo:")); Serial.print(F("- twizyState=")); - Serial.println(FS(twizyStateName[twizyState])); + Serial.println(stateName()); Serial.print(F("- clockCnt=")); Serial.println(clockCnt); @@ -905,7 +917,7 @@ void TwizyVirtualBMS::enterState(TwizyState newState) { #if TWIZY_DEBUG_LEVEL >= 1 Serial.print(F(TWIZY_TAG "enterState: newState=")); - Serial.println(FS(twizyStateName[newState])); + Serial.println(stateName(newState)); #endif switch (newState) {