e3ks_comm.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "plt.h"
  2. void e3ks_comm_dac( int idx )
  3. {
  4. unsigned short tab_us[128]={0};
  5. struct e3ks_t* dev = &e3ks[idx];
  6. struct comm_t* comm = &dev->comm;
  7. int start, nb;
  8. int chanidx = comm->chanidx;
  9. int addr = comm->adr;
  10. if(comm_get_state(comm) != COMMST_NORMAL){
  11. return;
  12. }
  13. comm_start_cal_dac_timing(comm);
  14. nb = 77;
  15. start = 0x0000;
  16. if( chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us) < 0){
  17. comm_set_state(comm, COMMST_ERR);
  18. return;
  19. }else{ /* read ok */
  20. dev->bat_v = tab_us[8 - start]/10;
  21. dev->temp = tab_us[13 - start]/10;
  22. dev->status = tab_us[64 - start]&0xF;
  23. if( dev->status == E3KS_STATUS_BAT ){
  24. strcpy(dev->szstatus, "bat");
  25. }else if( dev->status == E3KS_STATUS_LINE ){
  26. strcpy(dev->szstatus, "line");
  27. }else{
  28. strcpy(dev->szstatus, "unknown");
  29. }
  30. dev->line = tab_us[64 - start]>>7&0x01;
  31. comm_stop_cal_dac_timing(comm);
  32. }
  33. }
  34. int e3ks_comm_init(int idx)
  35. {
  36. struct e3ks_t* dev = &e3ks[idx];
  37. struct comm_t* comm = &dev->comm;
  38. comm_set_state( comm, COMMST_ERR );
  39. }
  40. int e3ks_comm_reset(int idx)
  41. {
  42. struct e3ks_t* dev = &e3ks[idx];
  43. struct comm_t* comm = &dev->comm;
  44. comm_set_state( comm, COMMST_NORMAL );
  45. }