示例#1
0
        private string ProcessWriteDataRequest(Request.WriteDataRequest writeData)
        {
            if (!_devices.ContainsKey(writeData.Id))
            {
                Logger.Logger.Log("WriteDataRequest on unknown device {0}", writeData.Id);
                return("");
            }

            OneWireAdapter.beginExclusive(true);
            DoWriteDeviceData(writeData);
            OneWireAdapter.endExclusive();

            return(JsonConvert.SerializeObject(new WriteAckAnswer {
                Ack = true
            }));
        }
示例#2
0
        private void DoWriteDeviceData(Request.WriteDataRequest writeData)
        {
            var device = OneWireAdapter.getDeviceContainer(_devices[writeData.Id].FullId);

            if (!device.isPresent())
            {
                Logger.Logger.Log("WriteDataRequest, selected device ({0}) is no longer present", writeData.Id);
                return;
            }

            var switchDevice = device as SwitchContainer;

            if (switchDevice != null)
            {
                var rawData = switchDevice.readDevice();
                if (writeData.Unit >= switchDevice.getNumberChannels(rawData))
                {
                    Logger.Logger.Log("WriteDataRequest, invalid unit number ({0}) for selected device ({1})", writeData.Unit, writeData.Id);
                    return;
                }
                switchDevice.setLatchState((int)writeData.Unit, writeData.Value, false, rawData);
                switchDevice.writeDevice(rawData);
            }
        }