LAPTOP-T815PCOQ\25526
2024-11-15 f5c4a7f3bce165fe2c8c6d934f0f49a363a2ea60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include "Component.h"
#include <vector>
#include <functional>
#include "CPLC.h"
#include <list>
#include <map>
#include "Recipe.h"
 
 
#define ER_NOERROR            0
#define ER_NOTSELECT        -1
#define ER_BUSY                -2
 
#define STATE_READY            0        /* ¾ÍÐ÷ */
#define STATE_RUNNING        1        /* ÔËÐÐÖР*/
#define STATE_STOP            2        /* Í£Ö¹ */
#define STATE_ERROR            3        /* ·¢Éú¹ÊÕÏ */
 
 
typedef std::function<void(void* pFrom, int)> ONBONDSTATECHANGED;
typedef std::function<void(void* pFrom, int)> ONPLCSTATECHANGED;
typedef std::function<void(void* pFrom, int)> ONCIMSTATECHANGED;
typedef std::function<void(void* pFrom, const char* pszAddr, int port, int)> ONEFEMSTATECHANGED;
typedef std::function<void(void* pFrom, void*)> ONRECVBROADCAST;
 
typedef struct _BondListener
{
    ONBONDSTATECHANGED        onStateChanged;
    ONPLCSTATECHANGED        onPlcStateChanged;
    ONCIMSTATECHANGED        onCimStateChanged;
    ONEFEMSTATECHANGED        onEfemStateChanged;
    ONRECVBROADCAST            onRecvBroadcast;
} BondListener;
 
class CBonder
{
public:
    CBonder();
    virtual ~CBonder();
 
 
public:
    void setListener(BondListener& listener);
    void setWorkDir(const char* pszWorkDir);
    const std::vector<CComponent*>& getComponents();
    int init();
    int term();
    void sendBroadcast(CComponent* pSender, CIntent* pIntent);
    void onRecvBroadcast(CComponent* pSender, CIntent* pIntent);
    int start();
    int stop();
    int clearError();
    BOOL isRunning();
    ULONGLONG getRunTime();
    void onTimer(UINT nTimerid);
    int save();
    int read(const char* pszFilepath);
    void setUnitId(const char* pszUnitId);
    void setEquipmentModelType(const char* pszModelType);
    void setSoftRev(const char* pszSoftRev);
    CComponent* GetComponent(const char* pszName);;
    int getRecipeList();
    int getRecipeListInBlock(BEQ::IEquipment* pEquipment, BEQ::IUnit* pUnit);
    int runRecipe(BEQ::IUnit* pUnit, int id);
    UINT GetRecipeListThreadFunction(BEQ::IEquipment* pEquipment, BEQ::IUnit* pUnit);
    int loadReady(BEQ::IUnit* pUnit, const char* pszMaterielId, const char* pszRecipeId);
    int loadComplete(BEQ::IUnit* pUnit, int layer);
    int unloadComplete(BEQ::IUnit* pUnit, int layer);
 
public:
    int writeInt(int unitId, int addr, int value);
    int writeData(MC::SOFT_COMPONENT softComponent, unsigned int addr,
        const char* pszData, unsigned int length, ONWRITE funOnWrite);
    int readData(MC::SOFT_COMPONENT softComponent, unsigned int addr,
        unsigned int length, ONREADDATA funOnRead);
    BOOL readDataBlocking(HANDLE hEvent, MC::SOFT_COMPONENT softComponent, unsigned int addr,
        unsigned int readLen, char* pszBuffer);
 
private:
    inline void Lock() { EnterCriticalSection(&m_criticalSection); }
    inline void Unlock() { LeaveCriticalSection(&m_criticalSection); }
    void AddComponent(CComponent* pComponent);
    void Serialize(CArchive& ar);
    unsigned int getSystemByte();
    const char* getCeidDataId();
    CRecipe* getRecipe(int id);
    void clearRecipes();
 
public:
    BEQ::IEquipment* getEquipment();
    BEQ::IUnit* getUnit(int index);
    std::string& getCurRecipeName();
 
private:
    std::string m_strWorkDir;
    std::vector<CComponent*> m_components;
    int m_state;
    ULONGLONG m_ullRunTime;
    ULONGLONG m_ullStartTick;
    CRITICAL_SECTION m_criticalSection;
    BondListener m_listener;
 
private:
    std::string m_strFilepath;
    std::string m_strUnitId;
    std::string m_strEquipmentModelType;
    std::string m_strSoftRev;
    BOOL m_bAreYouThereRequest;
 
private:
    char* m_pPlcData;
    BEQ::IEquipment* m_pEquipment;
    std::map<int, CRecipe*> m_recipes;
    std::string m_strCurRecipeName;
};