Esempio n. 1
0
void shavs_setalgo(char *param){
	param = strstrip(param);
	if(param[1]=='\0'){ /* single letter specified */
		uint8_t i, option = param[0] - 'a';

		if(!shavs_algolist){
			fputs_P(PSTR("\nERROR: shavs_algolist not set!"), shavs_out_file);
			return;
		}
		for(i=0; i<=option; ++i){
			if((void*)pgm_read_word(&(shavs_algolist[i]))==NULL){
				fputs_P(PSTR("\r\nERROR: invalid selection!"), shavs_out_file);
				return;
			}
		}
		shavs_algo=(hfdesc_t*)pgm_read_word(&(shavs_algolist[option]));
	} else { /* name specifyed */
		hfdesc_t *t=NULL;
		uint8_t i=0;
		while((t=(hfdesc_t*)pgm_read_word(&(shavs_algolist[i]))) &&
		       strcasecmp_P(param, (void*)pgm_read_word(&(t->name))))
			++i;
		if(t){
			shavs_algo=t;
		}else{
		    fprintf_P(shavs_out_file, PSTR("\nERROR: could not find \"%s\"!"), param);
			cli_putstr_P(PSTR("\r\nERROR: could not find \""));
			cli_putstr(param);
			cli_putstr_P(PSTR("\"!"));
		}
	}
}
Esempio n. 2
0
// Find a variable by name.
//
AP_Param *
AP_Param::find(const char *name, enum ap_var_type *ptype)
{
    for (uint8_t i=0; i<_num_vars; i++) {
        uint8_t type = PGM_UINT8(&_var_info[i].type);
        if (type == AP_PARAM_GROUP) {
            uint8_t len = strnlen_P(_var_info[i].name, AP_MAX_NAME_SIZE);
            if (strncmp_P(name, _var_info[i].name, len) != 0) {
                continue;
            }
            const struct GroupInfo *group_info = (const struct GroupInfo *)PGM_POINTER(&_var_info[i].group_info);
            AP_Param *ap = find_group(name + len, i, group_info, ptype);
            if (ap != NULL) {
                return ap;
            }
            // we continue looking as we want to allow top level
            // parameter to have the same prefix name as group
            // parameters, for example CAM_P_G
        } else if (strcasecmp_P(name, _var_info[i].name) == 0) {
            *ptype = (enum ap_var_type)type;
            return (AP_Param *)PGM_POINTER(&_var_info[i].ptr);
        }
    }
    return NULL;
}
Esempio n. 3
0
int8_t Copter::select_logs(uint8_t argc, const Menu::arg *argv)
{
    uint16_t bits;

    if (argc != 2) {
        cliSerial->printf_P(PSTR("missing log type\n"));
        return(-1);
    }

    bits = 0;

    // Macro to make the following code a bit easier on the eye.
    // Pass it the capitalised name of the log option, as defined
    // in defines.h but without the LOG_ prefix.  It will check for
    // that name as the argument to the command, and set the bit in
    // bits accordingly.
    //
    if (!strcasecmp_P(argv[1].str, PSTR("all"))) {
        bits = ~0;
    } else {
 #define TARG(_s)        if (!strcasecmp_P(argv[1].str, PSTR(# _s))) bits |= MASK_LOG_ ## _s
        TARG(ATTITUDE_FAST);
        TARG(ATTITUDE_MED);
        TARG(GPS);
        TARG(PM);
        TARG(CTUN);
        TARG(NTUN);
        TARG(RCIN);
        TARG(IMU);
        TARG(CMD);
        TARG(CURRENT);
        TARG(RCOUT);
        TARG(OPTFLOW);
        TARG(COMPASS);
        TARG(CAMERA);
        TARG(PID);
 #undef TARG
    }

    if (!strcasecmp_P(argv[0].str, PSTR("enable"))) {
        g.log_bitmask.set_and_save(g.log_bitmask | bits);
    }else{
        g.log_bitmask.set_and_save(g.log_bitmask & ~bits);
    }

    return(0);
}
Esempio n. 4
0
static bool parse_command (const char *args)
{
    if (args == NULL || *args == 0 || strcasecmp_P(args, PSTR("GET")) == 0) {
        luminosity_get_light();
        return true;
    }
    return false;
}
Esempio n. 5
0
// Find a object by name.
//
AP_Param *
AP_Param::find_object(const char *name)
{
    for (uint8_t i=0; i<_num_vars; i++) {
        if (strcasecmp_P(name, _var_info[i].name) == 0) {
            return (AP_Param *)PGM_POINTER(&_var_info[i].ptr);
        }
    }
    return NULL;
}
Esempio n. 6
0
static PFUN_CMD_HANDLER console_lookup_command(const char* command) {
    for(int i = 0; i < CONSOLE_MAX_COMMAND; i++) {
        if(cmdEntries[i].cmdName == NULL) {
            break;
        }
        if(strcasecmp_P(command,cmdEntries[i].cmdName) == 0) {
            return cmdEntries[i].cmdHandler;
        }
    }
    return NULL;
}
Esempio n. 7
0
SNES_FTYPE determine_filetype(char* filename) {
	char* ext = strrchr(filename, '.');
	if(ext == NULL)
		return TYPE_UNKNOWN;
	if(!strcasecmp_P(ext+1, PSTR("SMC"))) {
		return TYPE_SMC;
	}/* later
	if(!strcasecmp_P(ext+1, PSTR("SRM"))) {
		return TYPE_SRM;
	}
	if(!strcasecmp_P(ext+1, PSTR("SPC"))) {
		return TYPE_SPC;
	}*/
	return TYPE_UNKNOWN;
}
Esempio n. 8
0
// Find a variable by name in a group
AP_Param *
AP_Param::find_group(const char *name, uint8_t vindex, const struct GroupInfo *group_info, enum ap_var_type *ptype)
{
    uint8_t type;
    for (uint8_t i=0;
         (type=PGM_UINT8(&group_info[i].type)) != AP_PARAM_NONE;
         i++) {
#ifdef AP_NESTED_GROUPS_ENABLED
        if (type == AP_PARAM_GROUP) {
            const struct GroupInfo *ginfo = (const struct GroupInfo *)PGM_POINTER(&group_info[i].group_info);
            AP_Param *ap = find_group(name, vindex, ginfo, ptype);
            if (ap != NULL) {
                return ap;
            }
        } else
#endif // AP_NESTED_GROUPS_ENABLED
        if (strcasecmp_P(name, group_info[i].name) == 0) {
            uintptr_t p = PGM_POINTER(&_var_info[vindex].ptr);
            *ptype = (enum ap_var_type)type;
            return (AP_Param *)(p + PGM_POINTER(&group_info[i].offset));
        } else if (type == AP_PARAM_VECTOR3F) {
            // special case for finding Vector3f elements
            uint8_t suffix_len = strnlen_P(group_info[i].name, AP_MAX_NAME_SIZE);
            if (strncmp_P(name, group_info[i].name, suffix_len) == 0 &&
                name[suffix_len] == '_' &&
                (name[suffix_len+1] == 'X' ||
                 name[suffix_len+1] == 'Y' ||
                 name[suffix_len+1] == 'Z')) {
                uintptr_t p = PGM_POINTER(&_var_info[vindex].ptr);
                AP_Float *v = (AP_Float *)(p + PGM_POINTER(&group_info[i].offset));
                *ptype = AP_PARAM_FLOAT;
                switch (name[suffix_len+1]) {
                case 'X':
                    return (AP_Float *)&v[0];
                case 'Y':
                    return (AP_Float *)&v[1];
                case 'Z':
                    return (AP_Float *)&v[2];
                }
            }
        }
    }
    return NULL;
}
Esempio n. 9
0
/**
 * \ingroup tcpsrv
 * Tastatureingabe bei USART auswerten
 *
 * Die Funktion zerlegt den übergebenen Tastaturpuffer
 * in Befehl und Parameterliste. Dann wird die Befehlstabelle
 * <tt>CMD_TABLE[]</tt> nach dem Befehl durchsucht und die
 * passende Funktion aufgerufen.
 *
 * \param[in] pstr char-Pointer auf Eingabe-Puffer
 * \returns 0 bei Fehler, 1 bei ausgefuehrtem Befehl
 */
unsigned char extract_cmd(char *pstr)
{
	char *string_pointer_tmp;
	unsigned char cmd_index = 0;
 
 	// erst mal Tastaturpuffer in Kommando und Parameter aufteilen
    string_pointer_tmp = strsep(&pstr," "); 
	argv = pstr;	// Zeiger auf Cmd-Parameter setzen

	// Kommando in Tabelle CMD_TABLE suchen
	while(strcasecmp_P(string_pointer_tmp,(char *)pgm_read_word(&CMD_TABLE[cmd_index].cmd)))
    {
        // wenn letzter Eintrag ({NULL,NULL}) erreicht wurde,
		// Abruch der Whileschleife und Unterprogramm verlassen 
        if (pgm_read_word(&CMD_TABLE[++cmd_index].cmd) == 0) return(0);
    }
    
	// der Befehl wurde in der Tabelle gefunden;
	// jetzt Befehl ausführen und Ergebnis zurückgeben
	usart_write("\r\n");
	((cmd_fp)pgm_read_word(&CMD_TABLE[cmd_index].fp))(0);
	return(1); 
}
Esempio n. 10
0
uint8_t text_decode (uint8_t *buffer, uint8_t *cmd_argument)
{

 uint8_t  found,ch,ch2,cmd_no,j,k,index,cmd_complete;
 uint8_t  state = WAIT_CMD_STATE, quote  = 0;
 static uint16_t i=0; // Keep pointer for next command decode
 cmd_complete = 0;
 cmd_no 	= 0;
 index 		= 0;
 
 cmd_argument  = buffer;
 
 while (*(buffer+i))	  		//End with NULL
 {
// Check with delimiter

 	 j = 0;
	 found = 0;
	
	switch (state)
	{
	  case WAIT_CMD_STATE:   // If found first character in command table  then go to get_cmd state
 		j = 0;
		while ((ch = pgm_read_byte(&text_cmd[j][0])))     //Check first charaters in cmd table
		{ 
		  if (*(buffer+i) == ch)
		  {
			state = GET_CMD_STATE;   // Found delimiter
			*(cmd_argument) = ch;
			index = 1;
			break; 
		  }
		 j++;
		}  
	    break;
	  case GET_CMD_STATE:
	    ch = *(buffer+i);
        j = 0; 
		found = 0;
	  	while ((ch2 = pgm_read_byte(&delimiter[j])))   //Check delimiter End with NULL
		{  
		   if ( ch == ch2)
		   {
              found = 1;
              break;
		   } 	 
           j++;	
		}
		if (found)
		{
        	*(cmd_argument+index) = 0x00;
		     if (ch == '=')
			 {
// Check command number 
  				for (k = 0; k < CMD_NUM ; k++)
				{
					if (!(strcasecmp_P(cmd_argument,&text_cmd[k][0])))  // Found then keep command
					{
						cmd_no  = k+1;   // Start from 0 
						break;
					}
				}
// clear index
  				index = 0;
			    state = WAIT_ARG_STATE;	
			 }	
		}
		else
		{
			*(cmd_argument+index) = ch;
			index++;		
		}
		break;
		
	  case WAIT_ARG_STATE:
		ch = *(buffer+i);
        j = 0; 
		found = 0;
	  	while ((ch2 = pgm_read_byte(&delimiter[j])))   //Check delimiter End with NULL
		{  
		   if ( ch == ch2)
		   {
              found = 1;
              break;
		   } 	 
           j++;	
		}
				
		if ( ch == '"')   // Start quote
		{
			quote ^= 1;   // Toggle quote	
			state = GET_ARG_STATE;   
 			index = 0;
		}
		
		if (!found)    // Not delimiter start get Argument
		{
			state = GET_ARG_STATE;   
			*(cmd_argument) = ch;
			index = 1;
		}
		break;	
	  case	GET_ARG_STATE:
	  	ch = *(buffer+i);
        j = 0; 
		found = 0;
	  	while ((ch2 = pgm_read_byte(&delimiter[j])))   //Check delimiter End with NULL
		{  
		   if ( ch == ch2)
		   {
              found = 1;
              break;
		   } 	 
           j++;	
		}
 		if ( ch == '"')     // End quote
		{
			quote ^= 1;   // Toggle quote	
   		}
		if ( quote)
		{
         	found = 0; //  ignore all characters after the quote until found quote again
// Cancel quote
            
		}	
		if (found)
		{	
            cmd_complete = 1;
			*(cmd_argument+index) = 0;
		    state = WAIT_CMD_STATE;
		}
		else
		{
			*(cmd_argument+index) = ch;
			index++;		
		}  
		break;
	}
	
	if(cmd_complete)   // COmmand both cmd number and argument
	{
		return cmd_no;	 	 
	}
	i++;
 }
  i = 0;
  return 0xFF;  // End of Buffer

}
Esempio n. 11
0
void parse_request(void)
{
        uint8_t temp;
        char *bufptr;

        ((char *)uip_appdata)[uip_len] = '\0';

        bufptr = strtok(uip_appdata, " \r\n");

        if(device_list == NULL)
                return;

        if(strcasecmp_P(bufptr, PSTR("GET")) == 0) {
                bufptr = strtok(NULL, " \r\n");

                if(strcasecmp_P(bufptr, PSTR("VALUE")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';

                                sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), device_list[temp].value);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("UPTIME")) == 0) {
                        sprintf_P(uip_appdata, PSTR("OK\r\n%lu\r\n"), get_clock());

                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("NAME")) == 0) {
                        char buffer[32];
                        strcpy_P(buffer, hostname);
                        sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), buffer);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("PLACE")) == 0) {
                        char buffer[32];
                        strcpy_P(buffer, place);
                        sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), buffer);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("DEVICECOUNT")) == 0) {
                        sprintf_P(uip_appdata, PSTR("OK\r\n%d\r\n"), device_count);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                } else if(strcasecmp_P(bufptr, PSTR("TYPE")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%d\r\n"), device_list[temp].type);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("DTYPE")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%c\r\n"), device_list[temp].dtype);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("MIN")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), device_list[temp].min);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("MAX")) == 0) {
                        bufptr = strtok(NULL, " \r\n");

                        if(bufptr[0] >= '0' && bufptr[0] <= '8' && (bufptr[0] - '0') < device_count) {
                                temp = bufptr[0] - '0';
                                sprintf_P(uip_appdata, PSTR("OK\r\n%s\r\n"), device_list[temp].max);
                                uip_send(uip_appdata, strlen(uip_appdata));
                                return;
                        }

                } else if(strcasecmp_P(bufptr, PSTR("MAC")) == 0) {
                        sprintf_P(uip_appdata, PSTR("OK\r\n%02X:%02X:%02X:%02X:%02X:%02X\r\n"), uip_ethaddr.addr[5], uip_ethaddr.addr[4],
                                                                                                uip_ethaddr.addr[3], uip_ethaddr.addr[2],
                                                                                                uip_ethaddr.addr[1], uip_ethaddr.addr[0]);
                        uip_send(uip_appdata, strlen(uip_appdata));
                        return;
                }

        } else if(strcasecmp_P(bufptr, PSTR("SET")) == 0) {

        }

        strcpy_P(uip_appdata, PSTR("ERROR\r\n"));
        uip_send(uip_appdata, 7);
}
Esempio n. 12
0
/*
 void DellPass()
 {
 for (int i = 18 * 19; i < 18 * 20; i++)
 EEPROM.update(i, 0);
 }
 */
void Comand(char *nrtel, char *inmsg)
{
	char buffer[24];
	char OK[3] = "OK";
	//bool cmdok = false;
	ReadEprom(buffer, 18);
	if (strcmp(nrtel, buffer) == 0)
	{

		ReadEprom(buffer, 18 * 6);
		//Serial.println(strcasecmp(buffer, inmsg));
		//if (strstr(inmsg,buffer) != 0)
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD1, LOW);
			PORTD &= ~(1 << PD2);
			eeprom_update_byte((uint8_t*) 379, 0);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 7);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD1, HIGH);
			PORTD |= (1 << PD2);
			eeprom_update_byte((uint8_t*) 379, 1);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 8);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD2, LOW);
			PORTD &= ~(1 << PD3);
			eeprom_update_byte((uint8_t*) 380, 0);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 9);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD2, HIGH);
			PORTD |= (1 << PD3);
			eeprom_update_byte((uint8_t*) 380, 1);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 10);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD3, LOW);
			PORTD &= ~(1 << PD4);
			eeprom_update_byte((uint8_t*) 381, 0);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 11);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD3, HIGH);
			PORTD |= (1 << PD4);
			eeprom_update_byte((uint8_t*) 381, 1);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 12);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD4, LOW);
			PORTD &= ~(1 << PD5);
			eeprom_update_byte((uint8_t*) 382, 0);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 13);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD4, HIGH);
			PORTD |= (1 << PD5);
			eeprom_update_byte((uint8_t*) 382, 1);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 14);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD5, LOW);
			PORTD &= ~(1 << PD6);
			eeprom_update_byte((uint8_t*) 383, 0);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 15);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD5, HIGH);
			PORTD |= (1 << PD6);
			eeprom_update_byte((uint8_t*) 383, 1);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 16);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD5, LOW);
			PORTD &= ~(1 << PD7);
			eeprom_update_byte((uint8_t*) 384, 0);
			SendSms(nrtel, OK);
			return;
		}

		ReadEprom(buffer, 18 * 17);
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD5, HIGH);
			PORTD |= (1 << PD7);
			eeprom_update_byte((uint8_t*) 384, 1);
			SendSms(nrtel, OK);
			return;
		}

		//strcpy_P(buffer, (char*) pgm_read_word(&(comenzi[18])));
		//if (strcasecmp(buffer, inmsg) == 0)
		if (strcasecmp_P(inmsg, STARE_OUT) == 0)
		{
			StareOUT(nrtel);
			return;
		}
		//strcpy_P(buffer, (char*) pgm_read_word(&(comenzi[19])));
		//if (strcasecmp(buffer, inmsg) == 0)
		if (strcasecmp_P(inmsg, STARE_TMP) == 0)
		{
			StareTMP(nrtel);
			return;
		}

		//strcpy_P(buffer, (char*) pgm_read_word(&(comenzi[20])));
		//if (strcasecmp(buffer, inmsg) == 0)
		if (strcasecmp_P(inmsg, STARE_ALL) == 0)
		{
			StareOUT(nrtel);
			StareTMP(nrtel);
			return;
		}

		ReadEprom(buffer, 486);
		SendSms(nrtel, buffer);
		return;
	}
	else
	{
		ReadEprom(buffer, 18 * 21);
		if (strcmp(buffer, inmsg) == 0)
		{
			eeprom_write_block(nrtel, (int*) 18, 18);
			strcpy_P(buffer, LOGIN);
			SendSms(nrtel, buffer);
		}
	}
}
inline int        strcasecmp_P(const char *str1, const prog_char_t *pstr)
{
    return strcasecmp_P(str1, (const prog_char *)pstr);
}
Esempio n. 14
0
// run the menu
void
Menu::run(void)
{
    int8_t ret;
    uint8_t len, i;
    uint8_t argc;
    int c;
    char                *s;

	if (_port == NULL) {
		// default to main serial port
		_port = &Serial;
	}

    // loop performing commands
    for (;; ) {

        // run the pre-prompt function, if one is defined
        if ((NULL != _ppfunc) && !_ppfunc())
            return;

        // loop reading characters from the input
        len = 0;
        _port->printf_P(PSTR("%S] "), FPSTR(_prompt));
        for (;; ) {
            c = _port->read();
            if (-1 == c)
                continue;
            // carriage return -> process command
            if ('\r' == c) {
                _inbuf[len] = '\0';
                _port->write('\r');
                _port->write('\n');
                break;
            }
            // backspace
            if ('\b' == c) {
                if (len > 0) {
                    len--;
                    _port->write('\b');
                    _port->write(' ');
                    _port->write('\b');
                    continue;
                }
            }
            // printable character
            if (isprint(c) && (len < (MENU_COMMANDLINE_MAX - 1))) {
                _inbuf[len++] = c;
                _port->write((char)c);
                continue;
            }
        }

        // split the input line into tokens
        argc = 0;
        _argv[argc++].str = strtok_r(_inbuf, " ", &s);
        // XXX should an empty line by itself back out of the current menu?
        while (argc <= MENU_ARGS_MAX) {
            _argv[argc].str = strtok_r(NULL, " ", &s);
            if ('\0' == _argv[argc].str)
                break;
            _argv[argc].i = atol(_argv[argc].str);
            _argv[argc].f = atof(_argv[argc].str);      // calls strtod, > 700B !
            argc++;
        }

        if (_argv[0].str == NULL) {
            continue;
        }

        // populate arguments that have not been specified with "" and 0
        // this is safer than NULL in the case where commands may look
        // without testing argc
        i = argc;
        while (i <= MENU_ARGS_MAX) {
            _argv[i].str = "";
            _argv[i].i = 0;
            _argv[i].f = 0;
            i++;
        }

        bool cmd_found = false;
        // look for a command matching the first word (note that it may be empty)
        for (i = 0; i < _entries; i++) {
            if (!strcasecmp_P(_argv[0].str, _commands[i].command)) {
                ret = _call(i, argc);
                cmd_found=true;
                if (-2 == ret)
                    return;
                break;
            }
        }

        // implicit commands
        if (i == _entries) {
            if (!strcmp(_argv[0].str, "?") || (!strcasecmp_P(_argv[0].str, PSTR("help")))) {
                _help();
                cmd_found=true;
            } else if (!strcasecmp_P(_argv[0].str, PSTR("exit"))) {
                return;
            }
        }

        if (cmd_found==false)
        {
            _port->println_P(PSTR("Invalid command, type 'help'"));
        }

    }
}
Esempio n. 15
0
// run the menu
void
Menu::run(void)
{
	uint8_t		len, i, ret;
	uint8_t		argc;
	int			c;
	char		*s;
		
	// loop performing commands
	for (;;) {

		// run the pre-prompt function, if one is defined
		if ((NULL != _ppfunc) && !_ppfunc())
			return;

		// loop reading characters from the input
		len = 0;
		Serial.printf("%S] ", _prompt);
		for (;;) {
			c = Serial.read();
			if (-1 == c)
				continue;
			// carriage return -> process command
			if ('\r' == c) {
				_inbuf[len] = '\0';
				Serial.write('\r');
				Serial.write('\n');
				break;
			}
			// backspace
			if ('\b' == c) {
				if (len > 0) {
					len--;
					Serial.write('\b');
					Serial.write(' ');
					Serial.write('\b');
					continue;
				}
			}
			// printable character
			if (isprint(c) && (len < (MENU_COMMANDLINE_MAX - 1))) {
				_inbuf[len++] = c;
				Serial.write((char)c);
				continue;
			}
		}
		
		// split the input line into tokens
		argc = 0;
		_argv[argc++].str = strtok_r(_inbuf, " ", &s);
		// XXX should an empty line by itself back out of the current menu?
		while (argc <= MENU_ARGS_MAX) {
			_argv[argc].str = strtok_r(NULL, " ", &s);
			if ('\0' == _argv[argc].str)
				break;
			_argv[argc].i = atol(_argv[argc].str);
			_argv[argc].f = atof(_argv[argc].str);	// calls strtod, > 700B !
			argc++;
		}
			
		// look for a command matching the first word (note that it may be empty)
		for (i = 0; i < _entries; i++) {
			if (!strcasecmp_P(_argv[0].str, _commands[i].command)) {
				ret = _call(i, argc);
				if (-2 == ret)
					return;
				break;
			}
		}

		// implicit commands
		if (i == _entries) {
			if (!strcmp(_argv[0].str, "?") || (!strcasecmp_P(_argv[0].str, PSTR("help")))) {
				_help();
			} else if (!strcasecmp_P(_argv[0].str, PSTR("exit"))) {
				return;
			}
		}
	}			
}
Esempio n. 16
0
/**
 * @breaf execut sms commands
 *
 * @param nrtel: pfon number
 * 		  inmsg: sms command
 */
void Comand(char *nrtel, char *inmsg)
{
	char buffer[18];
	memset(buffer, 0, sizeof(buffer));
	char OK[3] = "OK";
	char smsc_num[18];
	memset(smsc_num, 0, sizeof(smsc_num));
	//bool cmdok = false;
	ReadEprom(buffer, 18);
	ReadEprom(smsc_num, 360);

	if (strcmp(nrtel, buffer) == 0)
	{

		ReadEprom(buffer, 108);	//18 * 6
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD1, LOW);
			PORTD &= ~(1 << PD2);
			eeprom_update_byte((uint8_t*) 379, 0);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 126);	//18 * 7
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD1, HIGH);
			PORTD |= (1 << PD2);
			eeprom_update_byte((uint8_t*) 379, 1);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 144);	//18 * 8
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD2, LOW);
			PORTD &= ~(1 << PD3);
			eeprom_update_byte((uint8_t*) 380, 0);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 162);	//18 * 9
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD2, HIGH);
			PORTD |= (1 << PD3);
			eeprom_update_byte((uint8_t*) 380, 1);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 180);	//18 * 10
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD3, LOW);
			PORTD &= ~(1 << PD4);
			eeprom_update_byte((uint8_t*) 381, 0);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 198);	//18 * 11
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD3, HIGH);
			PORTD |= (1 << PD4);
			eeprom_update_byte((uint8_t*) 381, 1);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 216);	//18 * 12
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD4, LOW);
			PORTD &= ~(1 << PD5);
			eeprom_update_byte((uint8_t*) 382, 0);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 234);	//18 * 13
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD4, HIGH);
			PORTD |= (1 << PD5);
			eeprom_update_byte((uint8_t*) 382, 1);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 252);	//18 * 14
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD5, LOW);
			PORTD &= ~(1 << PD6);
			eeprom_update_byte((uint8_t*) 383, 0);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		ReadEprom(buffer, 270);	//18 * 15
		if (strcasecmp(buffer, inmsg) == 0)
		{
			//digitalWrite(outD5, HIGH);
			PORTD |= (1 << PD6);
			eeprom_update_byte((uint8_t*) 383, 1);
			uart_sendsms(smsc_num, nrtel, OK);
			return;
		}

		//strcpy_P(buffer, (char*) pgm_read_word(&(comenzi[18])));
		//if (strcasecmp(buffer, inmsg) == 0)
		if (strcasecmp_P(inmsg, STARE_OUT) == 0)
		{
			StareOUT(smsc_num, nrtel);
			return;
		}
		//strcpy_P(buffer, (char*) pgm_read_word(&(comenzi[19])));
		//if (strcasecmp(buffer, inmsg) == 0)
		if (strcasecmp_P(inmsg, STARE_TMP) == 0)
		{
			StareTMP(smsc_num, nrtel);
			return;
		}

		//strcpy_P(buffer, (char*) pgm_read_word(&(comenzi[20])));
		//if (strcasecmp(buffer, inmsg) == 0)
		if (strcasecmp_P(inmsg, STARE_ALL) == 0)
		{
			StareTMP(smsc_num, nrtel);
			StareOUT(smsc_num, nrtel);
			return;
		}

		ReadEprom(buffer, 486);
		uart_sendsms(smsc_num, nrtel, buffer);
		return;
	}
	else
	{
		ReadEprom(buffer, 342);	//18 * 19
		if (strcmp(buffer, inmsg) == 0)
		{
			eeprom_write_block(nrtel, (int*) 18, 18);
			strcpy_P(buffer, LOGIN);
			uart_sendsms(smsc_num, nrtel, buffer);
		}
	}
}
Esempio n. 17
0
void console_parse_command(char* command, size_t commandLen) {
    char *key = NULL, *value = NULL;
    uint8_t valueLen = 0;
    Serial *pSer = &g_serial;

    // A simple hack to command "!5"
#if CFG_BEACON_TEST
    if(commandLen > 0 && command[0] == '!') {
        cmd_test_send(pSer, command+1,commandLen - 1);
        return;
    }
#endif

    if(commandLen >0 && command[0] == '?') {
        cmd_info(pSer,0,0);
#if CONSOLE_HELP_COMMAND_ENABLED
        cmd_help(pSer,0,0);
#endif
        return;
    }

    //TinyAPRS AT Command Handler
    if(commandLen >=6 && (command[0] == 'A' || command[0] == 'a') && (command[1] == 'T' || command[1] == 't') && (command[2] == '+') ) {
        // looking for the '='
        char* t = NULL;
        uint8_t i = 3;
        for(; i < commandLen; i++) {
            if(command[i] == '=') {
                t = command + i;
                break;
            }
        }
        if(t != NULL) {
            *t = 0; // split the key=value string into 2 strings.
            key = command + 3;
            value = t + 1;
            valueLen = strlen(value);
        }
    }

    // Compatible with OT2/Other TNCs KISS init command
    else if( (commandLen >=10) && (strcasecmp_P(command,PSTR("AMODE KISS")) == 0)) {
        // enter the kiss mode
        // reuse the existing command buffer
        key = command + 6;
        key[4] = 0;
        value = command;
        value[0] = '1';
        value[1] = 0;
        valueLen = 1;
    }
    else if( (commandLen >=7) && (strcasecmp_P(command,PSTR("KISS ON")) == 0)) {
        key = command;
        key[4] = 0;
        value = command + 5;
        value[0] = '1';
        value[1] = 0;
        valueLen = 1;
    }

    if(key == NULL && value == NULL) {
        // bail out
        SERIAL_PRINTF_P(pSer,PSTR("INVALID CMD: %.*s\r\n"),commandLen,command);
        return;
    }

    // look the command registry
    // convert to upper case
    strupr(key);
    PFUN_CMD_HANDLER fun = console_lookup_command(key);
    if(fun) {
        if(!fun(pSer, value, valueLen)) {
            // handle failure, should be invalid values
            SERIAL_PRINT_P(pSer,PSTR("INVALID CMD VALUE\r\n")); // user input command is parsed but the value is not valid
        }
    } else {
        SERIAL_PRINTF_P(pSer,PSTR("UNKNOWN CMD: %.*s\r\n"),commandLen,command);
    }

    return;
}