Example #1
0
        private static void Export(ISensorDataExport Output, IEnumerable <Record> History, ReadoutType Type, ReadoutRequest Request)
        {
            if ((Request.Types & Type) != 0)
            {
                foreach (Record Rec in History)
                {
                    if (!Request.ReportTimestamp(Rec.Timestamp))
                    {
                        continue;
                    }

                    Output.StartTimestamp(Rec.Timestamp);

                    if (Request.ReportField("Temperature"))
                    {
                        Output.ExportField("Temperature", Rec.TemperatureC, 1, "C", Type);
                    }

                    if (Request.ReportField("Light"))
                    {
                        Output.ExportField("Light", Rec.LightPercent, 1, "%", Type);
                    }

                    if (Request.ReportField("Motion"))
                    {
                        Output.ExportField("Motion", Rec.Motion, Type);
                    }

                    Output.EndTimestamp();
                }
            }
        }
 /// <summary>
 /// Class handling partitioned export of sensor data.
 /// </summary>
 public PartitionedExport(StringBuilder Output, ISensorDataExport Export, int PartitionAfterBytes, PartitionEventHandler PartitionCallback, object State)
 {
     this.sb     = Output;
     this.export = Export;
     this.partitionAfterBytes = PartitionAfterBytes;
     this.partitionCallback   = PartitionCallback;
     this.state = State;
 }
        /// <summary>
        /// Performs a readout.
        /// </summary>
        /// <param name="Request">Readout request object, specifying what to read.</param>
        /// <param name="Response">Sensor data will be output to this interface.</param>
        public void DoReadout(ReadoutRequest Request, ISensorDataExport Response)
        {
            ReadoutEventHandler h = this.OnReadout;

            if (h != null)
            {
                h(Request, Response);
            }
            else
            {
                Response.Start();
                Response.End();
            }
        }
Example #4
0
        public PendingEvent(double?Temp, double?TempDiff, double?Light, double?LightDiff, bool?Motion, int Timeout,
                            HttpServerResponse Response, string ContentType, ISensorDataExport ExportModule)
        {
            this.temp     = Temp;
            this.tempDiff = TempDiff;

            this.light     = Light;
            this.lightDiff = LightDiff;

            this.motion = Motion;

            this.timeout      = DateTime.Now.AddSeconds(Timeout);
            this.response     = Response;
            this.contentType  = ContentType;
            this.exportModule = ExportModule;
        }
Example #5
0
		public PendingEvent (double? Temp, double? TempDiff, double? Light, double? LightDiff, bool? Motion, int Timeout, 
			HttpServerResponse Response, string ContentType, ISensorDataExport ExportModule)
		{
			this.temp = Temp;
			this.tempDiff = TempDiff;

			this.light = Light;
			this.lightDiff = LightDiff;

			this.motion = Motion;

			this.timeout = DateTime.Now.AddSeconds (Timeout);
			this.response = Response;
			this.contentType = ContentType;
			this.exportModule = ExportModule;
		}
Example #6
0
        private static void ExportSensorData(ISensorDataExport Output, ReadoutRequest Request)
        {
            Output.Start();

            lock (synchObject)
            {
                Output.StartNode("Sensor");

                Export(Output, new Record[] { new Record(DateTime.Now, temperatureC, lightPercent, motionDetected) }, ReadoutType.MomentaryValues, Request);

                Export(Output, perSecond, ReadoutType.HistoricalValuesSecond, Request);
                Export(Output, perMinute, ReadoutType.HistoricalValuesMinute, Request);
                Export(Output, perHour, ReadoutType.HistoricalValuesHour, Request);
                Export(Output, perDay, ReadoutType.HistoricalValuesDay, Request);
                Export(Output, perMonth, ReadoutType.HistoricalValuesMonth, Request);

                Output.EndNode();
            }

            Output.End();
        }
        private static void ExportSensorData(ISensorDataExport Output, ReadoutRequest Request)
        {
            DateTime Now = DateTime.Now;
            string   s;
            int      i;

            Output.Start();
            Output.StartNode("Actuator");
            Output.StartTimestamp(Now);

            if ((Request.Types & ReadoutType.MomentaryValues) != 0 && Request.ReportTimestamp(Now))
            {
                if (Request.ReportField("Digital Output Count"))
                {
                    Output.ExportField("Digital Output Count", 8, ReadoutType.StatusValues);
                }

                for (i = 0; i < 8; i++)
                {
                    s = "Digital Output " + (i + 1).ToString();
                    if (Request.ReportField(s))
                    {
                        Output.ExportField(s, digitalOutputs [i].Value);
                    }
                }

                if (Request.ReportField("State"))
                {
                    Output.ExportField("State", alarmThread != null);
                }
            }

            Output.EndTimestamp();
            Output.EndNode();
            Output.End();
        }
Example #8
0
		private static void HttpGetSensorData (HttpServerResponse resp, HttpServerRequest req, string ContentType, ISensorDataExport ExportModule)
		{
			ReadoutRequest Request = new ReadoutRequest (req);
			HttpGetSensorData (resp, ContentType, ExportModule, Request);
		}
Example #9
0
        private static void HttpGetSensorData(HttpServerResponse resp, string ContentType, ISensorDataExport ExportModule, ReadoutRequest Request)
        {
            networkLed.High();
            try
            {
                resp.ContentType = ContentType;
                resp.Encoding    = System.Text.Encoding.UTF8;
                resp.Expires     = DateTime.Now;
                resp.ReturnCode  = HttpStatusCode.Successful_OK;

                ExportSensorData(ExportModule, Request);
            } finally
            {
                networkLed.Low();
            }
        }
Example #10
0
		private static void HttpGetSensorData (HttpServerResponse resp, string ContentType, ISensorDataExport Output, ReadoutRequest Request)
		{
			DateTime Now = DateTime.Now;
			string s;
			int i;

			resp.ContentType = ContentType;
			resp.Encoding = System.Text.Encoding.UTF8;
			resp.Expires = DateTime.Now;
			resp.ReturnCode = HttpStatusCode.Successful_OK;

			Output.Start ();
			Output.StartNode ("Actuator");
			Output.StartTimestamp (Now);

			if ((Request.Types & ReadoutType.MomentaryValues) != 0 && Request.ReportTimestamp (Now))
			{
				if (Request.ReportField ("Digital Output Count"))
					Output.ExportField ("Digital Output Count", 8, ReadoutType.StatusValues);

				for (i = 0; i < 8; i++)
				{
					s = "Digital Output " + (i + 1).ToString ();
					if (Request.ReportField (s))
						Output.ExportField (s, digitalOutputs [i].Value);
				}

				if (Request.ReportField ("State"))
					Output.ExportField ("State", alarmThread != null);
			}

			Output.EndTimestamp ();
			Output.EndNode ();
			Output.End ();
		}
        private static void HttpGetSensorData(HttpServerResponse resp, HttpServerRequest req, string ContentType, ISensorDataExport ExportModule)
        {
            ReadoutRequest Request = new ReadoutRequest(req);

            HttpGetSensorData(resp, ContentType, ExportModule, Request);
        }
Example #12
0
		private static void HttpGetEvent (HttpServerResponse resp, HttpServerRequest req, string ContentType, ISensorDataExport ExportModule)
		{
			networkLed.High ();
			try
			{
				double? Temperature = null;
				double? TemperatureDiff = null;
				double? Light = null;
				double? LightDiff = null;
				bool? Motion = null;
				double d, d2;
				string s;
				bool b;
				int Timeout;

				if (!req.Query.TryGetValue ("Timeout", out s) || !int.TryParse (s, out Timeout) || Timeout <= 0)
					throw new HttpException (HttpStatusCode.ClientError_BadRequest);

				if (req.Query.TryGetValue ("Temperature", out s) && XmlUtilities.TryParseDouble (s, out d) &&
				    req.Query.TryGetValue ("TemperatureDiff", out s) && XmlUtilities.TryParseDouble (s, out d2) && d2 > 0)
				{
					Temperature = d;
					TemperatureDiff = d2;
				}

				if (req.Query.TryGetValue ("Light", out s) && XmlUtilities.TryParseDouble (s, out d) &&
				    req.Query.TryGetValue ("LightDiff", out s) && XmlUtilities.TryParseDouble (s, out d2) && d2 > 0)
				{
					Light = d;
					LightDiff = d2;
				}

				if (req.Query.TryGetValue ("Motion", out s) && XmlUtilities.TryParseBoolean (s, out b))
					Motion = b;

				if (!(Temperature.HasValue || Light.HasValue || Motion.HasValue))
					throw new HttpException (HttpStatusCode.ClientError_BadRequest);

				lock (synchObject)
				{
					pendingEvents.Add (new PendingEvent (Temperature, TemperatureDiff, Light, LightDiff, Motion, Timeout, resp, ContentType, ExportModule));
				}

			} finally
			{
				networkLed.Low ();
			}
		}
Example #13
0
		private static void Export (ISensorDataExport Output, IEnumerable<Record> History, ReadoutType Type, ReadoutRequest Request)
		{
			if ((Request.Types & Type) != 0)
			{
				foreach (Record Rec in History)
				{
					if (!Request.ReportTimestamp (Rec.Timestamp))
						continue;

					Output.StartTimestamp (Rec.Timestamp);

					if (Request.ReportField ("Temperature"))
						Output.ExportField ("Temperature", Rec.TemperatureC, 1, "C", Type);

					if (Request.ReportField ("Light"))
						Output.ExportField ("Light", Rec.LightPercent, 1, "%", Type);

					if (Request.ReportField ("Motion"))
						Output.ExportField ("Motion", Rec.Motion, Type);

					Output.EndTimestamp ();
				}
			}
		}
        private static void HttpGetEvent(HttpServerResponse resp, HttpServerRequest req, string ContentType, ISensorDataExport ExportModule)
        {
            networkLed.High();
            try
            {
                double?Temperature = null;
                double?TemperatureDiff = null;
                double?Light = null;
                double?LightDiff = null;
                bool?  Motion = null;
                double d, d2;
                string s;
                bool   b;
                int    Timeout;

                if (!req.Query.TryGetValue("Timeout", out s) || !int.TryParse(s, out Timeout) || Timeout <= 0)
                {
                    throw new HttpException(HttpStatusCode.ClientError_BadRequest);
                }

                if (req.Query.TryGetValue("Temperature", out s) && XmlUtilities.TryParseDouble(s, out d) &&
                    req.Query.TryGetValue("TemperatureDiff", out s) && XmlUtilities.TryParseDouble(s, out d2) && d2 > 0)
                {
                    Temperature     = d;
                    TemperatureDiff = d2;
                }

                if (req.Query.TryGetValue("Light", out s) && XmlUtilities.TryParseDouble(s, out d) &&
                    req.Query.TryGetValue("LightDiff", out s) && XmlUtilities.TryParseDouble(s, out d2) && d2 > 0)
                {
                    Light     = d;
                    LightDiff = d2;
                }

                if (req.Query.TryGetValue("Motion", out s) && XmlUtilities.TryParseBoolean(s, out b))
                {
                    Motion = b;
                }

                if (!(Temperature.HasValue || Light.HasValue || Motion.HasValue))
                {
                    throw new HttpException(HttpStatusCode.ClientError_BadRequest);
                }

                lock (synchObject)
                {
                    pendingEvents.Add(new PendingEvent(Temperature, TemperatureDiff, Light, LightDiff, Motion, Timeout, resp, ContentType, ExportModule));
                }
            } finally
            {
                networkLed.Low();
            }
        }
        private static void HttpGetSensorData(HttpServerResponse resp, string ContentType, ISensorDataExport Output, ReadoutRequest Request)
        {
            resp.ContentType = ContentType;
            resp.Encoding    = System.Text.Encoding.UTF8;
            resp.Expires     = DateTime.Now;
            resp.ReturnCode  = HttpStatusCode.Successful_OK;

            ExportSensorData(Output, Request);
        }
Example #16
0
		private static void HttpGetSensorData (HttpServerResponse resp, string ContentType, ISensorDataExport Output, ReadoutRequest Request)
		{
			resp.ContentType = ContentType;
			resp.Encoding = System.Text.Encoding.UTF8;
			resp.Expires = DateTime.Now;
			resp.ReturnCode = HttpStatusCode.Successful_OK;

			ExportSensorData (Output, Request);
		}
Example #17
0
		private static void ExportSensorData (ISensorDataExport Output, ReadoutRequest Request)
		{
			DateTime Now = DateTime.Now;
			string s;
			int i;

			Output.Start ();
			Output.StartNode ("Actuator");
			Output.StartTimestamp (Now);

			if ((Request.Types & ReadoutType.MomentaryValues) != 0 && Request.ReportTimestamp (Now))
			{
				if (Request.ReportField ("Digital Output Count"))
					Output.ExportField ("Digital Output Count", 8, ReadoutType.StatusValues);

				for (i = 0; i < 8; i++)
				{
					s = "Digital Output " + (i + 1).ToString ();
					if (Request.ReportField (s))
						Output.ExportField (s, digitalOutputs [i].Value);
				}

				if (Request.ReportField ("State"))
					Output.ExportField ("State", alarmThread != null);
			}

			Output.EndTimestamp ();
			Output.EndNode ();
			Output.End ();
		}
Example #18
0
		private static void HttpGetSensorData (HttpServerResponse resp, string ContentType, ISensorDataExport ExportModule, ReadoutRequest Request)
		{
			networkLed.High ();
			try
			{
				resp.ContentType = ContentType;
				resp.Encoding = System.Text.Encoding.UTF8;
				resp.Expires = DateTime.Now;
				resp.ReturnCode = HttpStatusCode.Successful_OK;

				ExportSensorData (ExportModule, Request);

			} finally
			{
				networkLed.Low ();
			}
		}
        private static void HttpGetSensorData(HttpServerResponse resp, string ContentType, ISensorDataExport Output, ReadoutRequest Request)
        {
            DateTime Now = DateTime.Now;
            string   s;
            int      i;

            resp.ContentType = ContentType;
            resp.Encoding    = System.Text.Encoding.UTF8;
            resp.Expires     = DateTime.Now;
            resp.ReturnCode  = HttpStatusCode.Successful_OK;

            Output.Start();
            Output.StartNode("Actuator");
            Output.StartTimestamp(Now);

            if ((Request.Types & ReadoutType.MomentaryValues) != 0 && Request.ReportTimestamp(Now))
            {
                if (Request.ReportField("Digital Output Count"))
                {
                    Output.ExportField("Digital Output Count", 8, ReadoutType.StatusValues);
                }

                for (i = 0; i < 8; i++)
                {
                    s = "Digital Output " + (i + 1).ToString();
                    if (Request.ReportField(s))
                    {
                        Output.ExportField(s, digitalOutputs [i].Value);
                    }
                }

                if (Request.ReportField("State"))
                {
                    Output.ExportField("State", alarmThread != null);
                }
            }

            Output.EndTimestamp();
            Output.EndNode();
            Output.End();
        }
Example #20
0
		private static void ExportSensorData (ISensorDataExport Output, ReadoutRequest Request)
		{
			Output.Start ();

			lock (synchObject)
			{
				Output.StartNode ("Sensor");

				Export (Output, new Record[]{ new Record (DateTime.Now, temperatureC, lightPercent, motionDetected) }, ReadoutType.MomentaryValues, Request);

				Export (Output, perSecond, ReadoutType.HistoricalValuesSecond, Request);
				Export (Output, perMinute, ReadoutType.HistoricalValuesMinute, Request);
				Export (Output, perHour, ReadoutType.HistoricalValuesHour, Request);
				Export (Output, perDay, ReadoutType.HistoricalValuesDay, Request);
				Export (Output, perMonth, ReadoutType.HistoricalValuesMonth, Request);

				Output.EndNode ();
			} 

			Output.End ();
		}