예제 #1
0
        private string ProcessReadChanelsNbRequest(Request.ReadNbChanelsRequest readData)
        {
            if (!_devices.ContainsKey(readData.Id))
            {
                Logger.Logger.Log("ReadChanelsNbRequest on unknown device {0}", readData.Id);
                return(JsonConvert.SerializeObject(new InvalidRequestAnswer {
                    InvalidRequestReason = "UnknownDevice"
                }));
            }

            OneWireAdapter.beginExclusive(true);
            var answer = DoReadDeviceChanelsNb(readData);

            OneWireAdapter.endExclusive();

            return(JsonConvert.SerializeObject(answer));
        }
예제 #2
0
        private object DoReadDeviceChanelsNb(Request.ReadNbChanelsRequest readData)
        {
            var device = OneWireAdapter.getDeviceContainer(_devices[readData.Id].FullId);

            if (!device.isPresent())
            {
                Logger.Logger.Log("ReadChanelsNbRequest, selected device ({0}) is no longer present", readData.Id);
                return(new InvalidRequestAnswer {
                    InvalidRequestReason = "DeviceNotPresent"
                });
            }

            var switchDevice = device as SwitchContainer;

            if (switchDevice != null)
            {
                var rawData = switchDevice.readDevice();
                return(new ReadNbChanelsAnswer {
                    ChanelsNb = switchDevice.getNumberChannels(rawData)
                });
            }

            var adDevice = device as ADContainer;

            if (adDevice != null)
            {
                adDevice.readDevice();
                return(new ReadNbChanelsAnswer {
                    ChanelsNb = adDevice.getNumberADChannels()
                });
            }

            Logger.Logger.Log("ReadDeviceChanelsNb, type {0} for selected device ({1}) is not supported", device.GetType(), readData.Id);
            return(new InvalidRequestAnswer {
                InvalidRequestReason = "TryToReadChanelsNbUnsupportedDevice"
            });
        }