Subversion Repositories tpanel

Rev

Rev 92 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 92 Rev 93
Line 49... Line 49...
49
 
49
 
50
#define NSTATE_OFFLINE      0
50
#define NSTATE_OFFLINE      0
51
#define NSTATE_ONLINE       6
51
#define NSTATE_ONLINE       6
52
#define NSTATE_CONNECTING   9
52
#define NSTATE_CONNECTING   9
53
 
53
 
-
 
54
#define WAIT_RESET          3   // Number of seconds to wait in case of connecting to another controller
-
 
55
#define WAIT_RECONNECT      15  // Number of seconds to wait in case of reconnecting to the same controller
-
 
56
 
54
    typedef struct ANET_SEND
57
    typedef struct ANET_SEND
55
    {
58
    {
56
        uint16_t device{0};     // Device ID of panel
59
        uint16_t device{0};     // Device ID of panel
57
        uint16_t MC{0};         // message command number
60
        uint16_t MC{0};         // message command number
58
        uint16_t port{0};       // port number
61
        uint16_t port{0};       // port number
Line 361... Line 364...
361
            explicit TAmxNet(const std::string& sn, const std::string& nm);
364
            explicit TAmxNet(const std::string& sn, const std::string& nm);
362
            ~TAmxNet();
365
            ~TAmxNet();
363
 
366
 
364
            void Run();
367
            void Run();
365
            void stop(bool soft=false);
368
            void stop(bool soft=false);
-
 
369
            bool reconnect();
366
 
370
 
367
            void setCallback(std::function<void(const ANET_COMMAND&)> func) { callback = func; }
371
            void setCallback(std::function<void(const ANET_COMMAND&)> func) { callback = func; }
368
            void registerNetworkState(std::function<void(int)> registerNetwork, ulong handle);
372
            void registerNetworkState(std::function<void(int)> registerNetwork, ulong handle);
369
            void registerTimer(std::function<void(const ANET_BLINK&)> registerBlink, ulong handle);
373
            void registerTimer(std::function<void(const ANET_BLINK&)> registerBlink, ulong handle);
370
            void deregNetworkState(ulong handle);
374
            void deregNetworkState(ulong handle);
Line 378... Line 382...
378
            void setPanelID(int id) { panelID = id; }
382
            void setPanelID(int id) { panelID = id; }
379
            void setSerialNum(const std::string& sn);
383
            void setSerialNum(const std::string& sn);
380
            bool setupStatus() { return receiveSetup; }
384
            bool setupStatus() { return receiveSetup; }
381
            void setPanName(const std::string& nm) { panName.assign(nm); }
385
            void setPanName(const std::string& nm) { panName.assign(nm); }
382
 
386
 
-
 
387
            void setWaitTime(int secs);
-
 
388
            int getWaitTime() { return mWaitTime; }
-
 
389
            int swapWaitTime();
-
 
390
 
383
        protected:
391
        protected:
384
            void start();
392
            void start();
385
 
393
 
386
        private:
394
        private:
387
            enum R_TOKEN
395
            enum R_TOKEN
Line 423... Line 431...
423
            void sendAllFuncTimer(const ANET_BLINK& blink);
431
            void sendAllFuncTimer(const ANET_BLINK& blink);
424
 
432
 
425
            std::function<void(const ANET_COMMAND&)> callback;
433
            std::function<void(const ANET_COMMAND&)> callback;
426
            std::function<bool(TAmxNet *)> cbWebConn;
434
            std::function<bool(TAmxNet *)> cbWebConn;
427
 
435
 
428
            std::atomic<bool> stopped_{false};
-
 
429
            std::atomic<bool> mSendReady{false};
-
 
430
            TSocket *mSocket{nullptr};  // Pointer to socket class needed for communication
436
            TSocket *mSocket{nullptr};  // Pointer to socket class needed for communication
-
 
437
            FILE *rcvFile{nullptr};
-
 
438
            FILE *sndFile{nullptr};
-
 
439
            size_t posRcv{0};
-
 
440
            size_t lenRcv{0};
-
 
441
            size_t posSnd{0};
-
 
442
            size_t lenSnd{0};
-
 
443
            std::thread mThread;
431
            std::string input_buffer_;
444
            std::string input_buffer_;
432
            char buff_[BUF_SIZE];       // Internal used buffer for network communication
-
 
433
            std::string panName;        // The technical name of the panel
445
            std::string panName;        // The technical name of the panel
434
            bool protError{false};      // true = error on receive --> disconnect
-
 
435
//            std::atomic<int> reconCounter{0};   // Reconnect counter
-
 
436
            uint16_t reqDevStatus{0};
-
 
437
            ANET_COMMAND comm;          // received command
-
 
438
            ANET_COMMAND mSend;          // answer / request
-
 
439
            uint16_t sendCounter{0};    // Counter increment on every send
-
 
440
            std::vector<ANET_COMMAND> comStack; // commands to answer
446
            std::vector<ANET_COMMAND> comStack; // commands to answer
441
            bool initSend{false};       // TRUE = all init messages are send.
-
 
442
            bool ready{false};          // TRUE = ready for communication
-
 
443
            bool write_busy{false};
-
 
444
            std::vector<DEVICE_INFO> devInfo;
447
            std::vector<DEVICE_INFO> devInfo;
445
            std::string oldCmd;
448
            std::string oldCmd;
446
            int panelID{0};             // Panel ID of currently legalized panel.
-
 
447
            std::string serNum;
449
            std::string serNum;
448
            std::atomic<bool> receiveSetup{false};
-
 
449
            std::string sndFileName;
450
            std::string sndFileName;
450
            std::string rcvFileName;
451
            std::string rcvFileName;
-
 
452
            ANET_COMMAND comm;          // received command
-
 
453
            ANET_COMMAND mSend;         // answer / request
-
 
454
            int panelID{0};             // Panel ID of currently legalized panel.
-
 
455
            int mWaitTime{3};           // [seconds]: Wait by default for 3 seconds
-
 
456
            int mOldWaitTime{3};        // [seconds]: The previous wait time in case of change
451
            FILE *rcvFile{nullptr};
457
            FTRANSFER ftransfer;
-
 
458
            uint16_t reqDevStatus{0};
-
 
459
            uint16_t sendCounter{0};    // Counter increment on every send
-
 
460
            std::atomic<bool> stopped_{false};
-
 
461
            std::atomic<bool> mSendReady{false};
-
 
462
            bool protError{false};      // true = error on receive --> disconnect
-
 
463
            bool initSend{false};       // TRUE = all init messages are send.
-
 
464
            bool ready{false};          // TRUE = ready for communication
452
            FILE *sndFile{nullptr};
465
            bool write_busy{false};
-
 
466
            std::atomic<bool> receiveSetup{false};
453
            bool isOpenSnd{false};
467
            bool isOpenSnd{false};
454
            bool isOpenRcv{false};
468
            bool isOpenRcv{false};
455
            size_t posRcv{0};
-
 
456
            size_t lenRcv{0};
-
 
457
            size_t posSnd{0};
-
 
458
            size_t lenSnd{0};
-
 
459
            FTRANSFER ftransfer;
-
 
460
            bool _retry{false};
469
            bool _retry{false};
461
            std::thread mThread;
470
            char buff_[BUF_SIZE];       // Internal used buffer for network communication
462
    };
471
    };
463
}
472
}
464
 
473
 
465
#endif
474
#endif