action_window.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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.front_terminal_manager;
  15. using System.Threading;
  16. using Kitware.VTK;
  17. using Google.Protobuf;
  18. using System.Security.Cryptography;
  19. using System.Diagnostics;
  20. using System.Speech.Synthesis;
  21. using System.Globalization;
  22. namespace chutian_parking_terminal
  23. {
  24. public partial class action_window : Form
  25. {
  26. //自适应窗口大小
  27. AutoResizeForm m_auto_resize_form = new AutoResizeForm();
  28. //显示视频,图片,等
  29. private MediaPlayer m_mediaPlayer;
  30. //显示提示框
  31. private Thread m_tip_show_thread;
  32. private bool m_tip_show_condition;
  33. //本终端终端号
  34. private int m_ternimalID;
  35. //存车反馈
  36. private Message.Store_command_response_msg m_store_command_response_msg;
  37. //查询反馈
  38. private Message.Parkspace_search_response_msg m_search_response_msg;
  39. //取车反馈
  40. private Message.Pickup_command_response_msg m_pickup_command_response_msg;
  41. //存车车牌号
  42. private string m_parking_license;
  43. //取车车牌号
  44. private string m_pickup_license;
  45. //子进程
  46. private Process m_process;
  47. private bool m_process_is_start;
  48. public action_window()
  49. {
  50. InitializeComponent();
  51. m_parking_license = "";
  52. m_pickup_license = "";
  53. parkingBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
  54. // fetchingBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
  55. //初始化日志记录
  56. Log.Instance.LogInit();
  57. //初始化json文件操作
  58. json_file_operation.Instance.json_file_operation_init("./settings.json");
  59. m_ternimalID = int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber"));
  60. //初始化数据缓冲区
  61. Front_terminal_manager.Instance.front_terminal_manager_init(int.Parse(json_file_operation.Instance.read_json_string("pickup_singleChip_connect_count")));
  62. //初始化通信
  63. Channel_communication.Instance.channel_communication_init();
  64. Singlechip_communication.Instance.singlechip_communication_init();//单片机通信
  65. Singlechip_communication.Instance.singlechip_communication_connect();//默认从settings.json文件读取端口和IP
  66. //初始化打印机
  67. PrintManual.Instance.PrintManualInit();
  68. //创建显示器
  69. m_mediaPlayer = new MediaPlayer();
  70. //初始化显示器
  71. m_mediaPlayer.MediaPlayerInit(this, ref this.image_pictureBox, ref this.axWindowsMediaPlayer, ref this.time_label, ref this.date_label_1, ref this.date_label_2);
  72. //初始化提示显示线程
  73. m_tip_show_thread = new Thread(tip_show_thread);
  74. //初始化反馈
  75. m_store_command_response_msg = null;
  76. m_search_response_msg = null;
  77. m_pickup_command_response_msg = null;
  78. //设置回调函数
  79. Channel_communication.Instance.SetStoreResponseMsgDelegate(set_store_response_msg);
  80. Channel_communication.Instance.SetPickupResponseMsgDelegate(set_pickup_response_msg);
  81. Channel_communication.Instance.SetParkspaceSearchMsgDelegate(set_search_response_msg);
  82. //设置状态发送间隔
  83. Channel_communication.Instance.set_encapsulate_cycle_time(50);
  84. m_process_is_start = false;
  85. }
  86. //显示提示框
  87. private void tip_show_thread()
  88. {
  89. while (m_tip_show_condition)
  90. {
  91. //检查各个节点连接状态
  92. Message.Error_manager error = Channel_communication.Instance.check_statu();
  93. if (error.ErrorCode == 0 && Singlechip_communication.Instance.check_entrance_statu())
  94. {
  95. Front_terminal_manager.Instance.get_tip_data_buffer().set_tip_str("系统正常!");
  96. this.Invoke(new Action(() =>
  97. {
  98. this.parkingBtn.BackgroundImage = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + "./Resource/" + "parkingBtn.BackgroundImage.png");
  99. //this.fetchingBtn.BackgroundImage = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + "./Resource/" + "fetchingBtn.BackgroundImage.png"); ;
  100. //this.fetchingBtn.Enabled = true;
  101. this.parkingBtn.Enabled = true;
  102. }));
  103. }
  104. else
  105. {
  106. this.Invoke(new Action(() =>
  107. {
  108. this.parkingBtn.BackgroundImage = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + "./Resource/" + "parkingBtn_gray.BackgroundImage.png");
  109. this.parkingBtn.Enabled = false;
  110. //this.fetchingBtn.BackgroundImage = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + "./Resource/" + "fetchingBtn_gray.BackgroundImage.png");
  111. //this.fetchingBtn.Enabled = false;
  112. }));
  113. if (error.ErrorCode == 0 && !Singlechip_communication.Instance.check_entrance_statu())
  114. {
  115. Front_terminal_manager.Instance.get_tip_data_buffer().set_tip_str("单片机未连接!");
  116. }
  117. else if (error.ErrorCode != 0 && Singlechip_communication.Instance.check_entrance_statu())
  118. {
  119. Front_terminal_manager.Instance.get_tip_data_buffer().set_tip_str(error.ErrorDescription);
  120. }
  121. else if (error.ErrorCode != 0 && !Singlechip_communication.Instance.check_entrance_statu())
  122. {
  123. Front_terminal_manager.Instance.get_tip_data_buffer().set_tip_str("单片机未连接!"+error.ErrorDescription);
  124. }
  125. }
  126. if (this.InvokeRequired)
  127. {
  128. this.Invoke(new Action(() =>
  129. {
  130. tip_label.Text = Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str();
  131. }));
  132. }
  133. else
  134. {
  135. tip_label.Text = Front_terminal_manager.Instance.get_tip_data_buffer().get_tip_str();
  136. }
  137. Thread.Sleep(100);
  138. }
  139. }
  140. private void parkingBtn_Click(object sender, EventArgs e)
  141. {
  142. //PrintManual.Instance.PrintTicket("鄂A3BO6X:lkjhgfds");
  143. //return;
  144. try
  145. {
  146. //检查各个节点连接状态
  147. Message.Error_manager error = Channel_communication.Instance.check_statu();
  148. if (error.ErrorCode == 0 && Singlechip_communication.Instance.check_entrance_statu())
  149. {
  150. //判断能否发送停车请求。
  151. Message.UnNormalized_module_statu_msg unNormalized_Module = Front_terminal_manager.Instance.get_unnormalized_module_data_bufferr().get_unnormalized_module_status_msg();
  152. Message.Singlechip_data t_singlechip_msg = Front_terminal_manager.Instance.get_singlechip_data_bufferr().get_entrance_singlechip_msg();
  153. Message.Ground_status_msg t_ground_status_msg = Front_terminal_manager.Instance.get_ground_radar_data_buffer().get_ground_status_msg();
  154. string check_results = check_status(unNormalized_Module, t_singlechip_msg, t_ground_status_msg);
  155. //单片机检测门内有车,门内车未超界,雷达扫描未超界,号牌机拍摄到的号牌不为空。满足以上需求才可停车
  156. if (check_results == "")
  157. {
  158. Message.Store_command_request_msg store_Command_Request_Msg = new Message.Store_command_request_msg();
  159. Message.Base_info t_base_info = new Message.Base_info();
  160. Message.Id_struct t_id_Struct = new Message.Id_struct();
  161. t_base_info.MsgType = Message.Message_type.EStoreCommandRequestMsg;
  162. t_base_info.Sender = Message.Communicator.ETerminor;
  163. t_base_info.Receiver = Message.Communicator.EMain;
  164. //地面雷达的 实时定位信息
  165. Message.Locate_information locateInformation = new Message.Locate_information();
  166. //获取雷达的测量数据 雷达不稳定有可能状态正常但是测量失败 所以测量500毫秒
  167. DateTime t_start_time = DateTime.Now;
  168. while (DateTime.Now.Ticks / 10000 - t_start_time.Ticks / 10000 < 500)
  169. {
  170. locateInformation = Front_terminal_manager.Instance.get_ground_radar_data_buffer().get_ground_status_msg().LocateInformationRealtime;
  171. if (locateInformation.LocateCorrect)
  172. {
  173. break;
  174. }
  175. }
  176. if (!locateInformation.LocateCorrect)
  177. {
  178. MessageBoxForm message = new MessageBoxForm();
  179. message.ShowDialog("雷达测量失败!");
  180. }
  181. else
  182. {
  183. /*用单片机的数据填充车辆信息*/
  184. Message.Car_info car_Info = new Message.Car_info();
  185. car_Info.CarNumberPlate = unNormalized_Module.CarLicense;
  186. //Encoding FromEcoding = Encoding.GetEncoding("UTF-8");
  187. //Encoding ToEcoding = Encoding.GetEncoding("GB2312");
  188. //byte[] FromBytes = FromEcoding.GetBytes(unNormalized_Module.CarLicense);
  189. //byte[] ToBytes = Encoding.Convert(FromEcoding, ToEcoding, FromBytes);
  190. //car_Info.CarNumberPlate = ToEcoding.GetString(ToBytes);
  191. //char[] vs = car_Info.CarNumberPlate.ToCharArray();
  192. car_Info.License = GetUniqueIdentifier(16);
  193. m_parking_license = unNormalized_Module.CarLicense;
  194. if (t_singlechip_msg.CarHeightStatusCurrent == Message.Car_height_status.Small)
  195. {
  196. car_Info.CarHeight = 1.5f;
  197. }
  198. else if (t_singlechip_msg.CarHeightStatusCurrent == Message.Car_height_status.Medium)
  199. {
  200. car_Info.CarHeight = 1.7f;
  201. }
  202. else if (t_singlechip_msg.CarHeightStatusCurrent == Message.Car_height_status.Large)
  203. {
  204. car_Info.CarHeight = 1.9f;
  205. }
  206. else
  207. {
  208. car_Info.CarHeight = 2.2f;
  209. }
  210. car_Info.CarWheelBase = locateInformation.LocateWheelBase;
  211. car_Info.CarWheelWidth = locateInformation.LocateWheelWidth;
  212. store_Command_Request_Msg.BaseInfo = t_base_info;
  213. t_id_Struct.TerminalId = m_ternimalID;
  214. store_Command_Request_Msg.IdStruct = t_id_Struct;
  215. store_Command_Request_Msg.LocateInformation = locateInformation;
  216. store_Command_Request_Msg.CarInfo = car_Info;
  217. //发送停车请求
  218. Channel_communication.Instance.encapsulate_msg(store_Command_Request_Msg.ToByteArray());
  219. t_start_time = DateTime.Now;
  220. while ((DateTime.Now.Ticks / 10000 - t_start_time.Ticks / 10000) < 3000)
  221. {
  222. if (m_store_command_response_msg != null)
  223. {
  224. Log.Instance.WriteLog(LogType.PROCESS, LogFile.LOG, "@@@ 接收到停车请求反馈:" + m_store_command_response_msg.ToString());
  225. if(m_store_command_response_msg.Code == null)
  226. {
  227. Log.Instance.WriteLog(LogType.PROCESS, LogFile.LOG, "@@@ 接收到停车请求反馈 code null" );
  228. }
  229. else
  230. {
  231. Log.Instance.WriteLog(LogType.PROCESS, LogFile.LOG, "@@@ 接收到停车请求反馈 code: "+ m_store_command_response_msg.ToString());
  232. }
  233. //查看反馈结果
  234. if (m_store_command_response_msg.Code?.ErrorCode == 0)
  235. {
  236. //通知打印机打印
  237. PrintManual.Instance.PrintTicket(car_Info.License, car_Info.CarNumberPlate);
  238. //通知单片机关门
  239. Message.terminal_msg terminal_Msg = new Message.terminal_msg();
  240. terminal_Msg.TerminalID = m_ternimalID;
  241. terminal_Msg.DispatchDirection = 1;
  242. terminal_Msg.ProcessControl = Message.Process_control.AutoClose;
  243. terminal_Msg.OutPutDo = new Message.OutputDo();
  244. //给单片机发送关门
  245. Singlechip_communication.Instance.encapsulate_msg(Singlechip_communication.Instance.m_stop_singlechip_index, Newtonsoft.Json.JsonConvert.SerializeObject(terminal_Msg));
  246. MessageBoxForm messageBoxForm = new MessageBoxForm();
  247. messageBoxForm.ShowDialog(m_parking_license + " 停车成功,请取走小票!");
  248. Log.Instance.WriteLog(LogType.PROCESS, LogFile.LOG, "@@@ 停车请求反馈正常!" + m_store_command_response_msg.ToString() + "$$$" + m_store_command_response_msg.Code?.ErrorCode.ToString());
  249. }
  250. else
  251. {
  252. MessageBoxForm messageBoxForm = new MessageBoxForm();
  253. messageBoxForm.ShowDialog(" 停车请求反馈失败!" + m_store_command_response_msg.Code.ErrorDescription.ToString()+"号牌:"+ car_Info.CarNumberPlate + "车高等级:" + t_singlechip_msg.CarHeightStatusCurrent);
  254. Log.Instance.WriteLog(LogType.PROCESS, LogFile.LOG, " 停车请求反馈失败!" + m_store_command_response_msg.ToString() + "$$$" + m_store_command_response_msg.Code?.ErrorCode.ToString());
  255. }
  256. break;
  257. }
  258. }
  259. if (m_store_command_response_msg == null)
  260. {
  261. MessageBoxForm messageBoxForm = new MessageBoxForm();
  262. messageBoxForm.ShowDialog(m_parking_license + " 停车反馈超时!");
  263. m_parking_license = "";
  264. Log.Instance.WriteLog(LogType.PROCESS, LogFile.LOG, store_Command_Request_Msg.ToString() + " 停车反馈超时!发送时间:" + t_start_time.ToString() + " 当前时间:" + DateTime.Now.ToString());
  265. }
  266. m_parking_license = "";
  267. m_store_command_response_msg = null;
  268. }
  269. }
  270. else
  271. {
  272. MessageBoxForm message = new MessageBoxForm();
  273. message.ShowDialog(check_results);
  274. }
  275. }
  276. else
  277. {
  278. if (error.ErrorCode == 0 && !Singlechip_communication.Instance.check_entrance_statu())
  279. {
  280. MessageBoxForm message = new MessageBoxForm();
  281. message.ShowDialog("单片机未连接!");
  282. }
  283. else if (error.ErrorCode != 0 && Singlechip_communication.Instance.check_entrance_statu())
  284. {
  285. MessageBoxForm message = new MessageBoxForm();
  286. message.ShowDialog(error.ErrorDescription);
  287. }
  288. else if (error.ErrorCode != 0 && !Singlechip_communication.Instance.check_entrance_statu())
  289. {
  290. MessageBoxForm message = new MessageBoxForm();
  291. message.ShowDialog(error.ErrorDescription + "单片机未连接!");
  292. }
  293. }
  294. }
  295. catch(Exception ex)
  296. {
  297. MessageBox.Show(ex.StackTrace);
  298. }
  299. }
  300. private void fetchingBtn_Click(object sender, EventArgs e)
  301. {
  302. ///停车终端
  303. //try
  304. //{
  305. // //检查各个节点连接状态
  306. // Message.Error_manager error = Channel_communication.Instance.check_statu();
  307. // if (error.ErrorCode == 0)
  308. // {
  309. // //此窗口只获取车牌号
  310. // FetchingForm fetchingForm = new FetchingForm();
  311. // fetchingForm.StartPosition = FormStartPosition.CenterScreen;
  312. // fetchingForm.BringToFront();
  313. // fetchingForm.ShowDialog();
  314. // if (fetchingForm.m_is_return)
  315. // {
  316. // return;
  317. // }
  318. // m_pickup_license = fetchingForm.m_license;
  319. // string tip_pickup_license = "";
  320. // if (m_pickup_license.Length == 16 || m_pickup_license.Length == 17)
  321. // {
  322. // tip_pickup_license = m_pickup_license.Substring(0, m_pickup_license.Length - 9);
  323. // }
  324. // else
  325. // {
  326. // tip_pickup_license = m_pickup_license;
  327. // }
  328. // //检查车牌号是否合法
  329. // if (tip_pickup_license.Length == 7 || tip_pickup_license.Length == 8)
  330. // {
  331. // //查询请求
  332. // Message.Parkspace_search_request_msg t_msg = new Message.Parkspace_search_request_msg();
  333. // //消息头
  334. // Message.Base_info baseInfo = new Message.Base_info();
  335. // baseInfo.MsgType = Message.Message_type.EParkspaceSearchRequestMsg;
  336. // baseInfo.Sender = Message.Communicator.ETerminor;
  337. // baseInfo.Receiver = Message.Communicator.EParkspace;
  338. // baseInfo.TimeoutMs = 1000;
  339. // //车辆信息--只需填充车牌号
  340. // Message.Car_info car_Info = new Message.Car_info();
  341. // car_Info.License = m_pickup_license;
  342. // //填充信息
  343. // t_msg.BaseInfo = baseInfo;
  344. // t_msg.CommandKey = GetUniqueIdentifier(8);
  345. // t_msg.CarInfo = car_Info;
  346. // //发送查询车辆请求
  347. // Channel_communication.Instance.encapsulate_msg(t_msg.ToByteArray());
  348. // DateTime t_start_time = DateTime.Now;
  349. // while ((DateTime.Now.Ticks / 10000 - t_start_time.Ticks / 10000) < 500)
  350. // {
  351. // if (m_search_response_msg != null)
  352. // {
  353. // break;
  354. // }
  355. // }
  356. // if (m_search_response_msg != null)
  357. // {
  358. // //查看反馈结果
  359. // if (m_search_response_msg.ErrorManager.ErrorCode == 0)
  360. // {
  361. // //取车请求
  362. // Message.Pickup_command_request_msg t_pickup_command_request_msg = new Message.Pickup_command_request_msg();
  363. // //消息头
  364. // Message.Base_info t_baseInfo = new Message.Base_info();
  365. // baseInfo.MsgType = Message.Message_type.EPickupCommandRequestMsg;
  366. // baseInfo.Sender = Message.Communicator.ETerminor;
  367. // baseInfo.Receiver = Message.Communicator.EMain;
  368. // //车辆信息--只需填充车牌号
  369. // Message.Car_info t_car_Info = new Message.Car_info();
  370. // car_Info.License = m_pickup_license;
  371. // car_Info.CarNumberPlate = tip_pickup_license;
  372. // Message.Id_struct t_id_Struct = new Message.Id_struct();
  373. // //填充信息
  374. // t_pickup_command_request_msg.BaseInfo = baseInfo;
  375. // t_id_Struct.UnitId = m_search_response_msg.QueryParkspaceInfoEx[0].ParkingspaceUnitId; ;
  376. // t_pickup_command_request_msg.IdStruct = t_id_Struct;
  377. // t_pickup_command_request_msg.CarInfo = car_Info;
  378. // //发送取车请求
  379. // Channel_communication.Instance.encapsulate_msg(t_pickup_command_request_msg.ToByteArray());
  380. // //记录发送时间
  381. // t_start_time = DateTime.Now;
  382. // while ((DateTime.Now.Ticks / 10000 - t_start_time.Ticks / 10000) < 500)
  383. // {
  384. // if (m_pickup_command_response_msg != null)
  385. // {
  386. // break;
  387. // }
  388. // }
  389. // if (m_pickup_command_response_msg != null)
  390. // {
  391. // if (m_pickup_command_response_msg.Code.ErrorCode == 0)
  392. // {
  393. // MessageBoxForm messageBoxForm = new MessageBoxForm();
  394. // messageBoxForm.ShowDialog(tip_pickup_license + "取车成功!请观察LED屏幕提示取车!");
  395. // }
  396. // else
  397. // {
  398. // MessageBoxForm messageBoxForm = new MessageBoxForm();
  399. // messageBoxForm.ShowDialog(tip_pickup_license + "取车反馈失败!" + m_pickup_command_response_msg.Code.ErrorDescription);
  400. // }
  401. // t_pickup_command_request_msg = null;
  402. // }
  403. // else
  404. // {
  405. // MessageBoxForm messageBoxForm = new MessageBoxForm();
  406. // messageBoxForm.ShowDialog(tip_pickup_license + "取车反馈超时!");
  407. // }
  408. // m_search_response_msg = null;
  409. // }
  410. // else
  411. // {
  412. // MessageBoxForm messageBoxForm = new MessageBoxForm();
  413. // messageBoxForm.ShowDialog(tip_pickup_license + "车位查询反馈错误!"+ m_search_response_msg.ErrorManager.ErrorDescription);
  414. // m_search_response_msg = null;
  415. // }
  416. // }
  417. // else
  418. // {
  419. // MessageBoxForm messageBoxForm = new MessageBoxForm();
  420. // messageBoxForm.ShowDialog(tip_pickup_license + "车位查询反馈超时!");
  421. // }
  422. // }
  423. // else
  424. // {
  425. // MessageBoxForm messageBoxForm = new MessageBoxForm();
  426. // messageBoxForm.ShowDialog(tip_pickup_license + "非正常车牌号!");
  427. // }
  428. // }
  429. // else
  430. // {
  431. // MessageBoxForm message = new MessageBoxForm();
  432. // message.ShowDialog(error.ErrorDescription);
  433. // }
  434. //}
  435. //catch(Exception ex)
  436. //{
  437. // MessageBox.Show(ex.StackTrace);
  438. //}
  439. }
  440. private void action_window_Load(object sender, EventArgs e)
  441. {
  442. this.terminal_number_label.Text = "智象泊车终端" + (int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber")) + 1).ToString() + "号机";
  443. this.terminal_number_english_label.Text = this.terminal_number_english_label.Text + (int.Parse(json_file_operation.Instance.read_json_string("ternimalNumber")) + 1);
  444. //this.fetchingBtn.BackgroundImage = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + "./Resource/" + "fetchingBtn_gray.BackgroundImage.png");
  445. //this.fetchingBtn.Enabled = false;
  446. if (MessageBox.Show("是否最大化?", "tip", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
  447. {
  448. //设置最大化
  449. this.WindowState = FormWindowState.Maximized;
  450. }
  451. //启动播放器
  452. m_mediaPlayer.mediaplayer_run();
  453. //显示提示
  454. m_tip_show_condition = true;
  455. m_tip_show_thread.Start();
  456. //启动打印机
  457. PrintManual.Instance.Start();
  458. m_auto_resize_form.controllInitializeSize(this);
  459. //启动子程序
  460. Process[] myprocess = Process.GetProcessesByName("UnNomalized_node");
  461. if (myprocess.Count() == 0 )
  462. {
  463. try
  464. {
  465. m_process = new Process();//创建一个新的进程
  466. ProcessStartInfo startInfo = new ProcessStartInfo();//启动进程时使用的集合
  467. startInfo.FileName = @".\UnNomalized_node\UnNomalized_node.exe"; ;//要启动的应用程序
  468. startInfo.WindowStyle = ProcessWindowStyle.Normal;//启动应用程序时使用的窗口状态
  469. m_process.StartInfo = startInfo;//把启动进程的信息赋值给新建的进程
  470. m_process.StartInfo.UseShellExecute = true;//是否使用操作系统shell执行该程序
  471. m_process.Start();
  472. }
  473. catch (Exception)
  474. {
  475. }
  476. }
  477. }
  478. private void action_window_FormClosing(object sender, FormClosingEventArgs e)
  479. {
  480. //关闭播放器
  481. m_mediaPlayer.mediaplayer_uninit();
  482. //关闭单片机通信
  483. Singlechip_communication.Instance.singlechip_communication_uninit();
  484. //关闭出入口通信
  485. Channel_communication.Instance.channel_communication_uninit();
  486. //关闭显示提示
  487. m_tip_show_condition = false;
  488. m_tip_show_thread.Abort();
  489. //关闭数据管理的线程
  490. Front_terminal_manager.Instance.front_terminal_manager_uninit();
  491. //关闭打印机
  492. PrintManual.Instance.Close();
  493. //关闭子程序
  494. if (m_process != null && !m_process.HasExited)
  495. {
  496. m_process.Kill();
  497. }
  498. }
  499. private void axWindowsMediaPlayer1_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e)
  500. {
  501. if (this.axWindowsMediaPlayer.fullScreen == true)
  502. {
  503. this.axWindowsMediaPlayer.fullScreen = false;
  504. }
  505. }
  506. private void action_window_SizeChanged(object sender, EventArgs e)
  507. {
  508. m_auto_resize_form.controlAutoSize(this);
  509. }
  510. //设置存车的反馈--由上层调用
  511. public void set_store_response_msg(Message.Store_command_response_msg t_store_command_response_msg)
  512. {
  513. m_store_command_response_msg = new Message.Store_command_response_msg();
  514. m_store_command_response_msg = t_store_command_response_msg;
  515. }
  516. //设置查询的反馈--由上层调用
  517. public void set_search_response_msg(Message.Parkspace_search_response_msg t_search_response_msg)
  518. {
  519. //反馈是否与自己查询的车辆
  520. if (t_search_response_msg.QueryParkspaceInfoEx[0].CarInfo.License == m_pickup_license)
  521. {
  522. m_search_response_msg = new Message.Parkspace_search_response_msg();
  523. m_search_response_msg = t_search_response_msg;
  524. }
  525. }
  526. //设置取车的反馈--由上层调用
  527. public void set_pickup_response_msg(Message.Pickup_command_response_msg t_pickup_command_response_msg)
  528. {
  529. m_pickup_command_response_msg = new Message.Pickup_command_response_msg();
  530. m_pickup_command_response_msg = t_pickup_command_response_msg;
  531. }
  532. //生成指定长度唯一码
  533. public static string GetUniqueIdentifier(int length)
  534. {
  535. int maxSize = length;
  536. char[] chars = new char[62];
  537. string a;
  538. a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  539. chars = a.ToCharArray();
  540. int size = maxSize;
  541. byte[] data = new byte[1];
  542. var crypto = new RNGCryptoServiceProvider();
  543. crypto.GetNonZeroBytes(data);
  544. size = maxSize;
  545. data = new byte[size];
  546. crypto.GetNonZeroBytes(data);
  547. var result = new StringBuilder(size);
  548. foreach (byte b in data)
  549. {
  550. result.Append(chars[b % (chars.Length - 1)]);
  551. }
  552. if (result[0] >= '0' && result[0] <= '9')
  553. {
  554. return GetUniqueIdentifier(length);
  555. }
  556. return result.ToString();
  557. }
  558. //设置天气
  559. public void set_weatherLab_text(string str)
  560. {
  561. this.weather_label.Text = str;
  562. }
  563. //设置气温
  564. public void set_temperatureLab_text(string str)
  565. {
  566. this.temperature_label.Text = str;
  567. }
  568. public static void Speaking(string saying)
  569. {
  570. string say = saying;
  571. Task task = new Task(() =>
  572. {
  573. SpeechSynthesizer speech = new SpeechSynthesizer();
  574. speech.Volume = 100; //音量
  575. speech.Rate = -1;
  576. CultureInfo keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
  577. InstalledVoice neededVoice = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault();
  578. if (neededVoice == null)
  579. {
  580. say = "未知的操作";
  581. }
  582. else
  583. {
  584. speech.SelectVoice(neededVoice.VoiceInfo.Name);
  585. }
  586. speech.Speak(say);
  587. });
  588. task.Start();
  589. }
  590. //检查各模块状态 看能否发送消息
  591. public string check_status(Message.UnNormalized_module_statu_msg unNormalized_Module,Message.Singlechip_data t_singlechip_msg,Message.Ground_status_msg t_ground_status_msg)
  592. {
  593. int border_statu = t_ground_status_msg.BorderStatus;
  594. string results = "";
  595. //检车门内光电
  596. if (t_singlechip_msg.InsideExistenceFlag != 1)
  597. {
  598. results = "无车!";
  599. return results;
  600. }
  601. //检测号牌
  602. if (unNormalized_Module.CarLicense == "" )
  603. {
  604. results = "号牌机未拍摄到号牌,请尝试重新进入!";
  605. return results;
  606. }
  607. //检测光电超界信息
  608. switch (t_singlechip_msg.OverBorderStatus)
  609. {
  610. case Message.Over_border_status.Normal:
  611. {
  612. } break;
  613. case Message.Over_border_status.Front:
  614. {
  615. results = results + "前超界!";
  616. }
  617. break;
  618. case Message.Over_border_status.Left:
  619. {
  620. results = results + "左超界!";
  621. }
  622. break;
  623. case Message.Over_border_status.Right:
  624. {
  625. results = results + "右超界!";
  626. }
  627. break;
  628. case Message.Over_border_status.Back:
  629. {
  630. results = results + "后超界!";
  631. }
  632. break;
  633. default:
  634. {
  635. results = results + "单片机超界信息错误!";
  636. }
  637. break;
  638. }
  639. //检测雷达状态
  640. if (t_ground_status_msg.ErrorManager.ErrorCode != 0)
  641. {
  642. results = results + t_ground_status_msg.ErrorManager.ErrorDescription;
  643. }
  644. //检测非标状态
  645. if (unNormalized_Module.StatuCode.ErrorCode != 0)
  646. {
  647. results = results + unNormalized_Module.StatuCode.ErrorDescription;
  648. }
  649. //检测雷达超界信息
  650. if (((border_statu >> 0) & 0x01) > 0)
  651. {
  652. results = results + "前超界!";
  653. }
  654. if (((border_statu >> 1) & 0x01) > 0)
  655. {
  656. results = results + "后超界!";
  657. }
  658. if (((border_statu >> 2) & 0x01) > 0)
  659. {
  660. results = results + "左超界!";
  661. }
  662. if (((border_statu >> 3) & 0x01) > 0)
  663. {
  664. results = results + "右超界!";
  665. }
  666. if (((border_statu >> 6) & 0x01) > 0)
  667. {
  668. results = results + "车辆超宽!";
  669. }
  670. if (((border_statu >> 7) & 0x01) > 0)
  671. {
  672. results = results + "轴距超差!";
  673. }
  674. if (((border_statu >> 8) & 0x01) > 0 || ((border_statu >> 9) & 0x01) > 0)
  675. {
  676. results = results + "车辆倾斜严重!";
  677. }
  678. if (((border_statu >> 10) & 0x01) > 0)
  679. {
  680. results = results + "方向盘未回正!";
  681. }
  682. return results;
  683. }
  684. }
  685. }