Ejemplo n.º 1
0
        public Car findCarByCarId(string id)
        {
            using (DataContext db = new SqlserverContext())
            {
                Table <Car>         T_Car            = db.GetTable <Car>();
                Table <RunRealTime> runRealTimeTable = db.GetTable <RunRealTime>();
                Table <Order>       orderTable       = db.GetTable <Order>();
                Car car = T_Car.FirstOrDefault <Car>(o => o.id.Equals(id));
                if (car != null)
                {
                    RunRealTime runRealTime = (from m in runRealTimeTable where m.TerminalId == car.TermID orderby m.sampleTime descending select m).FirstOrDefault();
                    //if (runRealTime != null)
                    //{
                    //}
                    car.miles = (Convert.ToInt32(car.CarCharge) * 10).ToString();
                    Order order = (from m in orderTable where m.CarID == car.id orderby m.CreateTime descending select m).FirstOrDefault();
                    if (order != null)
                    {
                        car.lastUsedTime = order.CreateTime;
                    }

                    Order uorder = (from m in orderTable where m.CarID == car.id orderby m.CreateTime select m).FirstOrDefault();
                    if (uorder != null)
                    {
                        car.UpdateTime = order.CreateTime;
                    }
                }
                return(car);
            }
        }
        /**
         *
         * @param terminalID
         * @param longitudel
         * @param latitude
         * @return
         */
        public TerminalSession getSession(RunRealTime status)
        {
            lock (loc)
            {
                if (!isInit)
                {
                    Init();
                }
            }
            TerminalSession session = currentUser[status.TerminalId];

            if (session != null && session.isUsing())
            {
                session.setStatus(status);
                session.setLastTime(Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds));
                //session.setUsedCount(session.getUsedCount() + 1);
                return(session);
            }
            else
            {
                session = new TerminalSession(status);
                currentUser[status.TerminalId] = session;
                return(session);
            }
        }
Ejemplo n.º 3
0
        //解析输入流
        public static RunRealTime analysisRun(StringRequestInfo requestInfo)
        {
            byte[] src = new byte[33];
            for (var x = 0; x < requestInfo.Body.Length; x++)
            {
                src[x] = (byte)Convert.ToChar(x);
            }
            //如果有数据可读
            RunRealTime run = new RunRealTime();

            // readStream(input, src);
            //3字节ID
            byte[] id = new byte[3];
            Array.Copy(src, 0, id, 0, id.Length);
            run.TerminalId = ByteUtils.byteToHexStr(id);
            //4字节纬度--6  31 15.12 34 50
            byte[] lat = new byte[5];
            Array.Copy(src, 3, lat, 0, lat.Length);
            //lat转换int 直接放大10^6倍取整传输
            run.latitude = long.Parse("" + lat[0] + lat[1] + lat[2] + lat[3] + lat[4]);
            //run.latitude = ((lat[0] << 24) & 0xff000000) + ((lat[1] << 16) & 0xff0000) + ((lat[2] << 8) & 0xff00) + (lat[3] & 0xff);
            //经度--6 120 10 .56 78 90
            byte[] lon = new byte[5];
            Array.Copy(src, 3 + 5, lon, 0, lon.Length);
            // run.longitude = ((lon[0] << 24) & 0xff000000) + ((lon[1] << 16) & 0xff00000) + ((lon[2] << 8) & 0xff00) + (lon[3] & 0xff);
            run.longitude = long.Parse("" + lon[0] + lon[1] + lon[2] + lon[3] + lon[4]);
            //Power 1byte
            byte[] power = new byte[1];
            Array.Copy(src, 3 + 5 + 5, power, 0, power.Length);
            run.batteryInfo = power[0];
            //voltage 1+1byte
            byte[] voltage = new byte[2];
            Array.Copy(src, 3 + 5 + 5 + 1, voltage, 0, voltage.Length);
            run.voltage = ((voltage[0] << 8) & 0xff00) + (voltage[1] & 0xff);
            //current 1+1byte
            byte[] current = new byte[2];
            Array.Copy(src, 3 + 5 + 5 + 1 + 2, current, 0, current.Length);
            run.current = ((current[0] << 8) & 0xff00) + (current[1] & 0xff);
            //temper 1+1byte
            byte[] temper = new byte[2];
            Array.Copy(src, 3 + 5 + 5 + 1 + 2 + 2, temper, 0, temper.Length);
            run.Temper = ((temper[0] << 8) & 0xff00) + (temper[1] & 0xff);
            //门状态:前门1111开  0000关 后门1111开  0000关
            byte[] gate = new byte[1];
            Array.Copy(src, 3 + 5 + 5 + 1 + 2 + 2 + 2, gate, 0, gate.Length);
            run.beforeGateStatus = ((gate[0] >> 4) & 0x0f);
            run.behindGateStatus = ((gate[0]) & 0x0f);
            //车速 1+4byte 车速+续航
            byte[] speed = new byte[5];
            Array.Copy(src, 3 + 5 + 5 + 1 + 2 + 2 + 2 + 1, speed, 0, speed.Length);
            run.speed = speed[0];
            run.mile  = ((speed[1] << 24) & 0xff000000) + ((speed[2] << 16) & 0xff0000) + ((speed[3] << 8) & 0xff00) + (speed[4] & 0xff);
            //时间
            byte[] date = new byte[7];
            Array.Copy(src, 3 + 5 + 5 + 1 + 2 + 2 + 2 + 1 + 5, date, 0, date.Length);
            run.sampleTime = dateAnalisis(date, 0);
            return(run);
        }
Ejemplo n.º 4
0
        //查询电池 电压  电量  速度 经纬度等数据
        public ActionResult selectRun()
        {
            RunRealTime real = orderbll.selectRunReal();

            if (real != null)
            {
                ViewData.Model = real;
            }
            return(View());
        }
Ejemplo n.º 5
0
        public RunRealTime AddRunRealTime(RunRealTime run)
        {
            if (run != null)
            {
                using (DataContext db = new SqlserverContext())
                {
                    Table <RunRealTime> T_order = db.GetTable <RunRealTime>();
                    T_order.InsertOnSubmit(run);
                    db.SubmitChanges();
                    return(run);
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        //终端运行时上传实时位置数据
        public RunRealTime uploadRunRealTime(RunRealTime input)
        {
            //1.将终端数据加入计时器线程,更新为时间,判断是否超时
            // to do
            //  TerminalSession session=TerminalRealTimeInspector.CreateInstance().getSession(input);
            //2.判断updateTime时间差是否大于5S,如果超过则下发查分数,否则下发周边数据
            // todo
            //3.保存终端上传数据
            RunRealTime real = db_realtime.AddRunRealTime(input);

            if (real != null)
            {
                return(real);
            }
            return(null);
        }
Ejemplo n.º 7
0
        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);
            RunRealTime real = Analysis.analysisRun(requestInfo);

            //  33字节请求数据
            real.sampleTime = string.Format("{0:yyyyMMddHHmmssfff}", DateTime.Now);
            if (RealTimeThread.dic.ContainsKey(real.TerminalId))
            {
                CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo;
                if (info != null)
                {
                    info.Power     = real.batteryInfo;
                    info.Voltage   = real.voltage;
                    info.Speed     = real.speed;
                    info.Mile      = real.mile;
                    info.Longitude = real.longitude;
                    info.Latitude  = real.latitude;
                    RealTimeThread.dic[real.TerminalId] = info;
                }
            }
            else
            {
                CarInfo c = new CarInfo();
                c.Power     = real.batteryInfo;
                c.Voltage   = real.voltage;
                c.Speed     = real.speed;
                c.Mile      = real.mile;
                c.Longitude = real.longitude;
                c.Latitude  = real.latitude;
                RealTimeThread.dic.Add(real.TerminalId, c);
            }

            if (requestInfo != null)
            {
                db_realtime.uploadRunRealTime(real);
            }
            //服务器响应
            // session.Send(requestInfo.Body);
        }
Ejemplo n.º 8
0
        public void Run()
        {
            LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " RUN");
            Stream      inputStream = Request.GetBufferedInputStream();
            RunRealTime real        = RealTimeAnalysis.analysisRun(inputStream);

            real.sampleTime = string.Format("{0:yyyyMMddHHmmssfff}", DateTime.Now);
            if (RealTimeThread.dic.ContainsKey(real.TerminalId))
            {
                CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo;
                if (info != null)
                {
                    info.Power     = real.batteryInfo;
                    info.Voltage   = real.voltage;
                    info.Speed     = real.speed;
                    info.Mile      = real.mile;
                    info.Longitude = real.longitude;
                    info.Latitude  = real.latitude;
                    RealTimeThread.dic[real.TerminalId] = info;
                }
            }
            else
            {
                CarInfo c = new CarInfo();
                c.Power     = real.batteryInfo;
                c.Voltage   = real.voltage;
                c.Speed     = real.speed;
                c.Mile      = real.mile;
                c.Longitude = real.longitude;
                c.Latitude  = real.latitude;
                RealTimeThread.dic.Add(real.TerminalId, c);
            }

            if (real != null)
            {
                orderbll.uploadRunRealTime(real);
            }
        }
Ejemplo n.º 9
0
        public IList <Car> findCar(int id)
        {
            using (DataContext db = new SqlserverContext())
            {
                Table <ValidCar>    carTable         = db.GetTable <ValidCar>();
                Table <RunRealTime> runRealTimeTable = db.GetTable <RunRealTime>();
                Table <Order>       orderTable       = db.GetTable <Order>();
                List <ValidCar>     validCarList     = (from m in carTable where m.StationID == id select m).ToList();
                List <Car>          ret = new List <Car>();
                foreach (ValidCar car in validCarList)
                {
                    Car catItem = new Car()
                    {
                        CarCharge = car.CarCharge, CarFac = car.CarFac, CarNo = car.CarNo, CarStartDate = car.CarStartDate, CarType = car.CarType, CarVolume = car.CarVolume, CreateTime = car.CreateTime, id = car.id, TermID = car.TermID
                    };

                    RunRealTime runRealTime = (from m in runRealTimeTable where m.TerminalId == car.TermID orderby m.sampleTime descending select m).FirstOrDefault();
                    if (runRealTime != null)
                    {
                        catItem.miles = (Convert.ToInt32(catItem.CarCharge) * 10).ToString();
                    }
                    Order order = (from m in orderTable where m.CarID == car.id orderby m.CreateTime descending select m).FirstOrDefault();
                    if (order != null)
                    {
                        catItem.lastUsedTime = order.CreateTime;
                    }

                    Order uorder = (from m in orderTable where m.CarID == car.id orderby m.CreateTime select m).FirstOrDefault();
                    if (uorder != null)
                    {
                        catItem.UpdateTime = uorder.CreateTime;
                    }

                    ret.Add(catItem);
                }
                return(ret);
            }
        }