// Master104Demo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "master104.h"
int main (int argc, char *argv[])
{
char serverIP[128];
SYSTEMTIME systime;
///////////////////////////////////////////////////////////////////
stimeInit ();
//yw m_set_log_cfg ();
/* gs_debug_sel |= GS_LOG_FLOW; */
#if !defined (_WIN32)
{
gs_sleep_event_sem = gs_get_event_sem (SD_FALSE);
if (gs_sleep_event_sem == NULL) {
printf ("\nCreate GS_SLEEP semaphore failed, exiting...");
exit (1);
}
}
#endif /* */
printf ("Hello 104 master!\n");
GetLocalTime (&systime);
if (argc != 2) {
printf ("\n Please input : Master104Demo slaveIPaddress <enter>");
printf ("\n e.g. Master104Demo 192.168.1.100 <enter>");
return 0;
}
// Build_chSocket();
Build_IEC104link ();
Build_IEC104ASDU ();
Build_Master104 ();
sprintf (serverIP, "127.0.0.1");//"192.168.105.13"
sprintf (serverIP, argv[1]);
Init_SockServerIP (serverIP, 2404);
Init_Linkpara (30, 15, 10, 20, 12, 8);
InitLink ();
master_start (4);
Send_ASDU_Ucommand (2, CMD_USTART);
for (;;) {
Send_C_IC_NA (0); //总召唤
GS_SLEEP (20000);
Send_C_IC_NA (1); //group=0 for total calling,group=1 for calling group1.
GS_SLEEP (3000);
Send_C_CIfreeze (0); //冻结电度
GS_SLEEP (3000);
//Send_ASDU_Ucommand(0,CMD_DISCONN);
Send_C_CI_NA (0); //电度总召唤 group=0 for total calling,group=1 for calling group1.
GS_SLEEP (3000);
Send_C_CS_NA (); //时钟同步
GS_SLEEP (3000);
Send_C_RD_NA (0x4001); //读命令
GS_SLEEP (3000);
//Send_ASDU_Ucommand(0,CMD_DISCONN);
GS_SLEEP (5000);
Send_C_TS_TA (); //Test 107
GS_SLEEP (3000);
// Send_ASDU_Ucommand (2, CMD_USTOP);
// GS_SLEEP (3000);
// Send_ASDU_Ucommand (1, CMD_USTART);
// Send_C_RP_NA (0); // 0复位带时标的数据 ,1重启动
// GS_SLEEP (3000);
//Send_ASDU_Ucommand(4,CMD_USTART);
Send_C_SC_NA (0, 1, 1); //单点遥控 选择 合
GS_SLEEP (3000);
Send_C_SC_NA (0, 2, 1); //单点遥控 执行 合
GS_SLEEP (3000);
Send_C_SC_NA (0, 3, 1); //单点 撤销 合
GS_SLEEP (3000);
Send_C_DC_NA (1, 1, 1); //双点遥控 选择 合
GS_SLEEP (3000);
Send_C_DC_NA (1, 2, 1); //双点遥控 执行 合
GS_SLEEP (3000);
// Send_ASDU_Ucommand (1, CMD_USTOP);
// GS_SLEEP (3000);
// Send_ASDU_Ucommand (2, CMD_USTART);
// Send_C_DC_NA (1, 3, 1); //双点遥控 撤销 合
// GS_SLEEP (3000);
// Send_C_RC_NA (1, 1, 1); //档位 遥控 选择 升
// GS_SLEEP (3000);
// Send_C_RC_NA (1, 2, 1); //档位 遥控 执行 升
// GS_SLEEP (3000);
//Send_ASDU_Ucommand(2,CMD_DISCONN);
Send_C_SE_NA (0, 2, 0x1234); //规一化遥调
GS_SLEEP (3000);
Send_C_SE_NC (0, 2, (_float) 12.34); //短浮点遥调
GS_SLEEP (3000);
//Send_ASDU_Ucommand(1,CMD_ALLRESETCONN);
Send_P_ME_NA (0, 1, 0x2345); //规一化参数下装
GS_SLEEP (3000);
Send_P_ME_NC (0, 1, (_float) 23.45); //短浮点参数下装
GS_SLEEP (3000);
}
master_close ();
CloseLink ();
UnBuild_Master104 ();
UnBuild_IEC104ASDU ();
UnBuild_IEC104link ();
// UnBuild_chSocket();
/////////////////////////////////////////////////
#if !defined (_WIN32)
gs_free_event_sem (gs_sleep_event_sem);
#endif /* */
gs_timer_cleanup ();
printf ("\n gs_timer_cleanup pass");
/////////////////////////////////////////////
return 0;
}
评论4