Config Notify Class Example
Overview
This NetBurner application demonstrates the use of the config system with notification capabilities. The config system stores both system-defined boot and interface information (such as default BaudRate and current IP settings) and provides a framework for users to define and store their own persistent variables.
This example extends the basic ConfigClass functionality by implementing a notification system that alerts when any configuration variables change.
Features
- Persistent Configuration Storage: Variables are automatically saved to non-volatile storage
- Change Notifications: Automatic notifications when configuration values are modified
- Interactive Command Interface: User-friendly commands to view and modify settings
- Hierarchical Configuration: Demonstrates inheritance with TempRange and Thermostat classes
Application Structure
Classes
TempRange
A base configuration class that defines temperature-related settings:
m_maxTemp: Maximum temperature threshold (default: 100)
m_setTemp: Set point temperature (default: 30)
m_minTemp: Minimum temperature threshold (default: 10)
Thermostat
Extends TempRange and implements ConfigNotificationObject:
- Inherits all TempRange variables
m_tempRec1: Temperature record 1 (default: 101)
m_tempRec2: Temperature record 2 (default: 102)
m_active: Active status flag (default: true)
m_location: Thermostat location string (default: "Warehouse 1")
m_tempScale: Temperature scale chooser (Fahrenheit/Celsius/Kelvin)
Key Features
Notification System
The Thermostat class implements a Notify() method that is automatically called whenever any of its configuration variables change. This provides real-time awareness of configuration modifications.
Interactive Commands
The application provides a command-line interface with the following options:
C - Show complete configuration tree
L - View and set thermostat location
M - View and set maximum temperature
N - View and set minimum temperature
S - View and set target temperature
T - Display recorded temperatures
? - Show command list
Usage
- Startup: The application initializes the network interface and displays current IP settings
- Interactive Mode: Enter commands to view or modify configuration values
- Automatic Saving: All changes are automatically saved to persistent storage
- Notifications: The system prints a message whenever configuration values change
Network Information
On startup, the application displays:
- Current IP address
- AutoIP address
- Gateway address
Technical Implementation
Configuration Storage
- Uses NetBurner's config system for persistent storage
- Automatic serialization/deserialization of configuration objects
- Thread-safe access to configuration variables
Notification Mechanism
- Implements
ConfigNotificationObject interface
- Automatic registration for change notifications
- Custom
Notify() method for handling configuration changes
Input Processing
- Non-blocking character input using
charavail()
- User-friendly prompts for value modification
- Automatic type conversion and validation
Building and Running
This application is designed for NetBurner embedded systems and requires:
- NetBurner SDK and toolchain
- Network-capable NetBurner hardware platform
- Serial terminal for user interaction
The application runs continuously, processing user commands and maintaining configuration state across power cycles.
Example Output
Config Tree Demo built at 12:34:56 on Jan 01 2025
'?' for commands
IP: 192.168.1.100
AutoIP : 169.254.1.100
Gateway: 192.168.1.1
Command List
------------
C) Show Config Tree
L) Show and Set Thermostat Location
M) Show and Set Thermostat Max Temp
N) Show and Set Thermostat Min Temp
S) Show and Set Thermostat Set Temp
T) Show Thermostat Recorded Temps
?) Show Command List
Notes
- All configuration objects should be created at global scope
- Each configuration member must have a unique name within the config tree
- The
ConfigEndMarker is required after the last data member in each config class
- Changes trigger both the notification system and automatic storage saves