- New API calls stateName(), stateName(state)

- No out of bounds error messages in TWIZY_DEBUG_LEVEL 0
- Donors update
This commit is contained in:
Michael Balzer 2017-08-17 22:59:15 +02:00
parent ee4e5ae7a2
commit ce7c6e8311
10 changed files with 45 additions and 23 deletions

1
API.md
View file

@ -173,6 +173,7 @@ See [protocol documentation](extras/Protocol.ods) for details.
__API:__ __API:__
- `TwizyState state()` -- Query current state - `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 - `bool inState(TwizyState state1 [, … state5])` -- Test for 1-5 states
- `void enterState(TwizyState newState)` -- Force a state change - `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. - Call `enterState(StopCharge)` to stop a running charge process. Note that `setChargeCurrent(0)` will do so as well.

View file

@ -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:* *The following people have won our eternal love and respect by kindly supporting this project:*
- Bryce Nash
- Michael Langerhorst
- **Andreas Schmidt** - **Andreas Schmidt**
- Philip Despriet - Philip Despriet
- **Błażej Błaszczyk** :) - **Błażej Błaszczyk** :)

View file

@ -1,5 +1,11 @@
# History # 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) ## Version 1.2.0 (2017-07-29)
- Ticker increments clockCnt on exit (first hook call with clockCnt=0) - Ticker increments clockCnt on exit (first hook call with clockCnt=0)

View file

@ -351,7 +351,7 @@ void bmsTicker(unsigned int clockCnt) {
// bmsTicker: Output state to bluetooth port // bmsTicker: Output state to bluetooth port
// //
bt.print(FS(twizyStateName[twizy.state()])); bt.print(twizy.stateName());
bt.print(F(" -- ")); bt.print(F(" -- "));
bt.print(temp, 1); bt.print(F(" °C -- ")); bt.print(temp, 1); bt.print(F(" °C -- "));
bt.print(soc, 1); bt.print(F(" %SOC -- ")); bt.print(soc, 1); bt.print(F(" %SOC -- "));

View file

@ -8,8 +8,8 @@
#define _TwizyVirtualBMS_config_h #define _TwizyVirtualBMS_config_h
// Serial debug output: // Serial debug output:
// Level 0 = none, only output init & error messages // Level 0 = none, only output init message
// Level 1 = log state transitions & CAN statistics // Level 1 = log state transitions, errors & CAN statistics
// Level 2 = log CAN frame dumps (10 second interval) // Level 2 = log CAN frame dumps (10 second interval)
#define TWIZY_DEBUG_LEVEL 1 #define TWIZY_DEBUG_LEVEL 1

View file

@ -8,8 +8,8 @@
#define _TwizyVirtualBMS_config_h #define _TwizyVirtualBMS_config_h
// Serial debug output: // Serial debug output:
// Level 0 = none, only output init & error messages // Level 0 = none, only output init message
// Level 1 = log state transitions & CAN statistics // Level 1 = log state transitions, errors & CAN statistics
// Level 2 = log CAN frame dumps (10 second interval) // Level 2 = log CAN frame dumps (10 second interval)
#define TWIZY_DEBUG_LEVEL 1 #define TWIZY_DEBUG_LEVEL 1

View file

@ -8,8 +8,8 @@
#define _TwizyVirtualBMS_config_h #define _TwizyVirtualBMS_config_h
// Serial debug output: // Serial debug output:
// Level 0 = none, only output init & error messages // Level 0 = none, only output init message
// Level 1 = log state transitions & CAN statistics // Level 1 = log state transitions, errors & CAN statistics
// Level 2 = log CAN frame dumps (10 second interval) // Level 2 = log CAN frame dumps (10 second interval)
#define TWIZY_DEBUG_LEVEL 1 #define TWIZY_DEBUG_LEVEL 1

View file

@ -42,6 +42,7 @@ sendMsg KEYWORD2
setCanFilter KEYWORD2 setCanFilter KEYWORD2
state KEYWORD2 state KEYWORD2
stateName KEYWORD2
inState KEYWORD2 inState KEYWORD2
enterState KEYWORD2 enterState KEYWORD2

View file

@ -1,5 +1,5 @@
name=Twizy Virtual BMS name=Twizy Virtual BMS
version=1.1.0 version=1.2.1
author=Michael Balzer author=Michael Balzer
maintainer=Michael Balzer <dexter@dexters-web.de> maintainer=Michael Balzer <dexter@dexters-web.de>
sentence=Emulation of Renault Twizy BMS (battery management system) sentence=Emulation of Renault Twizy BMS (battery management system)

View file

@ -38,7 +38,7 @@
#ifndef _TwizyVirtualBMS_h #ifndef _TwizyVirtualBMS_h
#define _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 #ifndef TWIZY_TAG
#define TWIZY_TAG "twizy." #define TWIZY_TAG "twizy."
@ -93,7 +93,6 @@ enum TwizyState {
}; };
// Twizy state names: // Twizy state names:
#if TWIZY_DEBUG_LEVEL >= 1
const char twizyStateName[13][13] PROGMEM = { const char twizyStateName[13][13] PROGMEM = {
"Off", "Off",
"Init", "Init",
@ -109,7 +108,6 @@ const char twizyStateName[13][13] PROGMEM = {
"Trickle", "Trickle",
"StopTrickle" "StopTrickle"
}; };
#endif
// Known error codes for setError(): // Known error codes for setError():
@ -139,16 +137,24 @@ typedef void (*TwizyProcessCanMsgCallback)(unsigned long rxId, byte rxLen, byte
#define FLASHSTRING const __FlashStringHelper #define FLASHSTRING const __FlashStringHelper
#define FS(x) (__FlashStringHelper*)(x) #define FS(x) (__FlashStringHelper*)(x)
// Parameter boundary check with error output: #if TWIZY_DEBUG_LEVEL >= 1
#define CHECKLIMIT(var, minval, maxval) \ // Parameter boundary check with error output:
if (var < minval || var > maxval) { \ #define CHECKLIMIT(var, minval, maxval) \
Serial.print(TWIZY_TAG); \ if (var < minval || var > maxval) { \
Serial.print(__func__); \ Serial.print(TWIZY_TAG); \
Serial.print(F(": ERROR " #var "=")); \ Serial.print(__func__); \
Serial.print(var); \ Serial.print(F(": ERROR " #var "=")); \
Serial.println(F(" out of bounds [" #minval "," #maxval "]")); \ Serial.print(var); \
return false; \ 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() { TwizyState state() {
return twizyState; return twizyState;
} }
FLASHSTRING *stateName(TwizyState state) {
return FS(twizyStateName[state]);
}
FLASHSTRING *stateName() {
return FS(twizyStateName[twizyState]);
}
bool inState(TwizyState state1) { bool inState(TwizyState state1) {
return (twizyState==state1); return (twizyState==state1);
} }
@ -851,7 +863,7 @@ void TwizyVirtualBMS::debugInfo() {
Serial.println(F("\n" TWIZY_TAG "debugInfo:")); Serial.println(F("\n" TWIZY_TAG "debugInfo:"));
Serial.print(F("- twizyState=")); Serial.print(F("- twizyState="));
Serial.println(FS(twizyStateName[twizyState])); Serial.println(stateName());
Serial.print(F("- clockCnt=")); Serial.print(F("- clockCnt="));
Serial.println(clockCnt); Serial.println(clockCnt);
@ -905,7 +917,7 @@ void TwizyVirtualBMS::enterState(TwizyState newState) {
#if TWIZY_DEBUG_LEVEL >= 1 #if TWIZY_DEBUG_LEVEL >= 1
Serial.print(F(TWIZY_TAG "enterState: newState=")); Serial.print(F(TWIZY_TAG "enterState: newState="));
Serial.println(FS(twizyStateName[newState])); Serial.println(stateName(newState));
#endif #endif
switch (newState) { switch (newState) {