abb_b23_4_comm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "plt.h"
  2. void abb_b23_4_comm_dac( int idx )
  3. {
  4. unsigned short tab_us[128]={0};
  5. struct abb_b23_4_t* dev = &abb_b23_4[idx];
  6. struct comm_t* comm = &dev->comm;
  7. int chanidx = comm->chanidx;
  8. int addr = comm->adr;
  9. int start, nb, rc, i;
  10. int ret = 0;
  11. unsigned int tmp;
  12. unsigned long long temp64 = 0;
  13. if(comm_get_state(comm) != COMMST_NORMAL){
  14. return;
  15. }
  16. comm_start_cal_dac_timing(comm);
  17. nb = 12;
  18. start = 0x5000;
  19. chan_lock(chanidx);
  20. usleep(100000); // 100ms
  21. rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
  22. if( rc < 0){
  23. comm_set_state(comm, COMMST_ERR);
  24. }
  25. chan_unlock(chanidx);
  26. if( rc == 0 ){ // read ok
  27. dev->pos_active_e = ((unsigned long long)tab_us[0x5000 - start]<<48 | (unsigned long long)tab_us[0x5001 - start] << 32 | (unsigned long long)tab_us[0x5002 - start] << 16 | (unsigned long long)tab_us[0x5003 - start])*0.01;
  28. dev->neg_active_e = ((unsigned long long)tab_us[0x5004 - start]<<48 | (unsigned long long)tab_us[0x5005 - start] << 32 | (unsigned long long)tab_us[0x5006 - start] << 16 | (unsigned long long)tab_us[0x5007 - start])*0.01;
  29. temp64 = (unsigned long long)tab_us[0x5008 - start]<<48 | (unsigned long long)tab_us[0x5009 - start] << 32 | (unsigned long long)tab_us[0x500A - start] << 16 | (unsigned long long)tab_us[0x500B - start];
  30. dev->com_active_e = *((signed long long *)(&temp64)) * 0.01;
  31. }else{
  32. return;
  33. }
  34. nb = 22;
  35. start = 0x5B00;
  36. chan_lock(chanidx);
  37. usleep(100000); // 100ms
  38. rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
  39. if( rc < 0){
  40. comm_set_state(comm, COMMST_ERR);
  41. }
  42. chan_unlock(chanidx);
  43. if( rc == 0 ){ // read ok
  44. dev->ua = ((unsigned int)tab_us[0x5B00 - start] << 16 | (unsigned int)tab_us[0x5B01 - start])*0.1;
  45. dev->ub = ((unsigned int)tab_us[0x5B02 - start] << 16 | (unsigned int)tab_us[0x5B03 - start])*0.1;
  46. dev->uc = ((unsigned int)tab_us[0x5B04 - start] << 16 | (unsigned int)tab_us[0x5B05 - start])*0.1;
  47. dev->ia = ((unsigned int)tab_us[0x5B0C - start] << 16 | (unsigned int)tab_us[0x5B0D - start])*0.01;
  48. dev->ib = ((unsigned int)tab_us[0x5B0E - start] << 16 | (unsigned int)tab_us[0x5B0F - start])*0.01;
  49. dev->ic = ((unsigned int)tab_us[0x5B10 - start] << 16 | (unsigned int)tab_us[0x5B11 - start])*0.01;
  50. tmp = (unsigned int)tab_us[0x5B14 - start] << 16 | (unsigned int)tab_us[0x5B15 - start];
  51. dev->com_ap = *((signed int*)&tmp) * 0.01 * 0.001;//w->kw
  52. }else{
  53. return ;
  54. }
  55. nb = 12;
  56. start = 0x5B2C;
  57. chan_lock(chanidx);
  58. usleep(100000); // 100ms
  59. rc = chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us);
  60. if( rc < 0){
  61. comm_set_state(comm, COMMST_ERR);
  62. }
  63. chan_unlock(chanidx);
  64. if( rc == 0 ){ // read ok
  65. dev->freq = tab_us[0x5B2C - start] *0.01;
  66. dev->pwr_factor = *((signed short*)&tab_us[0x5B3A - start]);
  67. comm_stop_cal_dac_timing(comm);
  68. }else{
  69. return;
  70. }
  71. }
  72. // int dtsd1352_set_dev_pt( int idx, int val)
  73. // {
  74. // int ret = 0;
  75. // struct dtsd1352_t* dev = &dtsd1352[idx];
  76. // struct comm_t* comm = &dev->comm;
  77. // int chanidx = comm->chanidx;
  78. // int addr = comm->adr;
  79. // int regaddr = 0x008D;
  80. // int nb = 1;
  81. // chan_lock(chanidx);
  82. // usleep(100000); // 100ms
  83. // ret = chan_write_single_register_with_retry( chanidx, addr, regaddr, val);
  84. // chan_unlock(chanidx);
  85. // log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  86. // return ret;
  87. // }
  88. // int dtsd1352_set_dev_ct( int idx, int val)
  89. // {
  90. // int ret = 0;
  91. // struct dtsd1352_t* dev = &dtsd1352[idx];
  92. // struct comm_t* comm = &dev->comm;
  93. // int chanidx = comm->chanidx;
  94. // int addr = comm->adr;
  95. // int regaddr = 0x008E;
  96. // int nb = 1;
  97. // chan_lock(chanidx);
  98. // usleep(100000); // 100ms
  99. // ret = chan_write_single_register_with_retry( chanidx, addr, regaddr, val);
  100. // chan_unlock(chanidx);
  101. // log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  102. // return ret;
  103. // }
  104. int abb_b23_4_comm_init(int idx)
  105. {
  106. struct abb_b23_4_t* dev = &abb_b23_4[idx];
  107. struct comm_t* comm = &dev->comm;
  108. comm_set_state( comm, COMMST_ERR );
  109. }
  110. int abb_b23_4_comm_reset(int idx)
  111. {
  112. struct abb_b23_4_t* dev = &abb_b23_4[idx];
  113. struct comm_t* comm = &dev->comm;
  114. comm_set_state( comm, COMMST_NORMAL );
  115. comm_set_dac_param_en(comm, 1);
  116. }