action_window.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using chutian_parking_terminal.Media;
  11. using tool;
  12. using chutian_parking_terminal.data_buffer;
  13. using chutian_parking_terminal.communication;
  14. using chutian_parking_terminal.motion_executer;
  15. using chutian_parking_terminal.front_terminal_manager;
  16. using chutian_parking_terminal.process_manage;
  17. using System.Threading;
  18. using Kitware.VTK;
  19. using Sunny.UI;
  20. using chutian_parking_terminal.led_screen;
  21. namespace chutian_parking_terminal
  22. {
  23. public partial class action_window : Form
  24. {
  25. //显示点云
  26. FormVtk m_form_vtk;
  27. //自适应窗口大小
  28. AutoResizeForm m_auto_resize_form= new AutoResizeForm();
  29. //显示视频,图片,等
  30. private MediaPlayer m_mediaPlayer;
  31. //显示提示框
  32. private Thread m_tip_show_thread;
  33. private bool m_tip_show_condition;
  34. private int m_ternimalID;
  35. //显示点云线程
  36. private Thread m_show_cloud_thread;
  37. private bool m_show_cloud_condition;
  38. //显示车牌号
  39. private string m_car_license;
  40. public action_window()
  41. {
  42. InitializeComponent();
  43. m_car_license = "";
  44. parkingBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
  45. fetchingBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
  46. //初始化日志记录
  47. Log.Instance.LogInit();
  48. //初始化json文件操作
  49. json_file_operation.Instance.json_file_operation_init("../../../settings.json");
  50. m_ternimalID = int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber"));
  51. //初始化数据缓冲区
  52. Front_terminal_manager.Instance.front_terminal_manager_init(int.Parse(json_file_operation.Instance.read_json_string("pickup_singleChip_connect_count")));
  53. //初始化通信
  54. Singlechip_communication.Instance.singlechip_communication_init();//单片机通信
  55. Singlechip_communication.Instance.singlechip_communication_connect();//默认从settings.json文件读取端口和IP
  56. Channel_communication.Instance.channel_communication_init();//出入口通信
  57. //添加一个方屏
  58. BroadcastBoardManager.Instance.AddSquareScreen(int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber")),
  59. Encoding.Default.GetBytes(json_file_operation.Instance.read_json_string("square_led_screen_ip")),
  60. 5005, ONNONLed5KSDKD.Led5kSDK.bx_5k_card_type.BX_6K3, 2, 0);
  61. //添加一个取车屏
  62. //BroadcastBoardManager.Instance.AddFetchScreen(int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber")),
  63. // Encoding.Default.GetBytes(json_file_operation.Instance.read_json_string("square_led_screen_ip")),
  64. // 5005, ONNONLed5KSDKD.Led5kSDK.bx_5k_card_type.BX_6K3, 2, 0);
  65. //初始化打印机
  66. PrintManual.Instance.PrintManualInit();
  67. //创建显示器
  68. m_mediaPlayer = new MediaPlayer();
  69. //初始化显示器
  70. m_mediaPlayer.MediaPlayerInit(this, ref this.pictureBox1, ref this.axWindowsMediaPlayer1, ref this.timeLab, ref this.dateLab, ref this.dateLab1);
  71. //初始化流程管理
  72. Process_manage.Instance.process_manage_init();
  73. //初始化通知管理
  74. Notify_manage.Instance.notify_manage_init();
  75. //初始化提示显示线程
  76. m_tip_show_thread = new Thread(tip_show_thread);
  77. //显示点云窗口
  78. m_form_vtk = new FormVtk();
  79. //显示点云线程
  80. m_show_cloud_thread = new Thread(show_cloud_thread);
  81. }
  82. //显示提示框
  83. private void tip_show_thread()
  84. {
  85. while (m_tip_show_condition)
  86. {
  87. if (this.InvokeRequired)
  88. {
  89. this.Invoke(new Action(() =>
  90. {
  91. tip_label.Text = Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str();
  92. statu_label.Text = "入口任务数:" + Process_manage.Instance.get_entrance_task_count().ToString() + "\n出口任务数:" + Process_manage.Instance.get_exit_task_count().ToString();
  93. }));
  94. }
  95. else
  96. {
  97. tip_label.Text = Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str();
  98. statu_label.Text = "入口任务数:" + Process_manage.Instance.get_entrance_task_count().ToString() + "\n出口任务数:" + Process_manage.Instance.get_exit_task_count().ToString();
  99. }
  100. Thread.Sleep(100);
  101. }
  102. }
  103. //显示点云
  104. private void show_cloud_thread()
  105. {
  106. while (m_show_cloud_condition )
  107. {
  108. //Random rd = new Random();
  109. //vtkPoints points = new vtkPoints();
  110. //double offset = (rd.Next() % 10 - 5) * 0.1;
  111. //for (int i = -50; i < 50; ++i)
  112. //{
  113. // for (int j = -50; j < 50; ++j)
  114. // {
  115. // points.InsertNextPoint(i * 0.01 + offset, j * 0.01, Math.Sin(i * 0.05));
  116. // }
  117. //}
  118. //var red = 255;
  119. //var green = 0;
  120. //var blue = 0;
  121. //Color color = Color.FromArgb((int)red, (int)green, (int)blue);
  122. //m_form_vtk.SetCloud(points);
  123. //m_form_vtk.SetCloudColor(color);
  124. //points.Dispose();
  125. //FormVtk.Car_info car_Info1 = new FormVtk.Car_info();
  126. //car_Info1.correct = true;
  127. //car_Info1.cx = 0;
  128. //car_Info1.cy = 0;
  129. //car_Info1.theta = offset * 10 / 180.0 * Math.PI;
  130. //car_Info1.front_theta = offset * 30 / 180.0 * Math.PI;
  131. //car_Info1.wheel_base = 2.8;
  132. //car_Info1.width = 1.7;
  133. //m_form_vtk.SetCarInfo(car_Info1);
  134. //Thread.Sleep(100);
  135. if (!Front_terminal_manager.Instance.get_ground_radar_data_buffer().has_ground_statu_msg())
  136. {
  137. m_form_vtk.set_tip_label("雷达未连接!");
  138. }
  139. else if (!Front_terminal_manager.Instance.get_singlechip_data_bufferr().has_entrance_singlechip_msg())
  140. {
  141. m_form_vtk.set_tip_label("单片机未连接!");
  142. }
  143. else
  144. {
  145. //填充信息
  146. Message.Ground_status_msg t_ground_status_msg = Front_terminal_manager.Instance.get_ground_radar_data_buffer().get_ground_status_msg();
  147. if (t_ground_status_msg.TerminalId == m_ternimalID)
  148. {
  149. string t_license = Process_manage.Instance.get_entrance_task_license();
  150. if (t_license != "")
  151. {
  152. m_car_license = t_license;
  153. }
  154. string t_car_type = Process_manage.Instance.get_entrance_task_car_type();
  155. FormVtk.Car_info car_Info = new FormVtk.Car_info();
  156. //雷达测量结果是否正确
  157. car_Info.correct = t_ground_status_msg.LocateInformationRealtime.LocateCorrect;
  158. if (!car_Info.correct)
  159. {
  160. m_form_vtk.set_tip_label("测量中!");
  161. m_form_vtk.isArrowsVisible(false);
  162. t_ground_status_msg.LocateInformationRealtime.LocateWheelWidth = 0;
  163. t_ground_status_msg.LocateInformationRealtime.LocateWheelBase = 0;
  164. t_ground_status_msg.LocateInformationRealtime.LocateWidth = 0;
  165. t_ground_status_msg.LocateInformationRealtime.LocateLength = 0;
  166. t_ground_status_msg.LocateInformationRealtime.LocateFrontTheta = 0;
  167. t_ground_status_msg.LocateInformationRealtime.LocateAngle = 0;
  168. t_ground_status_msg.LocateInformationRealtime.LocateX = 0;
  169. t_ground_status_msg.LocateInformationRealtime.LocateY = 0;
  170. }
  171. car_Info.cx = t_ground_status_msg.LocateInformationRealtime.LocateX;
  172. car_Info.cy = t_ground_status_msg.LocateInformationRealtime.LocateY;
  173. car_Info.front_theta = t_ground_status_msg.LocateInformationRealtime.LocateFrontTheta / 180.0 * Math.PI;
  174. car_Info.theta = (t_ground_status_msg.LocateInformationRealtime.LocateAngle - 90) / 180.0 * Math.PI;
  175. car_Info.wheel_base = t_ground_status_msg.LocateInformationRealtime.LocateWheelBase;
  176. car_Info.width = t_ground_status_msg.LocateInformationRealtime.LocateWheelWidth;
  177. m_form_vtk.set_car_data_label("车牌号:" + m_car_license + "\n\n" +
  178. "车辆类型:" + t_car_type + "\n\n" +
  179. "左右轮距:" + t_ground_status_msg.LocateInformationRealtime.LocateWheelWidth.ToString() + "\n\n" +
  180. "前后轮距:" + t_ground_status_msg.LocateInformationRealtime.LocateWheelBase.ToString() + "\n\n" +
  181. "整车宽度:" + t_ground_status_msg.LocateInformationRealtime.LocateWidth.ToString() + "\n\n" +
  182. "整车长度:" + t_ground_status_msg.LocateInformationRealtime.LocateLength.ToString() + "\n\n" +
  183. "前轮旋转角度:" + t_ground_status_msg.LocateInformationRealtime.LocateFrontTheta.ToString() + "\n\n" +
  184. "整车旋转角:" + t_ground_status_msg.LocateInformationRealtime.LocateAngle.ToString() + "\n\n" +
  185. "中心点X:" + t_ground_status_msg.LocateInformationRealtime.LocateX.ToString() + "\n\n" +
  186. "中心点Y:" + t_ground_status_msg.LocateInformationRealtime.LocateY.ToString() + "\n\n\n\n\n\n\n");
  187. vtkPoints vtkPoints = new vtkPoints();
  188. for (int i = 0; i < t_ground_status_msg.Cloud.Count; ++i)
  189. {
  190. vtkPoints.InsertNextPoint(t_ground_status_msg.Cloud[i].X, t_ground_status_msg.Cloud[i].Y, t_ground_status_msg.Cloud[i].Z);
  191. }
  192. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.correct = " + car_Info.correct.ToString());
  193. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.cx = " + car_Info.cx.ToString());
  194. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.cy = " + car_Info.cy.ToString());
  195. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.front_theta = " + car_Info.front_theta.ToString());
  196. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.wheel_base = " + car_Info.wheel_base.ToString());
  197. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.width = " + car_Info.width.ToString());
  198. //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.theta = " + car_Info.theta.ToString());
  199. m_form_vtk.SetCarInfo(car_Info);
  200. m_form_vtk.SetCloud(vtkPoints);
  201. SingleChip.initial_singlechip_msg initial_Singlechip_Msg = Front_terminal_manager.Instance.get_singlechip_data_bufferr().get_entrance_singlechip_msg();
  202. //前超界
  203. if (initial_Singlechip_Msg.InPutDi.Di0 == 1)
  204. {
  205. m_form_vtk.set_tip_label("车辆前超界!");
  206. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_down);
  207. m_form_vtk.isArrowsVisible(true);
  208. m_form_vtk.set_tip_car_label("请后退!");
  209. }
  210. //后超界
  211. if (initial_Singlechip_Msg.InPutDi.Di1 == 1)
  212. {
  213. m_form_vtk.set_tip_label("车辆后超界!");
  214. m_form_vtk.isCorrect(false);
  215. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_top);
  216. m_form_vtk.isArrowsVisible(true);
  217. m_form_vtk.set_tip_car_label("请前进!");
  218. }
  219. //左超界
  220. else if (t_ground_status_msg.GroundStatus == Message.Ground_statu.CarLeftOut)
  221. {
  222. m_form_vtk.set_tip_label("车辆左超界!");
  223. m_form_vtk.isCorrect(false);
  224. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_right);
  225. m_form_vtk.isArrowsVisible(true);
  226. m_form_vtk.set_tip_car_label("请向右!");
  227. }
  228. //右超界
  229. else if (t_ground_status_msg.GroundStatus == Message.Ground_statu.CarRightOut)
  230. {
  231. m_form_vtk.set_tip_label("车辆右超界!");
  232. m_form_vtk.isCorrect(false);
  233. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_left);
  234. m_form_vtk.isArrowsVisible(true);
  235. m_form_vtk.set_tip_car_label("请向左!");
  236. }
  237. //前超界+左超界
  238. if (initial_Singlechip_Msg.InPutDi.Di0 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarLeftOut)
  239. {
  240. m_form_vtk.set_tip_label("车辆左前超界!");
  241. m_form_vtk.isCorrect(false);
  242. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_lowerright);
  243. m_form_vtk.isArrowsVisible(true);
  244. m_form_vtk.set_tip_car_label("请向右后!");
  245. }
  246. //前超界+右超界
  247. else if (initial_Singlechip_Msg.InPutDi.Di0 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarRightOut)
  248. {
  249. m_form_vtk.set_tip_label("车辆右前超界!");
  250. m_form_vtk.isCorrect(false);
  251. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_lowerleft);
  252. m_form_vtk.isArrowsVisible(true);
  253. m_form_vtk.set_tip_car_label("请向左后!");
  254. }
  255. //后超界+左超界
  256. if (initial_Singlechip_Msg.InPutDi.Di1 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarLeftOut)
  257. {
  258. m_form_vtk.set_tip_label("车辆左后超界!");
  259. m_form_vtk.isCorrect(false);
  260. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_upperright);
  261. m_form_vtk.isArrowsVisible(true);
  262. m_form_vtk.set_tip_car_label("请向右前!");
  263. }
  264. //后超界+右超界
  265. else if (initial_Singlechip_Msg.InPutDi.Di1 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarRightOut)
  266. {
  267. m_form_vtk.set_tip_label("车辆右后超界!");
  268. m_form_vtk.isCorrect(false);
  269. m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_upperleft);
  270. m_form_vtk.isArrowsVisible(true);
  271. m_form_vtk.set_tip_car_label("请向左前!");
  272. }
  273. //if ((t_ground_status_msg.LocateInformationRealtime.UniformedCarY +
  274. // t_ground_status_msg.LocateInformationRealtime.LocateWheelBase / 2) < -4.25)
  275. //{
  276. // m_form_vtk.set_tip_label("行程不够!");
  277. // m_form_vtk.SetScore(0);
  278. // m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_top);
  279. // m_form_vtk.isArrowsVisible(true);
  280. // m_form_vtk.set_tip_car_label("请前进!");
  281. //}
  282. if (initial_Singlechip_Msg.InPutDi.Di0 != 1 &&
  283. initial_Singlechip_Msg.InPutDi.Di1 != 1 &&
  284. t_ground_status_msg.GroundStatus == Message.Ground_statu.CarCorrect &&
  285. initial_Singlechip_Msg.InPutDi.Di6 == 1)
  286. {
  287. m_form_vtk.isCorrect(true) ;
  288. m_form_vtk.isArrowsVisible(false);
  289. m_form_vtk.set_tip_car_label("车已摆正!");
  290. }
  291. }
  292. else
  293. {
  294. m_form_vtk.set_tip_label("未接收到本终端雷达信息!");
  295. }
  296. }
  297. Thread.Sleep(1);
  298. }
  299. }
  300. private void parkingBtn_Click(object sender, EventArgs e)
  301. {
  302. //检查单片机通信状态
  303. if (Singlechip_communication.Instance.check_entrance_statu())
  304. {
  305. //点击停车按钮时 判断入口能否进行停车、
  306. if (Process_manage.Instance.check_entrance_statu())
  307. {
  308. //开始停车流程
  309. Process_manage.Instance.entrance_task_run();
  310. //修改方屏状态
  311. BroadcastBoardManager.Instance.squareBoardList[0].UpdateStatus(BroadcastSquareBoard.Entrance_statu.ENTRANCE_OCCUPIED, false);
  312. }
  313. else
  314. {
  315. if (Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str() == "")
  316. {
  317. MessageBoxForm messageBoxForm = new MessageBoxForm();
  318. messageBoxForm.ShowDialog("未检测到车辆!");
  319. }
  320. else
  321. {
  322. MessageBoxForm messageBoxForm = new MessageBoxForm();
  323. messageBoxForm.ShowDialog(Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str());
  324. }
  325. }
  326. }
  327. else
  328. {
  329. MessageBoxForm messageBoxForm = new MessageBoxForm();
  330. messageBoxForm.ShowDialog("单片机未连接...");
  331. }
  332. }
  333. private void fetchingBtn_Click(object sender, EventArgs e)
  334. {
  335. //MessageBoxForm messageBoxForm = new MessageBoxForm();
  336. //messageBoxForm.setText("该终端为停车终端,暂时无法用于取车!");
  337. //messageBoxForm.ShowDialog();
  338. //检查单片机通信状态
  339. if (Singlechip_communication.Instance.check_exit_statu())
  340. {
  341. //此窗口只获取车牌号
  342. FetchingForm fetchingForm = new FetchingForm();
  343. fetchingForm.StartPosition = FormStartPosition.CenterScreen;
  344. fetchingForm.BringToFront();
  345. fetchingForm.ShowDialog();
  346. if (fetchingForm.m_is_return)
  347. {
  348. return;
  349. }
  350. //检查车牌号是否合法
  351. if (Process_manage.Instance.check_exit_task_license())
  352. {
  353. Process_manage.Instance.add_exit_task();
  354. }
  355. else
  356. {
  357. MessageBoxForm messageBoxForm = new MessageBoxForm();
  358. messageBoxForm.ShowDialog("非正常车牌号!");
  359. }
  360. }
  361. else
  362. {
  363. MessageBoxForm messageBoxForm = new MessageBoxForm();
  364. messageBoxForm.ShowDialog("单片机未连接...");
  365. }
  366. }
  367. private void action_window_Load(object sender, EventArgs e)
  368. {
  369. if (MessageBox.Show("是否最大化?", "tip", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
  370. {
  371. //设置最大化
  372. this.WindowState = FormWindowState.Maximized;
  373. }
  374. //启动播放器
  375. m_mediaPlayer.mediaplayer_run();
  376. //显示提示
  377. m_tip_show_condition = true;
  378. m_tip_show_thread.Start();
  379. //启动打印机
  380. PrintManual.Instance.Start();
  381. m_show_cloud_condition = true;
  382. m_show_cloud_thread.Start();
  383. m_auto_resize_form.controllInitializeSize(this);
  384. Screen[] sc = Screen.AllScreens;
  385. if (sc.Count() > 1)
  386. {
  387. m_form_vtk.StartPosition = FormStartPosition.Manual;
  388. m_form_vtk.Location = new Point(sc[1].Bounds.Left, sc[1].Bounds.Top);
  389. m_form_vtk.WindowState = FormWindowState.Maximized;
  390. }
  391. m_form_vtk.SetBound(-2, 2, -3, 3, 0, 2.0);
  392. m_form_vtk.Show();
  393. }
  394. private void action_window_FormClosing(object sender, FormClosingEventArgs e)
  395. {
  396. //关闭点云显示
  397. m_show_cloud_condition = false;
  398. m_show_cloud_thread.Abort();
  399. m_form_vtk.FormVtkUninit();
  400. //关闭播放器
  401. m_mediaPlayer.mediaplayer_uninit();
  402. //关闭单片机通信
  403. Singlechip_communication.Instance.singlechip_communication_uninit();
  404. //关闭出入口通信
  405. Channel_communication.Instance.channel_communication_uninit();
  406. //关闭流程管理
  407. Process_manage.Instance.process_manage_uninit();
  408. //关闭通知管理
  409. Notify_manage.Instance.notify_manage_uninit();
  410. //关闭显示提示
  411. m_tip_show_condition = false;
  412. m_tip_show_thread.Abort();
  413. //关闭数据管理的线程
  414. Front_terminal_manager.Instance.front_terminal_manager_uninit();
  415. //关闭打印机
  416. PrintManual.Instance.Close();
  417. //设置屏幕无信号
  418. BroadcastBoardManager.Instance.squareBoardList[0].UpdateStatus(BroadcastSquareBoard.Entrance_statu.ENTRANCE_NOSIGNAL, false);
  419. BroadcastBoardManager.Instance.squareBoardList[0].set_disp_str(" 无信号 X");
  420. Thread.Sleep(160);
  421. //关闭led屏
  422. BroadcastBoardManager.Instance.Close();
  423. }
  424. private void axWindowsMediaPlayer1_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e)
  425. {
  426. if (this.axWindowsMediaPlayer1.fullScreen == true)
  427. {
  428. this.axWindowsMediaPlayer1.fullScreen = false;
  429. }
  430. }
  431. private void action_window_SizeChanged(object sender, EventArgs e)
  432. {
  433. m_auto_resize_form.controlAutoSize(this);
  434. }
  435. }
  436. }