コード例 #1
0
ファイル: A_Diag.cs プロジェクト: nalale/LFService
        private bool addResponse(ResponseData_ReadDataByIdentifier Response)
        {
            if (Response == null || !reqRespPair.ContainsKey(Response.DID))
            {
                return(false);
            }

            reqRespPair.TryUpdate(Response.DID, Response, reqRespPair[(byte)Response.DID]);
            return(true);
        }
コード例 #2
0
ファイル: StartWindow.xaml.cs プロジェクト: nalale/LFService
        private async void SetDateTime()
        {
            List <Diag.ResponseData_ReadDataByIdentifier> response = await Global.EcuList.CurrentEcu.GetEcuTime();

            if (response.Count > 0)
            {
                Diag.ResponseData_ReadDataByIdentifier it = response[0];
                // Найти в списке диагностических значений нужный
                DiagnosticData dv = Global.EcuList.CurrentEcu.GetDiagnosticSets().Find((diag) => diag.DataID == it.DID);
                // Если ЭБУ поддерживает запрашиваемый DID
                if (dv == null)
                {
                    return;
                }


                UInt32   sec      = BitConverter.ToUInt32(it.DV.ToArray(), 0);
                DateTime sys_time = (new DateTime(2000, 1, 1)).AddSeconds(sec);

                tbDateTime.Text = sys_time.ToString();
            }
        }
コード例 #3
0
        async public Task <bool> Download()
        {
            IntPtr ptr;
            int    ProfileSize = Marshal.SizeOf(typeof(Bms_ECU.CodingData_t));

            ptr = Marshal.AllocHGlobal(ProfileSize);
            byte[] buf = await Global.diag.ReadDataByID((byte)Global.EcuList.CurrentEcu.Address, (byte)BmsObjectsIndex_e.didConfigStructIndex);

            Marshal.Copy(buf, 0, ptr, ProfileSize);
            bms.Data = (Bms_ECU.CodingData_t)Marshal.PtrToStructure(ptr, typeof(Bms_ECU.CodingData_t));

            ushort loc_crc = Tools.CRC16(buf, ProfileSize / 4 - 1);

            if (bms.Data.CRC == loc_crc)
            {
                StructToForm();

                if (bms.IsTimeServer)
                {
                    //byte[] data = await Global.diag.ReadDataByID((byte)Global.EcuList.CurrentEcu.Address, (byte)BmsObjectsIndex_e.didDateTime);
                    //UInt32 _boardTime_s = BitConverter.ToUInt32(data, 0);

                    List <Diag.ResponseData_ReadDataByIdentifier> response = await CurrentEcu.GetEcuTime();

                    if (response.Count > 0)
                    {
                        Diag.ResponseData_ReadDataByIdentifier it = response[0];
                        // Найти в списке диагностических значений нужный
                        DiagnosticData dv = Global.EcuList.CurrentEcu.GetDiagnosticSets().Find((diag) => diag.DataID == it.DID);
                        // Если ЭБУ поддерживает запрашиваемый DID
                        if (dv == null)
                        {
                            return(true);
                        }

                        UInt32 _boardTime_s = BitConverter.ToUInt32(it.DV.ToArray(), 0);

                        // Точка отсчета 01.01.2000
                        TimeSpan _sysTime    = DateTime.Now - new DateTime(2000, 1, 1);
                        UInt32   _systemTime = Convert.ToUInt32(_sysTime.TotalSeconds);

                        if ((_boardTime_s < _systemTime - 600) || (_boardTime_s > _systemTime + 600))
                        {
                            MessageBoxResult res = MessageBox.Show("Время устройства отличается от системного времени.\n Установить системное время?", "Системное время", MessageBoxButton.YesNo);

                            if (res == MessageBoxResult.Yes)
                            {
                                byte[] data = BitConverter.GetBytes(_systemTime);
                                await Global.diag.WriteDataByID((byte)Global.EcuList.CurrentEcu.Address, (byte)BmsObjectsIndex_e.didDateTime, data);
                            }
                        }
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }