Exemplo n.º 1
0
        private void UpdateDeviceCatalogue(object stateInfo)
        {
            CANFrame frame = (CANFrame)stateInfo;

            DeviceCatalogueInfo dci = frame.ToDeviceCatalogueInfo();

            if (dci == null)
            {
                return;
            }

            CNXLog.InfoFormat("DeviceCataloge {0}", dci.ToString());
            DeviceCatalogue.CatalogueChangeType catalogeUpdated = mDeviceCatalogue.UpdateDeviceCatalogue(dci);
            if (catalogeUpdated != DeviceCatalogue.CatalogueChangeType.NONE)
            {
                CNXLog.InfoFormat("DeviceCataloge Updating calalogue.");
                if (catalogeUpdated == DeviceCatalogue.CatalogueChangeType.EQUIPMENT)
                {
                    // persist the catalogue
                    PersistCatalogue();
                }

                EquipmentChangedEventArgs a = new EquipmentChangedEventArgs(mDeviceCatalogue.EquipmentMask, mDeviceCatalogue.EquipmentStatus);
                OnRaiseEquipmentChangedEvent(a);
            }
        }
Exemplo n.º 2
0
 private static void ResetDeviceCatalogue(CANCommsServer canServer, DeviceCatalogueInfo.Product prodId, byte ver)
 {
     try
     {
         canServer.DeviceCatalogue.Clear();
         DeviceCatalogueInfo dci = new DeviceCatalogueInfo()
         {
             BuildNo   = ver,
             ProductId = (DeviceCatalogueInfo.Product)mProductCode
         };
         canServer.DeviceCatalogue.UpdateDeviceCatalogue(dci);
         canServer.PersistCatalogue();
     }
     catch (Exception e)
     {
         CNXLog.ErrorFormat("ResetDeviceCatalogue Error : {0}", e.ToString());
     }
 }
Exemplo n.º 3
0
        private void AddSelfToCatalogue()
        {
            try
            {
                DeviceCatalogueInfo dci = mCANServer.DeviceCatalogue.FindDevice((DeviceCatalogueInfo.Product)mProductCode);
                if (dci == null)
                {
                    ResetDeviceCatalogue(mCANServer, (DeviceCatalogueInfo.Product)mProductCode, (byte)mVersion);
                }
                // flush the catalouge on upgrade.
                else if (dci.BuildNo != (byte)mVersion)
                {
                    ResetDeviceCatalogue(mCANServer, (DeviceCatalogueInfo.Product)mProductCode, (byte)mVersion);
                }
            }
            catch (Exception e)
            {
                CNXLog.ErrorFormat("AddSelfToCatalogue Error : {0}", e.ToString());
            }

            CNXLog.WarnFormat("Device Catalogue {0}", mCANServer.DeviceCatalogue.ToString());
        }
Exemplo n.º 4
0
        private void StartFirmwareManagement(byte[] versionData, int startIndex)
        {
            try
            {
                // the vesion data is in id,version pairs
                // test against our cataloge to see if anything needs upgrading.
                for (int i = startIndex; i < versionData.Length; i += 2)
                {
                    // check if there is version information for this module
                    if (versionData[i] == mProductCode)
                    {
                        // it's for us, should we be doing a self upgrade!
                        // allow a 128 window to allow for version wrap round.
                        if (mVersion < versionData[i + 1])
                        {
                            CNXLog.InfoFormat("Doing self upgrade from {0} to {1}.", mVersion, versionData[i + 1]);
                            if (mBootstrapUpgrader == null)
                            {
                                //object[] args = { mRTTServer, Properties.Settings.Default.FirmwarePath, mProductCode, Properties.Settings.Default.FirmwareExtension };
                                object[] args = { mRTTServer, FirmwarePath, mProductCode, FirmwareExtension };
                                //object[] args = { mRTTServer, "", mProductCode, "" };
                                string url = string.Format("http://{0}{1}{2}{3}", args);
                                mBootstrapUpgrader = new BootstrapUpgrader(url);
                                mBootstrapUpgrader.BeginUpgrade();
                            }
                            else if (mBootstrapUpgrader.Status == BootstrapUpgrader.UpgradeState.Idle || mBootstrapUpgrader.Status == BootstrapUpgrader.UpgradeState.UpgradeComplete)
                            {
                                mBootstrapUpgrader.BeginUpgrade();
                            }
                        }
                    }
                    // Product Ids < 0x7f are not CAN upgradable so ignore them
                    if (versionData[i] < 0x7f)
                    {
                        continue;
                    }

                    DeviceCatalogueInfo info = mCANServer.DeviceCatalogue.FindDevice((DeviceCatalogueInfo.Product)versionData[i]);
                    if (info != null)
                    {
                        if (info.BuildNo < versionData[i + 1])
                        {
                            BlockTransferManager txManager = null;
                            // need to organise an upgrade
                            foreach (BlockTransferManager btm in mFirmwareList)
                            {
                                if (btm.BlockId == (byte)info.ProductId)
                                {
                                    txManager        = btm;
                                    btm.BlockVersion = versionData[i + 1];
                                    break;
                                }
                            }
                            if (txManager == null)
                            {
                                //object[] args = { mRTTServer, Properties.Settings.Default.FirmwarePath, versionData[i], Properties.Settings.Default.FirmwareExtension };
                                object[] args = { mRTTServer, FirmwarePath, versionData[i], FirmwareExtension };
                                //object[] args = { mRTTServer, "", versionData[i], "" };
                                string url = string.Format("http://{0}{1}{2}{3}", args);
                                mFirmwareList.Add(new BlockTransferManager(url, versionData[i], versionData[i + 1], mCANClient));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                CNXLog.ErrorFormat("StartFirmwareManagement error {0}", e.ToString());
            }
        }