- config parser modified for complex pin type
This commit is contained in:
127
src/lcec_conf.c
127
src/lcec_conf.c
@@ -156,6 +156,7 @@ LCEC_CONF_SLAVE_T *currSlave;
|
||||
LCEC_CONF_SYNCMANAGER_T *currSyncManager;
|
||||
LCEC_CONF_PDO_T *currPdo;
|
||||
LCEC_CONF_SDOCONF_T *currSdoConf;
|
||||
LCEC_CONF_PDOENTRY_T *currSdoEntry;
|
||||
|
||||
int shmem_id;
|
||||
|
||||
@@ -175,6 +176,7 @@ void parseSdoDataRawAttrs(const char **attr);
|
||||
void parseSyncManagerAttrs(const char **attr);
|
||||
void parsePdoAttrs(const char **attr);
|
||||
void parsePdoEntryAttrs(const char **attr);
|
||||
void parseComplexEntryAttrs(const char **attr);
|
||||
|
||||
int parseSyncCycle(const char *nptr);
|
||||
|
||||
@@ -264,6 +266,7 @@ int main(int argc, char **argv) {
|
||||
currSyncManager = NULL;
|
||||
currPdo = NULL;
|
||||
currSdoConf = NULL;
|
||||
currSdoEntry = NULL;
|
||||
for (done=0; !done;) {
|
||||
// read block
|
||||
int len = fread(buffer, 1, BUFFSIZE, file);
|
||||
@@ -406,6 +409,13 @@ void xml_start_handler(void *data, const char *el, const char **attr) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case lcecConfTypePdoEntry:
|
||||
if (strcmp(el, "complexEntry") == 0) {
|
||||
currConfType = lcecConfTypeComplexEntry;
|
||||
parseComplexEntryAttrs(attr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s: ERROR: unexpected node %s found\n", modname, el);
|
||||
@@ -1014,7 +1024,7 @@ void parsePdoEntryAttrs(const char **attr) {
|
||||
// parse bitLen
|
||||
if (strcmp(name, "bitLen") == 0) {
|
||||
tmp = atoi(val);
|
||||
if (tmp <= 0 || tmp > 32) {
|
||||
if (tmp <= 0 || tmp > LCEC_CONF_GENERIC_MAX_SUBPINS) {
|
||||
fprintf(stderr, "%s: ERROR: Invalid pdoEntry bitLen %d\n", modname, tmp);
|
||||
XML_StopParser(parser, 0);
|
||||
return;
|
||||
@@ -1030,20 +1040,27 @@ void parsePdoEntryAttrs(const char **attr) {
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "s32") == 0) {
|
||||
p->subType = lcecPdoEntTypeSimple;
|
||||
p->halType = HAL_S32;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "u32") == 0) {
|
||||
p->subType = lcecPdoEntTypeSimple;
|
||||
p->halType = HAL_U32;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "float") == 0) {
|
||||
p->subType = lcecPdoEntTypeFlaotSigned;
|
||||
p->halType = HAL_FLOAT;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "float-unsigned") == 0) {
|
||||
p->subType = lcecPdoEntTypeFloatUnsigned;
|
||||
p->halType = HAL_FLOAT;
|
||||
p->floatUnsigned = 1;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "complex") == 0) {
|
||||
p->subType = lcecPdoEntTypeComplex;
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, "%s: ERROR: Invalid pdoEntry halType %s\n", modname, val);
|
||||
@@ -1097,6 +1114,12 @@ void parsePdoEntryAttrs(const char **attr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// pin name must not be given for complex subtype
|
||||
if (p->subType == lcecPdoEntTypeComplex && p->halPin[0] != 0) {
|
||||
fprintf(stderr, "%s: ERROR: pdoEntry has halPin attributes but pin type is 'complex'\n", modname);
|
||||
XML_StopParser(parser, 0);
|
||||
}
|
||||
|
||||
// check for float type if required
|
||||
if (floatReq && p->halType != HAL_FLOAT) {
|
||||
fprintf(stderr, "%s: ERROR: pdoEntry has scale/offset attributes but pin type is not 'float'\n", modname);
|
||||
@@ -1109,6 +1132,106 @@ void parsePdoEntryAttrs(const char **attr) {
|
||||
(currSlave->pdoMappingCount)++;
|
||||
}
|
||||
(currPdo->pdoEntryCount)++;
|
||||
currSdoEntry = p;
|
||||
}
|
||||
|
||||
void parseComplexEntryAttrs(const char **attr) {
|
||||
int tmp;
|
||||
int floatReq;
|
||||
LCEC_CONF_COMPLEXENTRY_T *p = getOutputBuffer(sizeof(LCEC_CONF_COMPLEXENTRY_T));
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
floatReq = 0;
|
||||
p->confType = lcecConfTypeComplexEntry;
|
||||
p->floatScale = 1.0;
|
||||
while (*attr) {
|
||||
const char *name = *(attr++);
|
||||
const char *val = *(attr++);
|
||||
|
||||
// parse bitLen
|
||||
if (strcmp(name, "bitLen") == 0) {
|
||||
tmp = atoi(val);
|
||||
if (tmp <= 0 || tmp > LCEC_CONF_GENERIC_MAX_SUBPINS) {
|
||||
fprintf(stderr, "%s: ERROR: Invalid complexEntry bitLen %d\n", modname, tmp);
|
||||
XML_StopParser(parser, 0);
|
||||
return;
|
||||
}
|
||||
p->bitLength = tmp;
|
||||
continue;
|
||||
}
|
||||
|
||||
// parse halType
|
||||
if (strcmp(name, "halType") == 0) {
|
||||
if (strcasecmp(val, "bit") == 0) {
|
||||
p->subType = lcecPdoEntTypeSimple;
|
||||
p->halType = HAL_BIT;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "s32") == 0) {
|
||||
p->subType = lcecPdoEntTypeSimple;
|
||||
p->halType = HAL_S32;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "u32") == 0) {
|
||||
p->subType = lcecPdoEntTypeSimple;
|
||||
p->halType = HAL_U32;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "float") == 0) {
|
||||
p->subType = lcecPdoEntTypeFloatSigned;
|
||||
p->halType = HAL_FLOAT;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(val, "float-unsigned") == 0) {
|
||||
p->subType = lcecPdoEntTypeFloatUnsigned;
|
||||
p->halType = HAL_FLOAT;
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, "%s: ERROR: Invalid complexEntry halType %s\n", modname, val);
|
||||
XML_StopParser(parser, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// parse scale
|
||||
if (strcmp(name, "scale") == 0) {
|
||||
floatReq = 1;
|
||||
p->floatScale = atof(val);
|
||||
}
|
||||
|
||||
// parse offset
|
||||
if (strcmp(name, "offset") == 0) {
|
||||
floatReq = 1;
|
||||
p->floatOffset = atof(val);
|
||||
}
|
||||
|
||||
// parse halPin
|
||||
if (strcmp(name, "halPin") == 0) {
|
||||
strncpy(p->halPin, val, LCEC_CONF_STR_MAXLEN);
|
||||
p->halPin[LCEC_CONF_STR_MAXLEN - 1] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// handle error
|
||||
fprintf(stderr, "%s: ERROR: Invalid complexEntry attribute %s\n", modname, name);
|
||||
XML_StopParser(parser, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// bitLen is required
|
||||
if (p->bitLength == 0) {
|
||||
fprintf(stderr, "%s: ERROR: complexEntry has no bitLen attribute\n", modname);
|
||||
XML_StopParser(parser, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// check for float type if required
|
||||
if (floatReq && p->halType != HAL_FLOAT) {
|
||||
fprintf(stderr, "%s: ERROR: complexEntry has scale/offset attributes but pin type is not 'float'\n", modname);
|
||||
XML_StopParser(parser, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int parseSyncCycle(const char *nptr) {
|
||||
|
||||
Reference in New Issue
Block a user