00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #include <glib.h>
00025 #include <config.h>
00026 #include <alloca.h>
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <unistd.h>
00030 #include <errno.h>
00031 #include <ctype.h>
00032 #include <string.h>
00033
00034 #include "setupLog.h"
00035 #include "system.h"
00036
00037
00038 #define MAX_ARGS 255
00039
00040
00041 static const char* get_waveform_type();
00042 static const char* get_waveform_version();
00043
00044
00045 int shell_exec(const char *cmd)
00046 {
00047 const char *p = cmd;
00048 char *buf = alloca(strlen(cmd) + 1), *bufp = buf;
00049 char *argv[MAX_ARGS + 1];
00050 int nargs = 0;
00051 int escape = 0, squote = 0, dquote = 0;
00052 int rc;
00053 int i;
00054
00055 if (cmd[0] == 0)
00056 {
00057 errno = ENOENT;
00058 return -1;
00059 }
00060
00061 while (*p)
00062 {
00063 if (escape)
00064 {
00065 *bufp++ = *p;
00066 escape = 0;
00067 }
00068 else
00069 {
00070 switch (*p)
00071 {
00072 case '\\':
00073 escape = 1;
00074 break;
00075 case '"':
00076 if (squote)
00077 *bufp++ = *p;
00078 else
00079 dquote = !dquote;
00080 break;
00081 case '\'':
00082 if (dquote)
00083 *bufp++ = *p;
00084 else
00085 squote = !squote;
00086 break;
00087 case ' ':
00088 if (!squote && !dquote)
00089 {
00090 *bufp = 0;
00091 if (nargs < MAX_ARGS)
00092 argv[nargs++] = strdup(buf);
00093 bufp = buf;
00094 break;
00095 }
00096 default:
00097 *bufp++ = *p;
00098 break;
00099 }
00100 }
00101 p++;
00102 }
00103
00104 if (bufp != buf)
00105 {
00106 *bufp = 0;
00107 if (nargs < MAX_ARGS)
00108 argv[nargs++] = strdup(buf);
00109 }
00110
00111 argv[nargs] = NULL;
00112 rc = execvp(argv[0], argv);
00113
00114 for (i = 0; i < nargs; i++)
00115 free(argv[i]);
00116
00117 return rc;
00118 }
00119
00120 #define PINCODE_LENGTH (4*2)
00121 #define PINCODE_HEX_DECORATION 2
00122
00123 #define MAC_LENGTH 12
00124 #define MAC_HEX_DECORATION 2
00125
00126 #define PROCESS_BUFFER_MAX (2*1024)
00127
00128 const char *get_sysset_macAddress(int offset)
00129 {
00130 FILE *POUT = 0;
00131 int nProcessRet = 0;
00132 char cmd[32];
00133
00134 static char mac_address[MAC_LENGTH + 6] = " - - - - - ";
00135
00136 sprintf(cmd, "sysset -r -b -a %d -l 6", offset);
00137 POUT = popen(cmd, "r");
00138 if (POUT == NULL)
00139 {
00140 ST_ERRORPRINTF("Could not read EUI64");
00141 }
00142 else
00143 {
00144 int nChar;
00145 int index = 0;
00146 char szBuffer[PROCESS_BUFFER_MAX + 1];
00147
00148 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00149 {
00150 szBuffer[index] = (char)nChar;
00151 index++;
00152 }
00153 szBuffer[index] = '\0';
00154 ST_LOGPRINTF("echoed %s", szBuffer);
00155
00156 nProcessRet = pclose(POUT);
00157 if (WIFEXITED(nProcessRet))
00158 {
00159 if (WEXITSTATUS(nProcessRet) == 0)
00160 {
00161 int nLen;
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00172 nLen = strlen(szBuffer);
00173 if (nLen != MAC_LENGTH + 2 + 1)
00174 {
00175 ST_ERRORPRINTF("Wrong length [%d] of MAC address [%s]", nLen, szBuffer);
00176 }
00177 else
00178 {
00179 char *cp1 = mac_address;
00180 char *cp2 = szBuffer + MAC_HEX_DECORATION;
00181 for (index = 0; index < MAC_LENGTH; index += 2)
00182 {
00183
00184 *cp1 = tolower(*cp2);
00185 cp1++;
00186 cp2++;
00187
00188
00189 *cp1 = tolower(*cp2);
00190 cp1++;
00191 cp2++;
00192
00193
00194 cp1++;
00195 }
00196 }
00197 }
00198 else
00199 {
00200 ST_ERRORPRINTF("pclose returned %d. Error retrieving MAC", WEXITSTATUS(nProcessRet));
00201 }
00202 }
00203 else
00204 {
00205 ST_ERRORPRINTF("pclose did not exit normally");
00206 }
00207 }
00208
00209 ST_LOGPRINTF("return [%s]", mac_address);
00210 return mac_address;
00211 }
00212
00213 const char *get_sysset_product_id(void)
00214 {
00215 return get_sysset_macAddress(262);
00216 }
00217
00218 const char *get_wireless_macAddress(void)
00219 {
00220 return get_sysset_macAddress(270);
00221 }
00222
00223 const char *get_wired_macAddress(void)
00224 {
00225 char *cp;
00226 FILE *POUT = 0;
00227 int nProcessRet = 0;
00228
00229 static char mac_address[MAC_LENGTH + 6] = " - - - - - ";
00230
00231
00232 POUT = popen("/usr/bin/wired.sh mac | tail -1", "r");
00233 if (POUT == NULL)
00234 {
00235 ST_ERRORPRINTF("Could not read wired MAC address");
00236 }
00237 else
00238 {
00239 int nChar;
00240 int index = 0;
00241 char szBuffer[PROCESS_BUFFER_MAX + 1];
00242
00243 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00244 {
00245 szBuffer[index] = (char)nChar;
00246 index++;
00247 }
00248 szBuffer[index] = '\0';
00249 ST_LOGPRINTF("echoed %s", szBuffer);
00250
00251 nProcessRet = pclose(POUT);
00252 if (WIFEXITED(nProcessRet))
00253 {
00254 if (WEXITSTATUS(nProcessRet) == 0)
00255 {
00256 int nLen;
00257
00258
00259
00260
00261
00262 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00263 nLen = strlen(szBuffer);
00264 if (nLen != MAC_LENGTH + 5 + 1)
00265 {
00266 ST_ERRORPRINTF("Wrong length [%d] of MAC address [%s]", nLen, szBuffer);
00267 }
00268 else
00269 {
00270 strncpy(mac_address, szBuffer, MAC_LENGTH + 5);
00271 for (cp = mac_address ; *cp ; cp++)
00272 {
00273 *cp = tolower(*cp);
00274 }
00275 }
00276 }
00277 else
00278 {
00279 ST_ERRORPRINTF("pclose returned %d. Error retrieving MAC", WEXITSTATUS(nProcessRet));
00280 }
00281 }
00282 else
00283 {
00284 ST_ERRORPRINTF("pclose did not exit normally");
00285 }
00286 }
00287
00288 ST_LOGPRINTF("return [%s]", mac_address);
00289 return mac_address;
00290 }
00291
00293
00294
00295
00296
00297
00298 gint sysset_read_pincode_onoff(gboolean * enable)
00299 {
00300 FILE *POUT = 0;
00301 int nProcessRet = 0;
00302 int nRet = -1;
00303
00304 if (NULL == enable)
00305 return nRet;
00306 *enable = FALSE;
00307
00308 POUT = popen("sysset -r -a 58 -l 1", "r");
00309 if (POUT == NULL)
00310 {
00311 ST_ERRORPRINTF("Could not read PINCODE on/off");
00312 }
00313 else
00314 {
00315 int nChar;
00316 int index = 0;
00317 char szBuffer[100];
00318
00319 while (((nChar = getc(POUT)) != EOF) && (index < sizeof(szBuffer) - 1))
00320 {
00321 szBuffer[index] = (char)nChar;
00322 index++;
00323 }
00324 szBuffer[index] = '\0';
00325 ST_LOGPRINTF("Read PINCODE onoff- echoed %s", szBuffer);
00326 nProcessRet = pclose(POUT);
00327 if (WIFEXITED(nProcessRet))
00328 {
00329 if (WEXITSTATUS(nProcessRet) == 0)
00330 {
00331 int nLen;
00332
00333
00334 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00335 nLen = strlen(szBuffer);
00336
00337 if (0 == nLen)
00338 {
00339 szBuffer[0] = '0';
00340 szBuffer[1] = '\n';
00341 szBuffer[2] = '\0';
00342 nLen = 2;
00343 }
00344 if (nLen != 2)
00345 {
00346 ST_ERRORPRINTF("Retrieved pincode on/off [%s] wrong length [%d]", szBuffer, nLen);
00347 }
00348 else
00349 {
00350
00351 if (szBuffer[nLen - 1] == '\n')
00352 {
00353 nLen = nLen - 1;
00354 szBuffer[nLen] = '\0';
00355 }
00356
00357 if (strcmp(szBuffer, "0") == 0)
00358 {
00359 *enable = FALSE;
00360 nRet = 0;
00361 ST_LOGPRINTF("Read PINCODE onoff: %d", *enable);
00362 }
00363 else if (strcmp(szBuffer, "1") == 0)
00364 {
00365 *enable = TRUE;
00366 nRet = 0;
00367 ST_LOGPRINTF("Read PINCODE onoff: %d", *enable);
00368 }
00369 else
00370 {
00371 ST_ERRORPRINTF("Retrieved pincode on/off has illegal value: [%s]", szBuffer);
00372 }
00373 }
00374 }
00375 else
00376 {
00377 ST_ERRORPRINTF("pclose returned %d. Error retrieving pincode on/off", WEXITSTATUS(nProcessRet));
00378 }
00379 }
00380 else
00381 {
00382 ST_ERRORPRINTF("Read PINCODE onoff- pclose did not exit normally");
00383 }
00384 }
00385
00386 ST_LOGPRINTF("Read PINCODE onoff returned %d", nRet);
00387 return nRet;
00388 }
00389
00390 gint sysset_write_pincode_onoff(gboolean enable)
00391 {
00392 char szCommand[32] = "";
00393 int nProcessRet = 0;
00394 int nRet;
00395
00396 if (TRUE == enable)
00397 strcpy(szCommand, "sysset -w -a 58 -l 1 -v 1");
00398 else
00399 strcpy(szCommand, "sysset -w -a 58 -l 1 -v 0");
00400 ST_LOGPRINTF("Calling: %s", szCommand);
00401 nProcessRet = system(szCommand);
00402 nRet = WEXITSTATUS(nProcessRet);
00403 ST_LOGPRINTF("Write PINCODE onoff returned: %d", nRet);
00404 return nRet;
00405 }
00406
00407
00408
00409
00410
00411
00412 gint sysset_read_pincode_string(gchar * pincode)
00413 {
00414 FILE *POUT = 0;
00415 int nProcessRet = 0;
00416 char string[PINCODE_MAX_LENGTH + 1] = "";
00417 int nRet = -1;
00418
00419 if (NULL == pincode)
00420 return nRet;
00421
00422 POUT = popen("sysset -r -b -a 59 -l 4", "r");
00423 if (POUT == NULL)
00424 {
00425 ST_ERRORPRINTF("Sysset could not read PINCODE");
00426 }
00427 else
00428 {
00429 int nChar;
00430 int index = 0;
00431 char szBuffer[PROCESS_BUFFER_MAX + 1];
00432
00433 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00434 {
00435 szBuffer[index] = (char)nChar;
00436 index++;
00437 }
00438 szBuffer[index] = '\0';
00439 ST_LOGPRINTF("Read PINCODE echoed %s", szBuffer);
00440 nProcessRet = pclose(POUT);
00441 if (WIFEXITED(nProcessRet))
00442 {
00443 if (WEXITSTATUS(nProcessRet) == 0)
00444 {
00445 int nLen;
00446
00447
00448
00449
00450
00451
00452
00453 ST_LOGPRINTF("Read PINCODE-pclose returned %d", WEXITSTATUS(nProcessRet));
00454 nLen = strlen(szBuffer);
00455 if (nLen != (PINCODE_HEX_DECORATION + PINCODE_LENGTH + 1))
00456 {
00457 ST_ERRORPRINTF("Wrong length [%d] of PINCODE address [%s]", nLen, szBuffer);
00458 }
00459 else
00460 {
00461 char ch[2];
00462 int len;
00463 int integer = 0;
00464
00465 if (szBuffer[nLen - 1] == '\n')
00466 {
00467 nLen = nLen - 1;
00468 szBuffer[nLen] = '\0';
00469 }
00470
00471 ch[0] = szBuffer[strlen("0x8") - 1];
00472 ch[1] = '\0';
00473 len = strtoul(ch, NULL, 16);
00474 if (len > PINCODE_MAX_LENGTH)
00475 len = PINCODE_MAX_LENGTH;
00476
00477 szBuffer[strlen("0x8") - 1] = '0';
00478
00479 integer = strtoul(szBuffer, NULL, 16);
00480
00481 sprintf(string, "%0*d", len, integer);
00482
00483 if (0 == len && 0 == integer)
00484 {
00485 strcpy(string, "0000");
00486 }
00487 strcpy(pincode, string);
00488 ST_LOGPRINTF("PINCODE read returned [%s]", pincode);
00489 nRet = 0;
00490 }
00491 }
00492 else
00493 {
00494 ST_ERRORPRINTF("pclose returned %d. Error retrieving PINCODE", WEXITSTATUS(nProcessRet));
00495 }
00496 }
00497 else
00498 {
00499 ST_ERRORPRINTF("Read PINCODE pclose did not exit normally");
00500 }
00501 }
00502 return nRet;
00503 }
00504
00505 gint sysset_write_pincode_string(const gchar * pincode)
00506 {
00507 int nLen;
00508 unsigned int n, integer = 0;
00509 char string[32];
00510
00511 char szCommand[32] = "";
00512 int nProcessRet = 0;
00513 int nRet = -1;
00514
00515 if (NULL == pincode)
00516 return nRet;
00517 nLen = strlen(pincode);
00518 if (0 == nLen || (nLen >= PINCODE_MIN_LENGTH && nLen <= PINCODE_MAX_LENGTH))
00519 {
00520 if (0 == nLen)
00521 {
00522 integer = 0;
00523 }
00524 else
00525 {
00526
00527 integer = atoi(pincode);
00528 sprintf(string, "0x%d0000000", nLen);
00529 n = strtoul(string, NULL, 16);
00530 integer += n;
00531 }
00532 sprintf(szCommand, "sysset -w -b -a 59 -l 4 -v 0x%08X", integer);
00533 ST_LOGPRINTF("Calling: %s", szCommand);
00534 nProcessRet = system(szCommand);
00535 nRet = WEXITSTATUS(nProcessRet);
00536 }
00537 else
00538 {
00539 ST_ERRORPRINTF("Write PINCODE wrong length %d", nLen);
00540 }
00541 return nRet;
00542 }
00543
00544 gboolean sysset_is_pincode_empty()
00545 {
00546 gchar pincode[PINCODE_MAX_LENGTH + 1];
00547 int nLen;
00548 gboolean empty = FALSE;
00549
00550 sysset_read_pincode_string(pincode);
00551 nLen = strlen(pincode);
00552 if (0 == nLen)
00553 empty = TRUE;
00554 return empty;
00555 }
00556
00557
00558
00559
00560
00561 const char *get_sysset_fa_model(void)
00562 {
00563 FILE *POUT = 0;
00564 int nProcessRet = 0;
00565
00566 int i;
00567 static char fa_model[33] = "";
00568
00569 POUT = popen("sysset -r -a 16 -l 32", "r");
00570 if (POUT == NULL)
00571 {
00572 ST_ERRORPRINTF("Could not read FA model-id");
00573 }
00574 else
00575 {
00576 int nChar;
00577 int index = 0;
00578 char szBuffer[PROCESS_BUFFER_MAX + 1];
00579
00580 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00581 {
00582 szBuffer[index] = (char)nChar;
00583 index++;
00584 }
00585 szBuffer[index] = '\0';
00586 ST_LOGPRINTF("echoed %s", szBuffer);
00587
00588 nProcessRet = pclose(POUT);
00589 if (WIFEXITED(nProcessRet))
00590 {
00591 if (WEXITSTATUS(nProcessRet) == 0)
00592 {
00593 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00594
00595
00596 snprintf(fa_model, sizeof(fa_model), "%s", szBuffer);
00597
00598
00599 for ( i = strlen(fa_model) - 1 ;
00600 i > 0 && fa_model[i] == ' ' ;
00601 i-- )
00602 {
00603 fa_model[i] = '\0';
00604 }
00605 }
00606 else
00607 {
00608 ST_ERRORPRINTF("pclose returned %d. Error retrieving FA model-id", WEXITSTATUS(nProcessRet));
00609 }
00610 }
00611 else
00612 {
00613 ST_ERRORPRINTF("pclose did not exit normally");
00614 }
00615 }
00616
00617 ST_LOGPRINTF("return [%s]", fa_model);
00618 return fa_model;
00619 }
00620
00621
00622 int get_sysset_fa_region(void)
00623 {
00624 FILE *POUT = 0;
00625 int nProcessRet = 0;
00626
00627 static int fa_region = 0;
00628
00629 POUT = popen("sysset -r -b -a 50 -l 2", "r");
00630 if (POUT == NULL)
00631 {
00632 ST_ERRORPRINTF("Could not read FA region-code");
00633 }
00634 else
00635 {
00636 int nChar;
00637 int index = 0;
00638 char szBuffer[PROCESS_BUFFER_MAX + 1];
00639
00640 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00641 {
00642 szBuffer[index] = (char)nChar;
00643 index++;
00644 }
00645 szBuffer[index] = '\0';
00646 ST_LOGPRINTF("echoed %s", szBuffer);
00647
00648 nProcessRet = pclose(POUT);
00649 if (WIFEXITED(nProcessRet))
00650 {
00651 if (WEXITSTATUS(nProcessRet) == 0)
00652 {
00653 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00654
00655
00656 if (szBuffer[0] == '0' && szBuffer[1] == 'x')
00657 {
00658 fa_region = atoi(szBuffer + 2);
00659 }
00660 }
00661 else
00662 {
00663 ST_ERRORPRINTF("pclose returned %d. Error retrieving FA region-code", WEXITSTATUS(nProcessRet));
00664 }
00665 }
00666 else
00667 {
00668 ST_ERRORPRINTF("pclose did not exit normally");
00669 }
00670 }
00671 return fa_region;
00672 }
00673
00674
00675 const char *get_sysset_fa_oem_code(void)
00676 {
00677 FILE *POUT = 0;
00678 int nProcessRet = 0;
00679
00680 int n;
00681 static char fa_oem_code[4] = "";
00682
00683 POUT = popen("sysset -r -a 52 -l 3", "r");
00684 if (POUT == NULL)
00685 {
00686 ST_ERRORPRINTF("Could not read FA oem-code");
00687 }
00688 else
00689 {
00690 int nChar;
00691 int index = 0;
00692 char szBuffer[PROCESS_BUFFER_MAX + 1];
00693
00694 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00695 {
00696 szBuffer[index] = (char)nChar;
00697 index++;
00698 }
00699 szBuffer[index] = '\0';
00700 ST_LOGPRINTF("echoed %s", szBuffer);
00701
00702 nProcessRet = pclose(POUT);
00703 if (WIFEXITED(nProcessRet))
00704 {
00705 if (WEXITSTATUS(nProcessRet) == 0)
00706 {
00707 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00708
00709
00710 n = strlen(szBuffer);
00711 while ( n > 0 && isspace( szBuffer[n-1] ) )
00712 {
00713 n--;
00714 szBuffer[n] = '\0';
00715 }
00716
00717
00718 if (n == 0)
00719 {
00720 snprintf(fa_oem_code, sizeof(fa_oem_code), "000");
00721 }
00722 else if (n == 3)
00723 {
00724 snprintf(fa_oem_code, sizeof(fa_oem_code), "%s", szBuffer);
00725 }
00726 else
00727 {
00728 ST_ERRORPRINTF("invalid fa_oem_code from sysset [%s]", szBuffer);
00729 }
00730 }
00731 else
00732 {
00733 ST_ERRORPRINTF("pclose returned %d. Error retrieving FA oem-code", WEXITSTATUS(nProcessRet));
00734 }
00735 }
00736 else
00737 {
00738 ST_ERRORPRINTF("pclose did not exit normally");
00739 }
00740 }
00741
00742 ST_LOGPRINTF("return [%s]", fa_oem_code);
00743 return fa_oem_code;
00744 }
00745
00746
00747 const char *get_sysset_fa_country_code(void)
00748 {
00749 FILE *POUT = 0;
00750 int nProcessRet = 0;
00751
00752 int n;
00753 static char fa_country_code[4] = "";
00754
00755 POUT = popen("sysset -r -a 55 -l 3", "r");
00756 if (POUT == NULL)
00757 {
00758 ST_ERRORPRINTF("Could not read FA country-code");
00759 }
00760 else
00761 {
00762 int nChar;
00763 int index = 0;
00764 char szBuffer[PROCESS_BUFFER_MAX + 1];
00765
00766 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00767 {
00768 szBuffer[index] = (char)nChar;
00769 index++;
00770 }
00771 szBuffer[index] = '\0';
00772 ST_LOGPRINTF("echoed %s", szBuffer);
00773
00774 nProcessRet = pclose(POUT);
00775 if (WIFEXITED(nProcessRet))
00776 {
00777 if (WEXITSTATUS(nProcessRet) == 0)
00778 {
00779 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00780
00781
00782 n = strlen(szBuffer);
00783 while ( n > 0 && isspace( szBuffer[n-1] ) )
00784 {
00785 n--;
00786 szBuffer[n] = '\0';
00787 }
00788
00789
00790 if (n == 0)
00791 {
00792 snprintf(fa_country_code, sizeof(fa_country_code), "000");
00793 }
00794 else if (n == 3)
00795 {
00796 snprintf(fa_country_code, sizeof(fa_country_code), "%s", szBuffer);
00797 }
00798 else
00799 {
00800 ST_ERRORPRINTF("invalid fa_country_code from sysset [%s]", szBuffer);
00801 }
00802 }
00803 else
00804 {
00805 ST_ERRORPRINTF("pclose returned %d. Error retrieving FA country-code", WEXITSTATUS(nProcessRet));
00806 }
00807 }
00808 else
00809 {
00810 ST_ERRORPRINTF("pclose did not exit normally");
00811 }
00812 }
00813
00814 ST_LOGPRINTF("return [%s]", fa_country_code);
00815 return fa_country_code;
00816 }
00817
00818
00819 int get_sysset_pa_board_revision(void)
00820 {
00821 FILE *POUT = 0;
00822 int nProcessRet = 0;
00823
00824 static int pa_board_revision = 0;
00825
00826 POUT = popen("sysset -r -b -a 260 -l 1", "r");
00827 if (POUT == NULL)
00828 {
00829 ST_ERRORPRINTF("Could not read PA Board-revision");
00830 }
00831 else
00832 {
00833 int nChar;
00834 int index = 0;
00835 char szBuffer[PROCESS_BUFFER_MAX + 1];
00836
00837 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00838 {
00839 szBuffer[index] = (char)nChar;
00840 index++;
00841 }
00842 szBuffer[index] = '\0';
00843 ST_LOGPRINTF("echoed %s", szBuffer);
00844
00845 nProcessRet = pclose(POUT);
00846 if (WIFEXITED(nProcessRet))
00847 {
00848 if (WEXITSTATUS(nProcessRet) == 0)
00849 {
00850 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00851
00852
00853 if (szBuffer[0] == '0' && szBuffer[1] == 'x')
00854 {
00855 pa_board_revision = atoi(szBuffer + 2);
00856 }
00857 }
00858 else
00859 {
00860 ST_ERRORPRINTF("pclose returned %d. Error retrieving PA board-revision", WEXITSTATUS(nProcessRet));
00861 }
00862 }
00863 else
00864 {
00865 ST_ERRORPRINTF("pclose did not exit normally");
00866 }
00867 }
00868 return pa_board_revision;
00869 }
00870
00871
00872 const char *get_waveform_type()
00873 {
00874 FILE *POUT = 0;
00875 int nProcessRet = 0;
00876
00877 int n;
00878 static char dm_waveform_type[7] = "";
00879
00880 POUT = popen("sysset -r -a 186 -l 6", "r");
00881 if (POUT == NULL)
00882 {
00883 ST_ERRORPRINTF("Could not read DM waveform type");
00884 }
00885 else
00886 {
00887 int nChar;
00888 int index = 0;
00889 char szBuffer[PROCESS_BUFFER_MAX + 1];
00890
00891 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00892 {
00893 szBuffer[index] = (char)nChar;
00894 index++;
00895 }
00896 szBuffer[index] = '\0';
00897 ST_LOGPRINTF("echoed %s", szBuffer);
00898
00899 nProcessRet = pclose(POUT);
00900 if (WIFEXITED(nProcessRet))
00901 {
00902 if (WEXITSTATUS(nProcessRet) == 0)
00903 {
00904 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00905
00906
00907 n = strlen(szBuffer);
00908 while ( n > 0 && isspace( szBuffer[n-1] ) )
00909 {
00910 n--;
00911 szBuffer[n] = '\0';
00912 }
00913
00914
00915 if (n == 0)
00916 {
00917 snprintf(dm_waveform_type, sizeof(dm_waveform_type), "000000");
00918 }
00919 else if (n == 6)
00920 {
00921 snprintf(dm_waveform_type, sizeof(dm_waveform_type), "%s", szBuffer);
00922 }
00923 else
00924 {
00925 ST_ERRORPRINTF("invalid DM waveform type from sysset [%s]", szBuffer);
00926 }
00927 }
00928 else
00929 {
00930 ST_ERRORPRINTF("pclose returned %d. Error retrieving DM waveform type", WEXITSTATUS(nProcessRet));
00931 }
00932 }
00933 else
00934 {
00935 ST_ERRORPRINTF("pclose did not exit normally");
00936 }
00937 }
00938
00939 ST_LOGPRINTF("return [%s]", dm_waveform_type);
00940 return dm_waveform_type;
00941 }
00942
00943
00944 const char *get_waveform_version()
00945 {
00946 FILE *POUT = 0;
00947 int nProcessRet = 0;
00948
00949 int n;
00950 static char dm_waveform_version[3] = "";
00951
00952 POUT = popen("sysset -r -a 194 -l 2", "r");
00953 if (POUT == NULL)
00954 {
00955 ST_ERRORPRINTF("Could not read DM waveform version");
00956 }
00957 else
00958 {
00959 int nChar;
00960 int index = 0;
00961 char szBuffer[PROCESS_BUFFER_MAX + 1];
00962
00963 while (((nChar = getc(POUT)) != EOF) && (index < PROCESS_BUFFER_MAX))
00964 {
00965 szBuffer[index] = (char)nChar;
00966 index++;
00967 }
00968 szBuffer[index] = '\0';
00969 ST_LOGPRINTF("echoed %s", szBuffer);
00970
00971 nProcessRet = pclose(POUT);
00972 if (WIFEXITED(nProcessRet))
00973 {
00974 if (WEXITSTATUS(nProcessRet) == 0)
00975 {
00976 ST_LOGPRINTF("pclose returned %d", WEXITSTATUS(nProcessRet));
00977
00978
00979 n = strlen(szBuffer);
00980 while ( n > 0 && isspace( szBuffer[n-1] ) )
00981 {
00982 n--;
00983 szBuffer[n] = '\0';
00984 }
00985
00986
00987 if (n == 0)
00988 {
00989 snprintf(dm_waveform_version, sizeof(dm_waveform_version), "00");
00990 }
00991 else if (n == 2)
00992 {
00993 snprintf(dm_waveform_version, sizeof(dm_waveform_version), "%s", szBuffer);
00994 }
00995 else
00996 {
00997 ST_ERRORPRINTF("invalid dm_waveform_version from sysset [%s]", szBuffer);
00998 }
00999 }
01000 else
01001 {
01002 ST_ERRORPRINTF("pclose returned %d. Error retrieving DM waveform version", WEXITSTATUS(nProcessRet));
01003 }
01004 }
01005 else
01006 {
01007 ST_ERRORPRINTF("pclose did not exit normally");
01008 }
01009 }
01010
01011 ST_LOGPRINTF("return [%s]", dm_waveform_version);
01012 return dm_waveform_version;
01013 }
01014
01015 const char *get_sysset_epd_id(void)
01016 {
01017 static char dm_epd_id[9];
01018
01019 snprintf(dm_epd_id, 9, "%s%s", get_waveform_type(), get_waveform_version());
01020 return dm_epd_id;
01021 }
01022