void MTD_FLASHMEM HTTPGPIOResponseHTML::flush() { setStatus(STR_200_OK); addHeader(STR_Content_Type, STR_TEXTHTML); char const* cmd = getRequest().query[FSTR("cmd")]; if (cmd && f_strcmp(cmd, FSTR("set")) == 0) { // set gpio HTTPHelperConfiguration::GPIOSetValue(this); } else if (cmd && f_strcmp(cmd, FSTR("conf")) == 0) { // conf gpio HTTPHelperConfiguration::GPIOConf(this); } char const* gpio = getRequest().query[STR_gpio]; if (gpio) { uint8_t gpion = strtol(gpio, NULL, 10); addContent(GPIO(gpion).read()? STR_1 : STR_0); } HTTPResponse::flush(); }
static int enumerate(struct usb_host_device_t *device_p) { struct usb_descriptor_interface_t *int_desc_p; std_printf(FSTR("Enumerating a MASS_STORAGE device.\r\n")); int_desc_p = usb_desc_get_interface(device_p->descriptors.buf, device_p->descriptors.size, 1, 0); if (int_desc_p == NULL) { return (-1); } if (usb_host_device_set_configuration(device_p, 1) != 0) { return (-1); } get_max_lun(device_p); scsi_get_inquiry(device_p); if (scsi_test_unit_ready(device_p) != 0) { std_printf(FSTR("device is not ready\r\n")); } return (0); }
static int get_max_lun(struct usb_host_device_t *device_p) { struct usb_setup_t setup; uint8_t buf[1]; std_printf(FSTR("get number of LUN:s (logical units) from mass storage device\r\n")); /* Initiate the setup datastructure. */ setup.request_type = (REQUEST_TYPE_DATA_DIRECTION_DEVICE_TO_HOST | REQUEST_TYPE_TYPE_CLASS | REQUEST_TYPE_RECIPIENT_INTERFACE); setup.request = REQUEST_GET_MAX_LUN; setup.u.base.value = 0; setup.u.base.index = 0; setup.length = 1; if (usb_host_device_control_transfer(device_p, &setup, buf, sizeof(buf)) != sizeof(buf)) { return (-1); } std_printf(FSTR("LUN max = %d\r\n"), buf[0]); /* Save the max LUN number. */ //device_p->max_lun = 0; return (0); }
static int cmd_set_bits_per_sample_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { long bits_per_sample; if (argc != 2) { std_fprintf(out_p, FSTR("Usage: %s <number of bits>\r\n"), argv[0]); return (-EINVAL); } if (std_strtol(argv[1], &bits_per_sample) != 0) { std_fprintf(out_p, FSTR("Usage: %s <number of bits>\r\n"), argv[0]); return (-EINVAL); } if ((bits_per_sample < 0) || (bits_per_sample > 12)) { std_printf(FSTR("The number of bits per sample bust be " "an interger from 0 to 12.\r\n")); return (-EINVAL); } return (music_player_set_bits_per_sample(&music_player, bits_per_sample)); }
int main() { int address; int number_of_slaves; sys_start(); i2c_module_init(); i2c_init(&i2c, &i2c_0_dev, I2C_BAUDRATE_100KBPS, -1); i2c_start(&i2c); std_printf(FSTR("Scanning the i2c bus for slaves...\r\n" "\r\n")); number_of_slaves = 0; for (address = 0; address < 128; address++) { if (i2c_scan(&i2c, address) == 1) { std_printf(FSTR("Found slave with address 0x%x.\r\n"), address); number_of_slaves++; } } std_printf(FSTR("\r\n" "Scan complete. Found %d slaves.\r\n"), number_of_slaves); return (0); }
static int cmd_list_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { struct song_t *song_p; int number; if (argc != 1) { std_fprintf(out_p, FSTR("Usage: %s\r\n"), argv[0]); return (1); } /* Write the header. */ std_fprintf(out_p, FSTR("NUMBER NAME LENGTH\r\n")); /* Iterate over all songs in the ordered hash map. */ for (number = FIRST_SONG_NUMBER; ((song_p = hash_map_get(&song_map, number)) != NULL); number++) { std_fprintf(out_p, FSTR("%6d %15s %4d:%02d\r\n"), song_p->number, song_p->name, song_p->minutes, song_p->seconds); } return (0); }
void MTD_FLASHMEM HTTPHelperConfiguration::setDateTime(HTTPTemplateResponse* response) { // set current date and time char const* dateStr = response->getRequest().form[STR_date]; char const* timeStr = response->getRequest().form[STR_time]; if (dateStr && timeStr) { DateTime dt; dt.decode(dateStr, FSTR("%d/%m/%Y")); dt.decode(timeStr, FSTR("%H:%M:%S")); DateTime::setCurrentDateTime(dt); } // set timezone and NTP server char const* tzh = response->getRequest().form[STR_tzh]; char const* tzm = response->getRequest().form[STR_tzm]; char const* ntpsrv = response->getRequest().form[STR_ntpsrv]; if (tzh && tzm) { ConfigurationManager::setDateTimeParams(strtol(tzh, NULL, 10), strtol(tzm, NULL, 10), ntpsrv? ntpsrv : STR_); ConfigurationManager::applyDateTime(); } }
static int storage_init(fat16_read_t *read_p, fat16_write_t *write_p, void **arg_pp) { std_printf(FSTR("SD storage.\r\n")); std_printf(FSTR("spi bitrate = %lu kbps\r\n"), 2 * 16 * SAMPLES_PER_SOCOND / 1024); /* Initialize SPI for the SD card. */ spi_init(&spi, &spi_device[0], &pin_d53_dev, SPI_MODE_MASTER, SPI_SPEED_2MBPS, 0, 1); sd_init(&sd, &spi); if (sd_start(&sd) != 0) { return (-1); } std_printf(FSTR("sd card started\r\n")); *read_p = (fat16_read_t)sd_read_block; *write_p = (fat16_write_t)sd_write_block; *arg_pp = &sd; return (0); }
static int cmd_read_cb(int argc, const char *argv[], void *out_p, void *in_p, void *arg_p, void *call_arg_p) { int pin; int value; if (argc != 2) { std_fprintf(out_p, FSTR("Usage: %s <pin>\r\n"), argv[0]); return (-EINVAL); } /* Get pin. */ pin = board_pin_string_to_device_index(argv[1]); if (pin == -1) { std_fprintf(out_p, FSTR("%s: bad pin\r\n"), argv[1]); return (-EINVAL); } value = pin_device_read(&pin_device[pin]); if (value == 1) { std_fprintf(out_p, FSTR("high\r\n")); } else { std_fprintf(out_p, FSTR("low\r\n")); } return (0); }
// should be called only after setStatus, addHeader and addContent void MTD_FLASHMEM HTTPResponse::flush() { // status line m_httpHandler->getSocket()->writeFmt(FSTR("HTTP/1.1 %s\r\n"), m_status); // HTTPResponse headers addHeader(FSTR("Connection"), FSTR("close")); // user headers for (uint32_t i = 0; i != m_headers.getItemsCount(); ++i) { Fields::Item* item = m_headers[i]; m_httpHandler->getSocket()->writeFmt(FSTR("%s: %s\r\n"), APtr<char>(t_strdup(item->key)).get(), APtr<char>(t_strdup(item->value)).get()); } // content length header m_httpHandler->getSocket()->writeFmt(FSTR("%s: %d\r\n\r\n"), STR_Content_Length, m_content.getItemsCount()); // actual content if (m_content.getItemsCount() > 0) { CharChunksIterator iter = m_content.getIterator(); CharChunkBase* chunk = iter.getCurrentChunk(); while (chunk) { m_httpHandler->getSocket()->write((uint8_t const*)chunk->data, chunk->getItems()); chunk = iter.moveToNextChunk(); } m_content.clear(); } }
void MTD_FLASHMEM HTTPHelperConfiguration::getClientModeWiFiParams(HTTPTemplateResponse* response) { char const* SSID; char const* securityKey; ConfigurationManager::getClientParams(&SSID, &securityKey); response->addParamStr(FSTR("CLPSW"), securityKey); response->addParamStr(FSTR("CLSSID"), SSID); }
static int scsi_get_inquiry(struct usb_host_device_t *device_p) { struct cbw_t cbw; struct csw_t csw; struct scsi_cdb_inquiry_t *cdb_p; struct scsi_cdb_inquiry_data_t inquiry_data; std_printf(FSTR("get inquiry\r\n")); device_p->max_packet_size = 512; /* Initiate the Command Block Wrapper. */ memset(&cbw, 0, sizeof(cbw)); cbw.signature = CBW_SIGNATURE; cbw.tag = (uint32_t)device_p; cbw.data_transfer_length = sizeof(inquiry_data); cbw.flags = 0x80; cbw.lun = 0; cbw.command_block_length = sizeof(*cdb_p); cdb_p = (struct scsi_cdb_inquiry_t *)cbw.command_block; cdb_p->operation_code = SCSI_CDB_OPERATION_CODE_INQUIRY; cdb_p->allocation_length = sizeof(inquiry_data); /* Write the Command Block Wrapper to the device. */ if (usb_host_device_write(device_p, 2, &cbw, sizeof(cbw)) != sizeof(cbw)) { std_printf(FSTR("failed to write the command block wrapper.\r\n")); return (-1); } /* Read the data from the device. */ if (usb_host_device_read(device_p, 1, &inquiry_data, sizeof(inquiry_data)) != sizeof(inquiry_data)) { std_printf(FSTR("Failed to read data.\r\n")); return (-1); } /* Read the Comand Status Wrapper from the device. */ if (usb_host_device_read(device_p, 1, &csw, sizeof(csw)) != sizeof(csw)) { return (-1); } if (csw.status != CSW_STATUS_PASSED) { std_printf(FSTR("status = %d\r\n"), csw.status); return (-1); } std_printf(FSTR("version = %d\r\n"), inquiry_data.version); return (csw.data_residue); }
/** * Print a message after a script has been executed. */ static void print_exit_message(int res, const char *prefix_p) { if (res == 1) { std_printf(FSTR("%s exited normally.\r\n\r\n"), prefix_p); } else if (res & PYEXEC_FORCED_EXIT) { std_printf(FSTR("%s forced exit.\r\n\r\n"), prefix_p); } else { std_printf(FSTR("%s exited abnormally.\r\n\r\n"), prefix_p); } }
ssize_t usb_host_class_mass_storage_device_read( struct usb_host_device_t *device_p, void *buf_p, size_t address, size_t size) { struct cbw_t cbw; struct csw_t csw; struct scsi_cdb_read_t *cdb_p; device_p->max_packet_size = 512; /* Initiate the Command Block Wrapper. */ memset(&cbw, 0, sizeof(cbw)); cbw.signature = CBW_SIGNATURE; cbw.tag = (uint32_t)device_p; cbw.data_transfer_length = size; cbw.flags = 0x80; cbw.lun = 0; cbw.command_block_length = sizeof(*cdb_p); cdb_p = (struct scsi_cdb_read_t *)cbw.command_block; cdb_p->operation_code = SCSI_CDB_OPERATION_CODE_READ_10; cdb_p->logical_block_address = htonl(address / 512); cdb_p->transfer_length = htons(size / 512); /* Write the Command Block Wrapper to the device. */ if (usb_host_device_write(device_p, 2, &cbw, sizeof(cbw)) != sizeof(cbw)) { std_printf(FSTR("failed to write the command block wrapper.\r\n")); return (-1); } /* Read the dat from the device. */ if (usb_host_device_read(device_p, 1, buf_p, size) != size) { std_printf(FSTR("Failed to read data.\r\n")); return (-1); } /* Read the Comand Status Wrapper from the device. */ if (usb_host_device_read(device_p, 1, &csw, sizeof(csw)) != sizeof(csw)) { return (-1); } if (csw.status != CSW_STATUS_PASSED) { std_printf(FSTR("status = %d\r\n"), csw.status); return (-1); } return (size - csw.data_residue); }
/** * The listener thread main function. The listener listens for * connections from clients. */ static void *listener_main(void *arg_p) { struct http_server_t *self_p = arg_p; struct http_server_listener_t *listener_p; struct http_server_connection_t *connection_p; struct inet_addr_t addr; thrd_set_name(self_p->listener_p->thrd.name_p); listener_p = self_p->listener_p; if (socket_open_tcp(&listener_p->socket) != 0) { log_object_print(NULL, LOG_ERROR, FSTR("Failed to open socket.")); return (NULL); } if (inet_aton(listener_p->address_p, &addr.ip) != 0) { return (NULL); } addr.port = listener_p->port; if (socket_bind(&listener_p->socket, &addr) != 0) { log_object_print(NULL, LOG_ERROR, FSTR("Failed to bind socket.")); return (NULL); } if (socket_listen(&listener_p->socket, 3) != 0) { log_object_print(NULL, LOG_ERROR, FSTR("Failed to listen on socket.")); return (NULL); } /* Wait for clients to connect. */ while (1) { /* Allocate a connection. */ connection_p = allocate_connection(self_p); /* Wait for a client to connect. */ socket_accept(&listener_p->socket, &connection_p->socket, &addr); handle_accept(self_p, connection_p); } return (NULL); }
void MTD_FLASHMEM HTTPHelperConfiguration::setAPWiFiParams(HTTPTemplateResponse* response) { char const* APCH = response->getRequest().form[FSTR("APCH")]; char const* APSEC = response->getRequest().form[FSTR("APSEC")]; if (APCH && APSEC) ConfigurationManager::setAccessPointParams(response->getRequest().form[FSTR("APSSID")], response->getRequest().form[FSTR("APPSW")], strtol(APCH, NULL, 10), (WiFi::SecurityProtocol)strtol(APSEC, NULL, 10), response->getRequest().form[FSTR("APHSSID")] != NULL); }
void MTD_FLASHMEM MultipartFormDataProcessor::handle_DecodingHeaders(char c) { static char const EOH[4] = {0x0D, 0x0A, 0x0D, 0x0A}; if (c == EOH[substate]) { ++substate; if (substate == 2) { // useful if this is not an EOH to separate headers headers->append(0x0D, 1); } else if (substate == 4) { // end of headers headers->append(0, 1); // add string terminating zero // look for "name" parameter CharChunksIterator keyBegin; extractParameter(FSTR(" name="), headers->getIterator(), &keyBegin, &nameBegin, &nameEnd); // look for "filename" parameter CharChunksIterator filenameBegin, filenameEnd; if (extractParameter(FSTR(" filename="), headers->getIterator(), &keyBegin, &filenameBegin, &filenameEnd)) { //// this is a file // add "filename" to form fields filenameBegin = getFilename(filenameBegin, filenameEnd); // some browsers send a full path instead of a simple file name (IE) formfields->add(keyBegin + 1, keyBegin + 9, filenameBegin, filenameEnd); // extract Content-Type parameter CharChunksIterator contentTypeBegin, contentTypeEnd; if (extractParameter(FSTR("Content-Type:"), filenameEnd, &keyBegin, &contentTypeBegin, &contentTypeEnd)) { // add "Content-Type" to form fields formfields->add(keyBegin, keyBegin + 12, contentTypeBegin, contentTypeEnd); // create file file.create(APtr<char>(t_strdup(filenameBegin, filenameEnd)).get(), APtr<char>(t_strdup(contentTypeBegin, contentTypeEnd)).get()); state = GettingFile; } else { // missing content-type, cannot get as file! state = GettingValue; } } else { //// this is a normal field valueStorage = chunksFactory.add(); state = GettingValue; } substate = 0; } } else { // add to headers buffer headers->append(c, HEADERS_CHUNK_SIZE); substate = 0; } }
static int test_sine_440_hz(struct harness_t *harness_p) { #if !defined(SKIP_TEST_SINE_440_HZ) int i; float sample; int samples_per_second = (membersof(dac_gen_sine) * 440); struct dac_driver_t dac; int total_number_of_samples; BTASSERT(dac_init(&dac, &dac_0_dev, &pin_0_dev, NULL, samples_per_second) == 0); /* Samples are in the range -1.0 to 1.0. Convert them to the range 0 to AMPLITUDE_MAX. */ for (i = 0; i < membersof(samples); i++) { sample = dac_gen_sine[i % membersof(dac_gen_sine)]; samples[i] = AMPLITUDE_MAX * ((sample + 1.0) / 2.0); } std_printf(FSTR("Converting %d samples.\r\n"), (int)membersof(samples)); BTASSERT(dac_convert(&dac, (uint32_t *)samples, membersof(samples) / 2) == 0); /* Converting the signal on the DAC0-pin for 5 seconds. */ total_number_of_samples = (5 * samples_per_second); std_printf(FSTR("Converting %d samples.\r\n"), total_number_of_samples); for (i = 0; i < total_number_of_samples; i += membersof(samples)) { BTASSERT(dac_async_convert(&dac, (uint32_t *)samples, membersof(samples) / 2) == 0); std_printf(FSTR("Samples left = %d\r\n"), total_number_of_samples - i); } std_printf(FSTR("Waiting for last samples to be converted\r\n")); BTASSERT(dac_async_wait(&dac) == 0); return (0); #else (void)dac_gen_sine; return (1); #endif }
int settings_module_init(void) { /* Return immediately if the module is already initialized. */ if (module.initialized == 1) { return (0); } module.initialized = 1; #if CONFIG_FS_CMD_SETTINGS_LIST == 1 fs_command_init(&module.cmd_list, FSTR("/oam/settings/list"), cmd_list_cb, NULL); fs_command_register(&module.cmd_list); #endif #if CONFIG_FS_CMD_SETTINGS_RESET == 1 fs_command_init(&module.cmd_reset, FSTR("/oam/settings/reset"), cmd_reset_cb, NULL); fs_command_register(&module.cmd_reset); #endif #if CONFIG_FS_CMD_SETTINGS_READ == 1 fs_command_init(&module.cmd_read, FSTR("/oam/settings/read"), cmd_read_cb, NULL); fs_command_register(&module.cmd_read); #endif #if CONFIG_FS_CMD_SETTINGS_WRITE == 1 fs_command_init(&module.cmd_write, FSTR("/oam/settings/write"), cmd_write_cb, NULL); fs_command_register(&module.cmd_write); #endif return (settings_port_module_init()); }
static int test_create_multiple_files(struct harness_t *harness_p) { struct fat16_file_t file; char filename[32]; int i; for (i = 0; i < 32; i++) { std_sprintf(filename, FSTR("FILE%d.TXT"), i); std_printf(FSTR("Creating file with name '%s'.\r\n"), filename); BTASSERT(fat16_file_open(&fs, &file, filename, O_CREAT | O_WRITE) == 0); BTASSERT(fat16_file_close(&file) == 0); } return (0); }
char const* MTD_FLASHMEM ParameterReplacer::replaceTag(char const* curc) { char const* tagEnd; char const* tagStart = extractTagStr(curc, &tagEnd); if (getChar(tagStart) == '#') { // replace multiple parameters ('0param', '1param', ...) ++tagStart; uint32_t tagLen = tagEnd - tagStart; char tag[tagLen]; f_memcpy(tag, tagStart, tagLen); tag[tagLen] = 0; for (uint32_t index = 0; ; ++index) { char const* fulltagname = f_printf(FSTR("%d%s"), index, tag); Params::Item* item = m_params->getItem(fulltagname); if (item) m_result.addChunks(&item->value); // push parameter content else break; } } else { // replace one parameter Params::Item* item = m_params->getItem(tagStart, tagEnd); if (item) m_result.addChunks(&item->value); // push parameter content } return tagEnd + 2; // bypass "}}" }
static int test_duty_cycles(struct harness_t *harness_p) { int percentage; long duty_cycle; BTASSERT(pwm_soft_start(&pwm_soft[0]) == 0); BTASSERT(pwm_soft_start(&pwm_soft[1]) == 0); thrd_sleep_ms(100); /* Test various duty cycles. */ for (percentage = 0; percentage <= 100; percentage += 10) { duty_cycle = pwm_soft_duty_cycle(percentage); BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[0], duty_cycle) == 0); BTASSERT(pwm_soft_set_duty_cycle(&pwm_soft[1], duty_cycle) == 0); std_printf(FSTR("Duty cycle: %ld\r\n"), duty_cycle); thrd_sleep_ms(100); } BTASSERT(pwm_soft_stop(&pwm_soft[0]) == 0); BTASSERT(pwm_soft_stop(&pwm_soft[1]) == 0); return (0); }
static int read_initial_request_line(struct socket_t *socket_p, char *buf_p, struct http_server_request_t *request_p) { char *action_p = NULL; char *path_p = NULL; char *proto_p = NULL; *buf_p++ = '\0'; action_p = buf_p; while (1) { if (socket_read(socket_p, buf_p, sizeof(*buf_p)) != sizeof(*buf_p)) { return (-EIO); } buf_p++; /* The line ending is "\r\n". */ if ((buf_p[-2] == '\r') && (buf_p[-1] == '\n')) { buf_p[-2] = '\0'; break; } /* Action and path has ' ' as terminator. */ if (buf_p[-1] == ' ') { buf_p[-1] = '\0'; if (path_p == NULL) { path_p = buf_p; } else if (proto_p == NULL) { proto_p = buf_p; } } } /* A path is required. */ if (path_p == NULL) { return (-1); } log_object_print(NULL, LOG_DEBUG, FSTR("%s %s %s\r\n"), action_p, path_p, proto_p); /* Save the action and path in the request struct. */ strcpy(request_p->path, path_p); if (strcmp(action_p, "GET") == 0) { request_p->action = http_server_request_action_get_t; } else if (strcmp(action_p, "POST") == 0) { request_p->action = http_server_request_action_post_t; } else { return (-1); } return (0); }
int main() { sys_start(); uart_soft_init(&uart, &pin_d4_dev, &pin_d3_dev, &exti_d3_dev, 9600, qinbuf, sizeof(qinbuf)); fs_command_init(&cmd_at, CSTR("/at"), cmd_at_cb, NULL); fs_command_register(&cmd_at); std_printf(FSTR("Welcome to HC-0X configuration tool!\r\n" "\r\n" "SETUP: Connect pin34 to VCC so the device enters AT mode.\r\n" "\r\n" "Type 'at' to start communicating with the device.\r\n")); shell_init(&shell, sys_get_stdin(), sys_get_stdout(), NULL, NULL, NULL, NULL); shell_main(&shell); return (0); }
int test_get_temp(struct harness_t *harness_p) { struct owi_driver_t owi; struct ds18b20_driver_t ds; struct owi_device_t devices[4]; char buf[24]; int number_of_sensors; BTASSERT(owi_init(&owi, &pin_d7_dev, devices, membersof(devices)) == 0); BTASSERT(ds18b20_init(&ds, &owi) == 0); time_busy_wait_us(50000); number_of_sensors = owi_search(&owi); std_printf(FSTR("number_of_sensors = %d\r\n"), number_of_sensors); BTASSERT(number_of_sensors == 2); strcpy(buf, "drivers/ds18b20/list"); BTASSERT(fs_call(buf, NULL, sys_get_stdout(), NULL) == 0); time_busy_wait_us(50000); return (0); }
static int test_read_cid(struct harness_t *harness_p) { struct sd_cid_t cid; static const char *mdt_month[16] = { "0", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec", "13", "14", "15" }; /* Read CID and print it to stdout. */ BTASSERT(sd_read_cid(&sd, &cid) == sizeof(cid)); std_printf(FSTR("cid {\r\n" " manufacturer id = 0x%02x\r\n" " application id = '%c%c'\r\n" " product name = '%c%c%c%c%c'\r\n" " product revision = %02x\r\n" " product serial number = %lu\r\n" " manufacturing date = %s %u\r\n" " crc checksum = 0x%02x\r\n" "}\r\n"), (unsigned int)cid.mid, cid.oid[0], cid.oid[1], cid.pnm[0], cid.pnm[1], cid.pnm[2], cid.pnm[3], cid.pnm[4], cid.prv, cid.psn, mdt_month[ntohs(cid.mdt) & 0xf], 2000 + ((ntohs(cid.mdt) >> 4) & 0xff), cid.crc); return (0); }
static int test_read_performance(struct harness_t *harness_p) { int i, block, res; struct time_t start, stop, diff; float seconds; unsigned long bytes_per_seconds; int number_of_blocks = 32; /* Write reference data to given block and verify that it was written. */ for (i = 0; i < membersof(buf); i++) { buf[i] = (i & 0xff); } time_get(&start); /* Write to and read from the first five blocks. */ for (block = 0; block < number_of_blocks; block++) { BTASSERT((res = sd_read_block(&sd, buf, block)) == SD_BLOCK_SIZE, ", res = %d\r\n", res); } time_get(&stop); time_diff(&diff, &stop, &start); seconds = (diff.seconds + diff.nanoseconds / 1000000000.0f); bytes_per_seconds = ((SD_BLOCK_SIZE * number_of_blocks) / seconds); std_printf(FSTR("Read 32 blocks of %d bytes in %f s (%lu bytes/s).\r\n"), SD_BLOCK_SIZE, seconds, bytes_per_seconds); return (0); }
int test_exti(struct harness_t *harness_p) { int i; struct exti_driver_t exti; struct pin_driver_t pin; pin_init(&pin, &pin_d4_dev, PIN_OUTPUT); pin_write(&pin, 1); BTASSERT(exti_init(&exti, &exti_d3_dev, EXTI_TRIGGER_FALLING_EDGE, isr, NULL) == 0); BTASSERT(exti_start(&exti) == 0); for (i = 0; i < 10; i++) { pin_write(&pin, 0); time_busy_wait_us(10000); pin_write(&pin, 1); time_busy_wait_us(10000); } std_printf(FSTR("flag = %d\r\n"), (int)flag); BTASSERT(flag == 10); return (0); }
void MTD_FLASHMEM HTTPHandler::processMultipartFormData(CharChunksIterator headerEnd, int32_t contentLength, char const *contentType) { char const *boundary = f_strstr(contentType, FSTR("boundary=")); if (boundary) { // go to begin of boundary string boundary += 9; MultipartFormDataProcessor proc(boundary, &m_request.form); // consume already received data CharChunksIterator contentStart = headerEnd; while (contentStart != CharChunksIterator()) proc.push(*contentStart++); // consume new data while (getSocket()->isConnected() && proc.state != MultipartFormDataProcessor::EndOfContent) { char c; int32_t bytesRecv = getSocket()->read(&c, 1); if (bytesRecv <= 0) break; proc.push(c); } // dispatch must be inside this block, to have MultipartFormDataProcessor content available dispatch(); } else dispatch(); }
void MTD_FLASHMEM HTTPTemplateResponse::processFileRequest() { FlashFileSystem::Item file; if (m_filename && FlashFileSystem::find(m_filename, &file)) { // found setStatus(STR_200_OK); addHeader(STR_Content_Type, FSTR("text/html; charset=UTF-8")); // replace parameters m_replacer.start((char const *)file.data, (char const *)file.data + file.datalength, &m_params, NULL); // is this a specialized file (contains {%..%} blocks)? if (m_replacer.getBlocks()->getItemsCount() > 0 && m_replacer.getTemplateFilename() != NULL) { // this is a specialized file // load template file file.reset(); if (FlashFileSystem::find(m_replacer.getTemplateFilename(), &file)) { // replace parameters and blocks of template file m_templateReplacer.start((char const *)file.data, (char const *)file.data + file.datalength, &m_params, m_replacer.getBlocks()); // flush resulting content addContent(m_templateReplacer.getResult()); return; } } else { // just flush this file (contains only {{...}} blocks) addContent(m_replacer.getResult()); return; } } // not found setStatus(STR_404_Not_Found); }