MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / handle_post

Method handle_post

Tools/AP_Bootloader/network.cpp:380–475  ·  view source on GitHub ↗

handle an incoming HTTP POST request */

Source from the content-addressed store, hash-verified

378 handle an incoming HTTP POST request
379 */
380void BL_Network::handle_post(SocketAPM *sock, uint32_t content_length)
381{
382 /*
383 skip over form boundary. We don't care about the filename as we
384 only support one file
385 */
386 uint8_t state = 0;
387 while (true) {
388 char c;
389 if (sock->recv(&c, 1, 100) != 1) {
390 return;
391 }
392 content_length--;
393 // absorb up to \r\n\r\n
394 if (c == '\r') {
395 if (state == 2) {
396 state = 3;
397 } else {
398 state = 1;
399 }
400 } else if (c == '\n') {
401 if (state == 1 || state == 3) {
402 state++;
403 } else {
404 state = 0;
405 }
406 if (state == 4) {
407 break;
408 }
409 } else {
410 state = 0;
411 }
412 }
413 /*
414 erase all of flash
415 */
416 status_printf("Erasing ...");
417 flash_set_keep_unlocked(true);
418 uint32_t sec=0;
419 while (flash_func_sector_size(sec) != 0 &&
420 flash_func_erase_sector(sec)) {
421 thread_sleep_ms(10);
422 sec++;
423 if (stm32_flash_getpageaddr(sec) - stm32_flash_getpageaddr(0) >= content_length) {
424 break;
425 }
426 }
427 /*
428 receive file and write to flash
429 */
430 uint32_t buf[128];
431 uint32_t ofs = 0;
432
433 // must be multiple of 4
434 content_length &= ~3;
435
436 const uint32_t max_ofs = MIN(BOARD_FLASH_SIZE*1024, content_length);
437 uint8_t last_pct = 0;

Callers

nothing calls this directly

Calls 13

flash_set_keep_unlockedFunction · 0.85
flash_func_sector_sizeFunction · 0.85
flash_func_erase_sectorFunction · 0.85
thread_sleep_msFunction · 0.85
stm32_flash_getpageaddrFunction · 0.85
MINFunction · 0.85
flash_write_bufferFunction · 0.85
memsetFunction · 0.85
flash_write_flushFunction · 0.85
check_good_firmwareFunction · 0.85
strlenFunction · 0.85
recvMethod · 0.45

Tested by

no test coverage detected