This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

Configuration Interface by Setting Behavior

Abstraction layer for interactive mode
Setting behavior is a behavior for using configuration CUI via interactive mode. The interface for configuration is performed through serial port input and output. Interactive configuration using terminal software such as TWELITE STAGE APP / TeraTerm / screen is possible.

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

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>().

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.

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 IDContent
APPIDApplication ID
LOGICALIDLogical Device ID (8bit)
CHANNELChannel
CHANNELS_3Channel (up to 3 channels)
POWER_N_RETRYPower and retry count
OPTBITSOption 1
OPT_DWORD2Option 2
OPT_DWORD3Option 3
OPT_DWORD4Option 4
ENC_MODEEncryption mode
ENC_KEY_STRINGEncryption key (string input)

<STG_STD> defines representative settings and four freely usable 32bit values. These can be used freely by the user.

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.

Multiple Channel Setting Menu

	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.

Immediately Display the Configuration Screen

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.

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().

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.

MethodContent
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

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.

TargetItem IDContent
the_tweliteAPPIDReflected as TWENET::appid(value)
CHANNELReflected as TWENET::channel(value). ※ Not applied when SETTINGS::ch_multi() is specified
CHANNELS_3Reflected as TWENET::chmask(value). ※ Applied only as channel mask when SETTINGS::ch_multi() is specified
POWER_N_RETRYReflected as TWENET::tx_power(value) and TWENET::mac_retry_count(value). Note: <NWK_SIMPLE> retransmission uses the same value.
<NWK_SIMPLE>LOGICALIDReflected as NWK_SIMPLE::logical_id(LID)
POWER_N_RETRYReflected 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
APPIDApplication ID
LOGICALIDLogical ID (0..100)
CHANNELChannel
CHANNELS_3Channel (multiple)
POWER_N_RETRYPower and retry settings
OPTBITSOption bits
UARTBAUDUART baud rate setting
OPT_DWORD2Option bits 2
OPT_DWORD3Option bits 3
OPT_DWORD4Option bits 4
ENC_MODEEncryption mode
ENC_KEY_STRINGEncryption key

Extra Menu

[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.