Outriggers.cpp 890 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "Outriggers.h"
  2. #include "message_queue.h"
  3. COutriggersSensor::COutriggersSensor(CMessageQueue* q) :_message(q)
  4. {
  5. _run = false;
  6. }
  7. void COutriggersSensor::SetModbusTcpSensor(SensorModbusTcp<COutriggersSensor>* modbus)
  8. {
  9. _modbus = modbus;
  10. }
  11. void COutriggersSensor::Start()
  12. {
  13. if(!_run)
  14. {
  15. _thread = std::thread(&COutriggersSensor::Run, this);
  16. _run = true;
  17. }
  18. }
  19. void COutriggersSensor::Run()
  20. {
  21. while (_run)
  22. {
  23. _modbus->read_registers(0x00,0x10);
  24. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  25. }
  26. }
  27. void COutriggersSensor::Stop()
  28. {
  29. if (_run)
  30. {
  31. _run = false;
  32. _thread.join();
  33. }
  34. }
  35. void COutriggersSensor::Notify(uint16_t * buffer)
  36. {
  37. if (_run)
  38. {
  39. _message->_Feeddata.wire_sensor_l = buffer[0];
  40. _message->_Feeddata.wire_sensor_r = buffer[1];
  41. }
  42. }