123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using chutian_parking_terminal.Media;
- using tool;
- using chutian_parking_terminal.data_buffer;
- using chutian_parking_terminal.communication;
- using chutian_parking_terminal.motion_executer;
- using chutian_parking_terminal.front_terminal_manager;
- using chutian_parking_terminal.process_manage;
- using System.Threading;
- using Kitware.VTK;
- using Sunny.UI;
- using chutian_parking_terminal.led_screen;
- namespace chutian_parking_terminal
- {
- public partial class action_window : Form
- {
- //显示点云
- FormVtk m_form_vtk;
- //自适应窗口大小
- AutoResizeForm m_auto_resize_form= new AutoResizeForm();
- //显示视频,图片,等
- private MediaPlayer m_mediaPlayer;
- //显示提示框
- private Thread m_tip_show_thread;
- private bool m_tip_show_condition;
- private int m_ternimalID;
- //显示点云线程
- private Thread m_show_cloud_thread;
- private bool m_show_cloud_condition;
- //显示车牌号
- private string m_car_license;
- public action_window()
- {
- InitializeComponent();
- m_car_license = "";
- parkingBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- fetchingBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- //初始化日志记录
- Log.Instance.LogInit();
- //初始化json文件操作
- json_file_operation.Instance.json_file_operation_init("../../../settings.json");
- m_ternimalID = int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber"));
- //初始化数据缓冲区
- Front_terminal_manager.Instance.front_terminal_manager_init(int.Parse(json_file_operation.Instance.read_json_string("pickup_singleChip_connect_count")));
- //初始化通信
- Singlechip_communication.Instance.singlechip_communication_init();//单片机通信
- Singlechip_communication.Instance.singlechip_communication_connect();//默认从settings.json文件读取端口和IP
-
- Channel_communication.Instance.channel_communication_init();//出入口通信
- //添加一个方屏
- BroadcastBoardManager.Instance.AddSquareScreen(int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber")),
- Encoding.Default.GetBytes(json_file_operation.Instance.read_json_string("square_led_screen_ip")),
- 5005, ONNONLed5KSDKD.Led5kSDK.bx_5k_card_type.BX_6K3, 2, 0);
- //添加一个取车屏
- //BroadcastBoardManager.Instance.AddFetchScreen(int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber")),
- // Encoding.Default.GetBytes(json_file_operation.Instance.read_json_string("square_led_screen_ip")),
- // 5005, ONNONLed5KSDKD.Led5kSDK.bx_5k_card_type.BX_6K3, 2, 0);
- //初始化打印机
- PrintManual.Instance.PrintManualInit();
- //创建显示器
- m_mediaPlayer = new MediaPlayer();
- //初始化显示器
- m_mediaPlayer.MediaPlayerInit(this, ref this.pictureBox1, ref this.axWindowsMediaPlayer1, ref this.timeLab, ref this.dateLab, ref this.dateLab1);
- //初始化流程管理
- Process_manage.Instance.process_manage_init();
- //初始化通知管理
- Notify_manage.Instance.notify_manage_init();
- //初始化提示显示线程
- m_tip_show_thread = new Thread(tip_show_thread);
- //显示点云窗口
- m_form_vtk = new FormVtk();
- //显示点云线程
- m_show_cloud_thread = new Thread(show_cloud_thread);
- }
- //显示提示框
- private void tip_show_thread()
- {
- while (m_tip_show_condition)
- {
- if (this.InvokeRequired)
- {
- this.Invoke(new Action(() =>
- {
- tip_label.Text = Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str();
- statu_label.Text = "入口任务数:" + Process_manage.Instance.get_entrance_task_count().ToString() + "\n出口任务数:" + Process_manage.Instance.get_exit_task_count().ToString();
- }));
- }
- else
- {
- tip_label.Text = Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str();
- statu_label.Text = "入口任务数:" + Process_manage.Instance.get_entrance_task_count().ToString() + "\n出口任务数:" + Process_manage.Instance.get_exit_task_count().ToString();
- }
- Thread.Sleep(100);
- }
- }
- //显示点云
- private void show_cloud_thread()
- {
- while (m_show_cloud_condition )
- {
- //Random rd = new Random();
- //vtkPoints points = new vtkPoints();
- //double offset = (rd.Next() % 10 - 5) * 0.1;
- //for (int i = -50; i < 50; ++i)
- //{
- // for (int j = -50; j < 50; ++j)
- // {
- // points.InsertNextPoint(i * 0.01 + offset, j * 0.01, Math.Sin(i * 0.05));
- // }
- //}
- //var red = 255;
- //var green = 0;
- //var blue = 0;
- //Color color = Color.FromArgb((int)red, (int)green, (int)blue);
- //m_form_vtk.SetCloud(points);
- //m_form_vtk.SetCloudColor(color);
- //points.Dispose();
- //FormVtk.Car_info car_Info1 = new FormVtk.Car_info();
- //car_Info1.correct = true;
- //car_Info1.cx = 0;
- //car_Info1.cy = 0;
- //car_Info1.theta = offset * 10 / 180.0 * Math.PI;
- //car_Info1.front_theta = offset * 30 / 180.0 * Math.PI;
- //car_Info1.wheel_base = 2.8;
- //car_Info1.width = 1.7;
- //m_form_vtk.SetCarInfo(car_Info1);
- //Thread.Sleep(100);
- if (!Front_terminal_manager.Instance.get_ground_radar_data_buffer().has_ground_statu_msg())
- {
- m_form_vtk.set_tip_label("雷达未连接!");
- }
- else if (!Front_terminal_manager.Instance.get_singlechip_data_bufferr().has_entrance_singlechip_msg())
- {
- m_form_vtk.set_tip_label("单片机未连接!");
- }
- else
- {
- //填充信息
- Message.Ground_status_msg t_ground_status_msg = Front_terminal_manager.Instance.get_ground_radar_data_buffer().get_ground_status_msg();
- if (t_ground_status_msg.TerminalId == m_ternimalID)
- {
- string t_license = Process_manage.Instance.get_entrance_task_license();
- if (t_license != "")
- {
- m_car_license = t_license;
- }
- string t_car_type = Process_manage.Instance.get_entrance_task_car_type();
- FormVtk.Car_info car_Info = new FormVtk.Car_info();
- //雷达测量结果是否正确
- car_Info.correct = t_ground_status_msg.LocateInformationRealtime.LocateCorrect;
- if (!car_Info.correct)
- {
- m_form_vtk.set_tip_label("测量中!");
- m_form_vtk.isArrowsVisible(false);
- t_ground_status_msg.LocateInformationRealtime.LocateWheelWidth = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateWheelBase = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateWidth = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateLength = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateFrontTheta = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateAngle = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateX = 0;
- t_ground_status_msg.LocateInformationRealtime.LocateY = 0;
- }
- car_Info.cx = t_ground_status_msg.LocateInformationRealtime.LocateX;
- car_Info.cy = t_ground_status_msg.LocateInformationRealtime.LocateY;
- car_Info.front_theta = t_ground_status_msg.LocateInformationRealtime.LocateFrontTheta / 180.0 * Math.PI;
- car_Info.theta = (t_ground_status_msg.LocateInformationRealtime.LocateAngle - 90) / 180.0 * Math.PI;
- car_Info.wheel_base = t_ground_status_msg.LocateInformationRealtime.LocateWheelBase;
- car_Info.width = t_ground_status_msg.LocateInformationRealtime.LocateWheelWidth;
- m_form_vtk.set_car_data_label("车牌号:" + m_car_license + "\n\n" +
- "车辆类型:" + t_car_type + "\n\n" +
- "左右轮距:" + t_ground_status_msg.LocateInformationRealtime.LocateWheelWidth.ToString() + "\n\n" +
- "前后轮距:" + t_ground_status_msg.LocateInformationRealtime.LocateWheelBase.ToString() + "\n\n" +
- "整车宽度:" + t_ground_status_msg.LocateInformationRealtime.LocateWidth.ToString() + "\n\n" +
- "整车长度:" + t_ground_status_msg.LocateInformationRealtime.LocateLength.ToString() + "\n\n" +
- "前轮旋转角度:" + t_ground_status_msg.LocateInformationRealtime.LocateFrontTheta.ToString() + "\n\n" +
- "整车旋转角:" + t_ground_status_msg.LocateInformationRealtime.LocateAngle.ToString() + "\n\n" +
- "中心点X:" + t_ground_status_msg.LocateInformationRealtime.LocateX.ToString() + "\n\n" +
- "中心点Y:" + t_ground_status_msg.LocateInformationRealtime.LocateY.ToString() + "\n\n\n\n\n\n\n");
-
- vtkPoints vtkPoints = new vtkPoints();
- for (int i = 0; i < t_ground_status_msg.Cloud.Count; ++i)
- {
- vtkPoints.InsertNextPoint(t_ground_status_msg.Cloud[i].X, t_ground_status_msg.Cloud[i].Y, t_ground_status_msg.Cloud[i].Z);
- }
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.correct = " + car_Info.correct.ToString());
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.cx = " + car_Info.cx.ToString());
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.cy = " + car_Info.cy.ToString());
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.front_theta = " + car_Info.front_theta.ToString());
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.wheel_base = " + car_Info.wheel_base.ToString());
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.width = " + car_Info.width.ToString());
- //Log.Instance.WriteLog(LogType.PROCESS, tool.LogFile.LOG, "car_Info.theta = " + car_Info.theta.ToString());
- m_form_vtk.SetCarInfo(car_Info);
- m_form_vtk.SetCloud(vtkPoints);
- SingleChip.initial_singlechip_msg initial_Singlechip_Msg = Front_terminal_manager.Instance.get_singlechip_data_bufferr().get_entrance_singlechip_msg();
- //前超界
- if (initial_Singlechip_Msg.InPutDi.Di0 == 1)
- {
- m_form_vtk.set_tip_label("车辆前超界!");
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_down);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请后退!");
- }
- //后超界
- if (initial_Singlechip_Msg.InPutDi.Di1 == 1)
- {
- m_form_vtk.set_tip_label("车辆后超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_top);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请前进!");
- }
- //左超界
- else if (t_ground_status_msg.GroundStatus == Message.Ground_statu.CarLeftOut)
- {
- m_form_vtk.set_tip_label("车辆左超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_right);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请向右!");
- }
- //右超界
- else if (t_ground_status_msg.GroundStatus == Message.Ground_statu.CarRightOut)
- {
- m_form_vtk.set_tip_label("车辆右超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_left);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请向左!");
- }
- //前超界+左超界
- if (initial_Singlechip_Msg.InPutDi.Di0 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarLeftOut)
- {
- m_form_vtk.set_tip_label("车辆左前超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_lowerright);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请向右后!");
- }
- //前超界+右超界
- else if (initial_Singlechip_Msg.InPutDi.Di0 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarRightOut)
- {
- m_form_vtk.set_tip_label("车辆右前超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_lowerleft);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请向左后!");
- }
- //后超界+左超界
- if (initial_Singlechip_Msg.InPutDi.Di1 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarLeftOut)
- {
- m_form_vtk.set_tip_label("车辆左后超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_upperright);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请向右前!");
- }
- //后超界+右超界
- else if (initial_Singlechip_Msg.InPutDi.Di1 == 1 && t_ground_status_msg.GroundStatus == Message.Ground_statu.CarRightOut)
- {
- m_form_vtk.set_tip_label("车辆右后超界!");
- m_form_vtk.isCorrect(false);
- m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_upperleft);
- m_form_vtk.isArrowsVisible(true);
- m_form_vtk.set_tip_car_label("请向左前!");
- }
- //if ((t_ground_status_msg.LocateInformationRealtime.UniformedCarY +
- // t_ground_status_msg.LocateInformationRealtime.LocateWheelBase / 2) < -4.25)
- //{
- // m_form_vtk.set_tip_label("行程不够!");
- // m_form_vtk.SetScore(0);
- // m_form_vtk.SetArrows(FormVtk.Arrows.eArrows_top);
- // m_form_vtk.isArrowsVisible(true);
- // m_form_vtk.set_tip_car_label("请前进!");
- //}
- if (initial_Singlechip_Msg.InPutDi.Di0 != 1 &&
- initial_Singlechip_Msg.InPutDi.Di1 != 1 &&
- t_ground_status_msg.GroundStatus == Message.Ground_statu.CarCorrect &&
- initial_Singlechip_Msg.InPutDi.Di6 == 1)
- {
- m_form_vtk.isCorrect(true) ;
- m_form_vtk.isArrowsVisible(false);
- m_form_vtk.set_tip_car_label("车已摆正!");
- }
- }
- else
- {
- m_form_vtk.set_tip_label("未接收到本终端雷达信息!");
- }
- }
- Thread.Sleep(1);
- }
- }
- private void parkingBtn_Click(object sender, EventArgs e)
- {
- //检查单片机通信状态
- if (Singlechip_communication.Instance.check_entrance_statu())
- {
- //点击停车按钮时 判断入口能否进行停车、
- if (Process_manage.Instance.check_entrance_statu())
- {
- //开始停车流程
- Process_manage.Instance.entrance_task_run();
- //修改方屏状态
- BroadcastBoardManager.Instance.squareBoardList[0].UpdateStatus(BroadcastSquareBoard.Entrance_statu.ENTRANCE_OCCUPIED, false);
- }
- else
- {
- if (Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str() == "")
- {
- MessageBoxForm messageBoxForm = new MessageBoxForm();
- messageBoxForm.ShowDialog("未检测到车辆!");
- }
- else
- {
- MessageBoxForm messageBoxForm = new MessageBoxForm();
- messageBoxForm.ShowDialog(Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str());
- }
- }
- }
- else
- {
- MessageBoxForm messageBoxForm = new MessageBoxForm();
- messageBoxForm.ShowDialog("单片机未连接...");
- }
-
- }
- private void fetchingBtn_Click(object sender, EventArgs e)
- {
- //MessageBoxForm messageBoxForm = new MessageBoxForm();
- //messageBoxForm.setText("该终端为停车终端,暂时无法用于取车!");
- //messageBoxForm.ShowDialog();
- //检查单片机通信状态
- if (Singlechip_communication.Instance.check_exit_statu())
- {
- //此窗口只获取车牌号
- FetchingForm fetchingForm = new FetchingForm();
- fetchingForm.StartPosition = FormStartPosition.CenterScreen;
- fetchingForm.BringToFront();
- fetchingForm.ShowDialog();
- if (fetchingForm.m_is_return)
- {
- return;
- }
- //检查车牌号是否合法
- if (Process_manage.Instance.check_exit_task_license())
- {
- Process_manage.Instance.add_exit_task();
- }
- else
- {
- MessageBoxForm messageBoxForm = new MessageBoxForm();
- messageBoxForm.ShowDialog("非正常车牌号!");
- }
- }
- else
- {
- MessageBoxForm messageBoxForm = new MessageBoxForm();
- messageBoxForm.ShowDialog("单片机未连接...");
- }
-
- }
- private void action_window_Load(object sender, EventArgs e)
- {
- if (MessageBox.Show("是否最大化?", "tip", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
- {
- //设置最大化
- this.WindowState = FormWindowState.Maximized;
- }
- //启动播放器
- m_mediaPlayer.mediaplayer_run();
- //显示提示
- m_tip_show_condition = true;
- m_tip_show_thread.Start();
- //启动打印机
- PrintManual.Instance.Start();
- m_show_cloud_condition = true;
- m_show_cloud_thread.Start();
- m_auto_resize_form.controllInitializeSize(this);
- Screen[] sc = Screen.AllScreens;
- if (sc.Count() > 1)
- {
- m_form_vtk.StartPosition = FormStartPosition.Manual;
- m_form_vtk.Location = new Point(sc[1].Bounds.Left, sc[1].Bounds.Top);
- m_form_vtk.WindowState = FormWindowState.Maximized;
- }
- m_form_vtk.SetBound(-2, 2, -3, 3, 0, 2.0);
- m_form_vtk.Show();
- }
- private void action_window_FormClosing(object sender, FormClosingEventArgs e)
- {
-
- //关闭点云显示
- m_show_cloud_condition = false;
- m_show_cloud_thread.Abort();
- m_form_vtk.FormVtkUninit();
- //关闭播放器
- m_mediaPlayer.mediaplayer_uninit();
- //关闭单片机通信
- Singlechip_communication.Instance.singlechip_communication_uninit();
- //关闭出入口通信
- Channel_communication.Instance.channel_communication_uninit();
- //关闭流程管理
- Process_manage.Instance.process_manage_uninit();
- //关闭通知管理
- Notify_manage.Instance.notify_manage_uninit();
- //关闭显示提示
- m_tip_show_condition = false;
- m_tip_show_thread.Abort();
- //关闭数据管理的线程
- Front_terminal_manager.Instance.front_terminal_manager_uninit();
- //关闭打印机
- PrintManual.Instance.Close();
- //设置屏幕无信号
- BroadcastBoardManager.Instance.squareBoardList[0].UpdateStatus(BroadcastSquareBoard.Entrance_statu.ENTRANCE_NOSIGNAL, false);
- BroadcastBoardManager.Instance.squareBoardList[0].set_disp_str(" 无信号 X");
- Thread.Sleep(160);
- //关闭led屏
- BroadcastBoardManager.Instance.Close();
- }
- private void axWindowsMediaPlayer1_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e)
- {
- if (this.axWindowsMediaPlayer1.fullScreen == true)
- {
- this.axWindowsMediaPlayer1.fullScreen = false;
- }
- }
- private void action_window_SizeChanged(object sender, EventArgs e)
- {
- m_auto_resize_form.controlAutoSize(this);
- }
- }
- }
-
|