demo_hwm.c
Go to the documentation of this file.
00001 /****************************************************************************
00002 * Copyright (c) Advantech Co., Ltd. All Rights Reserved
00003 *
00004 * File Name:
00005 *       demo_hwm.c
00006 *
00007 * Programmers:
00008 *       Neo Lo
00009 *
00010 ****************************************************************************/
00011 
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 
00015 #include "REL_Linux_SUSI.H"
00016 
00017 // Return 0 if platform infomation is correctly obtained.
00018 // Otherwise, return 1.
00019 int show_platform_info(void)
00020 {
00021         int result;
00022         DWORD major, minor, year, month, date;
00023         const int BUF_LENGTH = 128;
00024         TCHAR buf[BUF_LENGTH];  // Buffer length includes the null character.
00025 
00026         SusiDllGetVersion(&major, &minor);
00027     year    = minor/10000;
00028     month   = minor%10000/100;
00029     date    = minor%100;
00030         printf("Version: %li (20%02li/%02li/%02li)\n", major, year, month, date);
00031 
00032 
00033         // Get platform name.
00034         result = SusiGetPlatformName(buf, BUF_LENGTH);
00035         if (result < 0) {
00036                 printf("SusiGetPlatformName() failed\n");
00037                 return 1;
00038         }
00039         else if (result > 0) {
00040                 printf("SusiGetPlatformName(): buffer is too short\n");
00041                 return 1;
00042         }
00043         else
00044                 printf("Platform name: %s\n", buf);
00045 
00046         // Get BIOS version.
00047         result = SusiGetBIOSVersion(buf, BUF_LENGTH);
00048         if (result < 0) {
00049                 return 1;
00050         }
00051         else if (result > 0) {
00052                 printf("SusiGetBIOSVersion(): buffer is too short\n");
00053                 return 1;
00054         }
00055         else
00056                 printf("BIOS version: %s\n", buf);
00057 
00058         return 0;
00059 }
00060 
00061 void show_menu(void)
00062 {
00063         printf("\n");
00064         printf("0) Terminate this program\n");
00065         printf("1) Get Voltage\n");
00066         printf("2) Get Temperature\n");
00067         printf("3) Get Fan Speed\n");
00068         printf("4) Set Fan Speed\n");
00069         printf("Enter your choice: ");
00070 }
00071 
00072 int get_voltage(void)
00073 {
00074         BOOL result;
00075         DWORD voltType, typeSupport;
00076     float retval = 0;
00077 
00078         printf("Get Voltage\n");
00079 
00080     voltType = typeSupport = 0;
00081         result = SusiHWMGetVoltage(voltType, &retval, &typeSupport);
00082         if (result == FALSE) {
00083                 printf("SusiHWMGetVoltage() failed\n");
00084                 return 1;
00085         }
00086         else
00087                 printf("typeSupport: 0x%08lX\n", typeSupport);
00088 
00089     if ( typeSupport )
00090     {
00091         if ( VCORE & typeSupport )
00092         {
00093                 result = SusiHWMGetVoltage(VCORE, &retval, NULL);
00094                 if (result == FALSE) {
00095                         printf("SusiHWMGetVoltage() failed\n");
00096                         return 1;
00097                 }
00098                 else
00099                         printf("VCORE: %f\n", retval);
00100         }
00101 
00102         if ( V25 & typeSupport )
00103         {
00104                 result = SusiHWMGetVoltage(V25, &retval, NULL);
00105                 if (result == FALSE) {
00106                         printf("SusiHWMGetVoltage() failed\n");
00107                         return 1;
00108                 }
00109                 else
00110                         printf("V25: %f\n", retval);
00111         }
00112 
00113         if ( V33 & typeSupport )
00114         {
00115                 result = SusiHWMGetVoltage(V33, &retval, NULL);
00116                 if (result == FALSE) {
00117                         printf("SusiHWMGetVoltage() failed\n");
00118                         return 1;
00119                 }
00120                 else
00121                         printf("V33: %f\n", retval);
00122         }
00123 
00124         if ( V50 & typeSupport )
00125         {
00126                 result = SusiHWMGetVoltage(V50, &retval, NULL);
00127                 if (result == FALSE) {
00128                         printf("SusiHWMGetVoltage() failed\n");
00129                         return 1;
00130                 }
00131                 else
00132                         printf("V50: %f\n", retval);
00133         }
00134 
00135         if ( V120 & typeSupport )
00136         {
00137                 result = SusiHWMGetVoltage(V120, &retval, NULL);
00138                 if (result == FALSE) {
00139                         printf("SusiHWMGetVoltage() failed\n");
00140                         return 1;
00141                 }
00142                 else
00143                         printf("V120: %f\n", retval);
00144         }
00145 
00146         if ( V5SB & typeSupport )
00147         {
00148                 result = SusiHWMGetVoltage(V5SB, &retval, NULL);
00149                 if (result == FALSE) {
00150                         printf("SusiHWMGetVoltage() failed\n");
00151                         return 1;
00152                 }
00153                 else
00154                         printf("V5SB: %f\n", retval);
00155         }
00156 
00157         if ( V3SB & typeSupport )
00158         {
00159                 result = SusiHWMGetVoltage(V3SB, &retval, NULL);
00160                 if (result == FALSE) {
00161                         printf("SusiHWMGetVoltage() failed\n");
00162                         return 1;
00163                 }
00164                 else
00165                         printf("V3SB: %f\n", retval);
00166         }
00167 
00168 
00169         if ( VBAT & typeSupport )
00170         {
00171                 result = SusiHWMGetVoltage(VBAT, &retval, NULL);
00172                 if (result == FALSE) {
00173                         printf("SusiHWMGetVoltage() failed\n");
00174                         return 1;
00175                 }
00176                 else
00177                         printf("VBAT: %f\n", retval);
00178         }
00179 
00180         if ( VN50 & typeSupport )
00181         {
00182                 result = SusiHWMGetVoltage(VN50, &retval, NULL);
00183                 if (result == FALSE) {
00184                         printf("SusiHWMGetVoltage() failed\n");
00185                         return 1;
00186                 }
00187                 else
00188                         printf("VN50: %f\n", retval);
00189         }
00190 
00191         if ( VN120 & typeSupport )
00192         {
00193                 result = SusiHWMGetVoltage(VN120, &retval, NULL);
00194                 if (result == FALSE) {
00195                         printf("SusiHWMGetVoltage() failed\n");
00196                         return 1;
00197                 }
00198                 else
00199                         printf("VN120: %f\n", retval);
00200         }
00201 
00202         if ( VTT & typeSupport )
00203         {
00204                 result = SusiHWMGetVoltage(VTT, &retval, NULL);
00205                 if (result == FALSE) {
00206                         printf("SusiHWMGetVoltage() failed\n");
00207                         return 1;
00208                 }
00209                 else
00210                         printf("VTT: %f\n", retval);
00211         }
00212 
00213         if ( VCORE2 & typeSupport )
00214         {
00215                 result = SusiHWMGetVoltage(VCORE2, &retval, NULL);
00216                 if (result == FALSE) {
00217                         printf("SusiHWMGetVoltage() failed\n");
00218                         return 1;
00219                 }
00220                 else
00221                         printf("VCORE2: %f\n", retval);
00222         }
00223 
00224         if ( V105 & typeSupport )
00225         {
00226                 result = SusiHWMGetVoltage(V105, &retval, NULL);
00227                 if (result == FALSE) {
00228                         printf("SusiHWMGetVoltage() failed\n");
00229                         return 1;
00230                 }
00231                 else
00232                         printf("V105: %f\n", retval);
00233         }
00234 
00235         if ( V15 & typeSupport )
00236         {
00237                 result = SusiHWMGetVoltage(V15, &retval, NULL);
00238                 if (result == FALSE) {
00239                         printf("SusiHWMGetVoltage() failed\n");
00240                         return 1;
00241                 }
00242                 else
00243                         printf("V15: %f\n", retval);
00244         }
00245 
00246         if ( V18 & typeSupport )
00247         {
00248                 result = SusiHWMGetVoltage(V18, &retval, NULL);
00249                 if (result == FALSE) {
00250                         printf("SusiHWMGetVoltage() failed\n");
00251                         return 1;
00252                 }
00253                 else
00254                         printf("V18: %f\n", retval);
00255         }
00256 
00257    }
00258     
00259         return 0;
00260 }
00261 
00262 int get_temperature(void)
00263 {
00264         BOOL result;
00265         WORD voltType, typeSupport;
00266     float retval = 0;
00267 
00268         printf("Get Temperature\n");
00269 
00270     voltType = typeSupport = 0;
00271         result = SusiHWMGetTemperature(voltType, &retval, &typeSupport);
00272         if (result == FALSE) {
00273                 printf("SusiHWMGetTemperature() failed\n");
00274                 return 1;
00275         }
00276         else
00277                 printf("typeSupport: 0x%08X\n", typeSupport);
00278 
00279     if ( typeSupport )
00280     {
00281         if ( TCPU & typeSupport )
00282         {
00283                 result = SusiHWMGetTemperature(TCPU, &retval, NULL);
00284                 if (result == FALSE) {
00285                         printf("SusiHWMGetTemperature() failed\n");
00286                         return 1;
00287                 }
00288                 else
00289                         printf("TCPU: %f\n", retval);
00290         }
00291         
00292         if ( TSYS & typeSupport )
00293         {
00294                 result = SusiHWMGetTemperature(TSYS, &retval, NULL);
00295                 if (result == FALSE) {
00296                         printf("SusiHWMGetTemperature() failed\n");
00297                         return 1;
00298                 }
00299                 else
00300                         printf("TSYS: %f\n", retval);
00301         }
00302         
00303         if ( TAUX & typeSupport )
00304         {
00305                 result = SusiHWMGetTemperature(TAUX, &retval, NULL);
00306                 if (result == FALSE) {
00307                         printf("SusiHWMGetTemperature() failed\n");
00308                         return 1;
00309                 }
00310                 else
00311                         printf("TAUX: %f\n", retval);
00312         }
00313     }
00314         return 0;
00315 }
00316 
00317 int get_fan_speed(void)
00318 {
00319         BOOL result;
00320     WORD typeSupport, voltType, retval;
00321 
00322         printf("Get Fan Speed\n");
00323 
00324     typeSupport = voltType = retval = 0;
00325         result = SusiHWMGetFanSpeed(voltType, &retval, &typeSupport);
00326         if (result == FALSE) {
00327                 printf("SusiHWMGetFanSpeed() failed\n");
00328                 return 1;
00329         }
00330         else
00331                 printf("typeSupport: 0x%08X\n", typeSupport);
00332 
00333     if ( typeSupport )
00334     {
00335         if ( FCPU & typeSupport )
00336         {
00337                 result = SusiHWMGetFanSpeed(FCPU, &retval, NULL);
00338                 if (result == FALSE) {
00339                         printf("SusiHWMGetFanSpeed() failed\n");
00340                         return 1;
00341                 }
00342                 else
00343                         printf("FCPU: %d\n", retval);
00344         }
00345         
00346         if ( FSYS & typeSupport )
00347         {
00348                 result = SusiHWMGetFanSpeed(FSYS, &retval, NULL);
00349                 if (result == FALSE) {
00350                         printf("SusiHWMGetFanSpeed() failed\n");
00351                         return 1;
00352                 }
00353                 else
00354                         printf("FSYS: %d\n", retval);
00355         }
00356         
00357         if ( F2ND & typeSupport )
00358         {
00359                 result = SusiHWMGetFanSpeed(F2ND, &retval, NULL);
00360                 if (result == FALSE) {
00361                         printf("SusiHWMGetFanSpeed() failed\n");
00362                         return 1;
00363                 }
00364                 else
00365                         printf("F2ND: %d\n", retval);
00366         }
00367         
00368         if ( FCPU2 & typeSupport )
00369         {
00370                 result = SusiHWMGetFanSpeed(FCPU2, &retval, NULL);
00371                 if (result == FALSE) {
00372                         printf("SusiHWMGetFanSpeed() failed\n");
00373                         return 1;
00374                 }
00375                 else
00376                         printf("FCPU2: %d\n", retval);
00377         }
00378     }
00379         return 0;
00380 }
00381 
00382 int set_fan_speed(void)
00383 {
00384         BOOL result;
00385     WORD typeSupport, voltType, retval;
00386 
00387         printf("Set Fan Speed\n");
00388 
00389     typeSupport = voltType = retval = 0;
00390         result = SusiHWMGetFanSpeed(voltType, &retval, &typeSupport);
00391         if (result == FALSE) {
00392                 printf("SusiHWMGetFanSpeed() failed\n");
00393                 return 1;
00394         }
00395         else
00396                 printf("typeSupport: 0x%08X\n", typeSupport);
00397 
00398     if ( typeSupport )
00399     {
00400         if ( FCPU & typeSupport )
00401         {
00402                 result = SusiHWMGetFanSpeed(FCPU, &retval, NULL);
00403                 if (result == FALSE) {
00404                         printf("SusiHWMGetFanSpeed() failed\n");
00405                         return 1;
00406                 }
00407                 else
00408                         printf("FCPU: %d\n", retval);
00409             
00410             printf("Please enter the new FanSpeed: \n");
00411                         if (scanf("%hi", &retval) <= 0)
00412                                 return 1;
00413                         
00414                 result = SusiHWMSetFanSpeed(FCPU, retval, NULL);
00415                 if (result == FALSE) {
00416                         printf("SusiHWMSetFanSpeed() failed\n");
00417                         return 1;
00418                 }
00419                 else
00420                         printf("Set FanSpeed OK!\n");
00421         }
00422         
00423         if ( FSYS & typeSupport )
00424         {
00425                 result = SusiHWMGetFanSpeed(FSYS, &retval, NULL);
00426                 if (result == FALSE) {
00427                         printf("SusiHWMGetFanSpeed() failed\n");
00428                         return 1;
00429                 }
00430                 else
00431                         printf("FSYS: %d\n", retval);
00432             
00433             printf("Please enter the new FanSpeed: \n");
00434                         if (scanf("%hi", &retval) <= 0)
00435                                 return 1;
00436 
00437                 result = SusiHWMSetFanSpeed(FSYS, retval, NULL);
00438                 if (result == FALSE) {
00439                         printf("SusiHWMSetFanSpeed() failed\n");
00440                         return 1;
00441                 }
00442                 else
00443                         printf("Set FanSpeed OK!\n");
00444         }
00445         
00446         if ( F2ND & typeSupport )
00447         {
00448                 result = SusiHWMGetFanSpeed(F2ND, &retval, NULL);
00449                 if (result == FALSE) {
00450                         printf("SusiHWMGetFanSpeed() failed\n");
00451                         return 1;
00452                 }
00453                 else
00454                         printf("F2ND: %d\n", retval);
00455             
00456             printf("Please enter the new FanSpeed: \n");
00457                         if (scanf("%hi", &retval) <= 0)
00458                                 return 1;
00459 
00460                 result = SusiHWMSetFanSpeed(F2ND, retval, NULL);
00461                 if (result == FALSE) {
00462                         printf("SusiHWMSetFanSpeed() failed\n");
00463                         return 1;
00464                 }
00465                 else
00466                         printf("Set FanSpeed OK!\n");
00467         }
00468     }
00469         return 0;
00470 }
00471 
00472 
00473 int main(void)
00474 {
00475         int result, done, op;
00476 
00477         result = SusiDllInit();
00478         if (result == FALSE) {
00479                 printf("SusiDllInit() failed\n");
00480                 return 1;
00481         }
00482 
00483         result = SusiHWMAvailable();
00484         if (result == FALSE) {
00485                 printf("SusiHWMAvailable() failed\n");
00486                 SusiDllUnInit();
00487                 return 1;
00488         }
00489 
00490         result = show_platform_info();
00491         
00492         done = 0;
00493         while (! done) {
00494                 show_menu();
00495                 if (scanf("%i", &op) <= 0)
00496                         op = -1;
00497 
00498                 switch (op) {
00499                 case 0:
00500                         done = 1;
00501                         continue;
00502                 case 1:
00503                         result = get_voltage();
00504                         break;
00505                 case 2:
00506                         result = get_temperature();
00507                         break;
00508                 case 3:
00509                         result = get_fan_speed();
00510                         break;
00511                 case 4:
00512                         result = set_fan_speed();
00513                         break;
00514                 default:
00515                         printf("\nUnknown choice!\n\n");
00516                         continue;
00517                 }
00518                 if (result != 0) {
00519                         printf("Library returns with error.\n");
00520                         SusiDllUnInit();
00521                         return 1;
00522                 }
00523         }
00524 
00525         result = SusiDllUnInit();
00526         if (result == FALSE) {
00527                 printf("SusiDllUnInit() failed\n");
00528                 return 1;
00529         }
00530 
00531         return 0;
00532 }
00533 


advantech
Author(s):
autogenerated on Fri Feb 7 2014 11:36:51