//
// Created by zx on 2019/12/9.
//

#ifndef PLCDATA_H
#define PLCDATA_H
#include <iostream>
#include <string.h>
#include <mutex>
#include "StdCondition.h"
#include <thread>
#include "s7_plc.h"
#include "unistd.h"
#include "define.h"

#define MAX_REGIONS 15
#define ELE_FENCE_START_ADDR 0
#define ELE_FENCE_DB_NUM 48

class PlcData
{
public:
    static PlcData* GetInstance(std::string ip="");
    static void Release();
    void UpdateData(stateCode code,int id);
    static void plcThread(PlcData* p);
private:
    static PlcData*                                 g_instance;
    StdCondition                                    m_cond_exit;
    std::thread*                                    p_send_thread;
    S7PLC*                                          p_plc;
    const int                                       m_send_interval_milli = 200;


    PlcData(std::string ip);

protected:
    std::mutex m_lock;
    short m_data[MAX_REGIONS];

};




#endif //PLCDATA_H
