CdevData_t rx;
CdevData_t tx;
UCSI_Data_t ucsiData;
+ UcsXmlVal_t* ucsConfig;
} ucsContextT;
typedef struct {
} EventData_t;
-static ucsContextT *ucsContextS;
+static ucsContextT *ucsContextS = NULL;
static EventData_t *eventData = NULL;
PUBLIC void UcsXml_CB_OnError(const char format[], uint16_t vargsCnt, ...) {
void UCSI_CB_OnNetworkState(void *pTag, bool isAvailable, uint16_t packetBandwidth, uint8_t amountOfNodes)
{
+ AFB_NOTICE ("Network is available=%d, bw=%d, nodeCnt=%d", isAvailable, packetBandwidth, amountOfNodes);
}
/* UCS2 Interface Timer Callback */
va_start(argptr, vargsCnt);
vsprintf(outbuf, format, argptr);
va_end(argptr);
- if (isError)
- AFB_NOTICE ("%s",outbuf);
+ AFB_NOTICE ("%s",outbuf);
}
/** UCSI_Service cannot be called directly within UNICENS context, need to service stack through mainloop */
}
}
+/** UcsXml_FreeVal be called directly within UNICENS context, need to service stack through mainloop */
+STATIC int OnStopCB (sd_event_source *source, uint64_t usec, void *pTag) {
+ if (NULL != ucsContextS && NULL != ucsContextS->ucsConfig) {
+ UcsXml_FreeVal(ucsContextS->ucsConfig);
+ ucsContextS->ucsConfig = NULL;
+ }
+}
+
/**
* \brief Callback when UNICENS instance has been stopped.
* \note This event can be used to free memory holding the resources
* \param pTag - Pointer given by the integrator by UCSI_Init
*/
void UCSI_CB_OnStop(void *pTag) {
- AFB_NOTICE ("UNICENS stopped");
-
+ AFB_NOTICE ("UNICENS stopped");
+ /* push an asynchronous request for loopback to call UcsXml_FreeVal */
+ sd_event_add_time(afb_daemon_get_event_loop(), NULL, CLOCK_MONOTONIC, 0, 0, OnStopCB, pTag);
}
/** This callback will be raised, when ever an applicative message on the control channel arrived */
void UCSI_CB_OnRouteResult(void *pTag, uint16_t routeId, bool isActive, uint16_t connectionLabel)
{
+ AFB_NOTICE ("Route 0x%X is active=%d, connection label=0x%X", routeId, isActive, connectionLabel);
}
void UCSI_CB_OnGpioStateChange(void *pTag, uint16_t nodeAddress, uint8_t gpioPinId, bool isHighState)
{
+ AFB_NOTICE ("GPIO state of node 0x%X changed, pin=%d isHigh=%d", nodeAddress, gpioPinId, isHighState);
}
PUBLIC void UCSI_CB_OnMgrReport(void *pTag, Ucs_MgrReport_t code, uint16_t nodeAddress, Ucs_Rm_Node_t *pNode){
ssize_t readSize;
int fdHandle ;
struct stat fdStat;
- UcsXmlVal_t* ucsConfig;
+ UcsXmlVal_t *ucsConfig = NULL;
fdHandle = open(filename, O_RDONLY);
if (fdHandle <= 0) {
AFB_ERROR("File XML invalid: '%s'", filename);
goto OnErrorExit;
}
+ AFB_NOTICE ("Parsing result: %d Nodes, %d Scripts, Ethernet Bandwith %d bytes = %.2f MBit/s", ucsConfig->nodSize, ucsConfig->routesSize, ucsConfig->packetBw, (48 * 8 * ucsConfig->packetBw / 1000.0));
return (ucsConfig);
}
PUBLIC int StartConfiguration(const char *filename) {
- static UcsXmlVal_t *ucsConfig;
- static ucsContextT ucsContext;
+ static ucsContextT ucsContext = { 0 };
sd_event_source *evtSource;
int err;
/* Read and parse XML file */
- ucsConfig = ParseFile(filename);
- if (NULL == ucsConfig) {
+ ucsContext.ucsConfig = ParseFile(filename);
+ if (NULL == ucsContext.ucsConfig) {
AFB_ERROR ("Cannot access or load file: '%s'", filename);
goto OnErrorExit;
}
ucsContextS = &ucsContext;
}
/* Initialise UNICENS with parsed config */
- if (!UCSI_NewConfig(&ucsContext.ucsiData, ucsConfig)) {
+ if (!UCSI_NewConfig(&ucsContext.ucsiData, ucsContext.ucsConfig)) {
AFB_ERROR ("Fail to initialize UNICENS");
goto OnErrorExit;
}