yf2825_comm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "yf2825_comm.h"
  2. #include "plt.h"
  3. #include "yf2825.h"
  4. #include "yf2825_sm.h"
  5. void yf2825_comm_dac(int idx)
  6. {
  7. unsigned char tab_us[128] = {0};
  8. struct yf2825_t *dev = &yf2825[idx];
  9. struct comm_t *comm = &dev->comm;
  10. int chanidx = comm->chanidx;
  11. int addr = comm->adr;
  12. int start, nb, rc, i;
  13. int ret = 0;
  14. if (comm_get_state(comm) != COMMST_NORMAL)
  15. {
  16. return;
  17. }
  18. comm_start_cal_dac_timing(comm);
  19. chan_lock(chanidx);
  20. nb = 8;
  21. start = 8;
  22. rc = chan_read_input_bits_with_retry(chanidx, addr, start, nb, tab_us);
  23. usleep(100000); // 100ms
  24. if (rc != 0)
  25. {
  26. comm_set_state(comm, COMMST_ERR);
  27. goto leave;
  28. }
  29. else if (rc == 0)
  30. { /* read ok */
  31. dev->smoke_detector_alarm = tab_us[0];
  32. dev->temperature_alarm = tab_us[1];
  33. dev->press_alarm = tab_us[2];
  34. dev->spurt_flag = tab_us[3];
  35. }
  36. nb = 6;
  37. start = 0;
  38. rc = chan_read_input_bits_with_retry(chanidx, addr, start, nb, tab_us);
  39. usleep(100000); // 100ms
  40. if (rc != 0)
  41. {
  42. comm_set_state(comm, COMMST_ERR);
  43. goto leave;
  44. }
  45. if (rc == 0)
  46. { /* read ok */
  47. dev->pack1_on = tab_us[0];
  48. dev->pack2_on = tab_us[1];
  49. dev->pack3_on = tab_us[2];
  50. dev->pack4_on = tab_us[3];
  51. dev->pack5_on = tab_us[4];
  52. dev->pack6_on = tab_us[5];
  53. }
  54. leave:
  55. chan_unlock(chanidx);
  56. comm_stop_cal_dac_timing(comm);
  57. }
  58. int yf2825_set_dev_mbadr(int idx, int val)
  59. {
  60. int ret = 0;
  61. struct yf2825_t *dev = &yf2825[idx];
  62. struct comm_t *comm = &dev->comm;
  63. chan_lock(comm->chanidx);
  64. ret = chan_write_single_register_with_retry(comm->chanidx, comm->adr, 0x400, val);
  65. chan_unlock(comm->chanidx);
  66. log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
  67. return ret;
  68. }
  69. static unsigned char val[6]={0};
  70. int yf2825_set_dev_start(int idx, int startIdx)
  71. {
  72. //暂时关闭pack级消防喷发
  73. return 0;
  74. int ret = 0;
  75. if(startIdx<0 || startIdx>=6)
  76. {
  77. memset(val, 0, 6);
  78. }
  79. else
  80. {
  81. val[startIdx] = 1;
  82. }
  83. struct yf2825_t *dev = &yf2825[idx];
  84. struct comm_t *comm = &dev->comm;
  85. chan_lock(comm->chanidx);
  86. ret = chan_write_bits(comm->chanidx, comm->adr, 0, 6, val);
  87. chan_unlock(comm->chanidx);
  88. log_dbg("%s, idx:%d, startidx:%d, ret:%d", __func__, idx, startIdx, ret);
  89. return ret;
  90. }
  91. int yf2825_comm_init(int idx)
  92. {
  93. struct yf2825_t *dev = &yf2825[idx];
  94. struct comm_t *comm = &dev->comm;
  95. comm_set_state(comm, COMMST_ERR);
  96. }
  97. int yf2825_comm_reset(int idx)
  98. {
  99. struct yf2825_t *dev = &yf2825[idx];
  100. struct comm_t *comm = &dev->comm;
  101. comm_set_state(comm, COMMST_NORMAL);
  102. }