📄 icta_dev.c
字号:
/************************************************************************//* SISCO SOFTWARE MODULE HEADER *****************************************//************************************************************************//* (c) Copyright Systems Integration Specialists Company, Inc., *//* 1996-2002, All Rights Reserved *//* *//* MODULE NAME : ICTA_DEV.C *//* *//* MODULE DESCRIPTION : *//* handle device control functions *//* *//* GLOBAL FUNCTIONS DEFINED IN THIS MODULE : *//* ST_VOID defCfgDevices (ST_VOID) *//* ST_VOID defNewDevice (ST_VOID) *//* ST_VOID selectDevice (ST_VOID) *//* ST_VOID operateDevice (ST_VOID) *//* ST_VOID clearDevice (ST_VOID) *//* *//* *//* MODIFICATION LOG : *//* Date Who Rev Comments *//* -------- --- ------ ------------------------------------------- *//* 07/05/02 nav 10 DoDefDevices: watch for nulls *//* 09/01/00 nav 9 Send a null reason *//* 10/18/99 nav 8 Conditional auto error responses *//* 07/12/99 nav 7 Fix autoresponse for device errors *//* 06/03/99 nav 6 More thorough bAutoResponse support *//* 03/31/98 NAV 5 Add tagging support *//* 01/19/98 EJV 4 Added typecast in list functions. *//* 06/20/97 nav 3 Overhaul - One process can be client& server *//* 06/05/97 nav 2 Convert to MMS-EASE V7.00 *//* 12/27/96 NAV creation *//************************************************************************/#include "ictamain.h"#include "scrndefs.h"#include "gvaldefs.h"#include "fkeydefs.h"#include "icthread.h"/************************************************************************//* Global and Local variables *//************************************************************************/static char *thisFileName = __FILE__;static icCheckbackID checkBackId = 0;static ST_BOOLEAN bSendErrorResp = SD_FALSE;/************************************************************************//* Static Function Declarations *//************************************************************************//************************************************************************//* defCfgDevices: define configured devices for client/server/both *//************************************************************************/ST_VOID defCfgDevices (ST_VOID) {int todo; printf("\n\nDefine Configured Devices . . .\n"); todo = findOutWho(); switch (todo) { case ICTA_CLIENT: if (doDefDevices (ICTA_CLIENT, pstVCC->remoteList) == SD_SUCCESS) printf ("Client Devices Defined.\n"); else printf ("Define Client Devices Failed - See Log File.\n"); break; case ICTA_SERVER: if (doDefDevices (ICTA_SERVER, pstVCC->remoteList) == SD_SUCCESS) printf ("Server Devices Defined.\n"); else printf ("Define Server Devices Failed - See Log File.\n"); break; case ICTA_BOTH: if (doDefDevices (ICTA_SERVER, pstVCC->remoteList) == SD_SUCCESS) printf ("Server Devices Defined.\n"); else printf ("Define Server Devices Failed - See Log File.\n"); if (doDefDevices (ICTA_CLIENT, pstVCC->remoteList) == SD_SUCCESS) printf ("Client Devices Defined.\n"); else printf ("Define Client Devices Failed - See Log File.\n"); break; default: printf ("NO DEVICES defined.\n"); break; } pause_msg("\nPress a key to continue!"); showCurrMenu(); }/************************************************************************//* defNewDevice: define new device *//************************************************************************/ST_VOID defNewDevice (ST_VOID) { printf("\n\nDefine New Device . . .\n"); printf("\n Sorry - Just a Stub!!!!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); }/************************************************************************//* selectDevice: allow the client to selecte a device *//************************************************************************/ST_VOID selectDevice (ST_VOID) {ICTA_REMOTE_INFO *pstRemote;ICTA_LINK_INFO *pstLink;ICTA_DEVICE *pstDevice;ST_BOOLEAN dataEntered;ST_CHAR buffer[100];icInt status;ST_BOOLEAN bIsClient = SD_FALSE; printf("\n\nSelect Device . . .\n"); pstRemote = pstVCC->remoteList; while (pstRemote && !bIsClient) { bIsClient = pstRemote->bIsClient; pstRemote = (ICTA_REMOTE_INFO *) list_get_next ((ST_VOID *)pstVCC->remoteList, (ST_VOID *)pstRemote); } if (!bIsClient) { printf("\nSelect Device is a CLIENT ONLY Operation!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } pstRemote = pstVCC->remoteList; pstLink = findOutWhichLink(&pstRemote); if (!pstLink) { printf("\nInvalid Link!!!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } printf("\nEnter Device Name: "); dataEntered = strget(buffer); pstDevice = findClientDevice(buffer, pstRemote); if (!pstDevice) { printf("\nInvalid Device Name!!!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } status = icSelectDevice(pstDevice->deviceId, pstLink->linkId, selectDevConf, (icUserData) pstDevice); if (status) { printf ("\nSelect Device Failed "); printf ("\nStatus=%d %s", status, icPerror (status)); ICA_Log_Err3("ERROR: select device %s status =%d %s", pstDevice->name, status, icPerror(status)); } else { printf ("\nSelect Device %s Request Issued", pstDevice->name); ICA_Log_Flow1 ("Select Device Request Issued for Device %s", pstDevice->name); } pause_msg("\nPress a key to continue!"); showCurrMenu(); }/************************************************************************//* operateDevice: allow the client to operate a device *//************************************************************************/ST_VOID operateDevice (ST_VOID) {ICTA_REMOTE_INFO *pstRemote;ICTA_LINK_INFO *pstLink;ICTA_DEVICE *pstDevice;ST_BOOLEAN dataEntered;ST_CHAR buffer[100];icInt status;ST_BOOLEAN bIsClient = SD_FALSE; printf("\n\nOperate Device . . .\n"); pstRemote = pstVCC->remoteList; while (pstRemote && !bIsClient) { bIsClient = pstRemote->bIsClient; pstRemote = (ICTA_REMOTE_INFO *) list_get_next ((ST_VOID *)pstVCC->remoteList, (ST_VOID *)pstRemote); } if (!bIsClient) { printf("\nOperate Device is a CLIENT ONLY Operation!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } pstRemote = pstVCC->remoteList; pstLink = findOutWhichLink(&pstRemote); if (!pstLink) { printf("\nInvalid Link!!!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } printf("\nEnter Device Name: "); dataEntered = strget(buffer); pstDevice = findClientDevice(buffer, pstRemote); if (!pstDevice) { printf("\nInvalid Device Name!!!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } printf("\nEnter Operate Value: "); dataEntered = strget(buffer); switch (pstDevice->type) { case IC_TYPE_COMMAND: case IC_TYPE_SETPOINT_DISCRETE: pstDevice->value.int_16 = atoi(buffer); break; case IC_TYPE_SETPOINT_REAL: pstDevice->value.real_32 = (float)atof(buffer); break; } status = icOperateDevice(pstDevice->deviceId, pstLink->linkId, pstDevice->value, operateDevConf, (icUserData) pstDevice); if (status) { printf("\nOperate Device Status %d '%s'", status, icPerror(status)); ICA_Log_Err3("ERROR: operate device %s status =%d %s", pstDevice->name, status, icPerror(status)); } else { printf ("\nOperate Device Request Issued for Device %s", pstDevice->name); ICA_Log_Flow1 ("Operate Device %s Request Issued", pstDevice->name); } pause_msg("\nPress a key to continue!"); showCurrMenu(); }/************************************************************************//* clearDevice: clear a selected device *//************************************************************************/ST_VOID clearDevice (ST_VOID) {ICTA_DEVICE *pstDevice;ST_BOOLEAN dataEntered;ST_CHAR buffer[100];icInt status;ST_BOOLEAN bIsServer = SD_FALSE;ICTA_REMOTE_INFO *pstRemote; printf("\n\nClear Selected Device . . .\n"); pstRemote = pstVCC->remoteList; while (pstRemote && !bIsServer) { bIsServer = pstRemote->bIsServer; pstRemote = (ICTA_REMOTE_INFO *) list_get_next ((ST_VOID *)pstVCC->remoteList, (ST_VOID *)pstRemote); } if (!bIsServer) { printf("\nClear Device is a SERVER ONLY Operation!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } printf("\nEnter Device Name: "); dataEntered = strget(buffer); pstDevice = findServerDevice(buffer); if (!pstDevice) { printf("\nInvalid Device Name!!!"); pause_msg("\nPress a key to continue!"); showCurrMenu(); return; } status = icClearSelect(pstDevice->deviceId); if (status) { printf("\nClear Selected Device Failed - see log file for details"); ICA_Log_Err3("ERROR: clear selected device %s status =%d %s", pstDevice->name, status, icPerror(status)); } else printf("\nClear Selected Device complete successfully."); pause_msg("\nPress a key to continue!"); showCurrMenu(); }/************************************************************************//* doDefDevices: define devices for all remotes in remote list *//************************************************************************/ST_RET doDefDevices (int who, ICTA_REMOTE_INFO *remoteList) {ICTA_REMOTE_INFO *pstRemote;ICTA_DEVICE *pstDevice, *pstDeviceList;icInt status;ST_INT rtnVal = SD_SUCCESS; pstRemote = remoteList; while (pstRemote) { pstDeviceList = NULL; if (who == ICTA_CLIENT) { if (pstRemote->bIsClient) pstDeviceList = pstRemote->clientObj->devicesList; } else { if (pstRemote->bIsServer) pstDeviceList = pstRemote->serverObj->devicesList; } pstDevice = pstDeviceList; while (pstDevice) { if (!pstDevice->bDeviceDefined) { switch (who) { case ICTA_CLIENT: status = icDefineClientDevice(pstRemote->remoteId, pstDevice->name, pstDevice->scope, pstDevice->type, &pstDevice->deviceId, pstDevice->sbo); if (status) { rtnVal = SD_FAILURE; ICA_Log_Err3("ERROR: DefineClientDevice %s status = %d %s", pstDevice->name, status, icPerror(status)); } else { pstDevice->bDeviceDefined = icTrue; status = icAddClientTags (pstDevice->deviceId, icTrue); if (status) { ICA_Log_Err3 ("ERROR: AddClientTags %s status = %d %s", pstDevice->name, status, icPerror (status)); } } break; case ICTA_SERVER: status = icDefineServerDevice(pstRemote->remoteId, pstDevice->name, pstDevice->scope, pstDevice->type, (icUserData) pstDevice, &pstDevice->deviceId, pstDevice->sbo, selectDevInd, operateDevInd); if (status) { rtnVal = SD_FAILURE; ICA_Log_Err3("ERROR: DefineServerDevice %s status = %d %s", pstDevice->name, status, icPerror(status)); } else { pstDevice->bDeviceDefined = icTrue; status = icAddServerTags (pstDevice->deviceId, icTrue, getDevTagInd, setDevTagInd); if (status) { ICA_Log_Err3("Error: AddServerTags for %s status = %d %s", pstDevice->name, status, icPerror (status)); } } break; } /* end the switch */ } /* end the if */ pstDevice = (ICTA_DEVICE *) list_get_next ((ST_VOID *)pstDeviceList, (ST_VOID *)pstDevice); } /* end while pstDevice */ pstRemote = (ICTA_REMOTE_INFO *) list_get_next ((ST_VOID *)remoteList, (ST_VOID *)pstRemote); } /* end while pstRemote */ return rtnVal; }/************************************************************************//* some CallBack functions to handle device control! *//************************************************************************//* selectDevInd: server receives select device indication *//************************************************************************/void selectDevInd(icRemoteId remoteId, icUserData ud) {ICTA_DEVICE *pstDevice;icInt status;ST_BOOLEAN dataEntered;static ST_INT selErrCode = -1;ST_INT theErrCode; pstDevice = (ICTA_DEVICE *)ud; pstDevice->checkBackId = checkBackId++; printf("\n*** Received a select indication for device %s.", pstDevice->name); ICA_Log_Flow1("Server SELECT Indication for Device %s", pstDevice->name); if (bSendErrorResp) theErrCode = (++selErrCode) % 5; else theErrCode = 0; if (!bAutoResponse) { if (ask ("\n Send Error Response (N)? ",SD_FALSE)) { printf("\nEnter Error Code (1 to 4): "); if (!(dataEntered = intget(&theErrCode))) theErrCode=0; } else theErrCode = 0; } ICA_Log_CFlow2 (" Returning CheckBackId=%d, Status=%d", pstDevice->checkBackId, theErrCode); status = icSelectResponse(pstDevice->deviceId, pstDevice->checkBackId, theErrCode); printf ("\nSelect Device Response Sent with status = %d\n checkbackid=%d", pstDevice->checkBackId, selErrCode); if (status) { printf("\nSelect Device Response Failed - see log file for details"); ICA_Log_Err3("ERROR: select device response%s status =%d %s", pstDevice->name, status, icPerror(status)); } if (!bAutoResponse) { pause_msg("\nPress a key to continue!"); showCurrMenu(); } }/************************************************************************//* operateDevInd: server received an operate device indication *//************************************************************************/void operateDevInd(icRemoteId remoteId, icDeviceValue value, icUserData ud) {ICTA_DEVICE *pstDevice;icInt status;ST_BOOLEAN dataEntered;static ST_INT operErrCode = -1;ST_INT theErrCode; pstDevice = (ICTA_DEVICE *)ud; printf("\nOperateDevice Indication for Device %s", pstDevice->name); switch (pstDevice->type) { case IC_TYPE_COMMAND: case IC_TYPE_SETPOINT_DISCRETE: pstDevice->value.int_16 = value.int_16; printf("\nValue = %d", pstDevice->value.int_16); ICA_Log_Flow2("Server OPERATE Device Indication for Device %s value %d", pstDevice->name, pstDevice->value.int_16); break; case IC_TYPE_SETPOINT_REAL: pstDevice->value.real_32 = value.real_32; printf("\nValue = %f", pstDevice->value.real_32); ICA_Log_Flow2("Server OPERATE Device Indication for Device %s value %f", pstDevice->name, pstDevice->value.real_32); break; default: printf("\nInvalid Device Type."); ICA_Log_Err1("Server OPERATE Device Indication for Device %s - UNKNOWN TYPE!", pstDevice->name); break; } if (bSendErrorResp) theErrCode = (++operErrCode) % 5; else theErrCode = 0; if (!bAutoResponse) { if (ask ("\n Send Error Response (N)? ",SD_FALSE)) { printf("\nEnter Error Code (1 to 4): "); if (!(dataEntered = intget(&theErrCode)))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -