cd1f3300_comm.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "plt.h"
  2. int cd1f3300_comm_init(int idx)
  3. {
  4. struct cd1f3300_t *dev = &cd1f3300[idx];
  5. struct comm_t *comm = &dev->comm;
  6. comm_set_state(comm, COMMST_ERR);
  7. }
  8. int cd1f3300_comm_reset(int idx)
  9. {
  10. struct cd1f3300_t *dev = &cd1f3300[idx];
  11. struct comm_t *comm = &dev->comm;
  12. comm_set_state(comm, COMMST_NORMAL);
  13. }
  14. void cd1f3300_comm_dac(int idx)
  15. {
  16. unsigned short tab_us[256] = {0};
  17. struct cd1f3300_t *dev = &cd1f3300[idx];
  18. struct comm_t *comm = &dev->comm;
  19. int chanidx = comm->chanidx;
  20. int addr = comm->adr;
  21. int start, nb, rc, i;
  22. int ret = 0;
  23. if (comm_get_state(comm) != COMMST_NORMAL)
  24. {
  25. return;
  26. }
  27. comm_start_cal_dac_timing(comm);
  28. nb = 2;
  29. start = 0x0001;
  30. chan_lock(comm->chanidx);
  31. ret = chan_read_holdingregisters_with_retry(chanidx, addr, start, nb, tab_us);
  32. if (ret < 0)
  33. {
  34. chan_unlock(comm->chanidx);
  35. comm_set_state(comm, COMMST_ERR);
  36. return;
  37. }
  38. else
  39. { /* read ok */
  40. chan_unlock(comm->chanidx);
  41. dev->state = tab_us[0x0001 - start];
  42. dev->co_density = tab_us[0x0002 - start];
  43. if (dev->state == 0x00)
  44. {
  45. sprintf(dev->state_str, "%s", "no alarm");
  46. }
  47. else if (dev->state == 0xFF)
  48. {
  49. sprintf(dev->state_str, "%s", "CO density alarm");
  50. }
  51. else if (dev->state == 0XFE)
  52. {
  53. sprintf(dev->state_str, "%s", "sensor fault");
  54. }
  55. else if (dev->state == 0XFD)
  56. {
  57. sprintf(dev->state_str, "%s", "sensor preheating");
  58. }
  59. else
  60. {
  61. sprintf(dev->state_str, "%s", "unkown");
  62. }
  63. }
  64. // nb = 1;
  65. // start = 0x0010;
  66. // chan_lock(comm->chanidx);
  67. // ret = chan_read_holdingregisters_with_retry(chanidx, addr, start, nb, tab_us);
  68. // if (ret < 0)
  69. // {
  70. // chan_unlock(comm->chanidx);
  71. // comm_set_state(comm, COMMST_ERR);
  72. // return;
  73. // }
  74. // else
  75. // { /* read ok */
  76. // chan_unlock(comm->chanidx);
  77. // dev->threshold = tab_us[0x0010 - start];
  78. // }
  79. comm_stop_cal_dac_timing(comm);
  80. }