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; }
static void jabber_main(void) { if (uip_aborted() || uip_timedout()) { JABDEBUG("connection aborted\n"); jabber_conn = NULL; } if (uip_closed()) { JABDEBUG("connection closed\n"); jabber_conn = NULL; } if (uip_connected()) { JABDEBUG("new connection\n"); STATE->stage = JABBER_OPEN_STREAM; STATE->sent = JABBER_INIT; #ifdef JABBER_STARTUP_MESSAGE_SUPPORT strncpy_P(STATE->target, PSTR(CONF_JABBER_BUDDY), sizeof(STATE->target)); strncpy_P(STATE->outbuf, jabber_startup_text, sizeof(STATE->outbuf)); STATE->action = JABBER_ACTION_MESSAGE; #endif /* JABBER_STARTUP_MESSAGE_SUPPORT */ } if (uip_acked() && STATE->stage == JABBER_CONNECTED) { STATE->action = JABBER_ACTION_NONE; *STATE->outbuf = 0; } if (uip_newdata() && uip_len) { /* Zero-terminate */ ((char *) uip_appdata)[uip_len] = 0; JABDEBUG("received data: %s\n", uip_appdata); if (jabber_parse()) { uip_close(); /* Parse error */ return; } } if (uip_rexmit()) jabber_send_data(STATE->stage, STATE->action); else if ((STATE->stage > STATE->sent || STATE->stage == JABBER_CONNECTED) && (uip_newdata() || uip_acked() || uip_connected())) jabber_send_data(STATE->stage, STATE->action); else if (STATE->stage == JABBER_CONNECTED && uip_poll() && STATE->action) jabber_send_data(STATE->stage, STATE->action); }
/* write a structure format to the log */ void DataFlash_Class::Log_Fill_Format(const struct LogStructure *s, struct log_Format &pkt) { memset(&pkt, 0, sizeof(pkt)); pkt.head1 = HEAD_BYTE1; pkt.head2 = HEAD_BYTE2; pkt.msgid = LOG_FORMAT_MSG; pkt.type = PGM_UINT8(&s->msg_type); pkt.length = PGM_UINT8(&s->msg_len); strncpy_P(pkt.name, s->name, sizeof(pkt.name)); strncpy_P(pkt.format, s->format, sizeof(pkt.format)); strncpy_P(pkt.labels, s->labels, sizeof(pkt.labels)); }
static inline uint8_t otoa(uint16_t val, char* buff) { struct Operand op; DECODE_OP(val, &op); if(op.type == OP_REGISTER) { strncpy_P(buff, Register[op.reg], REG_LEN); } else if(op.type == OP_PORT) { strncpy_P(buff, Port[op.port], PORT_LEN); } else if(op.type == OP_LITERAL) { itoa(op.litValue, buff, 10); } return strlen(buff); }
void ESP8266_Simple::getErrorMessage(byte responseCode, char *bufferWithMinLength50Char) { memset(bufferWithMinLength50Char, 0, 50); switch(responseCode) { case ESP8266_ERROR: strncpy_P(bufferWithMinLength50Char, PSTR("General Error"), 49); break; case ESP8266_TIMEOUT: strncpy_P(bufferWithMinLength50Char, PSTR("Timeout Waiting For Response"), 49); break; case ESP8266_OVERFLOW: strncpy_P(bufferWithMinLength50Char, PSTR("Overflow In Serial Buffer"), 49); break; case ESP8266_BUSY: strncpy_P(bufferWithMinLength50Char, PSTR("Device Is Busy"), 49); break; case ESP8266_READY: strncpy_P(bufferWithMinLength50Char, PSTR("Device issued \"ready\" unexpectedly (rebooted)"), 49); break; } }
static unsigned short function_tcp_connections(char* buffer, int bufsize) { unsigned short len = 0; // list as many connections as fit into the buffer for (int i = 0; len < bufsize && i<UIP_CONF_MAX_CONNECTIONS; i++) { len+=snprintf_P(buffer+len, bufsize-len, tcp_conn_formatter1, htons(uip_conns[i].lport), htons(uip_conns[i].ripaddr[0]) >> 8, htons(uip_conns[i].ripaddr[0]) & 0xff, htons(uip_conns[i].ripaddr[1]) >> 8, htons(uip_conns[i].ripaddr[1]) & 0xff, htons(uip_conns[i].rport)); switch (uip_conns[i].tcpstateflags & UIP_TS_MASK) { case UIP_CLOSED: strncpy_P(buffer+len,tcp_closed,bufsize-len); len+=sizeof(tcp_closed)-1; break; case UIP_SYN_RCVD: strncpy_P(buffer+len,tcp_syn_rcvd,bufsize-len); len+=sizeof(tcp_syn_rcvd)-1; break; case UIP_SYN_SENT: strncpy_P(buffer+len,tcp_syn_sent,bufsize-len); len+=sizeof(tcp_syn_sent)-1; break; case UIP_ESTABLISHED: strncpy_P(buffer+len,tcp_established,bufsize-len); len+=sizeof(tcp_established)-1; break; case UIP_FIN_WAIT_1: strncpy_P(buffer+len,tcp_fin_wait_1,bufsize-len); len+=sizeof(tcp_fin_wait_1)-1; break; case UIP_FIN_WAIT_2: strncpy_P(buffer+len,tcp_fin_wait_2,bufsize-len); len+=sizeof(tcp_fin_wait_1)-1; break; case UIP_CLOSING: strncpy_P(buffer+len,tcp_closing,bufsize-len); len+=sizeof(tcp_closing); break; case UIP_TIME_WAIT: strncpy_P(buffer+len,tcp_time_wait,bufsize-len); len+=sizeof(tcp_time_wait)-1; break; case UIP_LAST_ACK: strncpy_P(buffer+len,tcp_last_ack,bufsize-len); len+=sizeof(tcp_last_ack)-1; break; } len+=snprintf_P(buffer+len, bufsize-len, tcp_conn_formatter2, uip_conns[i].nrtx, uip_conns[i].timer, (uip_outstanding(&uip_conns[i])) ? '*' : ' ', (uip_stopped(&uip_conns[i])) ? '!' : ' '); } return len; }
void menu_draw(menu_t *menu, u8g_t *u8g) { uint8_t i, h; static char ramstr[32]; menu_buttons_t *b; u8g_uint_t w, d; if(!menu) return; // Calculate text size u8g_SetFont(u8g, u8g_font_5x7); u8g_SetFontRefHeightText(u8g); u8g_SetFontPosTop(u8g); h = u8g_GetFontAscent(u8g)-u8g_GetFontDescent(u8g); w = u8g_GetWidth(u8g); for( i = 0;; i++ ) { // draw all menu items // Copy string from program memory to a work string in RAM strncpy_P(ramstr, (PGM_P)pgm_read_word(&(menu->strings[i])), sizeof(ramstr)); ramstr[31] = 0; // Zero length string marks end of string list. if(!ramstr[0]) break; // Get its length in pixels d = (w-u8g_GetStrWidth(u8g, ramstr))/2; // Set foreground color u8g_SetDefaultForegroundColor(u8g); // If item selected if ( i == menu->selected ) { // current selected menu item u8g_DrawBox(u8g, 0, i*h+1, w, h); // draw cursor bar u8g_SetDefaultBackgroundColor(u8g); } // Display the string u8g_DrawStr(u8g, d, i*h, ramstr); } // Remember menu item count menu->item_count = i; // Ensure text and background are set back to normal u8g_SetDefaultForegroundColor(u8g); // If there are soft buttons, draw them here if(menu->buttons){ for(b = menu->buttons; b; b = b->next){ strncpy_P(ramstr, b->label, sizeof(ramstr)); ramstr[31] = 0; u8g_DrawStr(u8g, b->col, b->row, ramstr); } } }
/************************************************************************************************** ** Process an incoming packet */ void KBUS_process_command(const KBUS_PACKET_t *cmd, KBUS_PACKET_t *res) { res->command = cmd->command | 0x80; res->length = 0; memset(&res->data, 0, KBUS_PACKET_DATA_SIZE); if (cmd->length > KBUS_PACKET_DATA_SIZE) return; switch(cmd->command) { case KCMD_LOOPBACK: memcpy(&res->data, &cmd->data, cmd->length); res->length = cmd->length; break; case KCMD_READ_STRING: if (cmd->data[0] == KSTRING_DEVICE_NAME) strncpy_P((char *)&res->data, PSTR(USB_DEVICE_PRODUCT_NAME), KBUS_PACKET_DATA_SIZE); else if (cmd->data[0] == KSTRING_MANUFACTURER) strncpy_P((char *)&res->data, PSTR(USB_DEVICE_MANUFACTURE_NAME), KBUS_PACKET_DATA_SIZE); else if (cmd->data[0] == KSTRING_SERIAL_NUMBER) strncpy((char *)&res->data, (char *)USB_serial_number, KBUS_PACKET_DATA_SIZE); // otherwise empty string res->length = strnlen((char *)&res->data, KBUS_PACKET_DATA_SIZE); break; case KCMD_READ_VID_PID: *(uint16_t *)&res->data[0] = USB_DEVICE_VENDOR_ID; *(uint16_t *)&res->data[2] = USB_DEVICE_PRODUCT_ID; break; case KCMD_ENTER_BOOTLOADER: { uint32_t load = 0x4c4f4144; // "LOAD" EEP_DisableMapping(); EEP_WriteBuffer(&load, sizeof(load), 31); _delay_ms(100); // ensure all writes have definitely finished HW_CCPWrite(&RST.CTRL, RST_SWRST_bm); // reset MCU into bootloader NOP(); break; } default: res->command = 0; // unknown command response break; } }
/* * Write the configuration parameters to EEPROM */ void ConfigParms::commit(bool forced) { if (_stationName[0] == '\0') { // It was probably not initialized. return; } if (!forced && !needCommit) { return; } //DIAGPRINTLN(F("ConfigParms::commit")); // Fill in the magic and CRC, and write to EEPROM 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]; strncpy_P((char *)buffer, magic, magic_len); memcpy(buffer + magic_len, (uint8_t *)this, sizeof(*this)); uint16_t crc = crc16_ccitt(buffer, size - crc_size); *(uint16_t *)(buffer + size - crc_size) = crc; //dumpBuffer(buffer, size); eeprom_write_block((const void *)buffer, eepromAddr(), size); needCommit = false; }
void ConfigParms::reset() { //DIAGPRINTLN(F("ConfigParms::reset")); memset(this, 0, sizeof(*this)); // Initialize a few parameters that have default values _b = PARM_B; _s = PARM_S; strncpy_P(_stationName, stationName_Default, sizeof(_stationName) - 1); strncpy_P(_pwssrv, serverName_Default, sizeof(_pwssrv) - 1); _pwsport = serverPort_Default; needCommit = true; }
void lcd_material_reset_defaults() { //Fill in the defaults SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Materials reset"); char buffer[MATERIAL_NAME_LENGTH]; for (int a= 0; a< MATERIAL_PRESETS; a++) { strncpy_P(buffer, (char PROGMEM *) presets[a].name,MATERIAL_NAME_LENGTH); // this will pad out the whole length with 0 as needed. eeprom_write_block(buffer , EEPROM_MATERIAL_NAME_OFFSET(a), MATERIAL_NAME_LENGTH); material_preset temp; memcpy_P((void*) &temp,&presets[a],sizeof (material_preset)); eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(a) ,temp.temperature); eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(a),temp.bed); eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(a) ,temp.fan_speed); eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(a) ,temp.flow); eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(a) ,temp.diameter); } uint8_t e; for(e=0; e<EXTRUDERS; e++) { makeCustomName(e); strcpy(material_name[e],material_name_buf); lcd_material_store_current_material(); } eeprom_write_byte(EEPROM_MATERIAL_COUNT_OFFSET(), MATERIAL_PRESETS); lcd_lib_beep_ext(500,150); lcd_lib_beep_ext(750,100); }
void lcd_setstatuspgm(const char* message, uint8_t level) { if (level >= lcd_status_message_level && NextionON) { strncpy_P(lcd_status_message, message, 30); lcd_status_message_level = level; LedStatus.setText(lcd_status_message); } }
char* Menu::GetBuffer_P(const int StringIndex, char* pBuffer, int bufSize) { strncpy_P(pBuffer, (char*)pgm_read_word(&(WManagement_string_table[StringIndex])), bufSize); return pBuffer; }
void lcd_setstatuspgm(const char* message) { if (lcd_status_message_level > 0) return; strncpy_P(lcd_status_message, message, LCD_WIDTH); lcd_finishstatus(); }
static void jabber_parse_ecmd(char *message) { int16_t remain = sizeof(STATE->outbuf) - 1; int16_t written = 0; while (remain > 0) { int16_t len = ecmd_parse_command(message, STATE->outbuf + written, remain); if (is_ECMD_AGAIN(len)) { len = ECMD_AGAIN(len); written += len; remain -= len; if (remain) { STATE->outbuf[written++] = '\n'; remain--; } continue; } else if (is_ECMD_ERR(len)) { strncpy_P(STATE->outbuf, PSTR("parse error"), sizeof(STATE->outbuf)); len = 11; } written = len; break; } STATE->outbuf[written] = 0; }
void lcd_setstatuspgm(const char* message) { if (lcd_status_message_level > 0) return; strncpy_P(lcd_status_message, message, LCD_WIDTH); lcdDrawUpdate = 2; }
void initBitlash(unsigned long baud) { #if defined(TINY_BUILD) beginSerial(9600); #else beginSerial(baud); #endif #if defined(ARM_BUILD) eeinit(); #endif initTaskList(); vinit(); displayBanner(); #if !defined(TINY_BUILD) // Run the script named "startup" if there is one strncpy_P(lbuf, getmsg(M_startup), STRVALLEN); // get the name "startup" in our cmd buf //if (findKey(lbuf) >= 0) doCommand(lbuf); // look it up. exists? call it. if (findscript(lbuf)) doCommand(lbuf); // look it up. exists? call it. #endif initlbuf(); }
/*------------------------------------------------------------------------------------*/ static int gTR_A00(void) { static s08 inicio = TRUE; // Evento inicial. Solo salta al primer estado operativo. // Inicializo el sistema aqui vTaskDelay( (portTickType)( 500 / portTICK_RATE_MS ) ); strncpy_P(systemVars.dlgIp, PSTR("000.000.000.000\0"),16); systemVars.csq = 0; systemVars.dbm = 0; // // Arranque del equipo if ( inicio ) { // Cuando recien estoy arrancando espero solo 15s para prender. // No importa el pwrSave. inicio = FALSE; pv_configCTimer(TINIT_INIT); } else { pv_configCTimer(TINIT_NORMAL); } // Apago el modem MODEM_HWpwrOff(); snprintf_P( gprs_printfBuff,sizeof(gprs_printfBuff),PSTR("GPRS: Modem Apagado\r\n\0")); u_logPrint(gprs_printfBuff, sizeof(gprs_printfBuff) ); g_printExitMsg("A00\0"); return(gSST_MODEMAPAGADO_01); }
/* ---------------------------------------------------------------------------- * send an ArtDmx packet */ void artnet_sendDmxPacket(void) { static unsigned char sequence = 1; /* prepare artnet Dmx packet */ struct artnet_dmx *msg = (struct artnet_dmx *) &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; memset(msg, 0, sizeof(struct artnet_dmx)); strncpy_P((char *) msg->id, artnet_ID, 8); msg->opcode = OP_OUTPUT; msg->versionH = 0; msg->version = PROTOCOL_VERSION; msg->sequence = sequence++; if (sequence == 0) sequence = 1; msg->physical = 1; msg->universe = ((artnet_subNet << 4) | artnet_inputUniverse); msg->lengthHi = HI8(DMX_STORAGE_CHANNELS); msg->length = LO8(DMX_STORAGE_CHANNELS); for (uint8_t i = 0; i < DMX_STORAGE_CHANNELS; i++) msg->dataStart[i] = get_dmx_channel_slot(artnet_inputUniverse, i, artnet_conn_id); /* send packet to artnet_outputTarget */ artnet_send(&artnet_outputTarget, sizeof(struct artnet_dmx) + DMX_STORAGE_CHANNELS); }
uint8_t ATDev::readLine(char* readBuf, uint16_t readBufSize) { // CR LF to end buffer strncpy_P(m_endBuffer, ATDEV_END_LINE, ATDEV_BUFF_END_SIZE); return this->sendATCmdAbrupt(readBuf, readBufSize); }
size_t SerialUI::print_P(PGM_P message) { char p_buffer[SUI_SERIALUI_PROGMEM_STRING_ABS_MAXLEN + 1]; strncpy_P(p_buffer, message, SUI_SERIALUI_PROGMEM_STRING_ABS_MAXLEN); SUI_PRINTANDRETURN(print, p_buffer); }
void prompt(void) { char buf[IDLEN+1]; // Run the script named "prompt" if there is one else print "> " strncpy_P(buf, getmsg(M_promptid), IDLEN); // get the name "prompt" in our cmd buf if (findscript(buf)) doCommand(buf); else msgp(M_prompt); // else print default prompt }
void drawInstr(uint8_t i) { buffLen = 0; buff[0] = '\0'; uint8_t y = (i * 13) + BOX_TOP + 2; uint8_t x = BOX_LEFT + 2; if(i == GET_REG(REG_PC)) { fg = 0x0000; bg = 0xFFFF; } else { fg = 0xFFFF; bg = 0x0000; } ili9340_fillRect(x-1, y-1, CODE_WIDTH - 1, 14, bg); ili9340_setBackColor(bg); ili9340_setFrontColor(fg); if(labels[i][0] != '\0') { buffLen += strlen(strcpy(buff + buffLen, labels[i])); buff[buffLen++] = ':'; } if(GET_OPC_AT(i) == 0) { buff[buffLen++] = '\0'; ili9340_drawString(x, y, buff); //Just draw the label and continue return; } strncpy_P(buff + buffLen, Instruction[GET_OPC_AT(i)-1], OPC_LEN); buffLen += 3; //All instrctions are 3 bytes long; switch(GET_OPC_AT(i)) { case OPC_MOV: buff[buffLen++] = ' '; buffLen += otoa(GET_B_AT(i), buff + buffLen); buff[buffLen++] = ' '; buffLen += otoa(GET_A_AT(i), buff + buffLen); break; case OPC_ADD: case OPC_SUB: case OPC_JRO: buff[buffLen++] = ' '; buffLen += otoa(GET_A_AT(i), buff + buffLen); break; case OPC_JMP: case OPC_JEZ: case OPC_JNZ: case OPC_JGZ: case OPC_JLZ: { buff[buffLen++] = ' '; struct Operand dst; DECODE_OP(GET_A_AT(i), &dst); buffLen += strlen(strcpy(buff + buffLen, labels[dst.litValue])); break; } default: break; } ili9340_drawString(x, y, buff); }
void prompt(void) { char buf[IDLEN+1]; // Run the script named "prompt" if there is one else print "> " strncpy_P(buf, getmsg(M_promptid), IDLEN); // get the name "prompt" in our cmd buf int entry = findKey(buf); if (entry >= 0) doCommand(kludge(findend(entry))); else msgp(M_prompt); // else print default prompt }
/** * \ingroup time * GetUSdate gibt Datum kompatibel mit Internet Datumsangabe zurück */ char *GetUSdate(char *datestring) { char month[4]; strncpy_P(month,&US_Monate[(TM_MM-1)*3],3); month[3] = '\0'; sprintf_P(datestring,PSTR("%2d %s %4d"),TM_DD,month,GetYearYYYY()); return datestring; }
// Find a variable by name. // AP_Param * AP_Param::find_P(const prog_char_t *name, enum ap_var_type *ptype) { char param_name[AP_MAX_NAME_SIZE+1]; strncpy_P(param_name, name, AP_MAX_NAME_SIZE); param_name[AP_MAX_NAME_SIZE] = 0; return find(param_name, ptype); }
void ATSMS::setCMGLEndBuffer() { // Prepare answer end strncpy_P(m_endBuffer, ATDEV_STR_CMGL, ATDEV_BUFF_END_SIZE); // Timeout m_timeOut = ATDEV_SMS_TIMEOUT_LIST; }
int WebServer_put_notfound(int socket){ char req_pool[50]; memset(req_pool, 0, sizeof(req_pool)); strncpy_P(req_pool, PSTR("HTTP/1.0 404 Not Found\r\n"), sizeof(req_pool)); WebServer_put_response(socket, req_pool, strlen(req_pool)); memset(req_pool, 0, sizeof(req_pool)); strncpy_P(req_pool, PSTR("Content-Type: text/html\r\n"), sizeof(req_pool)); WebServer_put_response(socket, req_pool, strlen(req_pool)); memset(req_pool, 0, sizeof(req_pool)); strncpy_P(req_pool, PSTR("Connection: close\r\n\r\n"), sizeof(req_pool)); WebServer_put_response(socket, req_pool, strlen(req_pool)); return 0; }
void tx_aprs(int32_t lat, int32_t lon, int32_t alt) { char slat[5]; char slng[5]; char stlm[9]; static uint16_t seq = 0; /* Convert the UBLOX-style coordinates to * the APRS compressed format */ lat = 900000000 - lat; lat = lat / 26 - lat / 2710 + lat / 15384615; lon = 900000000 + lon / 2; lon = lon / 26 - lon / 2710 + lon / 15384615; alt = alt / 1000 * 32808 / 10000; /* Construct the compressed telemetry format */ ax25_base91enc(stlm + 0, 2, seq); ax25_base91enc(stlm + 2, 2, adc_read()); ax25_frame( APRS_CALLSIGN, APRS_SSID, "APRS", 0, 0, 0, 0, 0, //"WIDE1", 1, //"WIDE2", 1, "!/%s%sO /A=%06ld|%s|", ax25_base91enc(slat, 4, lat), ax25_base91enc(slng, 4, lon), alt, stlm ); if(seq % 60 == 0) { char s[10]; /* Make up the callsign */ strncpy_P(s, PSTR(APRS_CALLSIGN), 7); if(APRS_SSID) snprintf_P(s + strlen(s), 4, PSTR("-%i"), APRS_SSID); /* Transmit telemetry definitions */ ax25_frame( APRS_CALLSIGN, APRS_SSID, "APRS", 0, 0, 0, 0, 0, ":%-9s:PARM.Battery", s ); ax25_frame( APRS_CALLSIGN, APRS_SSID, "APRS", 0, 0, 0, 0, 0, ":%-9s:UNIT.mV", s ); } seq++; }
void modelDefault(uint8_t id) { memset(&g_model,0,sizeof(g_model)); strncpy_P(g_model.name,PSTR("MODEL "), 10); g_model.name[5]='0'+(id+1)/10; g_model.name[6]='0'+(id+1)%10; g_model.mdVers = 0; //MDVERS143; modelMixerDefault(id==0 ? 1 : 0); }