|
|
@@ -29,8 +29,6 @@
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
-//#define UPG_TEST
|
|
|
-
|
|
|
static void get_time(char *ts)
|
|
|
{
|
|
|
struct timeval tv;
|
|
|
@@ -77,7 +75,7 @@ static void db_ow_test(sqlite3 *db, int *index, int *index3)
|
|
|
#pragma pack (1)
|
|
|
typedef struct {
|
|
|
int16_t pid;
|
|
|
- uint8_t dlen;
|
|
|
+ uint16_t dlen;
|
|
|
uint8_t data[0];
|
|
|
}upg_pkt_t;
|
|
|
#pragma pack ()
|
|
|
@@ -92,48 +90,56 @@ static void mem_swap(void *buf, int len)
|
|
|
pbuf[i+1] = tmp;
|
|
|
}
|
|
|
}
|
|
|
-static int mb_read(uint16_t addr, uint16_t reg, void *data, int len)
|
|
|
+static int mb_read(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data, int len)
|
|
|
{
|
|
|
- int r,cnt=len+len%2;
|
|
|
- GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
- Modbus_Manger *mm=&dm->_globalRelaySampManger;
|
|
|
+ int r,cnt=(len+len%2)/2;
|
|
|
|
|
|
- r = g_modbus_read_x_reg(mm, addr, reg, len+len%2, data);
|
|
|
+ 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(uint16_t addr, uint16_t reg, void *data, int len)
|
|
|
+static int mb_write(Modbus_Manger *mm, uint16_t addr, uint16_t reg, void *data, int len)
|
|
|
{
|
|
|
- GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
- Modbus_Manger *mm=&dm->_globalRelaySampManger;
|
|
|
- return g_modbus_write_x_reg(mm, addr, reg, len+len%2, data);
|
|
|
+ int r,cnt=(len+len%2)/2;
|
|
|
+ return g_modbus_write_x_reg(mm, addr, reg, cnt, data);
|
|
|
}
|
|
|
-static int upgrade_send(uint16_t addr, char *data, int dlen)
|
|
|
+static int upgrade_send(Modbus_Manger *mm, uint16_t addr, char *data, int dlen)
|
|
|
{
|
|
|
int r,pid=0;
|
|
|
- int slen=0,onelen=0,onemax=200;
|
|
|
+ int slen=0,onelen=0,onemax=128;
|
|
|
char temp[400];
|
|
|
|
|
|
upg_pkt_t *pkt=(upg_pkt_t*)temp;
|
|
|
while(1) {
|
|
|
- onelen = ((slen+onemax)>dlen)?(dlen-(slen+onemax)):onemax;
|
|
|
+ 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->pid = pid;
|
|
|
pkt->dlen = onelen;
|
|
|
- mb_write(addr, REG_UPG_WRITE, data+slen, onelen+sizeof(upg_pkt_t));
|
|
|
+ r = mb_write(mm, addr, REG_UPG_WRITE, pkt, onelen+sizeof(upg_pkt_t));
|
|
|
slen += onelen;
|
|
|
+ usleep(10000);
|
|
|
+
|
|
|
+ if(pid<0) break;
|
|
|
+ pid++;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int upgrade_check(uint16_t addr)
|
|
|
+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(addr, REG_UPG_READ, pkt, sizeof(upg_pkt_t));
|
|
|
+ mb_read(mm, addr, REG_UPG_READ, pkt, sizeof(upg_pkt_t));
|
|
|
if(pkt->dlen>0) {
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -141,11 +147,10 @@ static int upgrade_check(uint16_t addr)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-static int upgrade_proc(char *path)
|
|
|
+static int upgrade_proc(char *path, Modbus_Manger *mm)
|
|
|
{
|
|
|
- int i,j,r;
|
|
|
+ int i,j,r,maxCh=2;//MAX_CHN_COUNT;
|
|
|
buf_t fbuf;
|
|
|
- int slen=0,onelen=0,onemax=128;
|
|
|
GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
GlobalPowerCtrlBoard *pboard=dm->_all_ctrl_board;
|
|
|
|
|
|
@@ -157,16 +162,16 @@ static int upgrade_proc(char *path)
|
|
|
}
|
|
|
|
|
|
//broad upgrade file
|
|
|
- upgrade_send(0, fbuf.buf, fbuf.dlen);
|
|
|
- for(i=0; i<MAX_CHN_COUNT; i++) {
|
|
|
+ upgrade_send(mm, 1, fbuf.buf, fbuf.dlen);
|
|
|
+ for(i=0; i<maxCh; i++) {
|
|
|
if(pboard[i].product_saddr==0) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
for(j=0; j<RETRY_MAX; j++) {
|
|
|
- r = upgrade_check(i);
|
|
|
+ r = upgrade_check(mm, i);
|
|
|
if(r==0) break;
|
|
|
- upgrade_send(i, fbuf.buf, fbuf.dlen);
|
|
|
+ upgrade_send(mm, i, fbuf.buf, fbuf.dlen);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -176,14 +181,14 @@ static int upgrade_proc(char *path)
|
|
|
}
|
|
|
|
|
|
|
|
|
-int power_upgrade(char *path)
|
|
|
+int power_upgrade(char *path, Modbus_Manger *mm)
|
|
|
{
|
|
|
int r;
|
|
|
|
|
|
thread_stop(THREAD_ID_SNMP);
|
|
|
thread_stop(THREAD_ID_POWER);
|
|
|
|
|
|
- r = upgrade_proc(path);
|
|
|
+ r = upgrade_proc(path, mm);
|
|
|
|
|
|
thread_restart(THREAD_ID_SNMP);
|
|
|
thread_restart(THREAD_ID_POWER);
|
|
|
@@ -191,21 +196,23 @@ int power_upgrade(char *path)
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+//#define UPG_TEST
|
|
|
void upg_test(void)
|
|
|
{
|
|
|
int r;
|
|
|
+ Modbus_Manger mm;
|
|
|
+ GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
#define UPG_FILE "/root/dl/fw.upg"
|
|
|
|
|
|
#ifdef UPG_TEST
|
|
|
- r = g_modbus_init(&_globalDeviceManager->_globalRelaySampManger,
|
|
|
+ r = g_modbus_init(&mm,
|
|
|
INTERL_MODBUS_PORT,
|
|
|
INTERL_MODBUS_BAUD,
|
|
|
MASTER_MODE,
|
|
|
0,
|
|
|
"relay",1);
|
|
|
|
|
|
- upgrade_proc(UPG_FILE);
|
|
|
+ upgrade_proc(UPG_FILE, &mm);
|
|
|
exit(0);
|
|
|
#endif
|
|
|
}
|
|
|
@@ -1821,21 +1828,36 @@ void* ntp_thread(void *arg)
|
|
|
|
|
|
int snmp_config(SNMPManager *m)
|
|
|
{
|
|
|
- char tmp[200],cmd[400];
|
|
|
+ char *pass_tok="createUser";
|
|
|
+ char *pass_conf="/var/net-snmp/snmpd.conf";
|
|
|
+ char *user_tok="rouser";
|
|
|
+ char *user_conf="/root/run/app/snmp/conf/snmpd.conf";
|
|
|
+ char user[100],pass[200],cmd[400];
|
|
|
+return 0;
|
|
|
+ if(strlen(m->crypt.auth.alg)<=1) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ sprintf(user, "%s %s", user_tok, m->crypt.user);
|
|
|
+ sprintf(pass, "%s %s \"%s\"", pass_tok, m->crypt.auth.alg, m->crypt.auth.passwd);
|
|
|
+ if(strlen(m->crypt.priv.alg)>1) {
|
|
|
+ sprintf(cmd, " %s \"%s\"", m->crypt.priv.alg, m->crypt.priv.passwd);
|
|
|
+ strcat(pass, cmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ snprintf(cmd, sizeof(cmd), "sed -i '/^%s/ { s/%s.*/%s/; t; a\\%s; }' %s", pass_tok, pass_tok, pass, pass, pass_conf);
|
|
|
+ system(cmd);
|
|
|
+
|
|
|
+ snprintf(cmd, sizeof(cmd), "sed -i '/^%s/ { s/%s.*/%s/; t; a\\%s; }' %s", user_tok, user_tok, user, user, user_conf);
|
|
|
+ system(cmd);
|
|
|
|
|
|
-
|
|
|
system("/etc/init.d/S90PDUApp stop snmpd");
|
|
|
//snprintf(tmp, sizeof(tmp), "net-snmp-create-v3-user -ro -a -A <auth_password> -x <priv_protocol> -X <priv_password> usernmae");
|
|
|
|
|
|
- sprintf(cmd, "net-snmp-create-v3-user -ro %s", m->crypt.user);
|
|
|
- if(strlen(m->crypt.auth.alg)>1) {
|
|
|
- sprintf(tmp, " -a %s -A %s", m->crypt.auth.alg, m->crypt.auth.passwd);
|
|
|
- strcat(cmd, tmp);
|
|
|
- }
|
|
|
- if(strlen(m->crypt.priv.alg)>1) {
|
|
|
- sprintf(tmp, " -x %s -X %s", m->crypt.priv.alg, m->crypt.priv.passwd);
|
|
|
- strcat(cmd, tmp);
|
|
|
- }
|
|
|
+
|
|
|
+ printf("___snmp: %s\n", cmd);
|
|
|
+ system(cmd);
|
|
|
+
|
|
|
system("/etc/init.d/S90PDUApp start snmpd");
|
|
|
|
|
|
thread_stop(THREAD_ID_SNMP);
|
|
|
@@ -1874,9 +1896,11 @@ void* snmp_thread(void *arg)
|
|
|
reconfig = 0;
|
|
|
}
|
|
|
agent_check_and_process(1);/* block every 1 second */
|
|
|
+ printf("______snmp agent________\n");
|
|
|
}
|
|
|
/* at shutdown time */
|
|
|
snmp_shutdown(path);
|
|
|
+ printf("______snmp agent quit________\n");
|
|
|
|
|
|
/* deinitialize your mib code here */
|
|
|
/* shutdown the agent library */
|