Quellcode durchsuchen

整理理控制板升级接口

guohui vor 1 Jahr
Ursprung
Commit
8612fbca4d
10 geänderte Dateien mit 386 neuen und 342 gelöschten Zeilen
  1. 1 274
      pro/src/app.c
  2. 4 7
      pro/src/appweb_handle.c
  3. 0 20
      pro/src/switch_ctrl.c
  4. 2 9
      pro/src/switch_ctrl.h
  5. 3 11
      pro/src/sys.c
  6. 1 0
      pro/src/thread.c
  7. 2 1
      pro/src/thread.h
  8. 364 17
      pro/src/upg.c
  9. 7 1
      pro/src/upg.h
  10. 2 2
      pro/src/websocket_handle.c

+ 1 - 274
pro/src/app.c

@@ -30,278 +30,6 @@
 #include "pduMIB_trap.h"
 
 
-#include "file.h"
-#define REG_UPG_READ        1501
-#define REG_UPG_CHECK       1502
-#define REG_UPG_WRITE       1550
-#pragma pack (1)
-typedef struct {
-    int16_t   pid;
-    uint16_t  dlen;
-    uint8_t   data[0];
-}upg_pkt_t;
-#pragma pack ()
-
-static void mem_swap(void *buf, int len)
-{
-    int i;
-    uint8_t tmp,*pbuf=(uint8_t*)buf;
-    for(i=0; i<len; i+=2) {
-        tmp = pbuf[i];
-        pbuf[i] = pbuf[i+1];
-        pbuf[i+1] = tmp;
-    }
-}
-
-static int mb_get_timeout(Modbus_Manger *mm)
-{
-    int r,timeout=0;;
-    r = g_modbus_get_timeout(mm, &timeout);
-    if(r) {
-        return -1;
-    }
-    return timeout;
-}
-static int mb_set_timeout(Modbus_Manger *mm, int timeout)
-{
-    return g_modbus_set_timeout(mm, timeout);
-}
-static int mb_read(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data, int len)
-{
-    int r,cnt=(len+len%2)/2;
-
-    r = g_modbus_read_x_reg(mm, addr, reg, cnt, data);
-    if(r>0) mem_swap(data, r*2);
-    return r;
-
-}
-static int mb_write(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data, int len)
-{
-    int r,cnt=(len+len%2)/2;
-    return g_modbus_write_x_reg(mm, addr, reg, cnt, data);
-}
-///////////////////////////////////////////////////////////////////////
-enum {
-    ONLINE=0,
-    OFFLINE,
-    UPGRADING,
-    UPGRADE_OK,
-    UPGRADE_FAIL,
-};
-typedef struct {
-    char path[200]; int  flag;
-}upgrade_arg_t;
-static upgrade_arg_t upg_arg;
-static board_list_t brd_list={0},upg_list={0};
-board_list_t *board_upgrade_list_get(void)
-{
-    return &upg_list;
-}
-int board_upgrade_list_set(char *s)
-{
-    int i=0,n=0,max=0;
-    char tmp[10],*p=s;
-    char *tok="productId=";
-    board_list_t *l=&upg_list;
-
-    if(!s) {
-        return -1;
-    }
-    memset(l, 0, sizeof(board_list_t));
-
-    max = sizeof(l->info)/sizeof(l->info[0]);
-    p = strstr(p, tok);
-    if(!p) {
-        return -1;
-    }
-
-    while(1) {
-        if((*p)==',' || (*p)=='&') {
-            tmp[i] = 0;
-            l->info[n].addr = atoi(tmp);
-            i = 0; n++;
-
-            if((*p)=='&' || n>=max) {
-                break;
-            }
-        }
-        else {
-            tmp[i++] = *p;
-        }
-        p++;
-    }
-    l->cnt = n;
-
-    return (n>0)?0:-1;
-}
-int board_upgrade_status_set(int addr, int status)
-{
-    int r=-1;
-    board_list_t *l=&upg_list;
-    for(int i=0; i<l->cnt; i++) {
-        if(addr>0) {
-            if(l->info[i].addr==addr) {
-                l->info[i].status = status;
-                r = 0;
-            }
-        }
-        else {
-            l->info[i].status = status;
-            r = 0;
-        }
-    }
-    return r;
-}
-int board_list_get(board_list_t *list)
-{
-    int r,max=0,addr,cnt=0;
-    board_list_t *l=&brd_list;
-    GlobalDeviceManager *dm=&__globalDeviceManage;
-    Modbus_Manger *mm=&dm->_globalRelaySampManger;
-    GlobalPowerManger *tmp,*hd=&dm->_globalPowerManger;
-    switch_info_t swinfo;
-
-    memset(l, 0, sizeof(board_list_t));
-    max = sizeof(l->info)/sizeof(l->info[0]);
-    list_for_each_entry(tmp,&hd->list,list) {
-        if(tmp->product_saddr>0) {
-            board_info_t *info=&l->info[l->cnt];
-            addr = tmp->product_saddr;
-            r = g_switch_get_board_info(mm, addr, &swinfo);
-            if(r==0) {
-                info->addr = addr;
-                info->brd_id = swinfo.id[0];
-                info->channels = swinfo.channels;
-                strcpy(info->date, swinfo.date);
-                strcpy(info->ver, swinfo.ver);
-                sprintf(info->name, "PowerBoard %d", l->cnt+1);
-
-                l->cnt++;
-                if(l->cnt>=max) break;
-            }
-        }
-    }
-    if(list) *list = *l;
-
-    return 0;
-}
-
-static int upgrade_send(Modbus_Manger *mm, uint16_t addr, char *data, int dlen)
-{
-    int r,pid=0;
-    int slen=0,onelen=0,onemax=128;
-    char temp[400];
-
-    upg_pkt_t *pkt=(upg_pkt_t*)temp;
-    while(1) {
-        if((slen+onemax)>=dlen) {
-            //onelen = dlen-(slen+onemax);
-            onelen = onemax;
-            pid = -1;
-        }
-        else {
-            onelen = onemax;
-        }
-        memcpy(pkt->data, data+slen, onelen);
-        pkt->pid = pid;
-        pkt->dlen = onelen;
-        r = mb_write(mm, addr, REG_UPG_WRITE, pkt, onelen+sizeof(upg_pkt_t));
-        slen += onelen;
-        if(pid) usleep(100000);
-
-        if(pid<0) break;
-        pid++;
-    }
-
-    return 0;
-}
-static int upgrade_check(Modbus_Manger *mm, uint16_t addr)
-{
-    char temp[300];
-
-    upg_pkt_t *pkt=(upg_pkt_t*)temp;
-    while(1) {
-        mb_read(mm, addr, REG_UPG_READ, pkt, sizeof(upg_pkt_t));
-        if(pkt->dlen>0) {
-            return 0;
-        }
-    }
-    return -1;
-}
-static int upgrade_proc(char *path, Modbus_Manger *mm)
-{
-    int i,j,r,timeout;
-    buf_t fbuf;
-    GlobalDeviceManager *dm=&__globalDeviceManage;
-
-    #define RETRY_MAX  3
-
-    r = file_load(path, &fbuf);
-    if(r) {
-        return -1;
-    }
-    
-    timeout = mb_get_timeout(mm);
-    mb_set_timeout(mm, 10);
-
-    board_upgrade_status_set(-1, UPGRADING);
-    //broadcase upgrade file
-    upgrade_send(mm, 0, fbuf.buf, fbuf.dlen);
-    for(i=1; i<=dm->brdMax; i++) {
-        if(dm->pCtrlBoard[i].product_saddr==0) {
-            continue;
-        }
-
-        for(j=0; j<RETRY_MAX; j++) {
-            r = upgrade_check(mm, i);
-            if(r==0) break;
-            upgrade_send(mm, i, fbuf.buf, fbuf.dlen);
-        }
-
-        if(r) {
-            board_upgrade_status_set(i, UPGRADE_FAIL);
-        }
-        else {
-            board_upgrade_status_set(i, UPGRADE_OK);
-        }
-    }
-    free(fbuf.buf);
-    mb_set_timeout(mm, timeout);
-
-    return 0;
-}
-static void* upgrade_thread(void *arg)
-{
-    int r;
-    upgrade_arg_t *parg=(upgrade_arg_t*)arg;
-    GlobalDeviceManager *dm=&__globalDeviceManage;
-    Modbus_Manger *mm=&dm->_globalRelaySampManger;
-
-    thread_stop(THREAD_ID_SNMP);
-    thread_stop(THREAD_ID_POWER);
-    
-    r = upgrade_proc(parg->path, mm);
-
-    thread_restart(THREAD_ID_SNMP);
-    thread_restart(THREAD_ID_POWER);
-    
-    file_remove(parg->path);
-    parg->flag = 0;
-
-    pthread_exit(NULL);
-}
-int board_upgrade(char *path)
-{
-    if(upg_arg.flag==1) {
-        return -1;
-    }
-    strcpy(upg_arg.path,path);
-    upg_arg.flag = 1;
-
-    thread_start_simp(upgrade_thread, &upg_arg, 4*MB);
-    return 0;
-}
-
 
 static void* power_thread(void* arg)
 {
@@ -2522,9 +2250,8 @@ int app_init(void)
     websocket_init();
     appweb_init();
 
-    dev_Alarm_Run_message(_globalDeviceManager,language_alarm_Init_Success[0],"Server Thread");
-    //通知smartUPG,app已经运行起来
     upg_init();
+    dev_Alarm_Run_message(_globalDeviceManager,language_alarm_Init_Success[0],"Server Thread");
     
     return 0;
 }

+ 4 - 7
pro/src/appweb_handle.c

@@ -386,7 +386,7 @@ static int file_io(void *conn, int ftype, int io, char *buf)
                 r = upload_file(conn, path);
                 if(r==0) {
                     printf("_____ upg_start\n");
-                    upg_start();
+                    upg_host_send(UPGRADE_EVT_UPLOAD_FINISH);
                 }
             }
         }
@@ -5784,9 +5784,6 @@ static void equipmentMintenanceExport(void *conn)
         file_io(conn, FILE_SYS_CFG, FILE_EXPORT, NULL);
     }
 }
-extern int board_upgrade_list_set(char *s);
-extern int board_list_get(board_list_t *list);
-extern int board_upgrade(char *path);
 
 static void controlBoardUpgrade(void *conn)
 {
@@ -5799,7 +5796,7 @@ static void controlBoardUpgrade(void *conn)
         board_info_t info;
         board_list_t list;
 
-        board_list_get(&list);
+        upg_board_all_get(&list);
         ack_str = board_to_json(&list);
         
         http_reply(conn, 200, ack_str);
@@ -5819,10 +5816,10 @@ static void controlBoardUpgradeUpload(void *conn)
         sprintf(path, "%s/%s", DOWN_FOLDER, "fw.upg");
         r = upload_file(conn, path);
         if(r==0) {
-            board_upgrade_list_set(hm->uri.buf);
+            upg_board_list_set(hm->uri.buf);
 
             printf("_____ board upgrade now ...\n");
-            board_upgrade(path);
+            upg_board_start(path);
         }
     }
 }

+ 0 - 20
pro/src/switch_ctrl.c

@@ -3239,23 +3239,3 @@ int g_switch_get_t_ac_breaker_info(void* manger,int saddr,GlobalBreakerManager*
     return 0;
 }
 
-
-////////////////////upgrade///////////////////////////////////
-int g_switch_get_upgrade(void* manger, int addr)
-{
-    int timeout=0;
-    g_modbus_get_timeout(manger, &timeout);
-    g_modbus_set_timeout(manger, 20);
-
-    g_modbus_set_timeout(manger, timeout);
-    return 0;
-}
-int g_switch_set_upgrade(void* manger, int addr)
-{
-    return 0;
-}
-int g_switch_get_board_info(void* manger, int addr, switch_info_t *info)
-{
-    return 0;
-}
-

+ 2 - 9
pro/src/switch_ctrl.h

@@ -209,13 +209,6 @@ int g_switch_get_t_ac_breaker_info(void* manger,int saddr,GlobalBreakerManager*
 int ResetChmData(int nCtrlType);
 
 //upgrade interface
-typedef struct {
-    uint32_t id[3];
-    uint32_t channels;
-    char ver[8];
-    char date[20];
-}switch_info_t;
-int g_switch_get_upgrade(void* manger, int addr);
-int g_switch_set_upgrade(void* manger, int addr);
-int g_switch_get_board_info(void* manger, int addr, switch_info_t *info);
+
+
 #endif

+ 3 - 11
pro/src/sys.c

@@ -242,7 +242,7 @@ static int get_ipaddr(int family, char *iface, char *addr, char *netmask)
 
                 if(addr) {
                     inet_ntop(family, &sa->sin_addr, addr, INET6_ADDRSTRLEN);
-                    printf("___addr: %s\n", addr);
+                    //printf("___addr: %s\n", addr);
                 }
 
                 if(netmask) {
@@ -1325,16 +1325,6 @@ static int wdog_init(void)
 
     return r;
 }
-static int wdog_enable(int en)
-{
-    int r=0;
-
-#ifdef USE_WDOG
-    int option = en?WDIOS_ENABLECARD:WDIOS_DISABLECARD;
-    r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
-#endif
-    return r;
-}
 static int wdog_feed(void)
 {
     int r=0,t1=200,t2=0;
@@ -1355,6 +1345,8 @@ static int wdog_feed(void)
 static void sig_handler(int signo)
 {
     printf("sigint_handler, signo: %d\n", signo);
+    //wdog_enable(0);
+
 }
 static void sig_init(void)
 {

+ 1 - 0
pro/src/thread.c

@@ -19,6 +19,7 @@ static thread_attr_t thdAttrs[THREAD_ID_MAX]={
     {"mqtt",        NULL,           NULL,           8*MB,           1},
     {"mail",        NULL,           NULL,           8*MB,           1},
     {"modbus_tcp",  NULL,           NULL,           8*MB,           1},
+    {"board",       NULL,           NULL,           8*MB,           1},
 };
 static thread_handle_t thdHandles[THREAD_ID_MAX]={0};
 

+ 2 - 1
pro/src/thread.h

@@ -30,8 +30,9 @@ enum {
     THREAD_ID_MQTT,
     THREAD_ID_MAIL,
     THREAD_ID_TCP,
+    THREAD_ID_BOARD,        //board upgrade
     
-    THREAD_ID_MAX=30
+    THREAD_ID_MAX
 };
 
 typedef void *(*thread_fn)(void *arg);

+ 364 - 17
pro/src/upg.c

@@ -4,22 +4,297 @@
 #include <sys/msg.h>
 #include "elog.h"
 #include "upg.h"
+#include "file.h"
+#include "thread.h"
+#include "modbus_handle.h"
+
 
 #if 1
-#define LOGD  log_d
-#define LOGE  log_e
+    #define LOGD  log_d
+    #define LOGE  log_e
 #else
-#define LOGD  printf
-#define LOGE  printf
+    #define LOGD  printf
+    #define LOGE  printf
 #endif
 
-static key_t ukey=0;
-static int upg_send(int evt)
+#define RETRY_MAX           3
+
+#define REG_UPG_READ        1501
+#define REG_UPG_WRITE       1550
+
+#define REG_UPG_JUMP        6330
+#define REG_BOARD_INFO      6331
+
+enum {
+    ONLINE=0,
+    OFFLINE,
+    UPGRADING,
+    UPGRADE_OK,
+    UPGRADE_FAIL,
+};
+
+#pragma pack (1)
+typedef struct {
+    int16_t   pid;
+    uint16_t  dlen;
+    uint8_t   data[0];
+}upg_pkt_t;
+#pragma pack ()
+
+#pragma pack (2)
+typedef struct {
+    uint32_t id[3];
+    uint32_t channels;
+    char ver[8];
+    char date[20];
+}switch_info_t;
+#pragma pack ()
+
+typedef struct {
+    int  flag;
+    char path[200];
+}upg_arg_t;
+
+typedef struct {
+    key_t        key;
+    upg_arg_t    arg;
+    board_list_t upg;
+    board_list_t all;
+    GlobalDeviceManager *dm;
+
+}upg_handle_t;
+static upg_handle_t uHandle={0};
+
+static int upg_board_scan(void);
+static void* board_thread(void *arg);
+
+
+static void mem_swap(void *buf, int len)
+{
+    int i;
+    uint8_t tmp,*pbuf=(uint8_t*)buf;
+    for(i=0; i<len; i+=2) {
+        tmp = pbuf[i];
+        pbuf[i] = pbuf[i+1];
+        pbuf[i+1] = tmp;
+    }
+}
+static int mb_get_timeout(Modbus_Manger *mm)
+{
+    int r,timeout=0;;
+    r = g_modbus_get_timeout(mm, &timeout);
+    if(r) {
+        return -1;
+    }
+    return timeout;
+}
+static int mb_set_timeout(Modbus_Manger *mm, int timeout)
+{
+    return g_modbus_set_timeout(mm, timeout);
+}
+static int mb_read(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data, int len)
+{
+    int r,cnt=(len+len%2)/2;
+
+    r = g_modbus_read_x_reg(mm, addr, reg, cnt, data);
+    if(r>0) mem_swap(data, r*2);
+    return (r==cnt)?0:-1;
+
+}
+static int mb_write(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data, int len)
+{
+    int r,cnt=(len+len%2)/2;
+    r = g_modbus_write_x_reg(mm, addr, reg, cnt, data);
+    return (r==cnt)?0:-1;
+}
+//////////////////////////////////////////////////////////////////////
+
+static int board_is_upgrading(void* manger, int addr)
+{
+    uint16_t tmp;
+    int r,timeout=0;
+
+    timeout = mb_get_timeout(manger);
+    mb_set_timeout(manger, 20);
+    r = mb_write(manger, addr, REG_UPG_READ, &tmp, sizeof(tmp));
+    mb_set_timeout(manger, timeout);
+
+    return r;
+}
+static int board_upgrade_set(void* manger, int addr)
+{
+    int r;
+    uint16_t tmp=1;
+
+    r = mb_write(manger, addr, REG_UPG_JUMP, &tmp, 1);
+    return r;
+}
+static int board_get_info(void* manger, int addr, switch_info_t *info)
+{
+    int r;
+    r = mb_read(manger, addr, REG_BOARD_INFO, info, sizeof(switch_info_t));
+    return r;
+}
+static int board_status_set(int addr, int status)
+{
+    int r=-1;
+    board_list_t *l=&uHandle.upg;
+
+    for(int i=0; i<l->cnt; i++) {
+        if(addr>0) {
+            if(l->info[i].addr==addr) {
+                l->info[i].status = status;
+                r = 0;
+            }
+        }
+        else {
+            l->info[i].status = status;
+            r = 0;
+        }
+    }
+    return r;
+}
+static int board_send(Modbus_Manger *mm, uint16_t addr, char *data, int dlen)
+{
+    int r,pid=0;
+    int slen=0,onelen=0,onemax=128;
+    char temp[400];
+
+    upg_pkt_t *pkt=(upg_pkt_t*)temp;
+    r = board_upgrade_set(mm, addr);
+    while(1) {
+        if((slen+onemax)>=dlen) {
+            //onelen = dlen-(slen+onemax);
+            onelen = onemax;
+            pid = -1;
+        }
+        else {
+            onelen = onemax;
+        }
+        memcpy(pkt->data, data+slen, onelen);
+        pkt->pid = pid;
+        pkt->dlen = onelen;
+        r = mb_write(mm, addr, REG_UPG_WRITE, pkt, onelen+sizeof(upg_pkt_t));
+        slen += onelen;
+        if(pid==0) usleep(100000);
+        else       usleep(100000);
+
+        if(pid<0) break;
+        pid++;
+    }
+
+    return 0;
+}
+static int board_check(Modbus_Manger *mm, uint16_t addr)
+{
+    int r;
+    switch_info_t info;
+
+    r = mb_read(mm, addr, REG_BOARD_INFO, &info, sizeof(info));
+    if(r==0) {
+        LOGD("___board %d ver: %s\n", info.ver);
+        LOGD("___board %d date: %s\n", info.date);
+    }
+    return r;
+}
+static int board_proc(upg_handle_t *h, int quit)
+{
+    buf_t fbuf;
+    int i,j,r,timeout;
+    Modbus_Manger *mm=&h->dm->_globalRelaySampManger;
+
+    r = file_load(h->arg.path, &fbuf);
+    if(r) {
+        return -1;
+    }
+    
+    timeout = mb_get_timeout(mm);
+    mb_set_timeout(mm, 10);
+
+    board_status_set(-1, UPGRADING);
+    //broadcase upgrade file
+    board_send(mm, 1, fbuf.buf, fbuf.dlen);
+    for(i=1; i<=h->dm->brdMax; i++) {
+        if(h->dm->pCtrlBoard[i].product_saddr==0) {
+            continue;
+        }
+
+        for(j=0; j<RETRY_MAX; j++) {
+            r = board_check(mm, i);
+            if(r==0) break;
+            LOGE("___ board upgrade failed, retry %d\n", i);
+            board_send(mm, i, fbuf.buf, fbuf.dlen);
+        }
+
+        if(r) {
+            board_status_set(i, UPGRADE_FAIL);
+        }
+        else {
+            board_status_set(i, UPGRADE_OK);
+        }
+    }
+    free(fbuf.buf);
+    mb_set_timeout(mm, timeout);
+
+    return 0;
+}
+static int board_scan(void)
+{
+    return 0;
+}
+static void* board_thread(void *arg)
+{
+    int r;
+    thread_handle_t *th=(thread_handle_t*)arg;
+    upg_handle_t *h=(upg_handle_t*)th->arg;
+    Modbus_Manger *mm=&h->dm->_globalRelaySampManger;
+
+    while(th->quit==0) {
+        if(h->arg.flag) {
+            thread_stop(THREAD_ID_SNMP);
+            thread_stop(THREAD_ID_POWER);
+            
+            r = board_proc(h, th->quit);
+
+            thread_restart(THREAD_ID_SNMP);
+            thread_restart(THREAD_ID_POWER);
+            
+            file_remove(h->arg.path);
+            h->arg.flag = 0;
+        }
+        else {
+            sleep(2);
+        }
+    }
+
+    pthread_exit(NULL);
+}
+/////////////////////////////////////////////////////
+int upg_init(void)
+{
+    int r,msgid;
+    upg_handle_t *h=&uHandle;
+    
+    memset(h, 0, sizeof(upg_handle_t));
+    h->dm = &__globalDeviceManage;
+
+    h->key = ftok(UPG_KEY_PATH, UPG_KEY_SN);
+    if(h->key<0) {
+        LOGE("ftok %s failed, errno: %d\n", UPG_KEY_PATH, errno);
+        return -1;
+    }
+    thread_start(THREAD_ID_BOARD, board_thread, h);
+    
+    return upg_host_send(UPGRADE_EVT_APP_RUNNING);
+}
+
+int upg_host_send(int evt)
 {
     int r,msgid;
     msgbuf_t mb;
+    upg_handle_t *h=&uHandle;
 
-    msgid = msgget(ukey, 0666| IPC_CREAT);
+    msgid = msgget(h->key, 0666|IPC_CREAT);
     //LOGD("+++++++++++ key: %d, msgid: %d\n", ukey, msgid);
     
     mb.evt = evt;
@@ -35,22 +310,94 @@ static int upg_send(int evt)
 }
 
 
-int upg_init(void)
+/////////////////////////////////////////////////////////
+board_list_t *upg_board_list_get(void)
 {
-    int r,msgid;
-    
-    ukey = ftok(UPG_KEY_PATH, UPG_KEY_SN);
-    if(ukey<0) {
-        LOGE("ftok %s failed, errno: %d\n", UPG_KEY_PATH, errno);
+    upg_handle_t *h=&uHandle;
+
+    return &h->upg;
+}
+
+int upg_board_list_set(char *s)
+{
+    int i=0,n=0,max=0;
+    char tmp[10],*p=s;
+    char *tok="productId=";
+    board_list_t *l=&uHandle.upg;
+
+    if(!s) {
         return -1;
     }
-    
-    return upg_send(UPGRADE_EVT_APP_RUNNING);
+    memset(l, 0, sizeof(board_list_t));
+
+    max = sizeof(l->info)/sizeof(l->info[0]);
+    p = strstr(p, tok);
+    if(!p) {
+        return -1;
+    }
+
+    while(1) {
+        if((*p)==',' || (*p)=='&') {
+            tmp[i] = 0;
+            l->info[n].addr = atoi(tmp);
+            i = 0; n++;
+
+            if((*p)=='&' || n>=max) {
+                break;
+            }
+        }
+        else {
+            tmp[i++] = *p;
+        }
+        p++;
+    }
+    l->cnt = n;
+
+    return (n>0)?0:-1;
 }
 
+int upg_board_all_get(board_list_t *l)
+{
+    int r,max=0,addr,cnt=0;
+    upg_handle_t *h=&uHandle;
+    Modbus_Manger *mm=&h->dm->_globalRelaySampManger;
+    GlobalPowerManger *tmp,*hd=&h->dm->_globalPowerManger;
+    switch_info_t swinfo;
+
+    memset(l, 0, sizeof(board_list_t));
+    max = sizeof(l->info)/sizeof(l->info[0]);
+    list_for_each_entry(tmp,&hd->list,list) {
+        if(tmp->product_saddr>0) {
+            board_info_t *info=&l->info[l->cnt];
+            addr = tmp->product_saddr;
+            r = board_get_info(mm, addr, &swinfo);
+            if(r==0) {
+                info->addr = addr;
+                info->brd_id = swinfo.id[0];
+                info->channels = swinfo.channels;
+                strcpy(info->date, swinfo.date);
+                strcpy(info->ver, swinfo.ver);
+                sprintf(info->name, "PowerBoard %d", l->cnt+1);
+
+                l->cnt++;
+                if(l->cnt>=max) break;
+            }
+        }
+    }
+
+    return 0;
+}
 
-int upg_start(void)
+int upg_board_start(char *path)
 {
-	return upg_send(UPGRADE_EVT_UPLOAD_FINISH);
+    upg_handle_t *h=&uHandle;
+
+    if(h->arg.flag==1) {
+        return -1;
+    }
+    strcpy(h->arg.path,path);
+    h->arg.flag = 1;
+
+    return 0;
 }
 

+ 7 - 1
pro/src/upg.h

@@ -2,9 +2,15 @@
 #define __UPG_Hx__
 
 #include "upgrade.h"
+#include "common.h"
 
 int upg_init(void);
-int upg_start(void);
+int upg_host_send(int evt);
+
+int upg_board_list_set(char *s);
+board_list_t *upg_board_list_get(void);
+int upg_board_all_get(board_list_t *l);
+int upg_board_start(char *path);
 
 #endif
 

+ 2 - 2
pro/src/websocket_handle.c

@@ -4,6 +4,7 @@
 #include "elog.h"
 #include "common.h"
 #include "sys.h"
+#include "upg.h"
 #include "lock.h"
 #include "file.h"
 #include "thread.h"
@@ -218,8 +219,7 @@ static int ws_breaker_update(ws_handle_t *h)
 
 static int ws_upg_update(ws_handle_t *h)
 {
-    extern board_list_t *board_upgrade_list_get(void);
-    board_list_t *l=board_upgrade_list_get();
+    board_list_t *l=upg_board_list_get();
 
     char* json = board_to_json(l);
     ws_send_data(h, json, strlen(json));