#include <userint.h>
#include "mpod_uir.h"
/** WIENER SNMP basic SNMP library to Demonstrate C-Access to WIENER-Crates via SNMP
// modified for LabView imprt 04/23/06, Andreas Ruben
//
// The path to the Net-SNMP include files (default /usr/include) must be added to the
// include file search path!
// The following libraries must be included:
// netsnmp.lib ws2_32.lib
// The path to the Net-SNMP library must be added to the linker files.
// /usr/lib
// path for the WIENER MIB file (mibdirs) c:/usr/share/snmp/mibs
*/
#include <windows.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <winsock2.h>
#include <ws2tcpip.h>
#include "netsnmplib.h"
#include "WIENER_SNMP.h"
#include "toolbox.h"
#define _strdup StrDup
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
const char* readCommunity
= "public"; ///< community name for read operations
const char* writeCommunity
= "guru"; ///< community name for write operation
// System Information OIDS
char *S_sysMainSwitch
= "sysMainSwitch.0";
oid oidSysMainSwitch
[MAX_OID_LEN
];
size_t lengthSysMainSwitch
;
char *S_sysStatus
= "sysStatus.0";
oid oidSysStatus
[MAX_OID_LEN
];
size_t lengthSysStatus
;
char *S_sysVmeSysReset
= "sysVmeSysReset.0";
oid oidSysVmeSysReset
[MAX_OID_LEN
];
size_t lengthSysVmeSysReset
;
//Output Count Information
char *S_outputNumber
= "outputNumber.0";
oid oidOutputNumber
[MAX_OID_LEN
];
size_t lengthOutputNumber
;
char *S_groupsNumber
= "groupsNumber.0";
oid oidGroupsNumber
[MAX_OID_LEN
];
size_t lengthGroupsNumber
;
//Ouput Channel information
char *S_outputNameBase
= "outputName.";
char *S_outputName
[1100];
oid oidOutputName
[1100] [MAX_OID_LEN
];
size_t lengthOutputName
[1100];
char *S_outputGroupBase
= "outputGroup.";
char *S_outputGroup
[1100];
oid oidOutputGroup
[1100] [MAX_OID_LEN
];
size_t lengthOutputGroup
[1100];
char *S_outputStatusBase
= "outputStatus.";
char *S_outputStatus
[1100];
oid oidOutputStatus
[1100] [MAX_OID_LEN
];
size_t lengthOutputStatus
[1100];
char *S_outputMeasurementSenseVoltageBase
= "outputMeasurementSenseVoltage.";
char *S_outputMeasurementSenseVoltage
[1100];
oid oidOutputMeasurementSenseVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputMeasurementSenseVoltage
[1100];
char *S_outputMeasurementTerminalVoltageBase
= "outputMeasurementTerminalVoltage.";
char *S_outputMeasurementTerminalVoltage
[1100];
oid oidOutputMeasurementTerminalVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputMeasurementTerminalVoltage
[1100];
char *S_outputMeasurementCurrentBase
="outputMeasurementCurrent.";
char *S_outputMeasurementCurrent
[1100];
oid oidOutputMeasurementCurrent
[1100] [MAX_OID_LEN
];
size_t lengthOutputMeasurementCurrent
[1100];
char *S_outputMeasurementTemperatureBase
="outputMeasurementTemperature.";
char *S_outputMeasurementTemperature
[1100];
oid oidOutputMeasurementTemperature
[1100] [MAX_OID_LEN
];
size_t lengthOutputMeasurementTemperature
[1100];
char *S_outputSwitchBase
= "outputSwitch.";
char *S_outputSwitch
[1100];
oid oidChannelSwitch
[1100] [MAX_OID_LEN
];
size_t lengthChannelSwitch
[1100];
char *S_groupSwitchBase
= "GroupSwitch.";
char *S_groupSwitch
[1100];
oid oidGroupSwitch
[1100] [MAX_OID_LEN
];
size_t lengthGroupSwitch
[1100];
char *S_outputVoltageBase
="outputVoltage.";
char *S_outputVoltage
[1100];
oid oidOutputVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputVoltage
[1100];
char *S_outputCurrentBase
= "outputCurrent.";
char *S_outputCurrent
[1100];
oid oidOutputCurrent
[1100] [MAX_OID_LEN
];
size_t lengthOutputCurrent
[1100];
char *S_outputRiseRateBase
="outputVoltageRiseRate.";
char *S_outputRiseRate
[1100];
oid oidOutputRiseRate
[1100] [MAX_OID_LEN
];
size_t lengthOutputRiseRate
[1100];
char *S_outputFallRateBase
="outputVoltageFallRate.";
char *S_outputFallRate
[1100];
oid oidOutputFallRate
[1100] [MAX_OID_LEN
];
size_t lengthOutputFallRate
[1100];
char *S_outputSupervisionBehaviorBase
="outputSupervisionBehavior.";
char *S_outputSupervisionBehavior
[1100];
oid oidOutputSupervisionBehavior
[1100] [MAX_OID_LEN
];
size_t lengthOutputSupervisionBehavior
[1100];
char *S_outputSupervisionMinSenseVoltageBase
="outputSupervisionMinSenseVoltage.";
char *S_outputSupervisionMinSenseVoltage
[1100];
oid oidOutputSupervisionMinSenseVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputSupervisionMinSenseVoltage
[1100];
char *S_outputSupervisionMaxSenseVoltageBase
="outputSupervisionMaxSenseVoltage.";
char *S_outputSupervisionMaxSenseVoltage
[1100];
oid oidOutputSupervisionMaxSenseVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputSupervisionMaxSenseVoltage
[1100];
char *S_outputSupervisionMaxTerminalVoltageBase
="outputSupervisionMaxTerminalVoltage.";
char *S_outputSupervisionMaxTerminalVoltage
[1100];
oid oidOutputSupervisionMaxTerminalVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputSupervisionMaxTerminalVoltage
[1100];
char *S_outputSupervisionMaxCurrentBase
="outputSupervisionMaxCurrent.";
char *S_outputSupervisionMaxCurrent
[1100];
oid oidOutputSupervisionMaxCurrent
[1100] [MAX_OID_LEN
];
size_t lengthOutputSupervisionMaxCurrent
[1100];
char *S_outputSupervisionMaxTemperatureBase
="outputSupervisionMaxTemperature.";
char *S_outputSupervisionMaxTemperature
[1100];
oid oidOutputSupervisionMaxTemperature
[1100] [MAX_OID_LEN
];
size_t lengthOutputSupervisionMaxTemperature
[1100];
char *S_outputConfigMaxSenseVoltageBase
="outputConfigMaxSenseVoltage.";
char *S_outputConfigMaxSenseVoltage
[1100];
oid oidOutputConfigMaxSenseVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputConfigMaxSenseVoltage
[1100];
char *S_outputConfigMaxTerminalVoltageBase
="outputConfigMaxTerminalVoltage.";
char *S_outputConfigMaxTerminalVoltage
[1100];
oid oidOutputConfigMaxTerminalVoltage
[1100] [MAX_OID_LEN
];
size_t lengthOutputConfigMaxTerminalVoltage
[1100];
char *S_outputConfigMaxCurrentBase
="outputConfigMaxCurrent.";
char *S_outputConfigMaxCurrent
[1100];
oid oidOutputConfigMaxCurrent
[1100] [MAX_OID_LEN
];
size_t lengthOutputConfigMaxCurrent
[1100];
char *S_outputConfigMaxPowerBase
="outputSupervisionMaxPower.";
char *S_outputConfigMaxPower
[1100];
oid oidOutputConfigMaxPower
[1100] [MAX_OID_LEN
];
size_t lengthOutputConfigMaxPower
[1100];
//Sensor Information
char *S_sensorNumber
="sensorNumber.0";
oid oidSensorNumber
[MAX_OID_LEN
];
size_t lengthSensorNumber
;
char *S_sensorTemperatureBase
="sensorTemperature.";
char *S_sensorTemperature
[12];
oid oidSensorTemperature
[12] [MAX_OID_LEN
];
size_t lengthSensorTemperature
[12];
char *S_sensorWarningThresholdBase
="sensorWarningThreshold.";
char *S_sensorWarningThreshold
[12];
oid oidSensorWarningThreshold
[12] [MAX_OID_LEN
];
size_t lengthSensorWarningThreshold
[12];
char *S_sensorFailureThresholdBase
="sensorFailureThreshold.";
char *S_sensorFailureThreshold
[12];
oid oidSensorFailureThreshold
[12] [MAX_OID_LEN
];
size_t lengthSensorFailureThreshold
[12];
//SNMP Community Information
char *S_snmpCommunityNameBase
="snmpCommunityName.";
char *S_snmpCommunityName
[4];
oid oidSnmpCommunityName
[4] [MAX_OID_LEN
];
size_t lengthSnmpCommunityName
[4];
// Power Supply Details
char *S_psFirmwareVersion
="psFirmwareVersion.0";
oid oidPsFirmwareVersion
[MAX_OID_LEN
];
size_t lengthPsFirmwareVersion
;
char *S_psSerialNumber
="psSerialNumber.0";
oid oidPsSerialNumber
[MAX_OID_LEN
];
size_t lengthPsSerialNumber
;
char *S_psOperatingTime
="psOperatingTime.0";
oid oidPsOperatingTime
[MAX_OID_LEN
];
size_t lengthPsOperatingTime
;
char *S_psDirectAccess
="psDirectAccess.0";
oid oidPsDirectAccess
[MAX_OID_LEN
];
size_t lengthPsDirectAccess
;
//Fan Tray Specific OIDs
char *S_fanFirmwareVersion
="fanFirmwareVersion.0";
oid oidFanFirmwareVersion
[MAX_OID_LEN
];
size_t lengthFanFirmwareVersion
;
char *S_fanSerialNumber
="fanSerialNumber.0";
oid oidFanSerialNumber
[MAX_OID_LEN
];
size_t lengthFanSerialNumber
;
char *S_fanOperatingTime
="fanOperatingTime.0";
oid oidFanOperatingTime
[MAX_OID_LEN
];
size_t lengthFanOperatingTime
;
char *S_fanAirTemperature
="fanAirTemperature.0";
oid oidFanAirTemperature
[MAX_OID_LEN
];
size_t lengthFanAirTemperature
;
char *S_fanSwitchOffDelay
="fanSwitchOffDelay.0";
oid oidFanSwitchOffDelay
[MAX_OID_LEN
];
size_t lengthFanSwitchOffDelay
;
char *S_fanNominalSpeed
="fanNominalSpeed.0";
oid oidFanNominalSpeed
[MAX_OID_LEN
];
size_t lengthFanNominalSpeed
;
char *S_fanNumberOfFans
="fanNumberOfFans.0";
oid oidFanNumberOfFans
[MAX_OID_LEN
];
size_t lengthFanNumberOfFans
;
char *S_fanSpeedBase
="fanSpeed.";
char *S_fanSpeed
[6];
oid oidFanSpeed
[6] [MAX_OID_LEN
];
size_t lengthFanSpeed
[6];
char *winsock_startup
(void)
{
WORD wVersionRequested
;
WSADATA wsaData
;
int err
;
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
wVersionRequested
= MAKEWORD
(2, 2);
err
= WSAStartup
(wVersionRequested
, &wsaData
);
if (err
!= 0) {
/* Tell the user that we could not find a usable */
/* Winsock DLL. */
printf("WSAStartup failed with error: %d\n", err
);
return NULL
;
}
/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */
if (LOBYTE
(wsaData.
wVersion) != 2 || HIBYTE
(wsaData.
wVersion) != 2) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
printf("Could not find a usable version of Winsock.dll\n");
WSACleanup
();
return NULL
;
}
else
printf("The Winsock 2.2 dll was found okay\n");
/* The Winsock DLL is acceptable. Proceed to use it. */
/* Add network programming using Winsock here */
/* then call WSACleanup when done using the Winsock dll */
return NULL
;
};
void winsock_cleanup
(void){
WSACleanup
();
};
#define SOCK_STARTUP winsock_startup()
#define SOCK_CLEANUP winsock_cleanup()
BOOL APIENTRY DllMain
( HANDLE hModule
,
DWORD ul_reason_for_call
,
LPVOID lpReserved
)
{
return TRUE
;
}
/******************************************************************************/
/** simple syslog replacement for this example.
*/
/*
* priorities/facilities are encoded into a single 32-bit quantity, where the
* bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
* (0-big number). Both the priorities and the facilities map roughly
* one-to-one to strings in the syslogd(8) source code. This mapping is
* included in this file.
*
* priorities (these are ordered)
*/
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR 3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
size_t lengthSysStatus
;
void syslog
(int priority
,const char* format
,...
) {
va_list vaPrintf
;
va_start(vaPrintf
,format
);
vprintf(format
,vaPrintf
); putchar('\n');
va_end(vaPrintf
);
}
/******************************************************************************/
/** SNMP Initialization.
*/
int __stdcall SnmpInit
(void) {
syslog
(LOG_DEBUG
,"*** Initialise SNMP ***");
init_snmp
("CrateTest"); // I never saw this name used !?!
init_mib
(); // init MIB processing
if(!read_module
("WIENER-CRATE-MIB")) { // read specific mibs
syslog
(LOG_ERR
,"Unable to load SNMP MIB file \"%s\"","WIENER-CRATE-MIB");
return 0;
}
syslog
(LOG_DEBUG
,"*** Translate OIDs ***");
//Translate System OIDS
lengthSysMainSwitch
= MAX_OID_LEN
;
if(!get_node
(S_sysMainSwitch
,oidSysMainSwitch
,&lengthSysMainSwitch
)) {
syslog
(LOG_ERR
,"OID \"sysMainSwitch.0\"not found"); return false; }
lengthSysStatus
= MAX_OID_LEN
;
if(!get_node
(S_sysStatus
,oidSysStatus
,&lengthSysStatus
)) {
syslog
(LOG_ERR
,"OID \"sysStatus.0\"not found"); return false;}
lengthSysVmeSysReset
= MAX_OID_LEN
;
if(!get_node
(S_sysVmeSysReset
,oidSysVmeSysReset
,&lengthSysVmeSysReset
)) {
syslog
(LOG_ERR
,"OID \"SysVmeSysReset.0\"not found"); return false;}
//Translate System Channel Count Information OIDS
lengthOutputNumber
= MAX_OID_LEN
;
if(!get_node
(S_outputNumber
,oidOutputNumber
,&lengthOutputNumber
)) {
syslog
(LOG_ERR
,"OID \"OutputNumber.0\"not found"); return false; }
lengthGroupsNumber
= MAX_OID_LEN
;
if(!get_node
(S_groupsNumber
,oidGroupsNumber
,&lengthGroupsNumber
)) {
syslog
(LOG_ERR
,"OID \"groupsNumber.0\"not found"); return false;}
//Translate Channel Information OIDS
char s
[10000];
char index
[4];
int base
=0;
int indexBase
=0;
int j
=0, idx
;
// 2014/01/21: i was set to run to 1 only and base was 32 resulting in module offset of 32
// corrected go to 100 and also field size for all OID's increased to 1000
// for( int i = 0; i < 2; i++) {
for( int i
= 0; i
< 10; i
++) {
base
= 100*i
;
indexBase
= 100*i
+1;
for( j
= 0; j
< 100; j
++)
{
idx
= indexBase
+j
;
if (idx
>=999) idx
=999;
strcpy(s
, S_outputNameBase
);
sprintf(index
, "%i", idx
);
strcat(s
, index
);
// printf("%s\n", s);
lengthOutputName
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputName
[base
+j
],&lengthOutputName
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputName\"not found"); return false;}
// groups not implemented
/* strcpy(s, S_outputGroupBase);
sprintf(index, "%i", indexBase+j);
strcat(s, index);
lengthOutputGroup[base+j] = MAX_OID_LEN;
if(!get_node(s,oidOutputGroup[base+j],&lengthOutputGroup[base+j])) {
syslog(LOG_ERR,"OID \"OutputGroup\"not found"); return false;}
*/
strcpy(s
, S_outputStatusBase
);
// sprintf(index, "%i",indexBase+j);
strcat(s
, index
);
lengthOutputStatus
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputStatus
[base
+j
],&lengthOutputStatus
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputStatus.1\"not found"); return false; }
strcpy(s
, S_outputMeasurementSenseVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputMeasurementSenseVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputMeasurementSenseVoltage
[base
+j
],&lengthOutputMeasurementSenseVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputMeasurementSenseVoltage.1\"not found"); return false;}
strcpy(s
, S_outputMeasurementTerminalVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputMeasurementTerminalVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputMeasurementTerminalVoltage
[base
+j
],&lengthOutputMeasurementTerminalVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputMeasurementTerminalVoltage.1\"not found"); return false;}
strcpy(s
, S_outputMeasurementCurrentBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputMeasurementCurrent
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputMeasurementCurrent
[base
+j
],&lengthOutputMeasurementCurrent
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputMeasurementCurrent.1\"not found"); return false; }
strcpy(s
, S_outputMeasurementTemperatureBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputMeasurementTemperature
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputMeasurementTemperature
[base
+j
],&lengthOutputMeasurementTemperature
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputMeasurementTemperature\"not found"); return false; }
strcpy(s
, S_outputSwitchBase
);
// sprintf(index, "%i",indexBase+j);
strcat(s
, index
);
lengthChannelSwitch
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidChannelSwitch
[base
+j
],&lengthChannelSwitch
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"channelSwitch.1\"not found"); return false; }
/*
// groupSwitch added 05/16/2013___AR but not working!!!
strcpy(s, S_groupSwitchBase);
sprintf(index, "%i",indexBase+j);
strcat(s, index);
lengthGroupSwitch[base+j] = MAX_OID_LEN;
if(!get_node(s,oidGroupSwitch[base+j],&lengthGroupSwitch[base+j])) {
syslog(LOG_ERR,"OID \"GroupSwitch.1\"not found"); return false; }
*/ //-----------------------------------
strcpy(s
, S_outputVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputVoltage
[base
+j
],&lengthOutputVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputVoltage.1\"not found"); return false; }
strcpy(s
, S_outputCurrentBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputCurrent
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputCurrent
[base
+j
],&lengthOutputCurrent
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputCurrent\"not found"); return false; }
strcpy(s
, S_outputRiseRateBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputRiseRate
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputRiseRate
[base
+j
],&lengthOutputRiseRate
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputRiseRate.1\"not found"); return false;}
strcpy(s
, S_outputFallRateBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputFallRate
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputFallRate
[base
+j
],&lengthOutputFallRate
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputRiseRate.1\"not found"); return false; }
strcpy(s
, S_outputSupervisionBehaviorBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputSupervisionBehavior
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputSupervisionBehavior
[base
+j
],&lengthOutputSupervisionBehavior
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputSupervisionBehavior\"not found"); return false; }
strcpy(s
, S_outputSupervisionMinSenseVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputSupervisionMinSenseVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputSupervisionMinSenseVoltage
[base
+j
],&lengthOutputSupervisionMinSenseVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputSupervisionMinSenseVoltage\"not found"); return false; }
strcpy(s
, S_outputSupervisionMaxSenseVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputSupervisionMaxSenseVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputSupervisionMaxSenseVoltage
[base
+j
],&lengthOutputSupervisionMaxSenseVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputSupervisionMaxSenseVoltage\"not found"); return false; }
strcpy(s
, S_outputSupervisionMaxTerminalVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputSupervisionMaxTerminalVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputSupervisionMaxTerminalVoltage
[base
+j
],&lengthOutputSupervisionMaxTerminalVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputSupervisionMaxTerminalVoltage\"not found"); return false; }
strcpy(s
, S_outputSupervisionMaxCurrentBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputSupervisionMaxCurrent
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputSupervisionMaxCurrent
[base
+j
],&lengthOutputSupervisionMaxCurrent
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputSupervisionMaxCurrent\"not found"); return false; }
/*
strcpy(s, S_outputSupervisionMaxTemperatureBase);
sprintf(index, "%i", indexBase+j);
strcat(s, index);
lengthOutputSupervisionMaxTemperature[base+j] = MAX_OID_LEN;
if(!get_node(s,oidOutputSupervisionMaxTemperature[base+j],&lengthOutputSupervisionMaxTemperature[base+j])) {
syslog(LOG_ERR,"OID \"outputSupervisionMaxTemperature\"not found"); return false; }
*/
strcpy(s
, S_outputConfigMaxSenseVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputConfigMaxSenseVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputConfigMaxSenseVoltage
[base
+j
],&lengthOutputConfigMaxSenseVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputConfigMaxSenseVoltage\"not found"); return false; }
strcpy(s
, S_outputConfigMaxTerminalVoltageBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputConfigMaxTerminalVoltage
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputConfigMaxTerminalVoltage
[base
+j
],&lengthOutputConfigMaxTerminalVoltage
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputConfigMaxTerminalVoltage\"not found"); return false; }
strcpy(s
, S_outputConfigMaxCurrentBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputConfigMaxCurrent
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputConfigMaxCurrent
[base
+j
],&lengthOutputConfigMaxCurrent
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputConfigMaxCurrent\"not found"); return false; }
strcpy(s
, S_outputConfigMaxPowerBase
);
// sprintf(index, "%i", indexBase+j);
strcat(s
, index
);
lengthOutputConfigMaxPower
[base
+j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidOutputConfigMaxPower
[base
+j
],&lengthOutputConfigMaxPower
[base
+j
])) {
syslog
(LOG_ERR
,"OID \"outputConfigMaxPower\"not found"); return false; }
}
}
//Sensor Information
lengthSensorNumber
= MAX_OID_LEN
;
if(!get_node
(S_sensorNumber
,oidSensorNumber
,&lengthSensorNumber
)) {
syslog
(LOG_ERR
,"OID \"SensorNumber.0\"not found"); return false;}
for(j
= 0; j
< 8; j
++)
{
strcpy(s
, S_sensorTemperatureBase
);
sprintf(index
, "%i", j
+1);
strcat(s
, index
);
lengthSensorTemperature
[j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidSensorTemperature
[j
],&lengthSensorTemperature
[j
])) {
syslog
(LOG_ERR
,"OID \"sensorTemperature.0\"not found"); return false; }
strcpy(s
, S_sensorWarningThresholdBase
);
sprintf(index
, "%i", j
+1);
strcat(s
, index
);
lengthSensorWarningThreshold
[j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidSensorWarningThreshold
[j
],&lengthSensorWarningThreshold
[j
])) {
syslog
(LOG_ERR
,"OID \"WarningThreshold\"not found"); return false; }
strcpy(s
, S_sensorFailureThresholdBase
);
sprintf(index
, "%i", j
+1);
strcat(s
, index
);
lengthSensorFailureThreshold
[j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidSensorFailureThreshold
[j
],&lengthSensorFailureThreshold
[j
])) {
syslog
(LOG_ERR
,"OID \"FailureThreshold\"not found"); return false; }
}
//Translate SNMP community Name OIDs
for(j
= 0; j
< 4; j
++)
{
strcpy(s
, S_snmpCommunityNameBase
);
sprintf(index
, "%i", j
+1);
strcat(s
, index
);
lengthSnmpCommunityName
[j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidSnmpCommunityName
[j
],&lengthSnmpCommunityName
[j
])) {
syslog
(LOG_ERR
,"OID \"smpCommunityNameBase\"not found"); return false; }
}
//Translate PS Specific OIDs
/*
lengthPsFirmwareVersion = MAX_OID_LEN;
if(!get_node(S_psFirmwareVersion,oidPsFirmwareVersion,&lengthPsFirmwareVersion)) {
syslog(LOG_ERR,"OID \"psFirmwareRevision\"not found"); return false; }
*/
lengthPsSerialNumber
= MAX_OID_LEN
;
printf("\nPs Serial Number: %s\n", S_psSerialNumber
);
if(!get_node
(S_psSerialNumber
,oidPsSerialNumber
,&lengthPsSerialNumber
)) {
syslog
(LOG_ERR
,"OID \"psSerialNumber\"not found"); return false; }
lengthPsOperatingTime
= MAX_OID_LEN
;
if(!get_node
(S_psOperatingTime
,oidPsOperatingTime
,&lengthPsOperatingTime
)) {
syslog
(LOG_ERR
,"OID \"PsOperatingTime\"not found"); return false; }
lengthPsDirectAccess
= MAX_OID_LEN
;
if(!get_node
(S_psDirectAccess
,oidPsDirectAccess
,&lengthPsDirectAccess
)) {
syslog
(LOG_ERR
,"OID \"PsDirectAccess\"not found"); return false; }
/*
//Translate Fan Tray OIDs
lengthFanFirmwareVersion = MAX_OID_LEN;
if(!get_node(S_fanFirmwareVersion,oidFanFirmwareVersion,&lengthFanFirmwareVersion)) {
syslog(LOG_ERR,"OID \"FanFirmwareVersion\"not found"); return false; }
*/
lengthFanSerialNumber
= MAX_OID_LEN
;
if(!get_node
(S_fanSerialNumber
,oidFanSerialNumber
,&lengthFanSerialNumber
)) {
syslog
(LOG_ERR
,"OID \"FanSerialNumber\"not found"); return false; }
lengthFanOperatingTime
= MAX_OID_LEN
;
if(!get_node
(S_fanOperatingTime
,oidFanOperatingTime
,&lengthFanOperatingTime
)) {
syslog
(LOG_ERR
,"OID \"FanOperatingTime\"not found"); return false; }
lengthFanAirTemperature
= MAX_OID_LEN
;
if(!get_node
(S_fanAirTemperature
,oidFanAirTemperature
,&lengthFanAirTemperature
)) {
syslog
(LOG_ERR
,"OID \"fanAirTemperature.0\"not found"); return false; }
lengthFanSwitchOffDelay
= MAX_OID_LEN
;
if(!get_node
(S_fanSwitchOffDelay
,oidFanSwitchOffDelay
,&lengthFanSwitchOffDelay
)) {
syslog
(LOG_ERR
,"OID \"FanSwitchOffDelay\"not found"); return false; }
lengthFanNominalSpeed
= MAX_OID_LEN
;
if(!get_node
(S_fanNominalSpeed
,oidFanNominalSpeed
,&lengthFanNominalSpeed
)) {
syslog
(LOG_ERR
,"OID \"FanNominalSpeed\"not found"); return false; }
lengthFanNumberOfFans
= MAX_OID_LEN
;
if(!get_node
(S_fanNumberOfFans
,oidFanNumberOfFans
,&lengthFanNumberOfFans
)) {
syslog
(LOG_ERR
,"OID \"NumberOfFans\"not found"); return false; }
for(j
= 0; j
< 6; j
++)
{
strcpy(s
, S_fanSpeedBase
);
sprintf(index
, "%i", j
+1);
strcat(s
, index
);
lengthFanSpeed
[j
] = MAX_OID_LEN
;
if(!get_node
(s
,oidFanSpeed
[j
],&lengthFanSpeed
[j
])) {
syslog
(LOG_ERR
,"OID \"FanSpeed\"not found"); return false; }
}
syslog
(LOG_DEBUG
,"*** Initialise SNMP done ***");
SOCK_STARTUP
; // only in main thread
return 1;
}
/******************************************************************************/
/** SNMP Cleanup.
*/
void __stdcall SnmpCleanup
(void) {
SOCK_CLEANUP
;
}
/******************************************************************************/
/** SNMP Open Session.
*/
//typedef void* HSNMP; // SNMP handle (like FILE)
HSNMP __stdcall SnmpOpen
(const char* ipAddress
) {
HSNMP m_sessp
;
struct snmp_session session
;
snmp_sess_init
(&session
); // structure defaults
session.
version = SNMP_VERSION_2c
;
session.
peername = _strdup
(ipAddress
);
session.
community = (u_char
*)_strdup
(readCommunity
);
session.
community_len = strlen((char*)session.
community);
session.
timeout = 100000; // timeout (us)
session.
retries = 3; // retries
if(!(m_sessp
= snmp_sess_open
(&session
))) {
int liberr
, syserr
;
char *errstr
;
snmp_error
(&session
, &liberr
, &syserr
, &errstr
);
syslog
(LOG_ERR
,"Open SNMP session for host \"%s\": %s",ipAddress
,errstr
);
//free(errstr);
return 0;
}
// m_session = snmp_sess_session(m_sessp); // get the session pointer
syslog
(LOG_INFO
,"SNMP session for host \"%s\" opened",ipAddress
);
return m_sessp
;
}
/******************************************************************************/
/** SNMP Close Session.
*/
void __stdcall SnmpClose
(HSNMP m_sessp
) {
if(!m_sessp
) return;
if(!snmp_sess_close
(m_sessp
)) {
syslog
(LOG_ERR
,"Close SNMP session: ERROR");
}
else syslog
(LOG_INFO
,"SNMP session closed");
}
//System Information Functions
/******************************************************************************/
/** Get on/off status of crate
*/
int __stdcall getMainSwitch
(HSNMP m_sessp
) {
int value
= snmpGetInt
(m_sessp
, oidSysMainSwitch
, lengthSysMainSwitch
);
return value
;
}
/******************************************************************************/
/** Write on/off status
*/
int __stdcall setMainSwitch
(HSNMP m_sessp
,int value
) {
value
= snmpSetInt
(m_sessp
, oidSysMainSwitch
, lengthSysMainSwitch
, value
);
return value
;
}
/******************************************************************************/
/** Get Main Status
*/
int __stdcall getMainStatus
(HSNMP m_sessp
){
int value
= snmpGetInt
(m_sessp
, oidSysStatus
, lengthSysStatus
);
return value
;
}
/******************************************************************************/
/** Get VmeReset Status
*/
int __stdcall getVmeReset
(HSNMP m_sessp
){
int value
= snmpGetInt
(m_sessp
, oidSysVmeSysReset
, lengthSysVmeSysReset
);
return value
;
}
/******************************************************************************/
/** Initiate VME SysReset
*/
int __stdcall setVmeReset
(HSNMP m_sessp
){
int value
= snmpSetInt
(m_sessp
, oidSysVmeSysReset
, lengthSysVmeSysReset
, 1);
return value
;
}
//System Count Functions
/******************************************************************************/
/** Get the number of channels from power supply
*/
int __stdcall getOutputNumber
(HSNMP m_sessp
){
int value
= snmpGetInt
(m_sessp
, oidOutputNumber
, lengthOutputNumber
);
return value
;
}
/******************************************************************************/
/** Get the number of channels from power supply
*/
int __stdcall getOutputGroups
(HSNMP m_sessp
){
int value
= snmpGetInt
(m_sessp
, oidGroupsNumber
, lengthGroupsNumber
);
return value
;
}
//Output Channel Information
/******************************************************************************/
/** I Don't know yet how to set this up
*/
// std::string __stdcall getOutputName(HSNMP m_sessp,int channel);
int __stdcall getOutputGroup
(HSNMP m_sessp
,int channel
){
int value
= snmpGetInt
(m_sessp
, oidOutputGroup
[channel
], lengthOutputGroup
[channel
]);
return value
; }
int __stdcall getChannelStatus
(HSNMP m_sessp
, int channel
){
int value
= snmpGetInt
(m_sessp
, oidOutputStatus
[channel
], lengthOutputStatus
[channel
]);
return value
;
}
double __stdcall getOutputSenseMeasurement
(HSNMP m_sessp
, int channel
){
double value
= snmpGetDouble
(m_sessp
, oidOutputMeasurementSenseVoltage
[channel
],
lengthOutputMeasurementSenseVoltage
[channel
]);
return value
; }
double __stdcall getOutputTerminalMeasurement
(HSNMP m_sessp
, int channel
){
double value
= snmpGetDouble
(m_sessp
, oidOutputMeasurementTerminalVoltage
[channel
],
lengthOutputMeasurementTerminalVoltage
[channel
]);
return value
; }
double __stdcall getCurrentMeasurement
(HSNMP m_sessp
, int channel
){
double value
= snmpGetDouble
(m_sessp
, oidOutputMeasurementCurrent
[channel
],
lengthOutputMeasurementCurrent
[channel
]);
return value
; }
int __stdcall getTemperatureMeasurement
(HSNMP m_sessp
, int channel
){
int value
= snmpGetInt
(m_sessp
, oidOutputMeasurementTemperature
[channel
],
lengthOutputMeasurementTemperature
[channel
]);
return value
; }
int __stdcall setChannelSwitch
(HSNMP m_sessp
, int channel
,int value
) {
value
= snmpSetInt
(m_sessp
, oidChannelSwitch
[channel
],
lengthChannelSwitch
[channel
], value
);
return value
; }
int __stdcall getChannelSwitch
(HSNMP m_sessmp
, int channel
){
int value
= snmpGetInt
(m_sessmp
, oidChannelSwitch
[channel
],
lengthChannelSwitch
[channel
]);
return value
; }
// groupSwitch added 05/16/2013___AR
int __stdcall setGroupSwitch
(HSNMP m_sessp
, int group
,int value
) {
value
= snmpSetInt
(m_sessp
, oidGroupSwitch
[group
],
lengthGroupSwitch
[group
], value
);
return value
; }
int __stdcall getGroupSwitch
(HSNMP m_sessmp
, int group
){
int value
= snmpGetInt
(m_sessmp
, oidGroupSwitch
[group
],
lengthGroupSwitch
[group
]);
return value
; }
//_______________________________________
double __stdcall getOutputVoltage
(HSNMP m_sessp
, int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputVoltage
[channel
],
lengthOutputVoltage
[channel
] );
return value
; }
double __stdcall setOutputVoltage
(HSNMP m_sessp
, int channel
, double value
) {
value
= snmpSetDouble
(m_sessp
, oidOutputVoltage
[channel
],
lengthOutputVoltage
[channel
], value
);
return value
; }
double __stdcall getOutputCurrent
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputCurrent
[channel
],
lengthOutputCurrent
[channel
]);
return value
; }
double __stdcall setOutputCurrent
(HSNMP m_sessp
,int channel
,double value
){
value
= snmpSetDouble
(m_sessp
, oidOutputCurrent
[channel
],
lengthOutputCurrent
[channel
], value
);
return value
; }
double __stdcall getOutputRiseRate
(HSNMP m_sessp
, int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputRiseRate
[channel
],
lengthOutputRiseRate
[channel
] );
return value
; }
double __stdcall setOutputRiseRate
(HSNMP m_sessp
,int channel
,double value
) {
value
= snmpSetDouble
(m_sessp
, oidOutputRiseRate
[channel
],
lengthOutputRiseRate
[channel
], value
);
return value
; }
double __stdcall getOutputFallRate
(HSNMP m_sessp
, int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputFallRate
[channel
],
lengthOutputFallRate
[channel
] );
return value
; }
double __stdcall setOutputFallRate
(HSNMP m_sessp
,int channel
,double value
) {
value
= snmpSetDouble
(m_sessp
, oidOutputFallRate
[channel
],
lengthOutputFallRate
[channel
], value
);
return value
; }
int __stdcall getOutputSupervisionBehavior
(HSNMP m_sessp
,int channel
) {
int value
= snmpGetInt
(m_sessp
, oidOutputSupervisionBehavior
[channel
],
lengthOutputSupervisionBehavior
[channel
] );
return value
; }
int __stdcall setOutputSupervisionBehavior
(HSNMP m_sessp
,int channel
,int value
) {
value
= snmpSetInt
(m_sessp
, oidOutputSupervisionBehavior
[channel
],
lengthOutputSupervisionBehavior
[channel
], value
);
return value
; }
double __stdcall getOutputSupervisionMinSenseVoltage
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputSupervisionMinSenseVoltage
[channel
],
lengthOutputSupervisionMinSenseVoltage
[channel
] );
return value
; }
double __stdcall setOutputSupervisionMinSenseVoltage
(HSNMP m_sessp
,int channel
,double value
) {
value
= snmpSetDouble
(m_sessp
, oidOutputSupervisionMinSenseVoltage
[channel
],
lengthOutputSupervisionMinSenseVoltage
[channel
], value
);
return value
; }
double __stdcall getOutputSupervisionMaxSenseVoltage
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputSupervisionMaxSenseVoltage
[channel
],
lengthOutputSupervisionMaxSenseVoltage
[channel
] );
return value
; }
double __stdcall setOutputSupervisionMaxSenseVoltage
(HSNMP m_sessp
,int channel
,double value
) {
value
= snmpSetDouble
(m_sessp
, oidOutputSupervisionMaxSenseVoltage
[channel
],
lengthOutputSupervisionMaxSenseVoltage
[channel
], value
);
return value
; }
double __stdcall getOutputSupervisionMaxTerminalVoltage
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputSupervisionMaxTerminalVoltage
[channel
],
lengthOutputSupervisionMaxTerminalVoltage
[channel
] );
return value
; }
double __stdcall setOutputSupervisionMaxTerminalVoltage
(HSNMP m_sessp
,int channel
,double value
) {
value
= snmpSetDouble
(m_sessp
, oidOutputSupervisionMaxTerminalVoltage
[channel
],
lengthOutputSupervisionMaxTerminalVoltage
[channel
], value
);
return value
; }
double __stdcall getOutputSupervisionMaxCurrent
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputSupervisionMaxCurrent
[channel
],
lengthOutputSupervisionMaxCurrent
[channel
] );
return value
; }
double __stdcall setOutputSupervisionMaxCurrent
(HSNMP m_sessp
,int channel
,double value
){
value
= snmpSetDouble
(m_sessp
, oidOutputSupervisionMaxCurrent
[channel
],
lengthOutputSupervisionMaxCurrent
[channel
], value
);
return value
; }
int __stdcall getOutputSupervisionMaxTemperature
(HSNMP m_sessp
,int channel
) {
int value
= snmpGetInt
(m_sessp
, oidOutputSupervisionMaxTemperature
[channel
],
lengthOutputSupervisionMaxTemperature
[channel
] );
return value
; }
double __stdcall getOutputConfigMaxSenseVoltage
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetDouble
(m_sessp
, oidOutputConfigMaxSenseVoltage
[channel
],
lengthOutputConfigMaxSenseVoltage
[channel
] );
return value
; }
double __stdcall getOutputConfigMaxTerminalVoltage
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetInt
(m_sessp
, oidOutputConfigMaxTerminalVoltage
[channel
],
lengthOutputConfigMaxTerminalVoltage
[channel
] );
return value
; }
double __stdcall getOutputConfigMaxCurrent
(HSNMP m_sessp
,int channel
) {
double value
= snmpGetInt
(m_sessp
, oidOutputConfigMaxCurrent
[channel
],
lengthOutputConfigMaxCurrent
[channel
] );
return value
; }
double __stdcall getOutputConfigMaxPower
(HSNMP m_sessp
,int channel
){
double value
= snmpGetInt
(m_sessp
, oidOutputConfigMaxPower
[channel
],
lengthOutputConfigMaxPower
[channel
] );
return value
; }
//Sensor Information functions
int __stdcall getSensorNumber
(HSNMP m_sessp
) {
double value
= snmpGetInt
(m_sessp
, oidSensorNumber
,
lengthSensorNumber
);
return (int)value
; }
int __stdcall getSensorTemp
(HSNMP m_sessp
, int sensor
) {
double value
= snmpGetInt
(m_sessp
, oidSensorTemperature
[sensor
],
lengthSensorTemperature
[sensor
]);
return (int)value
; }
int __stdcall getSensorWarningTemperature
(HSNMP m_sessp
,int sensor
) {
double value
= snmpGetInt
(m_sessp
, oidSensorWarningThreshold
[sensor
],
lengthSensorWarningThreshold
[sensor
]);
return (int)value
; }
int __stdcall setSensorWarningTemperature
(HSNMP m_sessp
,int sensor
,int value
){
value
= snmpSetInt
(m_sessp
, oidSensorWarningThreshold
[sensor
],
lengthSensorWarningThreshold
[sensor
], value
);
return (int)value
; }
int __stdcall getSensorFailureTemperature
(HSNMP m_sessp
,int sensor
) {
double value
= snmpGetInt
(m_sessp
, oidSensorFailureThreshold
[sensor
],
lengthSensorFailureThreshold
[sensor
]);
return (int)value
; }
int __stdcall setSensorFailureTemperature
(HSNMP m_sessp
,int sensor
,int value
){
value
= snmpSetInt
(m_sessp
, oidSensorFailureThreshold
[sensor
],
lengthSensorFailureThreshold
[sensor
], value
);
return (int)value
; }
//Power Supply specific Functions.
int __stdcall getPsOperatingTime
(HSNMP m_sessp
) {
double value
= snmpGetInt
(m_sessp
, oidPsOperatingTime
,
lengthPsOperatingTime
);
return (int)value
; }
//Fan Tray Functions
//std::string __stdcall getFanFirmwareVersion(HSNMP m_sessp);
//std::string __stdcall getFanSerialNumber(HSNMP m_sessp);
int __stdcall getFanOperatingTime
(HSNMP m_sessp
) {
double value
= snmpGetInt
(m_sessp
, oidFanOperatingTime
,
lengthFanOperatingTime
);
return (int)value
; }
int __stdcall getFanAirTemperature
(HSNMP m_sessp
) {
double value
= snmpGetInt
(m_sessp
, oidFanAirTemperature
,
lengthFanAirTemperature
);
return (int)value
; }
int __stdcall getFanSwitchOffDelay
(HSNMP m_sessp
) {
double value
= snmpGetInt
(m_sessp
, oidFanSwitchOffDelay
,
lengthFanSwitchOffDelay
);
return (int)value
; }
int __stdcall setFanSwitchOffDelay
(HSNMP m_sessp
, int value
) {
value
= snmpSetInt
(m_sessp
, oidFanSwitchOffDelay
,
lengthFanSwitchOffDelay
, value
);
return (int)value
; }
int __stdcall getFanNominalSpeed
(HSNMP m_sessp
) {
double value
= snmpGetInt
(m_sessp
, oidFanNominalSpeed
,
lengthFanNominalSpeed
);
return (int)value
; }
int __stdcall setFanNominalSpeed
(HSNMP m_sessp
, int value
){
value
= snmpSetInt
(m_sessp
, oidFanNominalSpeed
,
lengthFanNominalSpeed
, value
);
return (int)value
; }
int __stdcall getFanNumberOfFans
(HSNMP m_sessp
){
double value
= snmpGetInt
(m_sessp
, oidFanNumberOfFans
,
lengthFanNumberOfFans
);
return (int)value
; }
int __stdcall getFanSpeed
(HSNMP m_sessp
, int fan
) {
double value
= snmpGetInt
(m_sessp
, oidFanSpeed
[fan
],
lengthFanSpeed
[fan
]);
return (int)value
; }
char * __stdcall getOutputName
(HSNMP m_sessp
, int channel
) {
return snmpGetString
(m_sessp
, oidOutputName
[channel
],
lengthOutputName
[channel
]);
}
//The rest of the functions are utility functions that actually do the SNMP calls
int __stdcall snmpGetInt
(HSNMP m_sessp
, const oid
* parameter
, size_t length
) {
int value
=0;
struct snmp_pdu
* pdu
= snmp_pdu_create
(SNMP_MSG_GET
); // prepare get-request pdu
// for(each GET request to one crate) {
snmp_add_null_var
(pdu
,parameter
,length
); // generate request data
// } // endfor
struct snmp_pdu
* response
;
int status
= snmp_sess_synch_response
(m_sessp
,pdu
,&response
);
/*
* Process the response.
*/
if (status
== STAT_SUCCESS
&& response
->errstat
== SNMP_ERR_NOERROR
) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list
*vars
;
/* manipuate the information ourselves */
for(vars
= response
->variables
; vars
; vars
= vars
->next_variable
) {
if (vars
->type
== ASN_OPAQUE_FLOAT
) { // 0x78
value
= *vars
->val.
floatVal;
}
else if (vars
->type
== ASN_OPAQUE_DOUBLE
) { // 0x79
value
= (int) *vars
->val.
doubleVal;
}
else if(vars
->type
== ASN_INTEGER
) { // 0x02
value
= *vars
->val.
integer;
}
/*
else if(vars->type==ASN_OCTET_STR) {
value=(char *)malloc(1+vars->val_len);
memcpy(value,vars->val.string,vars->val_len);
value[vars->val_len]='\0';
}
*/
else {
value
= *vars
->val.
integer;
// fprintf(stderr, "Wrong type 0x%x len=%d value=0x%x\n", vars->type, vars->val_len, *vars->val.integer);
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status
== STAT_SUCCESS
)
fprintf(stderr
, "Error in packet\nReason: %s\n",
snmp_errstring
(response
->errstat
));
else
snmp_sess_perror
("snmpget",snmp_sess_session
(m_sessp
));
return 0;
}
snmp_free_pdu
(response
);
return (int) value
;
}
int __stdcall snmpSetInt
(HSNMP m_sessp
, const oid
* parameter
, size_t length
, int value
) {
struct snmp_pdu
* pdu
= snmp_pdu_create
(SNMP_MSG_SET
); // prepare set-request pdu
pdu
->community
= (u_char
*)_strdup
(writeCommunity
);
pdu
->community_len
= strlen(writeCommunity
);
// for(each SET request to one crate) {
int v
= (int) value
;
snmp_pdu_add_variable
(pdu
,parameter
,length
,ASN_INTEGER
,(u_char
*)&v
,sizeof(v
));
// } // endfor
value
=v
;
struct snmp_pdu
* response
;
int status
= snmp_sess_synch_response
(m_sessp
,pdu
,&response
);
/*
* Process the response.
*/
if (status
== STAT_SUCCESS
&& response
->errstat
== SNMP_ERR_NOERROR
) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list
*vars
;
// debug print
//for(vars = response->variables; vars; vars = vars->next_variable)
// print_variable(vars->name, vars->name_length, vars);
/* manipuate the information ourselves */
for(vars
= response
->variables
; vars
; vars
= vars
->next_variable
) {
if (vars
->type
== ASN_OPAQUE_FLOAT
) { // 0x78
value
= (int)*vars
->val.
floatVal;
}
else if (vars
->type
== ASN_OPAQUE_DOUBLE
) { // 0x79
value
= (int)*vars
->val.
doubleVal;
}
else if(vars
->type
== ASN_INTEGER
) { // 0x02
value
= *vars
->val.
integer;
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status
== STAT_SUCCESS
)
fprintf(stderr
, "Error in packet\nReason: %s\n",
snmp_errstring
(response
->errstat
));
else
snmp_sess_perror
("snmpget",snmp_sess_session
(m_sessp
));
return 0;
}
snmp_free_pdu
(response
);
return (int) value
;
}
double __stdcall snmpGetDouble
(HSNMP m_sessp
, const oid
* parameter
, size_t length
) {
double value
=0;
struct snmp_pdu
* pdu
= snmp_pdu_create
(SNMP_MSG_GET
); // prepare get-request pdu
// for(each GET request to one crate) {
snmp_add_null_var
(pdu
,parameter
,length
); // generate request data
// } // endfor
struct snmp_pdu
* response
;
int status
= snmp_sess_synch_response
(m_sessp
,pdu
,&response
);
/*
* Process the response.
*/
if (status
== STAT_SUCCESS
&& response
->errstat
== SNMP_ERR_NOERROR
) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list
*vars
;
/* manipuate the information ourselves */
for(vars
= response
->variables
; vars
; vars
= vars
->next_variable
) {
if (vars
->type
== ASN_OPAQUE_FLOAT
) { // 0x78
value
= *vars
->val.
floatVal;
}
else if (vars
->type
== ASN_OPAQUE_DOUBLE
) { // 0x79
value
= *vars
->val.
doubleVal;
}
else if(vars
->type
== ASN_INTEGER
) { // 0x02
value
= (double)*vars
->val.
integer;
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status
== STAT_SUCCESS
)
fprintf(stderr
, "Error in packet\nReason: %s\n",
snmp_errstring
(response
->errstat
));
else
snmp_sess_perror
("snmpget",snmp_sess_session
(m_sessp
));
return 0;
}
snmp_free_pdu
(response
);
return value
;
}
double __stdcall snmpSetDouble
(HSNMP m_sessp
, const oid
* parameter
, size_t length
, double value
) {
struct snmp_pdu
* pdu
= snmp_pdu_create
(SNMP_MSG_SET
); // prepare set-request pdu
pdu
->community
= (u_char
*)_strdup
(writeCommunity
);
pdu
->community_len
= strlen(writeCommunity
);
// for(each SET request to one crate) {
float v
= (float) value
;
snmp_pdu_add_variable
(pdu
,parameter
,length
,ASN_OPAQUE_FLOAT
,(u_char
*)&v
,sizeof(v
));
// } // endfor
value
=v
;
struct snmp_pdu
* response
;
int status
= snmp_sess_synch_response
(m_sessp
,pdu
,&response
);
/*
* Process the response.
*/
if (status
== STAT_SUCCESS
&& response
->errstat
== SNMP_ERR_NOERROR
) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list
*vars
;
// debug print
//for(vars = response->variables; vars; vars = vars->next_variable)
// print_variable(vars->name, vars->name_length, vars);
/* manipuate the information ourselves */
for(vars
= response
->variables
; vars
; vars
= vars
->next_variable
) {
if (vars
->type
== ASN_OPAQUE_FLOAT
) { // 0x78
value
= *vars
->val.
floatVal;
}
else if (vars
->type
== ASN_OPAQUE_DOUBLE
) { // 0x79
value
= *vars
->val.
doubleVal;
}
else if(vars
->type
== ASN_INTEGER
) { // 0x02
value
= (double)*vars
->val.
integer;
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status
== STAT_SUCCESS
)
fprintf(stderr
, "Error in packet\nReason: %s\n",
snmp_errstring
(response
->errstat
));
else
snmp_sess_perror
("snmpget",snmp_sess_session
(m_sessp
));
return 0;
}
snmp_free_pdu
(response
);
return value
;
}
char * __stdcall snmpGetString
(HSNMP m_sessp
, const oid
* parameter
, size_t length
) {
char *value
=NULL
;
struct snmp_pdu
* pdu
= snmp_pdu_create
(SNMP_MSG_GET
); // prepare get-request pdu
// for(each GET request to one crate) {
snmp_add_null_var
(pdu
,parameter
,length
); // generate request data
// } // endfor
struct snmp_pdu
* response
;
int status
= snmp_sess_synch_response
(m_sessp
,pdu
,&response
);
/*
* Process the response.
*/
if (status
== STAT_SUCCESS
&& response
->errstat
== SNMP_ERR_NOERROR
) {
/*
* SUCCESS: Print the result variables
*/
struct variable_list
*vars
;
/* manipuate the information ourselves */
for(vars
= response
->variables
; vars
; vars
= vars
->next_variable
) {
//printf("type 0x%x l=%d\n", vars->type, vars->val_len );
if(vars
->type
==ASN_OCTET_STR
) {
value
=(char *)malloc(1+vars
->val_len
);
memcpy(value
,vars
->val.
string,vars
->val_len
);
value
[vars
->val_len
]='\0';
}
else if (vars
->type
== ASN_OPAQUE_FLOAT
) { // 0x78
value
=(char *)malloc(10);
sprintf(value
,"%9f",vars
->val.
floatVal);
}
else if (vars
->type
== ASN_OPAQUE_DOUBLE
) { // 0x79
value
=(char *)malloc(10);
sprintf(value
,"%9f",vars
->val.
doubleVal);
}
else if(vars
->type
== ASN_INTEGER
) { // 0x02
value
=(char *)malloc(10);
sprintf(value
,"%9d",vars
->val.
integer);
}
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status
== STAT_SUCCESS
)
fprintf(stderr
, "Error in packet\nReason: %s\n",
snmp_errstring
(response
->errstat
));
else
snmp_sess_perror
("snmpget",snmp_sess_session
(m_sessp
));
return 0;
}
snmp_free_pdu
(response
);
return value
;
}