mdl.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "plt.h"
  2. #include "mdl.h"
  3. int random_range(int min, int max)
  4. {
  5. return min + rand() / (RAND_MAX / (max - min + 1) + 1);
  6. }
  7. void mdl_sim()
  8. {
  9. MDL.co_ppm = random_range(42, 60);
  10. }
  11. void mdl_prepare()
  12. {
  13. MDL.co_ppm = random_range(42, 60);
  14. MDL.co_alarm = 0;
  15. }
  16. void from_modbus_to_dev()
  17. {
  18. // usHoldingRegisters[0x6020] = uab;
  19. return 0;
  20. }
  21. int from_dev_to_modbus()
  22. {
  23. // uab = usHoldingRegisters[0x6020];
  24. return 0;
  25. }
  26. void update_states()
  27. {
  28. }
  29. static void *mdl_thrd_main(void *param)
  30. {
  31. mdl_prepare();
  32. from_dev_to_modbus();
  33. while (1)
  34. {
  35. from_modbus_to_dev();
  36. mdl_sim();
  37. from_dev_to_modbus();
  38. usleep(10000); /* 10ms */
  39. }
  40. return NULL;
  41. }
  42. int mdl_init()
  43. {
  44. log_dbg("%s, ++", __func__);
  45. int ret = 0;
  46. pthread_t xthrd;
  47. if (pthread_create(&xthrd, NULL, mdl_thrd_main, NULL) != 0)
  48. {
  49. log_dbg("%s, pthread_create fail", __func__);
  50. ret = -1;
  51. }
  52. log_dbg("%s, --, ret: %d", __func__, ret);
  53. return ret;
  54. }