Browse Source

* Fixed some bug in findbox services

Giancarlo Voci 8 years ago
parent
commit
bfa6f7c82d

+ 1 - 1
cfg/config - dimatec.ini

@@ -11,7 +11,7 @@ dbuser=root
 dbpass=giancarlo
 dbpass=giancarlo
 ;dbpass=OMG988of8$
 ;dbpass=OMG988of8$
 PHP_PATH=C:/nginx/php7/php.exe
 PHP_PATH=C:/nginx/php7/php.exe
-MAX_BLINK_TIME_SEC=60
+MAX_BLINK_TIME_SEC=120
 
 
 ; Path
 ; Path
 BASEURL=/omlink
 BASEURL=/omlink

+ 1 - 1
cfg/config.bin

@@ -1 +1 @@
-eJx1kWtvmzAUhr9b8n9A0T5smsYl5NZGluaAB7RcIi5RtapChDgEBTADkrWJ8t9n0nT7NEu2fHnPOc97/JwVbJ0U7QsEOAo928M6GrRNKg0g0LBmEgEJoR8RCCILHXIJAp0sIgMNISCu5umWa6BBFP74NuMBpmWYNp8h2vKUFIIH7Iv0tc4bis7nLi/p5y9fVWWsTmRZvlx4rsBFg/Kt/VXc71jboYKlSdHv5jVrOqSq8mS+WVdJSREri7za8yKb9aGlDWoY6/pDnbQtyvKkSpOmYBDMb1eeY9zNZmw7+wTB0lzGSxyaSLuXqiyvXqV6V0/7hdNxTAc/xQvbch/j0HJIHBANTWQIeDJhmXQ7CBY4IJFvI+mdAoLAComLHYL0vEw6mkJge4YXa1EQeg7xudvvt5jLReJt46qMttJNbbOMiXWVQWBpnhv3oVH4v5iCiw/du7wnCmhB0074vcvTnZAe2o6VtBHSgpsWaJWsC27og+OKuPlAhOBZ83wibtf8t6/9Vu6GojKZiYqojLjha9PH8mikQrCnb0iT/w1FGU1H8lCVx1Mu7Dv8s8lO++ND4z1WbqBVy8o4qYcznlAzcJ9Wx/ZacEX80NKwzXl8bJCX3oGTZMnplFdMONKmy/mXU4FrHP7mrGKs6z4Jgr9sw7EqKiqn+wPcGMvS
+eJx1kWtvmzAUhr9b8n9A0T5smsYl5NZGluaAB7RcIi5RtapChDgEBTADkrWJ8t9n0nT7NEu2fHnPOc97/JwVbJ0U7QsEOAo928M6GrRNKg0g0LBmEgEJoR8RCCILHXIJAp0sIgMNISCu5umWa6BBFP74NuMBpmWYNp8h2vKUFIIH7Iv0tc4bis7nLi/p5y9fVWWsTmRZvlx4rsBFg/Kt/VXc71jboYKlSdHv5jVrOqSq8mS+WVdJSREri7za8yKb9aGlDWoY6/pDnbQtyvKkSpOmYBDMb1eeY9zNZmw7+wTB0lzGSxyaSLuXqiyvXqV6V0/7hdNxTAc/xQvbch/j0HJIHBANKUMZAp5NWCbdDoIFDkjk20h6x4AgsELiYocgPS+TjqYQ2J7hxVoUhJ5DfG73+y3mcpF437gqo610U9ssY2JdZRBYmufGfWgU/i+m4OJD9y7viQJa0LQTfu/ydCekh7ZjJW2EtOCuBVol64I7+uC4Im4+ECF41jyfiNs1/+5rw5W7oahMZqIiKiNu+Nr1sTwaqRDs6RvS5H9DUUbTkTxU5fGUC/sW/2yy0/740HiPlRto1bIyTurhjCfUDNyn1bG9FlwRP7Q0bHMeHxvkpXfgJFlyOuUVE4606XL+51TgGoe/OasY67pPguAv23CsiorK6f4AeBPL/w==

+ 46 - 23
src/Modules/Dimatec/Pages.php

@@ -8,7 +8,7 @@
 namespace Modules\Dimatec;
 namespace Modules\Dimatec;
 
 
 use OpenMind\FindBox\FindBoxCoreSystem;
 use OpenMind\FindBox\FindBoxCoreSystem;
-use OpenMind\FindBox\LedAlive;
+use OpenMind\FindBox\QueueCommand;
 use OpenMind\FindBox\SmartESL;
 use OpenMind\FindBox\SmartESL;
 use OpenMind\System\QueueSystem;
 use OpenMind\System\QueueSystem;
 use OpenMind\Web\Controller;
 use OpenMind\Web\Controller;
@@ -25,6 +25,37 @@ class Pages extends Controller
     $this->findBoxCore = new FindBoxCoreSystem(...array_values($this->CORE_SETTINGS));
     $this->findBoxCore = new FindBoxCoreSystem(...array_values($this->CORE_SETTINGS));
   }
   }
 
 
+  /**
+   * Send QueueSystem command for all labels associated
+   *
+   * @param $distinta
+   * @param array $commesse
+   */
+  private function sendLabelMsg($distinta, array $commesse)
+  {
+    global $f3;
+    foreach($commesse as $commessa) {
+      $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
+      if ($labelid == null) {
+        $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
+        continue;
+      }
+
+      $msgBlink = new QueueCommand($labelid);
+      $msgSaveP = new QueueCommand($labelid);
+
+      $msgBlink->setLeds(2, 1, 1000, 16);
+      $msgSaveP->saveProducts($commessa['descrizione'], [
+        'Q.ta' => $commessa['qta_prelevare'],
+        'Commessa' => $commessa['commessa']
+      ]);
+
+      $qm = new QueueSystem('FindBoxService');
+      $qm->send($msgBlink);
+      $qm->send($msgSaveP);
+    }
+  }
+
   public function Pick2Light(object $f3, array $args)
   public function Pick2Light(object $f3, array $args)
   {
   {
     $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
     $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
@@ -46,6 +77,10 @@ class Pages extends Controller
           $f3->set('NEXTSTEP', 1);
           $f3->set('NEXTSTEP', 1);
           break;
           break;
         }
         }
+
+        // Send blink to all labels associated to barcode
+        $this->sendLabelMsg($distinta, $commesse);
+
         $distinta->SendToIcamStorage($commesse);
         $distinta->SendToIcamStorage($commesse);
 
 
         $f3->set('SESSION.barcode_mv', $stepValues['barcode_mv']);
         $f3->set('SESSION.barcode_mv', $stepValues['barcode_mv']);
@@ -55,20 +90,18 @@ class Pages extends Controller
       case 2:
       case 2:
         $f3->set('NEXTSTEP', 2);
         $f3->set('NEXTSTEP', 2);
         if (isset($stepValues['commessa'])) {
         if (isset($stepValues['commessa'])) {
-          $ok = $distinta->isCommessaPresent($stepValues['commessa']);
-          if (!$ok) {
+          if (!$distinta->isCommessaPresent($stepValues['commessa'])) {
             $f3->set('INFOTEXT', "Codice cesta non corretto");
             $f3->set('INFOTEXT', "Codice cesta non corretto");
           } else {
           } else {
             $labelid = $distinta->GetLabelIdFromBarcode($stepValues['commessa']);
             $labelid = $distinta->GetLabelIdFromBarcode($stepValues['commessa']);
             if ($labelid != null) {
             if ($labelid != null) {
               // Send BlinkOFF
               // Send BlinkOFF
-              $obj = new LedAlive($labelid);
+              $obj = new QueueCommand($labelid);
               $obj->setToBlinkOff();
               $obj->setToBlinkOff();
 
 
               // Send command to queue
               // Send command to queue
               $qm = new QueueSystem('FindBoxService');
               $qm = new QueueSystem('FindBoxService');
               $qm->send($obj);
               $qm->send($obj);
-              //$f3->get('DB')->exec('UPDATE label_bindings SET isBlinking=0 WHERE label_id=?', $labelid);
 
 
               $distinta->DeleteCommessa($stepValues['commessa']);
               $distinta->DeleteCommessa($stepValues['commessa']);
             }
             }
@@ -79,24 +112,14 @@ class Pages extends Controller
           $f3->set('INFOTEXT', "Ventilazione terminata");
           $f3->set('INFOTEXT', "Ventilazione terminata");
           $f3->set('RESTART_VENTILAZIONE', TRUE);
           $f3->set('RESTART_VENTILAZIONE', TRUE);
         }
         }
-        foreach($commesse as $commessa) {
-          $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
-          if ($labelid == null) {
-            $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
-            continue;
-          }
-
-          $obj = new LedAlive($labelid);
-          $obj->setToBlink();
-          $obj->SetLeds($commessa['descrizione'], 2, 1, 1000, 1);
-          $obj->setDataFields([
-            'Q.ta' => $commessa['qta_prelevare'],
-            'Commessa' => $commessa['commessa']
-          ]);
-
-          $qm = new QueueSystem('FindBoxService');
-          $qm->send($obj);
-        }
+        /*        foreach($commesse as $commessa) {
+                  $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
+                  if ($labelid == null) {
+                    $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
+                    continue;
+                  }
+
+                }*/
         $f3->set('COMMESSE', $commesse);
         $f3->set('COMMESSE', $commesse);
         break;
         break;
     }
     }

+ 48 - 28
src/OpenMind/FindBox/FindBoxService.php

@@ -8,42 +8,64 @@
 
 
 namespace OpenMind\FindBox;
 namespace OpenMind\FindBox;
 
 
-use DB\SQL\Mapper;
-use http\QueryString;
 use OpenMind\System\QueueSystem;
 use OpenMind\System\QueueSystem;
 
 
 class FindBoxService
 class FindBoxService
 {
 {
   private $dbHandle;
   private $dbHandle;
   private $findBoxCore;
   private $findBoxCore;
-  private $labels;
+  private $labelToBlink;
 
 
   public function __construct()
   public function __construct()
   {
   {
     global $f3;
     global $f3;
     $this->dbHandle = $f3->get('DB');
     $this->dbHandle = $f3->get('DB');
     $this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
     $this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
-
-    $this->labels = [];
+    $this->labelToBlink = [];
   }
   }
 
 
   private function getCurrentQueue()
   private function getCurrentQueue()
   {
   {
+    echo "Checking QueueSystem               \n";
     $table = new QueueSystem('FindBoxService');
     $table = new QueueSystem('FindBoxService');
     while (!$table->check()) {
     while (!$table->check()) {
 
 
-      /** @var LedAlive $apiParameters */
-      $apiParameters = $table->getCommandObject();
-      $this->labels[] = $apiParameters;
+      /** @var QueueCommand $qCommand */
+      $qCommand = $table->getCommandObject();
+      switch ($qCommand->operation) {
+        case Q_SAVEPRODUCT:
+          $this->saveProduct($qCommand);
+          break;
+        case Q_BLINK_ON:
+          $this->labelToBlink[$qCommand->id] = $qCommand;
+          break;
+        case Q_BLINK_OFF:
+          echo "BlinkOff for label {$qCommand->id} requested\n";
+          $esl = new SmartESL($this->findBoxCore, [$qCommand->id]);
+          $esl->BlinkOff();
+          unset($this->labelToBlink[$qCommand->id]);
+          break;
+      }
       $table->erase();
       $table->erase();
       $table->next();
       $table->next();
+      echo "Label {$qCommand->id} readed\n";
     }
     }
   }
   }
 
 
+  /**
+   * Send SaveProduct to Label
+   *
+   * @param  QueueCommand $label
+   * @return bool
+   */
   public function saveProduct($label)
   public function saveProduct($label)
   {
   {
-    if ($label->dataFields != null)
-      $this->findBoxCore->SaveProducts($label->id, $label->description, $label->dataFields);
+    if ($label->operation == Q_SAVEPRODUCT) {
+      $this->findBoxCore->SaveProducts($label->id, $label->description, $label->params['dataFields']);
+      echo "Save product {$label->id}\n";
+      return true;
+    }
+    return false;
   }
   }
 
 
   /**
   /**
@@ -61,45 +83,43 @@ class FindBoxService
 
 
       //$this->parseQueue();
       //$this->parseQueue();
 
 
-      /** @var LedAlive $label */
-      foreach($this->labels as $key => $label) {
+      /** @var QueueCommand $label */
+      echo 'Label in cache: ' . count($this->labelToBlink) . "     \n";
+      foreach($this->labelToBlink as $labelId => $label) {
 
 
-        $this->saveProduct($label);
 
 
         // Priority 1
         // Priority 1
         // ----------
         // ----------
         // Force exit and blink off if run time script > MAX_BLINK_TIME_SEC
         // Force exit and blink off if run time script > MAX_BLINK_TIME_SEC
         $now = time() - $label->tsFirstBlink;
         $now = time() - $label->tsFirstBlink;
         if ($now > $f3->get('MAX_BLINK_TIME_SEC')) {
         if ($now > $f3->get('MAX_BLINK_TIME_SEC')) {
+          echo "Stop label {$label->id} for timeout\n";
           $esl = new SmartESL($this->findBoxCore, [$label->id]);
           $esl = new SmartESL($this->findBoxCore, [$label->id]);
           $esl->BlinkOff();
           $esl->BlinkOff();
-          unset($this->labels[$key]);
+          unset($this->labelToBlink[$labelId]);
           continue;
           continue;
         }
         }
 
 
         // Priority 2
         // Priority 2
         // ----------
         // ----------
-        // Stop blink if isBlinking = 0
-        if ($label->operation == BLINK_OFF) {
-          $esl = new SmartESL($this->findBoxCore, [$label->id]);
-          $esl->BlinkOff();
-          unset($this->labels[$key]);
-          continue;
-        }
-
-        // Priority 3
-        // ----------
         // Restart blink if blink is ended
         // Restart blink if blink is ended
         $blinkEndTime = time() - $label->tsLastLongBlink;
         $blinkEndTime = time() - $label->tsLastLongBlink;
-        if ($blinkEndTime > $label->getBlinkDuration()) {
+        $calcDuration = $label->getBlinkDuration();
+        if ($blinkEndTime > $calcDuration) {
+          echo "Auto restart blinking for label $label->id\n";
+
           $esl = new SmartESL($this->findBoxCore, [$label->id]);
           $esl = new SmartESL($this->findBoxCore, [$label->id]);
-          $esl->BlinkSpecial($label->pattern, $label->repeat, $label->iter_time, $label->iterations, 0);
-          $esl->tsLastLongBlink = time();
+          $ledParams = $label->params;
+
+          $esl->BlinkSpecial($ledParams['pattern'], $ledParams['repeat'], $ledParams['iter_time'], $ledParams['iterations'], 0);
+          $label->tsLastLongBlink = time();
         }
         }
       }
       }
 
 
-
       sleep(1);
       sleep(1);
+      echo "Restart loop                  \n";
+      ob_flush();
+
     }
     }
 
 
     return;
     return;

+ 0 - 63
src/OpenMind/FindBox/LedAlive.php

@@ -1,63 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: Giancarlo
- * Date: 09/08/2018
- * Time: 14:42
- */
-
-namespace OpenMind\FindBox;
-
-define('BLINK_ON', 1);
-define('BLINK_OFF', 2);
-
-class LedAlive
-{
-  public $id;
-  public $description;
-  public $pattern;
-  public $repeat;
-  public $iter_time;
-  public $iterations;
-  public $dataFields;
-  public $operation;
-  public $tsFirstBlink;
-  public $tsLastLongBlink;
-
-  public function __construct(string $labelID)
-  {
-    $this->id = $labelID;
-    $this->dataFields = null;
-    $this->tsLastLongBlink = $this->tsFirstBlink = time();
-  }
-
-  public function SetLeds(string $description, int $pattern, int $repeat, int $iter_time, int $iterations)
-  {
-    list($this->description, $this->pattern, $this->repeat, $this->iter_time, $this->iterations) = func_get_args();
-  }
-
-  public function setDataFields(array $dataFields)
-  {
-    $this->dataFields = $dataFields;
-  }
-
-  public function setToBlink()
-  {
-    $this->operation = BLINK_ON;
-  }
-
-  public function setToBlinkOff()
-  {
-    $this->operation = BLINK_OFF;
-  }
-
-  /**
-   * Calculate blink duration in seconds for patterns_type=2
-   *
-   * @return int
-   */
-  public function getBlinkDuration(): int
-  {
-    return ($this->iter_time / 1000) * $this->iterations;
-  }
-}

+ 64 - 0
src/OpenMind/FindBox/QueueCommand.php

@@ -0,0 +1,64 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Giancarlo
+ * Date: 09/08/2018
+ * Time: 14:42
+ */
+
+namespace OpenMind\FindBox;
+
+define('Q_BLINK_ON', 1);
+define('Q_BLINK_OFF', 2);
+define('Q_SAVEPRODUCT', 3);
+
+class QueueCommand
+{
+  public $id;
+  public $operation;
+  public $description;
+  public $params;
+  public $tsFirstBlink;
+  public $tsLastLongBlink;
+
+  public function __construct(string $labelID)
+  {
+    $this->id = $labelID;
+    $this->params = null;
+    $this->tsLastLongBlink = time() - 3600;
+    $this->tsFirstBlink = time();
+  }
+
+  public function setLeds(int $pattern, int $repeat, int $iter_time, int $iterations)
+  {
+    $this->operation = Q_BLINK_ON;
+    list(
+      $this->params['pattern'],
+      $this->params['repeat'],
+      $this->params['iter_time'],
+      $this->params['iterations']
+      ) = func_get_args();
+  }
+
+  public function saveProducts(string $description, array $dataFields)
+  {
+    $this->operation = Q_SAVEPRODUCT;
+    $this->description = $description;
+    $this->params['dataFields'] = $dataFields;
+  }
+
+  public function setToBlinkOff()
+  {
+    $this->operation = Q_BLINK_OFF;
+  }
+
+  /**
+   * Calculate blink duration in seconds for patterns_type=2
+   *
+   * @return int
+   */
+  public function getBlinkDuration(): int
+  {
+    return (($this->params['iter_time'] / 1000) * $this->params['iterations']) * $this->params['repeat'];
+  }
+}