serial.cpp 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "serial.h"
  2. #include "message_queue.h"
  3. CSerialSensor::CSerialSensor(CMessageQueue* q) :_message(q)
  4. {
  5. _run = false;
  6. }
  7. void CSerialSensor::SetSerialSensor(SensorSerial<CSerialSensor>* serial)
  8. {
  9. _serial = serial;
  10. }
  11. void CSerialSensor::Start()
  12. {
  13. if(!_run)
  14. {
  15. //_thread = std::thread(&CSerialSensor::Run, this);
  16. _run = true;
  17. }
  18. }
  19. void CSerialSensor::Run()
  20. {
  21. uint8_t comment[] = "#01\r";
  22. while (_run)
  23. {
  24. _serial->Write(comment,4);
  25. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  26. }
  27. }
  28. void CSerialSensor::Stop()
  29. {
  30. if (_run)
  31. {
  32. _run = false;
  33. //_thread.join();
  34. }
  35. }
  36. void CSerialSensor::Notify(uint8_t * buffer,int32_t size)
  37. {
  38. //+0000000012↙,车辆姿态编码器
  39. u_char Temp = '+';
  40. u_char *p = nullptr;
  41. if(_run)
  42. {
  43. p = (u_char *)strchr((const char *)buffer,Temp);
  44. //_message->_Feeddata.steer_angle = strtol((const char *)p + 1,NULL,10);
  45. }
  46. }