/** * @brief User Process * @param phost: Host Handle * @param id: Host Library user message ID * @retval None */ static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id) { switch(id) { case HOST_USER_SELECT_CONFIGURATION: break; case HOST_USER_DISCONNECTION: Appli_state = APPLICATION_DISCONNECT; break; case HOST_USER_CLASS_ACTIVE: GetDefaultConfiguration(); Appli_state = APPLICATION_READY; break; case HOST_USER_CONNECTION: Appli_state = APPLICATION_START; break; default: break; } }
/* ParseConfigurationFile - parse a configuration file */ BoardConfig *ParseConfigurationFile(const char *name) { char path[PATH_MAX]; BoardConfig *baseConfig, *config; const char *src; char *tag, *dst; LineBuf buf; FILE *fp; int ch; /* make a local copy of the name in lowercase */ src = name; dst = path; while ((*dst++ = tolower(*src++)) != '\0') ; /* check for a request for the default configuration */ if (strcmp(path, DEF_BOARD) == 0) return GetDefaultConfiguration(); /* make the configuration file name */ strcat(path, ".cfg"); /* open the configuration file */ if (!(fp = xbOpenFileInPath(path, "r"))) return NULL; /* create a new board configuration */ baseConfig = config = NewBoardConfig(GetDefaultConfiguration(), name); /* initialize the line number */ buf.lineNumber = 0; /* process each line in the configuration file */ while (fgets(buf.lineBuf, sizeof(buf.lineBuf), fp)) { char *p; int len; /* check for a comment at the end of the line */ if ((p = strchr(buf.lineBuf, '#')) != NULL) *p = '\0'; /* trim any trailing newline and spaces */ for (len = strlen(buf.lineBuf); len > 0; --len) if (!isspace(buf.lineBuf[len-1])) break; buf.lineBuf[len] = '\0'; /* initialize token parser */ buf.linePtr = buf.lineBuf; ++buf.lineNumber; /* look for the first token on the line */ switch (SkipSpaces(&buf)) { case '\0': /* blank line */ case '#': /* comment */ // ignore blank lines and comments break; case '[': /* configuration tag */ /* get the configuration name */ ++buf.linePtr; if (!(tag = NextToken(&buf, "]", &ch))) ParseError(&buf, "missing configuration tag"); if (ch != ']') { if (SkipSpaces(&buf) != ']') ParseError(&buf, "missing close bracket after configuration tag"); ++buf.linePtr; } if (SkipSpaces(&buf) != '\0') ParseError(&buf, "missing end of line"); /* add a new board configuration */ config = NewBoardConfig(baseConfig, tag); break; default: /* tag:value pair */ /* get the tag */ if (!(tag = NextToken(&buf, ":", &ch))) ParseError(&buf, "missing tag"); /* check for the colon separator */ if (ch != ':') { if (SkipSpaces(&buf) != ':') ParseError(&buf, "missing colon"); ++buf.linePtr; } /* skip leading spaces before the value */ SkipSpaces(&buf); /* set the configuration value */ SetConfigField(config, tag, buf.linePtr); break; } } /* close the board configuration file */ fclose(fp); /* return the board configuration */ return baseConfig; }