LAPTOP-SNT8I5JK\Boounion
2025-09-20 5909ef662dca45ce0fd9c2217f7c185225c2bf0c
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include "stdafx.h"
#include "CPortStatusReport.h"
#include "ToolUnits.h"
#include "Common.h"
#include "Log.h"
 
 
namespace SERVO {
    CPortStatusReport::CPortStatusReport()
    {
        m_nPortStatus = 0;
        m_nCassetteSequenceNo = 0;
        m_nLoadingCassetteType = 0;
        m_nQTimeFlag = 0;
        m_nCassetteMappingState = 0;
        m_nCassetteStatus = 0;
    }
 
    CPortStatusReport::~CPortStatusReport()
    {
 
    }
 
    void CPortStatusReport::copyEx(CPortStatusReport& other)
    {
        m_nPortStatus = other.m_nPortStatus;
        m_nCassetteSequenceNo = other.m_nCassetteSequenceNo;
        m_strCassetteID = other.m_strCassetteID;
 
        // Job Existence Slot
        if (PORT_INUSE == m_nPortStatus) {
            for (int i = 0; i < 12; i++) {
                m_nJobExistenceSlot[i] = other.m_nJobExistenceSlot[i];
            }
        }
 
        if (!m_strCassetteID.empty()) {
            m_nLoadingCassetteType = other.m_nLoadingCassetteType;
        }
 
        if (PORT_UNLOAD_READY == m_nPortStatus) {
            m_nQTimeFlag = other.m_nQTimeFlag;
        }
 
        m_nCassetteMappingState = other.m_nCassetteMappingState;
        m_nCassetteStatus = other.m_nCassetteStatus;
    }
 
    short CPortStatusReport::getPortStatus()
    {
        return m_nPortStatus;
    }
 
    void CPortStatusReport::setPortStatus(short status)
    {
        m_nPortStatus = status;
    }
 
    short CPortStatusReport::getCassetteSequenceNo()
    {
        return m_nCassetteSequenceNo;
    }
 
    std::string& CPortStatusReport::getCassetteId()
    {
        return m_strCassetteID;
    }
 
    short CPortStatusReport::getLoadingCassetteType()
    {
        return m_nLoadingCassetteType;
    }
 
    short CPortStatusReport::getQTimeFlag()
    {
        return m_nQTimeFlag;
    }
 
    short CPortStatusReport::getCassetteMappingState()
    {
        return m_nCassetteMappingState;
    }
 
    short CPortStatusReport::getCassetteStatus()
    {
        return m_nCassetteStatus;
    }
 
    int CPortStatusReport::serialize(char* pszBuffer, int nBufferSize)
    {
        if (nBufferSize < 32 * 2) return -1;
 
        int index = 0;
        memcpy(&pszBuffer[index], &m_nPortStatus, sizeof(short));
        index += sizeof(short);
 
        memcpy(&pszBuffer[index], &m_nCassetteSequenceNo, sizeof(short));
        index += sizeof(short);
 
        int strLen = min(20, m_strCassetteID.size());
        memcpy(&pszBuffer[index], m_strCassetteID.c_str(), strLen);
        index += 20;
 
        memcpy(&pszBuffer[index], &m_nJobExistenceSlot[0], sizeof(short));
        index += 12 * sizeof(short);
 
        memcpy(&pszBuffer[index], &m_nLoadingCassetteType, sizeof(short));
        index += sizeof(short);
 
        memcpy(&pszBuffer[index], &m_nQTimeFlag, sizeof(short));
        index += sizeof(short);
 
        memcpy(&pszBuffer[index], &m_nCassetteMappingState, sizeof(short));
        index += sizeof(short);
 
        memcpy(&pszBuffer[index], &m_nCassetteStatus, sizeof(short));
        index += sizeof(short);
 
        return 32 * 2;
    }
 
    int CPortStatusReport::unserialize(const char* pszBuffer, int nBufferSize)
    {
        if (nBufferSize < 32 * 2) return -1;
 
        int index = 0;
        memcpy(&m_nPortStatus, &pszBuffer[index], sizeof(short));
        index += sizeof(short);
 
        memcpy(&m_nCassetteSequenceNo, &pszBuffer[index], sizeof(short));
        index += sizeof(short);
 
        CToolUnits::convertString(&pszBuffer[index], 20, m_strCassetteID);
        index += 20;
 
        memcpy(&m_nJobExistenceSlot[0], &pszBuffer[index], sizeof(short));
        index += 12 * sizeof(short);
 
        memcpy(&m_nLoadingCassetteType, &pszBuffer[index], sizeof(short));
        index += sizeof(short);
 
        memcpy(&m_nQTimeFlag, &pszBuffer[index], sizeof(short));
        index += sizeof(short);
 
        memcpy(&m_nCassetteMappingState, &pszBuffer[index], sizeof(short));
        index += sizeof(short);
 
        memcpy(&m_nCassetteStatus, &pszBuffer[index], sizeof(short));
        index += sizeof(short);
 
        return 32 * 2;
    }
 
    void CPortStatusReport::getAttributeVector(CAttributeVector& attrubutes, int beginWeight)
    {
        unsigned int weight = beginWeight;
        std::string strTemp;
 
        attrubutes.addAttribute(new CAttribute("PortStatus",
            std::to_string(m_nPortStatus).c_str(), "", weight++));
 
        attrubutes.addAttribute(new CAttribute("CassetteSequenceNo",
            std::to_string(m_nCassetteSequenceNo).c_str(), "", weight++));
 
        attrubutes.addAttribute(new CAttribute("CassetteID",
            m_strCassetteID.c_str(), "", weight++));
 
        attrubutes.addAttribute(new CAttribute("LoadingCassetteType",
            std::to_string(m_nLoadingCassetteType).c_str(), "", weight++));
 
        attrubutes.addAttribute(new CAttribute("QTimeFlag",
            std::to_string(m_nQTimeFlag).c_str(), "", weight++));
 
        attrubutes.addAttribute(new CAttribute("CassetteMappingState",
            std::to_string(m_nCassetteMappingState).c_str(), "", weight++));
 
        attrubutes.addAttribute(new CAttribute("CassetteStatus",
            std::to_string(m_nCassetteStatus).c_str(), "", weight++));
    }
 
    void CPortStatusReport::serialize(CArchive& ar)
    {
        if (ar.IsStoring()) {
            ar << m_nPortStatus;
            ar << m_nCassetteSequenceNo;
            WriteString(ar, m_strCassetteID);
            for (int i = 0; i < 12; i++) {
                ar << m_nJobExistenceSlot[i];
            }
            ar << m_nLoadingCassetteType;
            ar << m_nQTimeFlag;
            ar << m_nCassetteMappingState;
            ar << m_nCassetteStatus;
        }
        else {
            ar >> m_nPortStatus;
            ar >> m_nCassetteSequenceNo;
            ReadString(ar, m_strCassetteID);
            for (int i = 0; i < 12; i++) {
                ar >> m_nJobExistenceSlot[i];
            }
            ar >> m_nLoadingCassetteType;
            ar >> m_nQTimeFlag;
            ar >> m_nCassetteMappingState;
            ar >> m_nCassetteStatus;
        }
    }
 
    bool CPortStatusReport::canPickFromPort()
    {
        // 1. Port ×´Ì¬±ØÐëÊÇ Load Ready£¨ÉÏÁÏÇëÇó£©
        if (m_nPortStatus != PORT_LOAD_REQUEST) return false;
 
        // 2. Cassette ×´Ì¬±ØÐë²»ÊÇ¡°ÎÞºÐ×Ó¡±£¬Ó¦ÎªµÈ´ý¿ªÊ¼»ò´¦ÀíÖеÈ
        if (m_nCassetteStatus == CASSETTE_NO_EXIST || m_nCassetteStatus == CASSETTE_PROCCESS_PAUSED)
            return false;
 
        // 3. Cassette ID ²»¿ÉΪ¿Õ
        if (m_strCassetteID.empty()) return false;
 
        // 4. ÖÁÉÙÒ»¸öSlot´æÔÚ²£Á§
        if (!isJobExistenceSlot()) return false;
 
        // 5. Mapping״̬±ØÐëÒÑʹÓÃ
        if (m_nCassetteMappingState != 1) return false;
 
        // 6. Cassette ÀàÐͱØÐëÊÇÓÐЧºÐ×Ó
        if (m_nLoadingCassetteType != 1) return false;
 
        return true;
    }
 
    bool CPortStatusReport::isJobExistenceSlot()
    {
        for (int i = 0; i < 12; i++) {
            if (m_nJobExistenceSlot[i] != 0) return true;
        }
 
        return false;
    }
 
    short CPortStatusReport::getJobExistenceSlot()
    {
        return m_nJobExistenceSlot[0];
    }
 
    void CPortStatusReport::setJobExistenceSlot(short map)
    {
        m_nJobExistenceSlot[0] = map;
    }
 
    void CPortStatusReport::setCassetteId(const char* pszId)
    {
        m_strCassetteID = pszId;
    }
 
    void CPortStatusReport::WriteString(CArchive& ar, std::string& string)
    {
        CString strTemp = string.c_str();
        ar << strTemp;
    }
 
    void CPortStatusReport::ReadString(CArchive& ar, std::string& string)
    {
        CString strTemp;
        ar >> strTemp;
        string = (LPTSTR)(LPCTSTR)strTemp;
    }
}