Exemple #1
0
static void
soap_parse_element (soap_context_t *ctx)
{
  if (*ctx->buf != '<')
    SOAP_STREAM_ERROR();

  if (ctx->buf[1] == '?')
    return;			/* ignore parser instruction. */

  if (ctx->parsing_complete)
    return;

  ctx->buf[ctx->buflen] = 0;
  SOAP_DEBUG ("parse_element %s\n", ctx->buf);
  if (!ctx->found_envelope)
    {
      if (strncmp_P (ctx->buf + 1, PSTR("Envelope"), 8))
	SOAP_STREAM_ERROR();
      ctx->found_envelope = 1;
    }

  else if (!ctx->found_body)
    {
      if (strncmp_P (ctx->buf + 1, PSTR("Body"), 4))
	return;			/* ignore anything until <Body> */
      ctx->found_body = 1;
    }
  else if (!ctx->found_funcname)
    {
      soap_lookup_funcname (ctx);
      ctx->found_funcname = 1;
    }
  else if (strncmp_P (ctx->buf + 1, PSTR("/Body"), 5) == 0)
    {
      ctx->parsing_complete = 1;
    }
  else if (ctx->buf[1] != '/' && ctx->argslen < SOAP_MAXARGS)
    {
      char *ptr = strstr_P (ctx->buf + 1, PSTR("type="));
      if (!ptr)
	SOAP_STREAM_ERROR ();

      ptr += 6;			/* Skip type=" */
      char *end = strchr (ptr, '"');
      if (!end)
	SOAP_STREAM_ERROR ();
      *end = 0;			/* chop off rest beyond type specifier */

      end = strchr (ptr, ':');
      if (end) ptr = end + 1;	/* Ignore namespace specifier */

      SOAP_DEBUG ("found arg type: '%s'\n", ptr);
      if (strcmp_P (ptr, PSTR("int")) == 0)
	ctx->args[ctx->argslen].type = SOAP_TYPE_INT;
      else if (strcmp_P (ptr, PSTR("string")) == 0)
	ctx->args[ctx->argslen].type = SOAP_TYPE_STRING;
      else
	SOAP_STREAM_ERROR ();
    }
}
ModemGSM::EStandardAnswer ModemGSM::WaitAnswer(unsigned int pTimeoutMS, boolean pHandleURC)
{
	//DEBUG_P("WaitAnswer --> ");
	for(;;)
	{
		if(Readln(pTimeoutMS, false) == TIMEOUT)
		{
			DEBUG_P(PSTR("** TIMEOUT"LB));
			return saTimeout;
		}
		
		//DEBUGLN(FRXBuff);

		if(strcmp_P(FRXBuff,PSTR("OK")) == 0)
		{
			//DEBUGLN_P("OK");
			return saOk;    
		}
		else if(	(strcmp_P(FRXBuff,PSTR("ERROR")) == 0) ||
					(strncmp_P(FRXBuff,PSTR("+CME ERROR:"), 11) == 0) ||
					(strncmp_P(FRXBuff,PSTR("+CMS ERROR:"), 11) == 0))
		{
			DEBUG_P(PSTR("** "));
			DEBUGLN(FRXBuff);
			return saError;    
		}
		else if(pHandleURC)
			HandleURC();
		else
			return saUnknown;    
	}
}
Exemple #3
0
bool SikwiWifi::process()
{
  newLine = this->read_till_eol();
  if(newLine){
    if(strncmp_P(this->buffer, PSTR("SK+RDY"), 6)==0 || strncmp_P(this->buffer, PSTR("Exception"), 9)==0 || strncmp_P(this->buffer, PSTR(">>>st"), 5)==0)
      return false;

    this->previousMillis = millis();
    return true;
  }
  else if(millis() - this->previousMillis >= this->intervalTest) {
    this->previousMillis = millis();
    uint8_t i = 0;
    do{
      this->writeCharPROGMEMln(PSTR("SK"));
      if(this->wait_for_esp_response(1000))
        return true;
      delay(300);
    }while(i++<3);

    return false;
  }

  return true;
}
void loop()
{

    if (wifly.available() > 0) {

    	/* See if there is a request */
		if (wifly.gets(buf, sizeof(buf))) {
		    if (strncmp_P(buf, PSTR("GET /ping"), 9) == 0) {

				/* GET request */
#ifdef DEBUG
				Serial.println(F("PONG XML requested"));
#endif
				while (wifly.gets(buf, sizeof(buf)) > 0) {
				    //Skip rest of request
				}

				sendPong();

	   	 	} else if (strncmp_P(buf, PSTR("GET /data"), 9) == 0) {

	        	/* POST request */
#ifdef DEBUG
	        	Serial.println(F("DATACOLLECTOR XML: sendind sensors data"));
#endif

				while (wifly.gets(buf, sizeof(buf)) > 0) {
				    //Skip rest of request
				}

                // discard rest of input
		    	// wifly.flushRx();		
				sendSensorsDataXML();

	    	} else {

	       		// Unexpected request
#ifdef DEBUG
				Serial.print(F("Unexpected: "));
				Serial.println(buf);
				Serial.println(F("Sending 404"));
#endif
				while (wifly.gets(buf, sizeof(buf)) > 0) {
				    //Skip rest of request
				}

                // discard rest of input
				wifly.flushRx();		
				send404();

	    	}
		}
    }
}
/*
 * This method parses a incoming string (the message is expected to be complete)
 * Depending on the instruction the action is undertaken.
 */
void SerialCommunicator::setReceivedMessage(const char* newMessage)
{
	if (strcmp_P(newMessage, DUMP) == 0)
	{
		dumpAllFields();
	} else if (strncmp_P(newMessage, GET, 4) == 0)
	{
		SerialOutput.println((__FlashStringHelper *) GET);
		FieldData *fieldData = FieldData::findField(newMessage + 4);
		if (fieldData != 0) fieldData->dump();
	} else if (strncmp_P(newMessage, SET, 4) == 0)
	{
		SerialOutput.println((__FlashStringHelper *) SET);
		FieldData *fp = FieldData::findField(newMessage + 4);
		if (fp != 0)
		{
			fp->setValue(newMessage + 4 + strlen_P((const char *) fp->myClassName) + strlen_P((const char *) fp->myFieldName) + 2);
			fp->dump();
		}
	} else if (strncmp_P(newMessage, SET, 3) == 0)
	{
		SerialOutput.println((__FlashStringHelper *) SET);
		FieldData::visitAllFields(dumpWritableData, true);
	} else if (strcmp_P(newMessage, LOG_HEADER) == 0)
	{
		SerialOutput.print((__FlashStringHelper *) LOG_HEADER);
		SerialOutput.print(FIELDSEPERATOR);
		FieldData::visitAllFields(logHeaderVisitor, true);
		SerialOutput.println();
		return;
	} else if (strcmp_P(newMessage, LOG_VALUE) == 0)
	{
		logValue();
		return;
//#ifdef I_USE_RESET
//	} else if (strcmp_P(newMessage, RESET) == 0)
//	{
//		ForceHardReset();
//#endif
	} else
	{
		dumpCommands();
		if ('?' != newMessage[0])
		{
			SerialOutput.print((__FlashStringHelper *) ERROR);
			//Even though it is handy to see what has been send
			//The yun bootloader sends press ard to stop bootloader
			//echoing this means the bootloader receives ard
			//SerialOutput.println(newMessage);
		}
		return;
	}
	SerialOutput.println((__FlashStringHelper *) DONE);
}
bool CommandParser::ParseCommand(const String& command, Command& outCommand)
{
  Clear(); // clear first

  if(command.length() < MIN_COMMAND_LENGTH)
    return false;

  const char* readPtr = command.c_str();
  
  bool rightPrefix = !strncmp_P(readPtr,(const char*)CMD_PREFIX,CMD_PREFIX_LEN);// || !strncmp_P(readPtr,(const char*)CHILD_PREFIX,CMD_PREFIX_LEN);

  if(!rightPrefix)
    return false;


  // перемещаемся за префикс (CT или CD)
  readPtr += CMD_PREFIX_LEN;

  // проверяем, GET или SET должно быть передано
  bool isGet = !strncmp_P(readPtr,(const char*)CMD_GET,CMD_TYPE_LEN);
  bool rightType =  isGet || !strncmp_P(readPtr,(const char*)CMD_SET,CMD_TYPE_LEN);
  if(!rightType)
    return false;


  uint8_t commandType = isGet ? ctGET : ctSET;

  // перемещаемся за тип команды и знак '='
  readPtr += CMD_TYPE_LEN + 1;

  // ищем, есть ли разделитель в строке. Если он есть, значит, передали ещё и параметры помимо просто имени модуля
  const char* delimPtr = strchr(readPtr,'|');
  if(!delimPtr)
  {
    // без параметров, тупо конструируем и выходим
     outCommand.Construct(readPtr,NULL,commandType);
     return true;
  }

  // есть параметры, надо выцепить имя модуля
  size_t len = (delimPtr - readPtr);

  
  char* moduleName = new char[len+1];
  memset(moduleName,0,len+1);
  strncpy(moduleName,readPtr,len);
  
  delimPtr++;

  outCommand.Construct(moduleName,delimPtr,commandType);
  delete[] moduleName;
  return true;
   
}
Exemple #7
0
int16_t parse_cmd_lcd_shift(char *cmd, char *output, uint16_t len)
{
  if (strlen(cmd) < 1) 
    return ECMD_ERR_PARSE_ERROR;

  if (!strncmp_P(cmd + 1, PSTR("right"), 5))
    hd44780_shift(1);
  else if (!strncmp_P(cmd + 1, PSTR("left"), 4)) 
    hd44780_shift(0);
  else
    return ECMD_ERR_PARSE_ERROR;

  return ECMD_FINAL_OK;
}
Exemple #8
0
static void shell_network(char *str)
{
char *pos = str + sizeof("network");
uint8_t is_error = 0;
char dstr[DSTR_BUF];


	if (strncmp_P(pos, PSTR("set "), 4) == 0)
	{
        pos += 4;
		if (strncmp_P(pos, PSTR("ip "), 3) == 0)
		{
        	pos += 3;
			is_error = net_conf_set_ip_string(pos);
		}
		else if (strncmp_P(pos, PSTR("gw "), 3) == 0)
		{
        	pos += 3;
			is_error = net_conf_set_gw_string(pos);
		}
		else if (strncmp_P(pos, PSTR("nm "), 3) == 0)
		{
        	pos += 3;
			is_error = net_conf_set_nm_string(pos);
		}
		else if (strncmp_P(pos, PSTR("dhcp "), 5) == 0)
		{
        	pos += 5;
			is_error = net_conf_set_dhcpc_string(pos);
		}
		else
		{
			shell_output("unknown set operation: ", pos);
		}
	}
	else if (strncmp_P(pos, PSTR("show"), 4) == 0)
	{
        pos += 5;
		net_conf_get_mac_string(dstr, DSTR_BUF);
		shell_output("MAC: ", dstr);
		net_conf_get_ip_string(dstr, DSTR_BUF);
		shell_output("IP: ", dstr);
		net_conf_get_nm_string(dstr, DSTR_BUF);
		shell_output("NM: ", dstr);
		net_conf_get_gw_string(dstr, DSTR_BUF);
		shell_output("GW: ", dstr);
	}
	else if (strncmp_P(pos, PSTR("load"), 4) == 0)
	{
		net_conf_load();
	}
	else if (strncmp_P(pos, PSTR("save"), 4) == 0)
	{
		net_conf_save();
	}
	else
	{
		shell_output_P(PSTR("options: show, set, load, save"),PSTR(""));
	}
}
Exemple #9
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  PT_BEGIN(&s->outputpt);
 
  char *ptr;

  if(!httpd_fs_open(s->filename, &s->file)) {
    httpd_fs_open(http_404_html, &s->file);
    strcpy_P(s->filename, http_404_html);
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404));
    PT_WAIT_THREAD(&s->outputpt, send_file(s));
  } else {
    snprintf(s->tmp_str, sizeof(s->tmp_str) -1, "%d", s->file.len);
    //snprintf(s->str_tmp, 8, "%d", s->len);
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200));
    ptr = strchr(s->filename, ISO_period);
    if(ptr != NULL && strncmp_P(ptr, http_shtml, 6) == 0) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_script(s));
    } else {
      PT_WAIT_THREAD(&s->outputpt, send_file(s));
    }
  }

  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
int Jukebox2::fileCount(FatReader &dir){
  //Serial.print("WTF!");
  int count = 0;
  FatReader tempFile;
  dir_t dirBuf;     // buffer for directory reads
  dir.rewind();
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
    //Serial.print("QQQ!");
      // Skip it if not a subdirectory and not a .WAV file
    if (!DIR_IS_SUBDIR(dirBuf)
         && strncmp_P((char *)&dirBuf.name[8], PSTR("WAV"), 3)) {
      continue;
    }

    if (!tempFile.open(vol, dirBuf)) {        // open the file in the directory
      Serial.print("file.open failed");          // something went wrong
    }

    if (tempFile.isDir()) {                   // check if we opened a new directory

    }
    else{
      count++;
    }

  }
  dir.rewind();
  Serial.print("Count was:");
  Serial.println(count);
  return count;
}
/*
 * Processes a line of data in an HTTP request.  This function looks
 * for GET and saves a copy of the URL in the current connection's
 * server request.  It also sets the request's isValid flag if the
 * URL has been saved and an empty line is found.
 */
boolean processLine(char* data, int len) {

	// Check for a valid GET line
	if ((uip_conn->appstate.request == NULL) && (strncmp_P(data, httpGET, 4) == 0)) {
		// URL starts at the '/'
		char* start = data + 4;
		// Find trailing space after the URL
		data = start;
		char* end = data + len;
		while (++data < end) {
			if (' ' == *data) {
				// Replace the space with a NULL to terminate it
				*(data++) = '\0';
			
				// copy the URL to the static storage
				uip_conn->appstate.request = get_string_global;
				strncpy(get_string_global, start, WISERVER_GET_STRING_MAX - 1);
				// The following set is implicit. get_string_global is allocated in 
				// the BSS so it starts with a NULL last char and it stays there
				// as long as we never overwrite it
				// get_string_global[WISERVER_GET_STRING_MAX - 1] = '\0';

				return false;
			}
		}
		// No space, not valid
	}

	return (len == 0);
}
Exemple #12
0
bool SikwiWifi::wait_for_esp_response(const unsigned long timeout, const char* term)
{
  unsigned long t=millis();
  bool found=false;
  char len=strlen_P(term);
  uint8_t i=0;
  while(millis()<t+timeout) {
    if(this->espSerial->available()){
      char myChar = (char)this->espSerial->read();
      this->buffer[i++]=myChar;
      if(i>=len) {
        if(strncmp_P(this->buffer+i-len, term, len)==0) {
          found=true;
          break;
        }
      }
    }
  }

  this->buffer[i]=0;
  #if defined(DEBUG_WIFI)
    this->debugPrinter->println(this->buffer);
  #endif
  return found;
}
bool SerialConsole::handleCommand(const char *buffer, const uint8_t len)
{
    if (buffer[0] == 0)
        return false;

    for (uint8_t i = 0; i != MAX_COMMANDS; ++i)
    {
        if (commands[i].hasParam)
        {
            const uint8_t cmd_len = strlen_P(commands[i].command);
            if (strncmp_P(buffer, commands[i].command, cmd_len) == 0)
            {
                (this->*commands[i].handler) (buffer, len);
                return true;
            }

        } else if (strcmp_P(buffer, commands[i].command) == 0) {
            (this->*commands[i].handler) (buffer, len);
            return true;
        }
    }

    uart << PGM << STR_HELP_UNKNOWN;
    uart << " (" << buffer << ")" << CR;

    return false;
}
Exemple #14
0
/*
 * Read all of the config parameters from the EEPROM
 *
 * There are some sanity checks. If they fail then
 * it will call reset() instead.
 */
void ConfigParms::read()
{
  const size_t crc_size = sizeof(uint16_t);
  const size_t magic_len = sizeof(magic);
  size_t size = magic_len + sizeof(*this) + crc_size;
  uint8_t buffer[size];

  // Read the whole block from EEPROM in memory
  eeprom_read_block((void *)buffer, eepromAddr(), size);

  // Verify the checksum
  uint16_t crc = *(uint16_t *)(buffer + size - crc_size);
  uint16_t crc1 = crc16_ccitt(buffer, size - crc_size);

  if (strncmp_P((const char *)buffer, magic, magic_len) != 0) {
    //DIAGPRINTLN(F("ConfigParms::read - magic wrong"));
    goto do_reset;
  }
  if (crc != crc1) {
    goto do_reset;
  }

  // Initialize the ConfigParms instance with the info from EEPROM
  memcpy((uint8_t *)this, buffer + magic_len, sizeof(*this));
  return;

do_reset:
  reset();
}
Exemple #15
0
void SimGSM::handleCallback() {
	// Handle overflow request first
	size_t pos = 0;
	int i = _overflow_slot;
	if (_overflow_size > 0 && _cb[i].func)
		pos += _cb[i].func(_buf, _buf_size, _cb[i].data);

	// Handle the rest if we still have available space
	while (pos < _buf_size) {
		size_t used = 0;
		for (i = 0; i < GSM_MAX_CALLBACK; i++) {
			if (_cb[i].func && !strncmp_P((char *)_buf + pos, _cb[i].match, _cb[i].length)) {
				used = _cb[i].func(_buf + pos, _buf_size - pos, _cb[i].data);
				if (used)
					break;
			}
		}
		pos += used ? used : 1;
	}

	// Callback can request overflow by returning used space
	// beyond _buf space
	if (pos > _buf_size) {
		_overflow_size = pos - _buf_size;
		_overflow_slot = i;
	} else {
		_overflow_size = 0;
	}
}
Exemple #16
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;
}
Exemple #17
0
uint8_t cli_completion(char* buffer, uint16_t maxcmdlength, PGM_VOID_P cmdlist) {
    uint8_t i=0;
    char ref[maxcmdlength+1];
    char* itemstr;
    ref[0]='\0';
    /* check if we are behind the first word */
    while(buffer[i]) {
        if(!isgraph(buffer[i++]))
            return 0;
    }
    for(;;) {
        itemstr = (char*)pgm_read_word(cmdlist);
        if(itemstr==NULL)
            break;
        cmdlist = (uint8_t*)cmdlist +CMDLIST_ENTRY_SIZE;
        if(!strncmp_P(buffer, itemstr, i)) {
            if(!ref[0]) {
                strcpy_P(ref, itemstr);
            } else {
                ref[stridentcnt_P(ref, itemstr)]='\0';
            }
        }
    }
    i = strcmp(buffer, ref);
    if(i)
        strcpy(buffer, ref);
    return ~i;
}
Exemple #18
0
void handle_command() {
  serial_in[serial_in_ctr] = '\0';
  p = serial_out;

  if (!strncmp_P((char*)serial_in, PSTR("TIME"), 4)) {
    handle_time();
  } else if (!strncmp_P((char*)serial_in, PSTR("ACCELVERB"), 9)) {
    handle_accelverb();
  } else if (!strncmp_P((char*)serial_in, PSTR("ACCEL"), 5)) {
    handle_accel();
    p += strlcpy_P(p, off, 64);
  } else if (!strncmp_P((char*)serial_in, PSTR("SCAN"), 4)) {
    flash_scan();
    p += strlcpy_P(p, cmdresult, 64);
    p += sprintf(p, " %03d %03d", flash_addr >> 8, flash_addr & 0xFF);
  } else if (!strncmp_P((char*)serial_in, PSTR("ADDR"), 4)) {
Exemple #19
0
static void shell_udpds(char *str)
{
	char *pos = str + sizeof("udpds");

	if (strncmp_P(pos, PSTR("set "), 4) == 0)
	{
	}
	else if (strncmp_P(pos, PSTR("show"), 4) == 0)
	{
	}
	else if (strncmp_P(pos, PSTR("enable"), 6) == 0)
	{
	}
	else if (strncmp_P(pos, PSTR("disable"), 7) == 0)
	{
	}
}
Exemple #20
0
bool cmd_engine_led_command(const char *command, bool *startCmd)
{
  if (!strncmp_P(command, PSTR("led "), 4)) {
    cmd_engine_set_led(command + 4);
    return true;
  }

  return false;
}
Exemple #21
0
/* ----------------------------------------------------------------------------
 * receive Art-Net packet
 */
void
artnet_get(void)
{
  struct artnet_header *header;

  header = (struct artnet_header *) uip_appdata;

  /* check the id */
  if (strncmp_P((char *) header->id, artnet_ID, 8))
  {
    ARTNET_DEBUG("Wrong ArtNet header, discarded\r\n");
    artnet_status = RC_PARSE_FAIL;
    return;
  }
  switch (header->opcode)
  {
    case OP_POLL:;
      struct artnet_poll *poll;

      ARTNET_DEBUG("Received artnet poll packet!\r\n");
      poll = (struct artnet_poll *) uip_appdata;
      processPollPacket(poll);
      break;
    case OP_POLLREPLY:;
      ARTNET_DEBUG("Received artnet poll reply packet!\r\n");
      break;
    case OP_OUTPUT:;
      uip_ipaddr_t artnet_pollReplyTarget;
      struct artnet_dmx *dmx;

      ARTNET_DEBUG("Received artnet output packet!\r\n");
      dmx = (struct artnet_dmx *) uip_appdata;
      uip_ipaddr_copy(&artnet_pollReplyTarget, BUF->srcipaddr);

      if (dmx->universe == ((artnet_subNet << 4) | artnet_outputUniverse))
      {
        if (artnet_dmxDirection == 0)
        {
          uint16_t len = ((dmx->lengthHi << 8) + dmx->length);
          set_dmx_channels((const uint8_t *) &dmx->dataStart,
                           artnet_outputUniverse, 0, len);
          if (artnet_sendPollReplyOnChange == TRUE)
          {
            artnet_pollReplyCounter++;
            artnet_sendPollReply(&artnet_pollReplyTarget);
          }
        }
      }
      break;
    case OP_ADDRESS:;
    case OP_IPPROG:;
      break;
    default:
      ARTNET_DEBUG("Received an invalid artnet packet!\r\n");
      break;
  }
}
Exemple #22
0
const char PROGMEM *settingsLineSetNotifyCond(char *buf, uint16_t len, uint8_t index) {
    if (index > 3) {
        return TOO_MANY_NOTIFY;
    }
    if (currentSetLineIdx >= lineInputSize){
        return NO_NOTIFY_OUTPUT;
    }

    uint8_t notif;
    if (!strncmp_P(buf, LINE_NOTIFICATION_SUP, len)) {
        notif = OVER_EQ;
    } else if (!strncmp_P(buf, LINE_NOTIFICATION_INF, len)) {
        notif = UNDER_EQ;
    } else {
        return PSTR("invalid notify condition");
    }
    eeprom_write_byte((uint8_t *) &lineInputSettings[currentSetLineIdx].notifies[index].condition, notif);
    return 0;
}
Exemple #23
0
static int8_t find_message_index(char* code) {
  int8_t index = 0;
  for (; index < NUM_FW_COMMAND; index++) {
    const struct fw_command_struct* fw_command = &fw_command_table[index];
    if (strncmp_P(code, fw_command->code, 3) == 0) {
      return index;
    }
  }
  return -1;
}
Exemple #24
0
/**
 *	Find needle on haystack
 *
 *	@param const __FlashStringHelper *needle
 *	@param char *haystack
 *	@param __FlashStringHelper *separator
 *	@return *char value
 **/
const char *uHTTP::parse(const __FlashStringHelper *needle, char *haystack, const __FlashStringHelper *sep){
	char *act, *sub, *ptr;
	char buffer[uHTTP_BUFFER_SIZE];
	strcpy(buffer, haystack);
	for(act = buffer; strncmp_P(sub, (const PROGMEM char *) needle, strlen_P((const PROGMEM char *) needle)); act = NULL){
		sub = strtok_rP(act, (const PROGMEM char *) sep, &ptr);
		if(sub == NULL) break;
	}
	return (sub) ? strchr(sub, '=') + 1 : NULL;
}
Exemple #25
0
/*
 * Parses the string data points to, checks if it is any of the
 * defined commands, and calls the apropriate function.
 */
bool_t cmd_parse(const uint8_t* data, uint8_t size)
{
  uint8_t i;
  for(i=0; i < CMD_NUM; i++)
  {
    uint8_t cmd_len = pgm_read_byte(&cmds[i].cmd_len);
    uint8_t arg_len = pgm_read_byte(&cmds[i].arg_len);
    /*
     * Makes str point to the position in the string where the
     * command should be if it is valid
     */
    const uint8_t* str = data + size - cmd_len - arg_len - CONFIG_GRP_LEN;
    
#if 1
    /* can data even contain the command (and argument)?  */
    if(str < data);
    {
      /* check if it is broadcast or out group number and if it is a valid command */
      if((strncmp((const char*)str, "00", CONFIG_GRP_LEN) == 0 || 
          strncmp((const char*)str, (const char*)config.group, CONFIG_GRP_LEN) == 0))
      {
         if(strncmp_P((const char*)str + CONFIG_GRP_LEN, (PGM_P)pgm_read_word(&cmds[i].string), cmd_len) == 0)
#endif
#if 0
    /* can data even contain the command (and argument)?  */
    if((str < data) 
      /* and check that it starts with either witd broadcast id or
       * our group number */
       && (strncmp((const char*)str, "00", CONFIG_GRP_LEN) == 0 || 
           strncmp((const char*)str, (const char*)config.group, CONFIG_GRP_LEN) == 0)
       /* and is the command after if it is, check if it is the correct command */
       && strncmp_P((const char*)str + CONFIG_GRP_LEN, (PGM_P)pgm_read_word(&cmds[i].string), cmd_len) == 0)
#endif
    {
      /* Call the function with the pointer associated with the command */
      ((cmd_callback_t*)pgm_read_word(&cmds[i].f))(data+size-arg_len);
      return TRUE;
    }
    }
    }
  }
  return FALSE;
}
Exemple #26
0
static uint8_t
jabber_extract_from(void)
{
  const char *from = strstr_P(uip_appdata, PSTR("from="));
  if (!from)
    return 1;

  from += 6;                    /* skip from=' */

  const char *resource_end = strchr(from, '/');
  if (!resource_end)
  {
    JABDEBUG("from addr resource not found\n");
    return 1;
  }

  const char *endptr = strchr(from, '\'');
  if (!endptr)
    endptr = strchr(from, '\"');
  if (!endptr)
  {
    JABDEBUG("end of from addr not found\n");
    return 1;
  }

  uint8_t jid_len = resource_end - from;
  uint8_t len = endptr - from;
  if (len + 1 > TARGET_BUDDY_MAXLEN)
  {
    JABDEBUG("extract_from: from addr too long\n");
    return 1;
  }

  uint8_t auth = 1;
  for (uint8_t i = 0;
       i < (sizeof(jabber_known_buddies) / sizeof(jabber_known_buddies[0]));
       ++i)
  {
    char *jidlist_ptr = (char *) pgm_read_word(&jabber_known_buddies[i]);
    auth = strncmp_P(from, jidlist_ptr, jid_len) == 0;
    if (auth == 1)
      break;
  }

  JABDEBUG("authentificated %s: %d\n", from, auth);
  if (!auth)
    return 2;                   /* Permission denied. */

  memmove(STATE->target, from, len);
  STATE->target[len] = 0;

  JABDEBUG("message from: %s\n", STATE->target);
  return 0;                     /* Looks good. */
}
void parse_command(char* buffer, uint16_t *pos, uint8_t *color) {
	if (!strncmp_P(buffer, PSTR("\\1"), 2)) {
		(*pos) += 2;
		(*color) = 0;
	} else if (!strncmp_P(buffer, PSTR("\\2"), 2)) {
		(*pos) += 2;
		(*color) = 1;
	} else if (!strncmp_P(buffer, PSTR("\\3"), 2)) {
		(*pos) += 2;
		(*color) = 2;
	} else if (!strncmp_P(buffer, PSTR("\\-"), 2)) {
		if ((buffer[2] >= '0') && (buffer[2] <= '9')) {
			brightness = 16+(buffer[2] - '0')*10;
		}
		(*pos) += 3;
	} else {
		(*pos) += 1;
	}

}
Exemple #28
0
void SikwiWifiWebsocket::process()
{
  char *pb;
  if(this->wifi->newLine){
    if(strncmp_P(this->wifi->buffer, PSTR("WS:"), 3)==0){
      uint8_t responseType;
      pb = this->wifi->buffer+3;
      if(tcpHandler)
        tcpHandler(pb);
    }//if found TCP:
  }
}
Exemple #29
0
int16_t parse_cmd_lcd_backlight(char *cmd, char *output, uint16_t len)
{
  if (strlen(cmd) < 1) 
    return ECMD_ERR_PARSE_ERROR;

  if (!strncmp_P(cmd + 1, PSTR("on"), 2))
#ifdef HD44780_BACKLIGHT_INV
    hd44780_backlight(0);
#else
    hd44780_backlight(1);
#endif
  else if (!strncmp_P(cmd + 1, PSTR("off"), 3)) 
Exemple #30
0
void LLAPSerial::processMessage(){
	//if (LLAP.cMessage[0] != 'a') return; //not needed as already checked
	if( checkId ) {
	  if (cMessage[1] != deviceId[0]) return;
	  if (cMessage[2] != deviceId[1]) return;
	}
	// now we have LLAP.cMessage[3] to LLAP.cMessage[11] as the actual message
	if (0 == strncmp_P(&cMessage[3],PSTR("HELLO----"),9)) {
		_Serial->print(cMessage);	// echo the message
	} else if (0 == strncmp_P(&cMessage[3],PSTR("CHDEVID"),7)) {
	  if (strchr_P(PSTR("-#@?\\*ABCDEFGHIJKLMNOPQRSTUVWXYZ"), cMessage[10]) != 0 && strchr_P(PSTR("-#@?\\*ABCDEFGHIJKLMNOPQRSTUVWXYZ"), cMessage[11]) != 0)
	  {
		deviceId[0] = cMessage[10];
		deviceId[1] = cMessage[11];
		_Serial->print(cMessage);	// echo the message
	  }
	} else {
		sMessage = String(&cMessage[3]); // let the main program deal with it
		bMsgReceived = true;
	}
}