rsdriver.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef RSDRIVER_H
  2. #define RSDRIVER_H
  3. #include <thread>
  4. #include <iostream>
  5. #include <QUdpSocket>
  6. #include <QNetworkDatagram>
  7. #include <iostream>
  8. #include <QMutex>
  9. #include <QDateTime>
  10. #include "rawdata.h"
  11. #include <pcl/point_cloud.h>
  12. #include <pcl/point_types.h>
  13. #include "modulecomm.h"
  14. namespace lidar{
  15. extern char gstr_hostip[256];
  16. extern char gstr_port[256];
  17. struct {
  18. std::string frame_id; ///< tf frame ID
  19. std::string model; ///< device model name
  20. int npackets; ///< number of packets to collect
  21. double rpm; ///< device rotation rate (RPMs)
  22. double time_offset; ///< time in seconds added to each time stamp
  23. bool start_from_edge;
  24. } config_;
  25. void getPacket(int n);
  26. int StartLidar_rs_m1();
  27. void StopLidar_rs_m1();
  28. class rsM1_Buf
  29. {
  30. private:
  31. char * mstrdata;
  32. int mnSize; //Data SizeUse
  33. QMutex mMutex;
  34. int mIndex;
  35. public:
  36. rsM1_Buf()
  37. {
  38. mstrdata = new char[BK32_DATA_BUFSIZE];
  39. mIndex = 0;
  40. mnSize = 0;
  41. }
  42. ~rsM1_Buf()
  43. {
  44. delete mstrdata;
  45. }
  46. void WriteData(const char * strdata,const int nSize)
  47. {
  48. mMutex.lock();
  49. memcpy(mstrdata,strdata,nSize);
  50. mnSize = nSize;
  51. mIndex++;
  52. mMutex.unlock();
  53. }
  54. int ReadData(char * strdata,const int nRead,int * pnIndex)
  55. {
  56. int nRtn = 0;
  57. if(mnSize <= 0)return 0;
  58. mMutex.lock();
  59. nRtn = mnSize;
  60. if(nRtn >nRead)
  61. {
  62. nRtn = nRead;
  63. std::cout<<"lidar_rsM1 rsM1_Buf ReadData data nRead = "<<nRead<<" is small"<<std::endl;
  64. }
  65. memcpy(strdata,mstrdata,nRtn);
  66. mnSize = 0;
  67. if(pnIndex != 0)*pnIndex = mIndex;
  68. mMutex.unlock();
  69. return nRtn;
  70. }
  71. };
  72. }
  73. #endif // RSDRIVER_H