Przeglądaj źródła

get sensor value; dummy sensor

tags/0.1.0
Robin Thoni 9 lat temu
rodzic
commit
8bbc71295d

+ 0
- 2
app/Http/Business/Commands/DummyCommand.php Wyświetl plik

@@ -8,10 +8,8 @@
8 8
 
9 9
 namespace App\Http\Business\Commands;
10 10
 
11
-
12 11
 class DummyCommand extends AbstractCommand
13 12
 {
14
-
15 13
     /**
16 14
      * @return bool
17 15
      */

+ 30
- 0
app/Http/Business/Sensors/AbstractSensor.php Wyświetl plik

@@ -0,0 +1,30 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 11/24/15
6
+ * Time: 12:45 AM
7
+ */
8
+
9
+namespace App\Http\Business\Sensors;
10
+
11
+use App\Http\DBO\SensorsDbo;
12
+use app\Http\DBO\SensorsValueDbo;
13
+
14
+abstract class AbstractSensor
15
+{
16
+    /**
17
+     * @var SensorsDbo
18
+     */
19
+    protected $_sensor;
20
+
21
+    public function __construct(SensorsDbo $sensor)
22
+    {
23
+        $this->_sensor = $sensor;
24
+    }
25
+
26
+    /**
27
+     * @return SensorsValueDbo
28
+     */
29
+    public abstract function getValue();
30
+}

+ 28
- 0
app/Http/Business/Sensors/DummySensor.php Wyświetl plik

@@ -0,0 +1,28 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 11/24/15
6
+ * Time: 12:49 AM
7
+ */
8
+
9
+namespace App\Http\Business\Sensors;
10
+
11
+use App\Http\DBO\SensorsValueDbo;
12
+
13
+class DummySensor extends AbstractSensor
14
+{
15
+    /**
16
+     * @return SensorsValueDbo
17
+     */
18
+    public function getValue()
19
+    {
20
+        $data = $this->_sensor->getData();
21
+        $min = isset($data["Minimum"]) ? $data["Minimum"] : 0;
22
+        $max = isset($data["Maximum"]) ? $data["Maximum"] : 42;
23
+
24
+        $value = new SensorsValueDbo();
25
+        $value->setValue(rand($min, $max));
26
+        return $value;
27
+    }
28
+}

+ 31
- 0
app/Http/Business/SensorsBusiness.php Wyświetl plik

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+namespace App\Http\Business;
4
+
5
+use App\Http\Business\Sensors\AbstractSensor;
6
+use App\Http\DBO\SensorsDbo;
7
+use App\Http\DBO\SensorTypesDbo;
8
+
9
+/**
10
+ * Created by PhpStorm.
11
+ * User: robin
12
+ * Date: 11/23/15
13
+ * Time: 11:59 PM
14
+ */
15
+class SensorsBusiness
16
+{
17
+    /**
18
+     * @param SensorsDbo $sensor
19
+     * @param SensorTypesDbo $type
20
+     * @return mixed
21
+     */
22
+    public static function getValue(SensorsDbo $sensor, SensorTypesDbo $type)
23
+    {
24
+        /**
25
+         * @var $sens AbstractSensor
26
+         */
27
+        $class = $type->getClass();
28
+        $sens = new $class($sensor);
29
+        return $sens->getValue();
30
+    }
31
+}

+ 22
- 0
app/Http/Controller/SensorsController.php Wyświetl plik

@@ -0,0 +1,22 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 11/23/15
6
+ * Time: 11:44 PM
7
+ */
8
+
9
+namespace App\Http\Controller;
10
+
11
+use App\Http\Business\SensorsBusiness;
12
+use App\Http\DBO\SensorsDbo;
13
+use App\Http\DBO\SensorTypesDbo;
14
+use Laravel\Lumen\Routing\Controller as BaseController;
15
+
16
+class SensorsController extends BaseController
17
+{
18
+    public function getValue(SensorsDbo $sensor, SensorTypesDbo $type)
19
+    {
20
+        return SensorsBusiness::getValue($sensor, $type);
21
+    }
22
+}

+ 1
- 1
app/Http/DBO/SensorsDbo.php Wyświetl plik

@@ -42,7 +42,7 @@ class SensorsDbo extends LuDbo {
42 42
             $dbo->setSensorTypeId($json["SensorTypeId"]);
43 43
         }
44 44
         if (isset($json["Data"])) {
45
-            $dbo->setData($json["Data"]);
45
+            $dbo->setData(json_decode($json["Data"], true));
46 46
         }
47 47
         return $dbo;
48 48
     }

+ 47
- 0
app/Http/DBO/SensorsValueDbo.php Wyświetl plik

@@ -0,0 +1,47 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 11/24/15
6
+ * Time: 12:53 AM
7
+ */
8
+
9
+namespace app\Http\DBO;
10
+
11
+
12
+use Luticate\Utils\LuDbo;
13
+
14
+class SensorsValueDbo extends LuDbo
15
+{
16
+    private $_value;
17
+
18
+    /**
19
+     * @return mixed
20
+     */
21
+    public function getValue()
22
+    {
23
+        return $this->_value;
24
+    }
25
+
26
+    /**
27
+     * @param mixed $value
28
+     */
29
+    public function setValue($value)
30
+    {
31
+        $this->_value = $value;
32
+    }
33
+
34
+    /**
35
+     * Specify data which should be serialized to JSON
36
+     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
37
+     * @return mixed data which can be serialized by <b>json_encode</b>,
38
+     * which is a value of any type other than a resource.
39
+     * @since 5.4.0
40
+     */
41
+    function jsonSerialize()
42
+    {
43
+        return [
44
+            "Value" => $this->_value
45
+        ];
46
+    }
47
+}

+ 2
- 1
app/Http/routes.php Wyświetl plik

@@ -15,4 +15,5 @@ use Luticate\Utils\LuRoute;
15 15
 
16 16
 $route = LuRoute::getInstance();
17 17
 
18
-$route->post("/commands/exec", "Commands", "exec");
18
+$route->post("/commands/exec", "Commands", "exec");
19
+$route->post("/sensors/value", "Sensors", "getValue");

Ładowanie…
Anuluj
Zapisz