Beispiel #1
0
int16_t parse_cmd_dmx_set_channels(char *cmd, char *output, uint16_t len)
{
	uint16_t startchannel=0, universe=0, value=0, channelcounter=0,i=0,blankcounter=0;
	if (cmd[0]!=0) {
		sscanf_P(cmd, PSTR("%u %u"), &universe,&startchannel);
		if (startchannel >= DMX_STORAGE_CHANNELS)
			return ECMD_ERR_PARSE_ERROR;
		if (universe >= DMX_STORAGE_UNIVERSES)
			return ECMD_ERR_PARSE_ERROR;
		while(blankcounter<3)
		{	
			if(cmd[i] == ' ')
				blankcounter++;
			i++;
		}
		while (cmd[i]!='\0'){           //read and write all values
			sscanf_P(cmd+i, PSTR(" %u"),&value);
			if(set_dmx_channel(universe,startchannel+channelcounter,value))
				return ECMD_ERR_WRITE_ERROR;
			channelcounter++;
			do{                         //search for next space
				i++;
				if(cmd[i]=='\0') break;
			}while(cmd[i]!=' ');
		}

		return ECMD_FINAL_OK;
	}
	else
		return ECMD_ERR_PARSE_ERROR;
}
Beispiel #2
0
int16_t parse_cmd_pin_set(char *cmd, char *output, uint16_t len)
{
  uint16_t port, pin, on;

  /* Parse String */
  uint8_t ret = sscanf_P(cmd, PSTR("%u %u %u"), &port, &pin, &on);
  /* Fallback to named pins */
  if ( ret != 3 && *cmd) {
    char *ptr = strchr(cmd + 1, ' ');
    if (ptr) {
      *ptr = 0;
      uint8_t pincfg = named_pin_by_name(cmd + 1);
      if (pincfg != 255) {
        port = pgm_read_byte(&portio_pincfg[pincfg].port);
        pin = pgm_read_byte(&portio_pincfg[pincfg].pin);
        if (ptr[1]) {
          ptr++;
          if(sscanf_P(ptr, PSTR("%u"), &on) == 1)
            ret = 3;
          else {
            if (strcmp_P(ptr, PSTR("on")) == 0) {
              on = 1;
              ret = 3;
            }
            else if (strcmp_P(ptr, PSTR("off")) == 0) {
              on = 0;
              ret = 3;
            }
          }
        }
      }
    }
  }

  if (ret == 3 && port < IO_PORTS && pin < 8) {
    /* Set only if it is output */
    if (vport[port].read_ddr(port) & _BV(pin)) {
      uint8_t pincfg = named_pin_by_pin(port, pin);
      uint8_t active_high = 1;
      if (pincfg != 255)  
        active_high = pgm_read_byte(&portio_pincfg[pincfg].active_high);

      if (XOR_LOG(on, !active_high)) 
        vport[port].write_port(port, vport[port].read_port(port) | _BV(pin));
      else
        vport[port].write_port(port, vport[port].read_port(port) & ~_BV(pin));

      return ECMD_FINAL(snprintf_P(output, len, on ? PSTR("on") : PSTR("off")));
    } else 
      return ECMD_FINAL(snprintf_P(output, len, PSTR("error: pin is input")));

  } else
    return ECMD_ERR_PARSE_ERROR;
}
static int8_t parse_set_motor_command(char *bfr, int8_t bfr_length)
{
	int8_t ret_val = 0;
	motor_level_t levels;
	char speed_channel_string[16] = "";

	if (get_nvm_error_flag() != ERR_NONE)
	{
		send_response_P(PSTR(":ERR NVM_CORR\n"));
		ret_val = ERR_NVM_CORRUPT;
	}

	if (NUMBER_OF_MOTOR_CHANNELS != sscanf_P(bfr, PSTR("SML %s %u"),
			speed_channel_string, &levels.direction_channel_level))
	{
		ret_val = ERR_PARAM;
	}
	else if ((levels.direction_channel_level > MAX_ABSOLUTE_DIRECTION)
			|| (levels.direction_channel_level < MIN_ABSOLUTE_DIRECTION))
	{
		ret_val = ERR_PARAM;
	}

	if (ERR_NONE == ret_val)
	{
		if (0 == strcmp_P(speed_channel_string, PSTR("BRK")))
			levels.speed_channel_level = MOTOR_LEVEL_BRAKE;
		else if (1 != sscanf_P(speed_channel_string, PSTR("%d"),
				&levels.speed_channel_level))
			ret_val = ERR_PARAM;
		else if ((levels.speed_channel_level > MAX_ABSOLUTE_MOTOR_LEVEL)
				|| (levels.speed_channel_level < MIN_ABSOLUTE_MOTOR_LEVEL))
			ret_val = ERR_PARAM;
	}

	if (ERR_NONE == ret_val)
	{
		set_motor_levels(levels.speed_channel_level,
				levels.direction_channel_level);
	}

	if (ERR_NONE != ret_val)
	{
		shutdown_all_motors();
		if (ERR_PARAM == ret_val)
			send_response_P(PSTR(":ERR PARAM\n"));
		else if (ERR_EXEC == ret_val)
			send_response_P(PSTR(":ERR EXEC\n"));
	}
	else
		send_response_P(PSTR(":OK\n"));
	return ret_val;
}
Beispiel #4
0
int16_t parse_cmd_dali_scmd(char *cmd, char *output, uint16_t len)
{
    uint8_t frame[2];
    int scmd_int=0;
    
    while(*cmd == ' ') cmd++;

    if (sscanf_P(cmd, PSTR("%i"), &scmd_int) != 1
        || scmd_int > 287 || scmd_int < 256)
        return ECMD_ERR_PARSE_ERROR;
    
    // special commands have numbers 256-287, but that is just naming
        
    // fit into 8 bit
    uint8_t scmd=(scmd_int-0x100);

    // shift, lsb is always set, msb too
    scmd <<= 1;
    scmd++;
    
    // bits can't be used regularly to allow encoding all messages
    if (scmd & 0x20)
    {
        scmd &= 0x1F;
        scmd |= 0xC0;
    }
    else
        scmd |= 0xA0;

    frame[0]=scmd;

    // read pointer to beginning of next arg
    while(*cmd && *cmd != ' ') cmd++;
    while(*cmd == ' ') cmd++;

    if (sscanf_P(cmd, PSTR("%hhu"), frame+1) != 1)
        return ECMD_ERR_PARSE_ERROR;

    dali_send((uint16_t*)frame);

    repeat_dali_cmd(cmd,(uint16_t*)frame);

#ifdef DALI_RECEIVE_SUPPORT
    return read_dali_reply(cmd, output);
#endif
    
    return ECMD_FINAL_OK;
}
Beispiel #5
0
int16_t
parse_cmd_i2c_max7311_pulse(char *cmd, char *output, uint16_t len)
{
  uint8_t adr;
  uint8_t bit;
  uint16_t time;
  uint8_t ret;
  sscanf_P(cmd, PSTR("%hhu %hhu %hu"), &adr, &bit, &time);
  if (adr > 0x6F || bit > 15)
    return ECMD_ERR_PARSE_ERROR;
  if (time > 1000)
    time = 1000;
  ret = i2c_max7311_pulse(adr, bit, time);
  if (ret == 0)
  {
#ifdef ECMD_MIRROR_REQUEST
    return
      ECMD_FINAL(snprintf_P
                 (output, len, PSTR("max7311 pulse %u %u %u"), adr, bit,
                  time));
#else
    return ECMD_FINAL_OK;
#endif
  }
  else
  {
    return ECMD_FINAL(snprintf_P(output, len, PSTR("no sensor detected")));
  }
}
Beispiel #6
0
int16_t
parse_cmd_goto(char *cmd, char *output, uint16_t len)
{
  uint8_t gotoline = 0;
  char line[ECMD_INPUTBUF_LENGTH];

  if (current_script.handle == NULL)
  {
    return ECMD_FINAL(snprintf_P(output, len, PSTR("no script")));
  }
  sscanf_P(cmd, PSTR("%hhu"), &gotoline);

  SCRIPTDEBUG("current %u goto line %u\n", current_script.linenumber,
              gotoline);

  if (gotoline < current_script.linenumber)
  {
    SCRIPTDEBUG("seek to 0\n");
    vfs_fseek(current_script.handle, 0, SEEK_SET);
    current_script.linenumber = 0;
    current_script.filepointer = 0;
  }
  while ((current_script.linenumber != gotoline) &&
         (current_script.linenumber < ECMD_SCRIPT_MAXLINES))
  {
    SCRIPTDEBUG("seeking: current %i goto line %i\n",
                current_script.linenumber, gotoline);
    if (readline(line) == 0)
    {
      SCRIPTDEBUG("leaving\n");
      break;
    }
  }
  return ECMD_FINAL_OK;
}
Beispiel #7
0
int16_t parse_cmd_pin_get(char *cmd, char *output, uint16_t len)
{
  uint16_t port, pin;

  uint8_t ret = sscanf_P(cmd, PSTR("%u %u"), &port, &pin);
  /* Fallback to named pins */
  if ( ret != 2 && *cmd) {
    uint8_t pincfg = named_pin_by_name(cmd + 1);
    if (pincfg != 255) {
        port = pgm_read_byte(&portio_pincfg[pincfg].port);
        pin = pgm_read_byte(&portio_pincfg[pincfg].pin);
        ret = 2;
    }
  }
  if (ret == 2 && port < IO_PORTS && pin < 8) {
    uint8_t pincfg = named_pin_by_pin(port, pin);
    uint8_t active_high = 1;
    if (pincfg != 255)  
      active_high = pgm_read_byte(&portio_pincfg[pincfg].active_high);
    return ECMD_FINAL(snprintf_P(output, len,
                      XOR_LOG(vport[port].read_pin(port) & _BV(pin), !(active_high))
                      ? PSTR("on") : PSTR("off")));
  } else
    return ECMD_ERR_PARSE_ERROR;
}
Beispiel #8
0
int16_t parse_cmd_i2c_pcf8574x_set(char *cmd, char *output, uint16_t len)
{
	uint8_t adr;
	uint8_t chip;
	uint8_t value;
	sscanf_P(cmd, PSTR("%u %u %x"), &adr, &chip, &value);

#ifdef ECMD_MIRROR_REQUEST
	uint8_t oadr = adr;
#endif

	if (chip == 0)
	{
		adr += I2C_SLA_PCF8574;
	}
	else
	{
		adr += I2C_SLA_PCF8574A;
	}
#ifdef DEBUG_I2C
	debug_printf("I2C PCF8574X IC address 0x%X, value:%X\n",adr, value);
#endif
	i2c_pcf8574x_set(adr, value);
#ifdef ECMD_MIRROR_REQUEST
	return ECMD_FINAL(snprintf_P(output, len, PSTR("pcf8574x set %u %u 0x%X"), oadr, chip, value));
#else
	return ECMD_FINAL(snprintf_P(output, len, PSTR("0x%X"), value));
#endif
}
Beispiel #9
0
int16_t parse_cmd_i2c_pcf8574x_read(char *cmd, char *output, uint16_t len)
{
	uint8_t adr;
	uint8_t chip;
	sscanf_P(cmd, PSTR("%u %u"), &adr, &chip);

#ifdef ECMD_MIRROR_REQUEST
	uint8_t oadr = adr;
#endif

	if (chip == 0)
	{
		adr += I2C_SLA_PCF8574;
	}
	else
	{
		adr += I2C_SLA_PCF8574A;
	}
#ifdef DEBUG_I2C
	debug_printf("I2C PCF8574X IC address 0x%X\n", adr);
#endif
#ifdef ECMD_MIRROR_REQUEST
	uint8_t rc = i2c_pcf8574x_read(adr);
	return ECMD_FINAL(snprintf_P(output, len, PSTR("pcf8574x read %u %u 0x%X"), oadr, chip, rc));
#else
	return ECMD_FINAL(snprintf_P(output, len, PSTR("0x%X"), i2c_pcf8574x_read(adr)));
#endif
}
Beispiel #10
0
int16_t
parse_cmd_i2c_max7311_getDDRw(char *cmd, char *output, uint16_t len)
{
  uint8_t adr;
  uint16_t data;
  uint8_t ret;
  sscanf_P(cmd, PSTR("%hhu"), &adr);
  if (adr > 0x6F)
    return ECMD_ERR_PARSE_ERROR;
  ret = i2c_max7311_getDDRw(adr, &data);
  if (ret == 0)
  {
#ifdef ECMD_MIRROR_REQUEST
    return
      ECMD_FINAL(snprintf_P
                 (output, len, PSTR("max7311 getDDRw %u 0x%X"), adr, data));
#else
    return ECMD_FINAL(snprintf_P(output, len, PSTR("%X"), data));
#endif
  }
  else
  {
    return ECMD_FINAL(snprintf_P(output, len, PSTR("no sensor detected")));
  }
}
Beispiel #11
0
int16_t parse_cmd_dmx_get_universe(char *cmd, char *output, uint16_t len)
{
	uint16_t ret=0, universe=0;
	uint8_t value=0;
	if (cmd[0]!=0) ret = sscanf_P(cmd, PSTR("%u"), &universe);
	if(ret == 1 && universe < DMX_STORAGE_UNIVERSES)
	{
		ret=0;
		static uint16_t chan = 0;
		value=get_dmx_channel(universe,chan);
		output[ret+2] = value%10 +48;
		value /= 10;
		output[ret+1] = value%10 +48;
		value /= 10;
		output[ret+0] = value%10 +48;
		ret+=3;
		if(chan < DMX_STORAGE_CHANNELS-1)
		{
			chan++;
			return ECMD_AGAIN(ret);
		}
		else
		{
			chan=0;
			return ECMD_FINAL(ret);
		}

	}
	else
		return ECMD_ERR_PARSE_ERROR;
}
Beispiel #12
0
int16_t parse_cmd_lcd_init(char *cmd, char *output, uint16_t len)
{
	uint8_t cursor, blink;

#ifdef TEENSY_SUPPORT
	/* Skip leading spaces. */
	while(*cmd == ' ') cmd ++;

	/* Seek space (blink argument), chop and atoi to `blink'.  */
	char *p = cmd;
	while(*p && *p != ' ') p ++;
	if(!*p)
		return ECMD_ERR_PARSE_ERROR; /* Required argument `blink' missing. */

	*p = 0;
	blink = atoi(p + 1);
	cursor = atoi(cmd);
#else
	int ret = sscanf_P(cmd, PSTR("%hhu %hhu"), &cursor, &blink);
	if(ret != 2)
		return ECMD_ERR_PARSE_ERROR;
#endif

    hd44780_init();
    hd44780_config(cursor, blink,1);
    return ECMD_FINAL_OK;
}
Beispiel #13
0
int16_t parse_cmd_dmx_random(char *cmd, char *output, uint16_t len)
{
   uint8_t ret=0;
   uint16_t selection=0;
   if(cmd[0]!=0) ret = sscanf_P(cmd, PSTR("%u"), &selection);
   if(ret == 1)
   {
	if(selection == DMX_EFFECT_ENABLED)
	{
		/*seed the srand() with timer1*/
		srand(TC1_COUNTER_CURRENT);
		random_enabled=DMX_EFFECT_ENABLED;
                return ECMD_FINAL_OK;
	}
	else if(selection == DMX_EFFECT_DISABLED)
	{
		random_enabled=DMX_EFFECT_DISABLED;
                return ECMD_FINAL_OK;
	}
   	else
		return ECMD_ERR_PARSE_ERROR;
   } 
   return ECMD_ERR_PARSE_ERROR;

}
Beispiel #14
0
/* parse an onewire rom address at cmd, write result to ptr */
int8_t
parse_ow_rom(char *cmd, ow_rom_code_t * rom)
{
  uint8_t *addr = rom->bytewise;
  uint8_t end;

  OW_DEBUG_ROM("called parse_ow_rom with string '%s'\n", cmd);

  /* read 8 times 2 hex chars into a byte */
  int ret = sscanf_P(cmd, PSTR("%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx%c"),
                     addr + 0, addr + 1, addr + 2, addr + 3,
                     addr + 4, addr + 5, addr + 6, addr + 7, &end);

  OW_DEBUG_ROM("scanf returned %d\n", ret);

  if ((ret == 8) || ((ret == 9) && (end == ' ')))
  {
    OW_DEBUG_ROM("read rom %02x %02x %02x %02x %02x %02x %02x %02x\n",
                 addr[0], addr[1], addr[2], addr[3],
                 addr[4], addr[5], addr[6], addr[7]);
    return 0;
  }

  return -1;
}
Beispiel #15
0
int16_t parse_cmd_fht_send(char *cmd, char *output, uint16_t len)
{
#ifdef DEBUG_ECMD_FS20
    debug_printf("called with string %s\n", cmd);
#endif

    uint16_t hc, addr, c, c2;

    int ret = sscanf_P(cmd, PSTR("%x %x %x %x"),
                       &hc, &addr, &c, &c2);

    if (ret == 3 || ret == 4)
    {
        if (ret == 3)
        {
            c2 = 0;
        }


#ifdef DEBUG_ECMD_FS20
        debug_printf("fht_send(0x%x,0x%x,0x%x,0x%x)\n", hc, LO8(addr), LO8(c), LO8(c2));
#endif

        fs20_send(1, hc, LO8(addr), LO8(c), LO8(c2));
        return ECMD_FINAL_OK;
    }
    return ECMD_ERR_PARSE_ERROR;
}
Beispiel #16
0
static int16_t parse_cmd_dali_dimcmd(enum dali_cmd c, char *cmd, char *output, uint16_t len)
{
    uint8_t frame[2];

    if (!parse_dali_target(&cmd,&frame[0]))
        return ECMD_ERR_PARSE_ERROR;
           
    // commands are marked with lsb=1
    if (c == CMD)
        frame[0] |= 1;
        
    if (sscanf_P(cmd, PSTR("%hhu"), frame+1) != 1)
        return ECMD_ERR_PARSE_ERROR;

    dali_send((uint16_t*)frame);

    if (c == CMD)
    {
        repeat_dali_cmd(cmd,(uint16_t*)frame);
#ifdef DALI_RECEIVE_SUPPORT
        return read_dali_reply(cmd, output);
#endif
    }
    
    return ECMD_FINAL_OK;
}
static int8_t parse_set_motor_timeout(char *bfr, int8_t bfr_length)
{
	int16_t timeout;
	if (1 != sscanf_P(bfr, PSTR("SMT %d"), &timeout))
	{
		send_response_P(PSTR(":ERR PARAM\n"));
		return ERR_PARAM;
	}

	timeout = COMPUTE_TICKS(timeout);

	if (timeout == 0)
	{
		send_response_P(PSTR(":ERR PARAM\n"));
		return ERR_PARAM;
	}
	else
	{
		if (0 == set_motor_timeout(timeout))
		{
			send_response_P(PSTR(":OK\n"));
			return 0;
		}
		else
		{
			send_response_P(PSTR(":ERR EXEC\n"));
			return ERR_EXEC;
		}
	}
}
void console_process_cmd() {
	if ( console_buffer_pos == 0 ) return;
	char cmd = console_buffer[0];
	if ( cmd == 'h' ) { // read hex power values
		powermon_reading_t reading = powermon_read();
		for (int c = 0; c < POWERMON_NUM_CHANNELS; c++ ) {
			printf_P(PSTR("%d %08lX %08lX %08lX"),c,reading.true_power[c],reading.RMS_current[c],reading.RMS_voltage[c]);
			if ( c < POWERMON_NUM_CHANNELS - 1 )
				printf(",");
		}
		printf("\n");
	} else if (cmd == 'g' ) {
		uint32_t iGain,iOffset,vGain,vOffset;
		int r;
		r = sscanf_P(console_buffer+1,PSTR(" %08lx %08lX %08lx %08lx"),&iGain, &iOffset, &vGain, &vOffset);
		if ( r == 4 ) {
			powermon_set_gains_and_offsets(iGain,iOffset,vGain,vOffset);
			printf_P(PSTR("g OK\n"));
		}
	} else if ( cmd == '+' ) {
		turn_on_gate(console_buffer[1]-'0');
		printf_P(PSTR("+ OK\n"));
	} else if ( cmd == '-' ) {
		printf_P(PSTR("- OK\n"));
		turn_off_gate(console_buffer[1]-'0');
	} else if ( cmd == 't' ) {
		printf_P(PSTR("t OK\n"));
		toggle_gate(console_buffer[1]-'0');
	}
}
void change_addr_mac(){
    
    char key = 0;
    
    sprintf_P(lcd_buf_l1, PSTR("New MAC"));
    sprintf_P(lcd_buf_l2, PSTR("%02x%02x%02x%02x%02x%02x"), _network_mac_addr[0], _network_mac_addr[1], _network_mac_addr[2], _network_mac_addr[3], _network_mac_addr[4], _network_mac_addr[5]);
    lcd_write_buffer(lcd_buf_l1, lcd_buf_l2);
    
    unsigned int idx = 0;
    do{
        key = keypad_get_input();   //Note that this is blockin function
        
        //TODO: implement a-f
        if((key >= '0') && (key <= '9')){
            
            lcd_buf_l2[idx++] = key;
            
            if(idx == 12){	//Stay on last character
                idx--;
            }
        }
        
        //Disp can be refreshed directly because keys are read with blocking function
        disp_refresh();
        
        //Cancel without changes
        if(key == 'C'){
            return;
        }
        
    }while(key != 'A');
    
    sscanf_P(lcd_buf_l2, PSTR("%2x%2x%2x%2x%2x%2x"), _network_mac_addr, _network_mac_addr+1, _network_mac_addr+2, _network_mac_addr+3, _network_mac_addr+4, _network_mac_addr+5);	//Read user given data
}
Beispiel #20
0
/**
 * Parse and then execute the "S" command from the user, which sets the time.
 */
void command_set(char *command)
{
  uint8_t rc;
  rtc_datetime_24h_t dt;

  rc = rtc_clock_stop(rtc);
  printf_P(PSTR("Halted clock, rc=%i\n"), rc);

  rtc_sqw_enable(rtc);
  rtc_sqw_rate(rtc, 1);

  rc = rtc_read(rtc, &dt);

  sscanf_P(command,
      PSTR("S %04d-%02hhd-%02hhd %02hhd:%02hhd:%02hhd\n"),
      &dt.year, &dt.month, &dt.date,
      &dt.hour, &dt.minute, &dt.second);

  dt.day_of_week = rtc_find_dow(dt.year, dt.month, dt.date);

  printf_P(PSTR("Setting time to %04i-%02i-%02i %02i:%02i:%02i (%s)\n"),
      dt.year, dt.month, dt.date,
      dt.hour, dt.minute, dt.second,
      rtc_dow_names[dt.day_of_week]);

  printf_P(PSTR("Trying to write RTC...\n"));
  rc = rtc_write(rtc, &dt);
  printf_P(PSTR("Wrote RTC, rc=%i\n"), rc);

  rc = rtc_clock_start(rtc);
  printf_P(PSTR("Started clock, rc=%i\n"), rc);
}
boolean ModemGSM::NumberExistsInPB(const char *pNumber, int *pIndex)
{
	boolean hasEntry = false;

	DEBUG_P(PSTR("Searching Number in PB [1..20] --> %s"LB), pNumber);

	SendCommand(PSTR("AT+CPBR=1,20"));

	for(int foundIdx = 0;;)
	{
		switch(WaitAnswer(5000))
		{
			case saOk:
			{
				if(hasEntry)
				{
					DEBUG_P(PSTR("  Number Found at position --> %d"LB), foundIdx);

					if(pIndex)
						*pIndex = foundIdx;
				}
				else
				{
					DEBUG_P(PSTR("  Number Not Found"LB));
				}
				
				return hasEntry;

				break;
			}
			case saError:
			case saTimeout:
				return false;    
			case saUnknown:
			{
				char number[PHONE_NUMBER_BUFFER_SIZE];
				int idx;

				if((sscanf_P(FRXBuff,PSTR("+CPBR: %d,\"%20[^\"]\""), &idx, number) == 2))
				{
					//DEBUG_P("  Checking number --> ");
					//DEBUG(idx);
					//DEBUG_P(" : [");
					//DEBUG(number);
					//DEBUGLN_P("]");
					if(!hasEntry)
					{
						foundIdx = idx;
						hasEntry = strcmp(number, pNumber) == 0;
					}
				}
				else
					HandleURC();
			}		
		}
	}

	return false;
}
Beispiel #22
0
int16_t
parse_cmd_wait(char *cmd, char *output, uint16_t len)
{
  uint16_t delay;
  sscanf_P(cmd, PSTR("%u"), &delay);
  SCRIPTDEBUG("wait %ims\n", delay);
  _delay_ms(delay);
  return ECMD_FINAL_OK;
}
Beispiel #23
0
int16_t
parse_cmd_ask_2272_send(char *cmd, char *output, uint16_t len)
{
  (void) output;
  (void) len;

  uint8_t command[3];
  uint8_t delay = 74;
  uint8_t cnt = 10;
  uint8_t sync = 96;

#ifdef TEENSY_SUPPORT
  uint16_t val;
  uint8_t ret;

  for (uint8_t i = 0; i < sizeof(command); i++)
  {
    ret = next_uint16(cmd, &val);
    if (!ret)
      return ECMD_ERR_PARSE_ERROR;

    command[i] = (uint8_t) val;
    cmd += ret;
    if (i < sizeof(command) - 1 && *cmd != ',')
      return ECMD_ERR_PARSE_ERROR;

    cmd++;
  }
  ret = next_uint16(cmd, &val);
  if (ret)
  {
    delay = (uint8_t) val;
    cmd += ret;
    ret = next_uint16(cmd, &val);
    if (ret)
    {
      cnt = (uint8_t) val;
      cmd += ret;
      ret = next_uint16(cmd, &val);
      if (ret)
      {
        sync = (uint8_t) val;
      }
    }
  }
#else
  int ret = sscanf_P(cmd, PSTR("%hhu,%hhu,%hhu %hhu %hhu %hhu"),
                     &(command[0]), &(command[1]), &(command[2]),
                     &delay, &cnt, &sync);
  if (ret < 3)
    return ECMD_ERR_PARSE_ERROR;
#endif

  ask_2272_send(command, delay, cnt, sync);
  return ECMD_FINAL_OK;
}
Beispiel #24
0
int16_t parse_cmd_brew_set_command(char *cmd, char *output, uint16_t len) 
{
    uint8_t step,temp,tim;
    while (*cmd == ' ')
	cmd++;
	if (cmd[0]!=0) 
		sscanf_P(cmd, PSTR("%hu %hu %hu"),  &step,&temp,&tim);
	
  return brew_set(step, temp, tim);
}
Beispiel #25
0
bool testscanf()  {
  float ftest = 0;
  sscanf_P("2012.0326", PSTR("%f"), &ftest);
  if (ftest == 0) {
    return false;
  } else if (ftest == 2012.0326 ) {
    return true;
  }
  return false;  // should never get here...
}
Beispiel #26
0
void parse_ip_address(u8_t result[], char* source) {
    char c;
    int d0,d1,d2,d3; // needed because sscanf requires int variables
    sscanf_P(source,input_format,&d0,&c,&d1,&c,&d2,&c,&d3);
    // copy the int values to the result bytes.
    result[0]=d0;
    result[1]=d1;
    result[2]=d2;
    result[3]=d3;
}
Beispiel #27
0
int16_t
parse_cmd_get(char *cmd, char *output, uint16_t len)
{
  uint8_t pos;
  sscanf_P(cmd, PSTR("%hhu"), &pos);
  if (pos >= ECMD_SCRIPT_MAX_VARIABLES)
  {
    return to_many_vars_error_message(output, len);
  }
  return ECMD_FINAL(snprintf_P(output, len, PSTR("%s"), vars[pos].value));
}
static int8_t parse_set_error_led(char *bfr, int8_t bfr_length)
{
	char flash_string[16];
	int16_t flash_rate;
	LedFlashState_t flash_state;

	uint8_t param_count = sscanf_P(bfr, PSTR("SEL %s %d"), flash_string,
			&flash_rate);

	if (1 > param_count)
	{
		send_response_P(PSTR(":ERR PARAM\n"));
		return ERR_PARAM;
	}

	if (0 == strcmp(flash_string, "ON"))
	{
		flash_state = STATUS_LED_ON;
		if (1 == param_count)
			flash_rate = 0;
	}
	else if (0 == strcmp(flash_string, "OFF"))
	{
		flash_state = STATUS_LED_OFF;
		if (1 == param_count)
			flash_rate = 0;
	}
	else if (0 == strcmp(flash_string, "FLASH"))
	{
		if (2 != param_count)
		{
			send_response_P(PSTR(":ERR PARAM\n"));
			return ERR_PARAM;
		}

		flash_state = STATUS_LED_FLASH;
	}
	else
	{
		send_response_P(PSTR(":ERR PARAM\n"));
		return ERR_PARAM;
	}

	if (0 == set_error_led(flash_state, COMPUTE_TICKS(flash_rate)))
	{
		send_response_P(PSTR(":OK\n"));
		return 0;
	}
	else
	{
		send_response_P(PSTR(":ERR EXEC\n"));
		return ERR_EXEC;
	}
}
Beispiel #29
0
bool UbirchSIM800::expect_scan(const __FlashStringHelper *pattern, void *ref, void *ref1, uint16_t timeout) {
  char buf[SIM800_BUFSIZE];
  size_t len;
  do len = readline(buf, SIM800_BUFSIZE, timeout); while (is_urc(buf, len));
#ifdef DEBUG_AT
  PRINT("--- (");
  DEBUG(len);
  PRINT(") ");
  DEBUGQLN(buf);
#endif
  return sscanf_P(buf, (const char PROGMEM *) pattern, ref, ref1) == 2;
}
Beispiel #30
0
int16_t parse_cmd_pushbutton_down (char *cmd, char *output, uint16_t len)
{
   uint16_t time = 0;
   uint8_t ret  = 0;

   ret = sscanf_P(cmd, PSTR("%d"), &time );
   if (ret == 1) {
      push_button_down(time);
      return ECMD_FINAL_OK;
   } else
      return ECMD_ERR_PARSE_ERROR;
}