void CudaCompiler::splitPathList(Array<String>& res, const String& value) { for (int startIdx = 0; startIdx < value.getLength();) { int endIdx = value.indexOf(';', startIdx); if (endIdx == -1) endIdx = value.getLength(); String item = value.substring(startIdx, endIdx); if (item.getLength() >= 2 && item.startsWith("\"") && item.endsWith("\"")) item = item.substring(1, item.getLength() - 1); res.add(item); startIdx = endIdx + 1; } }
bool ESP::sATCWJAP(String ssid, String pwd) { String data; flush(); this->serial->print(F("AT+CWJAP=\"")); this->serial->print(ssid); this->serial->print("\",\""); this->serial->print(pwd); this->serial->println("\""); data = recvString(F("OK"), F("FAIL"), 10000); if (data.indexOf("OK") != -1) { return true; } return false; }
bool ESP8266::sATCIPMODE(uint8_t mode) { String data; if(mode>1||mode<0){ return false; } rx_empty(); m_puart->print(F("AT+CIPMODE=")); m_puart->println(mode); data = recvString("OK", "Link is builded",2000); if (data.indexOf("OK") != -1 ) { return true; } return false; }
int EB_Bluetooth_4_0::setName(String name) { int isSuccess = 0; String cmd(AT_NAME); cmd += name; String recvBuf; sendCommand(cmd,&recvBuf); if(recvBuf.indexOf(name) != -1){ isSuccess= 1; } return isSuccess; }
// numberOfParameters // // Get the number of parameters int numberOfParameters(String parameters) { if (parameters.equals("")) return 0; else { String temp = parameters; int count = 0, index; do { index = temp.indexOf(PARAM_SEP); temp = temp.substring(index + 1); count++; } while (index >= 0); return count; } }
bool ESP8266::sATCWJAP(String ssid, String pwd) { String data; rx_empty(); m_puart->print("AT+CWJAP=\""); m_puart->print(ssid); m_puart->print("\",\""); m_puart->print(pwd); m_puart->println("\""); data = recvString("OK", "FAIL", 10000); if (data.indexOf("OK") != -1) { return true; } return false; }
boolean Minitel::printAccentChar(char c) { if (isAccent(c)) { String accents = "áàâäéèëêíìîïóòôöúùûü"; int index = (accents.indexOf(c)-1)/2; int accentTypeIndex = index%4; printAccent(accentTypeIndex); int letterIndex = floor(index/4); char letter = getAccentLetter(letterIndex); textChar(letter); return true; } return false; }
void Orion::Iniciar(String _ssid, String _password){ esp8266.begin(BaudRate); char _ssid_buffer[32]; _ssid.toCharArray(_ssid_buffer, 32); esp8266.println("AT+CWJAP?"); unsigned long time = millis(); if (esp8266.find(_ssid_buffer)){ Serial.println(F("Ya estas conectado a Red")); Serial.println("Conectado a red: " + _ssid); delay(1000); } else { Serial.println(F("No Conectado a Red")); AT(); Desconectar(); Modo(); Mux(); Serial.println(F("Conectando a red Wifi:")); delay(50); String respuesta = ""; esp8266.println("AT+CWJAP=\"" + _ssid + "\",\"" + _password + "\""); time = millis(); int auxiliar = 1; if (esp8266.available()>0) { while (auxiliar == 1) { while (esp8266.available()) { char c = esp8266.read(); respuesta += c; } if (respuesta.indexOf("OK") != -1) { Serial.println("Conectado a red: " + _ssid); auxiliar = 0; break; } if ( millis() - time > 9000){ Serial.println(F("No se pudo conectar, reiniciar")); while(1); } } } } }
bool ESP8266::eATSAVETRANSLINK(uint8_t mode,String ip,uint32_t port) { String data; rx_empty(); m_puart->print(F("AT+SAVETRANSLINK=")); m_puart->print(mode); m_puart->print(F(",\"")); m_puart->print(ip); m_puart->print(F("\",")); m_puart->println(port); data = recvString("OK", "ERROR",2000); if (data.indexOf("OK") != -1 ) { return true; } return false; }
// reset the modem for direct access int GSM3ShieldV1ModemVerification::begin() { int result=0; String modemResponse; // check modem response modemAccess.begin(); // reset hardware modemAccess.restartModem(); modemResponse=modemAccess.writeModemCommand("AT", 1000); if(modemResponse.indexOf("OK")>=0) result=1; modemResponse=modemAccess.writeModemCommand("ATE0", 1000); return result; }
String ESP8266::recvString(String target, uint32_t timeout) { String data; char a; unsigned long start = millis(); while (millis() - start < timeout) { while(m_puart->available() > 0) { a = m_puart->read(); if(a == '\0') continue; data += a; } if (data.indexOf(target) != -1) { break; } } return data; }
/*=========================================*/ String WIFI::showIP(void) { Serial1.println("AT+ShowIP"); //发送AT指令 String data; while (1) { if(Serial1.available()>0) { char a =Serial1.read(); data=data+a; } if (data.indexOf("done")!=-1) { break; } } return data; }
int Me_SoftBluetooth::connected() { String conSymb = "OK"; String recvBuf; char recvChar; while(available()) { recvChar = read(); recvBuf += recvChar; if(recvBuf.indexOf(conSymb) != -1) { bluetoothState = BLUETOOTH_CONNECTED; } } return bluetoothState; }
static void COMM_parse_command(String command) { Serial.println("Command received: " + command); int delimiter_index = command.indexOf(DELIMITER); if(delimiter_index != -1) { String command_name = command.substring(0, delimiter_index); String arg_str = command.substring(delimiter_index+1); int arg = arg_str.toInt(); if ((arg == 0) && (arg_str != "0")) { Serial.println("Integer argument converted to zero, ignoring!!"); COMM_send_bluetooth_command("ERROR bad command argument, not int"); } else COMM_command_received(command_name, arg); } else { COMM_command_received(command); } }
int WIFI::ReceiveMessage(char *buf, int MsgLen) { //+IPD:11,wifi read11 //done String data = ""; if (Serial1.available()>0) { //Serial.println(Serial1.available()); char c0 = Serial1.read(); if (c0 == '+') { while (1) { if (Serial1.available()>0) { char c = Serial1.read(); data += c; } if (data.indexOf("done")!=-1) { break; } } //Serial.println(data); int sLen = strlen(data.c_str()); int i; for (i = 0; i <= sLen; i++) { if (data[i] == ':') { break; } } String _size = data.substring(4, i); int iSize = _size.toInt(); //Serial.println(_size); String str = data.substring(i+1, i+1+iSize); strcpy(buf, str.c_str()); //Serial.println(str); return iSize; } } return 0; }
bool RtspSocket::readPacketHeader(RtspHeader*& rtspHeader) { rtspHeader = new RtspHeader(); bool resultCode; String line; do { resultCode = readLine(line); if (resultCode && line.size() > 0) { if (rtspHeader->empty()) { sp< List<String> > resultCode = line.split(" "); if (resultCode->size() < 2) { delete rtspHeader; rtspHeader = NULL; return false; } else { List<String>::iterator itr = resultCode->begin(); if (itr->trim() != "RTSP/1.0") { delete rtspHeader; rtspHeader = NULL; return false; } else { ++itr; (*rtspHeader)[String("ResultCode")] = itr->trim(); } } } else { ssize_t pos = line.indexOf(":"); String key, value; if (pos >= 0) { key = line.substr(0, pos).trim().toLowerCase(); value = line.substr(pos + 1).trim(); } if (!value.isNull()) { (*rtspHeader)[key] = value; } } } } while (resultCode && line.size() > 0); if (!resultCode) { delete rtspHeader; rtspHeader = NULL; return false; } return true; }
void Terminal::parse_line(String line) { int spacer = line.indexOf(" "); String command = line.substring(0,spacer); if(command == "pid") { if(line.length() > (spacer + 1)) { String rest = line.substring(spacer+1); manage_pid(rest); } else { get_help(); } } else if(command == "online") { int cur_time = (millis() - global_info.start_time) / 1000; Serial1.print("Time from start : "); Serial1.println(cur_time); } else { get_help(); } }
//friends! void receiveSmartString(String message) { message.trim(); if(Everything::debug && message.length()>1) { Serial.print(F("Everything: Received: ")); Serial.println(message); } if (message.length() > 1) //ignore empty string messages from the ST Hub { Device *p = Everything::getDeviceByName(message.substring(0, message.indexOf(' '))); if (p != 0) { p->beSmart(message); //pass the incoming SmartThings Shield message to the correct Device's beSmart() routine } } }
// logo color purple, green int startDualColorAnimation(String colorNames) { int commaPos = colorNames.indexOf(","); String centerColorName = colorNames.substring(0, commaPos); String arrowColorName = colorNames.substring(commaPos + 1); centerColorName.trim(); Color centerColor = colorFromName(centerColorName); arrowColorName.trim(); Color arrowColor = colorFromName(arrowColorName); Animation *anim = new DualColorAnimation{context, centerColor, arrowColor, CLOUD_ANIMATION_TIME}; abortCurrentAnimations(); addAnimation(anim); return 0; }
bool Esp8266::setMode(char mode) { clearBuf(); write("AT+CWMODE="+String(mode)); delay(200); String str = readData(); if (str.indexOf("no change") > 0) return true; else { if (reset()) { this->wifiMode = mode; return true; } else { return false; } } }
bool NexUpload::_setUploadBaudrate(uint32_t baudrate) { String string = String(""); String cmd = String(""); String filesize_str = String(_unuploadByte, 10); String baudrate_str = String(baudrate, 10); cmd = "whmi-wri " + filesize_str + "," + baudrate_str + ",0"; this->sendCommand(""); this->sendCommand(cmd.c_str()); HAL::delayMilliseconds(50); nexSerial.begin(baudrate); this->recvRetString(string, 500); if(string.indexOf(0x05) != -1) return 1; return 0; }
void MEDP::execute(String message) { message = removeProtocolIdentifier(message); /** This while loop splits the message and extract every single instruction */ int start = 0; int end = 0; while (end != -1) { end = message.indexOf(MEDP::COMMANDS_DIVIDER_CHAR, ++start); String command; command = (end != -1) ? message.substring(start, end) : message.substring(start); start = end; executeCommand(command); } }
void S_TimedRelay::beSmart(const String &str) { String s = str.substring(str.indexOf(' ') + 1); if (st::Device::debug) { Serial.print(F("S_TimedRelay::beSmart s = ")); Serial.println(s); } if (s == F("on")) { m_bCurrentState = HIGH; //Save time turned on m_lTimeChanged = millis(); //Increment number of active timers if (!m_bTimerPending) { st::Everything::bTimersPending++; m_bTimerPending = true; } //Queue the relay status update the ST Cloud Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); //Set the initial count to zero m_iCurrentCount = 0; } else if (s == F("off")) { m_bCurrentState = LOW; //Decrement number of active timers if (st::Everything::bTimersPending > 0) st::Everything::bTimersPending--; m_bTimerPending = false; //Queue the relay status update the ST Cloud Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off"))); //Reset the count to the number of required cycles to prevent Update() routine from running if someone sends an OFF command m_iCurrentCount = m_iNumCycles; } //update the digital output writeStateToPin(); }
void Database::executeUpdate (const String& sql, const QueryArgs& args) { if (nullptr == db) return; char* err = nullptr; int res = SQLITE_ERROR; if (! sql.containsChar ('?')) { res = sqlite3_exec (db, sql.toRawUTF8(), ksp1_query_var, this, &err); } else { String query; int start = 0; int end = 0; for (const var& val : args) { const bool isString = val.isString(); end = sql.indexOf (start, "?"); query << sql.substring (start, end); if (isString) query << "'"; query << val.toString(); if (isString) query << "'"; start = end + 1; } query << sql.substring (start); res = sqlite3_exec (db, query.toRawUTF8(), ksp1_query_var, this, &err); } if (err) { DBG ("SQL Error: " << err); sqlite3_free (err); err = nullptr; } }
void loadConfigFile(const String& filename, ConfigMap& rval) { std::ifstream file(filename.c_str()); if (!file) { OW_THROW(ConfigException, Format("Unable to read config" " file: %1", filename).c_str()); } String line; int lineNum = 0; while (file) { lineNum++; line = String::getLine(file); if (!line.empty()) { // If comment line, ignore if (line[0] == '#' || line[0] == ';') { continue; } size_t idx = line.indexOf('='); if (idx != String::npos) { if (idx + 1 < line.length()) { String itemValue = line.substring(idx + 1).trim(); if (!itemValue.empty()) { String item = line.substring(0, idx).trim(); rval[item].push_back(ItemData(filename, itemValue)); } } } else { OW_THROW(ConfigException, Format("Error in config file:" " %1 at line %2.\n Line is %3", filename, lineNum, line).c_str()); } } } }
/************************************************************************* //send data in multiple connection mode id: <id>(0-4) str: string of message return: true - successfully false - unsuccessfully ***************************************************************************/ boolean WIFI::Send(byte id, String str) { if (!wifiPresent) return false; print("AT+CIPSEND="); print(String(id)); print(","); println(String(str.length())); unsigned long start; start = millis(); bool found; while (millis()-start<5000) { if(_cell.find(">")==true ) { found = true; break; } } if(found) _cell.print(str); else { closeMux(id); return false; } String data; start = millis(); while (millis()-start<5000) { if(_cell.available()>0) { char a =_cell.read(); data=data+a; } if (data.indexOf("SEND OK")!=-1) { return true; } } return false; }
HttpParseResult HttpRequest::parsePostData(HttpServer *server, pbuf* buf) { int start = 0; tmpbuf += NetUtils::pbufStrCopy(buf, 0, buf->tot_len); // First enter if (requestPostParameters == NULL) { int headerEnd = NetUtils::pbufFindStr(buf, "\r\n\r\n"); if (headerEnd == -1) return eHPR_Failed; if (headerEnd + getContentLength() > NETWORK_MAX_HTTP_PARSING_LEN) { debugf("NETWORK_MAX_HTTP_PARSING_LEN"); return eHPR_Failed; } requestPostParameters = new HashMap<String, String>(); start = headerEnd + 4; tmpbuf = tmpbuf.substring(start, tmpbuf.length()); } //parse if it is FormUrlEncoded - otherwise keep in buffer String contType = getContentType(); contType.toLowerCase(); if (contType.indexOf(ContentType::FormUrlEncoded) != -1) { tmpbuf = extractParsingItemsList(tmpbuf, 0, tmpbuf.length(), '&', ' ', requestPostParameters); } postDataProcessed += buf->tot_len - start ; if (postDataProcessed == getContentLength()) { return eHPR_Successful; } else if (postDataProcessed > getContentLength()) { //avoid bufferoverflow if client announces non-correct content-length debugf("NETWORK_MAX_HTTP_PARSING_LEN"); return eHPR_Failed; } else { return eHPR_Wait; } }
void Orion::Get(const String &_id, const String &_type){ String request = "GET /v1/contextEntities/type/" + _type + "/id/" + _id + "/ HTTP/1.1\r\n"; request += "Host: ws-fiware.tidnode.cl:1026\r\n"; request += "User-Agent: Arduino/1.0\r\n"; request += "Accept: application/json\r\n"; request += "Content-Type: application/json\r\n"; request += "\r\n"; String cipSend = "AT+CIPSEND=" + String(request.length()) + "\r\n"; String respuesta = ""; esp8266.println(cipSend); delay(100); unsigned long time = millis(); int flag = 0; if (esp8266.find(">")){ Serial.println(F("Listo Para enviar GET")); flag = 1; } else { Serial.println(F("Error: No se puede enviar Peticion GET")); } if(flag == 1){ esp8266.println(request); time = millis(); while ( millis() - time < 5000){ while (esp8266.available()) { char c = esp8266.read(); respuesta += c; } } Serial.println(respuesta); if (respuesta.indexOf("\"OK\"")!=-1){ respuesta +="\r\n"; Serial.println(F("Peticion GET enviada con exito")); } } Serial.flush(); }
void SystemConfigHelperClass::handleBrightness(String params) { TrafficLightBrightness newParam; int startInd = 0; int delimeterInd = 0; while (delimeterInd != -1) { delimeterInd = params.indexOf(",", startInd); String val; if (delimeterInd == -1) { val = params.substring(startInd + 2); } else { val = params.substring(startInd + 2, delimeterInd); } char typeOfLed = params.charAt(startInd); byte percVal = val.toInt(); percVal = percVal > 100 || percVal < 0 ? 0 : percVal; switch (typeOfLed) { case 'r': newParam.red = percVal; break; case 'y': newParam.yellow = percVal; break; case 'g': newParam.green = percVal; break; } startInd = delimeterInd + 1; } TrafficLightBrightness oldParam = SystemConfig.getTrafficLightBrightness(); if (oldParam.green != newParam.green || oldParam.red != newParam.red || oldParam.yellow != newParam.yellow) { SystemConfig.updateTrafficLightBrightness(newParam); } }
void BuffImplementation::parseSkillModifierString(const String& modifierstring) { StringTokenizer tokenizer(modifierstring); tokenizer.setDelimeter(";"); while (tokenizer.hasMoreTokens()) { String token; tokenizer.getStringToken(token); int tokpos = token.indexOf("="); if (tokpos == -1) continue; String modname = token.subString(0, tokpos); float value = Float::valueOf(token.subString(tokpos + 1, token.length())); skillModifiers.put(modname, (int) value); } }