+static int http_htmPageLoad(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)
+{
+ (void)revc_buf;
+ (void)revc_len;
+
+ if (SD_CARD_PRESENT())
+ {
+
+ // SD fat filesystem context
+ Sd sd;
+ FATFS fs;
+ FatFile in_file;
+ FRESULT result;
+
+ bool sd_ok = sd_init(&sd, NULL, 0);
+ if (sd_ok)
+ {
+ LOG_INFO("Mount FAT filesystem.\n");
+ result = f_mount(0, &fs);
+ if (result != FR_OK)
+ {
+ LOG_ERR("Mounting FAT volumes error[%d]\n", result);
+ sd_ok = false;
+ f_mount(0, NULL);
+ }
+
+ if (sd_ok)
+ {
+ result = fatfile_open(&in_file, name, FA_OPEN_EXISTING | FA_READ);
+
+ size_t count = 0;
+ if (result == FR_OK)
+ {
+ LOG_INFO("Opened file '%s' size %ld\n", name, in_file.fat_file.fsize);
+
+ http_sendOk(client);
+
+ while (count < in_file.fat_file.fsize)
+ {
+ int len = kfile_read(&in_file.fd, tx_buf, sizeof(tx_buf));
+ netconn_write(client, tx_buf, len, NETCONN_COPY);
+ count += len;
+ }
+
+ kfile_flush(&in_file.fd);
+ kfile_close(&in_file.fd);
+
+ LOG_INFO("Sent: %d\n", count);
+ }
+ else
+ {
+ LOG_ERR("Unable to open file: '%s' error[%d]\n", name, result);
+ http_sendFileNotFound(client);
+ netconn_write(client, http_file_not_found, http_file_not_found_len - 1, NETCONN_NOCOPY);
+ }
+ }
+ }
+ f_mount(0, NULL);
+ LOG_INFO("Umount FAT filesystem.\n");
+ }
+ else
+ {
+ http_sendFileNotFound(client);
+ netconn_write(client, http_sd_not_present, http_sd_not_present_len, NETCONN_NOCOPY);
+ }
+
+ return 0;
+}
+
+static int cgi_chipInfo(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)
+{
+ (void)revc_buf;
+ (void)revc_len;
+ (void)name;
+
+ sprintf((char *)tx_buf, "[ %s, %s, %s, %s, %s ]",
+ chipid_eproc_name(CHIPID_EPRCOC()),
+ chipid_archnames(CHIPID_ARCH()),
+ chipid_sramsize(CHIPID_SRAMSIZ()),
+ chipid_nvpsize(CHIPID_NVPSIZ()),
+ chipid_nvptype(CHIPID_NVTYP()));
+
+ http_sendOk(client);
+ netconn_write(client, tx_buf, strlen((char *)tx_buf), NETCONN_COPY);
+
+ return 0;
+}
+
+static int cgi_error(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)
+{
+ (void)revc_buf;
+ (void)revc_len;
+ (void)name;
+ (void)client;
+
+ return -1;
+}
+