Пример #1
0
        // Reindex a device in YAPI after a name change detected by device refresh
        internal virtual void imm_reindexDevice(YDevice dev)
        {
            string serial = dev.imm_getSerialNumber();
            string lname  = dev.imm_getLogicalName();

            _devs[serial] = dev;

            if (!lname.Equals(""))
            {
                _snByName[lname] = serial;
            }

            YFunctionType module        = _fnByType["Module"];
            YPEntry       moduleYPEntry = dev.ModuleYPEntry;

            module.imm_reindexFunction(moduleYPEntry);
            int count = dev.imm_functionCount();

            for (int i = 0; i < count; i++)
            {
                YPEntry       yp        = dev.imm_getYPEntryFromOfs(i);
                string        classname = yp.Classname;
                YFunctionType functionType;
                if (_fnByType.ContainsKey(classname))
                {
                    functionType = _fnByType[classname];
                }
                else
                {
                    functionType         = new YFunctionType(classname, _yctx);
                    _fnByType[classname] = functionType;
                }
                functionType.imm_reindexFunction(yp);
            }
        }
Пример #2
0
        internal override async Task <byte[]> devRequestSync(YDevice device, string req_first_line, byte[] req_head_and_body, RequestProgress progress, object context)
        {
            String serial = device.imm_getSerialNumber();

            byte[] req = imm_prepareRequest(req_first_line, req_head_and_body);
            return(await _ywatcher.DevRequestSync(serial, req, progress, context));
        }
Пример #3
0
        internal override async Task devRequestAsync(YDevice device, string req_first_line, byte[] req_head_and_body, RequestAsyncResult asyncResult, object asyncContext)
        {
            String serial = device.imm_getSerialNumber();

            byte[] req = imm_prepareRequest(req_first_line, req_head_and_body);
            await _ywatcher.DevRequestAsync(serial, req, asyncResult, asyncContext);

            //Debug.WriteLine("async req to " + serial + " " + req_first_line);
        }
Пример #4
0
        internal override async Task devRequestAsync(YDevice device, string req_first_line, byte[] req_head_and_body, YGenericHub.RequestAsyncResult asyncResult, object asyncContext)
        {
            ulong start = YAPI.GetTickCount();

            if (!_httpReqByDev.ContainsKey(device))
            {
                _httpReqByDev[device] = new YHTTPRequest(_hub, "Device " + device.imm_getSerialNumber());
            }

            YHTTPRequest req = _httpReqByDev[device];
            await req.RequestAsync(req_first_line, req_head_and_body, asyncResult, asyncContext);

            ulong stop = YAPI.GetTickCount();
            //Debug.WriteLine(string.Format("ASyncRes on {0} took {1}ms", device.SerialNumber, stop - start));
        }
Пример #5
0
        // Find the exact Hardware Id of the specified function, if currently connected
        // If device is not known as connected, return a clean error
        // This function will not cause any network access
        public virtual HWID imm_resolve(string func)
        {
            // Try to resolve str_func to a known Function instance, if possible, without any device access
            int dotpos = func.IndexOf('.');

            if (dotpos < 0)
            {
                // First case: func is the logical name of a function
                if (_hwIdByName.ContainsKey(func))
                {
                    string hwid_str = _hwIdByName[func];
                    return(new HWID(hwid_str));
                }

                // fallback to assuming that func is a logical name or serial number of a module
                // with an implicit function name (like serial.module for instance)
                func += string.Format(".{0}{1}", char.ToLower(_className[0]), _className.Substring(1));
            }

            // Second case: func is in the form: device_id.function_id
            HWID hwid = new HWID(func);

            // quick lookup for a known pure hardware id
            if (_ypEntries.ContainsKey(hwid.ToString()))
            {
                return(hwid);
            }

            if (hwid.module.Length > 0)
            {
                // either the device id is a logical name, or the function is unknown
                YDevice dev = _yctx._yHash.imm_getDevice(hwid.module);
                if (dev == null)
                {
                    throw new YAPI_Exception(YAPI.DEVICE_NOT_FOUND, "Device [" + hwid.module + "] not online");
                }
                string serial = dev.imm_getSerialNumber();
                hwid = new HWID(serial, hwid.Function);
                if (_ypEntries.ContainsKey(hwid.ToString()))
                {
                    return(hwid);
                }
                // not found neither, may be funcid is a function logicalname
                int nfun = dev.imm_functionCount();
                for (int i = 0; i < nfun; i++)
                {
                    YPEntry yp = dev.imm_getYPEntryFromOfs(i);
                    if (yp.LogicalName.Equals(hwid.Function) && _ypEntries.ContainsValue(yp))
                    {
                        return(new HWID(serial, yp.FuncId));
                    }
                }
            }
            else
            {
                // only functionId  (ie ".temperature")
                foreach (string hwid_str in _connectedFns.Keys)
                {
                    HWID tmpid = new HWID(hwid_str);
                    if (tmpid.Function.Equals(hwid.Function))
                    {
                        return(tmpid);
                    }
                }
            }
            throw new YAPI_Exception(YAPI.DEVICE_NOT_FOUND, "No function [" + hwid.function + "] found on device [" + hwid.module + "]");
        }