void cmdGetsModem( void ) { u8 ucBuffer[ __PYGMYCOM2BUFFERLEN ]; streamFIFOToString( MODEM_COM, ucBuffer ); //globalStreams[ COM2 ].RXBuffer[ globalStreams[ COM2 ].RXIndex++ ] = ; if( globalModemQueue.Count ){ if( globalModemQueue.Commands[ globalModemQueue.Index ].Status ){ //print( MODEM_DEBUG, "\rFIFO(%s)", ucBuffer ); if( globalModemQueue.Commands[ globalModemQueue.Index ].EventHandler( ucBuffer ) ) cmdDelete( &globalModemQueue, globalModemQueue.Index ); else{ globalModemQueue.Commands[ globalModemQueue.Index ].Status &= ~PYGMY_AT_TX; cmdProcess( &globalModemQueue ); } // else } // if } else{ } // else //print( MODEM_DEBUG, "\rProc Done." ); }
void DriverThread_ProcessCommands( void ) { cmdProcess( &globalModemQueue ); }
int main(int argc, char** argv) { Waifu2x::init_liblary(argc, argv); // Caffeのエラーでないログを保存しないようにする google::SetLogDestination(google::INFO, ""); google::SetLogDestination(google::WARNING, ""); // Caffeのエラーログを「error_log_〜」に出力 google::SetLogDestination(google::ERROR, "error_log_"); google::SetLogDestination(google::FATAL, "error_log_"); // definition of command line arguments TCLAP::CmdLine cmd("waifu2x reimplementation using Caffe", ' ', "1.0.0"); TCLAP::ValueArg<std::string> cmdInputFile("i", "input_path", "path to input image file", true, "", "string", cmd); TCLAP::ValueArg<std::string> cmdOutputFile("o", "output_path", "path to output image file (when input_path is folder, output_path must be folder)", false, "(auto)", "string", cmd); TCLAP::ValueArg<std::string> cmdInputFileExt("l", "input_extention_list", "extention to input image file when input_path is folder", false, "png:jpg:jpeg:tif:tiff:bmp:tga", "string", cmd); TCLAP::ValueArg<std::string> cmdOutputFileExt("e", "output_extention", "extention to output image file when output_path is (auto) or input_path is folder", false, "png", "string", cmd); std::vector<std::string> cmdModeConstraintV; cmdModeConstraintV.push_back("noise"); cmdModeConstraintV.push_back("scale"); cmdModeConstraintV.push_back("noise_scale"); cmdModeConstraintV.push_back("auto_scale"); TCLAP::ValuesConstraint<std::string> cmdModeConstraint(cmdModeConstraintV); TCLAP::ValueArg<std::string> cmdMode("m", "mode", "image processing mode", false, "noise_scale", &cmdModeConstraint, cmd); std::vector<int> cmdNRLConstraintV; cmdNRLConstraintV.push_back(1); cmdNRLConstraintV.push_back(2); cmdNRLConstraintV.push_back(3); TCLAP::ValuesConstraint<int> cmdNRLConstraint(cmdNRLConstraintV); TCLAP::ValueArg<int> cmdNRLevel("n", "noise_level", "noise reduction level", false, 1, &cmdNRLConstraint, cmd); TCLAP::ValueArg<double> cmdScaleRatio("s", "scale_ratio", "custom scale ratio", false, 2.0, "double", cmd); TCLAP::ValueArg<double> cmdScaleWidth("w", "scale_width", "custom scale width", false, 0, "double", cmd); TCLAP::ValueArg<double> cmdScaleHeight("h", "scale_height", "custom scale height", false, 0, "double", cmd); TCLAP::ValueArg<std::string> cmdModelPath("", "model_dir", "path to custom model directory (don't append last / )", false, "models/anime_style_art_rgb", "string", cmd); std::vector<std::string> cmdProcessConstraintV; cmdProcessConstraintV.push_back("cpu"); cmdProcessConstraintV.push_back("gpu"); cmdProcessConstraintV.push_back("cudnn"); TCLAP::ValuesConstraint<std::string> cmdProcessConstraint(cmdProcessConstraintV); TCLAP::ValueArg<std::string> cmdProcess("p", "process", "process mode", false, "gpu", &cmdProcessConstraint, cmd); TCLAP::ValueArg<int> cmdOutputQuality("q", "output_quality", "output image quality", false, -1, "int", cmd); TCLAP::ValueArg<int> cmdOutputDepth("d", "output_depth", "output image chaneel depth bit", false, 8, "int", cmd); TCLAP::ValueArg<int> cmdCropSizeFile("c", "crop_size", "input image split size", false, 128, "int", cmd); TCLAP::ValueArg<int> cmdCropWidth("", "crop_w", "input image split size(width)", false, 128, "int", cmd); TCLAP::ValueArg<int> cmdCropHeight("", "crop_h", "input image split size(height)", false, 128, "int", cmd); TCLAP::ValueArg<int> cmdBatchSizeFile("b", "batch_size", "input batch size", false, 1, "int", cmd); TCLAP::ValueArg<int> cmdGPUNoFile("", "gpu", "gpu device no", false, 0, "int", cmd); std::vector<int> cmdTTAConstraintV; cmdTTAConstraintV.push_back(0); cmdTTAConstraintV.push_back(1); TCLAP::ValuesConstraint<int> cmdTTAConstraint(cmdTTAConstraintV); TCLAP::ValueArg<int> cmdTTALevel("t", "tta", "8x slower and slightly high quality", false, 0, &cmdTTAConstraint, cmd); // definition of command line argument : end TCLAP::Arg::enableIgnoreMismatched(); // parse command line arguments try { cmd.parse(argc, argv); } catch (std::exception &e) { printf("エラー: %s\n", e.what()); return 1; } boost::optional<double> ScaleRatio; boost::optional<int> ScaleWidth; boost::optional<int> ScaleHeight; int valid_num = 0; if (cmdScaleWidth.getValue() > 0) valid_num++; if (cmdScaleHeight.getValue() > 0) valid_num++; if (valid_num > 1) { printf("エラー: scale_widthとscale_heightは同時に指定できません\n"); return 1; } int crop_w = cmdCropSizeFile.getValue(); int crop_h = cmdCropSizeFile.getValue(); if (cmdCropWidth.isSet()) crop_w = cmdCropWidth.getValue(); if (cmdCropHeight.isSet()) crop_h = cmdCropHeight.getValue(); if (cmdScaleWidth.getValue() > 0) ScaleWidth = cmdScaleWidth.getValue(); else if (cmdScaleHeight.getValue() > 0) ScaleHeight = cmdScaleHeight.getValue(); else ScaleRatio = cmdScaleRatio.getValue(); const boost::filesystem::path input_path(boost::filesystem::absolute((cmdInputFile.getValue()))); std::string outputExt = cmdOutputFileExt.getValue(); if (outputExt.length() > 0 && outputExt[0] != '.') outputExt = "." + outputExt; const std::string ModelName = Waifu2x::GetModelName(cmdModelPath.getValue()); const bool use_tta = cmdTTALevel.getValue() == 1; std::vector<std::pair<std::string, std::string>> file_paths; if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換 { boost::filesystem::path output_path; if (cmdOutputFile.getValue() == "(auto)") { // 「test」なら「test_noise_scale(Level1)(x2.000000)」みたいな感じにする std::string addstr("("); addstr += ModelName; addstr += ")"; const std::string &mode = cmdMode.getValue(); addstr += "(" + mode + ")"; if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos) addstr += "(Level" + std::to_string(cmdNRLevel.getValue()) + ")"; if (use_tta) addstr += "(tta)"; if (mode.find("scale") != mode.npos) { if(ScaleRatio) addstr += "(x" + std::to_string(*ScaleRatio) + ")"; else if (ScaleWidth) addstr += "(width " + std::to_string(*ScaleWidth) + ")"; else addstr += "(height " + std::to_string(*ScaleHeight) + ")"; } if (cmdOutputDepth.getValue() != 8) addstr += "(" + std::to_string(cmdOutputDepth.getValue()) + "bit)"; output_path = input_path.branch_path() / (input_path.stem().string() + addstr); } else output_path = cmdOutputFile.getValue(); output_path = boost::filesystem::absolute(output_path); if (!boost::filesystem::exists(output_path)) { if (!boost::filesystem::create_directory(output_path)) { printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", output_path.string().c_str()); return 1; } } std::vector<std::string> extList; { // input_extention_listを文字列の配列にする typedef boost::char_separator<char> char_separator; typedef boost::tokenizer<char_separator> tokenizer; char_separator sep(":", "", boost::drop_empty_tokens); tokenizer tokens(cmdInputFileExt.getValue(), sep); for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) { std::string ext(*tok_iter); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); extList.push_back("." + ext); } } // 変換する画像の入力、出力パスを取得 const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const boost::filesystem::path &path) { BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path), boost::filesystem::recursive_directory_iterator())) { if (boost::filesystem::is_directory(p)) { const auto out_relative = relativePath(p, input_path); const auto out_absolute = output_path / out_relative; if (!boost::filesystem::exists(out_absolute)) { if (!boost::filesystem::create_directory(out_absolute)) { printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", out_absolute.string().c_str()); return false; } } } else { std::string ext(p.extension().string()); std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); if (std::find(extList.begin(), extList.end(), ext) != extList.end()) { const auto out_relative = relativePath(p, input_path); const auto out_absolute = output_path / out_relative; const auto out = (out_absolute.branch_path() / out_absolute.stem()).string() + outputExt; file_paths.emplace_back(p.string(), out); } } } return true; }; if (!func(input_path)) return 1; } else {
int main(int argc, char** argv) { // definition of command line arguments TCLAP::CmdLine cmd("waifu2x reimplementation using Caffe", ' ', "1.0.0"); TCLAP::ValueArg<std::string> cmdInputFile("i", "input_path", "path to input image file", true, "", "string", cmd); TCLAP::ValueArg<std::string> cmdOutputFile("o", "output_path", "path to output image file (when input_path is folder, output_path must be folder)", false, "(auto)", "string", cmd); TCLAP::ValueArg<std::string> cmdInputFileExt("l", "input_extention_list", "extention to input image file when input_path is folder", false, "png:jpg:jpeg:tif:tiff:bmp", "string", cmd); TCLAP::ValueArg<std::string> cmdOutputFileExt("e", "output_extention", "extention to output image file when output_path is (auto) or input_path is folder", false, "png", "string", cmd); std::vector<std::string> cmdModeConstraintV; cmdModeConstraintV.push_back("noise"); cmdModeConstraintV.push_back("scale"); cmdModeConstraintV.push_back("noise_scale"); cmdModeConstraintV.push_back("auto_scale"); TCLAP::ValuesConstraint<std::string> cmdModeConstraint(cmdModeConstraintV); TCLAP::ValueArg<std::string> cmdMode("m", "mode", "image processing mode", false, "noise_scale", &cmdModeConstraint, cmd); std::vector<int> cmdNRLConstraintV; cmdNRLConstraintV.push_back(1); cmdNRLConstraintV.push_back(2); TCLAP::ValuesConstraint<int> cmdNRLConstraint(cmdNRLConstraintV); TCLAP::ValueArg<int> cmdNRLevel("n", "noise_level", "noise reduction level", false, 1, &cmdNRLConstraint, cmd); TCLAP::ValueArg<double> cmdScaleRatio("s", "scale_ratio", "custom scale ratio", false, 2.0, "double", cmd); TCLAP::ValueArg<std::string> cmdModelPath("", "model_dir", "path to custom model directory (don't append last / )", false, "models", "string", cmd); std::vector<std::string> cmdProcessConstraintV; cmdProcessConstraintV.push_back("cpu"); cmdProcessConstraintV.push_back("gpu"); cmdProcessConstraintV.push_back("cudnn"); TCLAP::ValuesConstraint<std::string> cmdProcessConstraint(cmdProcessConstraintV); TCLAP::ValueArg<std::string> cmdProcess("p", "process", "process mode", false, "gpu", &cmdProcessConstraint, cmd); TCLAP::ValueArg<int> cmdCropSizeFile("c", "crop_size", "input image split size", false, 128, "int", cmd); TCLAP::ValueArg<int> cmdBatchSizeFile("b", "batch_size", "input batch size", false, 1, "int", cmd); // definition of command line argument : end TCLAP::Arg::enableIgnoreMismatched(); // parse command line arguments try { cmd.parse(argc, argv); } catch (std::exception &e) { printf("エラー: %s\n", e.what()); return 1; } const boost::filesystem::path input_path(boost::filesystem::absolute((cmdInputFile.getValue()))); std::string outputExt = cmdOutputFileExt.getValue(); if (outputExt.length() > 0 && outputExt[0] != '.') outputExt = "." + outputExt; std::vector<std::pair<std::string, std::string>> file_paths; if (boost::filesystem::is_directory(input_path)) // input_pathがフォルダならそのディレクトリ以下の画像ファイルを一括変換 { boost::filesystem::path output_path; if (cmdOutputFile.getValue() == "(auto)") { // 「test」なら「test_noise_scale(Level1)(x2.000000)」みたいな感じにする std::string addstr("_" + cmdMode.getValue()); const std::string &mode = cmdMode.getValue(); if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos) addstr += "(Level" + std::to_string(cmdNRLevel.getValue()) + ")"; if (mode.find("scale") != mode.npos) addstr += "(x" + std::to_string(cmdScaleRatio.getValue()) + ")"; output_path = input_path.branch_path() / (input_path.stem().string() + addstr); } else output_path = cmdOutputFile.getValue(); output_path = boost::filesystem::absolute(output_path); if (!boost::filesystem::exists(output_path)) { if (!boost::filesystem::create_directory(output_path)) { printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", output_path.string().c_str()); return 1; } } std::vector<std::string> extList; { // input_extention_listを文字列の配列にする typedef boost::char_separator<char> char_separator; typedef boost::tokenizer<char_separator> tokenizer; char_separator sep(":", "", boost::drop_empty_tokens); tokenizer tokens(cmdInputFileExt.getValue(), sep); for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) extList.push_back("." + *tok_iter); } // 変換する画像の入力、出力パスを取得 const auto func = [&extList, &input_path, &output_path, &outputExt, &file_paths](const boost::filesystem::path &path) { BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path), boost::filesystem::recursive_directory_iterator())) { if (boost::filesystem::is_directory(p)) { const auto out_relative = relativePath(p, input_path); const auto out_absolute = output_path / out_relative; if (!boost::filesystem::exists(out_absolute)) { if (!boost::filesystem::create_directory(out_absolute)) { printf("エラー: 出力フォルダ「%s」の作成に失敗しました\n", out_absolute.string().c_str()); return false; } } } else if (std::find(extList.begin(), extList.end(), p.extension().string()) != extList.end()) { const auto out_relative = relativePath(p, input_path); const auto out_absolute = output_path / out_relative; const auto out = (out_absolute.branch_path() / out_absolute.stem()).string() + outputExt; file_paths.emplace_back(p.string(), out); } } return true; }; if (!func(input_path)) return 1; } else {
/******************************************************************************* * Function Name : cmdProcess * Description : process the command. * Input : cmd: command string * repeating: TRUE: repeat command, FALSE: new command * Output : None. * Return : None. *******************************************************************************/ void cmdMonitor(void) { char c; uint32_t repeating = 0; uint32_t histDownArw; static uint32_t upArrowCnt; if(ConsoleStartFlg) { c = (char)getkey(); } else { c = '\r'; ConsoleStartFlg = 1; } if(!logIn) { if(c == '\r') { logIn = TRUE; printf("\r\ncmd>"); } } else { switch(c) { case '\b': case '\x7f': if(pos > 0) { printf("\b \b"); pos--; } cmdBuffer[pos] = '\0'; break; case '\r': /* Process the command. */ printf("\r\n"); if(pos) { /* Do not place the same last command into the history if the same. */ if(strcmp((char *)histBuf[histIns], cmdBuffer)) { if(cmdIdxIncrease(&histIns) == TRUE) { histInsWrap = 1; } memcpy(histBuf[histIns], cmdBuffer, CMD_BUF_SIZE); histPos[histIns] = pos; } histOutput = histIns; histOutputWrap = 0; upArrowCnt = 0; repeating = FALSE; } if(pos) { cmdProcess(cmdBuffer, repeating); pos = 0; memset(cmdBuffer, 0, CMD_BUF_SIZE); printf("\n"); } printf("\rcmd>"); break; case '[': /* Non ASCII characters, arrow. */ c = getkey(); switch (c) { case 'A': /* Key: up arrow */ if(histOutputWrap == 1) { if(histOutput == histIns) { break; } } if(histInsWrap == 0) { if(histOutput == 0) { break; } } upArrowCnt++; cmdFlushCopy(pos,cmdBuffer,(char *)histBuf[histOutput],histPos[histOutput]); pos = histPos[histOutput]; cmdBuffer[pos + 1] = '\0'; printf(cmdBuffer); if(histInsWrap == 1) { if(histOutput == 0) { histOutput = CMD_HISTORIES - 1; histOutputWrap = 1; } else { histOutput--; } } else { if(histOutput != 0) { /* Note that when wrap around does not occur, the least * of index is 1 because it is the first one to be * written. */ histOutput--; } /* Nothing to do with histOutput == 0, * because there is no more commands. */ } break; case 'B': /* Key: down arrow */ if(upArrowCnt <= 1) break; upArrowCnt--; cmdIdxIncrease(&histOutput); histDownArw = histOutput; cmdIdxIncrease(&histDownArw); cmdFlushCopy(pos,cmdBuffer,(char *)histBuf[histDownArw],histPos[histDownArw]); pos = histPos[histDownArw]; cmdBuffer[pos + 1] = '\0'; printf(cmdBuffer); break; case 'C': /* Key: right arrow */ break; case 'D': /* Key: left arrow */ break; default: break; } break; default: if((pos < (CMD_BUF_SIZE - 1)) && (c >= ' ') && (c <= 'z')) { cmdBuffer[pos++] = c; cmdBuffer[pos] = '\0'; printf(cmdBuffer + pos - 1); } if( c == '\x7e' ) {// '~' cmdBuffer[pos++] = c; cmdBuffer[pos] = '\0'; printf(cmdBuffer + pos - 1); } break; } } /* else of if !logged_in */ }
/* * Main entry point. */ void main(void) { static TICK8 t = 0; static TICK8 tmr10ms = 0; //Initialize any application specific hardware. InitializeBoard(); //Initialize all stack related components. Following steps must //be performed for all applications using PICmicro TCP/IP Stack. TickInit(); //Initialize file system. fsysInit(); //Intialize HTTP Execution unit htpexecInit(); //Initialze serial port serInit(); //Initialize Stack and application related NV variables. appcfgInit(); appcfgUSART(); //Configure the USART #ifdef SER_USE_INTERRUPT //Interrupt enabled serial ports have to be enabled serEnable(); #endif appcfgCpuIO(); //Configure the CPU's I/O port pin directions - input or output appcfgCpuIOValues(); //Configure the CPU's I/O port pin default values appcfgADC(); //Configure ADC unit appcfgPWM(); //Configure PWM Channels //Serial configuration menu - display it for configured time and allow user to enter configuration menu scfInit(appcfgGetc(APPCFG_STARTUP_SER_DLY)); //LCD Display Initialize lcdInit(); StackInit(); #if defined(STACK_USE_HTTP_SERVER) HTTPInit(); #endif #if defined(STACK_USE_FTP_SERVER) FTPInit(); #endif //Initializes "UDP Command Port" and "UDP Command Responce Port". cmdUdpInit(); #if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) DHCPReset(); //Initialize DHCP module //If DHCP is NOT enabled if ((appcfgGetc(APPCFG_NETFLAGS) & APPCFG_NETFLAGS_DHCP) == 0) { //Force IP address display update. myDHCPBindCount = 1; #if defined(STACK_USE_DHCP) DHCPDisable(); #endif } #endif #if (DEBUG_MAIN >= LOG_DEBUG) debugPutMsg(1); //@mxd:1:Starting main loop #endif /* * Once all items are initialized, go into infinite loop and let * stack items execute their tasks. * If application needs to perform its own task, it should be * done at the end of while loop. * Note that this is a "co-operative mult-tasking" mechanism * where every task performs its tasks (whether all in one shot * or part of it) and returns so that other tasks can do their * job. * If a task needs very long time to do its job, it must broken * down into smaller pieces so that other tasks can have CPU time. */ while(1) { //Clear timer 1 every cycle, can be used to measure events. Has a overflow of 65ms. //Get delay in this function with: // TMR1L | (TMR1H<<8) TMR1H = 0; //First write to TMR1H buffer! TMR1L = 0; //This write will also update TMR1H with value written above to buffer //Blink SYSTEM LED every second. if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) { if ( TickGetDiff8bit(t) >= ((TICK8)TICKS_PER_SECOND / (TICK8)2) ) { t = TickGet8bit(); TRISB_RB6 = 0; LATB6 ^= 1; } } //Enter each 10ms if ( TickGetDiff8bit(tmr10ms) >= ((TICK8)TICKS_PER_SECOND / (TICK8)100) ) { tmr10ms = TickGet8bit(); } //This task performs normal stack task including checking for incoming packet, //type of packet and calling appropriate stack entity to process it. StackTask(); //Process "UDP Command Port" and "UDP Command Responce Port" cmdProcess(); #if defined(STACK_USE_HTTP_SERVER) //This is a TCP application. It listens to TCP port 80 //with one or more sockets and responds to remote requests. HTTPServer(); #endif #if defined(STACK_USE_FTP_SERVER) FTPServer(); #endif #if defined(STACK_USE_ANNOUNCE) DiscoveryTask(); #endif #if defined(STACK_USE_NBNS) NBNSTask(); #endif //Add your application speicifc tasks here. ProcessIO(); //For DHCP information, display how many times we have renewed the IP //configuration since last reset. if ( DHCPBindCount != myDHCPBindCount ) { #if (DEBUG_MAIN >= LOG_INFO) debugPutMsg(2); //@mxd:2:DHCP Bind Count = %D debugPutByteHex(DHCPBindCount); #endif //Display new IP address #if (DEBUG_MAIN >= LOG_INFO) debugPutMsg(3); //@mxd:3:DHCP complete, IP = %D.%D.%D.%D debugPutByteHex(AppConfig.MyIPAddr.v[0]); debugPutByteHex(AppConfig.MyIPAddr.v[1]); debugPutByteHex(AppConfig.MyIPAddr.v[2]); debugPutByteHex(AppConfig.MyIPAddr.v[3]); #endif myDHCPBindCount = DHCPBindCount; #if defined(STACK_USE_ANNOUNCE) AnnounceIP(); #endif } } }
/* * rx proccess */ static int doClientRxCommand(struct _client* client,struct _protocol *p){ struct _cmdInput in; struct _cmdOutput out; int tx_len = 0; int i = 0; int err = 0; in.cmd = p->thisCmd; in.data = p->data; in.len = p->dataLen; in.client = client; //need get id first if(client->isVeryfied == 0 && in.cmd != CMD_GET_ID ){ clientGetIdFromBoard(client); } /* * already verified, just do nothing! */ else if(client->isVeryfied !=0 && in.cmd == CMD_GET_ID){ return 0; } out.needRsp = 0; out.data = p->sendData; out.len = PROTOCOL_MAX_TXDATA_SIZE; //bms client cmd if( (err = cmdProcess(&in,&out,&client->m_data))>=0){ if( out.needRsp > 0 ){ tx_len = p->protocolPack(out.cmd, out.data, out.len, p); //if need response, just store in write buffer ,and wait to send /* printf("\r\nrsp a pack:\r\n"); for(i=0;i<p->sendPkgLen;i++){ printf("%02x ",p->sendBuff[i]&0x0ff); } printf("\r\n"); */ return client->write(client,p->sendBuff,p->sendPkgLen); } else{ //maybe a just response pack, do not need to response yet. //process already do in function doCommand //TODO //printProtocolData(&client->m_data); sqlStore(client->m_data.id, p, &client->m_data, &client->m_persis_data); } /* * bid check OK! */ if(in.cmd == CMD_GET_ID ){ if(is_bid_exist(client->m_data.id)!=0){ redis_bid_online(client->m_data.id); client->isVeryfied = 1; printf("****CLIENT:%s in!\r\n",client->m_data.id); } else{ doDeleteClient(client->socket); } } } else{ printf("err cmdProcess:%d!\r\n",err); } //control client cmd return -1; }
IEC_UINT cmdRun(STaskInfoVMM *pVMM, IEC_UINT uSignal, XBlock *pBlock) { SCmdVMM *pCMD = &pVMM->CMD; IEC_BOOL bFirst = TRUE; if (uSignal == SIG_DATA && pBlock->uBlock == 1) { /* Reset */ pCMD->uState = AS_IDLE; } while (bFirst || (pCMD->uState != AS_IDLE && pCMD->uState != AS_DATA_READY && pCMD->uState != AS_RESP_READY)) { switch (pCMD->uState) { case AS_IDLE: { pCMD->uState = AS_FIRST_DATA; break; } /* ------------------------------------------------------------- */ case AS_FIRST_DATA: { /* Process first data block */ if (cmdProcess (pVMM, SIG_FIRST, pBlock) != OK) { RETURN(ERR_ERROR); } pCMD->uState = (IEC_UINT)(pBlock->byLast ? AS_SWITCH : AS_DATA_READY); break; } /* ------------------------------------------------------------- */ case AS_DATA_READY: { pCMD->uState = AS_PROC_DATA; break; } /* ------------------------------------------------------------- */ case AS_PROC_DATA: { /* Process data block */ if (cmdProcess (pVMM, SIG_FIRST, pBlock) != OK) { RETURN(ERR_ERROR); } pCMD->uState = (IEC_UINT)(pBlock->byLast ? AS_SWITCH : AS_DATA_READY); break; } /* ------------------------------------------------------------- */ case AS_SWITCH: { /* Switch beetween command / resonse */ if (cmdProcess (pVMM, SIG_SWITCH, 0) != OK) { RETURN(ERR_ERROR); } pCMD->uState = AS_RESP_READY; break; } /* ------------------------------------------------------------- */ case AS_RESP_READY: { pCMD->uState = AS_PROC_RESPONSE; break; } /* ------------------------------------------------------------- */ case AS_PROC_RESPONSE: { /* Process the next response block */ if (cmdProcess (pVMM, SIG_RESPONSE, pBlock) != OK) { RETURN(ERR_ERROR); } pCMD->uState = (IEC_UINT)(pBlock->byLast ? AS_IDLE : AS_RESP_READY); break; } /* ------------------------------------------------------------- */ default: { RETURN(ERR_ERROR); } /* ------------------------------------------------------------- */ } bFirst = FALSE; } RETURN(OK); }