|
|
@@ -29,6 +29,8 @@
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
+//#define UPG_TEST
|
|
|
+
|
|
|
static void get_time(char *ts)
|
|
|
{
|
|
|
struct timeval tv;
|
|
|
@@ -69,14 +71,16 @@ static void db_ow_test(sqlite3 *db, int *index, int *index3)
|
|
|
}
|
|
|
|
|
|
#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;
|
|
|
uint8_t dlen;
|
|
|
uint8_t data[0];
|
|
|
}upg_pkt_t;
|
|
|
-
|
|
|
-#define REG_UPGRADE 0xff
|
|
|
-#define REG_CHECK 0xfe
|
|
|
+#pragma pack ()
|
|
|
|
|
|
static void mem_swap(void *buf, int len)
|
|
|
{
|
|
|
@@ -117,7 +121,7 @@ static int upgrade_send(uint16_t addr, char *data, int dlen)
|
|
|
memcpy(pkt->data, data+slen, onelen);
|
|
|
pkt->pid = pid++;
|
|
|
pkt->dlen = onelen;
|
|
|
- mb_write(addr, REG_UPGRADE, data+slen, onelen+sizeof(upg_pkt_t));
|
|
|
+ mb_write(addr, REG_UPG_WRITE, data+slen, onelen+sizeof(upg_pkt_t));
|
|
|
slen += onelen;
|
|
|
}
|
|
|
|
|
|
@@ -129,7 +133,7 @@ static int upgrade_check(uint16_t addr)
|
|
|
|
|
|
upg_pkt_t *pkt=(upg_pkt_t*)temp;
|
|
|
while(1) {
|
|
|
- mb_read(addr, REG_CHECK, pkt, sizeof(upg_pkt_t));
|
|
|
+ mb_read(addr, REG_UPG_READ, pkt, sizeof(upg_pkt_t));
|
|
|
if(pkt->dlen>0) {
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -137,19 +141,16 @@ static int upgrade_check(uint16_t addr)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-int power_upgrade(char *path)
|
|
|
+static int upgrade_proc(char *path)
|
|
|
{
|
|
|
int i,j,r;
|
|
|
buf_t fbuf;
|
|
|
- int slen=0,onelen=0,onemax=200;
|
|
|
+ int slen=0,onelen=0,onemax=128;
|
|
|
GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
GlobalPowerCtrlBoard *pboard=dm->_all_ctrl_board;
|
|
|
|
|
|
#define RETRY_MAX 3
|
|
|
|
|
|
- thread_stop(THREAD_ID_SNMP);
|
|
|
- thread_stop(THREAD_ID_POWER);
|
|
|
-
|
|
|
r = file_load(path, &fbuf);
|
|
|
if(r) {
|
|
|
return -1;
|
|
|
@@ -170,13 +171,45 @@ int power_upgrade(char *path)
|
|
|
}
|
|
|
|
|
|
free(fbuf.buf);
|
|
|
- thread_start(THREAD_ID_SNMP, dm);
|
|
|
- thread_start(THREAD_ID_POWER, dm);
|
|
|
-
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
+int power_upgrade(char *path)
|
|
|
+{
|
|
|
+ int r;
|
|
|
+
|
|
|
+ thread_stop(THREAD_ID_SNMP);
|
|
|
+ thread_stop(THREAD_ID_POWER);
|
|
|
+
|
|
|
+ r = upgrade_proc(path);
|
|
|
+
|
|
|
+ thread_restart(THREAD_ID_SNMP);
|
|
|
+ thread_restart(THREAD_ID_POWER);
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void upg_test(void)
|
|
|
+{
|
|
|
+ int r;
|
|
|
+ #define UPG_FILE "/root/dl/fw.upg"
|
|
|
+
|
|
|
+#ifdef UPG_TEST
|
|
|
+ r = g_modbus_init(&_globalDeviceManager->_globalRelaySampManger,
|
|
|
+ INTERL_MODBUS_PORT,
|
|
|
+ INTERL_MODBUS_BAUD,
|
|
|
+ MASTER_MODE,
|
|
|
+ 0,
|
|
|
+ "relay",1);
|
|
|
+
|
|
|
+ upgrade_proc(UPG_FILE);
|
|
|
+ exit(0);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
void* power_thread(void* arg)
|
|
|
{
|
|
|
@@ -1854,9 +1887,8 @@ void* snmp_thread(void *arg)
|
|
|
|
|
|
|
|
|
/// @brief 全局结构体初始化
|
|
|
-/// @param _globalDeviceManager
|
|
|
/// @return
|
|
|
-int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
|
|
|
+int app_init(void)
|
|
|
{
|
|
|
int ret = 0 ;
|
|
|
int type = 0 ;
|
|
|
@@ -1865,7 +1897,10 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
|
|
|
int io_thread_flag = 0 ;
|
|
|
int sensor_thread_flag = 0 ;
|
|
|
int nTac_chn=0;
|
|
|
-
|
|
|
+ GlobalDeviceManager* _globalDeviceManager=&__globalDeviceManage;
|
|
|
+
|
|
|
+ upg_test();
|
|
|
+
|
|
|
INIT_LIST_HEAD(&_GlobalUserLoginInfo.list);
|
|
|
INIT_LIST_HEAD(&_globalDeviceManager->_globalPowerManger.list);
|
|
|
INIT_LIST_HEAD(&_globalDeviceManager->_globalPowerManger.list_Tree_AC);
|