Project

General

Profile

Feature #3478 » pac3Plug.cpp

yufeng wu, 09/11/2024 03:14 PM

 
1
// pac3Plug.cpp: implementation of the CPac3Plug class.
2
//
3
//////////////////////////////////////////////////////////////////////
4

    
5
#include "stdafx.h"
6
#include "pac3Plug.h"
7
#include "se_rbac.h"
8

    
9
//#include "se_btl.h"
10

    
11
#ifdef _DEBUG
12
#undef THIS_FILE
13
static char THIS_FILE[]=__FILE__;
14
#define new DEBUG_NEW
15
#endif
16

    
17

    
18
/////////////////////////////////////////////////////////////////////////
19

    
20
extern "C" __declspec(dllexport) void StartBroadcast(PASelectParam * pParam, void *pPlugin)
21
{
22
/*
23
    char s1[36];
24
    unsigned int tmpV = pParam->stationNo[0] + (unsigned int)pParam->stationNo[1] * 256
25
        + (unsigned int)pParam->stationNo[2] * 65536 + (unsigned int)pParam->stationNo[3] * 16777216;
26
    itoa(tmpV, s1, 2);
27
    m_logger->WriteFmtStrWithTime_L3("Station Select Low : %s", s1);
28

    
29
    tmpV = pParam->stationNo[4] + (unsigned int)pParam->stationNo[5] * 256
30
        + (unsigned int)pParam->stationNo[6] * 65536 + (unsigned int)pParam->stationNo[7] * 16777216;
31
    itoa(tmpV, s1, 2);
32
    m_logger->WriteFmtStrWithTime_L3("Station Select High : %s", s1);
33

    
34
    tmpV = pParam->zone[0] + (unsigned int)pParam->zone[1] * 256;
35
    itoa(tmpV, s1, 2);
36
    m_logger->WriteFmtStrWithTime_L3("Zone Select : %s", s1);
37
*/
38
	CPlugPAC3 *pPlug = (CPlugPAC3 *)pPlugin;
39
    if (NULL == pPlug)
40
        return;
41

    
42
    uint32 stationNo_low = 0;
43
    uint32 stationNo_High = 0;
44
    uint16 zoneV = 0;
45

    
46
    uint i;
47
    for (i=0; i<4+4; i++)//WYF 20190322 ????bug
48
    {
49
        uint32 tmpV = pParam->stationNo[i];
50
        if (i < 4) {
51
            tmpV = tmpV << (i*8);
52
            stationNo_low += tmpV;
53
        }
54
        else {
55
            int j = i - 4;
56
            tmpV = tmpV << (j*8);
57
            stationNo_High += tmpV;
58
        }
59
    }
60
    if (stationNo_low == 0 && stationNo_High == 0)
61
        return;
62

    
63
    zoneV = pParam->zone[0] + (uint16)(pParam->zone[1]) * 256;
64
    if (zoneV == 0)
65
        return;
66

    
67
    pPlug->m_csiServer.PA_BeginSelect();
68
    pPlug->m_csiServer.PA_Login(pPlug->m_nKeyID);
69
    pPlug->m_csiServer.PA_SelectZone(stationNo_low, stationNo_High, zoneV);
70
    int nRet = pPlug->m_csiServer.PA_Mike();
71
}
72

    
73
extern "C" __declspec(dllexport) void StopBroadcast(PASelectParam * pParam, void *pPlugin)
74
{
75
    CPlugPAC3 *pPlug = (CPlugPAC3 *)pPlugin;
76
    if (NULL == pPlug)
77
        return;
78
    
79
    uint32 stationNo_low = 0;
80
    uint32 stationNo_High = 0;
81
    uint16 zoneV = 0;
82
    
83
    uint i;
84
    for (i=0; i<4+4; i++)//WYF 20190322 ????bug
85
    {
86
        uint32 tmpV = pParam->stationNo[i];
87
        if (i < 4) {
88
            tmpV = tmpV << (i*8);
89
            stationNo_low += tmpV;
90
        }
91
        else {
92
            int j = i - 4;
93
            tmpV = tmpV << (j*8);
94
            stationNo_High += tmpV;
95
        }
96
    }
97
    if (stationNo_low == 0 && stationNo_High == 0)
98
        return;
99
    
100
    zoneV = pParam->zone[0] + (uint16)(pParam->zone[1]) * 256;
101
    if (zoneV == 0)
102
        return;
103
    
104
    pPlug->m_csiServer.PA_BeginSelect();
105
    pPlug->m_csiServer.PA_Login(pPlug->m_nKeyID);
106
    pPlug->m_csiServer.PA_SelectZone(stationNo_low, stationNo_High, zoneV);
107
    int nRet = pPlug->m_csiServer.PA_Stop(1);
108
}
109

    
110

    
111
//////////////////////////////////////////////////////////////////////
112
// Construction/Destruction
113

    
114
CPlugPAC3::CPlugPAC3(LPVOID lpParam)
115
: m_hDll(NULL), m_flushTime(1000), m_nTimerGetStatus(0)
116
{
117
    memset(&m_paStatus, 0, sizeof(PAStatus));
118

    
119
    m_logger = new Logger("PAC3", "plugin_paC3.log");
120

    
121
    // ??ʼ??Ȩ??????
122
    uint32 nPLevel[AOJ_K_MAX_CTRLPRIO];	// 0-Switch;1-PTZ;2-PA
123
    char szRoleName[256];
124
    RBAC_Initialize();
125
    AOJ_Initialize();
126
    RBAC_GetUserRoleDescription(NULL, NULL, NULL, szRoleName);
127
    RBAC_GetRolePLevel(szRoleName, nPLevel);
128
    m_nKeyID = nPLevel[2];
129
	memset(m_rdbPara, 0 , sizeof(m_rdbPara));
130
}
131

    
132
CPlugPAC3::~CPlugPAC3()
133
{
134
    //if (0 != m_nTimerGetStatus)
135
    //{
136
     //   ::KillTimer(this->m_hWnd, m_nTimerGetStatus);
137
      //  m_nTimerGetStatus = 0;
138
    //}
139

    
140
    if (NULL != m_hDll) {
141
        PAUIDLL_CloseDialog CloseDialog = (PAUIDLL_CloseDialog)GetProcAddress(m_hDll, "CloseDialog");
142
        if (NULL != CloseDialog)
143
            CloseDialog(m_hWndFather);
144
        FreeLibrary(m_hDll);
145
    }
146

    
147
	if (m_logger != NULL)
148
	{
149
		delete m_logger;
150
		m_logger = NULL;
151
	}
152
}
153

    
154
BOOL CPlugPAC3::Create(CWnd * fatherWnd, RECT rect, UINT id, UINT length, LPVOID pExtData)
155
{
156
//     m_logger->WriteFmtStrWithTime_L3("fatherWnd=0x%08X, rect=(%d, %d, %d, %d), id=%d, length=%d, pExtData=0x%08X",
157
//         fatherWnd, rect.left, rect.top, rect.right, rect.bottom,
158
//         id, length, pExtData);
159

    
160
    //CWnd::Create(NULL, NULL, WS_CHILD, CRect(0, 0, 0, 0), fatherWnd, id);	
161
	if (fatherWnd == NULL)
162
		return FALSE;
163
    m_hWndFather = fatherWnd->m_hWnd;
164

    
165
    iniGroupInfo();
166

    
167
    
168
#ifdef _DEBUG
169
    strcat(m_dllName, "d.dll");
170
#else
171
    strcat(m_dllName, ".dll");
172
#endif
173
    m_hDll = LoadLibrary(m_dllName);
174
    if (NULL == m_hDll)
175
        return FALSE;
176

    
177
    getExeFuncAddr();
178

    
179
    /*
180
    RBAC_Initialize();
181
    AOJ_Initialize();
182
    RBAC_GetUserRoleDescription(NULL, NULL, NULL, szRoleName);
183
    RBAC_GetRolePLevel(szRoleName, nPLevel);
184
    m_nKeyID = nPLevel[2];
185
    */
186

    
187
    if (NULL != m_hDll) {
188
        PAUIDLL_ShowDialog ShowDialog = (PAUIDLL_ShowDialog)GetProcAddress(m_hDll, "ShowDialog");
189
        if (NULL != ShowDialog) {
190
            UIParamSet uiParam;
191
            uiParam.hParent = m_hWndFather;
192
            uiParam.pos_x = rect.left;
193
            uiParam.pos_y = rect.top;
194
            uiParam.width = rect.right-rect.left;
195
            uiParam.height = rect.bottom-rect.top;
196
            ShowDialog(&uiParam, &m_paParamSet, &m_paAreaSet, this);
197
        }
198
    }
199

    
200
    //m_nTimerGetStatus = ::SetTimer(this->m_hWnd, TIMERID_GetStatus, m_flushTime, GetStatusProc);
201
    return TRUE;
202
}
203

    
204
BOOL CPlugPAC3::MovePlugRect(RECT rect)
205
{
206
    /*
207
    if (NULL != m_hDll)
208
    {
209
        PAUIDLL_MoveDialog MoveDialog = (PAUIDLL_MoveDialog)GetProcAddress(m_hDll, "MoveDialog");
210
        if (MoveDialog) {
211
            UIParamSet uiParam;
212
            uiParam.hParent = m_hWndFather;
213
            uiParam.pos_x = rect.left;
214
            uiParam.pos_y = rect.top;
215
            uiParam.width = rect.right-rect.left;
216
            uiParam.height = rect.bottom-rect.top;
217
            MoveDialog(&uiParam);
218
        }
219
    }
220
    */
221
	return TRUE;
222
}
223

    
224
void CPlugPAC3::Draw(CDC *pDC, RECT rect)
225
{
226
}
227

    
228
BOOL CPlugPAC3::ShowProperty(void *pData, int *len)
229
{
230
	return TRUE;
231
}
232

    
233
void * CPlugPAC3::GetExData()
234
{
235
	return NULL;
236
}
237

    
238
UINT CPlugPAC3::GetExDataLength()
239
{
240
	return 0;
241
}
242

    
243
/*
244
void CPlugPAC3::SetParam(int paramID, void *pData)
245
{
246
    if (0 != paramID)
247
        return;
248

    
249
    if (NULL != m_pDlg)
250
        m_pDlg->SetParam(pData);
251
}
252
*/
253

    
254
void CPlugPAC3::iniGroupInfo()
255
{
256
//     int nRE = SEDB_StartDB();
257
//     RBAC_Initialize();
258
    
259
    memset(&m_paParamSet, 0, sizeof(PAParamSet));
260
    
261
    SEDB_CMDINFO cmdinfo;
262
    char cmdbuf[1256] = {0};
263
    sprintf(cmdinfo.table, "%s.dbo.%s", "SEMODEL", "TB1001_GROUP");
264
    strcpy(cmdbuf, "select ");
265
    char * fieldCodes[] = {"F1001_GROUPCODE", "F1001_GROUPDESC", "F1001_GROUPNO"}; //201=??վ
266
    int i;
267
    for (i=0; i<sizeof(fieldCodes)/sizeof(char *); i++){
268
        strcat(cmdbuf, fieldCodes[i]);
269
        if ( i < (sizeof(fieldCodes)/sizeof(char *)-1) )
270
            strcat(cmdbuf, ",");
271
    }
272
    strcat(cmdbuf, " from ");
273
    strcat(cmdbuf, cmdinfo.table);
274
    strcat(cmdbuf, " where F1005_DEVTYPEID=201 and F1001_GROUPCODE<>'0' ");//??????order by F1001_GROUPNO");//???ݿ??????п??ܻ????????Ϊ0?ij?վ,??Ҫ????
275
    
276
    CSE_DBOption dboption;
277
    dboption.BeginSelectRcdSet(cmdbuf);
278
    int grpNum = dboption.GetRcdCount();
279
    if (grpNum <= 0) {
280
        dboption.EndSelectRcdSet();
281
        return;
282
    }
283
    m_paParamSet.groupNum = grpNum > MaxNum_Group ? MaxNum_Group : grpNum;
284
    for (i=0; i<m_paParamSet.groupNum; i++)
285
    {
286
        strncpy(m_paParamSet.groupsInfo[i].code, (char *)dboption.GetColVal(i,0), MaxLen_CODE-1);
287
        strncpy(m_paParamSet.groupsInfo[i].desc, (char *)dboption.GetColVal(i,1), MaxLen_DESC-1);
288
        m_paParamSet.groupsInfo[i].groupNo = (int)dboption.GetIntVal(i,2);
289
    }
290
    dboption.EndSelectRcdSet();
291

    
292
	//??ȡ???????????? yansx 2019-01-24
293
    GetPAAreaInfo();
294

    
295
//     SEDB_EndDB();
296
    
297
    readIni();
298

    
299
	//????ʵʱ???ѯ?ֶ?m_rdbPara
300
	for (int ii = 0; ii < m_paParamSet.groupNum; ii++)
301
	{
302
		strcpy(m_rdbPara[ii].tbl, DAC_TBLNAME_DI);
303
		strcpy(m_rdbPara[ii].obj, m_paParamSet.groupsInfo[ii].status_code);
304
		strcpy(m_rdbPara[ii].field, "Value");
305
	}
306
	for (int jj = m_paParamSet.groupNum; jj < m_paParamSet.groupNum+m_paParamSet.chanNum; jj++)
307
	{
308
		strcpy(m_rdbPara[jj].tbl, DAC_TBLNAME_DI);
309
		strcpy(m_rdbPara[jj].obj, m_paParamSet.chansInfo[jj-m_paParamSet.groupNum].code);
310
		strcpy(m_rdbPara[jj].field, "Value");
311
	}
312
}
313

    
314
void CPlugPAC3::GetPAAreaInfo() //??ȡPA??????Ϣ
315
{
316
	CSE_DBOption dboption;
317
	char cmdbuf[256];
318

    
319
	memset(&m_paAreaSet, 0, sizeof(PAAreaParamSet));
320

    
321
    strcpy(cmdbuf, "select F1002_BAYAREACODE,F1002_BAYAREADESC,F1002_ASSIGNMENT from SEMODEL.TB1002_BAYAREA \
322
		where F1002_BAYAREA = 1 and rownum < 9 order by F1002_ASSIGNMENT");//=1 ??ʾ??PA???? ???ֵ?ǹ̶??? Ŀǰ????ֻ֧?????8??????
323
	int ret=dboption.BeginSelectRcdSet(cmdbuf);
324

    
325
	if(ret!=SEDB_SUCCESS)
326
		return;
327
	
328
    int count= dboption.GetRcdCount();
329
	if(count<=0)
330
	{
331
		dboption.EndSelectRcdSet();
332
		return ;
333
	}
334
	m_paAreaSet.nTotalArea = count;
335
    for (int i=0; i<count; i++)
336
    {
337
        strncpy(m_paAreaSet.paAreaList[i].areaCode, (char *)dboption.GetColVal(i,0), MaxLen_CODE-1);
338
        strncpy(m_paAreaSet.paAreaList[i].desc, (char *)dboption.GetColVal(i,1), MaxLen_DESC-1);
339
        m_paAreaSet.paAreaList[i].nCodeIndex = (int)dboption.GetIntVal(i,2);
340
    }
341
	
342
    dboption.EndSelectRcdSet();
343
}
344

    
345
void CPlugPAC3::readIni()
346
{
347
    char *home = getenv("SEROOT");
348
    if (NULL == home)
349
        return;
350
    char filename[256] = {0};
351
    sprintf(filename, "%s%s", home, "\\cfg\\PAUISet.ini");
352
    
353
    CReadConf readconf;
354

    
355
    memset(m_dllName, 0, 32*sizeof(char));
356
    readconf.ReadString("General", "UILibrary", m_dllName, filename, "");
357
    if (strlen(m_dllName) == 0)
358
        return;
359

    
360
    int nGrpNum = readconf.ReadLong("General", "StationNum", filename, "0");
361
    m_paParamSet.chanNum = 2;
362

    
363
    readconf.ReadString("General", "LineColor", m_paParamSet.strSubwayLineColor, filename, "0,148,216,0");
364

    
365
    char sectionName[16];
366
    int i;
367
    char sValue[MaxLen_CODE];
368
    for (i=0; i<nGrpNum; i++)
369
    {
370
        memset(sectionName, 0, 16);
371
        sprintf(sectionName, "Station%d", i+1);
372

    
373
        memset(sValue, 0, MaxLen_CODE);
374
        readconf.ReadString(sectionName, "StationCode", sValue, filename, "");
375
        for (int j=0; j<m_paParamSet.groupNum; j++)
376
        {
377
            if (0 == strcmp(sValue, m_paParamSet.groupsInfo[j].code))
378
            {
379
                readconf.ReadString(sectionName, "BCStatusCode", m_paParamSet.groupsInfo[j].status_code, filename, "");
380
                break;
381
            }
382
        }
383
    }
384
    int nRealGrpNum = m_paParamSet.groupNum;
385
    for (i=0; i<m_paParamSet.groupNum; i++)
386
    {
387
        if (0 == strlen(m_paParamSet.groupsInfo[i].status_code)) {
388
            for (int j=i+1; j<nRealGrpNum; j++)
389
            {
390
                memcpy(&(m_paParamSet.groupsInfo[j-1]), &(m_paParamSet.groupsInfo[j]), sizeof(GroupInfo));
391
            }
392
            nRealGrpNum--;
393
        }
394
    }
395
    m_paParamSet.groupNum = nRealGrpNum;
396

    
397

    
398
    for (i=0; i<m_paParamSet.chanNum; i++)
399
    {
400
        memset(sectionName, 0, 16);
401
        sprintf(sectionName, "Channel%d", i+1);
402

    
403
        readconf.ReadString(sectionName, "ChannelCode", m_paParamSet.chansInfo[i].code, filename, "");
404
    }
405

    
406
    m_flushTime = readconf.ReadLong("General", "ValueFlushMilliseconds", filename, "2000");
407

    
408
	m_paParamSet.flushTime = m_flushTime;
409
    m_paParamSet.broadcastTime = readconf.ReadLong("General", "BroadcastSeconds", filename, "0");	//??ʼ?㲥????ʱ????
410
	m_paParamSet.channelVisiable = readconf.ReadLong("General", "ChannelIsVisible", filename, "1");
411
	m_paParamSet.stopBroadBtnLockTime = readconf.ReadLong("General", "StopBroadBtnLockSeconds", filename, "2");	//Ĭ??2??
412
	if (m_paParamSet.stopBroadBtnLockTime <= 0 || m_paParamSet.stopBroadBtnLockTime > m_paParamSet.broadcastTime)
413
	{
414
		m_paParamSet.stopBroadBtnLockTime = 2;
415
	}
416
}
417

    
418
void CPlugPAC3::getExeFuncAddr()
419
{
420
    m_paParamSet.funcStartMike = StartBroadcast;
421
    m_paParamSet.funcStopMike = StopBroadcast;
422
	m_paParamSet.funcUpdateUiState = UpdateUiState;
423
}
424

    
425

    
426
//void CALLBACK GetStatusProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
427
extern "C" __declspec(dllexport) void UpdateUiState(void *pPlugin)
428
{
429
	CPlugPAC3 *pPlug = (CPlugPAC3 *)pPlugin;
430
	if (NULL == pPlug)
431
		return;
432
	memset(pPlug->m_paStatus.broadcast_status, 0, sizeof(pPlug->m_paStatus.broadcast_status));
433
	pPlug->m_paStatus.channel_status = 0;
434
    CRdbCltAccess sqlPaDataGet;	
435
	SREALDB_VAR rdbData;
436
	BOOL bValue = FALSE;
437
	int jj = 0, valNum = 0, byte_index = 0, tmp = 0;
438
	BYTE bit_index = 0;
439
	BYTE * p = NULL;
440
	sqlPaDataGet.SetUserPwd("guest", "");
441
	int allNum = pPlug->m_paParamSet.groupNum + pPlug->m_paParamSet.chanNum;
442
	valNum = sqlPaDataGet.SendGetDataPara(allNum, pPlug->m_rdbPara);
443
	//վ??
444
	for (jj = 0; jj < valNum; jj++)
445
	{
446
		tmp = sqlPaDataGet.GetVal(jj, &rdbData);
447
		if (tmp < 0 || tmp >= allNum)
448
		{
449
			continue;
450
		}
451
		bValue = (rdbData.m_val.intval == 1) ? TRUE : FALSE;
452
		if (tmp < pPlug->m_paParamSet.groupNum)
453
		{
454
			byte_index = tmp / 8;
455
			bit_index = tmp % 8;
456
			p = (BYTE *)(&(pPlug->m_paStatus.broadcast_status[byte_index]));
457
			Utility::SetValueToW(p, bit_index, bValue);
458
		}
459
		else
460
		{
461
			tmp -= pPlug->m_paParamSet.groupNum;
462
			p = (BYTE *)(&(pPlug->m_paStatus.channel_status));
463
			bit_index = tmp % 8;	
464
			Utility::SetValueToW(p, bit_index, bValue);
465
		}
466
	}
467
	
468
   /* 
469
    CRdbSqlAccess sqlAccessDI;
470
    sqlAccessDI.OptTbl(DAC_TBLNAME_DI);
471
    sqlAccessDI.ClearOldCond();
472
    sqlAccessDI.SelectCol("PointCode");
473
    sqlAccessDI.SelectCol("Value");
474
    BYTE bAppSysID = 11;
475
    sqlAccessDI.SetCond("AppSysId", REALDB_UCHAR, &bAppSysID); // ?㲥
476
    sqlAccessDI.SetUserPwd("guest", "");				
477
	int nRet = sqlAccessDI.ExecSelect();
478
    if (0 == nRet)
479
    {
480
        int nCount = sqlAccessDI.GetRcdCount();
481
        char point_code[MaxLen_CODE];
482
        for (int i=0; i<nCount; i++)
483
        {
484
            memset(point_code, 0, sizeof(char)*MaxLen_CODE);
485
            strcpy(point_code, sqlAccessDI.GetString(i, "PointCode"));
486
            UINT nValue = sqlAccessDI.GetUIntVal(i, "Value");
487
            BOOL bValue = (nValue == 1) ? TRUE : FALSE;
488

    
489
            int j;
490
            for (j=0; j<pCurCPlugPAC3->m_paParamSet.groupNum; j++)
491
            {
492
                if (0 == strcmp(pCurCPlugPAC3->m_paParamSet.groupsInfo[j].status_code, point_code))
493
                {
494
                    int byte_index = j / 8;
495
                    BYTE bit_index = j % 8;
496
                    BYTE * p = (BYTE *)(&(pCurCPlugPAC3->m_paStatus.broadcast_status[byte_index]));
497
                    Utility::SetValueToW(p, bit_index, bValue);
498
                    break;
499
                }
500
            }
501
            for (j=0; j<pCurCPlugPAC3->m_paParamSet.chanNum; j++)
502
            {
503
                if (0 == strcmp(pCurCPlugPAC3->m_paParamSet.chansInfo[j].code, point_code))
504
                {
505
                    BYTE bit_index = j % 8;
506
                    BYTE * p = (BYTE *)(&(pCurCPlugPAC3->m_paStatus.channel_status));
507
                    Utility::SetValueToW(p, bit_index, bValue);
508
                    break;
509
                }
510
            }
511
        }
512
    }
513
*/
514
    if (NULL != pPlug->m_hDll)
515
    {
516
        PAUIDLL_SetStatus SetStatusValue = (PAUIDLL_SetStatus)GetProcAddress(pPlug->m_hDll, "SetStatus");
517
        if (SetStatusValue) {
518
            SetStatusValue(pPlug->m_hWndFather, &(pPlug->m_paStatus));
519
        }
520
    }
521
}
522

    
(5-5/5)