123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #include "plt.h"
- #include "sdcs_comm.h"
- #include "sdcs_sm.h"
- #include "sdcs.h"
- int sdcs_comm_init(int idx)
- {
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
- comm_set_state( comm, COMMST_ERR );
- }
- int sdcs_comm_reset(int idx)
- {
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
- comm_set_state( comm, COMMST_NORMAL );
- }
- void sdcs_comm_dac( int idx )
- {
- unsigned short tab_us[256]={0};
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
- int chanidx = comm->chanidx;
- int addr = comm->adr;
- int start, nb, rc, i;
- int ret = 0;
- if(comm_get_state(comm) != COMMST_NORMAL){
- return;
- }
- comm_start_cal_dac_timing(comm);
- nb = 0x0E;
- start = 0;
- chan_lock(comm->chanidx);
- if( chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us) < 0){
- chan_unlock(comm->chanidx);
- comm_set_state(comm, COMMST_ERR);
- return;
- }else{ /* read ok */
- chan_unlock(comm->chanidx);
- dev->humi = tab_us[0x0001 - start]/10.0;
- dev->temp = *((SHORT*)&tab_us[0x0000 - start])/10.0;
- dev->start_humi = tab_us[0x0002 - start] / 10.0;
- dev->stop_humi = tab_us[0x0003 - start] / 10.0;
- if(tab_us[0x0004 - start] & 0x8000){
- dev->heat_temp = -(tab_us[0x0004 - start] - 0x8000) / 10.0;
- }else{
- dev->heat_temp = tab_us[0x0004 - start] / 10.0;
- }
- if(tab_us[0x0005 - start] & 0x8000){
- dev->alarm_temp = -(tab_us[0x0005 - start] - 0x8000) / 10.0;
- }else{
- dev->alarm_temp = tab_us[0x0005 - start] / 10.0;
- }
-
- dev->alarm_humi = tab_us[0x0006 - start] / 10.0;
- dev->heat_state = tab_us[0x0007 - start];
- dev->dehumi_state = tab_us[0x0008 - start];
- dev->dehumi_auto = tab_us[0x0009 - start];
- dev->dehumi_by_hand = tab_us[0x000A - start];
- dev->heat_by_hand = tab_us[0x000B - start];
- dev->over_temperature_alarm = tab_us[0x000C - start];
- dev->over_humi_alarm = tab_us[0x000D - start];
- comm_stop_cal_dac_timing(comm);
- }
-
- }
- int sdcs_set_dev_start_humi( int idx,double humi)
- {
- int ret = 0;
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
- unsigned short value = 0;
- value = humi * 10.0;
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0002, value);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
- int sdcs_set_dev_start_temperature( int idx,double temperature)
- {
- int ret = 0;
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
- unsigned short value = 0;
- if(temperature < 0.0){
- value = (- temperature * 10.0) + 0x8000;
- }else{
- value = temperature * 10.0;
- }
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0003, value);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
- int sdcs_set_dev_stop_temperature( int idx,double temperature)
- {
- int ret = 0;
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
- unsigned short value = 0;
- if(temperature < 0.0){
- value = (- temperature * 10.0) + 0x8000;
- }else{
- value = temperature * 10.0;
- }
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0004, value);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
- int sdcs_set_dev_stop_auto( int idx,int val)
- {
- int ret = 0;
- struct sdcs_t* dev = &sdcs[idx];
- struct comm_t* comm = &dev->comm;
-
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry( comm->chanidx, comm->adr, 0x0009, val);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
|