public void Stop() { LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " Stop"); Stream inputStream = Request.GetBufferedInputStream(); StopRealTime real = RealTimeAnalysis.analysisStop(inputStream); if (RealTimeThread.dic.ContainsKey(real.TerminalId)) { CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo; if (info != null) { info.Power = int.Parse(real.Power); info.Voltage = int.Parse(real.Voltage); info.Current = int.Parse(real.Current); info.Temperature = int.Parse(real.Temperature); RealTimeThread.dic[real.TerminalId] = info; } } else { CarInfo c = new CarInfo(); c.Power = int.Parse(real.Power); c.Voltage = int.Parse(real.Voltage); c.Current = int.Parse(real.Current); c.Temperature = int.Parse(real.Temperature); RealTimeThread.dic.Add(real.TerminalId, c); } if (real != null) { orderbll.uploadStopRealTime(real); } }
public static StopRealTime analysisStop(StringRequestInfo requestInfo) { byte[] src = new byte[10]; for (var x = 0; x < requestInfo.Body.Length; x++) { src[x] = (byte)Convert.ToChar(x); } StopRealTime stop = new StopRealTime(); //3字节ID byte[] id = new byte[3]; Array.Copy(src, 0, id, 0, id.Length); stop.TerminalId = ByteUtils.byteToHexStr(id); //1字节电量 0-100 byte[] power = new byte[1]; Array.Copy(src, 3, power, 0, power.Length); stop.Power = power[0].ToString(); //2字节电压 0-100 byte[] voltage = new byte[2]; Array.Copy(src, 3 + 1, voltage, 0, voltage.Length); stop.Voltage = (((voltage[0] << 8) & 0xff00) + (voltage[1] & 0xff)).ToString(); //2字节电流 0-100 byte[] current = new byte[2]; Array.Copy(src, 3 + 1 + 2, current, 0, current.Length); stop.Current = (((current[0] << 8) & 0xff00) + (current[1] & 0xff)).ToString(); //2字节电池温度 0-100 byte[] temperature = new byte[2]; Array.Copy(src, 3 + 1 + 2 + 2, temperature, 0, temperature.Length); stop.Temperature = temperature[0].ToString(); return(stop); }
public static StopRealTime analysisStop(Stream input) { StopRealTime stop = new StopRealTime(); byte[] src = new byte[10]; readStream(input, src); //3字节ID byte[] id = new byte[3]; Array.Copy(src, 0, id, 0, id.Length); stop.TerminalId = ByteUtils.byteToHexStr(id); //1字节电量 0-100 byte[] power = new byte[1]; Array.Copy(src, 3, power, 0, power.Length); stop.Power = power[0].ToString(); //2字节电压 0-100 byte[] voltage = new byte[2]; Array.Copy(src, 3 + 1, voltage, 0, voltage.Length); stop.Voltage = (((voltage[0] << 8) & 0xff00) + (voltage[1] & 0xff)).ToString(); //2字节电流 0-100 byte[] current = new byte[2]; Array.Copy(src, 3 + 1 + 2, current, 0, current.Length); stop.Current = (((current[0] << 8) & 0xff00) + (current[1] & 0xff)).ToString(); //2字节电池温度 0-100 byte[] temperature = new byte[2]; Array.Copy(src, 3 + 1 + 2 + 2, temperature, 0, temperature.Length); stop.Temperature = temperature[0].ToString(); return(stop); }
public ActionResult selectStop() { StopRealTime real = orderbll.selectStopReal(); if (real != null) { ViewData.Model = real; } return(View()); }
public StopRealTime uploadStopRealTime(StopRealTime input) { StopRealTime real = db_realtime.AddStopRealTime(input); if (real != null) { return(real); } return(null); }
public StopRealTime AddStopRealTime(StopRealTime run) { if (run != null) { using (DataContext db = new SqlserverContext()) { Table <StopRealTime> T_order = db.GetTable <StopRealTime>(); T_order.InsertOnSubmit(run); db.SubmitChanges(); return(run); } } return(null); }
public override void ExecuteCommand(MySession session, StringRequestInfo requestInfo) { // Console.WriteLine("Run:" + requestInfo.Body.Length); //foreach (var x in requestInfo.Body) //{ // Console.WriteLine((int)Convert.ToChar(x)); //} //session.Send(requestInfo.Body); StopRealTime real = Analysis.analysisStop(requestInfo); // 33字节请求数据 if (RealTimeThread.dic.ContainsKey(real.TerminalId)) { CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo; if (info != null) { info.Power = int.Parse(real.Power); info.Voltage = int.Parse(real.Voltage); info.Current = int.Parse(real.Current); info.Temperature = int.Parse(real.Temperature); RealTimeThread.dic[real.TerminalId] = info; } } else { CarInfo c = new CarInfo(); c.Power = int.Parse(real.Power); c.Voltage = int.Parse(real.Voltage); c.Current = int.Parse(real.Current); c.Temperature = int.Parse(real.Temperature); RealTimeThread.dic.Add(real.TerminalId, c); } if (requestInfo != null) { db_realtime.uploadStopRealTime(real); } //服务器响应 // session.Send(requestInfo.Body); }