Mateusz Grzywacz / SDI12_device
Revision:
14:88e212b7db59
Parent:
13:0093792f2325
--- a/SDI12_device.h	Thu Aug 02 17:42:45 2018 +0000
+++ b/SDI12_device.h	Sun Aug 05 18:25:03 2018 +0000
@@ -25,14 +25,13 @@
     static int detect(SDI12 &sdi12, char indices[], int stop = -1, int start = -1) {
         char found = 0;
         for (size_t i = (start==-1?0:start); i < (stop==-1?ADDRRICES.size():stop+1); ++i) {
-
             string question = "?!";
             question[0] = ADDRRICES[i];
             sdi12.sendCommand(question);
             std::string response;
             Timer detectTimer;
             detectTimer.start();
-            while (detectTimer.read_ms() < RESPONSE_TIMEOUT) {
+            while (detectTimer.read_ms() < RESPONSE_TIMEOUT * 4) {
                 if (sdi12.RxInProgress()) detectTimer.reset();
                 if (sdi12.RxBufferAvailable()) {
                     unsigned char bufferSize = sdi12.RxBufferAvailable();
@@ -50,11 +49,27 @@
         return found;
     };
 
-    SDI12_device (SDI12 &inst, char address, EventQueue &mainDispatcher) : _sdi12(inst),sensorQueue(4*EVENTS_QUEUE_SIZE) {
+    SDI12_device (SDI12 &inst, char address, EventQueue &mainDispatcher) : _sdi12(inst), parentQueue(mainDispatcher), sensorQueue(4*EVENTS_QUEUE_SIZE) {
         setAddress(address);
         sensorQueue.chain(&mainDispatcher);
         if(getIdentification(_ident_struct));
     };
+
+
+    SDI12_device & operator= (const SDI12_device & old) {
+        _address = old._address;
+        _ident_struct = old._ident_struct;
+//        _sdi12 = old._sdi12; // non-copyable -.-
+
+        _measurementEventId = old._measurementEventId;
+        _measurement = old._measurement;
+        _valuesReadyCount = old._valuesReadyCount;
+        _measurementReady = old._measurementReady;
+
+        parentQueue = old.parentQueue;
+        sensorQueue = old.sensorQueue;
+    }
+
     ~SDI12_device () {
         // unchain event queue
 //        sensorQueue.cancel(_measurementEventId);
@@ -62,7 +77,7 @@
     }
 
 
-        // concurrent means that device under measurement won't signal its prempt readiness to the bus
+    // concurrent means that device under measurement won't signal its prempt readiness to the bus
     int measure(bool concurrent = true, char group = '0') {
 
         std::string question = string("?") + string(concurrent?"C":"M") + string("!");
@@ -185,6 +200,7 @@
     size_t _valuesReadyCount;
     bool _measurementReady;
 
+    EventQueue &parentQueue;
     EventQueue sensorQueue;
 
     bool getIdentification(Identification_struct &ident) {