コード例 #1
0
ファイル: VehicleEventHub.cs プロジェクト: movia/rps_webapp
        public void VehiclePosition(VehiclePositionEvent vehiclePositionEvent)
        {
            clientManager.ConnectedIds.Add(Context.ConnectionId);
            var config = clientManager.GetConfiguration(Context.ConnectionId);

            vehiclePositionEvent.Source = Context.ConnectionId;
            vehiclePositionEvent.Target = config["endpointAddress"];
            vehicleEventQueue.Enqueue(vehiclePositionEvent);
        }
コード例 #2
0
ファイル: MessageConverter.cs プロジェクト: movia/rps_webapp
        public byte[] VehiclePositionReport(VehiclePositionEvent vehiclePositionEvent)
        {
            using (var stream = new MemoryStream())
            using (var writer = new BinaryWriter(stream))
            {
                writer.Write((byte)2);
                writer.Write((byte)127);

                var deviceId = config.Configuration.Get("vehicles:" + vehiclePositionEvent.VehicleId + ":deviceId");
                var deviceIdParts = deviceId.Split('-');

                if (deviceIdParts.Length != 8)
                    throw new FormatException($"Invalid Device Id '{deviceId}'.");

                // 3	2	Yes	Unit identity	Byte(8)	Fixed identity of sending unit	E.g. MAC-address or similar.
                for (var i = 0; i < 8; i++)
                {
                    writer.Write(Convert.ToByte(deviceIdParts[i], 16));
                }

                // 4	10	Yes	Sequence number	UInt16	0-65535	See 4.2.1.
                if (sequenceNumber == ushort.MaxValue)
                    sequenceNumber = 1;

                writer.Write(sequenceNumber++);

                // 5	12	Yes	Timestamp	UInt32	Time of fix.	Milliseconds since UTC midnight.
                writer.Write((UInt32)DateTime.UtcNow.TimeOfDay.TotalMilliseconds);

                // 6	16	Yes	Latitude	Single	-90,00000° - +90,00000°	IEEE 32-bits floating point number with single precision.
                writer.Write((Single)vehiclePositionEvent.Latitude);

                // 7	20	Yes	Longitude	Single	-180,00000° - +180,00000°
                writer.Write((Single)vehiclePositionEvent.Longitude);

                // 8	24	Yes	Speed	UInt16	0,00 – 655.36 m/s	Speed in steps of 0,01 m/s
                writer.Write((UInt16)(vehiclePositionEvent.Speed * 100f));

                // 9	26	Yes	Direction	UInt16	0,00 – 359.99° 	Direction in steps of 0.01°
                writer.Write((UInt16)(vehiclePositionEvent.Direction * 100f));

                // 10	28	Yes	GPS-quality	Byte	Quality for GPS.	See 4.2.6.
                writer.Write((Byte)(0x01 | (0x02 << 4)));

                // 11	29	Some	Signals	Byte	4 signals of 2 bits each	See 4.2.7.
                writer.Write((Byte)((0x03 << 6) | (0x00 << 4) | (0x00 << 2) | (0x03 << 0)));

                // 12	30	No	Distance	UInt32	Vehicle distance in steps of 5 meters	See 4.2.8
                writer.Write((UInt32)0);

                var vehicleId = Encoding.ASCII.GetBytes(vehiclePositionEvent.VehicleId);
                // L13	34	Yes	Length of field 13	Byte	0-255	Number of bytes.
                writer.Write((Byte)vehicleId.Length);

                // 13		Yes	Vehicle id	String	Identity of vehicle.	Must be a vehicle fixed unique value, e.g. BUS FMS VI field.
                writer.Write(vehicleId);

                // L14		No	Length of field 14	Byte	0-255	Number of bytes.
                writer.Write((Byte)0);

                // 14		No	Driver id	String	Identity of current driver.	Optional. Could be BUS FMS DI, or unique id from other available source in vehicle.
                //writer.Write();

                var serviceJourneyId = Encoding.ASCII.GetBytes(VehicleAssignmentManager.Instance.GetJourneyId(vehiclePositionEvent.VehicleId) ?? string.Empty);
                // L15		Yes	Length of field 15	Byte	0-255	Number of bytes.
                writer.Write((Byte)serviceJourneyId.Length);

                // 15		Yes	Service Journey Id	String	See 4.2.11.
                writer.Write(serviceJourneyId);

                // L16		No	Length of field 16	Byte	0-255	Number of bytes.
                writer.Write((Byte)0);

                // 16		No	Account Id	String	Identity of operator.	Optional.

                return stream.ToArray();
            }
        }