未来索引
开启左侧

installertooldlg.cpp:源码内容

[复制链接]
邢远 发表于 2014-9-20 21:06:07 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
  1. /*******************************  InstallerToolDlg.cpp  *********************
  2. *           #######
  3. *           ##  ##
  4. *           #  ##    ####   #####    #####  ##  ##   #####
  5. *             ##    ##  ##  ##  ##  ##      ##  ##  ##
  6. *            ##  #  ######  ##  ##   ####   ##  ##   ####
  7. *           ##  ##  ##      ##  ##      ##   #####      ##
  8. *          #######   ####   ##  ##  #####       ##  #####
  9. *                                           #####
  10. *          Z-Wave, the wireless language.
  11. *
  12. *              Copyright (c) 2001
  13. *              Zensys A/S
  14. *              Denmark
  15. *
  16. *              All Rights Reserved
  17. *
  18. *    This source file is subject to the terms and conditions of the
  19. *    Zensys Software License Agreement which restricts the manner
  20. *    in which it may be used.
  21. *
  22. *---------------------------------------------------------------------------
  23. *
  24. * Description: Implementation file for InstallerTool source code.
  25. *         All functionality for the Serial API based installer tool
  26. *         should be defined here.
  27. *
  28. * Author:   Henrik Holm
  29. *
  30. * Last Changed By:  $Author: heh $
  31. * Revision:         $Revision: 1.36 $
  32. * Last Changed:     $Date: 2005/04/14 11:34:52 $
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************/
  36. /*                              INCLUDE FILES                               */
  37. /****************************************************************************/
  38. #include "stdafx.h"
  39. #include "InstallerTool.h"
  40. #include "InstallerToolDlg.h"
  41. #include "winver.h"
  42. #include ".installertooldlg.h"
  43. #ifdef _DEBUG
  44. #define new DEBUG_NEW
  45. #undef THIS_FILE
  46. static char THIS_FILE[] = __FILE__;
  47. #endif
  48. //Version values
  49. #define PC_VERSION_MAJOR 1
  50. #define PC_VERSION_MINOR 11
  51. /*Number of ms between timer events*/
  52. #define TIMEOUT_TIME 100 /*ms*/
  53. /*Define colors to use           BBGGRR*/
  54. #define INVALID_COLOR         0x000000
  55. #define NODE_GT_COLOR         0x00FF99         //Generic controller
  56. #define NODE_ST_COLOR         0x9999FF         //Static controller
  57. #define NODE_SB_COLOR         0x660000         //Binary Switch
  58. #define NODE_SM_COLOR         0xFF0000         //Multilevel Switch
  59. #define NODE_SENB_COLOR         0x00AA00         //Binary sensor
  60. #define NODE_SENM_COLOR         0x111111         //Multilevel sensor
  61. #define NODE_MB_COLOR         0XE6E61C         //Meter
  62. #define NODE_EC_COLOR         0xAAAAAA         //Entry Control
  63. #define NO_NODE_COLOR         0xFFFFFF         //No node at this node id
  64. #define NODE_UNKNOWN_COLOR        0x9900FF
  65. #define NODE_BAD_COLOR         0x0000FF         //There is a node, but unable to the other node
  66. #define NODE_OK_COLOR         0xFF0000
  67. #define GRAPH_TOPOLOGY_SIZE 512         // The size of the network topologi map in pixels
  68. /* Max number of nodes in a Z-wave system */
  69. #define ZW_MAX_NODES        232
  70. /*Defined used to access m_nodeList display*/
  71. #define ID_FIELD        0
  72. #define NODE_ID_TXT 1
  73. #define DEVICE_TYPE 2
  74. #define TX_COUNT        3
  75. #define REPORT_LEVEL_TIMEOUT 0x01
  76. #define GET_LEVEL_TIMEOUT 0x02
  77. CSerialAPI api;
  78. BYTE nodeType[255];
  79. BYTE lastLearnedNodeID;
  80. BYTE lastLearnedNodeType;
  81. BYTE RoadList[6];
  82. static void *this_instance;
  83. static HWND this_hWnd;
  84. BYTE locateCount;
  85. BOOL replSend;
  86. int selected[255];
  87. BYTE selectCount;
  88. static BYTE routingTable[232][232/8];
  89. BOOL secondaryCtrl;
  90. char uCversion[40];
  91. BYTE bAbortNow = FALSE;
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CAboutDlg dialog used for App About
  94. class CAboutDlg : public CDialog
  95. {
  96. public:
  97. CAboutDlg();
  98. // Dialog Data
  99. //{{AFX_DATA(CAboutDlg)
  100. enum { IDD = IDD_ABOUTBOX };
  101. CString        m_txtVersion;
  102. CString        m_txtDevVer;
  103. //}}AFX_DATA
  104. // ClassWizard generated virtual function overrides
  105. //{{AFX_VIRTUAL(CAboutDlg)
  106. protected:
  107. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  108. //}}AFX_VIRTUAL
  109. // Implementation
  110. protected:
  111. //{{AFX_MSG(CAboutDlg)
  112. //}}AFX_MSG
  113. DECLARE_MESSAGE_MAP()
  114. };
  115. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  116. {
  117. //{{AFX_DATA_INIT(CAboutDlg)
  118. m_txtVersion = _T("");
  119. m_txtDevVer = _T("");
  120. //}}AFX_DATA_INIT
  121. char str[80];
  122. m_txtVersion.Delete(0,80);
  123.   sprintf(str,"PC version: %i.%i",PC_VERSION_MAJOR,PC_VERSION_MINOR);
  124. m_txtVersion.Insert(0, str);
  125. sprintf(str,"Module: %s",uCversion);
  126. m_txtDevVer.Delete(0,80);
  127. m_txtDevVer.Insert(0,str);
  128. }
  129. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  130. {
  131. CDialog::DoDataExchange(pDX);
  132. //{{AFX_DATA_MAP(CAboutDlg)
  133. DDX_Text(pDX, IDC_STATICVERSION, m_txtVersion);
  134. DDV_MaxChars(pDX, m_txtVersion, 80);
  135. DDX_Text(pDX, IDC_STATICDEV, m_txtDevVer);
  136. DDV_MaxChars(pDX, m_txtDevVer, 80);
  137. //}}AFX_DATA_MAP
  138. }
  139. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  140. //{{AFX_MSG_MAP(CAboutDlg)
  141. // No message handlers
  142. //}}AFX_MSG_MAP
  143. END_MESSAGE_MAP()
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CInstallerToolDlg dialog
  146. CInstallerToolDlg::CInstallerToolDlg(CWnd* pParent /*=NULL*/)
  147. : CDialog(CInstallerToolDlg::IDD, pParent)
  148. {
  149. //{{AFX_DATA_INIT(CInstallerToolDlg)
  150. m_RoutingTable = _T("");
  151. m_intLowNode = 0;
  152. m_intHighNode = 0;
  153. m_uintFrames = 10;
  154. //}}AFX_DATA_INIT
  155. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  156. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  157. }
  158. void CInstallerToolDlg::DoDataExchange(CDataExchange* pDX)
  159. {
  160. CDialog::DoDataExchange(pDX);
  161. //{{AFX_DATA_MAP(CInstallerToolDlg)
  162. DDX_Control(pDX, IDCANCEL, m_btnQuit);
  163. DDX_Control(pDX, IDC_BUTTON13, m_btnAbortAction);
  164. DDX_Control(pDX, IDC_BUTTON10, m_btnResetTool);
  165. DDX_Control(pDX, IDC_COMBO1, m_cTXLevel);
  166. DDX_Control(pDX, IDC_LQRESULT, m_txtLQResult);
  167. DDX_Control(pDX, IDC_LEGEND, m_legend);
  168. DDX_Control(pDX, IDC_LIST2, m_nodeList);
  169. DDX_Control(pDX, IDC_STATIC4, m_txtNodePoint);
  170. DDX_Control(pDX, IDC_BUTTON9, m_btnResetNode);
  171. DDX_Control(pDX, IDC_BUTTON6, m_btnRecInfo);
  172. DDX_Control(pDX, IDC_BUTTON4, m_btnRestore);
  173. DDX_Control(pDX, IDC_BUTTON3, m_btnBackup);
  174. DDX_Control(pDX, TOPOLOGY, m_btnTopology);
  175. DDX_Control(pDX, IDC_BUTTON8, m_btnAddNode);
  176. DDX_Control(pDX, IDC_BUTTON7, m_btnCheckLink);
  177. DDX_Control(pDX, IDC_BUTTON2, m_btnLocateNode);
  178. DDX_Control(pDX, IDC_BUTTON1, m_btnGetNeighbors);
  179. DDX_Control(pDX, IDC_STATIC2, m_txtHomeId);
  180. DDX_Control(pDX, IDC_STATIC1, m_txtStatus);
  181. DDX_Control(pDX, IDC_ROUTEMAP, m_cstaticNodeMap);
  182. DDX_Text(pDX, IDC_EDIT1, m_uintFrames);
  183. DDV_MinMaxUInt(pDX, m_uintFrames, 1, 32000);
  184. DDX_Control(pDX, IDC_BUTTON12, m_btnHandOverPrimary);
  185.     //}}AFX_DATA_MAP
  186. }
  187. BEGIN_MESSAGE_MAP(CInstallerToolDlg, CDialog)
  188. //{{AFX_MSG_MAP(CInstallerToolDlg)
  189. //ON_WM_SYSCOMMAND()
  190. ON_WM_PAINT()
  191. ON_WM_QUERYDRAGICON()
  192. ON_BN_CLICKED(TOPOLOGY, OnTOPOLOGY)
  193. ON_BN_CLICKED(IDC_BUTTON1, OnGetNeighbors)
  194. ON_WM_DRAWITEM()
  195. ON_BN_CLICKED(IDC_BUTTON2, OnLocateNode)
  196. ON_BN_CLICKED(IDC_BUTTON6, OnReplRec)
  197. ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
  198. ON_BN_CLICKED(IDC_BUTTON7, OnCheckLink)
  199. ON_BN_CLICKED(IDCANCEL, OnExit)
  200. ON_BN_CLICKED(IDC_BUTTON8, OnAddNode)
  201. ON_BN_CLICKED(IDC_BUTTON9, OnResetNode)
  202. ON_BN_CLICKED(IDC_BUTTON10, OnResetTool)
  203. ON_WM_MOUSEMOVE()
  204. ON_WM_LBUTTONDBLCLK()
  205. ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
  206. ON_CBN_EDITCHANGE(IDC_COMBO1, OnEditchangeCombo1)
  207. ON_WM_TIMER()
  208. ON_BN_CLICKED(IDC_BUTTON12, OnHandOverPrimary)
  209. ON_BN_CLICKED(IDC_BUTTON13, OnAbortButton)
  210. ON_WM_MBUTTONDBLCLK()
  211. ON_WM_ACTIVATE()
  212. //}}AFX_MSG_MAP
  213. #if _MSC_VER >= 1300
  214. ON_MESSAGE(WM_USER+2, (LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM)) EnableUI)
  215. ON_MESSAGE(WM_USER+4, (LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM)) OnReceiveRemoteData)
  216. #else
  217. ON_MESSAGE(WM_USER+2, EnableUI)
  218. ON_MESSAGE(WM_USER+4, OnReceiveRemoteData)
  219. #endif
  220. ON_BN_CLICKED(IDC_BUTTON14, OnBnClickedButton14)
  221.   ON_WM_SYSCOMMAND()
  222. END_MESSAGE_MAP()
  223. /*============================   EnableUI ====================================
  224. ** Function description
  225. **      Enables button presses
  226. **
  227. ** Side effects:
  228. **
  229. **--------------------------------------------------------------------------*/
  230. void CInstallerToolDlg::EnableUI()
  231. {
  232. EnableButtons(TRUE);
  233. }
  234. /*============================   AddNode   ==================================
  235. ** Function description
  236. **      Add a node to the internal nodeType table.
  237. **
  238. ** Side effects:
  239. **         Updates the bMaxNodeID variable.
  240. **--------------------------------------------------------------------------*/
  241. void CInstallerToolDlg::AddNode(BYTE nid, BYTE ntype)
  242. {
  243. BYTE i=255;
  244. nodeType[nid] = ntype;
  245. while((nodeType[i]==0)&&(i>0))
  246. i--;
  247. if(i)
  248. bMaxNodeID = i;
  249. else
  250. bMaxNodeID = 0;
  251. }
  252. /*============================   SetNodeIDText ==============================
  253. ** Function description
  254. **      Finds the nodeID in the Item list and updates the selected information
  255. **         Returns TRUE if success, FALSE if not
  256. ** Side effects:
  257. **
  258. **--------------------------------------------------------------------------*/
  259. BOOL CInstallerToolDlg::SetNodeIDText(BYTE nodeID,        /*IN nodeid to update*/
  260.   BYTE field,        /* IN What field we want updated*/
  261.   CString txtStr)        /*IN String containing the text write*/
  262. {
  263. BOOL retVal = FALSE;
  264. char buf4[4];
  265. int item;
  266. memset(buf4, 0, sizeof(buf4));
  267. lfv.flags = LVFI_STRING;  // Search on parmeter
  268. lfv.psz = itoa(nodeID, buf4, 10);         /*Find node ID*/
  269. item = m_nodeList.FindItem(&lfv,-1);
  270. if(item!=-1)
  271. {
  272. m_nodeList.SetItemText(item,field,txtStr);
  273. m_nodeList.SetItemText(item, NODE_ID_TXT,itoa(nodeID, buf4, 10));
  274. retVal = TRUE;
  275. }
  276. return retVal;
  277. }
  278. /*============================   ConvertStrtoInt  ===========================
  279. ** Function description
  280. **      Converts a string to an integer
  281. **
  282. ** Side effects:
  283. **
  284. **--------------------------------------------------------------------------*/
  285. int CInstallerToolDlg::ConvertStrtoInt(CString UnitIdStrTemp)
  286. {
  287.    BYTE Number = 0;
  288.    Number = atoi(UnitIdStrTemp);
  289.    return Number;
  290. }
  291. /*============================   GetUnitList ================================
  292. ** Function description
  293. **      GETS a list of selected node ids
  294. **
  295. ** Side effects:
  296. **
  297. **--------------------------------------------------------------------------*/
  298. void CInstallerToolDlg::GetUnitList(int *unitList, BYTE *numberUnits)
  299. {
  300.    CString UnitIdStrTemp;
  301.    int k=0;
  302.    memset(unitList, 0, 255);
  303.    POSITION pos = m_nodeList.GetFirstSelectedItemPosition();
  304.    int nSelectedItem = -1;
  305.    for (int i = 0;i < itemIndex;i++)
  306.    {
  307. if (pos != NULL)
  308. {
  309. nSelectedItem = m_nodeList.GetNextSelectedItem(pos);
  310. UnitIdStrTemp = m_nodeList.GetItemText(nSelectedItem,1);
  311. unitList[k++] = ConvertStrtoInt(UnitIdStrTemp);
  312.    }
  313.    }  
  314.    *numberUnits = k;
  315. }
  316. /*============================   ReloadNodeList =============================
  317. ** Function description
  318. **      Reloads the node IDs and types from the Device module
  319. ** Side effects:
  320. **--------------------------------------------------------------------------*/
  321. BOOL CInstallerToolDlg::ReloadNodeList(void)
  322. {
  323. BOOL bFound = FALSE;
  324. BYTE byNode = 1;
  325. BYTE j,i;
  326. BYTE bVer = 0;
  327. BYTE bCapab = 0;
  328. BYTE bLen = 0;
  329. BYTE bNodes[100];
  330. BYTE HomeId[4];
  331. BYTE NodeId;
  332. NODEINFO nodeInfo;
  333. char txt[40];
  334. bMaxNodeID = 0;
  335. api.MemoryGetID(HomeId, &NodeId);
  336. secondaryCtrl = api.SerialAPI_GetInitData(&bVer, &bCapab, &bLen, bNodes);
  337. /*Reset the nodelist before loading it again*/
  338. for (i=0;i<255;i++)
  339. nodeType[i] = 0;
  340. for (i=0;i<bLen;i++)
  341. {
  342. if (bNodes[i] != 0)
  343. {
  344. bFound = TRUE;
  345. for (j=0;j<8;j++)
  346. {
  347. if (bNodes[i] & (1<<j))
  348. {
  349. sprintf(txt,"Reading %i nodelist",byNode);
  350. m_txtStatus.SetWindowText(txt);
  351. api.ZW_GetNodeProtocolInfo(byNode, &nodeInfo);
  352. nodeType[byNode] = nodeInfo.nodeType.generic;
  353. bMaxNodeID = byNode;
  354. }
  355.     byNode++;
  356. }
  357. }
  358. else
  359. byNode += 8;
  360. }
  361. return bFound;
  362. }
  363. /*============================ DisplayStandardItems ==========================
  364. ** Function description
  365. **      Displays the nodeTable, Home ID and other standard items
  366. ** Side effects:
  367. **
  368. **--------------------------------------------------------------------------*/
  369. void CInstallerToolDlg::DisplayStandardItems(void)
  370. {
  371. char buffer[50];
  372. char a[50];
  373. BYTE HomeId[4];
  374. BYTE NodeId;
  375. int item;
  376. char buf4[4];
  377. memset(buf4, 0, sizeof(buf4));
  378. lfv.flags = LVFI_STRING;  // Search on text
  379. /*Get homeID*/
  380. api.MemoryGetID(HomeId, &NodeId);
  381. if(bMaxNodeID)
  382. {
  383. for(int i=0;i< bMaxNodeID;i++)
  384. {
  385.          lfv.psz = itoa(i+1, buf4, 10);         /*Find node ID*/
  386. item = m_nodeList.FindItem(&lfv,-1);
  387. if(nodeType[i+1]!=0)
  388. {
  389. if(NodeId == (i+1))
  390. sprintf(buffer, "This node");
  391. else
  392. sprintf(buffer, "%s",WriteNodeTypeString(nodeType[i+1]));
  393. if (item != -1)
  394. {
  395. SetNodeIDText(i+1,DEVICE_TYPE,buffer);
  396. }
  397. else
  398. {
  399. memset(buf4, 0, sizeof(buf4));
  400. m_nodeList.InsertItem(itemIndex, itoa(i+1, buf4, 10));
  401. m_nodeList.SetItemText(itemIndex, NODE_ID_TXT,itoa(i+1, buf4, 10));
  402. SetNodeIDText(i+1,DEVICE_TYPE,buffer);
  403. itemIndex++;
  404. }
  405. }
  406. else
  407. {        /*No node found here*/
  408. if (item != -1)
  409. {
  410. m_nodeList.DeleteItem(item);
  411. itemIndex--;
  412. }
  413. }
  414. }
  415. if(itemIndex>(bMaxNodeID))
  416. {
  417. m_nodeList.DeleteItem(--itemIndex);
  418. }
  419. }
  420. else /*No nodes in the controller*/
  421. m_nodeList.DeleteAllItems();
  422. sprintf(a,"%02X%02X%02X%02X, NodeId:%dn",HomeId[0],HomeId[1],HomeId[2],HomeId[3],NodeId);
  423. GetInstance()->m_txtHomeId.SetWindowText(a);
  424. GetInstance()->m_txtNodePoint.SetWindowText("...");
  425. GetInstance()->m_txtHomeId.UpdateWindow();
  426. }
  427. void CInstallerToolDlg::RemoveNodeFromList(BYTE bSource)
  428. {
  429.    char buf4[4];
  430.    memset(buf4, 0, sizeof(buf4));
  431.    lfv.flags = LVFI_STRING;  // Search on text
  432.    lfv.psz = itoa(bSource, buf4, 10);  
  433.    int nodelst = m_nodeList.FindItem(&lfv,-1);
  434.    if (nodelst != -1)
  435.    {
  436.        m_nodeList.DeleteItem(nodelst);
  437.    itemIndex--;
  438.    }
  439. }
  440. /*============================   IdleLearnNodeState_Compl ====================
  441. ** Function description
  442. **      Callback which is called when a node is added or removed by
  443. **         a SUC
  444. **
  445. ** Side effects:
  446. **
  447. **--------------------------------------------------------------------------*/
  448. void CInstallerToolDlg::IdleLearnNodeState_Compl(BYTE bStatus, /*IN Status of learn mode*/
  449. BYTE bSource, /*IN Source node*/
  450. BYTE *pCmd,   /*IN Data*/
  451. BYTE bLen)    /*Length of data*/
  452. {
  453. static BYTE lastLearnedNodeType;
  454. if (bLen)
  455. {
  456.       NODEINFO nodeInfo;
  457.       api.ZW_GetNodeProtocolInfo(bSource, &nodeInfo);
  458.       if (nodeInfo.nodeType.basic<BASIC_TYPE_SLAVE)
  459.       {
  460.          lastLearnedNodeType = nodeInfo.nodeType.basic;  /*For now we store the learned basic node type*/
  461.       }
  462.       else
  463.       {
  464.          lastLearnedNodeType = nodeInfo.nodeType.generic; /* Store learned generic node type*/
  465.       }
  466. }
  467. if (bStatus == UPDATE_STATE_ROUTING_PENDING)
  468. {
  469. GetInstance()->m_txtStatus.SetWindowText("Waiting ...");
  470. }
  471. else if (bStatus == UPDATE_STATE_ADD_DONE)
  472. {
  473. GetInstance()->AddNode(bSource,lastLearnedNodeType);
  474. GetInstance()->m_txtStatus.SetWindowText("Node included ...");
  475. ::PostMessage(this_hWnd, WM_USER+2, 0, 0);
  476. }
  477. else if (bStatus == UPDATE_STATE_DELETE_DONE)
  478. {
  479. GetInstance()->RemoveNodeFromList(bSource);
  480. GetInstance()->AddNode(bSource,0);
  481. GetInstance()->m_txtStatus.SetWindowText("Node removed...");
  482. ::PostMessage(this_hWnd, WM_USER+2, 0, 0);
  483. }
  484. }
  485. /*============================   CommErrorNotification =======================
  486. ** Function description
  487. **      Called when a communication error occours between Z-Wave module and
  488. **         PC
  489. **
  490. ** Side effects:
  491. **
  492. **--------------------------------------------------------------------------*/
  493. void CInstallerToolDlg::CommErrorNotification(BYTE byReason)
  494. {
  495. switch(byReason)
  496. {
  497. case CSerialAPI::COMM_RETRY_EXCEEDED:
  498.    GetInstance()->MessageBox("Communication with Z-Wave module was lost while sending command.nCheck the cable and either retry the operation or restart the application.","Error");
  499.    break;
  500. case CSerialAPI::COMM_NO_RESPONSE:
  501.    GetInstance()->MessageBox("Communication with Z-Wave module timed out while waiting for response.nCheck the cable and either retry the operation or restart the application.","Error");
  502.    break;
  503. default:
  504.    GetInstance()->MessageBox("Communication with Z-Wave module was lost.nCheck the cable and either retry the operation or restart the application.","Error");
  505.    break;
  506. }
  507. }
  508. /*======================   ApplicationCommandHandler =======================
  509. ** Function description
  510. **      All non protocol RF messages received are handled by this function
  511. **
  512. **
  513. ** Side effects:
  514. **
  515. **--------------------------------------------------------------------------*/
  516. void CInstallerToolDlg::ApplicationCommandHandler(BYTE rxStatus,
  517.    BYTE sourceNode,
  518.    BYTE *pCmd,
  519.    BYTE cmdLength)
  520. {
  521. ZW_APPLICATION_TX_BUFFER *pdata = (ZW_APPLICATION_TX_BUFFER *) pCmd;
  522. char txt[80];
  523. switch(*(pCmd+CMDBUF_CMDCLASS_OFFSET))
  524. {
  525.            case COMMAND_CLASS_SWITCH_MULTILEVEL:
  526. case COMMAND_CLASS_BASIC:
  527. if(*(pCmd+CMDBUF_CMD_OFFSET)== BASIC_REPORT)
  528. {
  529. }
  530. else if (*(pCmd+CMDBUF_CMD_OFFSET)== BASIC_SET)
  531. {
  532. }
  533. break;
  534. case COMMAND_CLASS_SENSOR_BINARY:
  535. if (*(pCmd+CMDBUF_CMD_OFFSET)== SENSOR_BINARY_REPORT)
  536. {
  537. }
  538. break;
  539. case COMMAND_CLASS_CONTROLLER_REPLICATION:
  540. api.ZW_ReplicationCommandComplete();
  541. break;
  542. case COMMAND_CLASS_POWERLEVEL:
  543. if(*(pCmd+CMDBUF_CMD_OFFSET)==POWERLEVEL_TEST_NODE_REPORT)
  544. {
  545. if(GetInstance()->timerID.eventID)
  546. GetInstance()->KillTimer(GetInstance()->timerID.eventID);
  547. GetInstance()->timerID.eventID = 0;
  548. unsigned int recCount = (pdata->ZW_PowerLevelTestNodeReportFrame.testFrameCountMsb<<8)&0xFF00;
  549. recCount |= pdata->ZW_PowerLevelTestNodeReportFrame.testFrameCountLsb&0x00FF;
  550. sprintf(txt," %d to: %d Frames OK:%i", sourceNode, pdata->ZW_PowerLevelTestNodeReportFrame.nodeId,
  551. recCount);
  552. /*pdata->ZW_PowerLevelTestNodeReportFrame.testStatus*/
  553. GetInstance()->m_txtLQResult.SetWindowText(txt);
  554. GetInstance()->EnableButtons(TRUE);
  555.    }
  556.    break;
  557. default:
  558. break;
  559. }
  560. }
  561. /////////////////////////////////////////////////////////////////////////////
  562. // CInstallerToolDlg message handlers
  563. /*================================   GetInstance =============================
  564. ** Function description
  565. **      Used to get the instance
  566. **
  567. ** Side effects:
  568. **
  569. **--------------------------------------------------------------------------*/
  570. CInstallerToolDlg *CInstallerToolDlg::GetInstance()
  571. {
  572. return (CInstallerToolDlg *)this_instance;
  573. }
  574. /*================================ OnInitDialog =============================
  575. ** Function description
  576. **      Called on program startup. Initializes the program and module
  577. **
  578. ** Side effects:
  579. **
  580. **--------------------------------------------------------------------------*/
  581. BOOL CInstallerToolDlg::OnInitDialog()
  582. {
  583. CDialog::OnInitDialog();
  584. // Add "About..." menu item to system menu.
  585. // IDM_ABOUTBOX must be in the system command range.
  586. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  587. ASSERT(IDM_ABOUTBOX < 0xF000);
  588. CMenu* pSysMenu = GetSystemMenu(FALSE);
  589. if (pSysMenu != NULL)
  590. {
  591. CString strAboutMenu;
  592. strAboutMenu.LoadString(IDS_ABOUTBOX);
  593. if (!strAboutMenu.IsEmpty())
  594. {
  595. pSysMenu->AppendMenu(MF_SEPARATOR);
  596. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  597. }
  598. }
  599. // Set the icon for this dialog.  The framework does this automatically
  600. //  when the application's main window is not a dialog
  601. SetIcon(m_hIcon, TRUE);         // Set big icon
  602. SetIcon(m_hIcon, FALSE);         // Set small icon
  603. this_instance = this;
  604. this_hWnd = m_hWnd;
  605. /* Start the Z-Wave initilization*/
  606. /* Find out which port is connected.*/
  607. bMaxNodeID = 0;
  608.     PortValue = 0;
  609.     libType = 0;
  610. #if _MSC_VER >= 1300
  611.         bySpeed = CSerialAPI::SPEED_115200;
  612. #else
  613. bySpeed = CSerialAPI.SPEED_115200;
  614. #endif
  615. lSpeed  = 115200;
  616. for (int i = 1; i < __argc; i++)
  617. {
  618. LPCTSTR pszParam = __argv[i];
  619. if (pszParam[0] == '-' || pszParam[0] == '/')
  620. {
  621. ++pszParam;
  622. }
  623. if (lstrcmpi(pszParam,"com=1") == 0)
  624. PortValue = 1;
  625. else if (lstrcmpi(pszParam,"com=2") == 0)
  626. PortValue = 2;
  627. else if (lstrcmpi(pszParam,"com=3") == 0)
  628. PortValue = 3;
  629. else if (lstrcmpi(pszParam,"com=4") == 0)
  630. PortValue = 4;
  631. else if (lstrcmpi(pszParam,"com=5") == 0)
  632. PortValue = 5;
  633. else if (lstrcmpi(pszParam,"com=6") == 0)
  634. PortValue = 6;
  635. else if (lstrcmpi(pszParam,"com=7") == 0)
  636. PortValue = 7;
  637. if (lstrcmpi(pszParam,"speed=19200") == 0)
  638. {
  639. #if _MSC_VER >= 1300
  640.             bySpeed = CSerialAPI::SPEED_19200;
  641. #else
  642. bySpeed = CSerialAPI.SPEED_19200;
  643. #endif
  644. lSpeed = 19200;
  645. }
  646. else if (lstrcmpi(pszParam,"speed=57600") == 0)
  647. {
  648. #if _MSC_VER >= 1300
  649.             bySpeed = CSerialAPI::SPEED_57600;
  650. #else
  651.             bySpeed = CSerialAPI.SPEED_57600;
  652. #endif
  653. lSpeed = 57600;
  654. }
  655. if (FindLib(PortValue,bySpeed) == 0)
  656. {
  657. api.Shutdown();
  658.             str.Format("This application requires a static controller Z-Wave module connected to the serialport.nnDownload the correct Serial API code to the Z-Wave Module and restart the application.");
  659. }  
  660. }
  661.    if (__argc < 2)
  662. {   
  663.        m_txtStatus.SetWindowText("No nodes added to controller");
  664.    while((libType != ZW_LIB_INSTALLER) && (PortValue < 8))
  665.    {
  666.        PortValue++;
  667.    FindLib(PortValue,bySpeed);
  668.    }
  669. }
  670.     if (libType != ZW_LIB_INSTALLER)
  671. {
  672.        MessageBox(str, "Error");
  673.    OnOK();
  674.    return TRUE;
  675.            }
  676. else
  677. {
  678.     char aa[40];
  679. CString str;
  680.     GetWindowText(str);
  681. sprintf(aa," - com%d %ld baud",PortValue,lSpeed);
  682. SetWindowText(str + aa);
  683. }
  684. /*Reload the nodes*/
  685. m_nodeList.SetExtendedStyle( (m_nodeList.GetExtendedStyle()| LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT |
  686. LVIS_SELECTED | LVS_SHOWSELALWAYS )& ~LVS_EX_TRACKSELECT);
  687. m_nodeList.InsertColumn( ID_FIELD, "Id");
  688. m_nodeList.InsertColumn( NODE_ID_TXT, "Node Id");
  689. m_nodeList.InsertColumn( DEVICE_TYPE, "Device Type");
  690. m_nodeList.InsertColumn(TX_COUNT, "TxCount");
  691. itemIndex = 0;
  692. m_nodeList.SetColumnWidth( ID_FIELD, 0);
  693. m_nodeList.SetColumnWidth( NODE_ID_TXT, 50);
  694. m_nodeList.SetColumnWidth( DEVICE_TYPE, 120);
  695. m_nodeList.SetColumnWidth( TX_COUNT, 50);
  696. if (ReloadNodeList())
  697.   {
  698.           m_txtStatus.SetWindowText("Nodes copied from Z-Wave module.");
  699.   }
  700. EnableButtons(TRUE);
  701. /*Set the node type to Generic controller, NOT listening*/
  702. BYTE ca[1];
  703. APPL_NODE_TYPE appType;
  704. ca[0] = 0;
  705. /*        appType.specific = */
  706. appType.generic = GENERIC_TYPE_GENERIC_CONTROLLER;
  707. api.SerialAPI_ApplicationNodeInformation(FALSE,appType, ca, 0 );
  708. /*Set Idle learn mode function.*/
  709. api.ZW_SetIdleNodeLearn(IdleLearnNodeState_Compl);
  710. /*reset timer*/
  711. timerID.eventID = 0;
  712.    /* Print the node table */
  713. DisplayStandardItems();
  714. memset(nodeState, 0, sizeof(nodeState));
  715.   /*Verify if ApplicationNodeInformation is stored correctly*/
  716.   BYTE HomeId[4];
  717.   BYTE NodeId;
  718.   NODEINFO nodeInfo;
  719.   api.MemoryGetID(HomeId, &NodeId);
  720.   api.ZW_GetNodeProtocolInfo(NodeId,&nodeInfo);
  721.   if(nodeInfo.nodeType.generic!= appType.generic)
  722.   {
  723.     m_txtStatus.SetWindowText("Incorrect type set for this nodetype. Please reset module");
  724.     EnableButtons(false);
  725.     m_btnResetTool.EnableWindow(true);
  726.     m_btnQuit.EnableWindow(true);
  727. //    api.ZW_SetDefault(SetDefault_Compl);
  728.   }
  729. return TRUE;  // return TRUE  unless you set the focus to a control
  730. }
  731. BYTE CInstallerToolDlg::FindLib(int PortValue, BYTE bySpeed)
  732. {
  733.    if (api.Initialize(PortValue, bySpeed, ApplicationCommandHandler, CommErrorNotification))
  734.    {
  735.       libType = api.ZW_Version((BYTE*)uCversion);        //Get the lib type and version from module
  736.   switch (libType)
  737.   {
  738.     case ZW_NO_INTELLIGENT_LIFE:
  739. {
  740.     api.Shutdown();
  741. str.Format("No Serial API code detected on port: com%d - check serial connections.nThis application requires an Installer version of the Serial APInon a Z-Wave module connected via a serialport.nDownload the correct Serial API code to the Z-Wave Module and restart the application.", PortValue);
  742. }
  743.         break;  
  744. case ZW_LIB_CONTROLLER_STATIC:
  745. {
  746.               api.Shutdown();
  747.              str.Format("Controller based serial API code detected on port: com%d.nThis application requires an Installer version of the Serial APInon a Z-Wave module connected via a serialport.nDownload the correct Serial API code to the Z-Wave Module and restart the application.", PortValue);
  748. }
  749.         break;  
  750. case ZW_LIB_CONTROLLER:
  751. {
  752.              api.Shutdown();
  753.             str.Format("Controller based serial API code detected on port: com%d.nThis application requires an Installer version of the Serial APInon a Z-Wave module connected via a serialport.nDownload the correct Serial API code to the Z-Wave Module and restart the application.", PortValue);
  754.          }
  755.         break;  
  756. case ZW_LIB_SLAVE_ENHANCED:
  757. {
  758.      api.Shutdown();
  759.              str.Format("Enhanced Slave based serial API code detected on port: com%d.nThis application requires an Installer version of the Serial APInon a Z-Wave module connected via a serialport.nDownload the correct Serial API code to the Z-Wave Module and restart the application.", PortValue);
  760.          }
  761.         break;  
  762. case ZW_LIB_SLAVE:
  763. {
  764.     api.Shutdown();
  765. str.Format("Slave based serial API code detected on port: com%d.nThis application requires an Installer version of the Serial APInon a Z-Wave module connected via a serialport.nDownload the correct Serial API code to the Z-Wave Module and restart the application.", PortValue);
  766. }
  767.         break;  
  768. case ZW_LIB_INSTALLER:
  769. {
  770.     char portstr[8];
  771. sprintf(portstr,"COM%d:",PortValue);
  772. Open(portstr);
  773. sprintf((char *)uCversion,"%s - Installer",uCversion);
  774. }
  775.         break;  
  776. default:
  777. {
  778.     api.Shutdown();
  779.             str.Format("This application requires an Installer version of the Z-Wave module connected to the serialport.nnDownload the correct Serial API code to the Z-Wave Module and restart the application.");
  780. }
  781.         break;  
  782. }
  783.    }
  784. return libType;
  785. }
  786. /*============================ OnSysCommand ===============================
  787. ** Function description
  788. **      System command handler (Prints the About box
  789. ** Side effects:
  790. **
  791. **--------------------------------------------------------------------------*/
  792. void CInstallerToolDlg::OnSysCommand(UINT nID, LPARAM lParam)
  793. {
  794. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  795. {
  796. CAboutDlg dlgAbout;
  797. dlgAbout.DoModal();
  798. }
  799. else
  800. {
  801. CDialog::OnSysCommand(nID, lParam);
  802.         }
  803. }
  804. /*============================ OnPaint ===============================
  805. ** Function description
  806. **         If you add a minimize button to your dialog, you will need the code below
  807. **         to draw the icon.  For MFC applications using the document/view model,
  808. **         this is automatically done for you by the framework.
  809. **      
  810. ** Side effects:
  811. **
  812. **--------------------------------------------------------------------------*/
  813. void CInstallerToolDlg::OnPaint()
  814. {
  815. if (IsIconic())
  816. {
  817. CPaintDC dc(this); // device context for painting
  818. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  819. // Center icon in client rectangle
  820. int cxIcon = GetSystemMetrics(SM_CXICON);
  821. int cyIcon = GetSystemMetrics(SM_CYICON);
  822. CRect rect;
  823. GetClientRect(&rect);
  824. int x = (rect.Width() - cxIcon + 1) / 2;
  825. int y = (rect.Height() - cyIcon + 1) / 2;
  826. // Draw the icon
  827. dc.DrawIcon(x, y, m_hIcon);
  828. }
  829. else
  830. {
  831. CDialog::OnPaint();
  832. DrawRoutingTable();
  833. }
  834. }
  835. // The system calls this to obtain the cursor to display while the user drags
  836. //  the minimized window.
  837. HCURSOR CInstallerToolDlg::OnQueryDragIcon()
  838. {
  839. return (HCURSOR) m_hIcon;
  840. }
  841. /*================================= DoDot ====================================
  842. ** Function description
  843. **      Paints a scaled square at the relative position given by x and y.
  844. **         Assumes that the resolution is pixels*pixels
  845. ** Side effects:
  846. **
  847. **--------------------------------------------------------------------------*/
  848. void DoDot(CDC *dc,         /*IN Device context pointer to update*/
  849.    int x,         /*IN relative x position*/
  850.    int y,         /*IN relative y position*/
  851.    COLORREF color,  /*IN Fill color*/
  852.    int pixels,         /*IN x or y number of total pixels for the whole node map*/
  853.    int maxNodes)        /*IN The number of nodes to make room for in the bitmap*/
  854. {
  855.     CBrush bkBrush;
  856. int scale =(int)(((float)pixels)/(float)maxNodes);
  857. int size = scale/2;
  858. int xCenter = scale*x-size;
  859. int yCenter = scale*y-size;
  860. //Create color to use for drawing
  861. bkBrush.CreateSolidBrush(color);
  862. //Set the color
  863. (CBrush*)dc->SelectObject(bkBrush);
  864. dc->Rectangle((xCenter-size),(yCenter-size),(xCenter+size),(yCenter+size));
  865. }
  866. /*============================ IsBitSet =====================================
  867. ** Function description
  868. **      Checks if a bit is set in a given nodemask
  869. ** Side effects:
  870. **
  871. **--------------------------------------------------------------------------*/
  872. BYTE         /*RET TRUE if bit is set, FALSE if not*/
  873. IsBitSet(BYTE nodeID,         /*IN Node ID to check for*/
  874.   BYTE *nodeMask)        /*IN Pointer to the nodemask to use*/
  875. {
  876. BYTE retVal = FALSE;
  877. BYTE byteToLookIn = (nodeID-1)/8;
  878. BYTE bitToLookAt = (nodeID-1)%8;
  879. if(((nodeMask[byteToLookIn]>>bitToLookAt)&0x01)!=0)
  880. retVal = TRUE;
  881. return retVal;
  882. }
  883. /*============================ DrawLegend ===================================
  884. ** Function description
  885. **      Draws a color coded legend which shows the colors attached to
  886. **         nodetypes
  887. ** Side effects:
  888. **
  889. **--------------------------------------------------------------------------*/
  890. void CInstallerToolDlg::DrawLegend(void)
  891. {
  892. int y;
  893. int scale =sizeof(nodeTypeList)+6;
  894. int size = scale/2;
  895. CStatic *m_test = (CStatic*) GetDlgItem(IDC_LEGEND);
  896. CDC *dc = m_test->GetDC();
  897. CFont font;
  898. //Set the pen and color
  899. font.CreatePointFont(scale*5,"Ariel");
  900. (CFont*)dc->SelectObject(font);
  901. for(y=0;y<sizeof(nodeTypeList);y++)
  902. {
  903. CBrush bkBrush;
  904. bkBrush.CreateSolidBrush(GetNodeColor(nodeTypeList[y],FALSE));
  905. (CBrush*)dc->SelectObject(bkBrush);
  906. int xCenter = scale*1;
  907. int yCenter = scale*y+size;//-(scale/2);
  908. char txt[40];
  909. dc->Rectangle((xCenter-2*size),(yCenter-size+1),(xCenter),(yCenter+size-1));
  910. sprintf(txt,"%s",WriteNodeTypeString(nodeTypeList[y]));
  911. dc->TextOut(xCenter+size,yCenter-size,txt);
  912. }
  913. dc->Detach();
  914. }
  915. /*============================  GetNodeColor ============================
  916. ** Function description
  917. **      Returns the color associated with a given node ID
  918. ** Side effects:
  919. **
  920. **--------------------------------------------------------------------------*/
  921. COLORREF CInstallerToolDlg::GetNodeColor(BYTE nodeID, BOOL useID = TRUE)
  922. {
  923. COLORREF color;
  924. BYTE use;
  925. if(useID)
  926. use = nodeType[nodeID];
  927. else
  928. use = nodeID;
  929. switch(use)
  930. {
  931. case 0:
  932. color = NO_NODE_COLOR;
  933. break;
  934.    case GENERIC_TYPE_GENERIC_CONTROLLER:
  935. color = NODE_GT_COLOR;
  936. break;
  937.    case GENERIC_TYPE_STATIC_CONTROLLER:
  938.            color = NODE_ST_COLOR;
  939. break;
  940.    case GENERIC_TYPE_SWITCH_BINARY:
  941.            color = NODE_SB_COLOR;
  942. break;
  943.    case GENERIC_TYPE_SWITCH_MULTILEVEL:
  944.            color = NODE_SM_COLOR;
  945. break;
  946.    case GENERIC_TYPE_SENSOR_BINARY:
  947.            color = NODE_SENB_COLOR;
  948. break;
  949.    case GENERIC_TYPE_SENSOR_MULTILEVEL:
  950. color = NODE_SENM_COLOR;
  951. break;
  952.    case GENERIC_TYPE_METER_PULSE:
  953. color = NODE_MB_COLOR;
  954. break;
  955.    case GENERIC_TYPE_ENTRY_CONTROL:
  956. color = NODE_EC_COLOR;
  957. break;
  958. default:
  959. color = NODE_UNKNOWN_COLOR;
  960. }
  961. return color;
  962. }
  963. /*============================  DrawRoutingTable ============================
  964. ** Function description
  965. **      Draws the routing Table from the global array routingTable[][]
  966. ** Side effects:
  967. **
  968. **--------------------------------------------------------------------------*/
  969. void CInstallerToolDlg::DrawRoutingTable(void)
  970. {
  971. int x,y;
  972. int nodeToUse=1;
  973. BOOL mirror=FALSE;
  974. CStatic *m_test = (CStatic*) GetDlgItem(IDC_ROUTEMAP);
  975. CDC *dc = m_test->GetDC();
  976. COLORREF color;
  977. CFont font;
  978.     CBrush bkBrush;
  979. //Set the pen and color
  980. font.CreatePointFont(60,"Ariel");
  981. (CFont*)dc->SelectObject(font);
  982. /*Clear the rectangle*/
  983. dc->FillSolidRect(-20,-20,GRAPH_TOPOLOGY_SIZE+20,GRAPH_TOPOLOGY_SIZE+20,dc->GetBkColor());
  984. //Draw the topologi from routingTable[][]
  985. if(bMaxNodeID)
  986. {
  987. for(y=1;y<=bMaxNodeID;y++)
  988. {
  989. for(x=1;x<=bMaxNodeID;x++)
  990. {
  991. if(x==y)
  992. {
  993. color = NO_NODE_COLOR;
  994. }
  995. else if(IsBitSet(x,routingTable[y-1]))
  996. {
  997. color = NODE_OK_COLOR;
  998. }
  999. else
  1000. {
  1001. if(nodeType[x])
  1002. color = NODE_BAD_COLOR;
  1003. else
  1004. color = NO_NODE_COLOR;
  1005. }
  1006. if(nodeType[y]==0)
  1007. color = NO_NODE_COLOR;
  1008. DoDot(dc,x,y,color,GRAPH_TOPOLOGY_SIZE,bMaxNodeID);
  1009. }
  1010. }
  1011. /*Draw the legend*/
  1012. for(y=1;y<=bMaxNodeID;y++)
  1013. {
  1014. CBrush bkBrush;
  1015. bkBrush.CreateSolidBrush(GetNodeColor(y));
  1016. (CBrush*)dc->SelectObject(bkBrush);
  1017. int scale =(int)(((float)GRAPH_TOPOLOGY_SIZE)/(float)bMaxNodeID);
  1018. int size = scale/2;
  1019. int xCenter = 0;
  1020. int yCenter = scale*y-(scale/2);
  1021. char txt[4];
  1022. if(size>10)
  1023. size = 10;
  1024. dc->Rectangle((xCenter-2*size),(yCenter-size),(xCenter),(yCenter+size));
  1025. sprintf(txt,"%i",y);
  1026. if((!(y%5))||(y==1))
  1027. {
  1028. dc->TextOut(-20,yCenter-5,txt);
  1029. dc->TextOut(yCenter-5,-10,txt);
  1030. }
  1031. }
  1032. }/*if Max ID*/
  1033. DrawLegend();
  1034. }
  1035. /*============================ OnTOPOLOGY ===============================
  1036. ** Function description
  1037. **      Called when the Get Topology button is pressed.
  1038. **         This function loads the routingtable from the z-wavemodule and
  1039. **         prints it out
  1040. ** Side effects:
  1041. **
  1042. **--------------------------------------------------------------------------*/
  1043. void CInstallerToolDlg::OnTOPOLOGY()
  1044. {
  1045. //Get the topology from the device module.
  1046. //For test purpuse we make a bitmap!
  1047. //Get the topology from Z-Wave module
  1048. int y;
  1049. char txt[20],i;
  1050. /*Reload the nodelist from the module*/
  1051. DisplayStandardItems();
  1052. for(y=1;y<=bMaxNodeID;y++)
  1053. {
  1054. if(nodeType[y])
  1055. {
  1056. api.ZW_GetRoutingInfo(y,routingTable[y-1],FALSE,FALSE);
  1057. sprintf(txt,"Reading %i",y);
  1058. m_txtStatus.SetWindowText(txt);
  1059. }
  1060. else
  1061. {        /*No node here.. Reset values*/
  1062. for(i=0;i<(MAX_NODES/8);i++)
  1063. routingTable[y-1][i]=0;
  1064. }
  1065. }
  1066. m_txtStatus.SetWindowText("Routing table read!");
  1067. DrawRoutingTable();
  1068. }
  1069. /*============================   TXTestComplete =============================
  1070. ** Function description
  1071. **      Callback function for completion of the TX test
  1072. ** Side effects:
  1073. **
  1074. **--------------------------------------------------------------------------*/
  1075. void CInstallerToolDlg::TXTestComplete(BYTE txStatus)
  1076. {
  1077. BYTE command[10];
  1078. char str[40];
  1079. char txt[40];
  1080. char count = api.ZW_GetTXCounter();
  1081. int s = selected[locateCount-1];
  1082. sprintf(str,"%i",count);
  1083. if (txStatus != TRANSMIT_COMPLETE_OK)
  1084. {
  1085. GetInstance()->m_txtStatus.SetWindowText(OPERATION_FAILED_STR);
  1086. sprintf(str,"nACK");
  1087. }
  1088. GetInstance()->SetNodeIDText(s,TX_COUNT,str);
  1089. api.ZW_ResetTXCounter();
  1090. if(bAbortNow)
  1091. {
  1092. GetInstance()->m_txtStatus.SetWindowText("User Aborted");
  1093. return;
  1094. }
  1095. /*Transmit to next in line if any*/
  1096. if((locateCount<=selectCount)&&(nodeType[selected[locateCount]]!=0))
  1097. {
  1098. sprintf(txt, "Transmitting to node: %i", selected[locateCount]);
  1099. GetInstance()->m_txtStatus.SetWindowText(txt);
  1100. command[CMDBUF_CMDCLASS_OFFSET] = 0;
  1101. command[CMDBUF_CMD_OFFSET] = 0;
  1102. GetInstance()->EnableButtons(FALSE);
  1103. api.ZW_SendData(selected[locateCount++], command, 2,
  1104. TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_ACK, TXTestComplete);
  1105. }
  1106. else
  1107. {
  1108. GetInstance()->EnableButtons(TRUE);
  1109. GetInstance()->m_txtStatus.SetWindowText(OPERATION_SUCCESS_STR);
  1110. }
  1111. GetInstance()->m_txtStatus.SetWindowText(str);
  1112. }
  1113. /*============================   OnCheckLink =================================
  1114. ** Function description
  1115. **      Makes a NOP operation to the node selected and updates the TX count
  1116. **         needed to reach the node.
  1117. ** Side effects:
  1118. **
  1119. **--------------------------------------------------------------------------*/
  1120. void CInstallerToolDlg::OnCheckLink()
  1121. {
  1122. BYTE command[10];
  1123. char txt[40];
  1124. api.ZW_ResetTXCounter();
  1125. bAbortNow = FALSE;
  1126. GetUnitList(selected, &selectCount);
  1127. if(selectCount!=0)
  1128. {
  1129. locateCount = 0;
  1130. if((locateCount<=selectCount)&&(nodeType[selected[locateCount]]!=0))
  1131. {
  1132. sprintf(txt, "Transmitting to node: %i", selected[locateCount]);
  1133. m_txtStatus.SetWindowText(txt);
  1134. command[CMDBUF_CMDCLASS_OFFSET] = 0;
  1135. command[CMDBUF_CMD_OFFSET] = 0;
  1136. EnableButtons(FALSE);
  1137. api.ZW_SendData(selected[locateCount++], command, 2,
  1138. TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_ACK, TXTestComplete);
  1139. }
  1140. else
  1141. m_txtStatus.SetWindowText(OPERATION_FAILED_STR);
  1142. }
  1143. else
  1144. m_txtStatus.SetWindowText(NO_NODES_SELECTED_STR);
  1145. }
  1146. /*============================ OnGetNeighbors ===============================
  1147. ** Function description
  1148. **      Function called when the Get Neighbour button is pressed.
  1149. ** Side effects:
  1150. **
  1151. **--------------------------------------------------------------------------*/
  1152. void CInstallerToolDlg::OnGetNeighbors()
  1153. {
  1154. char txt[40];
  1155. GetUnitList(selected, &selectCount);
  1156. bAbortNow = FALSE;
  1157. if(selectCount!=0)
  1158. {
  1159. locateCount = 0;
  1160. if((locateCount<=selectCount)&&(nodeType[selected[locateCount]]!=0))
  1161. {
  1162. sprintf(txt,"Getting neighbors for: %i",selected[locateCount]);
  1163. m_txtStatus.SetWindowText(txt);
  1164. GetInstance()->EnableButtons(FALSE);
  1165. api.ZW_RequestNodeNeighborUpdate(selected[locateCount++], GettingRouting);
  1166. }
  1167. else
  1168. m_txtStatus.SetWindowText(INVALID_NODE_SELECT_STR);
  1169. }else
  1170. m_txtStatus.SetWindowText(NO_NODES_SELECTED_STR);
  1171. }
  1172. /*============================ OnDrawItem ===============================
  1173. ** Function description
  1174. **      
  1175. ** Side effects:
  1176. **
  1177. **--------------------------------------------------------------------------*/
  1178. void CInstallerToolDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
  1179. {
  1180. CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
  1181. }
  1182. /*============================ NeighborDiscovery_Compl  ====================
  1183. ** Function description
  1184. **      Callback function Called when neighbour discovery terminates.
  1185. ** Side effects:
  1186. **
  1187. **--------------------------------------------------------------------------*/
  1188. void CInstallerToolDlg::NeighborDiscovery_Compl(BYTE bStatus)
  1189. {
  1190. char outstr[255];
  1191. if(bStatus == LEARN_STATE_DONE)
  1192. {
  1193. GetInstance()->m_txtStatus.SetWindowText("Discovery success");
  1194. }
  1195. if(bStatus == LEARN_STATE_FAIL)
  1196. {
  1197. sprintf(outstr, "Failed at Node %d ", selected[locateCount-1]);
  1198. GetInstance()->m_txtStatus.SetWindowText(outstr);
  1199. }
  1200. if (bStatus != LEARN_STATE_ROUTING_PENDING)
  1201. {
  1202. GetInstance()->EnableButtons(TRUE);
  1203. GetInstance()->OnTOPOLOGY();
  1204. }
  1205. }
  1206. /*============================  GettingRouting ==============================
  1207. ** Function description
  1208. **      Runs through the selected nodes and updates their neighbour information
  1209. ** Side effects:
  1210. **
  1211. **--------------------------------------------------------------------------*/
  1212. void CInstallerToolDlg::GettingRouting(BYTE bStatus)
  1213. {
  1214. char txt[40];
  1215. if (bStatus != LEARN_STATE_ROUTING_PENDING)
  1216. {
  1217. if(bAbortNow)
  1218. {
  1219. GetInstance()->m_txtStatus.SetWindowText("User Aborted");
  1220. return;
  1221. }
  1222. if(bStatus==LEARN_STATE_DONE)
  1223. {
  1224. if((locateCount<selectCount)&&(nodeType[selected[locateCount]]!=0))
  1225. {
  1226. sprintf(txt,"Getting neighbors for: %i",selected[locateCount]);
  1227. GetInstance()->m_txtStatus.SetWindowText(txt);
  1228. api.ZW_RequestNodeNeighborUpdate(selected[locateCount++], GettingRouting);
  1229. }
  1230. else
  1231. NeighborDiscovery_Compl(LEARN_STATE_DONE);
  1232. }
  1233. else
  1234. {
  1235. NeighborDiscovery_Compl(LEARN_STATE_FAIL);
  1236. sprintf(txt,"Neighbors for: %i failed",selected[locateCount-1]);
  1237. GetInstance()->m_txtStatus.SetWindowText(txt);
  1238. }
  1239. }
  1240. }
  1241. /*============================ OnLocateNode ===============================
  1242. ** Function description
  1243. **      
  1244. ** Side effects:
  1245. **
  1246. **--------------------------------------------------------------------------*/
  1247. void CInstallerToolDlg::OnLocateNode(void)
  1248. {
  1249. // TODO: Add your control notification handler code here
  1250. }
  1251. /*============================ OnReplRec ====================================
  1252. ** Function description
  1253. **      Called when the replication receive button is pressed.
  1254. ** Side effects:
  1255. **
  1256. **--------------------------------------------------------------------------*/
  1257. void CInstallerToolDlg::OnReplRec(void)
  1258. {
  1259. // TODO: Add your control notification handler code here
  1260. unsigned char i;
  1261. EnableButtons(FALSE);
  1262.   m_txtStatus.SetWindowText("Resetting remote ....");
  1263. /*Reset local nodelist*/
  1264. for(i=1;i<=ZW_MAX_NODES;i++)
  1265. AddNode(i,0);
  1266. ::PostMessage(this_hWnd, WM_USER+4, 0, 0); /*Signal*/
  1267. }
  1268. /*============================ OnReceiveRemoteData ==========================
  1269. ** Function description
  1270. **      Sets the controller in replication receive mode
  1271. ** Side effects:
  1272. **
  1273. **--------------------------------------------------------------------------*/
  1274. void CInstallerToolDlg::OnReceiveRemoteData()
  1275. {
  1276. //        ResetTables();
  1277. replSend = FALSE;
  1278. m_txtStatus.SetWindowText("Remote reset");
  1279.   api.ZW_SetLearnMode(TRUE,CopyRemoteComplete);
  1280. //        api.ZW_NewController(NEW_CTRL_STATE_RECEIVE, CopyRemoteComplete);
  1281. }
  1282. /*============================ CopyRemoteComplete ===========================
  1283. ** Function description
  1284. **      Callback function called during replication.
  1285. ** Side effects:
  1286. **
  1287. **--------------------------------------------------------------------------*/
  1288. void CInstallerToolDlg::CopyRemoteComplete(
  1289.   BYTE bStatus,  // IN  Status of learn process
  1290.   BYTE bSource,  // IN  Node id of the node that send node info
  1291.   BYTE* pCmd,    // IN  Pointer to Node information
  1292.   BYTE bLen)     // IN  Node info length
  1293. {
  1294. bLen = bLen;
  1295.         pCmd = pCmd;
  1296.   BYTE bVer = 0;
  1297.   BYTE bCapab = 0;
  1298.   if (bStatus == LEARN_MODE_STARTED)
  1299.   {
  1300.          /*Disable Abort Button once we are started*/
  1301.          GetInstance()->m_btnAbortAction.EnableWindow(FALSE);
  1302.          GetInstance()->m_txtStatus.SetWindowText("Replication started");
  1303.   }
  1304.   else if (bStatus == LEARN_MODE_FAILED)
  1305.   {
  1306.            GetInstance()->ReloadNodeList();
  1307.          GetInstance()->m_txtStatus.SetWindowText("Replication failed");
  1308.          GetInstance()->EnableButtons(TRUE);
  1309.          GetInstance()->DisplayStandardItems();
  1310.     api.ZW_ControllerChange(CONTROLLER_CHANGE_STOP_FAILED,NULL);
  1311.   }
  1312.   else if (bStatus == LEARN_MODE_DONE)
  1313.   {
  1314. /*          if(replSend)
  1315.          api.ZW_NewController(NEW_CTRL_STATE_STOP_OK, NULL);
  1316. */
  1317.     api.ZW_SetLearnMode(FALSE,NULL);
  1318.     GetInstance()->ReloadNodeList();
  1319.     GetInstance()->m_txtStatus.SetWindowText("Replication complete");
  1320.          GetInstance()->EnableButtons(TRUE);
  1321.          GetInstance()->DisplayStandardItems();
  1322.   }
  1323.   else
  1324.   {
  1325.     GetInstance()->m_txtStatus.SetWindowText("Unknown Callbackstate");
  1326.   }
  1327. }
  1328. /*============================ EnableButtons ===============================
  1329. ** Function description
  1330. **      This function is used to enable and disable the buttons on the
  1331. **         InstallerTool
  1332. ** Side effects:
  1333. **
  1334. **--------------------------------------------------------------------------*/
  1335. void CInstallerToolDlg::EnableButtons(BOOL bEnabled)
  1336. {
  1337. m_btnRecInfo.EnableWindow(bEnabled);
  1338. m_btnRestore.EnableWindow(bEnabled);
  1339. m_btnBackup.EnableWindow(bEnabled);
  1340. m_btnTopology.EnableWindow(bEnabled);
  1341. m_btnAddNode.EnableWindow(bEnabled);
  1342. m_btnCheckLink.EnableWindow(bEnabled);
  1343. m_btnLocateNode.EnableWindow(bEnabled);
  1344. m_btnQuit.EnableWindow(bEnabled);
  1345. m_btnResetTool.EnableWindow(bEnabled);
  1346. if(secondaryCtrl)
  1347. {
  1348. m_btnGetNeighbors.EnableWindow(FALSE);
  1349. m_btnResetNode.EnableWindow(FALSE);
  1350.     m_btnAddNode.EnableWindow(FALSE);
  1351.     m_btnHandOverPrimary.EnableWindow(FALSE);
  1352. }
  1353. else
  1354. {
  1355. m_btnGetNeighbors.EnableWindow(bEnabled);
  1356. m_btnResetNode.EnableWindow(bEnabled);
  1357.     m_btnAddNode.EnableWindow(bEnabled);
  1358.     m_btnHandOverPrimary.EnableWindow(bEnabled);
  1359. }
  1360. /*Only enable Abort button, Disabling is handled seperatly*/
  1361. if(bEnabled==TRUE)
  1362. m_btnAbortAction.EnableWindow(bEnabled);
  1363. }
  1364. /*============================  ===============================
  1365. ** Function description
  1366. **      
  1367. ** Side effects:
  1368. **
  1369. **--------------------------------------------------------------------------*/
  1370. void CInstallerToolDlg::OnSelchangeList2()
  1371. {
  1372. // TODO: Add your control notification handler code here
  1373. }
  1374. /*============================   WriteNodeTypeString ========================
  1375. ** Function description
  1376. **      Returns a CString containing a fitting name to the nodetype supplied
  1377. ** Side effects:
  1378. **
  1379. **--------------------------------------------------------------------------*/
  1380. CString CInstallerToolDlg::WriteNodeTypeString(BYTE nodeType)
  1381. {
  1382. switch (nodeType)
  1383.    {
  1384.    case GENERIC_TYPE_GENERIC_CONTROLLER:
  1385.    return "Generic Controller";
  1386.    case GENERIC_TYPE_STATIC_CONTROLLER:
  1387.            return "Static Controller";
  1388.    case GENERIC_TYPE_REPEATER_SLAVE:
  1389.            return "Repeater Slave";
  1390.    case GENERIC_TYPE_SWITCH_BINARY:
  1391.                return "Binary Switch";
  1392.    case GENERIC_TYPE_SWITCH_MULTILEVEL:
  1393.    return "Multilevel Switch";
  1394.    case GENERIC_TYPE_SENSOR_BINARY:
  1395.    return "Binary Sensor";
  1396.    case GENERIC_TYPE_SENSOR_MULTILEVEL:
  1397.    return "Multilevel Sensor";
  1398.    case GENERIC_TYPE_METER_PULSE:
  1399.    return "Pulse Meter";
  1400.        case GENERIC_TYPE_ENTRY_CONTROL:
  1401.            return "Entry control";
  1402.    case 0:         /* No NodeID */
  1403.    return "No device";
  1404.    default:
  1405.    return "Unknown Device type";
  1406. }
  1407. }
  1408. /*=============================== OnExit ===================================
  1409. ** Function description
  1410. **      Called when the Quit button is pressed.
  1411. ** Side effects:
  1412. **
  1413. **--------------------------------------------------------------------------*/
  1414. void CInstallerToolDlg::OnExit()
  1415. {
  1416. api.Shutdown();
  1417. EndDialog(IDCANCEL);
  1418. }
  1419. /*============================   OnAddNode =================================
  1420. ** Function description
  1421. **      Includes a new node to the network
  1422. ** Side effects:
  1423. **
  1424. **--------------------------------------------------------------------------*/
  1425. void CInstallerToolDlg::OnAddNode()
  1426. {
  1427. m_txtStatus.SetWindowText("Press button on Unit");
  1428. EnableButtons(FALSE);
  1429.   api.ZW_AddNodeToNetwork(ADD_NODE_ANY,SetLearnNodeState_Compl);
  1430. //  api.ZW_SetLearnNodeState(LEARN_NODE_STATE_NEW,SetLearnNodeState_Compl);
  1431. }
  1432. /*============================ SetLearnNodeState_Compl ======================
  1433. ** Function description
  1434. **      Called when a new node have been added
  1435. ** Side effects:
  1436. **
  1437. **--------------------------------------------------------------------------*/
  1438. void CInstallerToolDlg::SetLearnNodeState_Compl(
  1439. BYTE bStatus, /*IN Status of learn process*/
  1440. BYTE bSource, /*IN Node ID of node learned*/
  1441. BYTE *pCmd,          /*IN Pointer to node information*/
  1442. BYTE bLen)          /*IN Length of node information*/
  1443. {
  1444. if(bLen!=0)
  1445. {
  1446.       NODEINFO nodeInfo;
  1447.       api.ZW_GetNodeProtocolInfo(bSource, &nodeInfo);
  1448. /*Only store learned node type when length is != 0*/
  1449.       if (nodeInfo.nodeType.basic<BASIC_TYPE_SLAVE)
  1450.       {
  1451.          lastLearnedNodeType = nodeInfo.nodeType.basic;  /*For now we store the learned basic node type*/
  1452.       }
  1453.       else
  1454.       {
  1455.          lastLearnedNodeType = nodeInfo.nodeType.generic; /* Store learned generic node type*/
  1456.       }
  1457. lastLearnedNodeID = bSource;
  1458. }
  1459.   switch(bStatus)
  1460.   {
  1461.     case ADD_NODE_STATUS_LEARN_READY:
  1462.       break;
  1463.     case ADD_NODE_STATUS_NODE_FOUND:
  1464.                /*Disable Abort button*/
  1465.              GetInstance()->m_btnAbortAction.EnableWindow(FALSE);
  1466.     GetInstance()->m_txtStatus.SetWindowText("Waiting ...");
  1467.       break;
  1468.     case ADD_NODE_STATUS_ADDING_SLAVE:
  1469.     GetInstance()->m_txtStatus.SetWindowText("Adding slave unit...");
  1470.       break;
  1471.     case ADD_NODE_STATUS_ADDING_CONTROLLER:
  1472.     GetInstance()->m_txtStatus.SetWindowText("Adding Controller unit...");
  1473.       break;
  1474.     case ADD_NODE_STATUS_PROTOCOL_DONE:
  1475.     case ADD_NODE_STATUS_DONE:
  1476.       api.ZW_AddNodeToNetwork(ADD_NODE_STOP,NULL);
  1477.           GetInstance()->m_txtStatus.SetWindowText("Node included ...");
  1478.   GetInstance()->AddNode(lastLearnedNodeID,lastLearnedNodeType);
  1479.            GetInstance()->DisplayStandardItems();
  1480.       GetInstance()->ReloadNodeList();
  1481.            GetInstance()->EnableButtons(TRUE);
  1482.       break;
  1483.     case ADD_NODE_STATUS_FAILED:
  1484.     default:
  1485. /*If were not pending, we want to turn off learn mode..*/
  1486.            GetInstance()->EnableButtons(TRUE);
  1487.       api.ZW_AddNodeToNetwork(ADD_NODE_STOP,NULL);
  1488.            GetInstance()->DisplayStandardItems();
  1489. GetInstance()->m_txtStatus.SetWindowText(OPERATION_FAILED_STR);
  1490.       break;
  1491.   }
  1492. }
  1493. /*============================ OnResetNode ===============================
  1494. ** Function description
  1495. **      Called when the Reset Node button is called
  1496. ** Side effects:
  1497. **
  1498. **--------------------------------------------------------------------------*/
  1499. void CInstallerToolDlg::OnResetNode()
  1500. {
  1501. m_txtStatus.SetWindowText("Press button on Unit");
  1502. EnableButtons(FALSE);
  1503.   api.ZW_RemoveNodeFromNetwork(REMOVE_NODE_ANY,SetLearnNodeStateDelete_Compl);
  1504. //        api.ZW_SetLearnNodeState(LEARN_NODE_STATE_DELETE,SetLearnNodeStateDelete_Compl);
  1505. }
  1506. /*============================ SetLearnNodeStateDelete_Compl ================
  1507. ** Function description
  1508. **      Callback function for when deleting a node
  1509. ** Side effects:
  1510. **
  1511. **--------------------------------------------------------------------------*/
  1512. void CInstallerToolDlg::SetLearnNodeStateDelete_Compl(BYTE bStatus,
  1513.   BYTE bSource,
  1514.   BYTE *pCmd,
  1515.   BYTE bLen)
  1516. {
  1517.   switch(bStatus)
  1518.   {
  1519.     case REMOVE_NODE_STATUS_LEARN_READY:
  1520.       break;
  1521.     case REMOVE_NODE_STATUS_NODE_FOUND:
  1522. /*Disable Abort button*/
  1523. GetInstance()->m_btnAbortAction.EnableWindow(FALSE);
  1524. GetInstance()->m_txtStatus.SetWindowText("Waiting..");
  1525.       break;
  1526.     case REMOVE_NODE_STATUS_REMOVING_SLAVE:
  1527.     case REMOVE_NODE_STATUS_REMOVING_CONTROLLER:
  1528.   GetInstance()->m_txtStatus.SetWindowText("Node reset..");
  1529.   GetInstance()->RemoveNodeFromList(bSource);
  1530.   GetInstance()->AddNode(bSource,0);
  1531.     case REMOVE_NODE_STATUS_DONE:
  1532.   GetInstance()->EnableButtons(TRUE);
  1533.       api.ZW_AddNodeToNetwork(REMOVE_NODE_STOP,NULL);
  1534.   GetInstance()->DisplayStandardItems();
  1535.       break;
  1536.     case REMOVE_NODE_STATUS_FAILED:
  1537.     default:
  1538. /*If were not pending, we want to turn off learn mode..*/
  1539. GetInstance()->EnableButtons(TRUE);
  1540.     api.ZW_AddNodeToNetwork(REMOVE_NODE_STOP,NULL);
  1541. GetInstance()->DisplayStandardItems();
  1542. GetInstance()->m_txtStatus.SetWindowText(OPERATION_FAILED_STR);
  1543.       break;
  1544.   }
  1545. }
  1546. /*============================ SetDefault_Compl ==============================
  1547. ** Function description
  1548. **      Callback function for resetting Z-Wave module
  1549. ** Side effects:
  1550. **
  1551. **--------------------------------------------------------------------------*/
  1552. void CInstallerToolDlg::SetDefault_Compl()
  1553. {
  1554. GetInstance()->ReloadNodeList();
  1555. GetInstance()->DisplayStandardItems();
  1556. GetInstance()->EnableButtons(TRUE);
  1557. GetInstance()->OnTOPOLOGY();
  1558. }
  1559. /*============================ OnResetTool ==================================
  1560. ** Function description
  1561. **      Called when Reset Tool button is pressed
  1562. ** Side effects:
  1563. **
  1564. **--------------------------------------------------------------------------*/
  1565. void CInstallerToolDlg::OnResetTool()
  1566. {
  1567. EnableButtons(FALSE);
  1568. m_txtStatus.SetWindowText("Resetting Installer Tool..");
  1569. api.ZW_SetDefault(SetDefault_Compl);
  1570. }
  1571. /*============================ OnMouseMove ==============================
  1572. ** Function description
  1573. **      Called when the mouse is moved. This place is used to update
  1574. **         the text associated with the routing table
  1575. ** Side effects:
  1576. **
  1577. **--------------------------------------------------------------------------*/
  1578. void CInstallerToolDlg::OnMouseMove(UINT nFlags, CPoint point)
  1579. {
  1580. CStatic *m_test = (CStatic*) GetDlgItem(IDC_ROUTEMAP);
  1581. CDC *dc = m_test->GetDC();
  1582. POINT mypoint;
  1583. RECT rect;
  1584. char txt[100];
  1585. if(bMaxNodeID)
  1586. {
  1587. int scale =(int)(((float)GRAPH_TOPOLOGY_SIZE)/(float)bMaxNodeID);
  1588. int xCenter = 0;
  1589. int yCenter = 0;
  1590. CDialog::OnMouseMove(nFlags, point);
  1591. /*Get the coords of static*/
  1592. m_test->GetWindowRect(&rect);
  1593. mypoint.x = rect.left;
  1594. mypoint.y = rect.top;
  1595. ScreenToClient(&mypoint);
  1596. mypoint.x = point.x-mypoint.x;
  1597. mypoint.y = point.y-mypoint.y;
  1598. /*Calculate node number*/
  1599. xCenter = mypoint.x/scale+1;
  1600. yCenter = mypoint.y/scale+1;
  1601. if((xCenter>0)&&(xCenter<=bMaxNodeID)&&
  1602. (yCenter>0)&&(yCenter<=bMaxNodeID))
  1603. {
  1604. sprintf(txt,"%s(%i),%s(%i)",WriteNodeTypeString(nodeType[yCenter]),yCenter,
  1605. WriteNodeTypeString(nodeType[xCenter]),xCenter);
  1606. m_txtNodePoint.SetWindowText(txt);
  1607. }
  1608. }
  1609. }
  1610. /*============================   TestNodeSetComplete   =======================
  1611. ** Function description
  1612. **      Callback function for completion of the TX test
  1613. ** Side effects:
  1614. **
  1615. **--------------------------------------------------------------------------*/
  1616. void CInstallerToolDlg::TestNodeSetComplete(BYTE command)
  1617. {
  1618. UINT testFrames = GetInstance()->m_uintFrames;
  1619. if (command != TRANSMIT_COMPLETE_OK)
  1620. {
  1621. GetInstance()->m_txtLQResult.SetWindowText(OPERATION_FAILED_STR);
  1622. GetInstance()->EnableButtons(TRUE);
  1623. }
  1624. else
  1625. {
  1626. GetInstance()->m_txtLQResult.SetWindowText("Link check started");
  1627. GetInstance()->timerID.timeOutCount = testFrames*4,5+1; //Time out in 0.1 sec
  1628. GetInstance()->timerID.eventID = GetInstance()->SetTimer(REPORT_LEVEL_TIMEOUT,TIMEOUT_TIME,NULL); //Run it every 100ms
  1629. }
  1630. }
  1631. /*============================ OnLButtonDblClk ==============================
  1632. ** Function description
  1633. **      Called when the Left mouse button is double clicked.
  1634. **         This is used to handle events when doubleclicking the routing table
  1635. ** Side effects:
  1636. **
  1637. **--------------------------------------------------------------------------*/
  1638. void CInstallerToolDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
  1639. {
  1640. CStatic *m_test = (CStatic*) GetDlgItem(IDC_ROUTEMAP);
  1641. CDC *dc = m_test->GetDC();
  1642. POINT mypoint;
  1643. RECT rect;
  1644. ZW_APPLICATION_TX_BUFFER command;
  1645. if(bMaxNodeID)
  1646. {
  1647. int scale =(int)(((float)GRAPH_TOPOLOGY_SIZE)/(float)bMaxNodeID);
  1648. int xCenter = 0;
  1649. int yCenter = 0;
  1650. CDialog::OnLButtonDblClk(nFlags, point);
  1651. m_test->GetWindowRect(&rect);
  1652. mypoint.x = rect.left;
  1653. mypoint.y = rect.top;
  1654. ScreenToClient(&mypoint);
  1655. mypoint.x = point.x-mypoint.x;
  1656. mypoint.y = point.y-mypoint.y;
  1657. /*Calculate node number, from coord*/
  1658. xCenter = mypoint.x/scale+1;
  1659. yCenter = mypoint.y/scale+1;
  1660. /*If we are within node table then select the nodes in the list box*/
  1661. if((xCenter>0)&&(xCenter<=bMaxNodeID)&&
  1662. (yCenter>0)&&(yCenter<=bMaxNodeID)&&
  1663. (xCenter!=yCenter))
  1664. {
  1665. EnableButtons(FALSE);
  1666. CListBox *m_NodeTable = (CListBox*) GetDlgItem(IDC_LIST2);
  1667. m_NodeTable->SetSel(xCenter-1);
  1668. m_NodeTable->SetSel(yCenter-1);
  1669. command.ZW_PowerLevelTestNodeSetFrame.cmd = POWERLEVEL_TEST_NODE_SET;
  1670. command.ZW_PowerLevelTestNodeSetFrame.cmdClass = COMMAND_CLASS_POWERLEVEL;
  1671. command.ZW_PowerLevelTestNodeSetFrame.nodeId = xCenter;
  1672. if(m_cTXLevel.GetCurSel()!=CB_ERR)
  1673. {
  1674. timerID.nodeID = yCenter;
  1675. command.ZW_PowerLevelTestNodeSetFrame.powerLevel = m_cTXLevel.GetCurSel();
  1676. command.ZW_PowerLevelTestNodeSetFrame.testFrameCountMsb = m_uintFrames>>8;
  1677. command.ZW_PowerLevelTestNodeSetFrame.testFrameCountLsb = m_uintFrames;
  1678. api.ZW_SendData(yCenter,&command.ZW_PowerLevelTestNodeSetFrame.cmdClass,sizeof(ZW_POWERLEVEL_TEST_NODE_SET_FRAME),
  1679. TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_ACK,TestNodeSetComplete);
  1680. }
  1681. else
  1682. {
  1683. m_txtLQResult.SetWindowText("Error select Power level");
  1684. EnableButtons(TRUE);
  1685. }
  1686. }
  1687. } /*bMaxNodeID*/
  1688. }
  1689. void CInstallerToolDlg::OnChangeEdit1()
  1690. {
  1691. // TODO: If this is a RICHEDIT control, the control will not
  1692. // send this notification unless you override the CDialog::OnInitDialog()
  1693. // function and call CRichEditCtrl().SetEventMask()
  1694. // with the ENM_CHANGE flag ORed into the mask.
  1695. UpdateData(TRUE);
  1696. // TODO: Add your control notification handler code here
  1697. }
  1698. void CInstallerToolDlg::OnEditchangeCombo1()
  1699. {
  1700. // TODO: Add your control notification handler code here
  1701. }
  1702. /*============================   TestNodeGetComplete   =======================
  1703. ** Function description
  1704. **      Callback function for completion of the TX test
  1705. ** Side effects:
  1706. **
  1707. **--------------------------------------------------------------------------*/
  1708. void CInstallerToolDlg::TestNodeGetComplete(BYTE command)
  1709. {
  1710. BYTE i, nodeCount=0;
  1711. if (command != TRANSMIT_COMPLETE_OK)
  1712. {
  1713. GetInstance()->m_txtLQResult.SetWindowText(OPERATION_FAILED_STR);
  1714. GetInstance()->EnableButtons(TRUE);
  1715. }
  1716. else
  1717. {
  1718. GetInstance()->m_txtLQResult.SetWindowText("Link check started");
  1719. /*Calculate timeout in ms.*/
  1720. for(i=1;i<=bMaxNodeID;i++)
  1721. if(nodeType[i]!=0)
  1722. nodeCount++;
  1723. GetInstance()->timerID.timeOutCount = 10; //1 secs timeout on this one
  1724. GetInstance()->timerID.eventID = GetInstance()->SetTimer(GET_LEVEL_TIMEOUT,TIMEOUT_TIME,NULL);
  1725. }
  1726. }
  1727. /*============================   GetPowerLevelResult   =======================
  1728. ** Function description
  1729. **      Function to request result of a TX test
  1730. ** Side effects:
  1731. **
  1732. **--------------------------------------------------------------------------*/
  1733. void CInstallerToolDlg::GetPowerLevelResult(
  1734. BYTE nodeID) // Node ID to get result from
  1735. {
  1736. ZW_APPLICATION_TX_BUFFER command;
  1737. command.ZW_PowerLevelTestNodeGetFrame.cmdClass = COMMAND_CLASS_POWERLEVEL;
  1738. command.ZW_PowerLevelTestNodeGetFrame.cmd = POWERLEVEL_TEST_NODE_GET;
  1739. api.ZW_SendData(nodeID, &command.ZW_PowerLevelTestNodeGetFrame.cmdClass,
  1740. sizeof(ZW_POWERLEVEL_TEST_NODE_GET_FRAME),
  1741. TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_ACK,
  1742. TestNodeGetComplete);
  1743. }
  1744. /*============================   OnTimer  ===================================
  1745. ** Function description
  1746. **      Windows timer handling.. This function handles ON_TIMER events for
  1747. **         the InstallerTool
  1748. ** Side effects:
  1749. **
  1750. **--------------------------------------------------------------------------*/
  1751. void CInstallerToolDlg::OnTimer(UINT nIDEvent)
  1752. {
  1753. // TODO: Add your message handler code here and/or call default
  1754. CDialog::OnTimer(nIDEvent);
  1755. if((--timerID.timeOutCount==0))
  1756. {
  1757. switch(nIDEvent)
  1758. {
  1759. case REPORT_LEVEL_TIMEOUT:
  1760. if(timerID.nodeID)
  1761. GetPowerLevelResult(timerID.nodeID);
  1762. else
  1763. {
  1764. m_txtLQResult.SetWindowText("Error undefined node");
  1765. EnableButtons(TRUE);
  1766. }
  1767. break;
  1768. case GET_LEVEL_TIMEOUT:
  1769. m_txtLQResult.SetWindowText("Error no response");
  1770. EnableButtons(TRUE);
  1771. break;
  1772. }
  1773. /*We only support one timer at a time so kill the timer*/
  1774. KillTimer(nIDEvent);
  1775. }
  1776. }
  1777. /*============================   OnHandOverPrimary  ==========================
  1778. ** Function description
  1779. **      This function is called when the user wants to hand over the primary
  1780. **         controller status to another controller. Typically this would be done
  1781. **         when the Installation of the network is complete and configured.
  1782. **
  1783. ** Side effects:
  1784. **
  1785. **--------------------------------------------------------------------------*/
  1786. void CInstallerToolDlg::OnHandOverPrimary()
  1787. {
  1788. // TODO: Add your control notification handler code here
  1789. EnableButtons(FALSE);
  1790. replSend = TRUE;
  1791. m_txtStatus.SetWindowText("Waiting for Receiving Controller..");
  1792.   api.ZW_ControllerChange(CONTROLLER_CHANGE_START,SetLearnNodeState_Compl);
  1793. //        api.ZW_NewController(NEW_CTRL_STATE_CHANGE, CopyRemoteComplete);
  1794. }
  1795. /*============================   OnAbortButton  ==========================
  1796. ** Function description
  1797. **      Used to abort selected operations before they have started.
  1798. **         Button is disabled once a protocol operation is in progress.
  1799. **
  1800. ** Side effects:
  1801. **
  1802. **--------------------------------------------------------------------------*/
  1803. void CInstallerToolDlg::OnAbortButton()
  1804. {
  1805. // TODO: Add your control notification handler code here
  1806. //        api.ZW_NewController(NEW_CTRL_STATE_ABORT,NULL);
  1807. //        api.ZW_SetLearnNodeState(LEARN_NODE_STATE_OFF,NULL);
  1808.    api.ZW_AddNodeToNetwork(ADD_NODE_STATUS_DONE,NULL);
  1809. bAbortNow = TRUE;
  1810. EnableButtons(TRUE);
  1811. m_txtStatus.SetWindowText("Action Aborted by user");
  1812. }
  1813. //////////////////////////////////////////////////////////////////////////////
  1814. //  Following functions are used in the RoadMap file...
  1815. //
  1816. //
  1817. /////////////////////////////////////////////////////////////////////////////
  1818. BYTE CInstallerToolDlg::NodeGetType(BYTE NodeNumber)
  1819. {
  1820.     unitType = nodeType[NodeNumber];
  1821.     if(unitType != 0)
  1822.        return NodeNumber;
  1823.     else
  1824.     return 0;
  1825. }
  1826. // Find the neighbours used in RoadMap
  1827. int CInstallerToolDlg::FindNeighbours(int x, int y)
  1828. {
  1829.     if(IsBitSet(x,routingTable[y-1]))
  1830. {
  1831.     return x;
  1832. }
  1833.     return 0;
  1834. }
  1835. // Get MaxNodeId for for RoadMap
  1836. BYTE CInstallerToolDlg::GetMaxNodes()
  1837. {
  1838.     return bMaxNodeID;
  1839. }
  1840. void CInstallerToolDlg::Mesh()
  1841. {
  1842.     //Reload the nodelist from the module
  1843. for(int y=1;y<=bMaxNodeID;y++)
  1844. {
  1845. if(nodeType[y])
  1846. {
  1847. api.ZW_GetRoutingInfo(y,routingTable[y-1],FALSE,FALSE);
  1848. }
  1849. else
  1850. {        //No node here.. Reset values
  1851. for(int i=0;i<(MAX_NODES/8);i++)
  1852. routingTable[y-1][i]=0;
  1853. }
  1854. }
  1855. }
  1856. //void CInstallerToolDlg::PowerOnOff(BYTE *RoadList , BYTE numberUnits,void(__cdecl *completedFunc)(BYTE *txStatus))
  1857. void CInstallerToolDlg::PowerOnOff(BYTE *RoadList , BYTE numberUnits)
  1858. {
  1859.     ZW_APPLICATION_TX_BUFFER command;
  1860. command.ZW_BasicSetFrame.cmdClass = COMMAND_CLASS_BASIC;
  1861.     command.ZW_BasicSetFrame.cmd = BASIC_SET;
  1862. #if 1
  1863. if (nodeState[RoadList[0]])
  1864. {
  1865. nodeState[RoadList[0]] = 0;
  1866.     command.ZW_BasicSetFrame.value = SWITCHED_OFF;
  1867. }
  1868. else
  1869. {
  1870. nodeState[RoadList[0]] = 1;
  1871.     command.ZW_BasicSetFrame.value = SWITCHED_ON;
  1872. }
  1873. #else
  1874.     command.ZW_BasicSetFrame.value = SWITCHED_ON;
  1875. #endif
  1876.    api.ZW_SendDataMulti(RoadList, numberUnits, &command.ZW_BasicSetFrame.cmdClass, sizeof(ZW_BASIC_SET_FRAME), TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_ACK , RouteOnCompleted);
  1877. }
  1878. void CInstallerToolDlg::RouteOnCompleted(BYTE command)
  1879. {
  1880. }
  1881. void CInstallerToolDlg::AllOff()
  1882. {
  1883.     ZW_APPLICATION_TX_BUFFER command;
  1884. command.ZW_Common.cmdClass = COMMAND_CLASS_SWITCH_ALL;
  1885. command.ZW_Common.cmd = SWITCH_ALL_OFF;
  1886.   api.ZW_SendData(NODE_BROADCAST, &command.ZW_Common.cmdClass, sizeof(ZW_ALL_SWITCH_OFF_FRAME), TRANSMIT_OPTION_AUTO_ROUTE | TRANSMIT_OPTION_ACK, NULL);
  1887. }
  1888. void CInstallerToolDlg::SetSUCCompleted(BYTE bStatus)
  1889. {
  1890. if(ZW_SUC_SET_SUCCEEDED)
  1891. GetInstance()->m_txtStatus.SetWindowText("Set SUC Success..");
  1892. else
  1893. GetInstance()->m_txtStatus.SetWindowText("Set SUC failed");
  1894. }
  1895. void CInstallerToolDlg::OnBnClickedButton14()
  1896. {
  1897. // TODO: Add your control notification handler code here
  1898. BYTE nodeID = api.ZW_GetSUCNodeID();
  1899. if(!nodeID)
  1900. while((nodeType[nodeID]!=GENERIC_TYPE_STATIC_CONTROLLER)&&(nodeID<232))
  1901. nodeID++;
  1902. else
  1903. SetSUCCompleted(ZW_SUC_SET_SUCCEEDED);
  1904. if(nodeType[nodeID]==GENERIC_TYPE_STATIC_CONTROLLER)
  1905.         api.ZW_SetSUCNodeID(nodeID,TRUE,FALSE,SetSUCCompleted);
  1906. else
  1907. m_txtStatus.SetWindowText("No static controller");
  1908. }
  1909. HANDLE CInstallerToolDlg::Open(char *szComPort)
  1910. {
  1911.     hComm = CreateFile(szComPort, GENERIC_READ | GENERIC_WRITE,0, NULL, OPEN_EXISTING, NULL, NULL);
  1912. if (hComm != INVALID_HANDLE_VALUE)
  1913. {
  1914.     CloseHandle(hComm);
  1915. }
  1916.     return hComm;
  1917. }
复制代码

该会员没有填写今日想说内容.
高级模式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注2973

粉丝3237

帖子9937

发布主题
阅读排行 更多
广告位
!jz_fbzt! !jz_sgzt! !jz_xgzt! 快速回复 !jz_sctz! !jz_fhlb! 搜索

智能技术共享平台 - 未来论

关注服务号

进入小程序

全国服务中心:

运维中心:天津

未来之家:天津 青岛 济南 郑州 石家庄

                商务邮箱:xy@mywll.com

Copyright © 2012-2021 未来派 未来论 (津ICP备16000236号-5)