Browse Source

配置文件ok

guohui 1 year ago
parent
commit
024d12120c

+ 1 - 1
f407/applications/datadef.h

@@ -312,7 +312,7 @@ typedef struct {
 }board_fn_t;
 
 typedef struct board_data {
-    board_fn_t          *fn;
+    board_fn_t          fn;
     uint8_t             type;
     uint8_t             addr;
     uint8_t             chs;

+ 54 - 20
f407/applications/fs.c

@@ -66,23 +66,27 @@ static mnt_info_t* get_info(fs_handle_t *h, char *dev)
 }
 static int dfs_mounts(const char *dev, const char *path, const char *fs_type)
 {
-    int r,err;
-    char *p=NULL,tmp;
+    char *p=(char*)path;
+    int r=0,len=strlen(path);
     
-    p = strchr(path, '/');
+    if(len>1) {
+        p = strchr(path+1, '/');
+    }
     while(p) {
-        tmp = *p;
-        *p = 0;
+        if(p>path) *p = 0;
         r = dfs_mount(dev, path, fs_type, 0, 0);
         LOGD("___ %s mount %s!\n", path, r?"failed":"ok");
-        *p = tmp;
+        if(p>path) *p = '/';
         
         p = strchr(p+1, '/');
+        if(r) break;
     }
+    return r;
 }
 static int do_mount(fs_handle_t *h, char *dev, int flag)
 {
     int r=0;
+    rt_err_t err=0;
     mnt_info_t *info=NULL;
     rt_device_t devid=NULL;
     
@@ -106,13 +110,11 @@ static int do_mount(fs_handle_t *h, char *dev, int flag)
         if(flag) {
             r = dfs_mounts(info->dev, info->mpath, info->ftype);
             if (r) {
-                if(rt_get_errno()==EPERM) {
-                    r = dfs_mkfs(info->dev, info->ftype);
+                r = dfs_mkfs(info->dev, info->ftype);
+                if(r==0) {
+                    r = dfs_mounts(info->dev, info->mpath, info->ftype);
                     if(r==0) {
-                        r = dfs_mounts(info->dev, info->mpath, info->ftype);
-                        if(r==0) {
-                            h->mounted[info->id] = 1;
-                        }
+                        h->mounted[info->id] = 1;
                     }
                 }
             }
@@ -157,6 +159,33 @@ int fs_test(void)
 }
 
 
+int fs_mkdir(char *path)
+{
+    char tmp[256];
+    char *p = NULL;
+    size_t len;
+    mode_t mode=0755;
+ 
+    snprintf(tmp, sizeof(tmp),"%s",path);
+    len = strlen(tmp);
+    if(tmp[len - 1] == '/')
+        tmp[len - 1] = 0;
+    
+    for(p = tmp + 1; *p; p++) {
+        if(*p == '/') {
+            *p = 0;
+            if(access(tmp, F_OK)==-1) {
+                if (mkdir(tmp, mode) == -1) {
+                    if (errno != EEXIST) return -1;
+                }
+            }
+            *p = '/';
+        }
+    }
+    return mkdir(tmp, mode);
+}
+
+
 
 int fs_length(char* path)
 {
@@ -175,23 +204,28 @@ int fs_length(char* path)
 
 int fs_exist(char* path)
 {
-    int r;
-    struct stat st;
-
-    r = stat(path, &st);
-    if (r) {
-        return 0;
+    int r=0;
+    if(access(path, F_OK)!=-1) {
+        r = 1;
     }
 
-    return 1;
+    return r;
 }
 
 
 int fs_save(char *path, void *buf, int len)
 {
     int r;
-    FILE *fp=fopen(path, "w");;
+    FILE *fp=NULL;
+    char *p=strrchr(path, '/');
+    
+    if(p) {
+        *p = 0;
+        r = fs_mkdir(path);
+        *p = '/';
+    }
     
+    fp = fopen(path, "w");
     if(!fp) {
         LOGE("file_save, fopen %s failed\n", path);
         return -1;

+ 1 - 0
f407/applications/fs.h

@@ -18,6 +18,7 @@ typedef struct {
 }buf_t;
 
 int fs_mount(char *dev, int flag);
+int fs_mkdir(char *path);
 int fs_length(char* path);
 int fs_exist(char* path);
 int fs_save(char *path, void *buf, int len);

+ 4 - 1
f407/applications/paras.c

@@ -3080,7 +3080,10 @@ static int ini_reset(paras_handle_t *h)
 
     fprintf(fp, "[misc]\n");
     fprintf(fp, "watchdog    = \"%d\"\n", p->misc.watchdog);
-    fprintf(fp, "fliptime    = \"%d\"\n", p->misc.flip_time);
+    fprintf(fp, "flip_time   = \"%d\"\n", p->misc.flip_time);
+    fprintf(fp, "led         = \"%d\"\n", p->misc.led);
+    fprintf(fp, "beep        = \"%d\"\n", p->misc.beep);
+    fprintf(fp, "rotate      = \"%d\"\n", p->misc.rotate);
     fprintf(fp, "\n");
 
     fclose(fp);

+ 3 - 1
f407/applications/power.c

@@ -747,7 +747,7 @@ int power_init(void)
     h->brd_max = BRD_NUM;
     h->prod = &paras_get()->prod;
     power_scan();
-    //power_set_all_sw(1);
+    
     thread_start(THREAD_ID_POWER, power_thread, h);
     return 0;
 }
@@ -838,6 +838,7 @@ static int power_map(power_handle_t *h, int chs)
                 if(pbrd) {
                     for(j=0; j<pbrd->chs; j++) {
                         h->pch[idx] = &h->pbrd[i]->pch[j];
+                        h->pch[idx]->pbrd = h->pbrd[i];
                         sprintf(h->pch[idx]->info.name, "CH%d", idx);
                         idx++;
                     }
@@ -910,6 +911,7 @@ int power_scan(void)
                 return -1;
             }
             
+            pbrd->fn = board_fn;
             pbrd->type = pkey->type;
             pbrd->chs  = pkey->chs;
             pbrd->addr = i;

+ 7 - 0
f407/applications/sys.c

@@ -76,9 +76,16 @@ static int sd_mount(void)
     }
     return r;
 }
+static void mk_dir(void)
+{
+    fs_mkdir("/cfg");
+}
+
+
 int sys_init(void)
 {
     sd_mount();
+    mk_dir();
     paras_init();
     
     //thread_start(THREAD_ID_POLL, poll_thread, NULL);

+ 2 - 2
f407/applications/web.c

@@ -87,7 +87,7 @@ static int ws_send(mg_conn_t *c, void *data, int len, int isbin)
     if(!c || !data || len<=0) {
         return -1;
     }
-    LOGD("____ws_send, len: %d\n", len);
+    //LOGD("____ws_send, len: %d\n", len);
     
 #ifdef USE_MG716
     mg_ws_send(c, data, len, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT);
@@ -309,7 +309,7 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
                 }
             }
             else {
-                LOGD("_____ send_powerc\n");
+                //LOGD("_____ send_powerc\n");
                 if(hdr->addr!=0) {
                     //cascade_reinit(MODBUS_SLAVE, hdr->addr, 115200);
                 }