|
|
@@ -23,6 +23,7 @@ typedef struct {
|
|
|
|
|
|
uint8_t chs; //所有控制板的总通道数
|
|
|
power_ch_t **pch; //动态指针
|
|
|
+ power_ch_t ch0;
|
|
|
|
|
|
uint8_t cnt; //实际扫到的板子个数,不可大于BRD_MAX
|
|
|
uint8_t brd_max;
|
|
|
@@ -34,7 +35,22 @@ typedef struct {
|
|
|
product_data_t *prod;
|
|
|
power_data_t pdat;
|
|
|
}power_handle_t;
|
|
|
-power_handle_t pwrHandle={0};
|
|
|
+static board_fn_t board_fn={
|
|
|
+ .get_power = NULL,
|
|
|
+ .get_alarm = NULL,
|
|
|
+ .set_ch = NULL,
|
|
|
+ .set_open_delay = NULL,
|
|
|
+ .set_close_delay = NULL,
|
|
|
+ .set_kb_value = NULL,
|
|
|
+ .set_threshold = NULL,
|
|
|
+ .reset_consump = NULL,
|
|
|
+
|
|
|
+ .detect = NULL,
|
|
|
+ .get_info = NULL,
|
|
|
+ //.get_board = NULL,
|
|
|
+ .set_all = NULL,
|
|
|
+};
|
|
|
+static power_handle_t pwrHandle={0};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -747,7 +763,7 @@ int power_set(int ch, power_ch_t *pch)
|
|
|
|
|
|
static int power_map(power_handle_t *h, int chs)
|
|
|
{
|
|
|
- int i,j,r,idx=0;
|
|
|
+ int i,j,r,idx=1;
|
|
|
board_data_t *pbrd=NULL;
|
|
|
uint8_t pwr_type=paras_get()->prod.pwr_type;
|
|
|
|
|
|
@@ -756,11 +772,16 @@ static int power_map(power_handle_t *h, int chs)
|
|
|
h->pch = (power_ch_t**)calloc(1, sizeof(power_ch_t*)*chs);
|
|
|
if(h->pch) {
|
|
|
h->chs = chs;
|
|
|
+ h->pch[0] = &h->ch0;
|
|
|
+ strcpy(h->pch[0]->info.name, "ALL");
|
|
|
+
|
|
|
for(i=1; i<=h->brd_max; i++) {
|
|
|
pbrd = h->pbrd[i];
|
|
|
if(pbrd) {
|
|
|
for(j=0; j<pbrd->chs; j++) {
|
|
|
- h->pch[idx++] = &h->pbrd[i]->pch[j];
|
|
|
+ h->pch[idx] = &h->pbrd[i]->pch[j];
|
|
|
+ sprintf(h->pch[idx]->info.name, "CH%d", idx);
|
|
|
+ idx++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -773,6 +794,8 @@ static int power_map(power_handle_t *h, int chs)
|
|
|
static int power_clear(power_handle_t *h)
|
|
|
{
|
|
|
int i,j;
|
|
|
+
|
|
|
+ memset(&h->ch0, 0, sizeof(h->ch0));
|
|
|
for(i=0; i<=h->brd_max; i++) {
|
|
|
if(h->pbrd[i]) {
|
|
|
for(j=0; j<h->pbrd[i]->chs; j++) {
|
|
|
@@ -794,8 +817,8 @@ static int power_clear(power_handle_t *h)
|
|
|
}
|
|
|
int power_scan(void)
|
|
|
{
|
|
|
- int r,i,j,total_chs=0;
|
|
|
- int ch_idx=0,brd_idx=0;
|
|
|
+ int r,i,j,total_chs=1;
|
|
|
+ int ch_idx=1,brd_idx=0;
|
|
|
power_ch_t *pch=NULL;
|
|
|
board_key_t *pkey=NULL;
|
|
|
board_data_t *pbrd=NULL;
|
|
|
@@ -805,6 +828,10 @@ int power_scan(void)
|
|
|
lock_on(h->lck);
|
|
|
power_clear(h);
|
|
|
|
|
|
+ pch = &h->ch0;
|
|
|
+ pch->info.addr = 0;
|
|
|
+ pch->info.ch = 0;
|
|
|
+
|
|
|
for(i=1; i<=h->brd_max; i++) {
|
|
|
r = get_key(h, i, &h->key[i]);
|
|
|
if(r==0) {
|
|
|
@@ -844,11 +871,11 @@ int power_scan(void)
|
|
|
pch[j].info.stop_delay = 1000*times;
|
|
|
|
|
|
if(h->prod->pwr_type==PDU_AC_I3O3) {
|
|
|
- pch[j].info.ch = ch_idx+j/3; //序号程序从0开始
|
|
|
+ pch[j].info.ch = ch_idx+j/3; //序号从1开始, 发给控制板需从0开始
|
|
|
pch[j].info.ph_id = j%3;
|
|
|
}
|
|
|
else {
|
|
|
- pch[j].info.ch = ch_idx+j; //序号程序从0开始
|
|
|
+ pch[j].info.ch = ch_idx+j; //序号从1开始, 发给控制板需从0开始
|
|
|
pch[j].info.ph_id = 0;
|
|
|
}
|
|
|
}
|
|
|
@@ -890,10 +917,10 @@ int power_reset(void)
|
|
|
{
|
|
|
uint16_t tmp[8];
|
|
|
offset = POWER_AC_CH_STAT_L;
|
|
|
- for(i=0; i<pbrd->chs; i++) {
|
|
|
+ for(i=1; i<=pbrd->chs; i++) {
|
|
|
tmp[i] = pbrd->pch[i].power[0].status;
|
|
|
}
|
|
|
- r = write_reg(h, pbrd->addr, offset, tmp, pbrd->chs);
|
|
|
+ r = write_reg(h, pbrd->addr, offset, tmp+1, pbrd->chs-1);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
@@ -944,7 +971,7 @@ int power_reset(void)
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- for (i=0; i<pbrd->chs; i++) {
|
|
|
+ for (i=1; i<=pbrd->chs; i++) {
|
|
|
memset(data_temp, 0, sizeof(data_temp));
|
|
|
offset = POWER_AC3_OUT_ENABLE + i;
|
|
|
data_temp[0] = pbrd->pch[i].power[0].status;
|
|
|
@@ -991,7 +1018,7 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
|
|
|
case AC_SINGLE_S_TYPE:
|
|
|
case AC_SINGLE_B_TYPE:
|
|
|
{
|
|
|
- offset = POWER_AC_CH_STAT_L + pch->info.ch;
|
|
|
+ offset = POWER_AC_CH_STAT_L + pch->info.ch-1;
|
|
|
tmp[0] = st; tmp[1] = 0;
|
|
|
r = write_reg(h, pc.info.addr, offset, tmp, 2);
|
|
|
}
|
|
|
@@ -1000,11 +1027,11 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
|
|
|
case DCPDU_TYPE:
|
|
|
{
|
|
|
uint16_t mask;
|
|
|
- offset = POWER_DC_STAT_INFO+pch->info.ch;
|
|
|
+ offset = POWER_DC_STAT_INFO+pch->info.ch-1;
|
|
|
|
|
|
- mask = ~(1 << pch->info.ch);
|
|
|
+ mask = ~(1 << (pch->info.ch-1));
|
|
|
tmp[0] &= mask;
|
|
|
- tmp[0] |= (st << pch->info.ch);
|
|
|
+ tmp[0] |= (st << (pch->info.ch-1));
|
|
|
r = write_reg(h, pc.info.addr, offset, tmp, 2);
|
|
|
}
|
|
|
break;
|
|
|
@@ -1021,7 +1048,7 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
|
|
|
}
|
|
|
|
|
|
tmp[0] = st;
|
|
|
- offset = reg + +pch->info.ch;
|
|
|
+ offset = reg + +pch->info.ch-1;
|
|
|
r = write_reg(h, pc.info.addr, offset, tmp, 2);
|
|
|
}
|
|
|
break;
|
|
|
@@ -1042,7 +1069,7 @@ static int set_board_sw(board_data_t *pbrd, uint8_t on)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- for(i=0; i<pbrd->chs; i++) {
|
|
|
+ for(i=1; i<=pbrd->chs; i++) {
|
|
|
r = get_ch(h, i, &pc);
|
|
|
if(r==0) {
|
|
|
power_set_ch_sw(pc.info.ch, on);
|
|
|
@@ -1081,33 +1108,33 @@ int power_set_alarm(power_ch_t *pch)
|
|
|
case AC_SINGLE_S_TYPE:
|
|
|
case AC_SINGLE_B_TYPE:
|
|
|
{
|
|
|
- if (pch->info.ch<0) {
|
|
|
+ if (pch->info.ch==0) {
|
|
|
offset = POWER_AC_ALARM_CTRL_TOTAL;
|
|
|
}
|
|
|
else {
|
|
|
- offset = POWER_AC_ALARM_CTRL + pch->info.ch;
|
|
|
+ offset = POWER_AC_ALARM_CTRL + pch->info.ch-1;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case DCPDU_TYPE:
|
|
|
{
|
|
|
- if (pch->info.ch<0) {
|
|
|
+ if (pch->info.ch==0) {
|
|
|
offset = POWER_DC_ALARM_CTRL_TOTAL;
|
|
|
}
|
|
|
else {
|
|
|
- offset = POWER_DC_ALARM_CTRL + pch->info.ch;
|
|
|
+ offset = POWER_DC_ALARM_CTRL + pch->info.ch-1;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case TREE_AC_TYPE:
|
|
|
{
|
|
|
- if (pch->info.ch<0) {
|
|
|
+ if (pch->info.ch==0) {
|
|
|
offset = POWER_AC3_ALARM_CTRL_TOTAL;
|
|
|
}
|
|
|
else {
|
|
|
- offset = POWER_AC3_ALARM_CTRL + pch->info.ch;
|
|
|
+ offset = POWER_AC3_ALARM_CTRL + pch->info.ch-1;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -1180,11 +1207,11 @@ int power_set_threshold(power_ch_t *pch)
|
|
|
data_buf[14] = data_temp;
|
|
|
data_buf[15] = data_temp>>16;
|
|
|
|
|
|
- if(pch->info.ch<0) {
|
|
|
+ if(pch->info.ch==0) {
|
|
|
offset = POWER_AC_TOTAL_THRESHOLD;
|
|
|
}
|
|
|
else {
|
|
|
- offset = POWER_AC_THRESHOLD_L+pch->info.ch*16;
|
|
|
+ offset = POWER_AC_THRESHOLD_L+(pch->info.ch-1)*16;
|
|
|
}
|
|
|
|
|
|
r = write_reg(h, pch->info.addr, offset, data_buf, 16);
|
|
|
@@ -1319,7 +1346,7 @@ int power_set_start_delay(power_ch_t *pch)
|
|
|
case AC_SINGLE_B_TYPE:
|
|
|
{
|
|
|
tmp[0] = pch->info.start_delay;
|
|
|
- offset = POWER_AC_START_DELAY_TIME_L+pch->info.ch;
|
|
|
+ offset = POWER_AC_START_DELAY_TIME_L+pch->info.ch-1;
|
|
|
r = write_reg(h, pch->info.addr, offset, tmp, 1);
|
|
|
}
|
|
|
break;
|
|
|
@@ -1329,7 +1356,7 @@ int power_set_start_delay(power_ch_t *pch)
|
|
|
uint32_t time=pch->info.start_delay/1000;
|
|
|
tmp[0] = time & 0xffff;
|
|
|
tmp[1] = (time >> 16) & 0xffff;
|
|
|
- offset = POWER_DC_SET_START_DELAY+pch->info.ch;
|
|
|
+ offset = POWER_DC_SET_START_DELAY+pch->info.ch-1;
|
|
|
r = write_reg(h, pch->info.addr, offset, tmp, 2);
|
|
|
}
|
|
|
break;
|
|
|
@@ -1378,7 +1405,7 @@ int power_set_stop_delay(power_ch_t *pch)
|
|
|
case AC_SINGLE_B_TYPE:
|
|
|
{
|
|
|
tmp[0] = pch->info.start_delay;
|
|
|
- offset = POWER_AC_STOP_DELAY_TIME_L+pch->info.ch;
|
|
|
+ offset = POWER_AC_STOP_DELAY_TIME_L+pch->info.ch-1;
|
|
|
r = write_reg(h, pch->info.addr, offset, tmp, 1);
|
|
|
}
|
|
|
break;
|
|
|
@@ -1388,7 +1415,7 @@ int power_set_stop_delay(power_ch_t *pch)
|
|
|
uint32_t time=pch->info.stop_delay/1000;
|
|
|
tmp[0] = time & 0xffff;
|
|
|
tmp[1] = (time >> 16) & 0xffff;
|
|
|
- offset = POWER_DC_SET_STOP_DELAY+pch->info.ch;
|
|
|
+ offset = POWER_DC_SET_STOP_DELAY+pch->info.ch-1;
|
|
|
//r = write_reg(h, pch->info.addr, offset, tmp, 2);
|
|
|
}
|
|
|
break;
|