MainDlg.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // MainDlg.cpp : implementation of the CMainDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include <vector>
  7. #include <string>
  8. #include <json/json.h>
  9. #include <json/writer.h>
  10. #include <fstream>
  11. #include <array>
  12. #include "../common/comm.h"
  13. #include "RenderWindow.h"
  14. #include "FishEyeWindow.h"
  15. #include "MainDlg.h"
  16. LRESULT CMainDlg::OnInitDialog(HWND, LPARAM)
  17. {
  18. // center the dialog on the screen
  19. CenterWindow();
  20. // set icons
  21. HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
  22. SetIcon(hIcon, TRUE);
  23. HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
  24. SetIcon(hIconSmall, FALSE);
  25. _control = GetEgoController(this);
  26. std::array<IRender*, RenderPosition::ALL> _array;
  27. for (int32_t i = 0; i < RenderPosition::ALL; i++)
  28. {
  29. auto p = std::make_unique<CRenderWindow>();
  30. p->Start();
  31. _array[i] = p.get();
  32. _WindowArray.push_back(std::move(p));
  33. }
  34. _control->Start(_array);
  35. _fishWindow = std::make_unique<CFishEyeWindow>();
  36. _fishWindow->Start("192.168.1.64");
  37. Json::Value root;
  38. Json::Reader jsonReader;
  39. std::ifstream ifile("Config.json");
  40. std::string ip;
  41. if (jsonReader.parse(ifile, root))
  42. {
  43. _name = root["name"].asString();
  44. _account = root["account"].asString();
  45. _password = root["password"].asString();
  46. _control->Login(_account, _password);
  47. }
  48. //SetTimer(10002,10);
  49. return TRUE;
  50. }
  51. void CMainDlg::OnDestroy()
  52. {
  53. }
  54. void CMainDlg::OnNotifyConnected(bool bRet)
  55. {
  56. }
  57. void CMainDlg::OnNotifySigin(bool ret)
  58. {
  59. }
  60. void CMainDlg::OnCarConnect(WORD, WORD, HWND)
  61. {
  62. if (_carpeer != -1) return;
  63. CListViewCtrl box;
  64. box.Attach(GetDlgItem(IDC_CARLIST));
  65. int32_t cursel = box.GetSelectedIndex();
  66. if (cursel == -1) return;
  67. _carpeer = box.GetItemData(cursel);
  68. _control->OnCarConnect(_carpeer);
  69. }
  70. void CMainDlg::OnCarLeave(WORD, WORD, HWND)
  71. {
  72. _control->OnCarLeave();
  73. _carpeer = -1;
  74. }
  75. void CMainDlg::OnNotifyLeave(int32_t peer)
  76. {
  77. }
  78. void CMainDlg::OnNotifyMoveEnd(int32_t rid, WorkArea area, int32_t n)
  79. {
  80. }
  81. void CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND)
  82. {
  83. EndDialog(wID);
  84. }
  85. void CMainDlg::OnSigin(bool bRet)
  86. {
  87. PostMessage(WM_NOTIFYSIGIN, (WPARAM)bRet);
  88. }
  89. void CMainDlg::OnRobot(std::unique_ptr<UserCamera>& node)
  90. {
  91. CListViewCtrl box;
  92. box.Attach(GetDlgItem(IDC_CARLIST));
  93. std::string info = node->name;
  94. switch (node->state)
  95. {
  96. case UserState::Idle:
  97. info += " (Idle)";
  98. break;
  99. case UserState::Offline:
  100. info += " (offline)";
  101. break;
  102. case UserState::Remote:
  103. info += " (Remote)";
  104. break;
  105. case UserState::Automotive:
  106. info += "(automotive)";
  107. break;
  108. }
  109. int32_t index = box.AddItem(0, 0, info.c_str());
  110. //box.SetItemText(index, 1, robot.type() == EgoType::Car ? "Car" : "Cave");
  111. auto users = std::make_unique<UserCamera>();
  112. users->uid = node->uid;
  113. users->name = info;
  114. users->type = static_cast<EgoType>(node->type);
  115. users->state = static_cast<UserState>(node->state);
  116. // for (int32_t i = 0; i < robot.info().size(); i++)
  117. // {
  118. // auto& node = robot.info(i);
  119. // CameraInfo camera;
  120. // camera.index = static_cast<RenderPosition>(node.pos());
  121. // camera.label = node.label();
  122. // camera.solution = static_cast<DisplayResolution>(node.solution());
  123. // users->info.push_back(camera);
  124. // }
  125. box.SetItemData(index, users->uid);
  126. _userInfo.push_back(std::move(users));
  127. }
  128. void CMainDlg::OnNotifyDel(int32_t peer)
  129. {
  130. CListViewCtrl box;
  131. box.Attach(GetDlgItem(IDC_CARLIST));
  132. int32_t Count = box.GetItemCount();
  133. for (int32_t i = 0; i < Count; i++)
  134. {
  135. auto id = box.GetItemData(i);
  136. if (id == peer)
  137. {
  138. box.DeleteItem(i);
  139. break;
  140. }
  141. }
  142. for (auto it = _userInfo.begin(); it != _userInfo.end(); ++it)
  143. {
  144. if ((*it)->uid == peer)
  145. {
  146. _userInfo.erase(it);
  147. break;
  148. }
  149. }
  150. }
  151. void CMainDlg::OnNotifyPing(int32_t value)
  152. {
  153. }
  154. void CMainDlg::OnNotifyRadar(int32_t r0, int32_t r1, int32_t r2, int32_t r3, int32_t r4, int32_t r5)
  155. {
  156. }
  157. void CMainDlg::OnNotifyKickOff()
  158. {
  159. }
  160. /*
  161. void CMainDlg::OnEmergency(bool enable, bool motor, bool gear, bool turnl, bool turnR)
  162. {
  163. _enable = enable;
  164. _motor = motor;
  165. _gear = gear;
  166. _turnL = turnl;
  167. _turnR = turnR;
  168. }
  169. void CMainDlg::OnAccel(int16_t accel, bool onoff)
  170. {
  171. _accel = accel;
  172. _onoff = onoff;
  173. }
  174. void CMainDlg::OnSteer(uint64_t steer)
  175. {
  176. _steer = steer;
  177. std::string ret = std::string("steer :")+std::to_string(_steer);
  178. ret += "\n";
  179. OutputDebugString(ret.c_str());
  180. }
  181. */
  182. void CMainDlg::OnTimer(UINT idEvent)
  183. {
  184. SetDlgItemInt(IDC_ENABLE, _enable);
  185. SetDlgItemInt(IDC_MOTOR, _motor);
  186. SetDlgItemInt(IDC_GEAR, _gear);
  187. SetDlgItemInt(IDC_TURNL, _turnL);
  188. SetDlgItemInt(IDC_TURNR, _turnR);
  189. SetDlgItemInt(IDC_STEER, _steer);
  190. SetDlgItemInt(IDC_ACCEL, _accel);
  191. }
  192. /*
  193. void CMainDlg::OnArm(int16_t flip, int16_t armL, int16_t armR, bool onoff)
  194. {
  195. SetDlgItemInt(IDC_FLIP, flip);
  196. SetDlgItemInt(IDC_ARML, armL);
  197. SetDlgItemInt(IDC_ARMR, armR);
  198. SetDlgItemInt(IDC_ONOFF, onoff);
  199. }
  200. */
  201. void CMainDlg::OnLidarData(bool isLeft, bool isDense, int32_t seq, PointXYZI* data, int32_t length)
  202. {
  203. }
  204. void CMainDlg::OnNotifyFeed(const FeedData& data)
  205. {
  206. }