#include "PrjCfg.h" #include #include #include #include "EthCamCmdParser.h" #include "FileSysTsk.h" #include "EthCamCmdParserInt.h" #include "EthCam/EthCamSocket.h" #include "kwrap/semaphore.h" #include "kwrap/flag.h" #include VOS_MODULE_VERSION(EthCamCmdParser, 1, 00, 000, 00) #define THIS_DBGLVL 2 // 0=FATAL, 1=ERR, 2=WRN, 3=UNIT, 4=FUNC, 5=IND, 6=MSG, 7=VALUE, 8=USER /////////////////////////////////////////////////////////////////////////////// #define __MODULE__ EthCamCmdPaser #define __DBGLVL__ ((THIS_DBGLVL>=PRJ_DBG_LVL)?THIS_DBGLVL:PRJ_DBG_LVL) #define __DBGFLT__ "*" //*=All, [mark]=CustomClass #include /////////////////////////////////////////////////////////////////////////////// #define ETHCAMCMD_STRCPY(dst, src, dst_size) do { strncpy(dst, src, dst_size-1); dst[dst_size-1] = '\0'; } while(0) #define ETHCAMCMD_MIMETYPE_MAXLEN 40 ///< mime type max length,refer to CYG_HFS_MIMETYPE_MAXLEN static ETHCAM_CMD_ENTRY *g_pCmdTab; static EthCamCmd_DefCB *gDefReturnFormat = 0; static EthCamCmd_EventHandle *gEventHandle = 0; static EthCamCmd_APPStartupCheck *gAppStartupChecker = NULL; static UINT32 g_result[ETHCAM_PATH_ID_MAX] = {0}; static UINT32 g_receiver = 0; static UINT32 g_app_startup_cmd = 0; static UINT32 g_curEthCamCmd = 0; static char g_parStr[ETHCAM_PAR_STR_LEN]; extern UINT32 EthCamCmd_WaitFinish(UINT32 path_id, FLGPTN waiptn); extern void EthCamCmd_Lock(UINT32 path_id); extern void EthCamCmd_Unlock(UINT32 path_id); typedef enum { ETHCAMCMD_PAR_NULL = 0, ETHCAMCMD_PAR_NUM, ETHCAMCMD_PAR_STR, ENUM_DUMMY4WORD(ETHCAMCMD_PAR_TYPE) } ETHCAMCMD_PAR_TYPE; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void EthCamCmd_ReceiveCmd(UINT32 enable) { DBG_IND("EthCamCmd_ReceiveCmd %d\r\n", enable); UINT16 i; if (enable) { if (g_receiver) { DBG_WRN("is enabled\r\n"); return ; } if ((!g_pCmdTab) || (!gEventHandle)) { DBG_ERR("no Cmd Table or event handle\r\n"); return; } for(i=0;i %s, mimeType= %s, bufsize= %d, segmentCount= %d\r\n", path, argument, mimeType, *bufSize, segmentCount); if (segmentCount == ETHCAM_CMD_GETDATA_SEGMENT_ERROR_BREAK) { DBG_ERR("segmentCount %d\r\n", segmentCount); EthCamCmd_Unlock(path_id); return ETHCAM_CMD_GETDATA_RETURN_ERROR; } if (strncmp(argument, CMD_STR, strlen(CMD_STR)) == 0) { if (segmentCount == 0) { EthCamCmd_Lock(path_id); } sscanf_s(argument + strlen(CMD_STR), "%d", &cmd); pch = strchr(argument + strlen(CMD_STR), '&'); if (pch) { if (strncmp(pch, PAR_STR, strlen(PAR_STR)) == 0) { sscanf_s(pch + strlen(PAR_STR), "%d", &par); ret = EthCamCmd_DispatchCmd(path_id, cmd, ETHCAMCMD_PAR_NUM, par, &UserCB); } else if (strncmp(pch, PARS_STR, strlen(PARS_STR)) == 0) { //DBG_ERR("%s\r\n",pch+strlen(PARS_STR)); ret = EthCamCmd_DispatchCmd(path_id ,cmd, ETHCAMCMD_PAR_STR, (UINT32)pch + strlen(PARS_STR), &UserCB); } } else { ret = EthCamCmd_DispatchCmd(path_id, cmd, ETHCAMCMD_PAR_NULL, 0, &UserCB); } if (UserCB) { UINT32 hfs_result; hfs_result = ((EthCamCmd_getCustomData *)UserCB)(path, argument, bufAddr, bufSize, mimeType, segmentCount); if (hfs_result != ETHCAM_CMD_GETDATA_RETURN_CONTINUE && hfs_result != ETHCAM_CMD_GETDATA_RETURN_CONTI_NEED_ACKDATA) { EthCamCmd_Unlock(path_id); } return hfs_result; } else { //default return value xml if (gDefReturnFormat) { gDefReturnFormat(cmd, ret, bufAddr, bufSize, mimeType); EthCamCmd_Unlock(path_id); return ETHCAM_CMD_GETDATA_RETURN_OK; } else { DBG_ERR("no default CB\r\n"); EthCamCmd_Unlock(path_id); return ETHCAM_CMD_GETDATA_RETURN_ERROR; } } } else { //for test,list url command UINT32 len = 0; char *buf = (char *)bufAddr; FST_FILE filehdl = 0; char pFilePath[32]; UINT32 fileLen = *bufSize; snprintf(pFilePath, sizeof(pFilePath), "%s", HTML_PATH); //html of all command list filehdl = FileSys_OpenFile(pFilePath, FST_OPEN_READ); if (filehdl) { // set the data mimetype ETHCAMCMD_STRCPY(mimeType, "text/html", ETHCAMCMD_MIMETYPE_MAXLEN); FileSys_ReadFile(filehdl, (UINT8 *)buf, &fileLen, 0, 0); FileSys_CloseFile(filehdl); *bufSize = fileLen; *(buf + fileLen) = '\0'; } else { ETHCAMCMD_STRCPY(mimeType, "text/html", ETHCAMCMD_MIMETYPE_MAXLEN); len = snprintf(buf, *bufSize, "no %s file", HTML_PATH); buf += len; *bufSize = (UINT32)(buf) - bufAddr; } } return ETHCAM_CMD_GETDATA_RETURN_OK; } INT32 EthCamCmd_PutData(UINT32 path_id, char *path, char *argument, UINT32 bufAddr, UINT32 bufSize, UINT32 segmentCount, UINT32 putStatus) ///< Callback function for put custom data. { UINT32 cmd = 0, par = 0; char *pch = 0; UINT32 ret = 0; UINT32 UserCB = 0; DBG_IND("path =%s, argument = %s, bufAddr = 0x%x, bufSize =0x%x , segmentCount =%d , putStatus = %d\r\n", path, argument, bufAddr, bufSize, segmentCount, putStatus); if (strncmp(argument, CMD_STR, strlen(CMD_STR)) == 0) { if (segmentCount == 0) { EthCamCmd_Lock(path_id); } sscanf_s(argument + strlen(CMD_STR), "%d", &cmd); pch = strchr(argument + strlen(CMD_STR), '&'); if (pch) { if (strncmp(pch, PAR_STR, strlen(PAR_STR)) == 0) { sscanf_s(pch + strlen(PAR_STR), "%d", &par); ret = EthCamCmd_DispatchCmd(path_id, cmd, ETHCAMCMD_PAR_NUM, par, &UserCB); } else if (strncmp(pch, PARS_STR, strlen(PARS_STR)) == 0) { ret = EthCamCmd_DispatchCmd(path_id, cmd, ETHCAMCMD_PAR_STR, (UINT32)pch + strlen(PARS_STR), &UserCB); } } else { ret = EthCamCmd_DispatchCmd(path_id, cmd, ETHCAMCMD_PAR_NULL, 0, &UserCB); } if ((ret == 0) && (UserCB)) { UINT32 hfs_result; hfs_result = ((EthCamCmd_puttCustomData *)UserCB)(path, argument, bufAddr, bufSize, segmentCount, putStatus); if (putStatus == ETHCAM_CMD_PUT_STATUS_FINISH) { EthCamCmd_Unlock(path_id); } return hfs_result; } else { DBG_ERR("no default CB\r\n"); EthCamCmd_Unlock(path_id); return ETHCAM_CMD_UPLOAD_FAIL_WRITE_ERROR; } } return ETHCAM_CMD_UPLOAD_OK; }