Exemple #1
0
        protected internal virtual async Task updateFromWpAndYp(List <WPEntry> whitePages, Dictionary <string, List <YPEntry> > yellowPages)
        {
            // by default consider all known device as unplugged
            List <YDevice> toRemove = new List <YDevice>(_devices.Values);

            foreach (WPEntry wp in whitePages)
            {
                string serial = wp.SerialNumber;
                if (_devices.ContainsKey(serial))
                {
                    // already there
                    YDevice currdev = _devices[serial];
                    if (!currdev.imm_getLogicalName().Equals(wp.LogicalName))
                    {
                        // Reindex device from its own data
                        await currdev.refresh();

                        _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.CHANGE, serial);
                    }
                    else if (currdev.imm_getBeacon() > 0 != wp.Beacon > 0)
                    {
                        await currdev.refresh();
                    }

                    toRemove.Remove(currdev);
                }
                else
                {
                    YDevice dev = new YDevice(this, wp, yellowPages);
                    _yctx._yHash.imm_reindexDevice(dev);
                    _devices[serial] = dev;
                    _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.PLUG, serial);
                    _yctx._Log("HUB: device " + serial + " has been plugged\n");
                }
            }

            foreach (YDevice dev in toRemove)
            {
                string serial = dev.imm_getSerialNumber();
                _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.UNPLUG, serial);
                _yctx._Log("HUB: device " + serial + " has been unplugged\n");
                _devices.Remove(serial);
            }

            if (_hubSerialNumber == null)
            {
                foreach (WPEntry wp in whitePages)
                {
                    if (wp.NetworkUrl.Equals(""))
                    {
                        _hubSerialNumber = wp.SerialNumber;
                    }
                }
            }

            _yctx._yHash.imm_reindexYellowPages(yellowPages);
        }
Exemple #2
0
        // check procol version compatibility
        // compatible without limitation -> return 1
        // compatible with limitations -> return 0;
        // incompatible -> return YAPI_IO_ERROR
        private int imm_CheckVersionCompatibility(uint version)
        {
            // fixme: throw exception instead of logging error
            if ((version & 0xff00) != (YUSBPkt.YPKT_USB_VERSION_BCD & 0xff00))
            {
                // major version change
                if ((version & 0xff00) > (YUSBPkt.YPKT_USB_VERSION_BCD & 0xff00))
                {
                    String error = String.Format("Yoctpuce library is too old (using 0x%x, need 0x%x) to handle device, please upgrade your Yoctopuce library", YUSBPkt.YPKT_USB_VERSION_BCD, version);
                    _yctx._Log(error + "\n");
                    throw new YAPI_Exception(YAPI.VERSION_MISMATCH, error);
                }
                else
                {
                    // implement backward compatibility when implementing a new protocol
                    return(1);
                }
            }
            else if (version != YUSBPkt.YPKT_USB_VERSION_BCD)
            {
                if (_devVersion == YUSBPkt.YPKT_USB_VERSION_NO_CONFCHG_BCD && YUSBPkt.YPKT_USB_VERSION_BCD == _devVersion + 1)
                {
                    return(0);
                }
                if (version > YUSBPkt.YPKT_USB_VERSION_BCD)
                {
                    _yctx._Log("Device is using a newer protocol, consider upgrading your Yoctopuce library\n");
                }
                else
                {
                    _yctx._Log("Device is using an older protocol, consider upgrading the device firmware\n");
                }

                return(0);
            }
            else
            {
                return(1);
            }
        }
        /// <summary>
        /// Returns a list of all the modules in "firmware update" mode. Only devices
        /// connected over USB are listed. For devices connected to a YoctoHub, you
        /// must connect to the YoctoHub web interface.
        /// </summary>
        /// <param name="yctx"> : a YAPI context.
        /// </param>
        /// <returns> an array of strings containing the serial numbers of devices in "firmware update" mode. </returns>
        public static async Task <List <string> > GetAllBootLoadersInContext(YAPIContext yctx)
        {
            List <string> res = new List <string>();

            foreach (YGenericHub h in yctx._hubs)
            {
                try {
                    List <string> bootloaders;
                    bootloaders = await h.getBootloaders();

                    if (bootloaders != null)
                    {
                        res.AddRange(bootloaders);
                    }
                } catch (YAPI_Exception e) {
                    yctx._Log(e.Message);
                }
            }
            return(res);
        }