You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.7 KiB
C++

// widgets.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include "baohua.h"
#include "buban103.h"
#include "buban104.h"
#include "scadaprotect.h"
// 网络端口数据,范围为 0 - 16
#define NET_PORT_NUM 8
extern const char *gpStrBuban103ConfigInfo[];
extern const char *gpStrBuban104ConfigInfo[];
extern const char *gpStrScadaProtectConfigInfo[];
u_char Bit_8_Mask[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
BYTE SyncWordEB[6] = { 0xeb, 0x90, 0xeb, 0x90, 0xeb, 0x90 };
BYTE SyncWordD7[6] = { 0xd7, 0x09, 0xd7, 0x09, 0xd7, 0x09 };
FUNCTION_CALL FunctionCall[] =
{
// 配置一空协议, 主要用于处理协议序列为零的情况, 如零初始值等
{(char*)"none", (char*)"none", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
// 旁路协议,用于在上位机调试规约程序
{(char*)"bypass", (char*)"bypass", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
// BUBAN103规约
{(char*)"BUBAN103", (char*)"BUBAN103 protocol", NULL, Buban103ReadConfig,\
Buban103RecvData, Buban103Timer, Buban103YkYtProcess, Buban103SendSystemTime,\
Buban103Exit, Buban103BaoHuCmdProcess, Buban103GetBaohuDataBase},
// BUBAN104规约
{(char*)"BUBAN104", (char*)"BUBAN104 protocol", NULL, Buban104ReadConfig,\
Buban104RecvData, Buban104Timer, Buban104YkYtProcess, Buban104SendSystemTime,\
Buban104Exit, Buban104BaoHuCmdProcess, Buban104GetBaohuDataBase},
// SCADAPROTECT规约
{(char*)"SCADAPROTECT", (char*)"SCADA INSIDE", NULL, ScadaProtectReadConfig,\
ScadaProtectRecvData, ScadaProtectTimer, ScadaProtectYkYtProcess, NULL,\
ScadaProtectExit, ScadaProtectBaoHuCmdProcess, ScadaProtectGetBaohuDataBase},
// 添加协议名称及处理程序入口等
{(char*)" ", (char*)" ", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // 结束标志
};
int InitBaohuMainFlag = 0;
//int testcnt = 0;
//char testbuf[] = "1234567890";
void BaohuLibMain(int netportnum);
int main(void)
{
std::cout << "Hello World!\n";
int ret = SUCCESS;
char filename[256];
#ifdef OS_WINDOWS
WSADATA WSAData;
#endif
//定时器指针置空
//m_pMainTimer = NULL;
//该段代码进入环境变量KERNELFEND_ROOT所指定的目录
char* envBuf;
envBuf = getenv("CAC_ROOT");
if (envBuf != NULL) //如果取得环境变量,则使用其所指定的目录
{
sprintf(IniFilePath, "%s/ini", envBuf);
}
else //如果未取得环境变量,则使用当前工作目录
{
_getcwd(IniFilePath, sizeof(IniFilePath));
}
//清空数据文件名
memset((void*)pvDataFileName, 0, sizeof(pvDataFileName));
//采用哈希表读配置文件config.ini modified by jessie in 20060729
sprintf(filename, "%s/config.ini", IniFilePath);
ret = conf_open(filename, &pvconf_handle);
if (SUCCESS != ret)
{
printf("WARN(%04d): load config.ini is failed\n", _getpid());
return -1;
}
//采用哈希表读配置文件portconfig.ini modified by jessie in 20060729
sprintf(filename, "%s/portconfig.ini", IniFilePath);
ret = conf_open(filename, &pvportconf_handle);
if (SUCCESS != ret)
{
printf("WARN(%04d): load portconfig.ini is failed\n", _getpid());
return -1;
}
// 初始化数据屏设置数据库指针
if (InitBaohuMainFlag == 0)
{
FunCallPtr = &FunctionCall[0];
strcpy(DeviceName, DEVIVE_NAME);
strcpy(Version, VERSION);
strcpy(VersionDate, VERSION_DATE);
strcpy(Manufacturer, MANUFACTURER);
InitBaohuMainFlag = 1;
#ifdef OS_WINDOWS
if (WSAStartup(MAKEWORD(2, 1), (LPWSADATA)&WSAData) != 0)
{
ret = WSAGetLastError();
//HostWSAStartupErr = TRUE;
//return FALSE;
}
#endif
}
// 测试程序,产生下发数据,正常是规约程序产生数据
// if ( testcnt != DayTime.Sec )
// {
// testcnt = DayTime.Sec;
// PutPollCmdToBuf( 0, NORMAL_CMD_TYPE, 0, testbuf, strlen(testbuf));
// }
for(;;)
BaohuLibMain(NET_PORT_NUM);
if (pvconf_handle != NULL)
{
conf_close(pvconf_handle);
pvconf_handle = NULL;
}
if (pvportconf_handle != NULL)
{
conf_close(pvportconf_handle);
pvportconf_handle = NULL;
}
if (pvdataconf_handle != NULL)
{
conf_close(pvdataconf_handle);
pvdataconf_handle = NULL;
}
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件