auto_sensor.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "PCANBasic.h"
  2. #include "message_queue.h"
  3. #include "auto_sensor.h"
  4. #include "message.h"
  5. CAutoSensor::CAutoSensor(CMessageQueue * q):_message(q)
  6. {
  7. }
  8. bool CAutoSensor::Start()
  9. {
  10. return true;
  11. }
  12. void CAutoSensor::Notify(int8_t* data,int32_t size)
  13. {
  14. MessageHead head;
  15. head.Deserialize(data);
  16. auto ptr=data+sizeof(MessageHead);
  17. switch (head.Command)
  18. {
  19. case AR::AR_Finish/* constant-expression */:
  20. {
  21. ARFinish * node=(ARFinish *)ptr;
  22. _message->OnGoalFinish((WorkArea)node->area,node->no);
  23. RemoNet::CSMoveEnd Req;
  24. Req.set_area(node->area);
  25. Req.set_no(node->no);
  26. Req.set_uid(0);
  27. CIOBuffer buffer;
  28. MessageHead Head;
  29. Head.Command=RemoNet::CS_MoveEnd;
  30. Head.Length=Req.ByteSize();
  31. Head.Serialize(buffer.Buffer);
  32. auto ptr=buffer.Buffer+MessageHead::Size();
  33. Req.SerializeToArray(ptr,Head.Length);
  34. buffer.Length=MessageHead::Size()+Head.Length;
  35. _message->WriteBuffer(buffer);
  36. _message->SetAutomous(false,0);
  37. }
  38. break;
  39. case AR::AR_NDTPos:
  40. {
  41. ARNdtPos* node=(ARNdtPos *)ptr;
  42. _message->SetNdtPos(node);
  43. /*
  44. RemoNet::NDTPos Req;
  45. Req.set_x(node->x);
  46. Req.set_y(node->y);
  47. Req.set_z(node->z);
  48. Req.set_rx(node->rx);
  49. Req.set_ry(node->ry);
  50. Req.set_rz(node->rz);
  51. Req.set_rw(node->rw);
  52. CIOBuffer buffer;
  53. MessageHead Head;
  54. Head.Command=RemoNet::CC_NDTPOS;
  55. Head.Length=Req.ByteSize();
  56. Head.Serialize(buffer.Buffer);
  57. auto ptr=buffer.Buffer+MessageHead::Size();
  58. Req.SerializeToArray(ptr,Head.Length);
  59. buffer.Length=MessageHead::Size()+Head.Length;
  60. _message->WriteBuffer(ChannelType::CHANNEL_CAR,buffer);
  61. */
  62. }
  63. break;
  64. default:
  65. break;
  66. }
  67. }
  68. void CAutoSensor::SetSensorSocket(SensorSocket<CAutoSensor>* can)
  69. {
  70. _socket=can;
  71. }