The idea behind the Node Scripting is to allow execution of custom scripts in remote nodes. That means, the user can specify scripts based on FBlock command syntax and run these on remote nodes by the use of the Node Scripting module (NS).
A node script is a data structure (see code snippet), composed of:
A Ucs_Ns_ConfigMsg_t message is based on INIC FBlock-Syntax and looks like this:
The user specifies the desired scripts and then calls the function Ucs_Ns_Run() for processing. The scripts can also be bound to the structure of the target node for automatic script execution after network startup.
The result of the Ucs_Ns_Run() operation is reported via the result callback function Ucs_Ns_ResultCb_t, which is passed by user in the arguments list of Ucs_Ns_Run(). It is possible to give unique callback functions for different scripts. In addition to this callback function and the referred UCS instance the function requires a reference to the Node where the script(s) should be executed, a pointer to the script list and the size of the script list.
The Ucs_Ns_Run() function starts the process to transmit the script(s) to the node and then checks for the expected results (specified by customer). The Node Scripting module will start a timer of 5200ms before sending the Tx command of each script. That is, if no incoming messages match the expected result of the script during this time the result code UCS_NS_RES_ERR_TIMEOUT is returned via the Ucs_Ns_ResultCb_t user callback function. When the script module couldn't perform the device synchronization of the remote device the result code UCS_NS_RES_ERR_SYNC is returned (this can be read in the detailed error messages, if enabled. See below). Also if the scripts couldn't be transmitted UCS_NS_RES_ERR_TX is returned. To help users to identify errors caused by defective scripts the result codes UCS_NS_RES_ERR_PAYLOAD and UCS_NS_RES_ERR_OPTYPE and the Ucs_Ns_ErrorInfo_t are given to the callback function. The script_count
clarifies where the defective script is stored in the script list and funct_id
gives the respective function ID. If the incoming message matches the expected result, UCS_NS_RES_SUCCESS is returned.
The Ucs_Ns_Run() function will return UCS_RET_ERR_API_LOCKED when attempting to execute a script in a node that is currently busy with other(s) previous script(s). The Ucs_Ns_Run() function is namely locked for a node when handling script(s) on this node and unlocked after reporting the result of the operation. However processing scripts can be executed on different nodes in parallel.
exp_result
structure in Ucs_Ns_Script_t does not have to contain the full expected information. Since the validation of the data is only done for the expected length, User can either disable the data check on incoming messages by setting the expected length data_size element of Ucs_Ns_ConfigMsg_t to 0x00 or can just specify the maximum amount of data to be checked (Refer to the example below). However to set the expected length to long will effect that the message will be interpreted as incorrect. If the data_ptr is set to NULL the check is also disabled independently of the value of data_size.The detailed error messages can be read when enabling the error trace output in ucs_cfg.h
file as shown below.
The example below outlines the execution of a script within a node with address 0x200. It shows the option to run the node internal script and how to run any other script which is not included in the node structure. This example is inserted as a guide and may not contain all of the necessary details and information.