123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- #include "plt.h"
- void dtsd1352_comm_dac( int idx )
- {
- unsigned short tab_us[128]={0};
- struct dtsd1352_t* dev = &dtsd1352[idx];
- struct comm_t* comm = &dev->comm;
- int chanidx = comm->chanidx;
- int addr = comm->adr;
- int start, nb, rc, i;
- int ret = 0;
- unsigned int tmp;
- if(comm_get_state(comm) != COMMST_NORMAL){
- return;
- }
- comm_start_cal_dac_timing(comm);
- if( comm_get_dac_param_en(comm) == 1 ){
- comm_set_dac_param_en(comm, 0);
- nb = 32;
- start = 0x0078;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if( rc == 0 ){ // read ok
- dev->PT = tab_us[0x008D - start];
- dev->CT = tab_us[0x008E - start];
- }else{
- return;
- }
- }
- nb = 32;
- start = 0x0000;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
-
- if( rc == 0 ){ // read ok
- dev->com_active_e = (tab_us[0x0000 - start]<<16 | tab_us[0x0001 - start])*dev->PT*dev->CT*0.01;
- dev->pos_active_e = (tab_us[0x000A - start]<<16 | tab_us[0x000B - start])*dev->PT*dev->CT*0.01;
- dev->neg_active_e = (tab_us[0x0014 - start]<<16 | tab_us[0x0015 - start])*dev->PT*dev->CT*0.01;
- }else{
- return;
- }
- nb = 23;
- start = 0x0061;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if( rc == 0 ){ // read ok
- dev->ua = tab_us[0x0061 - start]*dev->PT*0.1;
- dev->ub = tab_us[0x0062 - start]*dev->PT*0.1;
- dev->uc = tab_us[0x0063 - start]*dev->PT*0.1;
- dev->ia = tab_us[0x0064 - start]*dev->CT*0.01;
- dev->ib = tab_us[0x0065 - start]*dev->CT*0.01;
- dev->ic = tab_us[0x0066 - start]*dev->CT*0.01;
- dev->freq = tab_us[0x0077 - start]*0.01;
- }else{
- return ;
- }
- nb = 24;
- start = 0x016A;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if( rc == 0 ){ // read ok
- //dev->com_active_p = (int)((tab_us[0x016A - start]<<16 | tab_us[0x016B - start]))*dev->PT*dev->CT*0.001;
- tmp = tab_us[0x016A - start]<<16 | tab_us[0x016B - start];
- dev->com_active_p = (*(int*)(&tmp))*dev->PT*dev->CT*0.001;
- dev->pwr_factor = tab_us[0x017F - start]*0.001;
- }else{
- return;
- }
- #if 1
- nb = 8;
- start = 0x0198;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if( rc == 0 ){ // read ok
- dev->pos_active_dem = tab_us[0x0198 - start];
- //comm_stop_cal_dac_timing(comm);
- }else{
- return;
- }
- #endif
- nb = 6;
- start = 0x05DD;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if( rc == 0 ){ // read ok
- dev->THDUa = tab_us[0x05DD - start]*0.01;
- dev->THDUb = tab_us[0x05DE - start]*0.01;
- dev->THDUc = tab_us[0x05DF - start]*0.01;
- dev->THDIa = tab_us[0x05E0 - start]*0.01;
- dev->THDIb = tab_us[0x05E1 - start]*0.01;
- dev->THDIc = tab_us[0x05E2 - start]*0.01;
- }else{
- return;
- }
- nb = 28;
- start = 0x0697;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
- if( rc < 0){
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if( rc == 0 ){ // read ok
- dev->total_fund_ap = tab_us[0x06A6 - start]*0.001;
- dev->total_fund_rp = tab_us[0x06AA - start]*0.001;
- dev->total_harm_ap = tab_us[0x06AE - start]*0.001;
- dev->total_harm_rp = tab_us[0x06B2 - start]*0.001;
- comm_stop_cal_dac_timing(comm);
- }else{
- return;
- }
- }
- int dtsd1352_set_dev_pt( int idx, int val)
- {
- int ret = 0;
- struct dtsd1352_t* dev = &dtsd1352[idx];
- struct comm_t* comm = &dev->comm;
- int chanidx = comm->chanidx;
- int addr = comm->adr;
- int regaddr = 0x008D;
- int nb = 1;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- ret = chan_write_single_register_with_retry( chanidx, addr, regaddr, val);
- chan_unlock(chanidx);
- log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
- return ret;
- }
- int dtsd1352_set_dev_ct( int idx, int val)
- {
- int ret = 0;
- struct dtsd1352_t* dev = &dtsd1352[idx];
- struct comm_t* comm = &dev->comm;
- int chanidx = comm->chanidx;
- int addr = comm->adr;
- int regaddr = 0x008E;
- int nb = 1;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- ret = chan_write_single_register_with_retry( chanidx, addr, regaddr, val);
- chan_unlock(chanidx);
-
- log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
- return ret;
- }
- int dtsd1352_comm_init(int idx)
- {
- struct dtsd1352_t* dev = &dtsd1352[idx];
- struct comm_t* comm = &dev->comm;
- comm_set_state( comm, COMMST_ERR );
- }
- int dtsd1352_comm_reset(int idx)
- {
- struct dtsd1352_t* dev = &dtsd1352[idx];
- struct comm_t* comm = &dev->comm;
- comm_set_state( comm, COMMST_NORMAL );
- comm_set_dac_param_en(comm, 1);
- }
|