1 - <STG_STD>
Minimal configuration behavior
<STG_STD>
is a configuration behavior with minimal configuration items.
Example configuration screen
[CONFIG/MY_APP:0/SID=8102ECE3]
a: (0x1234ABCD) Application ID [HEX:32bit]
i: ( 1) Device ID [1-100,etc]
c: ( 13) Channel [11-26]
o: (0x00000000) Option Bits [HEX:32bit]
[ESC]:Back [!]:Reset System [M]:Extr Menu
This behavior hooks the input/output of the Serial
object and performs screen input/output in interactive mode. There is no need to explicitly write input processing in the application. Screen output from the application during the interactive mode screen is suppressed.
Pressing the M key allows access to auxiliary functions. Please refer to the
Extra Menu section at the end for features.
Usage
Registration
// use twelite mwx c++ template library
##include <TWELITE>
##include <NWK_SIMPLE>
##include <STG_STD> // interactive mode
Add #include <STG_STD>
as above.
Reading with setup()
uint32_t APP_ID;
uint8_t CHANNEL;
uint8_t LID;
void setup() {
...
auto&& set = the_twelite.settings.use<STG_STD>();
// call reload() before reading values.
set.reload();
// read value
APP_ID = set.u32appid();
CHANNEL = set.u8ch();
LID = set.u8devid();
// apply them
the_twelite
<< TWENET::appid(APP_ID)
<< TWENET::channel(CHANNEL);
auto&& nwk = the_twelite.network.use<NWK_SIMPLE>();
nwk << NWK_SIMPLE::logical_id(LID);
}
In most cases, reading the settings is done at an early stage in setup()
.
In the above example, first, the configuration behavior is registered by the_twelite.settings.use<STG_STD>()
.
Immediately after registration, you can change the configuration behavior such as changing the default application ID, but this will be described later.
Next, call set.reload()
to actually read data from EEPROM and interpret it. Note that it does not read automatically.
set.u32appid()
, set.u8ch()
, and set.u8devid()
retrieve the application ID setting, channel setting, and logical device ID setting, respectively. Here, the settings are stored in variables.
Because the internal data structure storing the settings is relatively complex, data search of the design array is required until the desired setting is obtained. If you are concerned about computational cost, please store the setting value in another variable once.
Then, the application ID, channel, and other values are applied using the setting values.
List of Settings
Below is the list of setting IDs (enum class E_STGSTD_SETID
) definitions.
Setting ID | Content |
---|
APPID | Application ID |
LOGICALID | Logical Device ID (8bit) |
CHANNEL | Channel |
CHANNELS_3 | Channel (up to 3 channels) |
POWER_N_RETRY | Power and retry count |
OPTBITS | Option 1 |
OPT_DWORD2 | Option 2 |
OPT_DWORD3 | Option 3 |
OPT_DWORD4 | Option 4 |
ENC_MODE | Encryption mode |
ENC_KEY_STRING | Encryption key (string input) |
<STG_STD>
defines representative settings and four freely usable 32bit values. These can be used freely by the user.
- Settings are not reflected just by reading from
<STG_STD>
. - Unnecessary items can be hidden.
- Item names and details can be changed.
Customizing the Configuration Behavior
Customize all items before calling .reload()
.
Application Name
auto&& set = the_twelite.settings.use<STG_STD>();
set << SETTINGS::appname("MY_APP");
...
set.reload();
The application name is displayed on the first line of the interactive mode.
[CONFIG/MY_APP:0/SID=8102ECE3]
Please specify a string pointer. Since no copy is made internally, local variables cannot be specified.
Default Values
auto&& set = the_twelite.settings.use<STG_STD>();
set << SETTINGS::appid_default(0x13579be);
set << SETTINGS::ch_default(18);
set << SETTINGS::lid_default(7);
...
set.reload();
Default values for application ID, frequency channel, and logical device ID (LID) can be changed.
auto&& set = the_twelite.settings.use<STG_STD>();
set << SETTINGS::ch_multi();
...
set.reload();
Specifying SETTINGS::ch_multi()
makes the channel setting multiple. When multiple settings are made, use .u32chmask()
to read the setting value.
auto&& set = the_twelite.settings.use<STG_STD>();
set << SETTINGS::open_at_start();
...
set.reload();
Default values for application ID, channel, and logical ID can be changed.
Changing Item Names and Description Content
const TWESTG_tsMsgReplace SET_MSGS[] = {
{ int(E_STGSTD_SETID::OPTBITS), "Option 1",
"Please set option 1" },
{ int(E_STGSTD_SETID::OPT_DWORD2), "Option 2",
"Please set option 2\r\nOption 2 is such and such" },
{ 0xFF } // terminator
};
setup() {
auto&& set = the_twelite.settings.use<STG_STD>();
set.replace_item_name_desc(SET_MSGS);
...
You can change the item name to another one. The above example uses Japanese in UTF-8, but it may not display properly unless conditions such as terminal display are met.
In TWELITE STAGE, if the number of registered font characters is reduced, some characters may not be displayed. Please rebuild to include the necessary strings.
This array ends with { 0xFF }
.
The first entry is the setting ID, the second is the item name, and the third is the explanation displayed during setting input. You can insert line breaks with \r
.
Determine Whether the Configuration Screen is Open
auto&& set = the_twelite.settings.use<STG_STD>();
if (!set.is_screen_opened()) {
// Processing when the configuration screen is not displayed
}
Outputting to serial during the configuration screen output may cause the screen to collapse. Confirm that the screen is not open with .is_screen_opened()
.
Deleting Items
auto&& set = the_twelite.settings.use<STG_STD>();
set.hide_items(E_STGSTD_SETID::OPT_DWORD3, E_STGSTD_SETID::OPT_DWORD4);
...
if(set.is_hidden(E_STGSTD_SETID::OPT_DWORD3) {
; // OPT_DWORD3 is hidden
}
Delete unnecessary items. .hide_items
hides unnecessary items by specifying item IDs as parameters (multiple can be specified as variadic arguments). Whether an item is hidden can be checked with .is_hidden()
.
Application ID, channel, and logical ID (LID) cannot be deleted.
Hidden settings use internal work memory. Since the minimum memory size is 32 bytes, if many hidden items are set, some may not be hidden due to memory shortage. The work memory size can be specified as a compile argument like -DSIZE_SETSTD_CUST_COMMON=48
.
Methods
reload()
auto&& set = the_twelite.settings.use<STG_STD>();
set << SETTINGS::appname(APP_NAME)
<< SETTINGS::appid_default(DEF_APP_ID)
<< SETTINGS::open_at_start();
set.reload();
Reads the settings. Execute after all customizations are finished.
Methods (Data Reading)
Call the following methods to read data.
Be sure to call .reload()
before reading.
Method | Content |
---|
uint32_t u32appid() | Application ID |
uint8_t u8devid() | Logical Device ID |
uint8_t u8ch() | Configured channel (11..26) |
uint32_t u32chmask() | Channel setting mask (bitmask, e.g., for 13, set bit 1UL « 13) |
uint8_t u8power() | Power setting (0..3) |
uint8_t u8retry() | Retry count |
uint32_t u32opt1() | Option 1 |
uint32_t u32opt2() | Option 2 |
uint32_t u32opt3() | Option 3 |
uint32_t u32opt4() | Option 4 |
uint8_t u8encmode() | Encryption mode (0: none, 1: enabled, 2: enabled, plaintext packet also shown) |
const uint8_t * u8enckeystr() | Get encryption key |
Internally, a linear search is performed on the struct array to find the setting struct matching the setting ID, so there is overhead. Frequently referenced settings should be copied to another variable once.
Applying Settings
Settings can be directly applied to the_twelite
or <NWK_SIMPLE>
objects using this object.
auto&& set = the_twelite.settings.use<STG_STD>();
...
set.reload(); // Actual reading from EEPROM happens here
the_twelite << set; // Apply settings (such as APPID)
auto&& nwk = the_twelite.network.use<NWK_SIMPLE>();
nwk << set; // Apply settings (such as LID)
The applied settings are as follows. Items hidden by .hide_items()
are not applied.
Target | Item ID | Content |
---|
the_twelite | APPID | Reflected as TWENET::appid(value) |
| CHANNEL | Reflected as TWENET::channel(value) . ※ Not applied when SETTINGS::ch_multi() is specified |
| CHANNELS_3 | Reflected as TWENET::chmask(value) . ※ Applied only as channel mask when SETTINGS::ch_multi() is specified |
| POWER_N_RETRY | Reflected as TWENET::tx_power(value) and TWENET::mac_retry_count(value) . Note: <NWK_SIMPLE> retransmission uses the same value. |
<NWK_SIMPLE> | LOGICALID | Reflected as NWK_SIMPLE::logical_id(LID) |
| POWER_N_RETRY | Reflected as NWK_SIMPLE::repeat_max(LID) |
Item IDs
Item IDs are specified in .hide_items()
and other places. These item IDs are defined in enum class E_STGSTD_SETID
.
E_STGSTD_SETID:: | Content |
---|
APPID | Application ID |
LOGICALID | Logical ID (0..100) |
CHANNEL | Channel |
CHANNELS_3 | Channel (multiple) |
POWER_N_RETRY | Power and retry settings |
OPTBITS | Option bits |
UARTBAUD | UART baud rate setting |
OPT_DWORD2 | Option bits 2 |
OPT_DWORD3 | Option bits 3 |
OPT_DWORD4 | Option bits 4 |
ENC_MODE | Encryption mode |
ENC_KEY_STRING | Encryption key |
[ROOT MENU/BAT1/SID=810B645E]
0: CONFIG
1: EEPROM UTIL
2: H/W UTIL
[ESC]:Back [!]:Reset System
Press the M key to access the additional menu.
- CONFIG : Returns to the configuration screen
- EEPROM UTIL : Menu for EEPROM maintenance
- H/W UTIL : Menu to check hardware status
EEPROM UTIL
[EEPROM UTIL/BAT1/SID=810B645E]
r: Read sector.
R: Read ALL sectors.
e: Erase sector.
E: Erase ALL sectors.
[ESC]:Back [!]:Reset System [M]:Extr Menu
Read and erase sectors. When reading or erasing all sectors, input the uppercase “YES” (3 characters).
H/W UTIL
[H/W UTIL/BAT1/SID=810B645E]
No functionality is provided in the current version.