|
|
@@ -50,7 +50,7 @@ typedef struct {
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
- int flag;
|
|
|
+ int upging;
|
|
|
char path[200];
|
|
|
}upg_arg_t;
|
|
|
|
|
|
@@ -102,7 +102,18 @@ static int mb_write(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data,
|
|
|
return (r==cnt)?0:-1;
|
|
|
}
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
-#define UPG_RW_TIMEOUT 50
|
|
|
+#define UPG_RW_TIMEOUT 200
|
|
|
+static void sw_to_info(int addr, board_info_t *info, switch_info_t *swinfo, int status)
|
|
|
+{
|
|
|
+ info->addr = addr;
|
|
|
+ info->brd_id = swinfo->id[0];
|
|
|
+ info->channels = swinfo->channels;
|
|
|
+ info->status = status;
|
|
|
+
|
|
|
+ strcpy(info->name, "Board");
|
|
|
+ strcpy(info->ver, swinfo->ver);
|
|
|
+ get_bldtime2(info->date, swinfo->date);
|
|
|
+}
|
|
|
static int board_is_upgrading(Modbus_Manger* mm, int addr)
|
|
|
{
|
|
|
int r;
|
|
|
@@ -111,7 +122,7 @@ static int board_is_upgrading(Modbus_Manger* mm, int addr)
|
|
|
r = mb_read(mm, addr, REG_UPG_READ, &tmp, sizeof(tmp), UPG_RW_TIMEOUT);
|
|
|
return (r==0)?1:0;
|
|
|
}
|
|
|
-static int board_upgrade_set(Modbus_Manger* mm, int addr)
|
|
|
+static int board_upgrade_jump(Modbus_Manger* mm, int addr)
|
|
|
{
|
|
|
int r;
|
|
|
uint16_t tmp=1;
|
|
|
@@ -130,7 +141,7 @@ static int board_get_info(Modbus_Manger* mm, int addr, switch_info_t *info)
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
-static int set_status(handle_t l, node_t *nd, node_t *xd, void *arg, int *act)
|
|
|
+static int set_info(handle_t l, node_t *nd, node_t *xd, void *arg, int *act)
|
|
|
{
|
|
|
board_info_t *info1=(board_info_t*)nd->buf;
|
|
|
board_info_t *info2=(board_info_t*)xd->buf;
|
|
|
@@ -142,7 +153,7 @@ static int set_status(handle_t l, node_t *nd, node_t *xd, void *arg, int *act)
|
|
|
else {
|
|
|
if(info1->addr==info2->addr) {
|
|
|
*act = LIST_ACT_STOP;
|
|
|
- info2->status = info1->status;
|
|
|
+ *info2 = *info1;
|
|
|
return 0;
|
|
|
}
|
|
|
else {
|
|
|
@@ -150,20 +161,16 @@ static int set_status(handle_t l, node_t *nd, node_t *xd, void *arg, int *act)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-static int board_status_set(int addr, int status)
|
|
|
+static int board_info_set(board_info_t *info)
|
|
|
{
|
|
|
int r=-1;
|
|
|
- board_info_t tmp;
|
|
|
node_t node;
|
|
|
- handle_t *l=uHandle.upg;
|
|
|
-
|
|
|
- tmp.addr = addr;
|
|
|
- tmp.status = status;
|
|
|
+ handle_t l=uHandle.all;
|
|
|
|
|
|
- node.buf = &tmp;
|
|
|
- node.dlen = sizeof(tmp);
|
|
|
- node.blen = sizeof(tmp);
|
|
|
- r = xlist_iterator(l, &node, set_status, NULL);
|
|
|
+ node.buf = info;
|
|
|
+ node.dlen = sizeof(board_info_t);
|
|
|
+ node.blen = sizeof(board_info_t);
|
|
|
+ r = xlist_iterator(l, &node, set_info, NULL);
|
|
|
return r;
|
|
|
}
|
|
|
static int board_send(Modbus_Manger *mm, uint16_t addr, char *data, int dlen)
|
|
|
@@ -173,7 +180,7 @@ static int board_send(Modbus_Manger *mm, uint16_t addr, char *data, int dlen)
|
|
|
int slen=0,onelen=0,onemax=128;
|
|
|
|
|
|
upg_pkt_t *pkt=(upg_pkt_t*)temp;
|
|
|
- r = board_upgrade_set(mm, addr);
|
|
|
+ r = board_upgrade_jump(mm, addr);
|
|
|
while(1) {
|
|
|
if((slen+onemax)>=dlen) {
|
|
|
//onelen = dlen-(slen+onemax);
|
|
|
@@ -194,34 +201,37 @@ static int board_send(Modbus_Manger *mm, uint16_t addr, char *data, int dlen)
|
|
|
if(pid<0) break;
|
|
|
pid++;
|
|
|
}
|
|
|
+ sleep(1);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
static int board_proc(upg_handle_t *h, int quit)
|
|
|
{
|
|
|
- int err=0;
|
|
|
+ int ok=0,err=0;
|
|
|
buf_t fbuf;
|
|
|
int i,r,timeout;
|
|
|
switch_info_t swinfo;
|
|
|
handle_t l=h->upg;
|
|
|
list_node_t *ln=NULL;
|
|
|
- board_info_t *info;
|
|
|
+ board_info_t info,*tmp;
|
|
|
Modbus_Manger *mm=&h->dm->_globalRelaySampManger;
|
|
|
|
|
|
r = file_load(h->arg.path, &fbuf);
|
|
|
if(r) {
|
|
|
return -1;
|
|
|
}
|
|
|
- board_status_set(-1, UPGRADING);
|
|
|
+ info.addr = -1;
|
|
|
+ info.status = UPGRADING;
|
|
|
+ board_info_set(&info);
|
|
|
|
|
|
//broadcase upgrade file
|
|
|
board_send(mm, 0, fbuf.buf, fbuf.dlen);
|
|
|
while(1) {
|
|
|
r = xlist_get_node(l, &ln, 0);
|
|
|
if(r==0) {
|
|
|
- info = (board_info_t*)ln->data.buf;
|
|
|
+ tmp = (board_info_t*)ln->data.buf;
|
|
|
for(i=0; i<RETRY_MAX; i++) {
|
|
|
- r = board_get_info(mm, info->addr, &swinfo);
|
|
|
+ r = board_get_info(mm, tmp->addr, &swinfo);
|
|
|
if(r==0) {
|
|
|
break;
|
|
|
}
|
|
|
@@ -230,12 +240,16 @@ static int board_proc(upg_handle_t *h, int quit)
|
|
|
}
|
|
|
|
|
|
if(r) {
|
|
|
- board_status_set(i, UPGRADE_FAIL);
|
|
|
+ tmp->status = UPGRADE_FAIL;
|
|
|
err++;
|
|
|
}
|
|
|
else {
|
|
|
- board_status_set(i, UPGRADE_OK);
|
|
|
+ sw_to_info(tmp->addr, tmp, &swinfo, UPGRADE_OK);
|
|
|
+ ok++;
|
|
|
}
|
|
|
+ board_info_set(tmp);
|
|
|
+
|
|
|
+ xlist_remove(l, 0);
|
|
|
}
|
|
|
}
|
|
|
free(fbuf.buf);
|
|
|
@@ -289,17 +303,17 @@ static void* board_thread(void *arg)
|
|
|
Modbus_Manger *mm=&h->dm->_globalRelaySampManger;
|
|
|
|
|
|
board_scan();
|
|
|
- upg_board_update();
|
|
|
+ upg_board_all_update();
|
|
|
|
|
|
while(th->quit==0) {
|
|
|
- if(h->arg.flag) {
|
|
|
+ if(h->arg.upging) {
|
|
|
|
|
|
start_threads(0);
|
|
|
r = board_proc(h, th->quit);
|
|
|
start_threads(1);
|
|
|
|
|
|
file_remove(h->arg.path);
|
|
|
- h->arg.flag = 0;
|
|
|
+ h->arg.upging = 0;
|
|
|
}
|
|
|
else {
|
|
|
sleep(2);
|
|
|
@@ -381,6 +395,7 @@ int upg_board_list_set(char *s)
|
|
|
if(!p) {
|
|
|
return -1;
|
|
|
}
|
|
|
+ p += strlen(tok);
|
|
|
|
|
|
while(1) {
|
|
|
if((*p)==',' || (*p)=='&') {
|
|
|
@@ -406,22 +421,14 @@ int upg_board_list_set(char *s)
|
|
|
handle_t upg_board_all_get(void)
|
|
|
{
|
|
|
int r;
|
|
|
- list_node_t *ln=NULL;
|
|
|
upg_handle_t *h=&uHandle;
|
|
|
-
|
|
|
- if(h->arg.flag==0) {
|
|
|
- r = xlist_take_node(h->upg, &ln, 0);
|
|
|
- if(r==0) {
|
|
|
- xlist_append_node(h->all, ln);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return h->all;
|
|
|
}
|
|
|
|
|
|
-int upg_board_update(void)
|
|
|
+int upg_board_all_update(void)
|
|
|
{
|
|
|
- int r,max=0,addr,cnt=0;
|
|
|
+ int i,r,addr;
|
|
|
+ list_node_t *ln=NULL;
|
|
|
upg_handle_t *h=&uHandle;
|
|
|
handle_t l=h->all;
|
|
|
Modbus_Manger *mm=&h->dm->_globalRelaySampManger;
|
|
|
@@ -429,7 +436,7 @@ int upg_board_update(void)
|
|
|
switch_info_t swinfo;
|
|
|
board_info_t info;
|
|
|
|
|
|
- if(!h->init || h->arg.flag) {
|
|
|
+ if(!h->init) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -437,24 +444,25 @@ int upg_board_update(void)
|
|
|
list_for_each_entry(tmp,&hd->list,list) {
|
|
|
if(tmp->product_saddr>0) {
|
|
|
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;
|
|
|
- info.status = ONLINE;
|
|
|
-
|
|
|
- get_bldtime2(info.date, swinfo.date);
|
|
|
- //strcpy(info.date, swinfo.date);
|
|
|
- strcpy(info.ver, swinfo.ver);
|
|
|
- strcpy(info.name, "Board");
|
|
|
-
|
|
|
- xlist_append(l, 0, &info, sizeof(info));
|
|
|
- cnt++;
|
|
|
+ for(i=0; i<RETRY_MAX; i++) {
|
|
|
+ r = board_get_info(mm, addr, &swinfo);
|
|
|
+ if(r==0) {
|
|
|
+ sw_to_info(addr, &info, &swinfo, ONLINE);
|
|
|
+ xlist_append(l, 0, &info, sizeof(info));
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ while(1) {
|
|
|
+ r = xlist_take_node(h->upg, &ln, 0);
|
|
|
+ if(r) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ xlist_append_node(h->all, ln);
|
|
|
+ }
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -462,11 +470,11 @@ int upg_board_start(char *path)
|
|
|
{
|
|
|
upg_handle_t *h=&uHandle;
|
|
|
|
|
|
- if(h->arg.flag==1) {
|
|
|
+ if(h->arg.upging==1) {
|
|
|
return -1;
|
|
|
}
|
|
|
strcpy(h->arg.path,path);
|
|
|
- h->arg.flag = 1;
|
|
|
+ h->arg.upging = 1;
|
|
|
|
|
|
return 0;
|
|
|
}
|