| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include "cfg.h"
- #include "fs.h"
- #include <stdio.h>
- #include "md5.h"
- #include "led.h"
- #include "rtthread.h"
- #include "dfs_posix.h"
- //#include "channel_display.h"
- //#include "data_js.h"
- //#include "display_data.h"
- //#include "index_css.h"
- #include "index_html.h"
- //#include "index_js.h"
- //#include "operation.h"
- //#include "petite-vue.min.h"
- //#include "sys_para.h"
- //#include "ws.h"
- //https://embedded-rd.blog.csdn.net/article/details/109643188
- #define CHAR(b) (((b)<=9)?((b)+0x30):((b)-10+0x61));
- static void byte2char(char *chr, uint8_t b)
- {
- chr[0] = CHAR(b>>4);
- chr[1] = CHAR(b&0x0f);
- }
- //char * test_txt ="sadasdasjkdjalkdfnlakdfnjo'ajdfrlkasdjflkjasdlkfjasdlkfjlasdkjfmjsdlkmfasdlkfmsldfmsdlf;asldfkjsdl;fjslkjf;lskdfjlas;jfasdlkflkjsf";
- #define BASE_PATH "/nor/web"
- #define API_PATH "/nor/web/api"
- #define CSS_PATH "/nor/web/css"
- static void check_path()
- {
- DIR *dir_base = opendir(BASE_PATH);
- DIR *dir_api = opendir(API_PATH);
- DIR *dir_css = opendir(CSS_PATH);
- if(!dir_base)
- {
- mkdir(BASE_PATH,0777);
- }
- if(!dir_api)
- {
- mkdir(API_PATH,0777);
- }
- if(!dir_css)
- {
- mkdir(CSS_PATH,0777);
- }
- closedir(dir_base);
- closedir(dir_api);
- closedir(dir_css);
- }
- static void check_file(const char *nor_filename,const char *dst)
- {
-
- if(!nor_filename || !dst)
- return;
-
- md5_ctx_t ctx;
- md5_init(&ctx);
- uint8_t nor_tmp[16] = {0};
- char nor_m1[32]={0};
- char str_m1[32]={0};
-
- uint8_t str_tmp[16] = {0};
- char buff[1024] = {0};
- int fd = open(nor_filename,O_CREAT | O_RDWR,0777);
- if(fd <= 0)
- {
- return;
- }
- int read_len = 0;
- while((read_len = read(fd,buff,1024)) != 0)
- {
- md5_update(&ctx,(uint8_t*)&buff,read_len);
- }
- md5_final(&ctx, nor_tmp);
-
- for (int i=0; i<16; i++)
- byte2char(&nor_m1[i*2], nor_tmp[i]);
-
- //str
- md5_init(&ctx);
- uint32_t lenth = strlen(dst);
- uint32_t count = 1000;
- char *start = (char *)dst;
- do{
- if(lenth <= 1000)
- {
- memcpy(buff,start,lenth);
- md5_update(&ctx,(uint8_t*)&buff,lenth);
- lenth -= lenth;
- }else
- {
- memcpy(buff,start,1000);
- md5_update(&ctx,(uint8_t*)&buff,1000);
- lenth -= 1000;
- start += 1000;
- }
- }while(lenth);
- md5_final(&ctx, nor_tmp);
-
- for (int i=0; i<16; i++)
- byte2char(&str_m1[i*2], nor_tmp[i]);
- if(memcmp(nor_m1,str_m1,sizeof(nor_m1)))
- {
- //write filed to nor
- if (ftruncate(fd, 0) == -1) {
- close(fd);
- return;
- }
- lseek(fd,0,SEEK_SET);
- lenth = strlen(dst);
- char *start = (char *)dst;
-
- do{
- if(lenth <= 1000)
- {
- memcpy(buff,start,lenth);
- write(fd,buff,lenth);
- lenth-=lenth;
- }else
- {
- memcpy(buff,start,1000);
- lenth -= 1000;
- start += 1000;
- write(fd,buff,1000);
- }
- }while(lenth);
- }
-
- close(fd);
- fd = 0;
- }
- int main(void)
- {
- fs_init();
-
- check_path();
-
- // check_file("/nor/web/api/channel_display.js",p_channel_display);
- // check_file("/nor/web/api/data.js",p_data_js);
- // check_file("/nor/web/api/display_data.js",p_display_data);
- // check_file("/nor/web/api/index.js",p_index_js);
- // check_file("/nor/web/api/operation.js",p_operation);
- // check_file("/nor/web/api/petite-vue.min.js",p_petite_vue);
- // check_file("/nor/web/api/sys_paras.js",p_sys_para);
- // check_file("/nor/web/api/ws.js",p_ws);
- //
- //
- // check_file("/nor/web/css/index.css",p_css_index);
-
- check_file("/nor/web/index.html",p_index_html);
-
-
- led_init();
- led_set(0);
- while (1) {
- sleep(2);
- }
- }
|