diff options
author | Thorsten Kummermehr <thorsten.kummermehr@k2l.de> | 2017-11-07 16:12:54 +0100 |
---|---|---|
committer | Thorsten Kummermehr <thorsten.kummermehr@k2l.de> | 2017-11-07 16:12:54 +0100 |
commit | a18a8321a061ae60aec72d4cba4974ddf0bcf8f8 (patch) | |
tree | 75c4a49c3dc1fb0caa20f24c12d4fc15a950ad74 /ucs2-interface | |
parent | 1f25b3a06ec284ee132bae8a81e183bb2a9ec819 (diff) |
Improve general error handling
Diffstat (limited to 'ucs2-interface')
-rw-r--r-- | ucs2-interface/ucs-xml/UcsXml.c | 48 | ||||
-rw-r--r-- | ucs2-interface/ucs-xml/UcsXml_Private.c | 27 |
2 files changed, 56 insertions, 19 deletions
diff --git a/ucs2-interface/ucs-xml/UcsXml.c b/ucs2-interface/ucs-xml/UcsXml.c index fcbe5f5..c86746f 100644 --- a/ucs2-interface/ucs-xml/UcsXml.c +++ b/ucs2-interface/ucs-xml/UcsXml.c @@ -38,7 +38,7 @@ /************************************************************************/
#define COMPILETIME_CHECK(cond) (void)sizeof(int[2 * !!(cond) - 1])
-#define RETURN_ASSERT(result) { assert(false); return result; }
+#define RETURN_ASSERT(result) { UcsXml_CB_OnError("Assertion in file=%s, line=%d", 2, __FILE__, __LINE__); return result; }
#define MISC_HB(value) ((uint8_t)((uint16_t)(value) >> 8))
#define MISC_LB(value) ((uint8_t)((uint16_t)(value) & (uint16_t)0xFF))
@@ -54,6 +54,7 @@ struct UcsXmlRoute struct UcsXmlScript
{
+ bool inUse;
char scriptName[32];
Ucs_Rm_Node_t *node;
struct UcsXmlScript *next;
@@ -278,9 +279,9 @@ UcsXmlVal_t *UcsXml_Parse(const char *xmlString) return val;
ERROR:
if (Parse_MemoryError == result)
- UcsXml_CB_OnError("XML error, aborting..", 0);
+ UcsXml_CB_OnError("XML memory error, aborting..", 0);
else
- UcsXml_CB_OnError("Allocation error, aborting..", 0);
+ UcsXml_CB_OnError("XML parsing error, aborting..", 0);
assert(false);
if (!tree)
mxmlDelete(tree);
@@ -687,6 +688,8 @@ static ParseResult_t ParseAll(mxml_node_t *tree, UcsXmlVal_t *ucs, PrivateData_t /*Iterate all scripts. No scripts at all is allowed*/
if(GetElement(tree, SCRIPT, true, &sub, false))
{
+ bool found = true;
+ struct UcsXmlScript *scrlist = priv->pScrLst;
while(sub)
{
result = ParseScript(sub, priv);
@@ -695,6 +698,18 @@ static ParseResult_t ParseAll(mxml_node_t *tree, UcsXmlVal_t *ucs, PrivateData_t if(!GetElement(sub, SCRIPT, false, &sub, false))
break;
}
+ /* Check if all scripts where referenced */
+ while(NULL != scrlist)
+ {
+ if (!scrlist->inUse)
+ {
+ UcsXml_CB_OnError("Script not defined:'%s', used by node=0x%X", 1, scrlist->scriptName, scrlist->node->signature_ptr->node_address);
+ found = false;
+ }
+ scrlist = scrlist->next;
+ }
+ if (!found)
+ RETURN_ASSERT(Parse_XmlError);
}
return result;
}
@@ -995,6 +1010,7 @@ static ParseResult_t ParseSocket(mxml_node_t *soc, bool isSource, MSocketType_t /*Connect in and out socket once they are created*/
if (priv->conData.inSocket && priv->conData.outSocket)
{
+ bool mostIsInput;
bool mostIsOutput;
Ucs_Rm_EndPoint_t *ep;
struct UcsXmlRoute *route;
@@ -1031,7 +1047,13 @@ static ParseResult_t ParseSocket(mxml_node_t *soc, bool isSource, MSocketType_t ep = MCalloc(&priv->objList, 1, sizeof(Ucs_Rm_EndPoint_t));
if (NULL == ep) RETURN_ASSERT(Parse_MemoryError);
+ mostIsInput = (UCS_XRM_RC_TYPE_MOST_SOCKET == *((Ucs_Xrm_ResourceType_t *)priv->conData.inSocket));
mostIsOutput = (UCS_XRM_RC_TYPE_MOST_SOCKET == *((Ucs_Xrm_ResourceType_t *)priv->conData.outSocket));
+ if (!mostIsInput && !mostIsOutput)
+ {
+ UcsXml_CB_OnError("At least one MOST socket required per connection", 0);
+ RETURN_ASSERT(Parse_XmlError);
+ }
ep->endpoint_type = mostIsOutput ? UCS_RM_EP_SOURCE : UCS_RM_EP_SINK;
ep->jobs_list_ptr = GetJobList(*jobList, &priv->objList);
if(NULL == ep->jobs_list_ptr) RETURN_ASSERT(Parse_MemoryError);
@@ -1102,7 +1124,7 @@ static ParseResult_t ParseScript(mxml_node_t *scr, PrivateData_t *priv) if (Parse_Success != result) return result;
} else {
UcsXml_CB_OnError("Unknown script action:'%s'", 1, txt);
- /*RETURN_ASSERT(Parse_XmlError);*/
+ RETURN_ASSERT(Parse_XmlError);
}
if (!GetElementArray(act, ALL_SCRIPTS, &txt, &act))
break;
@@ -1117,6 +1139,7 @@ static ParseResult_t ParseScript(mxml_node_t *scr, PrivateData_t *priv) Ucs_Rm_Node_t *node = scrlist->node;
node->script_list_ptr = script;
node->script_list_size = actCnt;
+ scrlist->inUse = true;
found = true;
}
scrlist = scrlist->next;
@@ -1277,7 +1300,11 @@ static ParseResult_t ParseScriptPortCreate(mxml_node_t *act, Ucs_Ns_Script_t *sc speed = 0;
else if (0 == strcmp(txt, I2C_SPEED_FAST))
speed = 1;
- else RETURN_ASSERT(Parse_XmlError);
+ else
+ {
+ UcsXml_CB_OnError("Invalid I2C speed:'%s'", 1, txt);
+ RETURN_ASSERT(Parse_XmlError);
+ }
req = scr->send_cmd;
res = scr->exp_result;
req->InstId = res->InstId = 1;
@@ -1317,6 +1344,11 @@ static ParseResult_t ParseScriptPortWrite(mxml_node_t *act, Ucs_Ns_Script_t *scr mode = 1;
else if (0 == strcmp(txt, I2C_WRITE_MODE_BURST))
mode = 2;
+ else
+ {
+ UcsXml_CB_OnError("Invalid I2C mode:'%s'", 1, txt);
+ RETURN_ASSERT(Parse_XmlError);
+ }
} else {
mode = 0;
}
@@ -1458,7 +1490,11 @@ static ParseResult_t ParseRoutes(UcsXmlVal_t *ucs, PrivateData_t *priv) }
sourceRoute = sourceRoute->next;
}
- assert(routeAmount == ucs->routesSize);
+ if (routeAmount != ucs->routesSize)
+ {
+ UcsXml_CB_OnError("At least one sink (num=%d) is not connected, because of wrong Route name!", 2, (routeAmount - ucs->routesSize));
+ RETURN_ASSERT(Parse_XmlError);
+ }
#ifdef DEBUG
/* Third perform checks when running in debug mode*/
diff --git a/ucs2-interface/ucs-xml/UcsXml_Private.c b/ucs2-interface/ucs-xml/UcsXml_Private.c index f914ccb..743598f 100644 --- a/ucs2-interface/ucs-xml/UcsXml_Private.c +++ b/ucs2-interface/ucs-xml/UcsXml_Private.c @@ -31,6 +31,7 @@ #include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include "UcsXml.h"
#include "UcsXml_Private.h"
static const char* USB_PHY_STANDARD = "Standard";
@@ -69,8 +70,8 @@ static const char* VAL_TRUE = "true"; static const char* VAL_FALSE = "false";
*/
-#define ASSERT_FALSE() { assert(false); return false; }
-#define CHECK_POINTER(PTR) if (NULL == PTR) { ASSERT_FALSE(); }
+#define ASSERT_FALSE(func, par) { UcsXml_CB_OnError("Parameter error in attribute=%s value=%s, file=%s, line=%d", 4, func, par, __FILE__, __LINE__); return false; }
+#define CHECK_POINTER(PTR) if (NULL == PTR) { ASSERT_FALSE(PTR, "NULL pointer"); }
static int32_t Str2Int(const char *val)
{
@@ -149,7 +150,7 @@ bool GetMostSocket(Ucs_Xrm_MostSocket_t **mostSoc, struct MostSocketParameters * soc->data_type = UCS_MOST_SCKT_DISC_FRAME_PHASE;
break;
default:
- ASSERT_FALSE();
+ ASSERT_FALSE("GetMostSocket->dataType", "");
}
return true;
}
@@ -176,7 +177,7 @@ bool GetUsbPort(Ucs_Xrm_UsbPort_t **usbPort, struct UsbPortParameters *param) port->physical_layer = UCS_USB_PHY_LAYER_STANDARD;
else if (0 == strcmp(USB_PHY_HSIC, param->physicalLayer))
port->physical_layer = UCS_USB_PHY_LAYER_HSCI;
- else ASSERT_FALSE();
+ else ASSERT_FALSE("GetUsbPort->physical_layer", param->physicalLayer);
return true;
}
@@ -220,7 +221,7 @@ bool GetUsbSocket(Ucs_Xrm_UsbSocket_t **usbSoc, struct UsbSocketParameters *para soc->data_type = UCS_USB_SCKT_IPC_PACKET;
break;
default:
- ASSERT_FALSE();
+ ASSERT_FALSE("GetUsbSocket->dataType", "");
}
soc->end_point_addr = (uint8_t)Str2Int(param->endpointAddress);
soc->frames_per_transfer = (uint16_t)Str2Int(param->framesPerTrans);
@@ -256,7 +257,7 @@ bool GetMlbPort(Ucs_Xrm_MlbPort_t **mlbPort, struct MlbPortParameters *param) port->clock_config = UCS_MLB_CLK_CFG_6144_FS;
else if (0 == strcmp(param->clockConfig, CLOCK_8192FS))
port->clock_config = UCS_MLB_CLK_CFG_8192_FS;
- else ASSERT_FALSE();
+ else ASSERT_FALSE("GetMlbPort->clockConfig", param->clockConfig);
return true;
}
@@ -306,7 +307,7 @@ bool GetMlbSocket(Ucs_Xrm_MlbSocket_t **mlbSoc, struct MlbSocketParameters *para soc->data_type = UCS_MLB_SCKT_IPC_PACKET;
break;
default:
- ASSERT_FALSE();
+ ASSERT_FALSE("GetMlbSocket->dataType", "");
}
soc->channel_address = (uint16_t)Str2Int(param->channelAddress);
soc->mlb_port_obj_ptr = param->mlbPort;
@@ -343,7 +344,7 @@ bool GetStrmPort(Ucs_Xrm_StrmPort_t **strmPort, struct StrmPortParameters *param port->clock_config = UCS_STREAM_PORT_CLK_CFG_512FS;
else if (0 == strcmp(param->clockConfig, CLOCK_WILDCARD))
port->clock_config = UCS_STREAM_PORT_CLK_CFG_WILD;
- else ASSERT_FALSE();
+ else ASSERT_FALSE("GetStrmPort->clockConfig", param->clockConfig);
} else {
port->clock_config = UCS_STREAM_PORT_CLK_CFG_WILD;
}
@@ -358,7 +359,7 @@ bool GetStrmPort(Ucs_Xrm_StrmPort_t **strmPort, struct StrmPortParameters *param port->data_alignment = UCS_STREAM_PORT_ALGN_RIGHT24BIT;
else if (0 == strcmp(param->dataAlignment, STRM_ALIGN_SEQUENTIAL))
port->data_alignment = UCS_STREAM_PORT_ALGN_SEQ;
- else ASSERT_FALSE();
+ else ASSERT_FALSE("GetStrmPort->dataAlignment", param->dataAlignment);
return true;
}
@@ -382,7 +383,7 @@ bool GetStrmSocket(Ucs_Xrm_StrmSocket_t **strmSoc, struct StrmSocketParameters * soc->data_type = UCS_STREAM_PORT_SCKT_SYNC_DATA;
break;
default:
- ASSERT_FALSE();
+ ASSERT_FALSE("GetStrmSocket->dataType", "");
}
soc->bandwidth = param->bandwidth;
if (0 == strcmp(param->streamPin, I2S_PIN_SRXA0))
@@ -409,7 +410,7 @@ bool GetStrmSocket(Ucs_Xrm_StrmSocket_t **strmSoc, struct StrmSocketParameters * soc->stream_port_obj_ptr = param->streamPortB;
return true;
}
- else ASSERT_FALSE();
+ else ASSERT_FALSE("GetStrmSocket->streamPin", param->streamPin);
return true;
}
@@ -462,7 +463,7 @@ bool GetSyncCon(Ucs_Xrm_SyncCon_t **syncCon, struct SyncConParameters *param) con->mute_mode = UCS_SYNC_MUTE_MODE_NO_MUTING;
else if (0 == strcmp(param->muteMode, MUTE_SIGNAL))
con->mute_mode = UCS_SYNC_MUTE_MODE_MUTE_SIGNAL;
- else ASSERT_FALSE();
+ else ASSERT_FALSE("GetSyncCon->mute_mode", param->muteMode);
if (param->optional_offset)
con->offset = (uint16_t)Str2Int(param->optional_offset);
else
@@ -501,7 +502,7 @@ bool GetAvpCon(Ucs_Xrm_AvpCon_t **avpCon, struct AvpConParameters *param) con->isoc_packet_size = UCS_ISOC_PCKT_SIZE_206;
break;
default:
- ASSERT_FALSE();
+ ASSERT_FALSE("GetAvpCon->isoc_packet_size", "");
}
} else {
con->isoc_packet_size = UCS_ISOC_PCKT_SIZE_188;
|