#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "settings.h" #include "packets.h" #include "http_utils.h" #include "TimeControl.h" #include "ui.h" #include "framcontrol.h" #include "zvlc.h" #include "comm485.h" #define CMD_STACK_SIZE 32 #define ESC 27 #define DEL 127 #define DEST_ADDR_SIZE 5 extern volatile unsigned long time_to_reset; extern FILE *uart; extern SETTINGSCOMM* pSettingsComm; extern SETTINGSPACK* pSettingsPack; extern volatile type_ticks ticks; extern volatile type_RTC_timedate rtc_datetime; extern u_char old_interval; extern u_char* pMsgBuf; // buffer for terminal reply messages extern volatile char bSynchronizeTime; extern volatile unsigned int g_ChatMin; extern volatile u_char bReboot; extern TCPSOCKET *tcpSocketList; volatile u_char bWriteLog = LOG_SHORT; //LOG_NET; // volatile char nKeepUserDlgModeMin = 5; void ViewSettings( SETTINGSCOMM* ps ); int IPisValud( const u_char* p ); void parse_date_command( const u_char* p1 ); u_char timeFmtIsValid( const u_char* p, int min, int max ); char ParseDestAddr( const u_char* p1, u_char dest_addr[3] ); u_char escape=0; u_char arrow=0; u_char nRotor=0; u_char sticks[]="-\\|/"; void PrintSharp( void ) { fprintf(uart,"%c\b", sticks[nRotor++]); if(nRotor>3) nRotor=0; fflush(uart); } void PrintPrompt( void ) { fputs_P (PSTR("\r\n>"),uart); fflush(uart); } void PrintVersion(void) { strcpy_p( pMsgBuf, VERSION ); } void PrintHelp( void ) { addToMsg( PSTR("\r\nconf - configuration;" "\r\ndate - view or set date and time;" "\r\ndefault - restore default configuration;" "\r\nlog [-sfdw ] view log;" "\r\nmac [-s ] view mac or set mac;" "\r\npack - manage packets;" "\r\nreboot - reboot the box;" "\r\nsave - save configuration to EEPROM;" "\r\nsearch [-z -m -o] - search zvlcs, mepcos or oplcs on the line;" "\r\ntest - right now;" "\r\nreset [485] - reset remote RS485 KYZ counter. Example: reset 485 50 1" "\r\n?, help - this screen.") ); } void PrintLogHelp( void ) { addToMsg( PSTR( "\r\nUsage:log ? -sfdw;" "\r\n-d - view log of device interaction;" "\r\n-f - view full log of;" "\r\n-r - view radio log;" "\r\n-s - view short log;" "\r\n-w - view log of http interaction;" "\r\n? - this screen.") ); } void PrintDateHelp( void ) { addToMsg( PSTR("\r\nUsage:date ? [-r min] [-z] [-s [Www,][dd][Mon][YYYY][hh:mm:[ss]];" "\r\nWhen invoked without arguments - display the current date and time;" "\r\n-s - set date and time, for example -s Wed, 26 Feb 2003 17:45:30;" "\r\n-z synchroniZe datetime with http server;" "\r\n-r synchronize datetime of remote device having id = ID with http server;" "\r\n? - this screen") ); } void PrintConfHelp( void ) { addToMsg( PSTR("\r\nUsage:conf -limgsht;" "\r\n-l - list of configuration;" "\r\n-q - list of threads;" "\r\n-i set IP address of the Box;" "\r\n-m set IP mask of the Box;" "\r\n-g set default gateway;" "\r\n-s set IP address of the HTTP Server;" "\r\n-t - set field polling period in seconds from 5 to 3600;" "\r\n it is strongly recommended to choose a whole number" "\r\n of polling periods within an hour interval" "\r\n? - this screen.") ); } void PrintPackHelp( FILE* outstream ) { fputs_P( PSTR("\r\nUsage:pack -laimrvdA;" "\r\n-l - list all or n-th packet; -A xxxxxx - destination Address if radio is on;" "\r\n-v

[ []]- add packet for

rotocol;" "\r\n\tp=6-temperature; ex: pack -v 6" "\r\n\tp=7-ZVLC; ddress[1...99] ex: pack -v 7 1" "\r\n\tp=8-Pulse counter; ddress[1...200] ex: pack -v 8 50" "\r\n\tp=14-Input contacts state ex: pack -v 14" "\r\n\tp=16-OPLC; ddress[1...99] ex: pack -v 16 1" "\r\n\tp=15-MEPCO; ddress[1...35] ex: pack -v 15 1" "\r\n\tp=19-'4-20mA' receiver; ddress[1...200] ex: pack -v 19 50" "\r\n-d - delete packet n;" "\r\n? - this screen."), outstream); } void PrintExecHelp( void ) { addToMsg( PSTR("\r\nUsage: Send some command to field device\r\n")); } THREAD( Ui, arg ) { int rlen = 0; u_char* pCmd; u_char* pLastCmd; // pointer to the 1st byte of the last pushed command u_char* pCmdStackTop; // pointer to where to place entered command u_char* pCmdStack; pCmd = NutHeapAllocClear( 128 ); pCmdStack = NutHeapAllocClear( CMD_STACK_SIZE ); pCmdStackTop = pCmdStack; pLastCmd = pCmdStack; NutThreadSetPriority(128); u_char buf[1]; u_char* pThis=pCmd; u_char* pEnd=pCmd; for( ; ; ) { if( (rlen = _read(_fileno(uart), buf, sizeof(buf))) > 0 ){ nKeepUserDlgModeMin = 5; // keep User Dialog Mode for next 5 min; if(bWriteLog!=LOG_PROMPT) { bWriteLog=LOG_PROMPT; PrintPrompt(); pThis=pCmd; pEnd=pCmd; } u_char* p = buf; // first coming character // fprintf(uart, "\t\tGot %x \n\r", *p ); if(*p== ESC){ //arrow is ESC-sequence. escape = 1; } else if((*p=='[')&&(escape == 1)){ arrow = 1; } else if(*p==DEL){ fputs_P(PSTR("\t\t got del"), uart); if(pThis pThis ) fputs_P(PSTR("\b"),uart); // move cursor one position back } } else if(arrow==0){ if( (*p>=' ') && (*p<128) ){ // printable _write(_fileno(uart),0,0); u_char* p1 = ++pEnd; while(p1>pThis) { *p1=*(p1-1); p1--;} *pThis = *p; _write(_fileno(uart), pThis, (pEnd-pThis)); //provide echo p1=pEnd; pThis++; while(p1-- > pThis ) fputs_P(PSTR("\b"),uart); // wipe out last charcter } else if( *p == '\b' && pThis>pCmd){ // backSpace _write( _fileno(uart), "\b",1 ); pThis--; u_char* p1 = pThis; pEnd--; while(p1 pThis ) _write( _fileno(uart), "\b",1 ); // back one position } } else { // Arrows if( *p =='D'){ if(pThis > pCmd) //Left arrow { // _write( _fileno(uart), "\b",1 ); fputs_P(PSTR("\b"), uart); pThis--; } arrow = 0; escape = 0; } else if( *p =='C') { if(pThispCmd) { while(pThis-- >pCmd ) fputs_P( PSTR("\b"), uart); // Home pThis=pCmd; } arrow = 0; escape = 0; } else if(*p =='K'){ //End if(pThis 0 ); pA++; if( pA >= (pCmdStack+CMD_STACK_SIZE) ) pA = pCmdStack; if(*pA>0 ){ // not empty string while( pEnd-- > pCmd) fputs_P(PSTR("\b \b"), uart); // erase the command on the screen // pop stored command pLastCmd = pA; if( pLastCmd <= pCmdStack) pLastCmd = pCmdStack+CMD_STACK_SIZE; pLastCmd--; pEnd = pCmd; while( *pA>0 ) { *pEnd++ = *pA++; if( pA>=pCmdStack+CMD_STACK_SIZE) pA = pCmdStack; // circle stack } pThis=pEnd; _write(_fileno(uart), pCmd, (pEnd-pCmd)); } else fputs_P(PSTR("\a"), uart); arrow = 0; escape = 0; } else if( (*p =='B') ) { // down arrow // try to pop stored command if any u_char* p = pLastCmd+1; if( p>=pCmdStack+CMD_STACK_SIZE) p = pCmdStack; // circle stack while( (*p > 0) ) { // roll back pLastCmd pointer to pop up previous command p++; if( p >= (pCmdStack+CMD_STACK_SIZE) ) p = pCmdStack; } p++; if( p>=pCmdStack+CMD_STACK_SIZE) p = pCmdStack; // circle stack if( *p >0 ) { // there is a command line! pLastCmd = p; if( pLastCmd <= pCmdStack) pLastCmd = pCmdStack+CMD_STACK_SIZE; pLastCmd--; //NutPrintFormat(uart, "B pCmdStackTop=%d, pLastCmd=%d *pLastCmd=%c\r\n", pCmdStackTop-pCmdStack, pLastCmd-pCmdStack, *pLastCmd); while( pEnd-- > pCmd) fputs_P(PSTR("\b \b"), uart);// NutPrintString_P( uart, PSTR("\b \b") ); // erase the command on the screen pEnd = pCmd; while( *p>0 ) { *pEnd++ = *p++; if( p>=pCmdStack+CMD_STACK_SIZE) p = pCmdStack; // circle stack } pThis=pEnd; _write(_fileno(uart), pCmd, (pEnd-pCmd)); // Right arrow } else fputs_P(PSTR("\a"), uart); arrow = 0; escape = 0; } } if( *p == '\r' || *p == '\n'){ *pEnd = 0; // store command u_char* p = pCmd; do{ *pCmdStackTop++ = *p++; if( pCmdStackTop>=pCmdStack+CMD_STACK_SIZE) pCmdStackTop = pCmdStack; // circle stack }while( *p>0); pLastCmd = pCmdStackTop; // last zero byte *pCmdStackTop++ = 0; if( pCmdStackTop>=pCmdStack+CMD_STACK_SIZE) pCmdStackTop = pCmdStack; // circle stack p = pCmdStackTop; while( *p>0 ){ // wipe out old line "garbage" *p++ = 0; // mark top of stack with the second zero byte if( p >= pCmdStack+CMD_STACK_SIZE) p = pCmdStack; // circle stack } // strcpy( pCmdStack, pCmd ); // Empty pMsgBuf u_char *pCmd1=pCmd; do { pCmd1=ParseCmd( pCmd1,uart ); // all reply message now in pMsgBuf, just print it to console fputs(pMsgBuf,uart); } while( pCmd1>0 ); pThis=pCmd; pEnd=pCmd; if( bWriteLog == LOG_PROMPT ) PrintPrompt(); } fflush(uart); } NutThreadYield(); } } void ViewSettings( SETTINGSCOMM* ps ) { addToMsg( PSTR( "\r\nNetwork Configuration\r\nIP:\t\t" ) ); strcat( pMsgBuf, ps->ip ); addToMsg( PSTR( "\r\nMask:\t\t") ); strcat( pMsgBuf, ps->mask ); addToMsg( PSTR( "\r\nGateway:\t") ); strcat( pMsgBuf, ps->gateway ); addToMsg( PSTR( "\r\nHttp Server:\t") ); strcat( pMsgBuf, ps->http_server_ip ); // addToMsg( PSTR( "\r\nHttp header:\r\n") ); // strcat( pMsgBuf, ps->http_header ); addToMsg( PSTR( "\r\nPolling period, sec = " ) ); strcat_dec( pMsgBuf, ps->rq_period_sec ); } int IPisValud( const u_char* p ){ u_char i=0; u_char ipt=0; u_int r=0; while( (i++<16) && (*p>0) && (!isspace(*p)) && (r==0) ) { if( (!isdigit(*p)) && (*p!='.') ) r=1; if(*p=='.') ipt++; p++; } if(ipt!=3) r=2; // must be 3 '.' if(r>0) fputs_P(PSTR("\r\nError: Invalid format of IP address"), uart); // NutPrintString_P(uart, PSTR("\r\nError: Invalid format of IP address") ); return r; } /* commands can be separated by semicolon ParseCmd returns 0 if last command have been executed */ unsigned char* ParseCmd( u_char* pCmd, FILE *stream ) { u_char* p1 = pCmd; u_char* p0 = p1; while( (*p1!=0) && (*p1!=';')) *p1++; if(*p1>0) { *p1=0; //DEBUG fputs_P(PSTR("Command is NOT last\r\n"),uart ); ParseCmd1( p0, stream ); *p1++=';'; return p1; } //DEBUG fputs_P(PSTR("Command is last\r\n"),uart ); ParseCmd1( p0,stream ); return 0; } void ParseCmd1( const u_char* pCmd, FILE *stream ){ //DEBUG fprintf(stream, "Exec: %s", pCmd); fputs_P(PSTR("\r\n"), stream); fflush(stream); pMsgBuf[0]=0; // Empty message buffer const u_char* pEnd = pCmd; while(*pEnd>0) pEnd++; const u_char* p1 = pCmd; while( isspace(*p1)) p1++; if( p1>=pEnd || *p1=='?'){ // set command "alone" - show help PrintHelp(); return; } if( strncmp( p1, "save", 4)==0){ time_to_reset = 5*RESET_TIMEOUT; fputs_P(PSTR("Saving Settings to EEPROM..."),stream); fflush(stream); SaveCommSettingsToEEPROM( ); SavePackSettingsToEEPROM( ); fputs_P(PSTR("Done."),stream); fflush(stream); return; } else if( strncmp( p1, "default", 7)==0){ SetDefaultCommSettings( ); SetDefaultPackSettings( ); fputs_P( PSTR("Default configuration restored. You need to save it to EEPROM and reboot to make it takes effect"),stream); fflush(stream); } else if( strncmp( p1, "ver", 3)==0){ PrintVersion(); return; } else if( strncmp( p1, "mac", 3)==0){ NEXT_TERM(p1); if( p1>=pEnd || *p1=='?' ){ // set command "alone" - show help fputs_P(PSTR("mac address: "),stream); PrintPacket( stream, pSettingsComm->mac, 6); return; } if(*p1=='-' || *p1=='\\') { u_char c = *++p1; // cmd char if( c == 's' ) // set mac { SetMacAddr( p1 ); return; } } } else if( strncmp( p1, "test", 4)==0){ //QQQ fputs_P(PSTR("Test. Hit any key to come back to prompt...\r\n"),stream); fflush(stream); bWriteLog = LOG_FIELD; old_interval=254; // set it more than 60 but not 255 - so next second the requests to field devices will be sent } else if( strncmp( p1, "reboot", 6)==0){ bReboot = 0xAA; addToMsg( PSTR("Reboot command received.")); } else if( strncmp( p1, "reset", 5)==0){ NEXT_TERM(p1); if( strncmp( p1, "485", 3)==0){ u_char numdev = 0,numcnt = 0; NEXT_TERM(p1); if( isdigit(*p1)) numdev = atoi(p1); NEXT_TERM(p1); if( isdigit(*p1)) numcnt = atoi(p1); if(numcnt > 1) { fputs_P(PSTR("counter # should be 0 or 1. Let it be 0..\r\n"), uart); } if((reset_485_kyz(numdev,numcnt)) != 0) { fputs_P(PSTR("no communication by RS485"),uart); } else{ fprintf(uart,"KYZ counter %x of %x 485 device reset to zero\r\n ",numcnt, numdev); } fflush(uart); } } else if( strncmp( p1, "chat", 4)==0){ NEXT_TERM(p1); if( isdigit(*p1)) g_ChatMin = atoi(p1); if( (g_ChatMin<1)||(g_ChatMin>60) ) { g_ChatMin = 15; // 15 minutes by default } addToMsg( PSTR("Chat mode is set for ")); strcat_dec( pMsgBuf, g_ChatMin ); addToMsg( PSTR(" min.")); } else if( strncmp( p1, "conf", 4)==0){ NEXT_TERM(p1); if( p1>=pEnd || *p1=='?' ){ // set command "alone" - show help PrintConfHelp(); return; } while(*p1>0) { // we need to set something if(*p1=='-' || *p1=='\\') { u_char* pd = 0; // destination u_char c = *++p1; // cmd char if(c == 't') // set polling period in min { while( (*p1>0)&&(!isspace(*p1)) ) p1++; while( isspace(*p1)||(*p1=='=')||(*p1==':') ) p1++; // point to new param int dt = 0; while( isdigit(*p1) ) dt = dt*10 + (*p1++ - '0'); if( dt>5 && dt<3600 ) { pSettingsComm->rq_period_sec = dt; // field device polling period in seconds addToMsg( PSTR("Polling period is ")); strcat_dec( pMsgBuf, pSettingsComm->rq_period_sec ); addToMsg( PSTR(" sec.")); if(3600%dt !=0) { addToMsg( PSTR("Number of periods within an hour interval is not whole.")); } } else { addToMsg( PSTR("Wrong value. period t must be more than 5 and less than 3600 seconds")); } return; } else if( c =='l'){ ViewSettings( pSettingsComm ); } else if(c == 'q'){ ListOfThreads(stream); } else if( c=='i') { pd = pSettingsComm->ip; } else if( c=='m') { pd = pSettingsComm->mask; } else if( c=='g') { pd = pSettingsComm->gateway; } else if( c=='s') { pd = pSettingsComm->http_server_ip; } else if( c=='h') { pd = pSettingsComm->http_header; } if(c != 'z' && c!='l' && c!='w' && c != 'd'&& c != 'q'){ while( (*p1>0)&&(!isspace(*p1)) ) p1++; while( isspace(*p1)||(*p1=='=')||(*p1==':') ) p1++; // point to new param if(c!='h'){ fprintf(uart, "ip = %lx \r\n ", (long)inet_addr(p1) ); if((long)inet_addr(p1) != 0xffffffff){ memset( pd, 0, 16 ); while( isdigit(*p1)|| *p1=='.' ) *pd++ = *p1++; } } else { // -h header pd = pSettingsComm->http_header; memset( pd, 0, 256 ); while(*p1>0) { if( *p1 == '\\' && *(p1+1)=='r' ){ *pd++ = '\r'; p1+=2; } else if( *p1 == '\\' && *(p1+1)=='n' ){ *pd++ = '\n'; p1+=2; } else { *pd++ = *p1++; } } } } } if(*p1>0) p1++; } } else if( strncmp( p1, "log", 3)==0){ NEXT_TERM(p1); if( *p1=='?' ){ // set command "alone" - show help PrintLogHelp(); return; } fputs_P(PSTR("ViewLog Mode. Hit any key to come back to prompt...\r\n"), stream); fflush(stream); u_char c ='s'; // by default if(*p1=='-' || *p1=='\\') { c = *++p1; // cmd char } switch(c) { case 'd': bWriteLog = LOG_FIELD; break; case 'f': bWriteLog = LOG_ALL; break; case 'w': bWriteLog = LOG_NET; break; default: bWriteLog = LOG_SHORT; break; } return; } else if( strncmp( p1, "date", 4)==0){ parse_date_command( p1 ); return; } else if( strncmp( p1, "help", 4)==0){ const u_char* p2 = p1+4; while( isspace(*p2)) p2++; if( p2>=pEnd ){ // set command "alone" means view settings PrintHelp( ); } return; } else if( strncmp( p1, "pack", 4)==0){ NEXT_TERM(p1); if( p1>=pEnd || *p1=='?' ){ // set command "alone" - show help PrintPackHelp(stream); return; } int replyLen =0; // zero means do not control reply length int nPacket=-1; // number of edited/inserted/added packet while(*p1>0) { // we need to set something if(*p1=='-' || *p1=='\\') { u_char c = *++p1; // cmd char if( c =='r'){ NEXT_TERM(p1); if( isdigit(*p1)) replyLen=atoi(p1); if((replyLen>(DATA_LEN-20))||(replyLen<0)) { addToMsg( PSTR("Error. Incorrect Reply Length")); return; } } if( c =='l'){ int np=-1; //number of packets to view, -1 means "All" NEXT_TERM(p1); if( isdigit(*p1)) np=atoi(p1); ViewPackets( pSettingsPack, np, stream ); } else if( c =='v'){ nPacket = InsertDevice( p1, replyLen, 0 ); // 1 - insert ( 0 - add ) } else if( c =='d'){ DeletePacket( p1 ); // 1 - insert ( 0 - add ) return; } } if(*p1>0) p1++; } return; } else if (strncmp( p1, "exec", 4)==0){ NEXT_TERM(p1); fputs_P(PSTR("\n\r No exec commands here any more \n\r"), stream); } else if (strncmp( p1, "search", 4)==0){ NEXT_TERM(p1); while(*p1>0) { // we need to set something if(*p1=='-' || *p1=='\\') { u_char c = *++p1; // cmd char if(( c =='z')||(c == 'o')){ SearchZVLCs(stream); } else if(c == 'm'){ SearchMEPCOs(stream); } } } } else { fputs_P(PSTR(" Unknown command\r\n"),stream); } } int PacketToString( u_char* buf, const u_char p[], const int len) { int i,c, j=0; for(i=0;i>4; buf[j++] = (c>9)?(c-10+'A'):(c+'0'); c = p[i]&0x0F; buf[j++] = (c>9)?(c-10+'A'):(c+'0'); if( (i>4) && !((i+1)%8)){ buf[j++]=' '; } } buf[j++]=0; return j; } char* dayName[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; char* monthName[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; void parseDateTime( type_RTC_timedate* pDateTime, const u_char* p1 ) { register u_char n; while(*p1>'\r') { while( (*p1>'\r') && isspace(*p1) ) p1++; // skip spaces at the beginning if( isalpha(*p1)) { //Parse day of week int i; for(i=0;i<7;i++) { if(strncmp(p1, dayName[i],3)==0) { pDateTime->day_of_week=i+1; break; } } // Month for(i=0;i<12;i++) { if(strncmp(p1,monthName[i],3)==0) { pDateTime->month=HEX2BCD(i+1); break; } } } if(isdigit(*p1)) { if( isspace(*(p1+1)) || isspace(*(p1+2)) ) { // standalone 1 or 2 digit(s) consider as day of month n = atoi(p1); pDateTime->day = HEX2BCD( n ); } else if( isdigit(*(p1+1)) && isdigit(*(p1+2)) &&isdigit(*(p1+3)) ) { // standalone 4 digits consider as year n = atoi(p1+2); // utilise 2 last digits pDateTime->year = HEX2BCD( n ); } u_char* p2 = (u_char*)(p1+1); if( isdigit(*p2)) p2++; if(*p2++ == ':') { // 1 or 2 digits before ':' consider as hours n = atoi(p1); pDateTime->hr = HEX2BCD( n ); p1=p2++; if(isdigit(*p1)) { // 1 or 2 digits after':' consider as min n = atoi(p1); pDateTime->min = HEX2BCD( n ); if( isdigit(*p2)) p2++; if(*p2++ == ':') { p1=p2; // 1 or 2 digits after second ':' consider as sec if(isdigit(*p1)) { n = atoi(p1); pDateTime->sec = HEX2BCD( n ); } } } } else if(*p2++ == '.') { // 1 or 2 digits before '.' consider as hours n = atoi(p1); pDateTime->month = HEX2BCD( n ); p1=p2++; if(isdigit(*p1)) { // 1 or 2 digits after'.' consider as min n = atoi(p1); pDateTime->day = HEX2BCD( n ); if( isdigit(*p2)) p2++; if(*p2++ == '.') { p1=p2++; // 1 or 2 digits after second ':' consider as sec while( isdigit(*++p2)) p1++; // skip 2 left digits if there are 4 of them in a year if(isdigit(*p1)) { n = atoi(p1); pDateTime->year = HEX2BCD( n ); } } } } } while( (*p1>'\n')&&(!isspace(*p1)) ) p1++; } // PrintRtcTime( pDateTime, uart, 0 ); } void PrintRtcTime( type_RTC_timedate* pDateTime, FILE *outstream, u_char* outBuf) { u_char buf[]="\rwww, dd MMM 20yy hh:mm:ss "; char* p = (dayName[ pDateTime->day_of_week-1 ]); buf[1] = *p++; buf[2] = *p++; buf[3] = *p; buf[6] = ((pDateTime->day>>4)&0x0F)+'0'; buf[7] = ((pDateTime->day)&0x0F)+'0'; int m = BCD2HEX( pDateTime->month ) -1; p = (monthName[ m ]); buf[9] = *p++; buf[10] = *p++; buf[11] = *p; buf[15] = ((pDateTime->year>>4)&0x0F)+'0'; buf[16] = ((pDateTime->year)&0x0F)+'0'; buf[18] = ((pDateTime->hr>>4)&0x0F)+'0'; buf[19] = ((pDateTime->hr)&0x0F)+'0'; buf[21] = ((pDateTime->min>>4)&0x0F)+'0'; buf[22] = ((pDateTime->min)&0x0F)+'0'; buf[24] = ((pDateTime->sec>>4)&0x0F)+'0'; buf[25] = ((pDateTime->sec)&0x0F)+'0'; // if( uart!=0) NutPrintString(uart, buf ); if( outstream!=0) fputs(buf, outstream ); if(outBuf!=0) strcat( outBuf, buf); } void parse_date_command( const u_char* p1 ) { while( (*p1>0)&&(!isspace(*p1)) ) p1++; while( (*p1>0)&&isspace(*p1) ) p1++; if( *p1=='?' ) { // set command "alone" - show help PrintDateHelp(); return; } else if( *p1==0 ) { // no arguments - just print current date and time PrintRtcTime( (type_RTC_timedate*)&rtc_datetime, 0, pMsgBuf ); return; } while(*p1>0) { // we need to set something if(*p1=='-' || *p1=='\\') { u_char c = *++p1; // cmd char if(c == 'z') // synchronize box time to server time { bSynchronizeTime = 1; // NutPrintString_P( uart, PSTR("Date and time will be synchronized to the http server") ); fputs_P(PSTR("Date and time will be synchronized to the http server"), uart); } if(c == 's') { while( (*p1>0)&&(!isspace(*p1)) ) p1++; parseDateTime( (type_RTC_timedate*)&rtc_datetime, p1 ); // write new datetime to Rtc. WriteRtcTimer(); NutDelay(1); ReadRtcTimer( ); addToMsg( PSTR("New date and time is:") ); PrintRtcTime( (type_RTC_timedate*)&rtc_datetime, 0, pMsgBuf ); } } if(*p1>0) p1++; } } u_char timeFmtIsValid( const u_char* p, int min, int max ) { u_char n1 = *p++; if(n1==0) return 0xFF; u_char n2 = *p++; if(n2==0) return 0xFF; n1 -= '0'; n2 -= '0'; int a = n1*10+n2; if( amax ) return 0xFF; u_char t = ((n1<<4)+n2); return t; } void SetMacAddr(const u_char* p1) { NEXT_TERM(p1); u_char new_mac[6]; memset( new_mac, 0, 6); int j; u_char err = 0; for(j=0; j<6;j++){ u_int c=0; u_int v=0; u_int nc=0; while( (isspace(*p1))||(*p1==':') ) p1++; // shift to the next first XX if(*p1>0 ) { for(nc=0;nc<2;nc++){ c = toupper(*p1++); if(!isxdigit(c)){ if(nc==0) { addToMsg( PSTR("Error: Wrong character '")); strncat( pMsgBuf, (u_char*)&c, 1 ); addToMsg( PSTR("' in the input string only '0-9,A-F'allowed\r\n" )); err=1; } else break; // we have one character already, so just break "for(nc=..." } v = (v<<4)|((c>='A')?(c-'A'+10):(c-'0')); if(*p1==0) break; //break cycle if EOL } } else break; new_mac[j] = v; } if(err==0){ int k=6; while ( (k>0) && (j>0) ) pSettingsComm->mac[--k]=new_mac[--j]; // NutPrintString_P( uart, PSTR("New mac: ") ); fputs_P(PSTR("New mac: "),uart); PrintPacket( uart, pSettingsComm->mac, 6); // NutPrintString_P( uart, PSTR(" is setted\r\nsave and reboot to make changes take effect.") ); fputs_P(PSTR(" is set\r\nsave and reboot to make changes take effect."),uart); } } char ParseDestAddr( const u_char* p1, u_char dest_addr[DEST_ADDR_SIZE] ) { memset( &dest_addr[0], 0, DEST_ADDR_SIZE); int j; u_char err = 0; for(j=0; j0 ) { for(nc=0;nc<2;nc++){ c = toupper(*p1++); if(!isxdigit(c)){ if(nc==0) { addToMsg( PSTR("Error: Wrong character '")); strncat( pMsgBuf, (u_char*)&c, 1 ); addToMsg( PSTR("' in the input string only '0-9,A-F'allowed\r\n" )); err=1; } else break; // we have one character already, so just break "for(nc=..." } v = (v<<4)|((c>='A')?(c-'A'+10):(c-'0')); if(*p1==0) break; //break cycle if EOL } } else break; dest_addr[j] = v; } if(err==0) return 1; else return 0; } void ListOfThreads(FILE *outstream) { NUTTHREADINFO *tdp; NUTTIMERINFO *tnp; fputs_P(PSTR("Name\t\t State\t Priority\tMemory\t Life\t Ticks Left\r\n"), outstream); for (tdp = nutThreadList; tdp; tdp = tdp->td_next) { fprintf(outstream, "%s", tdp->td_name); fflush(outstream); switch (tdp->td_state) { case TDS_TERM: fputs("\t\tTerm", outstream); fflush(outstream); break; case TDS_RUNNING: fputs("\t\tRun", outstream); fflush(outstream); break; case TDS_READY: fputs("\t\tReady", outstream); fflush(outstream); break; case TDS_SLEEP: fputs("\t\tSleep", outstream); fflush(outstream); break; } fprintf(outstream, "\t%u\t\t%u", tdp->td_priority, (u_short) tdp->td_sp - (u_short) tdp->td_memory); if (*((u_long *) tdp->td_memory) != DEADBEEF) { fputs("\tCorrup\t", outstream); fflush(outstream); } else{ fputs("\tOK\t", outstream); fflush(outstream); } if ((tnp = (NUTTIMERINFO *) tdp->td_timer) != 0) { fprintf(outstream, "\t%lu\r\n", tnp->tn_ticks_left); } else{ fputs("\tNone\r\n",outstream ); } fputs(".\r\n", outstream); fflush(outstream); continue; } }