public void Receive(byte[] bytes) { var id = (int)bytes[0]; var deviceType = (int)bytes[1]; var deviceNum = (int)bytes[2]; //新增和删除分站时将数据修改为发送分站状态协议数据 if (id == 22 || id == 23) { byte[] sendBytes = { 3, 4, 0, bytes[3], 0 }; //发送到地面信息接口 _socketSendServer.SendMessage((int)DeviceTypeEnum.UpDataInterface, 0, sendBytes); //发送井下数据接口 _socketSendServer.SendMessage((int)DeviceTypeEnum.DownDataInterface, 0, sendBytes); } else { _socketSendServer.SendMessage(deviceType, deviceNum, bytes); } }
public async Task ExecReceive(TimeCheckGroupModel protocolModel) { try { if (protocolModel != null) { var date = DateTime.Now; byte[] bytes = new byte[10]; bytes[0] = 11; bytes[1] = (byte)protocolModel.RequestDeviceType; bytes[2] = (byte)protocolModel.RequestId; bytes[3] = (byte)(date.Year % 2000); bytes[4] = (byte)date.Month; bytes[5] = (byte)date.Day; bytes[6] = (byte)date.Hour; bytes[7] = (byte)date.Minute; bytes[8] = (byte)date.Second; bytes[9] = (byte)(date.Millisecond / 10); await Task.Run(() => { _socketSendServer.SendMessage((int)protocolModel.RequestDeviceType, protocolModel.RequestId, bytes); }); } } catch (Exception e) { _logger.LogError(e.InnerException?.Message ?? e.Message); } }
public void Receive(byte[] bytes) { var substationId = (int)bytes[1]; if (substationId == 0) { var setting = _kj1012CollectionSetting.CurrentValue; for (int i = 1; i <= setting.MaxSubstationCount; i++) { _socketSendServer.SendMessage(4, i, bytes); } } else { _socketSendServer.SendMessage(4, substationId, bytes); } }
public async Task ExecReceive(BaseStationListGroupModel protocolModel) { try { if (protocolModel != null) { //依赖注入是以作用域管理对象,net core 默认作用域为每一个请求 //在这里没有请求,所有通过IServiceProvider构建一个作用域对象,保证后面的数据操作引用异步始终都是独立的对象 using (var serviceScope = _serviceProvider.CreateScope()) { IDeviceService service = serviceScope.ServiceProvider.GetService <IDeviceService>(); var devices = await service.GetDevicesByTypeAndSubNum(DeviceTypeEnum.BaseStation, protocolModel.RequestSubstation).ToListAsync(); var bytes = SendBytes(protocolModel, devices); _socketSendServer.SendMessage((int)protocolModel.RequestDeviceType, protocolModel.RequestNum, bytes); } } } catch (Exception e) { _logger.LogError(e.InnerException?.Message ?? e.Message); } }
private void SocketTcpServer_ReceiveData(UserToken userToken, byte[] bytes) { if (!_isReceive) { return; } try { //包含误码测试解析 #if TEST if (userToken.WorkingMode != 0) { ErrorTestProtocol(bytes); return; } #endif string message = CommonHelper.BytesToHexStr(bytes); //收到QUIT的十六进制消息51495554消息则服务器主动关闭客户端连接 if (message == "51495554") { userToken.Socket.Shutdown(SocketShutdown.Send); return; } var deviceType = userToken.DeviceType; switch (deviceType) { case 04: case 06: case 07: { #if TEST var result = DeviceModeChange(bytes); if (result) { return; } #endif _logger.LogInformation($"r [{userToken.Remote}]:{message}"); ProtocolMessage(bytes); break; } //包含误码测试解析 #if TEST case 98: { if (_bitErrorTest[0] != 0) { _socketSendServer.SendMessage(_bitErrorTest[0], _bitErrorTest[1], bytes, false); } else { _socketSendServer.SendMessage(bytes[1], bytes[2], bytes, false); } } break; #endif case 99: { _socketSendServer.SendMessage(bytes[1], bytes[2], bytes, false); } break; } } catch (Exception e) { _logger.LogError(e.InnerException?.Message ?? e.Message); } }