bits.c 731 B

1234567891011121314151617181920212223242526272829303132
  1. #include "slave.h"
  2. static uint8_t _tab_bits[10] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
  3. static int get_map_buf(void *buf, int bufsz)
  4. {
  5. uint8_t *ptr = (uint8_t *)buf;
  6. pthread_mutex_lock(&slave_mtx);
  7. for (int i = 0; i < sizeof(_tab_bits); i++) {
  8. ptr[i] = _tab_bits[i];
  9. }
  10. pthread_mutex_unlock(&slave_mtx);
  11. return 0;
  12. }
  13. static int set_map_buf(int index, int len, void *buf, int bufsz)
  14. {
  15. uint8_t *ptr = (uint8_t *)buf;
  16. pthread_mutex_lock(&slave_mtx);
  17. for (int i = 0; i < len; i++) {
  18. _tab_bits[index + i] = ptr[index + i];
  19. }
  20. pthread_mutex_unlock(&slave_mtx);
  21. return 0;
  22. }
  23. const agile_modbus_slave_util_map_t bit_maps[1] = {
  24. {0x041A, 0x0423, get_map_buf, set_map_buf}};