Logo
UNICENS V2.1.0-3491
User Manual and API Reference
Ucs_Return_t Ucs_Ns_Run ( Ucs_Inst_t self,
Ucs_Rm_Node_t node_ptr,
Ucs_Ns_ResultCb_t  result_fptr 
)

Runs the script(s) contained in the given node.

The function starts the process to transmit the script(s) contained in the given node and checks for the expected results (specified by customer). The Node Scripting module will start a timer of 2600ms 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_ERROR is returned via the Ucs_Ns_ResultCb_t user callback function. This error code is also get when the script module couldn't perform the device synchronization of the remote device. Otherwise, if an incoming message matches the expected result, UCS_NS_RES_SUCCESS is returned.
The 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). Ucs_Ns_Run() is namely locked for a Node when running script(s) on this node and unlocked after reporting the operation's result. However processing scripts can be executed on different nodes in parallel.

Parameters
selfThe UNICENS instance
node_ptrReference to the node instance.
result_fptrReference to the result function pointer
Returns
Possible return values are shown in the table below.
Value Description
UCS_RET_SUCCESS No error
UCS_RET_ERR_NOT_AVAILABLE No internal resources allocated for the given node.
Check if value of UCS_NUM_REMOTE_DEVICES is less than
the current number of remote devices in network.
UCS_RET_ERR_PARAM At least one parameter is NULL.
UCS_RET_ERR_NOT_INITIALIZED UNICENS is not initialized
UCS_RET_ERR_BUFFER_OVERFLOW No TxBuffer Handles available
UCS_RET_ERR_API_LOCKED The API is locked.
Attention
The Node Scripting module is designed and intended for the use of I2C and GPIO commands only. That is, using the Scripting for any other FBlock INIC commands (for example MOST, MediaLB, USB, Streaming, Connections, etc.) is expressly prohibited.



Example

// Forward declaration of result callback function
static void App_OnScriptingResult(uint16_t node_address, Ucs_Ns_ResultCode_t result, void *user_ptr);
// Configuration Msg specification
static uint8_t tx_data [] = { 0x00, 0x40, 0x01, 0x01 };
static uint8_t rx_data [] = { 0x0F, 0x00 };
static Ucs_Ns_ConfigMsg_t tx_msg = { 0x00, 0x00, 0x6C1, 0x2, 4U, &tx_data };
static Ucs_Ns_ConfigMsg_t rx_msg = { 0x00, 0x01, 0x6C1, 0xC, 2U, &rx_data };
// Scripts specification
static Ucs_Ns_Script_t script_x = { 100U, &tx_msg, &rx_msg };
// Signature specification
Ucs_Signature_t sig_200 = { 200U };
// Nodes objects Specification
static Ucs_Rm_Node_t node_200 = { &sig_200, &script_x, 1U, 0U };
// Main function
void main(uint8_t argc, char *argv[])
{
// ...
if (node200_discovered)
{
(void)Ucs_Ns_Run(ucs_inst_ptr, &node_200, &App_OnScriptingResult);
}
// ...
}
// The result callback function
static void App_OnScriptingResult(Ucs_Rm_Node_t * node_ptr, Ucs_Ns_ResultCode_t result, void *user_ptr)
{
switch (result)
{
// Node can be set to "Available" for example
Ucs_Rm_SetNodeAvailable(ucs_inst_ptr, node_ptr, true);
break;
default:
// Do whatever is necessary here
break;
}
}