TWENETstgs - twesettings Library
This library primarily contains various functions for performing configuration processing in interactive mode.
Note: These functions are not publicly exposed as APIs for end-users.
This is the multi-page printable view of this section. Click here to print...
This library primarily contains various functions for performing configuration processing in interactive mode.
Note: These functions are not publicly exposed as APIs for end-users.
{{< hint color=“info” >}}
The printf
library to reference is stored in TWENETmcu/printf
.
{{< /hint >}}
This TWENETstgs
defines fprintf
, vfprintf
, and sprintf
equivalent functions using an open-source printf
library.
int TWE_fprintf(TWE_tsFILE *fp, const char *format, ...);
int TWE_vfprintf(TWE_tsFILE *fp, const char *format, va_list va);
#define TWE_snprintf(out,siz,fmt,...) snprintf_(out,siz,fmt,__VA_ARGS__)
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland (info@paland.com)
// 2014-2019, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant.
//
///////////////////////////////////////////////////////////////////////////////
TWESTG_CMD_u32CmdOp()
.TWESTG_CMD_u32CmdOp()
function provides common procedures with applications (firmware) implemented using the TWENETstgs library. However, this information relates to the internal implementation of the library and is not intended for use by general users.The TWESTG_CMD_u32CmdOp()
function in twesettings_cmd.[ch]
is intended to execute 0xdb
commands. This function includes processes such as obtaining module various information, obtaining configuration information, reflecting configuration information, and resetting. Many processes call the configuration-related helper function TWEINTRCT_cbu32GenericHandler()
.
TWE_APIRET
: Success if the 0x80000000
bit is set, failure if not. The remaining 31 bits are used for parameters.TWE_tsBuffer
: A structure containing a pointer to the buffer, the sequence length, and the maximum buffer length.TWESTG_tsFinal
: The management structure for configuration-related settings.TWESTG_CMD_u32CmdOp()
TWE_APIRET TWESTG_CMD_u32CmdOp(uint8 u8Op, TWE_tsBuffer *pBufIn, TWE_tsBuffer *pBufOut, TWESTG_tsFinal *psFinal)
Performs processing corresponding to u8Op
. Input data pBufIn
and output data pBufOut
are used depending on the process. The last parameter specifies the configuration management structure psFinal
.
Parameter | Type | Description |
---|---|---|
u8Op | uint8 | Specifies the processing content. |
pBufIn | TWE_tsBuffer * | Input sequence. |
pBufOut | TWE_tsBuffer * | Specifies the storage area for output data. NULL can be specified for some processes. The state on processing failure is undefined in principle. |
psFinal | TWESTG_tsFinal * | Specifies the configuration information management structure. |
The u8Op
overview is as follows:
E_TWESTG_CMD_OP_ACK = 0xF0 ACK processing
E_TWESTG_CMD_OP_QUERY_MODULE_INFO = 0xF1 Acquisition of SID, etc.
E_TWESTG_CMD_OP_APPLY_SETTINGS = 0xF2 Apply settings (do not save)
E_TWESTG_CMD_OP_QUERY_SETTINGS = 0xF3 Read settings
E_TWESTG_CMD_OP_MODULE_CONTROL = 0xF8 Various processes related to settings
E_TWESTG_CMD_OP_REVERT = 0xFD Revert settings
E_TWESTG_CMD_OP_SAVE = 0xFE Save settings
E_TWESTG_CMD_OP_DO_MDDULE_RESET = 0xFF, Module reset
The return value indicates success or failure. Parameters may be set depending on the process.
Return Value | Value | Status |
---|---|---|
TWE_APIRET_SUCCESS | b0..b7 → u8Op, others depend on processing | On success |
TWE_APIRET_FAIL | b0..b7 → u8Op, others depend on processing | On failure |
Performs an ACK response. The input sequence is output as-is.
(None) -> 01 : If no input, 01 is returned.
112233 -> 112233 : If 112233, it is returned as-is in the output.
Retrieves various module information.
Input Column | Data Type | Value | Content |
---|---|---|---|
[0] | OCTET | 0x01 | Get module’s SID. |
Other | Undefined | ||
Subsequent data is undefined |
Output Column ([0] == 0x01) | Data Type | Value | Content |
---|---|---|---|
[0..3] | BE_DWORD | Module’s SID. |
Modifies configuration information.
E_TWESTG_CMD_OP_SAVE
) is executed, no actual save will occur.pBufOut
).Input Column | Data Type | Value | Content |
---|---|---|---|
[0] | OCTET | 0x01 | Change the setting specified by ID. |
[1] | OCTET | Not 0x00 | Setting ID |
[2..] | Data type dependent |
Setting ID | Content | Input Data | Remarks |
---|---|---|---|
0x01 | Application ID | BE_DWORD (uint32_t) | |
0x02 | Logical ID (8bit) | OCTET (uint8_t) | |
0x03 | Channel | OCTET (uint8_t) | |
0x04 | Multiple Channels | BE_WORD(uint16_t) | b0: ch11, b1: ch12, …, b15: ch16 |
BE_DWORD(uint32_t) | Bitwise OR of 1UL << ch (e.g., for 11, 13 it’s `1UL « 11 | ||
0x05 | Radio Output and Retransmission | OCTET (uint8_t) | Upper 4 bits: retransmission count, Lower 4 bits: output setting (0..3, 3 is highest output) |
0x06, 0x08, 0x09, 0x0A | Option (32bit) | BE_DWORD (uint32_t) | |
0x07 | UART Settings | BE_WORD (int16_t) | Input configuration data in internal format as-is. |
BE_DWORD | Specifies baud rate (9600 … 250000). Other communication conditions are 8N1. | ||
BE_DWORD OCTET OCTET OCTET | Specifies all parameters: - Baud rate (DWORD) - Data bits (7 or 8) - Parity (‘N’ or ‘E’ or ‘O’) - Stop bits (1 or 2) |
01011234BEEF Sets Application ID (0x01) to 0x1234BEEF.
010212 Sets Channel (0x02) to 0x12 (18).
Retrieves configuration information.
Input Column | Data Type | Value | Content |
---|---|---|---|
[0] | OCTET | 0x01 | (QTYP) Get the setting specified by ID. |
[1] | OCTET | Not 0x00 | Setting ID |
Remarks | ||
---|---|---|
[0] | OCTET | Data type (uint8_t: 1, int8_t: 2, uint16_t: 3, int16_t: 4, uint32_t: 5, int32_t: 6, uint8_t[]: 0x80 (lower 5 bits are data length)) |
[...] | Data type dependent (Integer types WORD, DWORD are Big Endian order) |
Setting ID | Content | Input Data | Remarks |
---|---|---|---|
0x01 | Application ID | BE_DWORD (uint32_t) | |
0x02 | Logical ID (8bit) | OCTET (uint8_t) | |
0x03 | Channel | OCTET (uint8_t) | |
0x04 | Multiple Channels | BE_WORD(uint16_t) | b0: ch11, b1: ch12, …, b15: ch16 |
0x05 | Radio Output and Retransmission | OCTET (uint8_t) | Upper 4 bits: retransmission count, Lower 4 bits: output setting (0..3, 3 is highest output) |
0x06, 0x08, 0x09, 0x0A | Option (32bit) | BE_DWORD (uint32_t) | |
0x07 | UART Settings | BE_WORD (int16_t) | Internal format configuration data. b15: 1 for 7bit, 0 for 8bit. b14: 1 for STOPBIT=2, 0 for 1. b12,13: 0->NONE, 1->ODD, 2->EVEN. b0..b11->Baud rate / 100. |
0101 -> 051234BEEF -> Application ID (uint32_t 0x1234beef)
0102 -> 010D -> Channel (uint8_t 13)
By executing E_TWESTG_CMD_OP_SAVE
immediately after this command, the configuration information is reverted to its initial values.
TWEINTRCT_cbu32GenericHandler(psIntr, E_TWEINRCT_OP_REVERT, TRUE, 0, NULL)
. The TRUE
specified in the third argument means that the saved configuration information is not loaded. Ensure that the application’s TWEINTRCT_cbu32GenericHandler()
is correctly implemented.No input data, no output data.
When configuration information is changed, it is saved to non-volatile memory.
TWE_APIRET_SUCCESS_W_VALUE(0x100 | E_TWESTG_CMD_OP_SAVE)
.No input data, no output data.
Resets the module.
No input data, no output data.