// receive thread private void ReceiveData(UdpClient client) { while (true) { try { // Bytes empfangen. IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0); byte[] received = client.Receive(ref anyIP); //print(anyIP.Address); // Bytes mit der UTF8-Kodierung in das Textformat kodieren. string text = Encoding.UTF8.GetString(received); if (text.Contains("Art-Net")) { // Den abgerufenen Text anzeigen. print(">> " + text); int dmx = 18; StringBuilder[] sb = new StringBuilder[21]; String[] str = new String[21]; for (int i = 0; i < 21; i++) { sb[i] = new StringBuilder(); sb[i].Append("#"); sb[i].Append(received[dmx++].ToString("X2")); sb[i].Append(received[dmx++].ToString("X2")); sb[i].Append(received[dmx++].ToString("X2")); str[i] = sb[i].ToString(); } //Output the colors received color values to the Car's LEDs LEDControl led = GameObject.Find("LEDs").GetComponent <LEDControl>(); led.ChangeColor(str); //writeSocket("test2"); } } catch (Exception err) { print(err.ToString()); } } }
/// <summary> /// 选择应用层下发的任务 /// </summary> /// <param name="receivedBuffer">接收缓冲区数据</param> /// <param name="remotePoint">客户端端点</param> public void SwitchEvent(EndPoint remotePoint, byte[] receivedBuffer) { try { //GPSCode string gpsCode = string.Empty; //读取命令 CmdData cmdData = new CmdData(); //读入数据 cmdData.ReadBuffer(0, receivedBuffer); Logger.Trace("收到应用层下发指令,指令类型:" + cmdData.Data.Cmd.ToString()); byte[] sendBuffer = null; switch (cmdData.Data.Cmd) { //调度命令 case ControlCmdType.DispatchControl: DispatchControl DispatchControl = new DispatchControl(); //读入数据 DispatchControl.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + DispatchControl.GPSCode); //将连接加入连接哈希表 GpsDataParser.OnPostAppLayerAddressEvent(DispatchControl.GPSCode, remotePoint); //下发调度命令 HandleDispatchControlInfo(DispatchControl); break; //监听喊话 case ControlCmdType.ListenCall: ListenCallControl CallControl = new ListenCallControl(); //读入数据 CallControl.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + CallControl.GPSCode); //将连接加入连接哈希表 GpsDataParser.OnPostAppLayerAddressEvent(CallControl.GPSCode, remotePoint); //下发调度命令 HandleListenCallInfo(CallControl); break; //简单控制命令 //case ControlCmdType.SimpleInstruction: //下发广告或LED其它命令 case ControlCmdType.LEDControl: SimpleInstructionControl SimpleControl = new SimpleInstructionControl(); SimpleControl.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + SimpleControl.GPSCode); //将连接加入连接哈希表 GpsDataParser.OnPostAppLayerAddressEvent(SimpleControl.GPSCode, remotePoint); HandleSimpleInstructionControl(SimpleControl); break; //下发拍照的动作 case ControlCmdType.SendTakePicture: TakePictureControl takePicture = new TakePictureControl(); takePicture.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + takePicture.GPSCode); //将连接加入哈希表 GpsDataParser.OnPostAppLayerAddressEvent(takePicture.GPSCode, remotePoint); HandleShootInstructionControl(takePicture); break; //下发拍照的动作(多摄像头) case ControlCmdType.SendTakePictureMultiCamera: TakePictureControlMultiCamera takePictureMultiCamera = new TakePictureControlMultiCamera(); takePictureMultiCamera.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + takePictureMultiCamera.GPSCode); //将连接加入哈希表 GpsDataParser.OnPostAppLayerAddressEvent(takePictureMultiCamera.GPSCode, remotePoint); HandleShootInstructionControl(takePictureMultiCamera); break; case ControlCmdType.SupplyOilCircuit: //强制断油断电 case ControlCmdType.BreakOilCircuitByForce: //智能断油断电 case ControlCmdType.BreakOilCircuitBySmart: ControlOilCircuit ControlOil = new ControlOilCircuit(); ControlOil.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + ControlOil.GPSCode); //将连接加入连接哈希表 GpsDataParser.OnPostAppLayerAddressEvent(ControlOil.GPSCode, remotePoint); //油路通断控制 HandleBreakOilCircuit(ControlOil); break; //北京视展LED控制 case ControlCmdType.BJSZLedControl: case ControlCmdType.SendAdvertisement: LEDControl ledControl = new LEDControl(); ledControl.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + ledControl.GPSCode); //将连接加入连接哈希表 GpsDataParser.OnPostAppLayerAddressEvent(ledControl.GPSCode, remotePoint); HandleBJSZLEDContentInfo(ledControl); break; //解除报警 case ControlCmdType.DischargeAlarm: DischangeAlarmControl dischangeAlarm = new DischangeAlarmControl(); dischangeAlarm.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + dischangeAlarm.GPSCode); //将连接加入连接哈希表 GpsDataParser.OnPostAppLayerAddressEvent(dischangeAlarm.GPSCode, remotePoint); DischargeAlarm(dischangeAlarm); break; //超速报警 case ControlCmdType.OverSpeedAlarm: OverSpeedAlarmControl overSpeedAlarm = new OverSpeedAlarmControl(); overSpeedAlarm.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + overSpeedAlarm.GPSCode); GpsDataParser.OnPostAppLayerAddressEvent(overSpeedAlarm.GPSCode, remotePoint); HandleOverSpeed(overSpeedAlarm); break; //获取网关活动信息 case ControlCmdType.GetGatewayActiveInfo: GatewayActiveInfo activeInfo = new GatewayActiveInfo(); activeInfo.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + activeInfo.GPSCode); GpsDataParser.OnPostAppLayerAddressEvent(activeInfo.GPSCode, remotePoint); SendGatewayActiveInfo(activeInfo, remotePoint); break; //更新GPS总里程值 case ControlCmdType.updatemileage: UpdateMileage UpMileage = new UpdateMileage(); UpMileage.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + UpMileage.GPSCode); GpsDataParser.OnPostAppLayerAddressEvent(UpMileage.GPSCode, remotePoint); SendUpdateMileage(UpMileage); break; //设置GPS上传周期 case ControlCmdType.SendGPSPosUploadInterval: GPSPosUploadInterval posUploadInterval = new GPSPosUploadInterval(); posUploadInterval.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + posUploadInterval.GPSCode); GpsDataParser.OnPostAppLayerAddressEvent(posUploadInterval.GPSCode, remotePoint); HandleGPSPosUploadInterval(posUploadInterval); break; //设置移动台初始经参数 case ControlCmdType.SetMobileInitPara: SetMobileInitPara setMobileInitPara = new SetMobileInitPara(); setMobileInitPara.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + setMobileInitPara.GPSCode); SetMobileInitPara(setMobileInitPara); break; //雅迅设备,配置报警器 case ControlCmdType.AllocateAnnounciator: SetAnnounciator setAnnounciator = new SetAnnounciator(); setAnnounciator.ReadBuffer(0, cmdData.DataBuffer); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + setAnnounciator.GPSCode); gpsCode = setAnnounciator.GPSCode; sendBuffer = GpsDataParser.ParseControlInstruction(ControlCmdType.AllocateAnnounciator, setAnnounciator); break; case ControlCmdType.SetCircleRegion: case ControlCmdType.SetRectangleRegion: case ControlCmdType.SetPloygon: case ControlCmdType.SetFixedLine: case ControlCmdType.RemoveCircleRegion: case ControlCmdType.RemoveRectangleRegion: case ControlCmdType.RemovePloygon: case ControlCmdType.RemoveFixedLine: case ControlCmdType.TMLControl: case ControlCmdType.SendTxtToTML: case ControlCmdType.PhoneCallback: case ControlCmdType.CameraShootImmediately: case ControlCmdType.PositionQueryReq: case ControlCmdType.SetStopCarAlarm: case ControlCmdType.SetOverFatigueAlarm: case ControlCmdType.SetOverSpeedAlarm: case ControlCmdType.GetRravelRecord: BuBiaoCommonControl BBControl = new BuBiaoCommonControl(); BBControl.ReadBuffer(0, cmdData.DataBuffer); GpsDataParser.OnPostAppLayerAddressEvent(BBControl.GPSCode, remotePoint); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + BBControl.GPSCode); HandleBuBiaoMessage(BBControl, cmdData.Data.Cmd); break; //部标解除报警 case ControlCmdType.ReleaseAlarm: BuBiaoCommonControl ReleaseControl = new BuBiaoCommonControl(); ReleaseControl.ReadBuffer(0, cmdData.DataBuffer); GpsDataParser.ReleaseAlarm(ReleaseControl); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + ReleaseControl.GPSCode); break; case ControlCmdType.OpenGPS: KKSSimpleControl openGPSControl = new KKSSimpleControl(); openGPSControl.ReadBuffer(0, cmdData.DataBuffer); GpsDataParser.OnPostAppLayerAddressEvent(openGPSControl.GPSCode, remotePoint); HandleKKSSimpleControlInfo(ControlCmdType.OpenGPS, openGPSControl); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + openGPSControl.GPSCode); break; case ControlCmdType.SetFriendNumber: KKSSimpleControl setfriendnumberControl = new KKSSimpleControl(); setfriendnumberControl.ReadBuffer(0, cmdData.DataBuffer); GpsDataParser.OnPostAppLayerAddressEvent(setfriendnumberControl.GPSCode, remotePoint); HandleKKSSimpleControlInfo(ControlCmdType.SetFriendNumber,setfriendnumberControl); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + setfriendnumberControl.GPSCode); break; case ControlCmdType.GetFriendNumber: KKSSimpleControl getfriendnumberControl = new KKSSimpleControl(); getfriendnumberControl.ReadBuffer(0, cmdData.DataBuffer); GpsDataParser.OnPostAppLayerAddressEvent(getfriendnumberControl.GPSCode, remotePoint); HandleKKSSimpleControlInfo(ControlCmdType.GetFriendNumber,getfriendnumberControl); Logger.Trace("应用层下发指令类型:" + cmdData.Data.Cmd.ToString() + ";GPSCode:" + getfriendnumberControl.GPSCode); break; default: break; } //GpsDataParser.OnPostSendHandlerEvent(gpsCode, string.Empty, sendBuffer); } catch (Exception ex) { Logger.Error(ex, null); } }
/// <summary> /// 获取北京视展LED的信息命令,并发送后删除LED信息 /// 应在gps_screen表和gps_screendemension表加入gps_code对应的一条记录,如: /// insert into gps_screen values ('00092040200103',1) /// insert into gps_screendemension(gpscode) VALUES('00092040200103') /// 其中00092040200103为gpd code /// </summary> /// <returns></returns> public void HandleBJSZLEDContentInfo(LEDControl ledControl) { List<byte[]> lstData; LEDBJSZContentInfoEntity ledBJSZInfoEntity = new LEDBJSZContentInfoEntity(); ledBJSZInfoEntity.GPSCode = ledControl.GPSCode; string gpsCode = ledControl.GPSCode; try { //取得已建立的套接字 //获取屏的参数设置,从MemCache缓存读取 //获取led屏的参数,//分辨率:默认为128*16,设定后为160*132 ledBJSZInfoEntity.LEDDisplayType = ledControl.Data.LEDDisplayType; ledBJSZInfoEntity.ColorType = ledControl.Data.LedColorType; ledBJSZInfoEntity.Width = ledControl.Data.Width; ledBJSZInfoEntity.Height = ledControl.Data.Height; ledBJSZInfoEntity.SendContent = ledControl.SendContent; ledBJSZInfoEntity.LEDSpeed = ledControl.Data.LEDSpeed; ledBJSZInfoEntity.LEDTimeLen = ledControl.Data.LEDTimeLen; lstData = GpsDataParser.ParseControlInstructionRetMultipleData(ControlCmdType.LEDControl, ledBJSZInfoEntity); if (lstData == null || lstData.Count <= 0) { return; } IEnumerator<byte[]> data = lstData.GetEnumerator(); int sendResult = 0; bool bSendSuccess = true; while (data.MoveNext()) { byte[] instruction = data.Current; try { Socket socket = TCPConnList.Instance().GetTCPConnection(gpsCode); if (socket != null && socket.Connected) { sendResult = socket.Send(instruction); if (sendResult <= 0) bSendSuccess = false; //add log for trace #2586 Logger.Trace("GPSYouWei:GPSCode=" + gpsCode + "-" + ledControl.SerialNumber + "-" + sendResult.ToString(), null); } else { //从列表移除此连接 //TCPConnList.Instance().RemoveTCPConnection(gpsCode); } } catch (SocketException ex) { //从列表移除此连接 //TCPConnList.Instance().RemoveTCPConnection(gpsCode); Logger.Trace("发送BJSZ LED命令异常:" + ex.ToString(), null); } finally { instruction = null; } }//end while OnSendAnswerToWebEvent(ledControl.SerialNumber, false, gpsCode, ControlCmdType.SendAdvertisement, bSendSuccess); Logger.Trace("GPSYouWei:GPSCode=" + gpsCode + "-" + ledControl.SerialNumber + "--" + bSendSuccess.ToString(), null); } catch (Exception ex) { Logger.Error(ex, null); } }
/// <summary> 发送应答信息给应用 /// 发送应答信息给应用 /// </summary> /// <param name="serialNumber">流水号</param> /// <param name="isGpsAckMsg">是否是GPS应答消息</param> /// <param name="gpscode"></param> /// <param name="cmdType">下发的命令类型</param> /// <param name="result">GPS终端对命令的执行结果:成功或失败</param> //private void SendAnswerToWeb(string serialNumber, bool isGpsAckMsg, string gpscode, ControlCmdType cmdType, bool result, params SimpleCmdType[] simplecmd) //{ // //获取WEB列表 // EndPoint adress = (EndPoint)WebTable[gpscode]; // if (adress != null) // { // byte[] answerBytes = SetAnswerByte(serialNumber, isGpsAckMsg, gpscode, cmdType, result, simplecmd); // CmdServer.SendTo((IPEndPoint)adress, answerBytes); // } //} /// <summary> 构造应答数据 /// 构造应答数据 /// </summary> /// <param name="serialNumber">流水号</param> /// <param name="isGpsAckMsg">是否是GPS应答信息</param> /// <param name="gpsCode">GPSG带前缀编码</param> /// <param name="cmd">下发的命令类型</param> /// <param name="result">GPS终端对命令的执行结果:成功或失败</param> /// <param name="simpleCmd">简单控制命令类型</param> /// <returns></returns> private byte[] SetAnswerByte(string serialNumber,bool isGpsAckMsg, string gpsCode, ControlCmdType cmd, bool result, params SimpleCmdType[] simpleCmd) { try { byte[] sendBuffer = null; byte[] dataBuffer = null; CmdData cmddata = new CmdData(); cmddata.Data.Cmd = cmd; byte gpsCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; byte serialLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; switch (cmd) { case ControlCmdType.DeviceCircuitresAndOil://控制油路应答 ControlOilCircuit structOil = new ControlOilCircuit(); structOil.Data.IsGpsAckMsg = isGpsAckMsg; structOil.GPSCode = gpsCode; structOil.Data.Result = result; structOil.Data.GPSCodeLen = gpsCodeLen; structOil.SerialNumber = serialNumber; structOil.Data.SerialNumberLen = serialLen; byte[] bytsOil = new byte[structOil.GetLength()]; structOil.WriteBuffer(0, bytsOil); cmddata.DataBuffer = bytsOil; cmddata.Data.DataLen = (ushort)bytsOil.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //解除报警应答 case ControlCmdType.DischargeAlarm: DischangeAlarmControl structAlarm = new DischangeAlarmControl(); structAlarm.GPSCode = gpsCode; structAlarm.Data.Result = result; structAlarm.Data.GPSCodeLen = gpsCodeLen; structAlarm.SerialNumber = serialNumber; structAlarm.Data.SerialNumberLen = serialLen; byte[] bytsAlarm = new byte[structAlarm.GetLength()]; structAlarm.WriteBuffer(0, bytsAlarm); cmddata.DataBuffer = bytsAlarm; cmddata.Data.DataLen = (ushort)bytsAlarm.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //调度控制(下发文本) case ControlCmdType.DispatchControl: DispatchControl structDispatch = new DispatchControl(); structDispatch.Data.IsGpsAckMsg = isGpsAckMsg; structDispatch.GPSCode = gpsCode; structDispatch.Data.Result = result; structDispatch.Data.GPSCodeLen = gpsCodeLen; structDispatch.SerialNumber = serialNumber; byte[] bytsDispatch = new byte[structDispatch.GetLength()]; structDispatch.WriteBuffer(0, bytsDispatch); cmddata.DataBuffer = bytsDispatch; cmddata.Data.DataLen = (ushort)bytsDispatch.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //监听喊话 case ControlCmdType.ListenCall: ListenCallControl structListenCall = new ListenCallControl(); structListenCall.Data.IsGpsAckMsg = isGpsAckMsg; structListenCall.GPSCode = gpsCode; structListenCall.Data.GPSCodeLen = gpsCodeLen; structListenCall.Data.Result = result; structListenCall.Data.SerialNumberLen = serialLen; structListenCall.SerialNumber = serialNumber; byte[] bytsListenCall = new byte[structListenCall.GetLength()]; structListenCall.WriteBuffer(0, bytsListenCall); cmddata.DataBuffer = bytsListenCall; cmddata.Data.DataLen = (ushort)bytsListenCall.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.BJSZLedControl://透传数据应答(BJSZ LED) BJSZLEDContentControl structBJSZLED = new BJSZLEDContentControl(); structBJSZLED.Data.IsGpsAckMsg = isGpsAckMsg; structBJSZLED.GPSCode = gpsCode; structBJSZLED.Data.Result = result; structBJSZLED.Data.SerialNumberLen = serialLen; structBJSZLED.SerialNumber = serialNumber; structBJSZLED.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; byte[] bytsBJSZLED = new byte[structBJSZLED.GetLength()]; structBJSZLED.WriteBuffer(0, bytsBJSZLED); cmddata.DataBuffer = bytsBJSZLED; cmddata.Data.DataLen = (ushort)bytsBJSZLED.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.LongHanAnswered://龙汗数据应答 break; case ControlCmdType.SimpleInstruction://简单控制命令 SimpleInstructionControl structSimple = new SimpleInstructionControl(); structSimple.Data.InstructionType = simpleCmd[0]; structSimple.Data.IsGpsAckMsg = isGpsAckMsg; structSimple.GPSCode = gpsCode; structSimple.Data.Result = result; structSimple.Data.SerialNumberLen = serialLen; structSimple.SerialNumber = serialNumber; structSimple.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; byte[] bytsSimple = new byte[structSimple.GetLength()]; structSimple.WriteBuffer(0, bytsSimple); cmddata.DataBuffer = bytsSimple; cmddata.Data.DataLen = (ushort)bytsSimple.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.SendTakePicture://拍照应答 TakePictureControl structPicture = new TakePictureControl(); structPicture.Data.IsGpsAckMsg = isGpsAckMsg; structPicture.GPSCode = gpsCode; structPicture.Data.Result = result; structPicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; structPicture.SerialNumber = serialNumber; structPicture.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; byte[] bytsPicture = new byte[structPicture.GetLength()]; structPicture.WriteBuffer(0, bytsPicture); cmddata.DataBuffer = bytsPicture; cmddata.Data.DataLen = (ushort)bytsPicture.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //对下发广告的回复 case ControlCmdType.SendAdvertisement: LEDControl ledControl = new LEDControl(); ledControl.GPSCode = gpsCode; ledControl.SerialNumber = serialNumber; ledControl.Data.SerialNumberLen = serialLen; ledControl.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; ledControl.Data.IsGpsAckMsg = false; ledControl.Data.Result = result; dataBuffer = new byte[ledControl.GetLength()]; ledControl.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.SendAdvertisement; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //超速报警 case ControlCmdType.OverSpeedAlarm: OverSpeedAlarmControl overSpeedCrl = new OverSpeedAlarmControl(); overSpeedCrl.GPSCode = gpsCode; overSpeedCrl.Data.GPSCodeLen = gpsCodeLen; overSpeedCrl.SerialNumber = serialNumber; overSpeedCrl.Data.SerialNumberLen = serialLen; overSpeedCrl.Data.IsGpsAckMsg = isGpsAckMsg; overSpeedCrl.Data.Result = result; dataBuffer = new byte[overSpeedCrl.GetLength()]; overSpeedCrl.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.OverSpeedAlarm; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; } return sendBuffer; } catch (Exception ex) { Logger.Error(ex, null); return new byte[0]; } }
private void Button_Click_1(object sender, RoutedEventArgs e) { LEDControl vLEDControl = new LEDControl(App.WatchHouseID); vLEDControl.Test(); }
private void button_FaShong_Click(object sender, RoutedEventArgs e) { LEDSend vLEDSend = new LEDSend(); vLEDSend.SelectedIPArray = m_SelectedIPArray; vLEDSend.TextArray = RTFBox1.ImagePathList.ToArray(); List <ConfigInfo> vPicList = new List <ConfigInfo>(); List <ConfigInfo> vVideoList = new List <ConfigInfo>(); for (int i = 1; i <= 4; i++) { TextBox vVideoTextBox = (TextBox)FindName(string.Format("textBox_ShiPing_SPLJ{0}", i)); if (vVideoTextBox.Text != null && vVideoTextBox.Text != "") { if (File.Exists(vVideoTextBox.Text)) { ConfigInfo vConfigInfo = new ConfigInfo() { Path = vVideoTextBox.Text, ID = i }; vVideoList.Add(vConfigInfo); } } TextBox vPicTextBox = (TextBox)FindName(string.Format("textBox_TuPian_TPLJ{0}", i)); if (vPicTextBox.Text != null && vPicTextBox.Text != "") { if (File.Exists(vPicTextBox.Text)) { ConfigInfo vConfigInfo = new ConfigInfo() { Path = vPicTextBox.Text, ID = i }; vPicList.Add(vConfigInfo); } } } vLEDSend.PicArray = new string[vPicList.Count]; for (int i = 0; i < vPicList.Count; i++) { vLEDSend.PicArray[i] = vPicList[i].Path; } vLEDSend.VideoArray = new string[vVideoList.Count]; for (int i = 0; i < vVideoList.Count; i++) { vLEDSend.VideoArray[i] = vVideoList[i].Path; } vLEDSend.Owner = Application.Current.MainWindow; if (vLEDSend.ShowDialog() ?? false) { List <LEDChannelInfo> vLEDChannelInfoList = new List <LEDChannelInfo>(); LEDControl vLEDControl = new LEDControl(App.WatchHouseID); List <LEDChannelInfo> vTextLedList = new List <LEDChannelInfo>(); foreach (string vTempText in vLEDSend.SelectedTextArray) { LEDChannelInfo vTextChannelInfo = new LEDChannelInfo() { ChannelType = LEDChanneTypeEnum.Text, Content = vTempText, InEff = (int)comboBox_Text_XianShi1.SelectedValue, OutEff = (int)comboBox_Text_QinPing1.SelectedValue, HoldTime = (integerUpDown_Text.Value ?? 0) * 10 }; vLEDChannelInfoList.Add(vTextChannelInfo); vTextLedList.Add(vTextChannelInfo); } List <LEDChannelInfo> vPicLedList = new List <LEDChannelInfo>(); foreach (string vTempPic in vLEDSend.SelectedPicArray) { int vID = vPicList.Where(m => m.Path == vTempPic).FirstOrDefault().ID; ComboBox vComboBox_TuPian_XianShi = (ComboBox)FindName(string.Format("comboBox_TuPian_XianShi{0}", vID)); ComboBox vComboBox_TuPain_QinPing = (ComboBox)FindName(string.Format("comboBox_TuPian_QinPing{0}", vID)); Xceed.Wpf.Toolkit.IntegerUpDown vIntegerUpDown_TuPian = (Xceed.Wpf.Toolkit.IntegerUpDown)FindName(string.Format("integerUpDown_TuPian{0}", vID)); LEDChannelInfo vPicChannelInfo = new LEDChannelInfo() { ChannelType = LEDChanneTypeEnum.Image, Content = vTempPic, InEff = (int)vComboBox_TuPian_XianShi.SelectedValue, OutEff = (int)vComboBox_TuPain_QinPing.SelectedValue, HoldTime = (vIntegerUpDown_TuPian.Value ?? 0) * 10 }; vLEDChannelInfoList.Add(vPicChannelInfo); vPicLedList.Add(vPicChannelInfo); } List <LEDChannelInfo> vVideoLedList = new List <LEDChannelInfo>(); foreach (string vTempVideo in vLEDSend.SelectedVideoArray) { int vID = vVideoList.Where(m => m.Path == vTempVideo).FirstOrDefault().ID; ComboBox vComboBox_ShiPing_XianShi = (ComboBox)FindName(string.Format("comboBox_ShiPing_XianShi{0}", vID)); ComboBox vComboBox_ShiPing_QinPing = (ComboBox)FindName(string.Format("comboBox_ShiPing_QinPing{0}", vID)); Xceed.Wpf.Toolkit.IntegerUpDown vIntegerUpDown_ShiPing = (Xceed.Wpf.Toolkit.IntegerUpDown)FindName(string.Format("integerUpDown_ShiPing{0}", vID)); LEDChannelInfo vVideoChannelInfo = new LEDChannelInfo() { ChannelType = LEDChanneTypeEnum.Video, Content = vTempVideo, InEff = (int)vComboBox_ShiPing_XianShi.SelectedValue, OutEff = (int)vComboBox_ShiPing_QinPing.SelectedValue, HoldTime = (vIntegerUpDown_ShiPing.Value ?? 0) * 10 }; vLEDChannelInfoList.Add(vVideoChannelInfo); vVideoLedList.Add(vVideoChannelInfo); } m_SelectedIPArray = vLEDSend.SelectedIPArray; vLEDControl.SendMultiChannel(vLEDChannelInfoList, m_SelectedIPArray); Xceed.Wpf.Toolkit.MessageBox.Show("已发送", "信息", MessageBoxButton.OK, MessageBoxImage.Information); Config vConfig = new Config(); vConfig.LedTextArray = vTextLedList.ToArray(); vConfig.LedPicArray = vPicLedList.ToArray(); vConfig.LedVideoArray = vVideoLedList.ToArray(); vConfig.Save(); } }
private void Page_Loaded(object sender, RoutedEventArgs e) { m_LEDControl = new LEDControl(App.WatchHouseID); Config vConfig = new Config(); if (m_LEDControl.Width != 0 && m_LEDControl.Heigth != 0) { RTFBox1.RichWidth = m_LEDControl.Width; RTFBox1.RichHeight = m_LEDControl.Heigth; } else { Xceed.Wpf.Toolkit.MessageBox.Show("未设置LED广告屏的分辨率", "错误", MessageBoxButton.OK, MessageBoxImage.Error); tabControl.IsEnabled = false; RTFBox1.Visibility = Visibility.Hidden; } //文字显示 comboBox_Text_XianShi1.ItemsSource = m_Eff; comboBox_Text_XianShi1.SelectedValuePath = "Key"; comboBox_Text_XianShi1.DisplayMemberPath = "Value"; comboBox_Text_XianShi1.SelectedValue = 25; //文字清屏 comboBox_Text_QinPing1.ItemsSource = m_Eff; comboBox_Text_QinPing1.SelectedValuePath = "Key"; comboBox_Text_QinPing1.DisplayMemberPath = "Value"; comboBox_Text_QinPing1.SelectedValue = 25; integerUpDown_Text.Value = 0; for (int i = 1; i <= 4; i++) { //视频路径 TextBox vTextBox_ShiPing_SPLJ = (TextBox)FindName(string.Format("textBox_ShiPing_SPLJ{0}", i)); //视频清屏 ComboBox vComboBox_ShiPing_QinPing = (ComboBox)FindName(string.Format("comboBox_ShiPing_QinPing{0}", i)); vComboBox_ShiPing_QinPing.ItemsSource = m_Eff; vComboBox_ShiPing_QinPing.SelectedValuePath = "Key"; vComboBox_ShiPing_QinPing.DisplayMemberPath = "Value"; vComboBox_ShiPing_QinPing.SelectedValue = 25; //视频显示 ComboBox vComboBox_ShiPing_XianShi = (ComboBox)FindName(string.Format("comboBox_ShiPing_XianShi{0}", i)); vComboBox_ShiPing_XianShi.ItemsSource = m_Eff; vComboBox_ShiPing_XianShi.SelectedValuePath = "Key"; vComboBox_ShiPing_XianShi.DisplayMemberPath = "Value"; vComboBox_ShiPing_XianShi.SelectedValue = 25; //视频停留时间 Xceed.Wpf.Toolkit.IntegerUpDown vIntegerUpDown_ShiPing = (Xceed.Wpf.Toolkit.IntegerUpDown)FindName(string.Format("integerUpDown_ShiPing{0}", i)); vIntegerUpDown_ShiPing.Value = 0; if (i <= vConfig.LedVideoArray.Length) { vComboBox_ShiPing_QinPing.SelectedValue = vConfig.LedVideoArray[i - 1].OutEff; vComboBox_ShiPing_XianShi.SelectedValue = vConfig.LedVideoArray[i - 1].InEff; vIntegerUpDown_ShiPing.Value = vConfig.LedVideoArray[i - 1].HoldTime; vTextBox_ShiPing_SPLJ.Text = vConfig.LedVideoArray[i - 1].Content; } //图片路径 TextBox vTextBox_TuPian_TPLJ = (TextBox)FindName(string.Format("textBox_TuPian_TPLJ{0}", i)); //图片清屏 ComboBox vComboBox_TuPian_QinPing = (ComboBox)FindName(string.Format("comboBox_TuPian_QinPing{0}", i)); vComboBox_TuPian_QinPing.ItemsSource = m_Eff; vComboBox_TuPian_QinPing.SelectedValuePath = "Key"; vComboBox_TuPian_QinPing.DisplayMemberPath = "Value"; vComboBox_TuPian_QinPing.SelectedValue = 25; //图片显示 ComboBox vComboBox_TuPian_XianShi = (ComboBox)FindName(string.Format("comboBox_TuPian_XianShi{0}", i)); vComboBox_TuPian_XianShi.ItemsSource = m_Eff; vComboBox_TuPian_XianShi.SelectedValuePath = "Key"; vComboBox_TuPian_XianShi.DisplayMemberPath = "Value"; vComboBox_TuPian_XianShi.SelectedValue = 25; //图片停留时间 Xceed.Wpf.Toolkit.IntegerUpDown vIntegerUpDown_TuPian = (Xceed.Wpf.Toolkit.IntegerUpDown)FindName(string.Format("integerUpDown_TuPian{0}", i)); vIntegerUpDown_TuPian.Value = 0; if (i <= vConfig.LedPicArray.Length) { vTextBox_TuPian_TPLJ.Text = vConfig.LedPicArray[i - 1].Content; vComboBox_TuPian_QinPing.SelectedValue = vConfig.LedPicArray[i - 1].OutEff; vComboBox_TuPian_XianShi.SelectedValue = vConfig.LedPicArray[i - 1].InEff; vIntegerUpDown_TuPian.Value = vConfig.LedPicArray[i - 1].HoldTime; } } //上一次发送成功的图片 for (int i = 1; i <= 10; i++) { if (i <= vConfig.LedTextArray.Length) { RTFBox1.ImagePathList.Add(vConfig.LedTextArray[i - 1].Content); } } }
public string GetGpsCodeFromBuffer(byte[] receivedBuffer) { string gpsCode = string.Empty; try { CmdData cmdData = new CmdData(); cmdData.ReadBuffer(0, receivedBuffer); switch (cmdData.Data.Cmd) { //调度命令 case ControlCmdType.DispatchControl: DispatchControl DispatchControl = new DispatchControl(); DispatchControl.ReadBuffer(0, cmdData.DataBuffer); gpsCode = DispatchControl.GPSCode; break; //监听喊话 case ControlCmdType.ListenCall: ListenCallControl CallControl = new ListenCallControl(); CallControl.ReadBuffer(0, cmdData.DataBuffer); gpsCode = CallControl.GPSCode; break; case ControlCmdType.LEDControl: SimpleInstructionControl SimpleControl = new SimpleInstructionControl(); SimpleControl.ReadBuffer(0, cmdData.DataBuffer); gpsCode = SimpleControl.GPSCode; break; //下发拍照的动作 case ControlCmdType.SendTakePicture: TakePictureControl takePicture = new TakePictureControl(); takePicture.ReadBuffer(0, cmdData.DataBuffer); gpsCode = takePicture.GPSCode; break; //下发拍照的动作(多摄像头) case ControlCmdType.SendTakePictureMultiCamera: TakePictureControlMultiCamera takePictureMultiCamera = new TakePictureControlMultiCamera(); takePictureMultiCamera.ReadBuffer(0, cmdData.DataBuffer); gpsCode = takePictureMultiCamera.GPSCode; break; case ControlCmdType.SupplyOilCircuit: //强制断油断电 case ControlCmdType.BreakOilCircuitByForce: //智能断油断电 case ControlCmdType.BreakOilCircuitBySmart: ControlOilCircuit ControlOil = new ControlOilCircuit(); ControlOil.ReadBuffer(0, cmdData.DataBuffer); gpsCode = ControlOil.GPSCode; break; //北京视展LED控制 case ControlCmdType.BJSZLedControl: case ControlCmdType.SendAdvertisement: LEDControl ledControl = new LEDControl(); ledControl.ReadBuffer(0, cmdData.DataBuffer); gpsCode = ledControl.GPSCode; break; //解除报警 case ControlCmdType.DischargeAlarm: DischangeAlarmControl dischangeAlarm = new DischangeAlarmControl(); dischangeAlarm.ReadBuffer(0, cmdData.DataBuffer); gpsCode = dischangeAlarm.GPSCode; break; //超速报警 case ControlCmdType.OverSpeedAlarm: OverSpeedAlarmControl overSpeedAlarm = new OverSpeedAlarmControl(); overSpeedAlarm.ReadBuffer(0, cmdData.DataBuffer); gpsCode = overSpeedAlarm.GPSCode; break; //获取网关活动信息 case ControlCmdType.GetGatewayActiveInfo: GatewayActiveInfo activeInfo = new GatewayActiveInfo(); activeInfo.ReadBuffer(0, cmdData.DataBuffer); gpsCode = activeInfo.GPSCode; break; //更新GPS总里程值 case ControlCmdType.updatemileage: UpdateMileage UpMileage = new UpdateMileage(); UpMileage.ReadBuffer(0, cmdData.DataBuffer); gpsCode = UpMileage.GPSCode; break; //设置GPS上传周期 case ControlCmdType.SendGPSPosUploadInterval: GPSPosUploadInterval posUploadInterval = new GPSPosUploadInterval(); posUploadInterval.ReadBuffer(0, cmdData.DataBuffer); gpsCode = posUploadInterval.GPSCode; break; //设置移动台初始经参数 case ControlCmdType.SetMobileInitPara: SetMobileInitPara setMobileInitPara = new SetMobileInitPara(); setMobileInitPara.ReadBuffer(0, cmdData.DataBuffer); gpsCode = setMobileInitPara.GPSCode; break; //雅迅设备,配置报警器 case ControlCmdType.AllocateAnnounciator: SetAnnounciator setAnnounciator = new SetAnnounciator(); setAnnounciator.ReadBuffer(0, cmdData.DataBuffer); gpsCode = setAnnounciator.GPSCode; break; case ControlCmdType.SetCircleRegion: case ControlCmdType.SetRectangleRegion: case ControlCmdType.SetPloygon: case ControlCmdType.SetFixedLine: case ControlCmdType.RemoveCircleRegion: case ControlCmdType.RemoveRectangleRegion: case ControlCmdType.RemovePloygon: case ControlCmdType.RemoveFixedLine: case ControlCmdType.TMLControl: case ControlCmdType.SendTxtToTML: case ControlCmdType.PhoneCallback: case ControlCmdType.CameraShootImmediately: case ControlCmdType.PositionQueryReq: case ControlCmdType.SetStopCarAlarm: case ControlCmdType.SetOverFatigueAlarm: case ControlCmdType.SetOverSpeedAlarm: case ControlCmdType.GetRravelRecord: //case ControlCmdType.MediaInfoSetting: //case ControlCmdType.MediaInfoService: //case ControlCmdType.EventSetting: //case ControlCmdType.PublishQuestion: //case ControlCmdType.TempLocationTrace: //case ControlCmdType.VehicleControl: BuBiaoCommonControl BBControl = new BuBiaoCommonControl(); BBControl.ReadBuffer(0, cmdData.DataBuffer); gpsCode = BBControl.GPSCode; break; //部标解除报警 case ControlCmdType.ReleaseAlarm: BuBiaoCommonControl ReleaseControl = new BuBiaoCommonControl(); ReleaseControl.ReadBuffer(0, cmdData.DataBuffer); gpsCode = ReleaseControl.GPSCode; break; default: break; } } catch (Exception ex) { Logger.Error(ex, null); } return gpsCode; }
private void MainForm_Load(object sender, EventArgs e) { m_WatchHouseControl = new WatchHouseControl(); m_PowerControl = new PowerControl(); m_LEDControl = new LEDControl(); }
private void btnBJSZLedContrl_Click(object sender, EventArgs e) { LEDControl data = new LEDControl(); data.GPSCode = "00092042100264"; data.SendContent = "btnBJSZLedContrl_Click"; data.Data.LEDDisplayType = 0;//永远为0 data.Data.LEDSpeed = 2; data.Data.LEDTimeLen = 3; CommandService.GetInstance().BJSZLedContrl(data); }
private void btnSendAds_Click(object sender, EventArgs e) { //AdvertisementControl data = new AdvertisementControl(); //data.SendContent = "AdvertisementControl"; //data.GPSCode = "00092042100264"; //data.Data.ContentLen = (ushort)Encoding.Default.GetBytes(data.SendContent).Length; //data.Data.GPSCodeLen = (ushort)Encoding.Default.GetBytes(data.GPSCode).Length; //byte[] buffer = new byte[data.GetLength()]; //data.WriteBuffer(0, buffer); //CommandService.GetInstance().SendAdvertisement(data); LEDControl data = new LEDControl(); data.Data.LedColorType = LEDColorType.Homochromy; data.Data.LEDDisplayType = 1; data.SendContent ="GetAdvertContent(advertInfo.Contents)"; data.GPSCode = "00092042100264"; data.Data.LEDSpeed = 30; data.Data.LEDTimeLen = 20; data.Data.ContentLen = (ushort)Encoding.Default.GetBytes(data.SendContent).Length; data.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(data.GPSCode).Length; data.Data.GpsType = GPSType.YouWei; data.Data.Width = 160; data.Data.Height = 32; bool flag = CommandService.GetInstance().SendAdvertisement(data); }