Beispiel #1
0
 public int SaveMessage(Mt90Message message)
 {
     using (var conn = new SqlConnection(_connectionString))
     {
         conn.Open();
         var result = conn.Query <int>(@"Mt90AddMessage",
                                       new
         {
             Protocol = 1,
             message.DataIdentifier,
             message.DataLength,
             message.CommandType,
             message.Imei,
             message.EventCode,
             message.Latitude,
             message.Longitude,
             message.DateAndTime,
             message.PositioningStatus,
             message.NumberOfSatellites,
             message.GsmSignalStrength,
             message.Speed,
             message.Direction,
             message.HorizontalPositioningAccuracy,
             message.Altitude,
             message.Mileage,
             message.RunTime,
             message.BaseStationInfo,
             message.IOPortStatus,
             message.AnalogInputValue,
             message.Ip,
             message.Battery,
         }, commandType: CommandType.StoredProcedure).FirstOrDefault();
         return(result);
     }
 }
Beispiel #2
0
        public Mt90Message GetMt90Message(string s)
        {
            var message = new Mt90Message();

            //"$$B145,863158020721157,AAA,35,52.691971,25.372790,150204170317,V,0,8,0,0,0.0,0,7067,150931,257|1|00FE|066A,0000,0000|0000|0000|09E9|0000,00000001,*"
            if (!String.IsNullOrEmpty(s) && s.IndexOf(',') > -1)
            {
                var messageArr = s.Split(',');
                if (messageArr.Length > 3 && messageArr[0].StartsWith("$$"))
                {
                    var message0 = messageArr[0].Remove(0, 2);
                    message.DataIdentifier = message0.Remove(1);
                    message.DataLength     = Convert.ToInt32(message0.Remove(0, 1));
                    message.Imei           = messageArr[1];
                    message.CommandType    = messageArr[2];



                    if (message.CommandType == "AAA")
                    {
                        message.EventCode = messageArr[3];
                        message.Latitude  = messageArr[4];
                        message.Longitude = messageArr[5];


                        string formatString = "yy''MM''dd''HH''mm''ss";
                        string sampleData   = messageArr[6];;
                        message.DateAndTime = DateTime.ParseExact(sampleData, formatString, null);

                        message.PositioningStatus  = messageArr[7];
                        message.NumberOfSatellites = Convert.ToInt32(messageArr[8]);
                        message.GsmSignalStrength  = Convert.ToInt32(messageArr[9]);
                        message.Speed     = messageArr[10];
                        message.Direction = Convert.ToInt32(messageArr[11]);
                        message.HorizontalPositioningAccuracy = messageArr[12];
                        message.Altitude         = messageArr[13];
                        message.Mileage          = messageArr[14];
                        message.RunTime          = messageArr[15];
                        message.BaseStationInfo  = messageArr[16];
                        message.IOPortStatus     = messageArr[17];
                        message.AnalogInputValue = messageArr[18];

                        var batteryHex = messageArr[18].Split('|')[3];
                        var voltage    = int.Parse(batteryHex, System.Globalization.NumberStyles.HexNumber);;
                        var battery    = ((voltage - 2114) * 100) / 492;
                        message.Battery = battery;
                    }
                    else
                    {
                    }
                }
            }



            return(message);
        }