Master104_DemoDlg.cpp
上传用户:tengfei
上传日期:2014-02-20
资源大小:423k
文件大小:12k
源码类别:

邮电通讯系统

开发平台:

Visual C++

  1. // Master104_DemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Master104_Demo.h"
  5. #include "Master104real.h"
  6. #include "Master104_DemoDlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMaster104_DemoDlg dialog
  51. CMaster104_DemoDlg::CMaster104_DemoDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CMaster104_DemoDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CMaster104_DemoDlg)
  55. m_conn = FALSE;
  56. m_start = FALSE;
  57. //}}AFX_DATA_INIT
  58. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. }
  61. void CMaster104_DemoDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CMaster104_DemoDlg)
  65. DDX_Control(pDX, IDC_IPADDRESS1, m_ip);
  66. DDX_Control(pDX, IDC_LIST1, m_list);
  67. DDX_Check(pDX, IDC_CHECKconn, m_conn);
  68. DDX_Check(pDX, IDC_CHECKstarted, m_start);
  69. //}}AFX_DATA_MAP
  70. }
  71. BEGIN_MESSAGE_MAP(CMaster104_DemoDlg, CDialog)
  72. //{{AFX_MSG_MAP(CMaster104_DemoDlg)
  73. ON_WM_SYSCOMMAND()
  74. ON_WM_PAINT()
  75. ON_WM_QUERYDRAGICON()
  76. ON_BN_CLICKED(IDC_BUTTONstart, OnBUTTONstart)
  77. ON_BN_CLICKED(IDC_BUTTONstop, OnBUTTONstop)
  78. ON_BN_CLICKED(IDC_BUTTONreqcall, OnBUTTONreqcall)
  79. ON_BN_CLICKED(IDC_BUTTONreqcallgrp1, OnBUTTONreqcallgrp1)
  80. ON_BN_CLICKED(IDC_BUTTONreadfunc, OnBUTTONreadfunc)
  81. ON_BN_CLICKED(IDC_BUTTONcontrolselect, OnBUTTONcontrolselect)
  82. ON_BN_CLICKED(IDC_BUTTONcontroloperate, OnBUTTONcontroloperate)
  83. ON_BN_CLICKED(IDC_BUTTONcontroldeact, OnBUTTONcontroldeact)
  84. ON_BN_CLICKED(IDC_BUTTONitfreeze, OnBUTTONitfreeze)
  85. ON_BN_CLICKED(IDC_BUTTONitreqcall, OnBUTTONitreqcall)
  86. ON_BN_CLICKED(IDC_BUTTONitreqcallgrp1, OnBUTTONitreqcallgrp1)
  87. ON_BN_CLICKED(IDC_BUTTONresetproc, OnBUTTONresetproc)
  88. ON_BN_CLICKED(IDC_BUTTONresetdata, OnBUTTONresetdata)
  89. ON_BN_CLICKED(IDC_BUTTONtest, OnBUTTONtest)
  90. ON_BN_CLICKED(IDC_BUTTONsetME_NA, OnBUTTONsetMENA)
  91. ON_BN_CLICKED(IDC_BUTTONsetpMENA, OnBUTTONsetpMENA)
  92. ON_BN_CLICKED(IDC_BUTTONsyncolock, OnBUTTONsyncolock)
  93. ON_BN_CLICKED(IDC_BUTTONU_start, OnBUTTONUstart)
  94. ON_BN_CLICKED(IDC_BUTTONU_stop, OnBUTTONUstop)
  95. ON_BN_CLICKED(IDC_BUTTONconnect, OnBUTTONconnect)
  96. ON_BN_CLICKED(IDC_BUTTONdisconn, OnBUTTONdisconn)
  97. ON_WM_TIMER()
  98. //}}AFX_MSG_MAP
  99. END_MESSAGE_MAP()
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMaster104_DemoDlg message handlers
  102. BOOL CMaster104_DemoDlg::OnInitDialog()
  103. {
  104. CDialog::OnInitDialog();
  105. // Add "About..." menu item to system menu.
  106. // IDM_ABOUTBOX must be in the system command range.
  107. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  108. ASSERT(IDM_ABOUTBOX < 0xF000);
  109. CMenu* pSysMenu = GetSystemMenu(FALSE);
  110. if (pSysMenu != NULL)
  111. {
  112. CString strAboutMenu;
  113. strAboutMenu.LoadString(IDS_ABOUTBOX);
  114. if (!strAboutMenu.IsEmpty())
  115. {
  116. pSysMenu->AppendMenu(MF_SEPARATOR);
  117. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  118. }
  119. }
  120. // Set the icon for this dialog.  The framework does this automatically
  121. //  when the application's main window is not a dialog
  122. SetIcon(m_hIcon, TRUE); // Set big icon
  123. SetIcon(m_hIcon, FALSE); // Set small icon
  124. // TODO: Add extra initialization here
  125. real=0;
  126. m_ip.SetAddress(192,168,0,100);
  127. UpdateData(0);
  128. SetTimer(1,1000,NULL);
  129. return TRUE;  // return TRUE  unless you set the focus to a control
  130. }
  131. void CMaster104_DemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  132. {
  133. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  134. {
  135. CAboutDlg dlgAbout;
  136. dlgAbout.DoModal();
  137. }
  138. else
  139. {
  140. CDialog::OnSysCommand(nID, lParam);
  141. }
  142. }
  143. // If you add a minimize button to your dialog, you will need the code below
  144. //  to draw the icon.  For MFC applications using the document/view model,
  145. //  this is automatically done for you by the framework.
  146. void CMaster104_DemoDlg::OnPaint() 
  147. {
  148. if (IsIconic())
  149. {
  150. CPaintDC dc(this); // device context for painting
  151. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  152. // Center icon in client rectangle
  153. int cxIcon = GetSystemMetrics(SM_CXICON);
  154. int cyIcon = GetSystemMetrics(SM_CYICON);
  155. CRect rect;
  156. GetClientRect(&rect);
  157. int x = (rect.Width() - cxIcon + 1) / 2;
  158. int y = (rect.Height() - cyIcon + 1) / 2;
  159. // Draw the icon
  160. dc.DrawIcon(x, y, m_hIcon);
  161. }
  162. else
  163. {
  164. CDialog::OnPaint();
  165. }
  166. }
  167. // The system calls this to obtain the cursor to display while the user drags
  168. //  the minimized window.
  169. HCURSOR CMaster104_DemoDlg::OnQueryDragIcon()
  170. {
  171. return (HCURSOR) m_hIcon;
  172. }
  173. void CMaster104_DemoDlg::OnBUTTONstart() 
  174. {
  175. // TODO: Add your control notification handler code here
  176. if(real) return;
  177. real=new CMaster104real() ;
  178. real->dlg=this;
  179. BYTE fd0,fd1,fd2,fd3;
  180. UpdateData(1);
  181. m_ip.GetAddress(fd0,fd1,fd2,fd3);
  182. sprintf(serverIP,"%d.%d.%d.%d",fd0,fd1,fd2,fd3);
  183. real->Init_SockServerIP(serverIP);
  184. real->Init_Linkpara();
  185. real->master_start();
  186. }
  187. void CMaster104_DemoDlg::OnBUTTONstop() 
  188. {
  189. // TODO: Add your control notification handler code here
  190. if(real)
  191. {
  192. real->master_close();
  193. delete real;
  194. real=NULL;
  195. }
  196. }
  197. void CMaster104_DemoDlg::SendMsg(BYTE *txbuf,int txlen) 
  198. {
  199. real->Send_ASDU_Msg(txbuf,txlen);
  200. CString ch, str;
  201. str="Tx:";
  202. for(int i=0;i<txlen;i++)
  203. {
  204. ch.Format(" %02x",txbuf[i]);
  205. str+=ch;
  206. }
  207. m_list.AddString(str);
  208. if(m_list.GetCount()>100)
  209. m_list.DeleteString(0);
  210. int count=m_list.GetCount();
  211. m_list.SetCurSel(count-1);
  212. }
  213. void CMaster104_DemoDlg::OnBUTTONreqcall() 
  214. {
  215. // TODO: Add your control notification handler code here
  216. BYTE buf[]={100,1,6,0,1,0,0,0,0,20};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  217. SendMsg(buf,sizeof(buf));
  218. }
  219. void CMaster104_DemoDlg::OnBUTTONreqcallgrp1() 
  220. {
  221. // TODO: Add your control notification handler code here
  222. BYTE buf[]={100,1,6,0,1,0,0,0,0,21};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  223. SendMsg(buf,sizeof(buf));
  224. }
  225. void CMaster104_DemoDlg::OnBUTTONreadfunc() 
  226. {
  227. // TODO: Add your control notification handler code here
  228. BYTE buf[]={102,1,5,0,1,0,0x01,0x00,0x00};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  229. //BYTE buf[]={102,1,5,0,1,0,0x01,0x40,0x00};//读遥测量
  230. SendMsg(buf,sizeof(buf));
  231. }
  232. void CMaster104_DemoDlg::OnBUTTONcontrolselect() 
  233. {
  234. // TODO: Add your control notification handler code here
  235. BYTE buf[]={45,1,6,0,1,0,0x01,0x60,0x00,0x81};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  236. SendMsg(buf,sizeof(buf));
  237. }
  238. void CMaster104_DemoDlg::OnBUTTONcontroloperate() 
  239. {
  240. // TODO: Add your control notification handler code here
  241. BYTE buf[]={45,1,6,0,1,0,0x01,0x60,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  242. SendMsg(buf,sizeof(buf));
  243. }
  244. void CMaster104_DemoDlg::OnBUTTONcontroldeact() 
  245. {
  246. // TODO: Add your control notification handler code here
  247. BYTE buf[]={45,1,8,0,1,0,0x01,0x60,0x00,0x81};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  248. SendMsg(buf,sizeof(buf));
  249. }
  250. void CMaster104_DemoDlg::OnBUTTONitfreeze() 
  251. {
  252. // TODO: Add your control notification handler code here
  253. BYTE buf[]={101,1,6,0,1,0,0x00,0x00,0x00,0x45};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  254. SendMsg(buf,sizeof(buf));
  255. }
  256. void CMaster104_DemoDlg::OnBUTTONitreqcall() 
  257. {
  258. // TODO: Add your control notification handler code here
  259. BYTE buf[]={101,1,6,0,1,0,0x00,0x00,0x00,0x05};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  260. SendMsg(buf,sizeof(buf));
  261. }
  262. void CMaster104_DemoDlg::OnBUTTONitreqcallgrp1() 
  263. {
  264. // TODO: Add your control notification handler code here
  265. BYTE buf[]={101,1,6,0,1,0,0x00,0x00,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  266. SendMsg(buf,sizeof(buf));
  267. }
  268. void CMaster104_DemoDlg::OnBUTTONresetproc() 
  269. {
  270. // TODO: Add your control notification handler code here
  271. BYTE buf[]={105,1,6,0,1,0,0x00,0x00,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  272. SendMsg(buf,sizeof(buf));
  273. }
  274. void CMaster104_DemoDlg::OnBUTTONresetdata() 
  275. {
  276. // TODO: Add your control notification handler code here
  277. BYTE buf[]={105,1,6,0,1,0,0x00,0x00,0x00,0x02};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  278. SendMsg(buf,sizeof(buf));
  279. }
  280. void CMaster104_DemoDlg::OnBUTTONtest() 
  281. {
  282. // TODO: Add your control notification handler code here
  283. BYTE buf[]={104,1,6,0,1,0,0x00,0x00,0x00,0xaa,0x55};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  284. SendMsg(buf,sizeof(buf));
  285. }
  286. void CMaster104_DemoDlg::OnBUTTONsetMENA() 
  287. {
  288. // TODO: Add your control notification handler code here
  289. BYTE buf[]={48,1,6,0,1,0,0x01,0x62,0x00,0x01,0x02,0x00};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  290. SendMsg(buf,sizeof(buf));
  291. }
  292. void CMaster104_DemoDlg::OnBUTTONsetpMENA() 
  293. {
  294. // TODO: Add your control notification handler code here
  295. BYTE buf[]={110,1,6,0,1,0,0x01,0x50,0x00,0x05,0x00,0x01};//Type,Informationbody num,COT,Source ADDR,ASDU addressLow,ASDU addressHigh
  296. SendMsg(buf,sizeof(buf));
  297. }
  298. void CMaster104_DemoDlg::OnBUTTONsyncolock() 
  299. {
  300. // TODO: Add your control notification handler code here
  301. BYTE Txbuf[256];
  302. BYTE *buff=Txbuf;
  303. BYTE *csbuff;
  304. *buff++=103; //type
  305. *buff++=1;
  306. *buff++=6;
  307. *buff++=1; //address
  308. *buff++=0;
  309. *buff++=0;
  310. SYSTEMTIME ctim;
  311. GetLocalTime(&ctim);
  312. *((WORD*)buff)=ctim.wMilliseconds+ctim.wSecond*1000;
  313. buff++;
  314. buff++;
  315. *buff++=ctim.wMinute;
  316. *buff++=ctim.wHour;
  317. *buff++=ctim.wDay;//(ctim.wDay&0x1f)|((ctim.wDayOfWeek<<5)&0xe0);
  318. *buff++=ctim.wMonth;
  319. *buff++=ctim.wYear-2000;
  320. int Txlen=buff-Txbuf;
  321. SendMsg(Txbuf,Txlen);
  322. }
  323. void CMaster104_DemoDlg::OnBUTTONUstart() 
  324. {
  325. // TODO: Add your control notification handler code here
  326. if(real)
  327. real->Send_ASDU_Ucommand(CMD_USTART);
  328. }
  329. void CMaster104_DemoDlg::OnBUTTONUstop() 
  330. {
  331. // TODO: Add your control notification handler code here
  332. if(real)
  333. real->Send_ASDU_Ucommand(CMD_USTOP);
  334. }
  335. void CMaster104_DemoDlg::OnBUTTONconnect() 
  336. {
  337. // TODO: Add your control notification handler code here
  338. if(real)
  339. real->Send_ASDU_Ucommand(CMD_CONN);
  340. }
  341. void CMaster104_DemoDlg::OnBUTTONdisconn() 
  342. {
  343. // TODO: Add your control notification handler code here
  344. if(real)
  345. real->Send_ASDU_Ucommand(CMD_DISCONN);
  346. }
  347. void CMaster104_DemoDlg::OnTimer(UINT nIDEvent) 
  348. {
  349. // TODO: Add your message handler code here and/or call default
  350. if(real)
  351. {
  352. m_conn=real->GetSockConnectStatus();
  353. m_start=real->GetUstartStatus();
  354. UpdateData(0);
  355. }
  356. CDialog::OnTimer(nIDEvent);
  357. }