// Parse a quoted string in the response fields and copy its value (without quotes) // to the specified character array (v). Only up to maxlen characters are copied // into the result buffer, so make sure to pass a large enough buffer to handle the // response. boolean FonaSMS::parseReplyQuoted(const __FlashStringHelper *toreply, char *v, int maxlen, char divider, uint8_t index) { uint8_t i=0, j; // Verify response starts with toreply. char *p = strstr_P(replybuffer, (prog_char*)toreply); if (p == 0) return false; p+=strlen_P((prog_char*)toreply); // Find location of desired response field. for (i=0; i<index;i++) { // increment dividers p = strchr(p, divider); if (!p) return false; p++; } // Copy characters from response field into result string. for(i=0, j=0; j<maxlen && i<strlen(p); ++i) { // Stop if a divier is found. if(p[i] == divider) break; // Skip any quotation marks. else if(p[i] == '"') continue; v[j++] = p[i]; } // Add a null terminator if result string buffer was not filled. if (j < maxlen) v[j] = '\0'; return true; }
bool ESP8266proConnection::internalSend(const __FlashStringHelper* dataP, const char* dataR) { bool ok; int len = 0; if (dataP != NULL) len += strlen_P(reinterpret_cast<PGM_P>(dataP)); if (dataR != NULL) len += strlen(dataR); uint8_t id = getId(); if (id == ESP_INVALID_CONNECTION) return false; parent.execute((String)"AT+CIPSEND=" + id + "," + len, eCEM_NoResponse); // Write request data if (dataP != NULL) parent.writeString(dataP); ok = parent.execute(dataR!= NULL ? dataR : "", eCEM_NoLineBreak); if (!ok) return false; // Wait "SEND OK" response for (uint8_t i = 0; i < 3; i++) { if (getId() == ESP_INVALID_CONNECTION) return false; // Already closed.. if (parent.getState() == ePS_Completed) return true; if (!parent.execute("", eCEM_NoLineBreak)) return false; } return false; }
String & String::operator = (const __FlashStringHelper *pstr) { if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); else invalidate(); return *this; }
int ThingSpeak::Channel::post(const char* entry, str_P status) { // Use an iostream for the http post request Socket* sock = m_client->m_sock; IOStream page(sock); size_t length = strlen(entry); if (status != NULL) length += strlen_P(status) + 8; // Connect to the server int res = m_client->connect(); if (res < 0) goto error; // Generate the http post request with entry and status page << PSTR("POST /update HTTP/1.1") << CRLF << PSTR("Host: api.thingspeak.com") << CRLF << PSTR("Connection: close") << CRLF << PSTR("X-THINGSPEAKAPIKEY: ") << m_key << CRLF << PSTR("Content-Type: application/x-www-form-urlencoded") << CRLF << PSTR("Content-Length: ") << strlen(entry) << CRLF << CRLF << (char*) entry; if (status != NULL) page << PSTR("&status=") << status; sock->flush(); res = 0; error: // Disconnect and close the socket. Reopen for the next post (if any) m_client->disconnect(); return (res); }
void uecmd_sender_net_main(void) { if (uip_newdata()) { if(ucallback) { ucallback(uip_appdata, uip_len); } send_data = NULL; } if (send_data) { resend_counter --; if (!resend_counter) { if(ucallback) { ucallback(NULL, 0); } send_data = NULL; return; } uint8_t len = strlen_P(send_data); memcpy_P(uip_appdata, send_data, len); uip_slen = len; /* build a new connection on the stack */ ecmd_conn->rport = HTONS(2701); uip_udp_conn = ecmd_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); } }
static unsigned short function_file_stats(char* buffer, int bufsize) { unsigned short len = 0; // list as many files as fit into the buffer for (int i = 0; len < bufsize; i++) { // name fo the file char* name = httpd_fs_getName(i); // break if there is no file left anmyore if (name == 0) { break; } // we cant simply pass the filename to snprintf because it is in // program memory and snprintf requires strings in RAM. strncpy_P(buffer + len, file_stat_formatter1, bufsize - len); len += sizeof (file_stat_formatter1); if (len < bufsize - len) { char* name = httpd_fs_getName(i); strncpy_P(buffer + len, name, bufsize - len); len += strlen_P(name); } if (len < bufsize - len) { int count = httpd_fs_getCount(i); len += snprintf_P(buffer + len, bufsize - len, file_stat_formatter2, count); } } return len; }
byte ESP8266_Simple::sendCommand(const __FlashStringHelper *cmd) { char cmdBuffer[strlen_P((const char *)cmd)+1]; strcpy_P(cmdBuffer, (const char *) cmd); return this->sendCommand(cmdBuffer, NULL, 0); }
/** * Get all named pins in a list (separator is the newline character). * Warning: this funtion return only that much entries that fit into * the output buffer. * */ int16_t parse_cmd_pin_list(char *cmd, char *output, uint16_t len) { uint16_t help_len = 0; uint8_t counter = 0; while (1) { /* get named-pin from array */ const char *text = (const char *)pgm_read_word(&portio_pincfg[ counter++ ].name); /* leave loop if end of array is reached or output buffer is too small */ if (text == NULL) break; uint8_t lineLength = strlen_P (text); if (help_len+lineLength+1>len) break; memcpy_P (output, text, lineLength); output += lineLength; /* add newline character */ *output = '\n'; ++output; help_len += lineLength+1; } /* Remove last newline character */ if (help_len) --help_len; return ECMD_FINAL(help_len); }
char* HTTP::checkHeader(char *buff, prog_char *header) { int i; for (i=0;i<strlen_P(header);i++) {if (buff[i]!=pgm_read_byte(&header[i])) return NULL;} return &buff[i]; }
/* * Version for pages made by multiple modules (to optimize prog space) * amodule: array of PROGMEM module; nm: its dimension */ void HTTP::sendDynResponse(int sk,prog_char* amodule[],uint8_t nm,int npar,char *param[]) { if (amodule==NULL) {respERR(sk);return;} if ((param==NULL)|(npar<=0)) {sendResponse(sk,amodule,nm);return;} startLongResponse(sk); int k; for (k=0;k<nm;k++) { prog_char* page=amodule[k]; if (page==NULL){endLongResponse(sk);return;} int len=strlen_P(page); int i,lp=0,np=0,pos=0; char c; if ((param==NULL)|(npar<=0)) {sendResponse(sk,page);return;} while(pos<len) { lp=0; for(i=pos;i<len;i++) { lp++;c=pgm_read_byte(page+i); if (c=='@') { if ((np<npar)&(param[np]!=NULL)) {sendChunkResponse(sk,page+pos,lp,param[np]);np++;break;} else np++; } if ((lp>=MAXC)&(c!='@')) {sendChunkResponse(sk,page+pos,lp,NULL);break;} if (i==len-1)sendChunkResponse(sk,page+pos,lp,NULL); } pos=pos+lp; } } endLongResponse(sk); }
/* * Sends dynamically assembled page substituting tag @ with strings found in * array param[] (array of string: array of char array i.e. array of pointer to * char array) * npar is the dimension of this array */ void HTTP::sendDynResponse(int sk,prog_char page[],int npar,char *param[]) { int len=strlen_P(page); int i,lp=0,np=0,pos=0; char c; if ((param==NULL)|(npar<=0)) {sendResponse(sk,page);return;} startLongResponse(sk); while(pos<len) { lp=0; for(i=pos;i<len;i++) { lp++;c=pgm_read_byte(page+i); if (c=='@') { if ((np<npar)&(param[np]!=NULL)) {sendChunkResponse(sk,page+pos,lp,param[np]);np++;break;} else np++; } if ((lp>=MAXC)&(c!='@')) {sendChunkResponse(sk,page+pos,lp,NULL);break;} if (i==len-1)sendChunkResponse(sk,page+pos,lp,NULL); } pos=pos+lp; } endLongResponse(sk); }
// Equivalent to Arduino Stream find() function, but with search string in // flash/PROGMEM rather than RAM-resident. Returns true if string found // (any further pending input remains in stream), false if timeout occurs. // Can optionally pass NULL (or no argument) to read/purge the OK+CR/LF // returned by most AT commands. The ipd flag indicates this call follows // a CIPSEND request and might be broken into multiple sections with +IPD // delimiters, which must be parsed and handled (as the search string may // cross these delimiters and/or contain \r or \n itself). boolean Adafruit_ESP8266::find(Fstr *str, boolean ipd) { uint8_t stringLength, matchedLength = 0; int c; boolean found = false; uint32_t t, save; uint16_t bytesToGo = 0; if(ipd) { // IPD stream stalls really long occasionally, what gives? save = receiveTimeout; setTimeouts(ipdTimeout); } if(str == NULL) str = F("OK\r\n"); stringLength = strlen_P((Pchr *)str); if(debug && writing) { debug->print(F("<--- '")); writing = false; } for(t = millis();;) { if(ipd && !bytesToGo) { // Expecting next IPD marker? if(find(F("+IPD,"))) { // Find marker in stream for(;;) { if((c = stream->read()) > 0) { // Read subsequent chars... if(debug) debug->write(c); if(c == ':') break; // ...until delimiter. bytesToGo = (bytesToGo * 10) + (c - '0'); // Keep count t = millis(); // Timeout resets w/each byte received } else if(c < 0) { // No data on stream, check for timeout if((millis() - t) > receiveTimeout) goto bail; } else goto bail; // EOD on stream } } else break; // OK (EOD) or ERROR } if((c = stream->read()) > 0) { // Character received? if(debug) debug->write(c); // Copy to debug stream bytesToGo--; if(c == pgm_read_byte((Pchr *)str + matchedLength)) { // Match next byte? if(++matchedLength == stringLength) { // Matched whole string? found = true; // Winner! break; } } else { // Character mismatch; reset match pointer+counter matchedLength = 0; } t = millis(); // Timeout resets w/each byte received } else if(c < 0) { // No data on stream, check for timeout if((millis() - t) > receiveTimeout) break; // You lose, good day sir } else break; // End-of-data on stream } bail: // Sorry, dreaded goto. Because nested loops. if(debug) debug->println('\''); if(ipd) setTimeouts(save); return found; }
void lcd12864st_print_P(uint8_t x, uint8_t y, const char *str) { if ((y >= LCD12864ST_LINES) || (x >= LCD12864ST_COLUMNS)) return; char *data = lcd12864st_buffer + y * LCD12864ST_COLUMNS + x; memcpy_P(data, str, MIN((size_t) LCD12864ST_COLUMNS - x, strlen_P(str))); }
//Создать текст ошибки void CreateError(const char *str_P){ u08 len = strlen_P(str_P); ErrorText = malloc(len+1); if (ErrorText != NULL){ strcpy_P(ErrorText, str_P); } CmdStartClear(); }
void lcd_info_screen(menuFunc_t cancelMenu, menuFunc_t callbackOnCancel, const char* cancelButtonText, uint8_t direction) { lcd_lib_encoder_pos = 0; if (lcd_lib_button_pressed && IS_SELECTED_MAIN(0)) { if (cancelMenu) lcd_change_to_menu(cancelMenu,MAIN_MENU_ITEM_POS(0), direction); if (callbackOnCancel) callbackOnCancel(); } lcd_basic_screen(); if (!cancelButtonText) cancelButtonText = LS(PSTR("CANCEL"), PSTR("\xD8" "\x80" "\xD9" "\x80" ), PSTR("\xFF" "\x82" "\xC6" "\x82" )) ; switch (languageType) { case LANGUAGE_CHINESE: case LANGUAGE_KOREAN: if (IS_SELECTED_MAIN(0)) { lcd_lib_draw_box(3+3, 54-3+1, 63+61-3, 64-1); lcd_lib_set(3+4, 54-3+2, 63+61-4, 64-2); lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 56-3, cancelButtonText); }else{ lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 56-3, cancelButtonText); } break; case LANGUAGE_ENGLISH: if (IS_SELECTED_MAIN(0)) { lcd_lib_draw_box(3+3, 54+1, 63+61-3, 64-1); lcd_lib_set(3+4, 54+2, 63+61-4, 64-2); lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 56, cancelButtonText); }else{ lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 56, cancelButtonText); } break; default: break; } }
void ELClientMqtt::subscribe(const __FlashStringHelper* topic, uint8_t qos) { uint16_t crc; crc = _elc->Request(CMD_MQTT_SUBSCRIBE, 0, 0, 3); crc = _elc->Request(crc, (uint8_t*)&remote_instance, 4); crc = _elc->Request(crc, topic, strlen_P((const char*)topic)); crc = _elc->Request(crc, (uint8_t*)&qos, 1); _elc->Request(crc); }
unsigned short fill_buf(void* blk) { uint16_t webpage_len; char int_string[4]; webpage_len = (strlen_P(webpage)>uip_mss())?uip_mss():strlen_P(webpage); xSerialPrintf_P(PSTR("fill_buf : %s\r\n"), webpage); memcpy_P(uip_appdata, webpage, webpage_len); sprintf(int_string, "%X", mfg_id[0]); memcpy(&uip_appdata[104], int_string, 2); sprintf(int_string, "%X", mfg_id[1]); memcpy(&uip_appdata[108], int_string, 2); return webpage_len; }
void GuiPainter::box(const char* text, ArrowType_t arrow) { uint8_t save_color_index = m_impl.getColorIndex(); //Print box setColorIndex(1); m_impl.drawBox(0, ((screen_height - 1) - (box_height - 1)), box_width, box_height); //Set font and color setFont(FontType_t::BODY_FONT); setColorIndex(0); //Print arrows switch (arrow) { case LEFT: setPrintPos(2, ((screen_height - 1) - (max_font_height - 1))); print("<"); break; case RIGHT: setPrintPos(((screen_width - 1) - 2 - (max_font_width - 1)), ((screen_height - 1) - (max_font_height - 1))); print(">"); break; case BOTH: setPrintPos(2, ((screen_height - 1) - (max_font_height - 1))); print("<"); setPrintPos(((screen_width - 1) - 2 - (max_font_width - 1)), ((screen_height - 1) - (max_font_height - 1))); print(">"); break; case NONE: break; } //Print text label if ( (text != NULL) && (strlen_P(text) > 0) ) { setPrintPos( (screen_width - strlen_P(text) * max_font_width) / 2, ((screen_height - 1) - (max_font_height - 1))); print_P(text); } coordinateYEnd(51); setColorIndex(save_color_index); }
Publish::Publish(String topic, const __FlashStringHelper* payload) : Message(PUBLISH), _topic(topic), _payload_len(strlen_P((PGM_P)payload)), _payload(new uint8_t[_payload_len + 1]), _payload_mine(true) { strncpy((char*)_payload, (PGM_P)payload, _payload_len); }
void vDeviceTestTxHello (void) { xTxLen = strlen_P (pcHelloWorld) + 1; memcpy_P (ucBuffer, pcHelloWorld, xTxLen); printf_P (PSTR ("Test de transmission %s\n"), ucBuffer); prvvDeviceTestTx (); }
void PusherClient::getPusherInfoItem(int index, String& text) { char* ptr = (char*)pgm_read_word(&(pusherInfos[index])); int len = strlen_P(ptr); char buffer[len+1]; strcpy_P(buffer, ptr); text = buffer; }
int OSC_effectiveStringLength(char PROGMEM *string) { int len = strlen_P(string) + 1; /* We need space for the null char. */ /* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */ if ((len % STRING_ALIGN_PAD) != 0) { len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD); } return len; }
extern "C" char *strncpy_P(char * dest, size_t max_len, const char * src_P) { int len = strlen_P(src_P); if(len >= max_len) len = max_len-1; memcpy_P(dest, src_P, len); dest[len] = 0; return dest; }
String & String::append(const __FlashStringHelper *pgmstr) { unsigned int length = strlen_P((const char PROGMEM *)pgmstr); unsigned int newlen = len + length; if (length == 0 || !reserve(newlen)) return *this; strcpy_P(buffer + len, (const char PROGMEM *)pgmstr); len = newlen; return *this; }
uint8_t CDC_Device_SendString_P(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, const char* const String) { if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return ENDPOINT_RWSTREAM_DeviceDisconnected; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address); return Endpoint_Write_PStream_LE(String, strlen_P(String), NULL); }
void Devices::flash_println(Stream* stream, const prog_char *ptr) { int32_t len = strlen_P((char*)ptr); // char buf[len]; // strcpy_P(buf, (char*)ptr); // stream->println(buf); Devices::flash_print(stream, ptr); stream->println(); }
//------------------------------------------------------------------------------ void testVerify_P(char* result, PGM_P expect) { testOut->write('"'); testOut->print(result); testOut->print("\",\""); print_P(testOut, expect); testOut->write('"'); uint8_t n = strlen(result) + strlen_P(expect) + 5; testResult(!strcmp_P(result, expect), n); }
//------------------------------------------------------------------------------ void ostream::putPgm(const pgm &arg) { char *str = arg.ptr; int n = strlen_P(str); fill_not_left(n); for (uint8_t c; (c = pgm_read_byte(str)); str++) { putch(c); } do_fill(n); }
/** * Adds the input PROGMEM string reference to linebuffer (if it has space for it) */ void BMDSmartViewClient::_addToLineBuffer_P(const char *str) { // PROGMEM pointer if (_linebufferPointer+strlen_P(str)<BMDSmartViewClient_BUFFERSIZE) { strcpy_P(_linebuffer+_linebufferPointer, str); _linebufferPointer+=strlen_P(str); } else Serial.println(F("_addToLineBuffer_P ERROR")); /* uint8_t val; while (true) { val = pgm_read_byte(str); if (!val) break; if (_linebufferPointer<BMDSmartViewClient_BUFFERSIZE-1) { _linebuffer[_linebufferPointer] = val; _linebufferPointer++; } str++; } */ }
MenuItemStruct::MenuItemStruct(PGM_P key_pstr, PGM_P help_pstr, Menu * submenu_ptr, MenuCommand_Callback cmd_ptr) { key = key_pstr; help = help_pstr; subMenu = submenu_ptr; command = cmd_ptr; key_size = strlen_P(key); }