Exemplo n.º 1
0
        private unsafe int rawListeningFunction(char *data, int controllerId, int callbackId, void *context)
        {
            UnmanagedException ex = null;
            string             data2;

            try
            {
                data2 = AsString(data, false);
            }
            catch (Exception innerException)
            {
                data2 = "error;TelldusAPIError:";
                ex    = new UnmanagedException("GetString failed during callback from Telldus API.", innerException);
            }
            foreach (RawListeningCallbackFunction current in rawListenerList.Values)
            {
                if (context != null)
                {
                    current(data2, controllerId, callbackId, GCHandle.FromIntPtr((IntPtr)context).Target, ex);
                }
                else
                {
                    current(data2, controllerId, callbackId, null, ex);
                }
            }
            return(0);
        }
Exemplo n.º 2
0
        private unsafe int sensorListeningFunction(char *protocol, char *model, int id, int dataType, char *value,
                                                   int timestamp, int callbackId, void *context)
        {
            string             protocol2 = "Invalid data from Telldus API.";
            string             model2    = "Invalid data from Telldus API.";
            string             val       = "Invalid data from Telldus API.";
            UnmanagedException ex        = null;

            try
            {
                protocol2 = AsString(protocol, false);
                model2    = AsString(model, false);
                val       = AsString(value, false);
            }
            catch (Exception innerException)
            {
                ex = new UnmanagedException("GetString failed during callback from Telldus API.", innerException);
            }
            foreach (SensorCallbackFunction current in sensorListenerList.Values)
            {
                if (context != null)
                {
                    current(protocol2, model2, id, dataType, val, timestamp, callbackId, GCHandle.FromIntPtr((IntPtr)context).Target,
                            ex);
                }
                else
                {
                    current(protocol2, model2, id, dataType, val, timestamp, callbackId, null, ex);
                }
            }
            return(0);
        }
Exemplo n.º 3
0
        //Helpers
        private unsafe int eventFunction(int deviceId, int method, char *data, int callbackId, void *context)
        {
            string             data2 = "Invalid data from Telldus API.";
            UnmanagedException ex    = null;

            try
            {
                data2 = AsString(data, false);
            }
            catch (Exception innerException)
            {
                ex = new UnmanagedException("GetString failed during callback from Telldus API.", innerException);
            }
            foreach (EventCallbackFunction current in eventList.Values)
            {
                if (context != null)
                {
                    current(deviceId, method, data2, callbackId, GCHandle.FromIntPtr((IntPtr)context).Target, ex);
                }
                else
                {
                    current(deviceId, method, data2, callbackId, null, ex);
                }
            }
            return(0);
        }
        private int SensorUpdated(
            string protocol, string model, int id, int dataType, string val, int timestamp, int callbackId, object obj,
            UnmanagedException ex)
        {
            Console.WriteLine("TS: " + protocol + ", " + model + ", " + id + ", " + dataType + ", " + val + ", " + timestamp + ", " + callbackId);
            var module = interfaceModules.FirstOrDefault(i => i.Address == id.ToString());
            if (module == null)
            {

                module = new InterfaceModule
                {
                    Domain = Domain,
                    Address = id.ToString(),
                    Description = model + " - " + protocol,
                    ModuleType = ModuleTypes.Sensor
                };
                interfaceModules.Add(module);

                OnInterfaceModulesChanged(this.GetDomain());
            }

            var path = ModuleEvents.Status_Level;
            if (dataType == (int)TelldusLib.DataType.TEMPERATURE)
                path = ModuleEvents.Sensor_Temperature;
            else if (dataType == (int)TelldusLib.DataType.HUMIDITY)
                path = ModuleEvents.Sensor_Humidity;

            OnInterfacePropertyChanged(this.GetDomain(), module.Address, Event_Sensor_Description, path, val);

            return 1;
        }
        private int OnDeviceUpdated(int deviceId, int method, string data, int callbackId, object obj, UnmanagedException ex)
        {
            var path = ModuleEvents.Status_Level;
            int value = 0;
            if (method == (int)TelldusLib.Command.TURNON)
            {
                path = ModuleEvents.Status_Level;
                value = 1;
            }
            else if (method == (int)TelldusLib.Command.TURNOFF)
            {
                path = ModuleEvents.Status_Level;
                value = 0;
            }

            var module = interfaceModules.FirstOrDefault(i => i.Address == deviceId.ToString());

            OnInterfacePropertyChanged(this.GetDomain(), module.Address, Event_Sensor_Description, path, value);

            return 1;
        }
Exemplo n.º 6
0
		private unsafe int sensorListeningFunction(char* protocol, char* model, int id, int dataType, char* value,
			int timestamp, int callbackId, void* context)
		{
			string protocol2 = "Invalid data from Telldus API.";
			string model2 = "Invalid data from Telldus API.";
			string val = "Invalid data from Telldus API.";
			UnmanagedException ex = null;
			try
			{
				protocol2 = AsString(protocol, false);
				model2 = AsString(model, false);
				val = AsString(value, false);
			}
			catch (Exception innerException)
			{
				ex = new UnmanagedException("GetString failed during callback from Telldus API.", innerException);
			}
			foreach (SensorCallbackFunction current in sensorListenerList.Values)
			{
				if (context != null)
				{
					current(protocol2, model2, id, dataType, val, timestamp, callbackId, GCHandle.FromIntPtr((IntPtr) context).Target,
						ex);
				}
				else
				{
					current(protocol2, model2, id, dataType, val, timestamp, callbackId, null, ex);
				}
			}
			return 0;
		}
Exemplo n.º 7
0
		private unsafe int rawListeningFunction(char* data, int controllerId, int callbackId, void* context)
		{
			UnmanagedException ex = null;
			string data2;
			try
			{
				data2 = AsString(data, false);
			}
			catch (Exception innerException)
			{
				data2 = "error;TelldusAPIError:";
				ex = new UnmanagedException("GetString failed during callback from Telldus API.", innerException);
			}
			foreach (RawListeningCallbackFunction current in rawListenerList.Values)
			{
				if (context != null)
				{
					current(data2, controllerId, callbackId, GCHandle.FromIntPtr((IntPtr) context).Target, ex);
				}
				else
				{
					current(data2, controllerId, callbackId, null, ex);
				}
			}
			return 0;
		}
Exemplo n.º 8
0
		//Helpers
		private unsafe int eventFunction(int deviceId, int method, char* data, int callbackId, void* context)
		{
			string data2 = "Invalid data from Telldus API.";
			UnmanagedException ex = null;
			try
			{
				data2 = AsString(data, false);
			}
			catch (Exception innerException)
			{
				ex = new UnmanagedException("GetString failed during callback from Telldus API.", innerException);
			}
			foreach (EventCallbackFunction current in eventList.Values)
			{
				if (context != null)
				{
					current(deviceId, method, data2, callbackId, GCHandle.FromIntPtr((IntPtr) context).Target, ex);
				}
				else
				{
					current(deviceId, method, data2, callbackId, null, ex);
				}
			}
			return 0;
		}
Exemplo n.º 9
0
	    private int SensorUpdated(
		    string protocol, string model, int id, int dataType, string val, int timestamp, int callbackId, object obj,
		    UnmanagedException ex)
	    {
		    Console.WriteLine("TS: " + protocol + ", " + model + ", " + id + ", " + dataType + ", " + val + ", " + timestamp + ", " + callbackId);
			var module = interfaceModules.FirstOrDefault(i => i.Address == id.ToString());
		    if (module == null)
		    {

				module = new InterfaceModule
				{
					Domain = Domain,
					Address = id.ToString(),
					Description = model + " - " + protocol,
					ModuleType = ModuleTypes.Sensor
				};
				interfaceModules.Add(module);

                InterfaceModulesChangedAction(new InterfaceModulesChangedAction
                {
                    Domain = Domain
                });
            }
			
			var path = ModuleParameters.MODPAR_STATUS_LEVEL;
			if(dataType == (int)TelldusLib.DataType.TEMPERATURE)
				path = ModuleParameters.MODPAR_SENSOR_TEMPERATURE;
			else if(dataType == (int)TelldusLib.DataType.HUMIDITY)
				path = ModuleParameters.MODPAR_SENSOR_HUMIDITY;
            
			InterfacePropertyChangedAction(new InterfacePropertyChangedAction() {
                Domain = Domain,
                SourceId = module.Address,
                SourceType = "Tellstick Sensor",
                Path = path,
                Value = val
            });

			//Sensor.Temperature
			//MODPAR_SENSOR_TEMPERATURE

			return 1;
	    }