Пример #1
0
        private devices SelectDevice(int id)
        {
            devices devices = new devices();

            devices.Read(id);
            return(devices);
        }
Пример #2
0
        private void loadDevice(devices dv)
        {
            // devices dv = new devices();
            int number = panel1.Controls.Count;

            dv.Location = new Point(0, number * 60);
            panel1.Controls.Add(dv);
        }
Пример #3
0
        public IActionResult getDeviceswithSorting(String SortColumn, String SortDirection)
        {
            Db.Connection.Open();
            var query  = new devices(Db);
            var result = query.SortAlldevices(SortColumn, SortDirection);

            Db.Connection.Close();
            return(Ok(result));
        }
Пример #4
0
        public IActionResult getDeviceswithSearch(String search)
        {
            Db.Connection.Open();
            var query  = new devices(Db);
            var result = query.getDeviceBySearch(search);

            Db.Connection.Close();
            return(Ok(result));
        }
Пример #5
0
        public IActionResult DeleteOne(int device_id)
        {
            Db.Connection.Open();
            devices query = new devices(Db);

            query.device_id = device_id;
            query.Delete();
            Db.Connection.Close();
            return(Ok());
        }
Пример #6
0
        public IActionResult GetAllDevices()
        {
            int limit1  = Convert.ToInt32(HttpContext.Request.Query["limit1"]);
            int offset1 = Convert.ToInt32(HttpContext.Request.Query["offset1"]);

            Db.Connection.Open();
            var query  = new devices(Db);
            var result = query.GetAllDevices(limit1, offset1);

            Db.Connection.Close();
            return(Ok(result));
        }
Пример #7
0
        public devices GetSingleDeviceInfo(string id)
        {
            devices send = new devices();
            int     nId  = Convert.ToInt32(id);

            if (dict.ContainsKey(nId))
            {
                send = dict[nId];
            }

            return(send);
        }
Пример #8
0
		public void Update (devices.IDevice device)
		{

			if (device == null)
				return;


			int i = 0;
			int numAxis = device.Axis.Count;
			int numButtons = device.Buttons.Count;
                   
			//int index = device.Index;//if this was as easy=> Unity reorder/insert new added devices

			//  Debug.Log(String.Join(Input.GetJoystickNames()
			int index = Array.IndexOf (Input.GetJoystickNames (), device.Name);
			if (index < 0) {
				Debug.LogWarning ("Devices can't be found by UnityDriver");		
				return;
			}

			// Debug.Log("axis value raw:" + Input.GetAxisRaw("10") + " " + Input.GetAxis("11"));
			//Debug.Log("axis value raw:" +);
			//   joystick.Axis[0].value=Input.GetAxis("00");//index-of joystick, i-ord number of axis
			// Debug.Log("axis value:" + joystick.Axis[0].value + " state:" + joystick.Axis[0].buttonState);

			// index = 1;
			float axisValue = 0f;
			for (; i < numAxis; i++) {

				axisValue = Input.GetAxisRaw (index.ToString () + i.ToString ());
				device.Axis [i].value = axisValue;
				//(Input.GetAxis (index.ToString () + i.ToString ()) + 1f) * 0.5f;//index-of joystick, i-ord number of axis

				//axisValue = Input.GetAxis (index.ToString () + i.ToString ()) + " ";

//							if(i==1){
//								Debug.Log(axisValue);
//								
//							}

			}

						


			for (i=0; i < numButtons; i++) {
               
				device.Buttons [i].value = Input.GetKey ((KeyCode)Enum.Parse (typeof(KeyCode), "Joystick" + (index + 1) + "Button" + i)) == true ? 1f : 0f;

			}
		}
Пример #9
0
        private void PopulateDDL()
        {
            devices        devices = new devices();
            List <devices> List    = devices.List();

            ddlDevices.DataTextField  = "device_name";
            ddlDevices.DataValueField = "id";
            ddlDevices.DataSource     = List;
            ddlDevices.DataBind();


            devices startupDevices = new devices();

            if (ddlDevices.Items.Count > 0)
            {
                startupDevices = SelectDevice(Convert.ToInt32(ddlDevices.Items[0].Value));
            }
        }
Пример #10
0
        public List <devices> DeviceList(string email, string password)
        {
            SqlCommand     cmddevicelist;
            List <devices> d_list = new List <devices>();
            devices        temp   = new devices();

            con.Open();
            cmddevicelist = new SqlCommand("SELECT Device.ItemId,Device.Name,Device.Type,Device.topicname FROM Device INNER JOIN [User] ON Device.userid= [User].UserId WHERE email='" + email + "' and password='******'", con);
            SqlDataReader reader = cmddevicelist.ExecuteReader();

            while (reader.Read())
            {
                temp.DeviceId  = Convert.ToInt32(reader[0]);
                temp.name      = reader[1].ToString();
                temp.type      = reader[2].ToString();
                temp.topicname = reader[3].ToString();
                d_list.Add(temp);
            }
            con.Close();
            cmddevicelist.Connection.Close();
            return(d_list);
        }
Пример #11
0
        private void LoadDevice(Int32 intDeviceID)
        {
            List <DisplayGrid> lst = new List <DisplayGrid>();

            DisplayGrid obj    = new DisplayGrid();
            devices     device = new devices();

            device      = device.Read(intDeviceID);
            obj.setting = "Device ID";
            obj.value   = device.id.ToString();
            lst.Add(obj);

            obj         = new DisplayGrid();
            obj.setting = "Device URL name";
            obj.value   = device.device_url_name.ToString();
            lst.Add(obj);

            obj         = new DisplayGrid();
            obj.setting = "Device friendly name";
            obj.value   = device.device_name.ToString();
            lst.Add(obj);

            obj         = new DisplayGrid();
            obj.setting = "Device is retired";
            obj.value   = device.device_retired.ToString();
            lst.Add(obj);

            transactions transactions = new DAL.transactions();

            transactions.transactions_stats stats = transactions.GetDisplayStats(intDeviceID);

            if (stats.SerialNumber != null)
            {
                obj         = new DisplayGrid();
                obj.setting = "Serial number";
                obj.value   = stats.SerialNumber;
                lst.Add(obj);
            }
            if (stats.AndroidID != null)
            {
                obj         = new DisplayGrid();
                obj.setting = "Android ID";
                obj.value   = stats.AndroidID;
                lst.Add(obj);
            }
            if (stats.FirstLog != null)
            {
                obj         = new DisplayGrid();
                obj.setting = "First log date (time)";
                obj.value   = string.Format("{0:dddd, d MMMM yyyy (H:mm:ss)}", stats.FirstLog);
                obj.value  += " (" + CalculateTimeAgo(stats.FirstLog) + ")";
                lst.Add(obj);
            }
            if (stats.LastLog != null)
            {
                obj         = new DisplayGrid();
                obj.setting = "Last log date (time)";
                obj.value   = string.Format("{0:dddd, d MMMM yyyy (H:mm:ss)}", stats.LastLog);
                obj.value  += " (" + CalculateTimeAgo(stats.LastLog) + ")";
                lst.Add(obj);
            }
            if (stats.TotalNumberOfLogs > 0)
            {
                obj         = new DisplayGrid();
                obj.setting = "Total number of logs (all devices)";
                obj.value   = (string.Format("{0:### ### ### ### ### ### ##0}", stats.TotalNumberOfLogs)).Trim();
                lst.Add(obj);
            }
            if (stats.NumberOfLogs > 0)
            {
                obj         = new DisplayGrid();
                obj.setting = "Device logs (this device only)";
                obj.value   = (string.Format("{0:### ### ### ### ### ### ##0}", stats.NumberOfLogs)).Trim();
                lst.Add(obj);
            }
            if (stats.LastLongitude > -1000)
            {
                obj         = new DisplayGrid();
                obj.setting = "Longitude";
                obj.value   = string.Format("{0:##0.0###########}", stats.LastLongitude).Trim();
                lst.Add(obj);
            }
            if (stats.LastLatitude > -1000)
            {
                obj         = new DisplayGrid();
                obj.setting = "LastLatitude";
                obj.value   = string.Format("{0:##0.0###########}", stats.LastLatitude).Trim();
                lst.Add(obj);
            }
            if (stats.Altitude > 0)
            {
                obj         = new DisplayGrid();
                obj.setting = "Altitude";
                obj.value   = string.Format("{0:### ##0}", stats.Altitude).Trim();
                lst.Add(obj);
            }
            if (stats.Speed > 0)
            {
                obj         = new DisplayGrid();
                obj.setting = "Speed";
                obj.value   = string.Format("{0:### ##0}", stats.Speed).Trim();
                lst.Add(obj);
            }
            if (stats.Accuracy > 0)
            {
                obj         = new DisplayGrid();
                obj.setting = "Accuracy";
                obj.value   = string.Format("{0:### ##0}", stats.Accuracy).Trim();
                lst.Add(obj);
            }
            if (stats.Direction > -1)
            {
                obj         = new DisplayGrid();
                obj.setting = "Direction";
                obj.value   = string.Format("{0:##0}", stats.Direction);
                lst.Add(obj);
            }
            if (stats.Provider != "")
            {
                obj         = new DisplayGrid();
                obj.setting = "Location provider";
                obj.value   = stats.Provider;
                lst.Add(obj);
            }
            if (stats.Time_UTC > DateTime.MinValue)
            {
                obj         = new DisplayGrid();
                obj.setting = "Device local date(time)";
                obj.value   = string.Format("{0:dddd, d MMMM yyyy (H:mm:ss)}", stats.Time_UTC);
                lst.Add(obj);
            }
            if (stats.Battery > -1)
            {
                obj         = new DisplayGrid();
                obj.setting = "Battery";
                obj.value   = string.Format("{0:##0}", stats.Battery) + "%";
                lst.Add(obj);
            }

            grdDetail.DataSource = lst;
            grdDetail.DataBind();
        }
Пример #12
0
 private void loadDevice(devices dv)
 {
    // devices dv = new devices();
     int number = panel1.Controls.Count;
     dv.Location = new Point(0, number * 60);
     panel1.Controls.Add(dv);
 }
Пример #13
0
 protected void ddlDevices_SelectedIndexChanged(object sender, EventArgs e)
 {
     devices devices = SelectDevice(Convert.ToInt32(ddlDevices.SelectedItem.Value));
 }
Пример #14
0
        public void ThreadReceiveGPS()
        {
            db = new gpsEntities();
            String DeviceID = "";

            try
            {
                //Remote ip and remote port
                String remoteAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
                String remotePort    = ((IPEndPoint)client.Client.RemoteEndPoint).Port.ToString();

                // Buffer for reading data
                Byte[] bytes       = new Byte[250];
                string hex         = "";
                String invertedHex = "";


                int i;
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    /*
                     * IMPORTANT: the data sent by the GPS can be ordered in two formats Little-Endian or Big-Endian
                     * (If you have not heard these two terms look for information about Endianness), providers should
                     * tell us in what format they were written the most common is the Big-Endian but for this case I play a
                     * GPS that ordered them in Little-Endian and I had to invert the data so that it has some meaning.
                     *
                     * If your provider has no idea of how this information is sent or for one reason or another you can not communicate
                     * with your provider, you can make trial and error test. It will not take you long just to have the hex in two ways as
                     * you can see below and use the form that gives you meaningful data.
                     *
                     * The way you know that data is correct, is seeing the protocol document that comes with the device or that your provider provides you.
                     *
                     * There are many types of protocols and it is important to make sure that you have the right one so as not to waste your time and think
                     * that you are the one programming the server in an erroneous way.
                     */

                    // Console.WriteLine("Info: " + message);
                    hex         = BitConverter.ToString(bytes, 0, i).Replace("-", " ");
                    invertedHex = Strings.Invert(hex, ' ');

                    //If you want to see the hex before and after being inverted uncomment the two lines below

                    //Console.WriteLine("Received HEX: [ {1}:{2} ] {0} ", hex, remoteAddress, remotePort);
                    //Console.WriteLine("Received HEX: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort);

                    //
                    messageType = Strings.Right(invertedHex, 8);

                    /*
                     * These are nested if they verify the type of message that the GPS sends to execute the appropriate code for each one (the types of messages are in the gps protocol)
                     *
                     * The process that is carried out with each one of these messages is the following:
                     *
                     *  1.The hex that is sent via TCP / IP is captured.
                     *  2.It is verified in the GPS protocol in which order the variables come and what size each one occupies in bytes.
                     *  3.A place is created where each of these data is stored, the variable is matched to the corresponding bytes and these are eliminated from the main
                     *  hex and the corresponding data type is parsed.
                     *  4.The data that interests us is saved in the database.
                     *
                     */
                    if (messageType == registerType)
                    {
                        Console.WriteLine("Received HEX: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort);
                        uint uiType = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        uint uiLength = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        ushort uiVersion = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        ushort uiSequeue = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);


                        var header = new s_NV_Message
                        {
                            uiLength  = uiLength,
                            uiType    = uiType,
                            uiVersion = uiVersion,
                            uiSequeue = uiSequeue
                        };


                        String szID = Strings.FromHexLittleEndianToString(invertedHex, 24);
                        invertedHex = Strings.Shorten(invertedHex, 24);
                        DeviceID    = szID;
                        int nNetAdpaterType = int.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        String szModel = Strings.FromHexLittleEndianToString(invertedHex, 48);
                        invertedHex = Strings.Shorten(invertedHex, 48);
                        int nType = int.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        String szSoftware = Strings.FromHexLittleEndianToString(invertedHex, 16);
                        invertedHex = Strings.Shorten(invertedHex, 16);
                        String szHardware = Strings.FromHexLittleEndianToString(invertedHex, 16);
                        invertedHex = Strings.Shorten(invertedHex, 16);

                        var s_NV_Protocol_Device_SignalRegister = new s_NV_Protocol_Device_SignalRegister
                        {
                            header          = header,
                            szID            = szID,
                            nNetAdpaterType = nNetAdpaterType,
                            szModel         = szModel,
                            nType           = nType,
                            szSoftware      = szSoftware,
                            szHardware      = szHardware
                        };
                    }
                    else if (messageType == gpsType)
                    {
                        Console.WriteLine("Received HEX from Device [{3}]: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort, DeviceID);
                        uint uiType = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        uint uiLength = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        ushort uiVersion = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        ushort uiSequeue = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);


                        var header = new s_NV_Message
                        {
                            uiLength  = uiLength,
                            uiType    = uiType,
                            uiVersion = uiVersion,
                            uiSequeue = uiSequeue
                        };

                        string szTimeStamp = Strings.FromHexLittleEndianToString(invertedHex, 16);
                        invertedHex = Strings.Shorten(invertedHex, 16);
                        char usDataType = (char)Int16.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);

                        var gpsHeader = new s_NV_Protocol_Device_GPSHeader
                        {
                            szTimeStamp = szTimeStamp,
                            usDataType  = usDataType
                        };

                        ushort usDirect = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        ushort usSpeed = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        decimal ucLongitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);
                        decimal ucLongitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        ucLongitude_Score /= 60;
                        invertedHex        = Strings.Shorten(invertedHex, 2);
                        decimal ucLatitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);
                        decimal ucLatitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        ucLatitude_Score /= 60;
                        invertedHex       = Strings.Shorten(invertedHex, 2);
                        decimal unLongitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        unLongitude_Second /= 3600;
                        unLongitude_Second /= 10000000;
                        invertedHex         = Strings.Shorten(invertedHex, 8);
                        decimal unLatitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        unLatitude_Second /= 3600;
                        unLatitude_Second /= 10000000;
                        invertedHex        = Strings.Shorten(invertedHex, 8);
                        string ucStatus = Strings.FromHexToBinary(Strings.Right(invertedHex, 2));
                        invertedHex = Strings.Shorten(invertedHex, 2);

                        string north = "1";
                        string west  = "1";

                        decimal latitude  = ucLatitude_degree + ucLatitude_Score + unLatitude_Second;
                        decimal longitude = ucLongitude_degree + ucLongitude_Score + unLongitude_Second;

                        if (ucStatus.Substring(1, 1) != north)
                        {
                            latitude *= -1;
                        }


                        if (ucStatus.Substring(2, 1) == west)
                        {
                            longitude *= -1;
                        }


                        var gpsBaseinfo = new s_NV_Protocol_GPS_BaseInfo
                        {
                            usDirect                 = usDirect,
                            usSpeed                  = usSpeed,
                            ucLongitude_degree       = ucLongitude_degree,
                            ucLongitude_Score        = ucLongitude_Score,
                            ucLatitude_degree        = ucLatitude_degree,
                            ucLatitude_Score         = ucLatitude_Score,
                            unLongitude_Second       = unLongitude_Second,
                            unLatitude_Second        = unLatitude_Second,
                            latitude_decimal_degree  = latitude,
                            longitude_decimal_degree = longitude,
                            ucStatus                 = ucStatus
                        };

                        string ucValid = Strings.FromHexToBinary(Strings.Right(invertedHex, 2));
                        invertedHex = Strings.Shorten(invertedHex, 2);

                        var gpsStatus = new s_NV_Protocol_Device_GPSStatus
                        {
                            ucValid = ucValid
                        };

                        short sAccelate_X = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        short sAccelate_Y = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        short sAccelate_Z = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        short sAccelate_Unit = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);

                        var gSensor = new s_NV_Protocol_GPS_GSensor
                        {
                            sAccelate_X    = sAccelate_X,
                            sAccelate_Y    = sAccelate_Y,
                            sAccelate_Z    = sAccelate_Z,
                            sAccelate_Unit = sAccelate_Unit
                        };

                        short sCorner = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        short sUnit = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);

                        var gyroSensor = new s_NV_Protocol_GPS_GyroSensor
                        {
                            sCorner = sCorner,
                            sUnit   = sUnit
                        };

                        short sHigh = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        short sTemperature = short.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        decimal sOilWear = uint.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier); // Oil consumption //(Actual data received *10)
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        string cSatelliteNumber = Strings.FromHexLittleEndianToString(invertedHex, 2);
                        invertedHex = Strings.Shorten(invertedHex, 2);
                        // string ucReserved = Strings.FromHexLittleEndianToString(invertedHex, 2);
                        invertedHex = Strings.Shorten(invertedHex, 2);

                        var gpsExternInfo = new s_NV_Protocol_GPS_ExternInfoEx
                        {
                            sHigh            = sHigh,
                            sTemperature     = sTemperature,
                            sOilWear         = (sOilWear * 10),// Oil consumption //(Actual data received *10)
                            cSatelliteNumber = cSatelliteNumber,
                            // ucReserved = ucReserved
                        };

                        devices devices = new devices
                        {
                            attributes = "{Tank:{" + gpsExternInfo.sOilWear + "}}"
                        };



                        uint usYear = uint.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);     //year
                        uint ucMonth = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);     //month
                        uint ucDay = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);     //day(1~31)
                        uint ucHour = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);     //hour(0~23)
                        uint ucMinute = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);     //minute(0~59)
                        uint ucSecond = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);     //second(0~59)
                                                                           // uint uReserved= uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);     //reserve

                        var gpsTimeInfo = new s_NV_Protocol_GPS_TimeInfo
                        {
                            usYear   = usYear,
                            ucMonth  = ucMonth,
                            ucDay    = ucDay,
                            ucHour   = ucHour,
                            ucMinute = ucMinute,
                            ucSecond = ucSecond,
                            // ucReserved=uReserved
                        };

                        var gpsData = new GPSData
                        {
                            gpsHeader    = gpsHeader,
                            gpsStatus    = gpsStatus,
                            gSensor      = gSensor,
                            gyroSensor   = gyroSensor,
                            baseInfo     = gpsBaseinfo,
                            externInfoEx = gpsExternInfo,
                            timeInfo     = gpsTimeInfo,
                            header       = header
                        };

                        var devices_id = (from dev in db.devices
                                          where dev.uniqueid == DeviceID
                                          select dev.id).First();


                        positions positions = new positions
                        {
                            deviceid   = devices_id,
                            servertime = DateTime.Now,
                            devicetime = DateTime.ParseExact(gpsTimeInfo.ucDay.ToString() + "-" + gpsTimeInfo.ucMonth.ToString() + "-" + gpsTimeInfo.usYear.ToString()
                                                             + " " + gpsTimeInfo.ucHour.ToString() + ":" + gpsTimeInfo.ucMinute.ToString() + ":" + gpsTimeInfo.ucSecond.ToString(),
                                                             "d-M-yyyy H:m:s",
                                                             System.Globalization.CultureInfo.InvariantCulture),
                            fixtime   = DateTime.Now,
                            latitude  = decimal.ToDouble(gpsBaseinfo.latitude_decimal_degree),
                            longitude = decimal.ToDouble(gpsBaseinfo.longitude_decimal_degree),
                            speed     = gpsBaseinfo.usSpeed,
                            protocol  = "sodimax-mdvr",
                            altitude  = 0,
                            valid     = true,
                            course    = 0,
                            accuracy  = 0,
                            address   = "",
                            network   = ""
                        };

                        db.positions.Add(positions);
                        db.SaveChanges();
                    }
                    else if (messageType == counterType)
                    {
                        Console.WriteLine("Received HEX from Device [{3}]: [ {1}:{2} ] {0} ", invertedHex, remoteAddress, remotePort, DeviceID);
                        uint uiType = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        uint uiLength = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 8);
                        ushort uiVersion = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        ushort uiSequeue = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);


                        var header = new s_NV_Message
                        {
                            uiLength  = uiLength,
                            uiType    = uiType,
                            uiVersion = uiVersion,
                            uiSequeue = uiSequeue
                        };


                        uint usYear = uint.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);         //year
                        uint ucMonth = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);         //month
                        uint ucDay = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);         //day(1~31)
                        uint ucHour = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);         //hour(0~23)
                        uint ucMinute = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);         //minute(0~59)
                        uint ucSecond = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);         //second(0~59)
                                                                               // uint uReserved= uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                                                                               //invertedHex = Strings.Shorten(invertedHex, 2);     //reserve

                        var gpsTimeInfo = new s_NV_Protocol_GPS_TimeInfo
                        {
                            usYear   = usYear,
                            ucMonth  = ucMonth,
                            ucDay    = ucDay,
                            ucHour   = ucHour,
                            ucMinute = ucMinute,
                            ucSecond = ucSecond,
                            // ucReserved=uReserved
                        };

                        DateTime counterDate = DateTime.ParseExact(gpsTimeInfo.ucDay.ToString() + "-" + gpsTimeInfo.ucMonth.ToString() + "-" + gpsTimeInfo.usYear.ToString()
                                                                   + " " + gpsTimeInfo.ucHour.ToString() + ":" + gpsTimeInfo.ucMinute.ToString() + ":" + gpsTimeInfo.ucSecond.ToString(),
                                                                   "d-M-yyyy H:m:s",
                                                                   System.Globalization.CultureInfo.InvariantCulture);

                        string mesType = Strings.FromHexToBinary(Strings.Right(invertedHex, 8));
                        invertedHex = Strings.Shorten(invertedHex, 8);

                        var MesType = new MesType()
                        {
                            mesType = mesType
                        };

                        ushort usDirect = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);
                        ushort usSpeed = ushort.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);
                        decimal ucLongitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);
                        decimal ucLongitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        ucLongitude_Score /= 60;
                        invertedHex        = Strings.Shorten(invertedHex, 2);
                        decimal ucLatitude_degree = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 2);
                        decimal ucLatitude_Score = uint.Parse(Strings.Right(invertedHex, 2), NumberStyles.AllowHexSpecifier);
                        ucLatitude_Score /= 60;
                        invertedHex       = Strings.Shorten(invertedHex, 2);
                        decimal unLongitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        unLongitude_Second /= 3600;
                        unLongitude_Second /= 10000000;
                        invertedHex         = Strings.Shorten(invertedHex, 8);
                        decimal unLatitude_Second = uint.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        unLatitude_Second /= 3600;
                        unLatitude_Second /= 10000000;
                        invertedHex        = Strings.Shorten(invertedHex, 8);
                        string ucStatus = Strings.FromHexToBinary(Strings.Right(invertedHex, 2));
                        invertedHex = Strings.Shorten(invertedHex, 2);

                        string north = "1";
                        string west  = "1";

                        decimal latitude  = ucLatitude_degree + ucLatitude_Score + unLatitude_Second;
                        decimal longitude = ucLongitude_degree + ucLongitude_Score + unLongitude_Second;

                        if (ucStatus.Substring(1, 1) != north)
                        {
                            latitude *= -1;
                        }


                        if (ucStatus.Substring(2, 1) == west)
                        {
                            longitude *= -1;
                        }

                        //invertedHex = Strings.Shorten(invertedHex, 6); //3 bytes de reserva

                        var gpsBaseinfo = new s_NV_Protocol_GPS_BaseInfo
                        {
                            usDirect                 = usDirect,
                            usSpeed                  = usSpeed,
                            ucLongitude_degree       = ucLongitude_degree,
                            ucLongitude_Score        = ucLongitude_Score,
                            ucLatitude_degree        = ucLatitude_degree,
                            ucLatitude_Score         = ucLatitude_Score,
                            unLongitude_Second       = unLongitude_Second,
                            unLatitude_Second        = unLatitude_Second,
                            latitude_decimal_degree  = latitude,
                            longitude_decimal_degree = longitude,
                            ucStatus                 = ucStatus
                        };

                        ushort ucfIn = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);          // Number of passengers on board
                        ushort ucfOut = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);          //  The number of passengers getting off
                        ushort ucbIn = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);          // The total number of passengers on board
                        ushort ucbOut = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);          //The total number of passengers getting off
                        ushort ucnCunt = ushort.Parse(Strings.Right(invertedHex, 4), NumberStyles.AllowHexSpecifier);
                        invertedHex = Strings.Shorten(invertedHex, 4);          //Current total number of passengers on //board
                                                                                // string ucReserved = Strings.FromHexToBinary(Strings.Right(invertedHex, 4));
                                                                                // invertedHex = Strings.Shorten(invertedHex, 4);      // reserve
                        ucnum = int.Parse(Strings.Right(invertedHex, 8), NumberStyles.AllowHexSpecifier);
                        num   = Strings.FromHex(Strings.Right(invertedHex, 8)); //Parsing hex to byte to response to the device

                        invertedHex = Strings.Shorten(invertedHex, 8);          //  identifier—-- The server needs to return this number //to the device by response,if this number is 1, it is void data ,do not need response


                        var peopleCount = new s_NV_PeopleCount()
                        {
                            ucbIn   = ucfOut,                   // How many people entered Up-in down-out
                            ucbOut  = ucbOut,
                            ucfIn   = (ushort)(ucfOut - ucbIn), // How many people are there
                            ucfOut  = ucbIn,                    // How many people went up-in down-out
                            ucnCunt = ucnCunt,
                            ucnum   = ucnum,                    // Number to send
                                                                // ucReserved = ucReserved
                        };

                        var devices_id = (from dev in db.devices
                                          where dev.uniqueid == DeviceID
                                          select dev.id).First();

                        var route_id = (from dev in db.devices
                                        where dev.uniqueid == DeviceID
                                        select dev.routeId).First();



                        int lastPassengerIn = (from counter in db.passenger_counters
                                               orderby counter.servertime descending
                                               select counter.totalPassengerIn).First();

                        int lastPassengerOut = (from counter in db.passenger_counters
                                                orderby counter.servertime descending
                                                select counter.totalPassengerOut).First();

                        int invalidData = 1;

                        if (ucnum != invalidData && (peopleCount.ucbIn != lastPassengerIn || peopleCount.ucfOut != lastPassengerOut))
                        {
                            passenger_counters passenger_Counters = new passenger_counters
                            {
                                deviceid           = devices_id,
                                servertime         = DateTime.Now,
                                devicetime         = counterDate,
                                totalPassengerIn   = peopleCount.ucbIn,
                                totalPassengerOut  = peopleCount.ucfOut,
                                currentPassengerIn = peopleCount.ucfIn,
                                routeid            = (int)route_id
                                                     //currentPassengerIn= ucfIn
                            };



                            db.passenger_counters.Add(passenger_Counters);
                            db.SaveChanges();
                        }
                    }



                    stream.Flush();
                    //  Thread.Sleep(10000);
                }
            }
            catch (SocketException ex)
            {
                //If an error occur the client connection will close
                Console.WriteLine("Error!\n" + ex.Message + "\nClosing connection...");
                client.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error!\n" + ex.Message + "\n" + ex.StackTrace);
                client.Close();
            }
        }
Пример #15
0
    /// <summary>
    /// Update is called every frame.
    /// For SteamVR plugin this is where the device Index is set up.
    /// For Oculus plugin this is where the tracking is done.
    /// </summary>
    void Update()
    {
#if ZED_OCULUS
        //Check if the VR headset is connected.
        if (OVRManager.isHmdPresent && loadedDevice == "Oculus")
        {
            if (OVRInput.GetConnectedControllers().ToString() == "Touch")
            {
                //Depending on which tracked device we are looking for, start tracking it.
                if (deviceToTrack == devices.LeftController) //Track the Left Oculus Controller.
                {
                    RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch));
                }
                if (deviceToTrack == devices.RightController) //Track the Right Oculus Controller.
                {
                    RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch));
                }

                if (deviceToTrack == devices.Hmd) //Track the Oculus Hmd.
                {
                    RegisterPosition(1, UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye), UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye));
                }

                //Taking our saved positions, and applying a delay before assigning it to our Transform.
                if (poseData.Count > 0)
                {
                    sl.Pose p;
                    //Delaying the saved values inside GetValuePosition() by a factor of latencyCompensation to the millisecond.
                    p = GetValuePosition(1, (float)(_latencyCompensation / 1000.0f));
                    transform.position = p.translation; //Assign new delayed Position
                    transform.rotation = p.rotation;    //Assign new delayed Rotation.
                }
            }
        }
        //Enabling the updates of the internal state of OVRInput.
        OVRInput.Update();
#endif
#if ZED_STEAM_VR
        //Timer for checking on devices
        timerVive += Time.deltaTime;

        if (timerVive <= timerMaxVive)
        {
            return;
        }

        timerVive = 0f;

        //Checks if a device has been assigned
        if (index == EIndex.None && loadedDevice == "OpenVR")
        {
            if (BIsManufacturerController("HTC") || BIsManufacturerController("Oculus"))
            {
                //We look for any device that has "tracker" in its 3D model mesh name.
                //We're doing this since the device ID changes based on how many devices are connected to Steam VR.
                //This way if there's no controllers or just one, it's going to get the right ID for the Tracker.
                if (deviceToTrack == devices.ViveTracker)
                {
                    var error = ETrackedPropertyError.TrackedProp_Success;
                    for (uint i = 0; i < 16; i++)
                    {
                        var result = new System.Text.StringBuilder((int)64);
                        OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error);
                        if (result.ToString().Contains("tracker"))
                        {
                            index = (EIndex)i;
                            break; //We break out of the loop, but we can use this to set up multiple Vive Trackers if we want to.
                        }
                    }
                }

                //Looks for a device with the role of a Right Hand.
                if (deviceToTrack == devices.RightController)
                {
                    index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);
                }
                //Looks for a device with the role of a Left Hand.
                if (deviceToTrack == devices.LeftController)
                {
                    index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
                }

                //Assigns the Hmd
                if (deviceToTrack == devices.Hmd)
                {
                    index = EIndex.Hmd;
                }
            }

            //Display Warning if there was supposed to be a calibration file, and none was found.
            if (SNHolder.Equals("NONE"))
            {
                Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_NOT_FOUND));
            }
            else if (SNHolder != null && index != EIndex.None)
            {
                //If the Serial number of the Calibrated device isn't the same as the current tracked device by this script...
                if (!SteamVR.instance.GetStringProperty(Valve.VR.ETrackedDeviceProperty.Prop_SerialNumber_String, (uint)index).Contains(SNHolder))
                {
                    Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_MISMATCH) + SNHolder);
                    //... then look for that device through all the connected devices.
                    for (int i = 0; i < 16; i++)
                    {
                        //If a device with the same Serial Number is found, then change the device to track of this script.
                        if (SteamVR.instance.GetStringProperty(Valve.VR.ETrackedDeviceProperty.Prop_SerialNumber_String, (uint)i).Contains(SNHolder))
                        {
                            index = (EIndex)i;
                            string deviceRole = OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)index).ToString();
                            if (deviceRole.Equals("RightHand"))
                            {
                                deviceToTrack = devices.RightController;
                            }
                            else if (deviceRole.Equals("LeftHand"))
                            {
                                deviceToTrack = devices.LeftController;
                            }
                            else if (deviceRole.Equals("Invalid"))
                            {
                                var error  = ETrackedPropertyError.TrackedProp_Success;
                                var result = new System.Text.StringBuilder((int)64);
                                OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error);
                                if (result.ToString().Contains("tracker"))
                                {
                                    deviceToTrack = devices.ViveTracker;
                                }
                            }
                            Debug.Log("A connected device with the correct Serial Number was found, and assigned to " + this + " the correct device to track.");
                            break;
                        }
                    }
                }
            }
            oldDevice = deviceToTrack;
        }

        if (deviceToTrack != oldDevice)
        {
            index = EIndex.None;
        }
#endif
    }
Пример #16
0
        public BaseTran <devices> GetDeviceList(string types, string code, string name)
        {
            BaseTran <devices> send = new BaseTran <devices>();
            List <devices>     lst  = new List <devices>();

            string[] type = null;
            Dictionary <int, int> dictKey = new Dictionary <int, int>();
            Dictionary <int, int> dictCom = new Dictionary <int, int>();

            int[] ntype = null;

            if (types != null)
            {
                type  = types.Split(',');
                ntype = new int[type.Length];
                foreach (string t in type)
                {
                    int nt = Convert.ToInt32(t);
                    if (dict3.ContainsKey(nt))
                    {
                        List <int> val = dict3[nt];
                        foreach (int i in val)
                        {
                            if (!dictKey.ContainsKey(i))
                            {
                                dictKey.Add(i, i);
                            }
                        }
                    }
                }

                foreach (var item in dictKey)
                {
                    if (dict3.ContainsKey(item.Key))
                    {
                        List <int> val = dict3[item.Key];
                        foreach (int i in val)
                        {
                            if (!dictCom.ContainsKey(i))
                            {
                                dictCom.Add(i, i);
                            }
                        }
                    }
                }
            }

            foreach (var item in dict)
            {
                devices dev1 = item.Value.Clone();
                devices dev2 = null;

                if (dictCom.ContainsKey(dev1.type))
                {
                    dev2 = dev1.Clone();
                }

                if (code != null)
                {
                    if (code == dev1.code)
                    {
                        dev2 = dev1.Clone();
                    }
                    else
                    {
                        dev2 = null;
                    }
                }


                if (name != null)
                {
                    if (name == dev1.name)
                    {
                        dev2 = dev1.Clone();
                    }
                    else
                    {
                        dev2 = null;
                    }
                }

                if (dev2 != null)
                {
                    lst.Add(dev2);
                }
            }


            send.total = lst.Count;
            send.msg   = "ok";
            send.data  = lst;

            return(send);
        }