Step 3d: ZWave - CC_CONFIGURATION

 

The code for this step is found here.

 

Our data logger has run with a fixed number of samples at a fixed time interval. We want to be able to configure these by ZWave, and also to start the log remotely. We will use the CC_CONFIGURATION commands, version 1, to do this. Parameter 1 will be time in seconds between samples, Parameter 2 the number of samples, and Parameter 3 a start/stop flag.

 

As with the sensor command, we create new files ZAF_CC/CC_Configuration.[ch] with the header and source. There is one framework function for incoming frames, handleCCConfiguration(), which operates much like the multilevel sensor handler. It uses four functions left as prototypes for the application code to implement. appConfigValidParam() tests if the requested parameter ID is supported, appConfigValue() returns a parameter's value, appConfigLevel() returns the size byte for the REPORT, and appConfigSet() changes a parameter, perhaps resetting it to its default value. Note that the command class defines default behavior if a bad parameter identifier or value is received, and this must be handled in the application code. The command class handler is a switch for GET, SET, and REPORT (which is ignored). The GET builds and sends a REPORT, the SET changes the logging setup and may start or stop the logger. Like the multi-byte values we had to assemble for sensor readings, with different frame structures for different sizes, here we need to unpack a SET value depending on the size indicated in the command, or fill in the REPORT with the correct number of value bytes.

 

We have a few changes in the application code besides implementing the four functions for the command class and adding the command class. The most important is wrapping the log in a mutex, since the timer/logging and incoming parameter changes can happen asynchronously. FreeRTOS semaphores provide the functionality and we add some limited error checking if a lock or unlock fails. You can see this in the appConfigSet() code snippet above. We modify the graphing functions to calculate point coordinates locally so we only have to take the lock once if we end up re-scaling the y axis. We also add a running flag to the log for when we need to check the status, because there's no way to read back the LED2 state, which would otherwise signal if logging is underway.

 

Besides the two command class files and ignoring edits within functions just to add the mutex lock, our application changes are

object

status

role

description

htlog_mutex, _lock (globals)

new

logger

protect asynch access to log

appnif1 (global var)

edit

transport

add command class

bound_nsample

new

CC support

validation of nsample parameter

graph_humidity

edit

LCD driver

store points locally before drawing

graph_temperature

edit

LCD driver

store points locally before drawing

appConfigValidParam

new

CC support

validate parameter identifier

appConfigValue

new

CC support

get current parameter value

appConfigLevel

new

CC support

get size of parameter value

appConfigSet

new

CC support

change parameter value

ApplicationInit

edit

ZAF

create mutex lock for log

Transport_AppCmdHandlerEx

edit

ZAF

add command class

 

The project file list includes the new command class.

hw/

src/

ZAF_AppUtil/

ZAF_CC/

displayconfigapp.h

config_app.h

ZAF_TSE.c

CC_Configuration.c

displayfont16x20HT.h

config_rf.h

 

CC_Configuration.h

em_types.h

HTSensor1.c

 

CC_MultiSensor.c

graphdisplay.c

i2cspmconfig.h

 

CC_MultiSensor.h

graphdisplay.h

 

 

CC_Version.c

textdisplay.c

 

 

 

testdisplayconfig.h

 

 

 

textdisplay.h

 

 

 

linked within Simplicity Studio

display.c

 

application_properties.c

CC_Supervision.c

displayls013b7dh03.c

 

AppTimer.c

multichannel.c

displaypalemlib.c

 

board_BRD420x.c

 

em_i2c.c

 

board_indicator.c

 

em_letimer.c

 

board.c

 

em_prs.c

 

ZAF_command_class_utils.c

 

gpiointerrupts.c

 

zaf_event_helper.c

 

i2cspm.c

 

ZAF_network_learn.c

 

startup_zgm13.S

 

ZAF_uart_utils.c

 

system_zgm13.c

 

ZW_TransportEndpoint.c

 

 

 

ZW_TransportMulticast.c

 

 

 

ZW_TransportSecProtocol.c

 

linked on file system

 

 

 

CC_Common.h

 

 

 

CC_Supervision.h

 

 

 

CC_Version.h

 

 

 

multichannel.h

 

Our last edits will be to add S0 encryption to the new command classes.