int8_t ICACHE_FLASH_ATTR cb_fota_slot_in_use_info(uint8_t IsFirstCall, char* OutputData, uint16_t MaxBytes, uint16_t* RetBytes, uint8_t* RetDone){ /* TAG CALLBACK FUNCTION for [[FOTA_SLOT_IN_USE_INFO]] * -------------------------------------------- * ! See whttpd_pp_item_struct structure definition to know what is passed to / what is expected from tag callback function. * ! This function could be called multiple times for one tag, if we signal by RetDone that we didn't end yet (probably because MaxBytes was less that what we needed). */ //allocate memory for OutString (local) char* OutString = malloc(30); if(OutString==NULL){ *RetBytes = 0; *RetDone = 1; return -1; } if(IsFirstCall) cb_fsiui_CopiedBytes = 0; // //>> ---- generate whole OutString (enter your code here) uint32_t StartAddr = system_get_userbin_addr(); //slot in use uint32_t ID = spi_flash_get_id(); uint32_t FlashSizeB = ((uint32_t)1)<<((uint8_t*)&ID)[2]; //flash size in bytes uint32_t Len = (FlashSizeB/2) - ((StartAddr>(FlashSizeB/2))?StartAddr-(FlashSizeB/2):StartAddr) - 0x04000; //(FlashSizeB/2) - start offset of usercode - 16 kB for system parameter area sprintf(OutString, "0x%05X - 0x%05X, %d kB", StartAddr, StartAddr+Len-1, Len/1024); //<< ---- // whttpd_preproc_manage_cb_output(OutputData, OutString, &cb_fsiui_CopiedBytes, MaxBytes, RetBytes, RetDone); //output into OutputData (if MaxBytes is less than size of our data, manage subsequent chunked output throughout more calls of this tag callback function using global variable *_CopiedBytes) free(OutString); //free allocated memory return 0; //no error (don't abort tag preprocessing) }
// Handle system information variables and print their value, returns the number of // characters appended to buff int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) { if (TOKEN("si_chip_id")) { return os_sprintf(buff, "0x%x", system_get_chip_id()); } else if (TOKEN("si_freeheap")) { return os_sprintf(buff, "%dKB", system_get_free_heap_size()/1024); } else if (TOKEN("si_uptime")) { uint32 t = system_get_time() / 1000000; // in seconds return os_sprintf(buff, "%dd%dh%dm%ds", t/(24*3600), (t/(3600))%24, (t/60)%60, t%60); } else if (TOKEN("si_boot_version")) { return os_sprintf(buff, "%d", system_get_boot_version()); } else if (TOKEN("si_boot_address")) { return os_sprintf(buff, "0x%x", system_get_userbin_addr()); } else if (TOKEN("si_cpu_freq")) { return os_sprintf(buff, "%dMhz", system_get_cpu_freq()); } else { return 0; } }