Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. #include <userint.h>
  2. #include "mpod_uir.h"
  3.  
  4. /** WIENER SNMP basic SNMP library to Demonstrate C-Access to WIENER-Crates via SNMP
  5. // modified for LabView imprt 04/23/06, Andreas Ruben
  6. //
  7. // The path to the Net-SNMP include files (default /usr/include) must be added to the
  8. // include file search path!
  9. // The following libraries must be included:
  10. // netsnmp.lib ws2_32.lib
  11. // The path to the Net-SNMP library must be added to the linker files.
  12. // /usr/lib
  13. // path for the WIENER MIB file (mibdirs) c:/usr/share/snmp/mibs
  14. */
  15.  
  16.  
  17. #include <windows.h>
  18.  
  19. #define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers  
  20.  
  21.  
  22. #include <winsock2.h>
  23. #include <ws2tcpip.h>    
  24.  
  25. #include "netsnmplib.h"  
  26.  
  27. #include "WIENER_SNMP.h"
  28.  
  29.  
  30. #include "toolbox.h"
  31. #define _strdup StrDup
  32.  
  33.  
  34.  
  35. #define WIN32_LEAN_AND_MEAN
  36.  
  37.  
  38.  
  39. #include <stdio.h>
  40.  
  41.  
  42. const char* readCommunity = "public";       ///< community name for read operations
  43. const char* writeCommunity = "guru";        ///< community name for write operation
  44.  
  45.  
  46.  
  47. // System Information OIDS
  48. char *S_sysMainSwitch = "sysMainSwitch.0";
  49. oid oidSysMainSwitch [MAX_OID_LEN];
  50. size_t lengthSysMainSwitch;
  51.  
  52. char *S_sysStatus = "sysStatus.0";
  53. oid oidSysStatus [MAX_OID_LEN];
  54. size_t lengthSysStatus;
  55.  
  56. char *S_sysVmeSysReset = "sysVmeSysReset.0";
  57. oid oidSysVmeSysReset [MAX_OID_LEN];
  58. size_t lengthSysVmeSysReset;
  59.  
  60.  
  61. //Output Count Information
  62. char *S_outputNumber = "outputNumber.0";
  63. oid oidOutputNumber [MAX_OID_LEN];
  64. size_t lengthOutputNumber;
  65.  
  66. char *S_groupsNumber = "groupsNumber.0";
  67. oid oidGroupsNumber [MAX_OID_LEN];
  68. size_t lengthGroupsNumber;
  69.  
  70.  
  71. //Ouput Channel information
  72. char *S_outputNameBase = "outputName.";
  73. char *S_outputName[1100];
  74. oid oidOutputName[1100] [MAX_OID_LEN];
  75. size_t lengthOutputName[1100];
  76.  
  77. char *S_outputGroupBase = "outputGroup.";
  78. char *S_outputGroup[1100];
  79. oid oidOutputGroup[1100] [MAX_OID_LEN];
  80. size_t lengthOutputGroup[1100];
  81.  
  82. char *S_outputStatusBase = "outputStatus.";
  83. char *S_outputStatus[1100];
  84. oid oidOutputStatus[1100] [MAX_OID_LEN];
  85. size_t lengthOutputStatus[1100];
  86.  
  87. char *S_outputMeasurementSenseVoltageBase = "outputMeasurementSenseVoltage.";
  88. char *S_outputMeasurementSenseVoltage[1100];
  89. oid oidOutputMeasurementSenseVoltage[1100] [MAX_OID_LEN];
  90. size_t lengthOutputMeasurementSenseVoltage[1100];
  91.  
  92. char *S_outputMeasurementTerminalVoltageBase = "outputMeasurementTerminalVoltage.";
  93. char *S_outputMeasurementTerminalVoltage[1100];
  94. oid oidOutputMeasurementTerminalVoltage[1100] [MAX_OID_LEN];
  95. size_t lengthOutputMeasurementTerminalVoltage[1100];
  96.  
  97. char *S_outputMeasurementCurrentBase ="outputMeasurementCurrent.";
  98. char *S_outputMeasurementCurrent[1100];
  99. oid oidOutputMeasurementCurrent[1100] [MAX_OID_LEN];
  100. size_t lengthOutputMeasurementCurrent[1100];
  101.  
  102. char *S_outputMeasurementTemperatureBase ="outputMeasurementTemperature.";
  103. char *S_outputMeasurementTemperature[1100];
  104. oid oidOutputMeasurementTemperature[1100] [MAX_OID_LEN];
  105. size_t lengthOutputMeasurementTemperature[1100];
  106.  
  107. char *S_outputSwitchBase = "outputSwitch.";
  108. char *S_outputSwitch[1100];
  109. oid oidChannelSwitch[1100] [MAX_OID_LEN];
  110. size_t lengthChannelSwitch[1100];
  111.  
  112. char *S_groupSwitchBase = "GroupSwitch.";
  113. char *S_groupSwitch[1100];
  114. oid oidGroupSwitch[1100] [MAX_OID_LEN];
  115. size_t lengthGroupSwitch[1100];
  116.  
  117. char *S_outputVoltageBase ="outputVoltage.";
  118. char *S_outputVoltage[1100];
  119. oid oidOutputVoltage[1100] [MAX_OID_LEN];
  120. size_t lengthOutputVoltage[1100];
  121.  
  122. char *S_outputCurrentBase = "outputCurrent.";
  123. char *S_outputCurrent[1100];
  124. oid oidOutputCurrent[1100] [MAX_OID_LEN];
  125. size_t lengthOutputCurrent[1100];
  126.  
  127. char *S_outputRiseRateBase ="outputVoltageRiseRate.";
  128. char *S_outputRiseRate[1100];
  129. oid oidOutputRiseRate[1100] [MAX_OID_LEN];
  130. size_t lengthOutputRiseRate[1100];
  131.  
  132. char *S_outputFallRateBase ="outputVoltageFallRate.";
  133. char *S_outputFallRate[1100];
  134. oid oidOutputFallRate[1100] [MAX_OID_LEN];
  135. size_t lengthOutputFallRate[1100];
  136.  
  137. char *S_outputSupervisionBehaviorBase ="outputSupervisionBehavior.";
  138. char *S_outputSupervisionBehavior[1100];
  139. oid oidOutputSupervisionBehavior[1100] [MAX_OID_LEN];
  140. size_t lengthOutputSupervisionBehavior[1100];
  141.  
  142. char *S_outputSupervisionMinSenseVoltageBase ="outputSupervisionMinSenseVoltage.";
  143. char *S_outputSupervisionMinSenseVoltage[1100];
  144. oid oidOutputSupervisionMinSenseVoltage[1100] [MAX_OID_LEN];
  145. size_t lengthOutputSupervisionMinSenseVoltage[1100];
  146.  
  147. char *S_outputSupervisionMaxSenseVoltageBase ="outputSupervisionMaxSenseVoltage.";
  148. char *S_outputSupervisionMaxSenseVoltage[1100];
  149. oid oidOutputSupervisionMaxSenseVoltage[1100] [MAX_OID_LEN];
  150. size_t lengthOutputSupervisionMaxSenseVoltage[1100];
  151.  
  152. char *S_outputSupervisionMaxTerminalVoltageBase ="outputSupervisionMaxTerminalVoltage.";
  153. char *S_outputSupervisionMaxTerminalVoltage[1100];
  154. oid oidOutputSupervisionMaxTerminalVoltage[1100] [MAX_OID_LEN];
  155. size_t lengthOutputSupervisionMaxTerminalVoltage[1100];
  156.  
  157. char *S_outputSupervisionMaxCurrentBase ="outputSupervisionMaxCurrent.";
  158. char *S_outputSupervisionMaxCurrent[1100];
  159. oid oidOutputSupervisionMaxCurrent[1100] [MAX_OID_LEN];
  160. size_t lengthOutputSupervisionMaxCurrent[1100];
  161.  
  162. char *S_outputSupervisionMaxTemperatureBase ="outputSupervisionMaxTemperature.";
  163. char *S_outputSupervisionMaxTemperature[1100];
  164. oid oidOutputSupervisionMaxTemperature[1100] [MAX_OID_LEN];
  165. size_t lengthOutputSupervisionMaxTemperature[1100];
  166.  
  167. char *S_outputConfigMaxSenseVoltageBase ="outputConfigMaxSenseVoltage.";
  168. char *S_outputConfigMaxSenseVoltage[1100];
  169. oid oidOutputConfigMaxSenseVoltage[1100] [MAX_OID_LEN];
  170. size_t lengthOutputConfigMaxSenseVoltage[1100];
  171.  
  172. char *S_outputConfigMaxTerminalVoltageBase ="outputConfigMaxTerminalVoltage.";
  173. char *S_outputConfigMaxTerminalVoltage[1100];
  174. oid oidOutputConfigMaxTerminalVoltage[1100] [MAX_OID_LEN];
  175. size_t lengthOutputConfigMaxTerminalVoltage[1100];
  176.  
  177. char *S_outputConfigMaxCurrentBase ="outputConfigMaxCurrent.";
  178. char *S_outputConfigMaxCurrent[1100];
  179. oid oidOutputConfigMaxCurrent[1100] [MAX_OID_LEN];
  180. size_t lengthOutputConfigMaxCurrent[1100];
  181.  
  182. char *S_outputConfigMaxPowerBase ="outputSupervisionMaxPower.";
  183. char *S_outputConfigMaxPower[1100];
  184. oid oidOutputConfigMaxPower[1100] [MAX_OID_LEN];
  185. size_t lengthOutputConfigMaxPower[1100];
  186.  
  187.  
  188.  
  189. //Sensor Information
  190. char *S_sensorNumber ="sensorNumber.0";
  191. oid oidSensorNumber [MAX_OID_LEN];
  192. size_t lengthSensorNumber;
  193.  
  194. char *S_sensorTemperatureBase ="sensorTemperature.";
  195. char *S_sensorTemperature[12];
  196. oid oidSensorTemperature[12] [MAX_OID_LEN];
  197. size_t lengthSensorTemperature[12];
  198.  
  199. char *S_sensorWarningThresholdBase ="sensorWarningThreshold.";
  200. char *S_sensorWarningThreshold[12];
  201. oid oidSensorWarningThreshold[12] [MAX_OID_LEN];
  202. size_t lengthSensorWarningThreshold[12];
  203.  
  204. char *S_sensorFailureThresholdBase ="sensorFailureThreshold.";
  205. char *S_sensorFailureThreshold[12];
  206. oid oidSensorFailureThreshold[12] [MAX_OID_LEN];
  207. size_t lengthSensorFailureThreshold[12];
  208.  
  209.  
  210.  
  211. //SNMP Community Information
  212. char *S_snmpCommunityNameBase ="snmpCommunityName.";
  213. char *S_snmpCommunityName[4];
  214. oid oidSnmpCommunityName[4] [MAX_OID_LEN];
  215. size_t lengthSnmpCommunityName[4];
  216.  
  217.  
  218.  
  219. // Power Supply Details
  220. char *S_psFirmwareVersion ="psFirmwareVersion.0";
  221. oid oidPsFirmwareVersion[MAX_OID_LEN];
  222. size_t lengthPsFirmwareVersion;
  223.  
  224. char *S_psSerialNumber ="psSerialNumber.0";
  225. oid oidPsSerialNumber[MAX_OID_LEN];
  226. size_t lengthPsSerialNumber;
  227.  
  228. char *S_psOperatingTime ="psOperatingTime.0";
  229. oid oidPsOperatingTime[MAX_OID_LEN];
  230. size_t lengthPsOperatingTime;
  231.  
  232. char *S_psDirectAccess ="psDirectAccess.0";
  233. oid oidPsDirectAccess[MAX_OID_LEN];
  234. size_t lengthPsDirectAccess;
  235.  
  236.  
  237. //Fan Tray Specific OIDs
  238. char *S_fanFirmwareVersion ="fanFirmwareVersion.0";
  239. oid oidFanFirmwareVersion[MAX_OID_LEN];
  240. size_t lengthFanFirmwareVersion;
  241.  
  242. char *S_fanSerialNumber ="fanSerialNumber.0";
  243. oid oidFanSerialNumber[MAX_OID_LEN];
  244. size_t lengthFanSerialNumber;
  245.  
  246. char *S_fanOperatingTime ="fanOperatingTime.0";
  247. oid oidFanOperatingTime[MAX_OID_LEN];
  248. size_t lengthFanOperatingTime;
  249.  
  250. char *S_fanAirTemperature ="fanAirTemperature.0";
  251. oid oidFanAirTemperature[MAX_OID_LEN];
  252. size_t lengthFanAirTemperature;
  253.  
  254. char *S_fanSwitchOffDelay ="fanSwitchOffDelay.0";
  255. oid oidFanSwitchOffDelay[MAX_OID_LEN];
  256. size_t lengthFanSwitchOffDelay;
  257.  
  258. char *S_fanNominalSpeed ="fanNominalSpeed.0";
  259. oid oidFanNominalSpeed[MAX_OID_LEN];
  260. size_t lengthFanNominalSpeed;
  261.  
  262. char *S_fanNumberOfFans ="fanNumberOfFans.0";
  263. oid oidFanNumberOfFans[MAX_OID_LEN];
  264. size_t lengthFanNumberOfFans;
  265.  
  266. char *S_fanSpeedBase ="fanSpeed.";
  267. char *S_fanSpeed[6];
  268. oid oidFanSpeed[6] [MAX_OID_LEN];
  269. size_t lengthFanSpeed[6];
  270.  
  271.  
  272.  
  273. char *winsock_startup(void)
  274. {
  275.  
  276.     WORD wVersionRequested;
  277.     WSADATA wsaData;
  278.     int err;
  279.  
  280. /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
  281.     wVersionRequested = MAKEWORD(2, 2);
  282.  
  283.     err = WSAStartup(wVersionRequested, &wsaData);
  284.     if (err != 0) {
  285.         /* Tell the user that we could not find a usable */
  286.         /* Winsock DLL.                                  */
  287.         printf("WSAStartup failed with error: %d\n", err);
  288.         return NULL;
  289.     }
  290.  
  291. /* Confirm that the WinSock DLL supports 2.2.*/
  292. /* Note that if the DLL supports versions greater    */
  293. /* than 2.2 in addition to 2.2, it will still return */
  294. /* 2.2 in wVersion since that is the version we      */
  295. /* requested.                                        */
  296.  
  297.     if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
  298.         /* Tell the user that we could not find a usable */
  299.         /* WinSock DLL.                                  */
  300.         printf("Could not find a usable version of Winsock.dll\n");
  301.         WSACleanup();
  302.         return NULL;
  303.     }
  304.     else
  305.         printf("The Winsock 2.2 dll was found okay\n");
  306.        
  307.  
  308. /* The Winsock DLL is acceptable. Proceed to use it. */
  309.  
  310. /* Add network programming using Winsock here */
  311.  
  312. /* then call WSACleanup when done using the Winsock dll */
  313.    
  314.    return NULL;
  315.  
  316. };
  317.  
  318.  
  319. void            winsock_cleanup(void){
  320.  WSACleanup();
  321. };
  322.  
  323. #define SOCK_STARTUP winsock_startup()
  324. #define SOCK_CLEANUP winsock_cleanup()
  325.  
  326.  
  327.  
  328.  
  329.  
  330. BOOL APIENTRY DllMain( HANDLE hModule,
  331.                        DWORD  ul_reason_for_call,
  332.                        LPVOID lpReserved)
  333. {
  334.     return TRUE;
  335. }
  336.  
  337. /******************************************************************************/
  338. /** simple syslog replacement for this example.
  339. */
  340. /*
  341.  * priorities/facilities are encoded into a single 32-bit quantity, where the
  342.  * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
  343.  * (0-big number).  Both the priorities and the facilities map roughly
  344.  * one-to-one to strings in the syslogd(8) source code.  This mapping is
  345.  * included in this file.
  346.  *
  347.  * priorities (these are ordered)
  348.  */
  349. #define LOG_EMERG       0       /* system is unusable */
  350. #define LOG_ALERT       1       /* action must be taken immediately */
  351. #define LOG_CRIT        2       /* critical conditions */
  352. #define LOG_ERR         3       /* error conditions */
  353. #define LOG_WARNING     4       /* warning conditions */
  354. #define LOG_NOTICE      5       /* normal but significant condition */
  355. #define LOG_INFO        6       /* informational */
  356. #define LOG_DEBUG       7       /* debug-level messages */
  357.  
  358. size_t lengthSysStatus;  
  359.  
  360. void syslog(int priority,const char* format,...) {
  361.   va_list vaPrintf;
  362.   va_start(vaPrintf,format);
  363.   vprintf(format,vaPrintf); putchar('\n');
  364.   va_end(vaPrintf);
  365. }
  366.  
  367.  
  368. /******************************************************************************/
  369. /** SNMP Initialization.
  370. */
  371.  
  372.  
  373. int __stdcall SnmpInit(void) {
  374.         syslog(LOG_DEBUG,"*** Initialise SNMP ***");
  375.  
  376.   init_snmp("CrateTest");                                                                         // I never saw this name used !?!
  377.         init_mib();                                                                                                                             // init MIB processing
  378.   if(!read_module("WIENER-CRATE-MIB")) {                // read specific mibs
  379.     syslog(LOG_ERR,"Unable to load SNMP MIB file \"%s\"","WIENER-CRATE-MIB");
  380.     return 0;
  381.   }
  382.   syslog(LOG_DEBUG,"*** Translate OIDs ***");
  383.  
  384. //Translate System OIDS
  385.   lengthSysMainSwitch = MAX_OID_LEN;
  386.   if(!get_node(S_sysMainSwitch,oidSysMainSwitch,&lengthSysMainSwitch)) {
  387.                 syslog(LOG_ERR,"OID \"sysMainSwitch.0\"not found"); return false; }
  388.  
  389.   lengthSysStatus = MAX_OID_LEN;
  390.   if(!get_node(S_sysStatus,oidSysStatus,&lengthSysStatus)) {
  391.                 syslog(LOG_ERR,"OID \"sysStatus.0\"not found"); return false;}
  392.  
  393.   lengthSysVmeSysReset = MAX_OID_LEN;
  394.   if(!get_node(S_sysVmeSysReset,oidSysVmeSysReset,&lengthSysVmeSysReset)) {
  395.                 syslog(LOG_ERR,"OID \"SysVmeSysReset.0\"not found"); return false;}
  396.  
  397.  
  398.  
  399. //Translate System Channel Count Information OIDS
  400.   lengthOutputNumber = MAX_OID_LEN;
  401.   if(!get_node(S_outputNumber,oidOutputNumber,&lengthOutputNumber)) {
  402.                 syslog(LOG_ERR,"OID \"OutputNumber.0\"not found"); return false; }
  403.  
  404.   lengthGroupsNumber = MAX_OID_LEN;
  405.   if(!get_node(S_groupsNumber,oidGroupsNumber,&lengthGroupsNumber)) {
  406.                 syslog(LOG_ERR,"OID \"groupsNumber.0\"not found"); return false;}
  407.  
  408.  
  409. //Translate Channel Information OIDS
  410.  
  411.  
  412.   char s[10000];
  413.   char index[4];
  414.   int base =0;
  415.   int indexBase=0;
  416.   int j=0, idx;
  417. // 2014/01/21:  i was set to run to 1 only and base was 32 resulting in module offset of 32
  418. // corrected go to 100 and also field size for all OID's increased to 1000
  419. //  for( int i = 0; i < 2; i++) {
  420.   for( int i = 0; i < 10; i++) {
  421.         base = 100*i;
  422.         indexBase = 100*i+1;
  423.     for( j = 0; j < 100; j++)
  424.     {
  425.           idx = indexBase+j;
  426.           if (idx>=999) idx=999;
  427.           strcpy(s, S_outputNameBase);
  428.           sprintf(index, "%i", idx);
  429.           strcat(s, index);
  430. //        printf("%s\n", s);
  431.           lengthOutputName[base+j] = MAX_OID_LEN;
  432.           if(!get_node(s,oidOutputName[base+j],&lengthOutputName[base+j])) {
  433.                 syslog(LOG_ERR,"OID \"outputName\"not found"); return false;}
  434. // groups not implemented
  435. /*        strcpy(s, S_outputGroupBase);
  436.           sprintf(index, "%i", indexBase+j);
  437.           strcat(s, index);
  438.           lengthOutputGroup[base+j] = MAX_OID_LEN;
  439.           if(!get_node(s,oidOutputGroup[base+j],&lengthOutputGroup[base+j])) {
  440.                 syslog(LOG_ERR,"OID \"OutputGroup\"not found"); return false;}
  441. */
  442.       strcpy(s, S_outputStatusBase);
  443. //        sprintf(index, "%i",indexBase+j);
  444.           strcat(s, index);
  445.           lengthOutputStatus[base+j] = MAX_OID_LEN;
  446.           if(!get_node(s,oidOutputStatus[base+j],&lengthOutputStatus[base+j])) {
  447.                 syslog(LOG_ERR,"OID \"outputStatus.1\"not found"); return false; }
  448.  
  449.           strcpy(s, S_outputMeasurementSenseVoltageBase);
  450. //        sprintf(index, "%i", indexBase+j);
  451.           strcat(s, index);
  452.           lengthOutputMeasurementSenseVoltage[base+j] = MAX_OID_LEN;
  453.           if(!get_node(s,oidOutputMeasurementSenseVoltage[base+j],&lengthOutputMeasurementSenseVoltage[base+j])) {
  454.                 syslog(LOG_ERR,"OID \"outputMeasurementSenseVoltage.1\"not found"); return false;}
  455.  
  456.           strcpy(s, S_outputMeasurementTerminalVoltageBase);
  457. //        sprintf(index, "%i", indexBase+j);
  458.           strcat(s, index);
  459.           lengthOutputMeasurementTerminalVoltage[base+j] = MAX_OID_LEN;
  460.           if(!get_node(s,oidOutputMeasurementTerminalVoltage[base+j],&lengthOutputMeasurementTerminalVoltage[base+j])) {
  461.                 syslog(LOG_ERR,"OID \"outputMeasurementTerminalVoltage.1\"not found"); return false;}
  462.  
  463.           strcpy(s, S_outputMeasurementCurrentBase);
  464. //        sprintf(index, "%i", indexBase+j);
  465.           strcat(s, index);
  466.           lengthOutputMeasurementCurrent[base+j] = MAX_OID_LEN;
  467.                 if(!get_node(s,oidOutputMeasurementCurrent[base+j],&lengthOutputMeasurementCurrent[base+j])) {
  468.                         syslog(LOG_ERR,"OID \"outputMeasurementCurrent.1\"not found"); return false; }
  469.  
  470.           strcpy(s, S_outputMeasurementTemperatureBase);
  471. //        sprintf(index, "%i", indexBase+j);
  472.           strcat(s, index);
  473.           lengthOutputMeasurementTemperature[base+j] = MAX_OID_LEN;
  474.                 if(!get_node(s,oidOutputMeasurementTemperature[base+j],&lengthOutputMeasurementTemperature[base+j])) {
  475.                         syslog(LOG_ERR,"OID \"outputMeasurementTemperature\"not found"); return false; }
  476.    
  477.           strcpy(s, S_outputSwitchBase);
  478. //        sprintf(index, "%i",indexBase+j);
  479.           strcat(s, index);
  480.           lengthChannelSwitch[base+j] = MAX_OID_LEN;
  481.           if(!get_node(s,oidChannelSwitch[base+j],&lengthChannelSwitch[base+j])) {
  482.                 syslog(LOG_ERR,"OID \"channelSwitch.1\"not found"); return false;  }
  483. /*
  484.           // groupSwitch added 05/16/2013___AR but not working!!!
  485.           strcpy(s, S_groupSwitchBase);
  486.           sprintf(index, "%i",indexBase+j);
  487.           strcat(s, index);
  488.           lengthGroupSwitch[base+j] = MAX_OID_LEN;
  489.           if(!get_node(s,oidGroupSwitch[base+j],&lengthGroupSwitch[base+j])) {
  490.                 syslog(LOG_ERR,"OID \"GroupSwitch.1\"not found"); return false;  }
  491. */        //-----------------------------------
  492.           strcpy(s, S_outputVoltageBase);
  493. //        sprintf(index, "%i", indexBase+j);
  494.           strcat(s, index);
  495.           lengthOutputVoltage[base+j] = MAX_OID_LEN;
  496.           if(!get_node(s,oidOutputVoltage[base+j],&lengthOutputVoltage[base+j])) {
  497.                 syslog(LOG_ERR,"OID \"outputVoltage.1\"not found"); return false; }
  498.  
  499.           strcpy(s, S_outputCurrentBase);
  500. //        sprintf(index, "%i", indexBase+j);
  501.           strcat(s, index);
  502.           lengthOutputCurrent[base+j] = MAX_OID_LEN;
  503.           if(!get_node(s,oidOutputCurrent[base+j],&lengthOutputCurrent[base+j])) {
  504.                 syslog(LOG_ERR,"OID \"outputCurrent\"not found"); return false; }
  505.  
  506.           strcpy(s, S_outputRiseRateBase);
  507. //        sprintf(index, "%i", indexBase+j);
  508.           strcat(s, index);
  509.           lengthOutputRiseRate[base+j] = MAX_OID_LEN;
  510.           if(!get_node(s,oidOutputRiseRate[base+j],&lengthOutputRiseRate[base+j])) {
  511.                 syslog(LOG_ERR,"OID \"outputRiseRate.1\"not found"); return false;}
  512.        
  513.           strcpy(s, S_outputFallRateBase);
  514. //        sprintf(index, "%i", indexBase+j);
  515.           strcat(s, index);
  516.           lengthOutputFallRate[base+j] = MAX_OID_LEN;
  517.           if(!get_node(s,oidOutputFallRate[base+j],&lengthOutputFallRate[base+j])) {
  518.                 syslog(LOG_ERR,"OID \"outputRiseRate.1\"not found"); return false; }
  519.        
  520.           strcpy(s, S_outputSupervisionBehaviorBase);
  521. //        sprintf(index, "%i", indexBase+j);
  522.           strcat(s, index);
  523.           lengthOutputSupervisionBehavior[base+j] = MAX_OID_LEN;
  524.           if(!get_node(s,oidOutputSupervisionBehavior[base+j],&lengthOutputSupervisionBehavior[base+j])) {
  525.                 syslog(LOG_ERR,"OID \"outputSupervisionBehavior\"not found"); return false; }
  526.        
  527.           strcpy(s, S_outputSupervisionMinSenseVoltageBase);
  528. //        sprintf(index, "%i", indexBase+j);
  529.           strcat(s, index);
  530.           lengthOutputSupervisionMinSenseVoltage[base+j] = MAX_OID_LEN;
  531.           if(!get_node(s,oidOutputSupervisionMinSenseVoltage[base+j],&lengthOutputSupervisionMinSenseVoltage[base+j])) {
  532.                 syslog(LOG_ERR,"OID \"outputSupervisionMinSenseVoltage\"not found"); return false; }
  533.  
  534.           strcpy(s, S_outputSupervisionMaxSenseVoltageBase);
  535. //        sprintf(index, "%i", indexBase+j);
  536.           strcat(s, index);
  537.           lengthOutputSupervisionMaxSenseVoltage[base+j] = MAX_OID_LEN;
  538.           if(!get_node(s,oidOutputSupervisionMaxSenseVoltage[base+j],&lengthOutputSupervisionMaxSenseVoltage[base+j])) {
  539.                 syslog(LOG_ERR,"OID \"outputSupervisionMaxSenseVoltage\"not found"); return false; }
  540.  
  541.           strcpy(s, S_outputSupervisionMaxTerminalVoltageBase);
  542. //        sprintf(index, "%i", indexBase+j);
  543.           strcat(s, index);
  544.           lengthOutputSupervisionMaxTerminalVoltage[base+j] = MAX_OID_LEN;
  545.           if(!get_node(s,oidOutputSupervisionMaxTerminalVoltage[base+j],&lengthOutputSupervisionMaxTerminalVoltage[base+j])) {
  546.                 syslog(LOG_ERR,"OID \"outputSupervisionMaxTerminalVoltage\"not found"); return false; }
  547.  
  548.           strcpy(s, S_outputSupervisionMaxCurrentBase);
  549. //        sprintf(index, "%i", indexBase+j);
  550.           strcat(s, index);
  551.           lengthOutputSupervisionMaxCurrent[base+j] = MAX_OID_LEN;
  552.           if(!get_node(s,oidOutputSupervisionMaxCurrent[base+j],&lengthOutputSupervisionMaxCurrent[base+j])) {
  553.                 syslog(LOG_ERR,"OID \"outputSupervisionMaxCurrent\"not found"); return false; }
  554. /*
  555.           strcpy(s, S_outputSupervisionMaxTemperatureBase);
  556.           sprintf(index, "%i", indexBase+j);
  557.           strcat(s, index);
  558.           lengthOutputSupervisionMaxTemperature[base+j] = MAX_OID_LEN;
  559.           if(!get_node(s,oidOutputSupervisionMaxTemperature[base+j],&lengthOutputSupervisionMaxTemperature[base+j])) {
  560.                 syslog(LOG_ERR,"OID \"outputSupervisionMaxTemperature\"not found"); return false; }
  561. */
  562.           strcpy(s, S_outputConfigMaxSenseVoltageBase);
  563. //        sprintf(index, "%i", indexBase+j);
  564.           strcat(s, index);
  565.           lengthOutputConfigMaxSenseVoltage[base+j] = MAX_OID_LEN;
  566.           if(!get_node(s,oidOutputConfigMaxSenseVoltage[base+j],&lengthOutputConfigMaxSenseVoltage[base+j])) {
  567.                 syslog(LOG_ERR,"OID \"outputConfigMaxSenseVoltage\"not found"); return false; }
  568.  
  569.           strcpy(s, S_outputConfigMaxTerminalVoltageBase);
  570. //        sprintf(index, "%i", indexBase+j);
  571.           strcat(s, index);
  572.           lengthOutputConfigMaxTerminalVoltage[base+j] = MAX_OID_LEN;
  573.           if(!get_node(s,oidOutputConfigMaxTerminalVoltage[base+j],&lengthOutputConfigMaxTerminalVoltage[base+j])) {
  574.                 syslog(LOG_ERR,"OID \"outputConfigMaxTerminalVoltage\"not found"); return false; }
  575.          
  576.           strcpy(s, S_outputConfigMaxCurrentBase);
  577. //        sprintf(index, "%i", indexBase+j);
  578.           strcat(s, index);
  579.           lengthOutputConfigMaxCurrent[base+j] = MAX_OID_LEN;
  580.           if(!get_node(s,oidOutputConfigMaxCurrent[base+j],&lengthOutputConfigMaxCurrent[base+j])) {
  581.                 syslog(LOG_ERR,"OID \"outputConfigMaxCurrent\"not found"); return false; }
  582.  
  583.           strcpy(s, S_outputConfigMaxPowerBase);
  584. //        sprintf(index, "%i", indexBase+j);
  585.           strcat(s, index);
  586.           lengthOutputConfigMaxPower[base+j] = MAX_OID_LEN;
  587.           if(!get_node(s,oidOutputConfigMaxPower[base+j],&lengthOutputConfigMaxPower[base+j])) {
  588.                 syslog(LOG_ERR,"OID \"outputConfigMaxPower\"not found"); return false; }
  589.         }  
  590.   }
  591.  
  592.  
  593. //Sensor Information
  594.   lengthSensorNumber = MAX_OID_LEN;
  595.   if(!get_node(S_sensorNumber,oidSensorNumber,&lengthSensorNumber)) {
  596.                 syslog(LOG_ERR,"OID \"SensorNumber.0\"not found"); return false;}
  597.  
  598.   for(j = 0; j < 8; j++)
  599.   {
  600.         strcpy(s, S_sensorTemperatureBase);
  601.         sprintf(index, "%i", j+1);
  602.         strcat(s, index);
  603.         lengthSensorTemperature[j] = MAX_OID_LEN;
  604.         if(!get_node(s,oidSensorTemperature[j],&lengthSensorTemperature[j])) {
  605.                 syslog(LOG_ERR,"OID \"sensorTemperature.0\"not found"); return false; }
  606.  
  607.         strcpy(s, S_sensorWarningThresholdBase);
  608.         sprintf(index, "%i", j+1);
  609.         strcat(s, index);
  610.         lengthSensorWarningThreshold[j] = MAX_OID_LEN;
  611.         if(!get_node(s,oidSensorWarningThreshold[j],&lengthSensorWarningThreshold[j])) {
  612.                 syslog(LOG_ERR,"OID \"WarningThreshold\"not found"); return false; }
  613.  
  614.         strcpy(s, S_sensorFailureThresholdBase);
  615.         sprintf(index, "%i", j+1);
  616.         strcat(s, index);
  617.         lengthSensorFailureThreshold[j] = MAX_OID_LEN;
  618.         if(!get_node(s,oidSensorFailureThreshold[j],&lengthSensorFailureThreshold[j])) {
  619.                 syslog(LOG_ERR,"OID \"FailureThreshold\"not found"); return false; }
  620.   }
  621.  
  622.  
  623. //Translate SNMP community Name OIDs
  624.   for(j = 0; j < 4; j++)
  625.   {
  626.         strcpy(s, S_snmpCommunityNameBase);
  627.         sprintf(index, "%i", j+1);
  628.         strcat(s, index);
  629.         lengthSnmpCommunityName[j] = MAX_OID_LEN;
  630.         if(!get_node(s,oidSnmpCommunityName[j],&lengthSnmpCommunityName[j])) {
  631.                 syslog(LOG_ERR,"OID \"smpCommunityNameBase\"not found"); return false; }
  632.   }
  633.  
  634.  
  635. //Translate PS Specific OIDs
  636. /*
  637.   lengthPsFirmwareVersion = MAX_OID_LEN;
  638.   if(!get_node(S_psFirmwareVersion,oidPsFirmwareVersion,&lengthPsFirmwareVersion)) {
  639.                 syslog(LOG_ERR,"OID \"psFirmwareRevision\"not found"); return false; }
  640. */
  641.   lengthPsSerialNumber = MAX_OID_LEN;
  642.   printf("\nPs Serial Number: %s\n", S_psSerialNumber);
  643.   if(!get_node(S_psSerialNumber,oidPsSerialNumber,&lengthPsSerialNumber)) {
  644.                 syslog(LOG_ERR,"OID \"psSerialNumber\"not found"); return false; }
  645.  
  646.   lengthPsOperatingTime = MAX_OID_LEN;
  647.   if(!get_node(S_psOperatingTime,oidPsOperatingTime,&lengthPsOperatingTime)) {
  648.                 syslog(LOG_ERR,"OID \"PsOperatingTime\"not found"); return false; }
  649.  
  650.   lengthPsDirectAccess = MAX_OID_LEN;
  651.   if(!get_node(S_psDirectAccess,oidPsDirectAccess,&lengthPsDirectAccess)) {
  652.                 syslog(LOG_ERR,"OID \"PsDirectAccess\"not found"); return false; }
  653.  
  654. /*
  655. //Translate Fan Tray OIDs
  656.   lengthFanFirmwareVersion = MAX_OID_LEN;
  657.   if(!get_node(S_fanFirmwareVersion,oidFanFirmwareVersion,&lengthFanFirmwareVersion)) {
  658.                 syslog(LOG_ERR,"OID \"FanFirmwareVersion\"not found"); return false; }
  659. */
  660.   lengthFanSerialNumber = MAX_OID_LEN;
  661.   if(!get_node(S_fanSerialNumber,oidFanSerialNumber,&lengthFanSerialNumber)) {
  662.                 syslog(LOG_ERR,"OID \"FanSerialNumber\"not found"); return false; }
  663.  
  664.   lengthFanOperatingTime = MAX_OID_LEN;
  665.   if(!get_node(S_fanOperatingTime,oidFanOperatingTime,&lengthFanOperatingTime)) {
  666.                 syslog(LOG_ERR,"OID \"FanOperatingTime\"not found"); return false; }
  667.  
  668.   lengthFanAirTemperature = MAX_OID_LEN;
  669.   if(!get_node(S_fanAirTemperature,oidFanAirTemperature,&lengthFanAirTemperature)) {
  670.                 syslog(LOG_ERR,"OID \"fanAirTemperature.0\"not found"); return false; }
  671.  
  672.   lengthFanSwitchOffDelay = MAX_OID_LEN;
  673.   if(!get_node(S_fanSwitchOffDelay,oidFanSwitchOffDelay,&lengthFanSwitchOffDelay)) {
  674.                 syslog(LOG_ERR,"OID \"FanSwitchOffDelay\"not found"); return false; }
  675.  
  676.   lengthFanNominalSpeed = MAX_OID_LEN;
  677.   if(!get_node(S_fanNominalSpeed,oidFanNominalSpeed,&lengthFanNominalSpeed)) {
  678.                 syslog(LOG_ERR,"OID \"FanNominalSpeed\"not found"); return false; }
  679.  
  680.   lengthFanNumberOfFans = MAX_OID_LEN;
  681.   if(!get_node(S_fanNumberOfFans,oidFanNumberOfFans,&lengthFanNumberOfFans)) {
  682.                 syslog(LOG_ERR,"OID \"NumberOfFans\"not found"); return false; }
  683.  
  684.   for(j = 0; j < 6; j++)
  685.   {
  686.         strcpy(s, S_fanSpeedBase);
  687.         sprintf(index, "%i", j+1);
  688.         strcat(s, index);
  689.         lengthFanSpeed[j] = MAX_OID_LEN;
  690.         if(!get_node(s,oidFanSpeed[j],&lengthFanSpeed[j])) {
  691.                 syslog(LOG_ERR,"OID \"FanSpeed\"not found"); return false; }
  692.   }
  693.  
  694.   syslog(LOG_DEBUG,"*** Initialise SNMP done ***");
  695.   SOCK_STARTUP;                                                                                                                 // only in main thread
  696.   return 1;
  697. }
  698.  
  699. /******************************************************************************/
  700. /** SNMP Cleanup.
  701. */
  702. void __stdcall SnmpCleanup(void) {
  703.         SOCK_CLEANUP;
  704. }
  705.  
  706.  
  707. /******************************************************************************/
  708. /** SNMP Open Session.
  709. */
  710. //typedef void* HSNMP;                              // SNMP handle (like FILE)
  711.  
  712. HSNMP __stdcall SnmpOpen(const char* ipAddress) {
  713.         HSNMP m_sessp;
  714.   struct snmp_session session;
  715.   snmp_sess_init(&session);                                       // structure defaults
  716.   session.version = SNMP_VERSION_2c;
  717.   session.peername = _strdup(ipAddress);
  718.   session.community = (u_char*)_strdup(readCommunity);
  719.   session.community_len = strlen((char*)session.community);
  720.  
  721.   session.timeout = 100000;   // timeout (us)
  722.   session.retries = 3;        // retries
  723.  
  724.   if(!(m_sessp = snmp_sess_open(&session))) {
  725.     int liberr, syserr;
  726.     char *errstr;
  727.     snmp_error(&session, &liberr, &syserr, &errstr);
  728.     syslog(LOG_ERR,"Open SNMP session for host \"%s\": %s",ipAddress,errstr);
  729.     //free(errstr);
  730.     return 0;
  731.   }
  732.  
  733. //  m_session = snmp_sess_session(m_sessp);     // get the session pointer
  734.  
  735.   syslog(LOG_INFO,"SNMP session for host \"%s\" opened",ipAddress);
  736.   return m_sessp;
  737. }
  738.  
  739. /******************************************************************************/
  740. /** SNMP Close Session.
  741. */
  742. void __stdcall SnmpClose(HSNMP m_sessp) {
  743.   if(!m_sessp) return;
  744.   if(!snmp_sess_close(m_sessp)) {
  745.     syslog(LOG_ERR,"Close SNMP session: ERROR");
  746.   }
  747.   else syslog(LOG_INFO,"SNMP session closed");
  748. }
  749.  
  750.  
  751.  
  752. //System Information Functions
  753.  
  754.  
  755. /******************************************************************************/
  756. /** Get on/off status of crate
  757. */
  758. int __stdcall getMainSwitch(HSNMP m_sessp) {
  759.         int value = snmpGetInt(m_sessp, oidSysMainSwitch, lengthSysMainSwitch);
  760.         return value;
  761. }
  762.  
  763. /******************************************************************************/
  764. /** Write on/off status
  765. */
  766. int  __stdcall setMainSwitch(HSNMP m_sessp,int value) {
  767.         value = snmpSetInt(m_sessp, oidSysMainSwitch, lengthSysMainSwitch, value);
  768.         return value;
  769. }
  770.  
  771. /******************************************************************************/
  772. /** Get Main Status
  773. */
  774. int __stdcall getMainStatus(HSNMP m_sessp){
  775.         int value = snmpGetInt(m_sessp, oidSysStatus, lengthSysStatus);
  776.         return value;
  777. }
  778.  
  779. /******************************************************************************/
  780. /** Get VmeReset Status
  781. */
  782. int __stdcall getVmeReset(HSNMP m_sessp){
  783.         int value = snmpGetInt(m_sessp, oidSysVmeSysReset, lengthSysVmeSysReset);
  784.         return value;
  785. }
  786.  
  787. /******************************************************************************/
  788. /** Initiate VME SysReset
  789. */
  790. int __stdcall setVmeReset(HSNMP m_sessp){
  791.         int value = snmpSetInt(m_sessp, oidSysVmeSysReset, lengthSysVmeSysReset, 1);
  792.         return value;
  793. }
  794.  
  795.  
  796.  
  797. //System Count Functions
  798.  
  799. /******************************************************************************/
  800. /** Get the number of channels from power supply
  801. */
  802. int __stdcall getOutputNumber(HSNMP m_sessp){
  803.         int value = snmpGetInt(m_sessp, oidOutputNumber, lengthOutputNumber);
  804.         return value;
  805. }
  806.  
  807. /******************************************************************************/
  808. /** Get the number of channels from power supply
  809. */
  810. int __stdcall getOutputGroups(HSNMP m_sessp){
  811.         int value = snmpGetInt(m_sessp, oidGroupsNumber, lengthGroupsNumber);
  812.         return value;
  813. }
  814.  
  815.  
  816.  
  817.  
  818. //Output Channel Information
  819.  
  820. /******************************************************************************/
  821. /** I Don't know yet how to set this up
  822. */
  823. // std::string __stdcall getOutputName(HSNMP m_sessp,int channel);
  824.  
  825. int __stdcall getOutputGroup(HSNMP m_sessp,int channel){
  826.         int value = snmpGetInt(m_sessp, oidOutputGroup[channel], lengthOutputGroup[channel]);
  827.         return value; }
  828.  
  829. int __stdcall getChannelStatus(HSNMP m_sessp, int channel){
  830.         int value = snmpGetInt(m_sessp, oidOutputStatus[channel], lengthOutputStatus[channel]);
  831.         return value;
  832. }
  833.  
  834. double __stdcall getOutputSenseMeasurement(HSNMP m_sessp, int channel){
  835.         double value = snmpGetDouble(m_sessp, oidOutputMeasurementSenseVoltage[channel],
  836.                                    lengthOutputMeasurementSenseVoltage[channel]);
  837.         return value; }
  838.  
  839. double __stdcall getOutputTerminalMeasurement(HSNMP m_sessp, int channel){
  840.         double value = snmpGetDouble(m_sessp, oidOutputMeasurementTerminalVoltage[channel],
  841.                                    lengthOutputMeasurementTerminalVoltage[channel]);
  842.         return value; }
  843.  
  844. double __stdcall getCurrentMeasurement(HSNMP m_sessp, int channel){
  845.         double value = snmpGetDouble(m_sessp, oidOutputMeasurementCurrent[channel],
  846.                                    lengthOutputMeasurementCurrent[channel]);
  847.         return value; }
  848.  
  849. int __stdcall getTemperatureMeasurement(HSNMP m_sessp, int channel){
  850.         int value = snmpGetInt(m_sessp, oidOutputMeasurementTemperature[channel],
  851.                                    lengthOutputMeasurementTemperature[channel]);
  852.         return value; }
  853.  
  854. int __stdcall setChannelSwitch(HSNMP m_sessp, int channel,int value) {
  855.         value = snmpSetInt(m_sessp, oidChannelSwitch[channel],
  856.                                                    lengthChannelSwitch[channel], value);
  857.         return value; }
  858.  
  859. int __stdcall getChannelSwitch(HSNMP m_sessmp, int channel){
  860.         int value = snmpGetInt(m_sessmp, oidChannelSwitch[channel],
  861.                                                    lengthChannelSwitch[channel]);
  862.         return value; }
  863.  
  864. // groupSwitch added 05/16/2013___AR
  865. int __stdcall setGroupSwitch(HSNMP m_sessp, int group,int value) {
  866.         value = snmpSetInt(m_sessp, oidGroupSwitch[group],
  867.                                                    lengthGroupSwitch[group], value);
  868.         return value; }
  869.  
  870. int __stdcall getGroupSwitch(HSNMP m_sessmp, int group){
  871.         int value = snmpGetInt(m_sessmp, oidGroupSwitch[group],
  872.                                                    lengthGroupSwitch[group]);
  873.         return value; }
  874. //_______________________________________
  875. double __stdcall getOutputVoltage(HSNMP m_sessp, int channel) {
  876.     double value = snmpGetDouble(m_sessp, oidOutputVoltage[channel],
  877.                                    lengthOutputVoltage[channel] );
  878.   return value; }
  879.  
  880. double __stdcall setOutputVoltage(HSNMP m_sessp, int channel, double value) {
  881.         value = snmpSetDouble(m_sessp, oidOutputVoltage[channel],
  882.                               lengthOutputVoltage[channel], value );
  883.         return value; }
  884.  
  885. double __stdcall getOutputCurrent(HSNMP m_sessp,int channel) {
  886.         double value = snmpGetDouble(m_sessp, oidOutputCurrent[channel],
  887.                               lengthOutputCurrent[channel]);
  888.         return value; }
  889.  
  890. double __stdcall setOutputCurrent(HSNMP m_sessp,int channel,double value){
  891.         value = snmpSetDouble(m_sessp, oidOutputCurrent[channel],
  892.                               lengthOutputCurrent[channel], value );
  893.         return value; }
  894.  
  895. double __stdcall getOutputRiseRate(HSNMP m_sessp, int channel) {
  896.         double value = snmpGetDouble(m_sessp, oidOutputRiseRate[channel],
  897.                                    lengthOutputRiseRate[channel] );
  898.         return value; }
  899.  
  900. double  __stdcall setOutputRiseRate(HSNMP m_sessp,int channel,double value) {
  901.         value = snmpSetDouble(m_sessp, oidOutputRiseRate[channel],
  902.                               lengthOutputRiseRate[channel], value );
  903.         return value; }
  904.  
  905. double __stdcall getOutputFallRate(HSNMP m_sessp, int channel) {
  906.         double value = snmpGetDouble(m_sessp, oidOutputFallRate[channel],
  907.                                    lengthOutputFallRate[channel] );
  908.         return value; }
  909.  
  910. double  __stdcall setOutputFallRate(HSNMP m_sessp,int channel,double value) {
  911.         value = snmpSetDouble(m_sessp, oidOutputFallRate[channel],
  912.                                    lengthOutputFallRate[channel], value );
  913.         return value; }
  914.  
  915. int __stdcall getOutputSupervisionBehavior(HSNMP m_sessp,int channel) {
  916.         int value = snmpGetInt(m_sessp, oidOutputSupervisionBehavior[channel],
  917.                                    lengthOutputSupervisionBehavior[channel] );
  918.         return value; }
  919.  
  920. int __stdcall setOutputSupervisionBehavior(HSNMP m_sessp,int channel,int value) {
  921.         value = snmpSetInt(m_sessp, oidOutputSupervisionBehavior[channel],
  922.                                    lengthOutputSupervisionBehavior[channel], value );
  923.         return value; }
  924.  
  925. double __stdcall getOutputSupervisionMinSenseVoltage(HSNMP m_sessp,int channel) {
  926.         double value = snmpGetDouble(m_sessp, oidOutputSupervisionMinSenseVoltage[channel],
  927.                                    lengthOutputSupervisionMinSenseVoltage[channel] );
  928.         return value; }
  929.  
  930. double __stdcall setOutputSupervisionMinSenseVoltage(HSNMP m_sessp,int channel,double value) {
  931.         value = snmpSetDouble(m_sessp, oidOutputSupervisionMinSenseVoltage[channel],
  932.                                    lengthOutputSupervisionMinSenseVoltage[channel], value );
  933.         return value; }
  934.  
  935. double __stdcall getOutputSupervisionMaxSenseVoltage(HSNMP m_sessp,int channel) {
  936.         double value = snmpGetDouble(m_sessp, oidOutputSupervisionMaxSenseVoltage[channel],
  937.                                    lengthOutputSupervisionMaxSenseVoltage[channel] );
  938.         return value; }
  939.  
  940. double __stdcall setOutputSupervisionMaxSenseVoltage(HSNMP m_sessp,int channel,double value) {
  941.         value = snmpSetDouble(m_sessp, oidOutputSupervisionMaxSenseVoltage[channel],
  942.                                    lengthOutputSupervisionMaxSenseVoltage[channel], value );
  943.         return value; }
  944.  
  945. double __stdcall getOutputSupervisionMaxTerminalVoltage(HSNMP m_sessp,int channel) {
  946.         double value = snmpGetDouble(m_sessp, oidOutputSupervisionMaxTerminalVoltage[channel],
  947.                                    lengthOutputSupervisionMaxTerminalVoltage[channel] );
  948.         return value; }
  949.  
  950. double __stdcall setOutputSupervisionMaxTerminalVoltage(HSNMP m_sessp,int channel,double value) {
  951.         value = snmpSetDouble(m_sessp, oidOutputSupervisionMaxTerminalVoltage[channel],
  952.                                    lengthOutputSupervisionMaxTerminalVoltage[channel], value );
  953.         return value; }
  954.  
  955. double __stdcall getOutputSupervisionMaxCurrent(HSNMP m_sessp,int channel) {
  956.         double value = snmpGetDouble(m_sessp, oidOutputSupervisionMaxCurrent[channel],
  957.                                    lengthOutputSupervisionMaxCurrent[channel] );
  958.         return value; }
  959.  
  960. double __stdcall setOutputSupervisionMaxCurrent(HSNMP m_sessp,int channel,double value){
  961.         value = snmpSetDouble(m_sessp, oidOutputSupervisionMaxCurrent[channel],
  962.                                    lengthOutputSupervisionMaxCurrent[channel], value );
  963.         return value; }
  964.  
  965. int __stdcall getOutputSupervisionMaxTemperature(HSNMP m_sessp,int channel) {
  966.         int value = snmpGetInt(m_sessp, oidOutputSupervisionMaxTemperature[channel],
  967.                                    lengthOutputSupervisionMaxTemperature[channel] );
  968.         return value; }
  969.  
  970.  
  971. double __stdcall getOutputConfigMaxSenseVoltage(HSNMP m_sessp,int channel)  {
  972.         double value = snmpGetDouble(m_sessp, oidOutputConfigMaxSenseVoltage[channel],
  973.                                    lengthOutputConfigMaxSenseVoltage[channel] );
  974.         return value; }
  975.  
  976. double __stdcall getOutputConfigMaxTerminalVoltage(HSNMP m_sessp,int channel) {
  977.         double value = snmpGetInt(m_sessp, oidOutputConfigMaxTerminalVoltage[channel],
  978.                                    lengthOutputConfigMaxTerminalVoltage[channel] );
  979.         return value; }
  980.  
  981. double __stdcall getOutputConfigMaxCurrent(HSNMP m_sessp,int channel) {
  982.         double value = snmpGetInt(m_sessp, oidOutputConfigMaxCurrent[channel],
  983.                                    lengthOutputConfigMaxCurrent[channel] );
  984.         return value; }
  985.  
  986. double __stdcall getOutputConfigMaxPower(HSNMP m_sessp,int channel){
  987.         double value = snmpGetInt(m_sessp, oidOutputConfigMaxPower[channel],
  988.                                    lengthOutputConfigMaxPower[channel] );
  989.         return value; }
  990.  
  991.  
  992.  
  993.  
  994. //Sensor Information functions
  995. int __stdcall getSensorNumber(HSNMP m_sessp) {
  996.         double value = snmpGetInt(m_sessp, oidSensorNumber,
  997.                                    lengthSensorNumber);
  998.         return (int)value; }
  999.  
  1000. int __stdcall getSensorTemp(HSNMP m_sessp, int sensor) {
  1001.         double value = snmpGetInt(m_sessp, oidSensorTemperature[sensor],
  1002.                                    lengthSensorTemperature[sensor]);
  1003.         return (int)value; }
  1004.  
  1005. int __stdcall getSensorWarningTemperature(HSNMP m_sessp,int sensor) {
  1006.         double value = snmpGetInt(m_sessp, oidSensorWarningThreshold[sensor],
  1007.                                    lengthSensorWarningThreshold[sensor]);
  1008.         return (int)value; }
  1009.  
  1010. int __stdcall setSensorWarningTemperature(HSNMP m_sessp,int sensor,int value){
  1011.          value = snmpSetInt(m_sessp, oidSensorWarningThreshold[sensor],
  1012.                                    lengthSensorWarningThreshold[sensor], value);
  1013.         return (int)value; }
  1014.  
  1015. int __stdcall getSensorFailureTemperature(HSNMP m_sessp,int sensor) {
  1016.         double value = snmpGetInt(m_sessp, oidSensorFailureThreshold[sensor],
  1017.                                    lengthSensorFailureThreshold[sensor]);
  1018.         return (int)value; }
  1019.  
  1020. int __stdcall setSensorFailureTemperature(HSNMP m_sessp,int sensor,int value){
  1021.         value = snmpSetInt(m_sessp, oidSensorFailureThreshold[sensor],
  1022.                                    lengthSensorFailureThreshold[sensor], value);
  1023.         return (int)value; }
  1024.  
  1025.  
  1026.  
  1027. //Power Supply specific Functions.  
  1028. int __stdcall getPsOperatingTime(HSNMP m_sessp) {
  1029.         double value = snmpGetInt(m_sessp, oidPsOperatingTime,
  1030.                                    lengthPsOperatingTime);
  1031.         return (int)value; }
  1032.  
  1033.  
  1034. //Fan Tray Functions
  1035. //std::string __stdcall getFanFirmwareVersion(HSNMP m_sessp);
  1036. //std::string __stdcall getFanSerialNumber(HSNMP m_sessp);
  1037. int __stdcall getFanOperatingTime(HSNMP m_sessp) {
  1038.         double value = snmpGetInt(m_sessp, oidFanOperatingTime,
  1039.                                    lengthFanOperatingTime );
  1040.         return (int)value; }
  1041.  
  1042. int __stdcall getFanAirTemperature(HSNMP m_sessp) {
  1043.         double value = snmpGetInt(m_sessp, oidFanAirTemperature,
  1044.                                    lengthFanAirTemperature );
  1045.         return (int)value; }
  1046.  
  1047. int __stdcall getFanSwitchOffDelay(HSNMP m_sessp) {
  1048.         double value = snmpGetInt(m_sessp, oidFanSwitchOffDelay,
  1049.                                    lengthFanSwitchOffDelay );
  1050.         return (int)value; }
  1051.  
  1052. int __stdcall setFanSwitchOffDelay(HSNMP m_sessp, int value) {
  1053.         value = snmpSetInt(m_sessp, oidFanSwitchOffDelay,
  1054.                                    lengthFanSwitchOffDelay, value );
  1055.         return (int)value; }
  1056.  
  1057. int __stdcall getFanNominalSpeed(HSNMP m_sessp) {
  1058.         double value = snmpGetInt(m_sessp, oidFanNominalSpeed,
  1059.                                    lengthFanNominalSpeed );
  1060.         return (int)value; }
  1061.  
  1062. int __stdcall setFanNominalSpeed(HSNMP m_sessp, int value){
  1063.         value = snmpSetInt(m_sessp, oidFanNominalSpeed,
  1064.                                    lengthFanNominalSpeed, value );
  1065.         return (int)value; }
  1066.  
  1067. int __stdcall getFanNumberOfFans(HSNMP m_sessp){
  1068.         double value = snmpGetInt(m_sessp, oidFanNumberOfFans,
  1069.                                    lengthFanNumberOfFans );
  1070.         return (int)value; }
  1071.  
  1072. int __stdcall getFanSpeed(HSNMP m_sessp, int fan) {
  1073.         double value = snmpGetInt(m_sessp, oidFanSpeed[fan],
  1074.                                    lengthFanSpeed[fan]);
  1075.         return (int)value; }
  1076.  
  1077.  
  1078. char * __stdcall getOutputName(HSNMP m_sessp, int channel) {
  1079.         return  snmpGetString(m_sessp, oidOutputName[channel],
  1080.                                    lengthOutputName[channel]);
  1081. }
  1082.  
  1083.  
  1084.  
  1085. //The rest of the functions are utility functions that actually do the SNMP calls
  1086.  
  1087. int __stdcall snmpGetInt(HSNMP m_sessp, const oid* parameter, size_t length) {
  1088.   int value=0;
  1089.  
  1090.   struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_GET);    // prepare get-request pdu
  1091.  
  1092.   // for(each GET request to one crate) {
  1093.     snmp_add_null_var(pdu,parameter,length);   // generate request data
  1094.   // } // endfor
  1095.  
  1096.   struct snmp_pdu* response;
  1097.         int status = snmp_sess_synch_response(m_sessp,pdu,&response);
  1098.  
  1099.   /*
  1100.   * Process the response.
  1101.   */
  1102.   if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
  1103.     /*
  1104.     * SUCCESS: Print the result variables
  1105.     */
  1106.     struct variable_list *vars;
  1107.  
  1108.     /* manipuate the information ourselves */
  1109.     for(vars = response->variables; vars; vars = vars->next_variable) {
  1110.                         if (vars->type == ASN_OPAQUE_FLOAT) {                               // 0x78
  1111.         value = *vars->val.floatVal;
  1112.       }
  1113.                         else if (vars->type == ASN_OPAQUE_DOUBLE) {                     // 0x79
  1114.         value = (int) *vars->val.doubleVal;
  1115.       }
  1116.                         else if(vars->type == ASN_INTEGER) {                                  // 0x02
  1117.                                 value = *vars->val.integer;
  1118.       }
  1119.        /*
  1120.         else if(vars->type==ASN_OCTET_STR) {
  1121.         value=(char *)malloc(1+vars->val_len);
  1122.         memcpy(value,vars->val.string,vars->val_len);
  1123.         value[vars->val_len]='\0';
  1124.       }
  1125.        */
  1126.        
  1127.       else {
  1128.         value = *vars->val.integer;
  1129.         // fprintf(stderr, "Wrong type 0x%x len=%d value=0x%x\n", vars->type, vars->val_len, *vars->val.integer);
  1130.       }
  1131.     }
  1132.   } else {
  1133.     /*
  1134.     * FAILURE: print what went wrong!
  1135.     */
  1136.  
  1137.     if (status == STAT_SUCCESS)
  1138.       fprintf(stderr, "Error in packet\nReason: %s\n",
  1139.       snmp_errstring(response->errstat));
  1140.     else
  1141.       snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
  1142.     return 0;
  1143.   }
  1144.   snmp_free_pdu(response);
  1145.   return (int) value;
  1146. }
  1147.  
  1148.  
  1149.  
  1150. int __stdcall snmpSetInt(HSNMP m_sessp, const oid* parameter, size_t length, int value) {
  1151.   struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_SET);    // prepare set-request pdu
  1152.   pdu->community = (u_char*)_strdup(writeCommunity);
  1153.   pdu->community_len = strlen(writeCommunity);
  1154.  
  1155.   // for(each SET request to one crate) {
  1156.   int v = (int) value;
  1157.   snmp_pdu_add_variable(pdu,parameter,length,ASN_INTEGER,(u_char*)&v,sizeof(v));
  1158.   // } // endfor
  1159.   value=v;
  1160.   struct snmp_pdu* response;
  1161.         int status = snmp_sess_synch_response(m_sessp,pdu,&response);
  1162.  
  1163.   /*
  1164.   * Process the response.
  1165.   */
  1166.   if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
  1167.     /*
  1168.     * SUCCESS: Print the result variables
  1169.     */
  1170.     struct variable_list *vars;
  1171.    
  1172.     // debug print
  1173.     //for(vars = response->variables; vars; vars = vars->next_variable)
  1174.     //  print_variable(vars->name, vars->name_length, vars);
  1175.  
  1176.     /* manipuate the information ourselves */
  1177.     for(vars = response->variables; vars; vars = vars->next_variable) {
  1178.                         if (vars->type == ASN_OPAQUE_FLOAT) {                               // 0x78
  1179.         value = (int)*vars->val.floatVal;
  1180.       }
  1181.                         else if (vars->type == ASN_OPAQUE_DOUBLE) {                     // 0x79
  1182.         value = (int)*vars->val.doubleVal;
  1183.       }
  1184.                         else if(vars->type == ASN_INTEGER) {                                  // 0x02
  1185.                                 value = *vars->val.integer;
  1186.       }
  1187.     }
  1188.   } else {
  1189.     /*
  1190.     * FAILURE: print what went wrong!
  1191.     */
  1192.  
  1193.     if (status == STAT_SUCCESS)
  1194.       fprintf(stderr, "Error in packet\nReason: %s\n",
  1195.       snmp_errstring(response->errstat));
  1196.     else
  1197.       snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
  1198.     return 0;
  1199.   }
  1200.   snmp_free_pdu(response);
  1201.   return (int) value;
  1202. }
  1203.  
  1204.  
  1205.  
  1206. double __stdcall snmpGetDouble(HSNMP m_sessp, const oid* parameter, size_t length) {
  1207.   double value=0;
  1208.  
  1209.   struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_GET);    // prepare get-request pdu
  1210.  
  1211.   // for(each GET request to one crate) {
  1212.     snmp_add_null_var(pdu,parameter,length);   // generate request data
  1213.   // } // endfor
  1214.  
  1215.   struct snmp_pdu* response;
  1216.         int status = snmp_sess_synch_response(m_sessp,pdu,&response);
  1217.  
  1218.   /*
  1219.   * Process the response.
  1220.   */
  1221.   if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
  1222.     /*
  1223.     * SUCCESS: Print the result variables
  1224.     */
  1225.     struct variable_list *vars;
  1226.  
  1227.     /* manipuate the information ourselves */
  1228.     for(vars = response->variables; vars; vars = vars->next_variable) {
  1229.                         if (vars->type == ASN_OPAQUE_FLOAT) {                               // 0x78
  1230.         value = *vars->val.floatVal;
  1231.       }
  1232.                         else if (vars->type == ASN_OPAQUE_DOUBLE) {                     // 0x79
  1233.         value = *vars->val.doubleVal;
  1234.       }
  1235.                         else if(vars->type == ASN_INTEGER) {                                  // 0x02
  1236.                                 value = (double)*vars->val.integer;
  1237.       }
  1238.     }
  1239.   } else {
  1240.     /*
  1241.     * FAILURE: print what went wrong!
  1242.     */
  1243.  
  1244.     if (status == STAT_SUCCESS)
  1245.       fprintf(stderr, "Error in packet\nReason: %s\n",
  1246.       snmp_errstring(response->errstat));
  1247.     else
  1248.       snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
  1249.     return 0;
  1250.   }
  1251.   snmp_free_pdu(response);
  1252.   return  value;
  1253. }
  1254.  
  1255.  
  1256.  
  1257.  
  1258. double __stdcall snmpSetDouble(HSNMP m_sessp, const oid* parameter, size_t length, double value) {
  1259.   struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_SET);    // prepare set-request pdu
  1260.   pdu->community = (u_char*)_strdup(writeCommunity);
  1261.   pdu->community_len = strlen(writeCommunity);
  1262.  
  1263.   // for(each SET request to one crate) {
  1264.   float v = (float) value;
  1265.   snmp_pdu_add_variable(pdu,parameter,length,ASN_OPAQUE_FLOAT,(u_char*)&v,sizeof(v));
  1266.   // } // endfor
  1267.  
  1268.   value =v;
  1269.   struct snmp_pdu* response;
  1270.         int status = snmp_sess_synch_response(m_sessp,pdu,&response);
  1271.  
  1272.   /*
  1273.   * Process the response.
  1274.   */
  1275.   if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
  1276.     /*
  1277.     * SUCCESS: Print the result variables
  1278.     */
  1279.     struct variable_list *vars;
  1280.    
  1281.     // debug print
  1282.     //for(vars = response->variables; vars; vars = vars->next_variable)
  1283.     //  print_variable(vars->name, vars->name_length, vars);
  1284.  
  1285.     /* manipuate the information ourselves */
  1286.     for(vars = response->variables; vars; vars = vars->next_variable) {
  1287.                         if (vars->type == ASN_OPAQUE_FLOAT) {                               // 0x78
  1288.         value = *vars->val.floatVal;
  1289.       }
  1290.                         else if (vars->type == ASN_OPAQUE_DOUBLE) {                     // 0x79
  1291.         value = *vars->val.doubleVal;
  1292.       }
  1293.                         else if(vars->type == ASN_INTEGER) {                                  // 0x02
  1294.                                 value = (double)*vars->val.integer;
  1295.       }
  1296.      
  1297.         }
  1298.   } else {
  1299.     /*
  1300.     * FAILURE: print what went wrong!
  1301.     */
  1302.  
  1303.     if (status == STAT_SUCCESS)
  1304.       fprintf(stderr, "Error in packet\nReason: %s\n",
  1305.       snmp_errstring(response->errstat));
  1306.     else
  1307.       snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
  1308.     return 0;
  1309.   }
  1310.   snmp_free_pdu(response);
  1311.   return value;
  1312. }
  1313.  
  1314.  
  1315. char * __stdcall snmpGetString(HSNMP m_sessp, const oid* parameter, size_t length) {
  1316.   char *value=NULL;
  1317.  
  1318.  
  1319.  
  1320.   struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_GET);    // prepare get-request pdu
  1321.  
  1322.   // for(each GET request to one crate) {
  1323.     snmp_add_null_var(pdu,parameter,length);   // generate request data
  1324.   // } // endfor
  1325.  
  1326.   struct snmp_pdu* response;
  1327.         int status = snmp_sess_synch_response(m_sessp,pdu,&response);
  1328.  
  1329.   /*
  1330.   * Process the response.
  1331.   */
  1332.   if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
  1333.     /*
  1334.     * SUCCESS: Print the result variables
  1335.     */
  1336.     struct variable_list *vars;
  1337.  
  1338.     /* manipuate the information ourselves */
  1339.     for(vars = response->variables; vars; vars = vars->next_variable) {
  1340.       //printf("type 0x%x l=%d\n", vars->type, vars->val_len );
  1341.       if(vars->type==ASN_OCTET_STR) {
  1342.         value=(char *)malloc(1+vars->val_len);
  1343.         memcpy(value,vars->val.string,vars->val_len);
  1344.         value[vars->val_len]='\0';
  1345.       }
  1346.       else if (vars->type == ASN_OPAQUE_FLOAT) {                                    // 0x78
  1347.         value=(char *)malloc(10);
  1348.         sprintf(value,"%9f",vars->val.floatVal);
  1349.       }
  1350.                         else if (vars->type == ASN_OPAQUE_DOUBLE) {                     // 0x79
  1351.         value=(char *)malloc(10);
  1352.         sprintf(value,"%9f",vars->val.doubleVal);
  1353.       }
  1354.                         else if(vars->type == ASN_INTEGER) {                                  // 0x02
  1355.                                 value=(char *)malloc(10);
  1356.         sprintf(value,"%9d",vars->val.integer);
  1357.       }
  1358.      
  1359.     }
  1360.   } else {
  1361.     /*
  1362.     * FAILURE: print what went wrong!
  1363.     */
  1364.  
  1365.     if (status == STAT_SUCCESS)
  1366.       fprintf(stderr, "Error in packet\nReason: %s\n",
  1367.       snmp_errstring(response->errstat));
  1368.     else
  1369.       snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
  1370.     return 0;
  1371.   }
  1372.   snmp_free_pdu(response);
  1373.   return  value;
  1374. }
  1375.  
  1376.  
  1377.