00001 #include "common.h"
00002
00003 int main (int argc, char **argv)
00004 {
00005 njb_t njbs[NJB_MAX_DEVICES];
00006 njb_t *njb;
00007 int i, n, opt, debug;
00008 extern char *optarg;
00009 u_int8_t sdmiid[16];
00010
00011 debug = 0;
00012 while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
00013 switch (opt) {
00014 case 'D':
00015 debug= atoi(optarg);
00016 break;
00017 default:
00018 fprintf(stderr, "usage: handshake [ -D debuglvl ]\n");
00019 return 1;
00020 }
00021 }
00022
00023 if ( debug ) NJB_Set_Debug(debug);
00024
00025 if (NJB_Discover(njbs, 0, &n) == -1) {
00026 fprintf(stderr, "could not locate any jukeboxes\n");
00027 return 1;
00028 }
00029
00030 if ( n == 0 ) {
00031 fprintf(stderr, "No NJB devices found\n");
00032 return 1;
00033 }
00034
00035 printf("Found %u devices.\n", n);
00036
00037 for (i = 0; i < n; i++) {
00038 njb_keyval_t *key;
00039 int j;
00040 int chargestat;
00041 int auxpowstat;
00042 const char *devname;
00043 const char *prodname;
00044
00045 njb = &njbs[i];
00046
00047 printf("Device %u: ", i+1);
00048 printf("\n Player device type: ");
00049
00050
00051 njb = &njbs[i];
00052
00053 if (NJB_Open(njb) == -1) {
00054 NJB_Error_Dump(njb, stderr);
00055 return 1;
00056 }
00057
00058 if ((devname = NJB_Get_Device_Name(njb, 0)) != NULL) {
00059 printf("%s\n", devname);
00060 } else {
00061 printf("Error getting device name.\n");
00062 return 1;
00063 }
00064
00065
00066 NJB_Ping(njb);
00067
00068
00069 if (NJB_Get_SDMI_ID(njb, (u_int8_t *) &sdmiid) == 0) {
00070 printf(" Jukebox SDMI ID: ");
00071 for (j = 0; j < 16; j++) {
00072 printf("%02X", sdmiid[j]);
00073 }
00074 printf("\n");
00075 } else {
00076 printf(" Error getting SDMI ID.\n");
00077 }
00078
00079
00080 if (njb->device_type == NJB_DEVICE_NJB1) {
00081 u_int8_t major, minor, release;
00082
00083 if (NJB_Get_Firmware_Revision(njb, &major, &minor, &release) == 0) {
00084 printf(" Firmware: %u.%u\n", major, minor);
00085 }
00086 #ifdef __WIN32__
00087 printf(" Library counter: %I64u\n", NJB_Get_NJB1_Libcounter(njb));
00088 #else
00089 printf(" Library counter: %llu\n", NJB_Get_NJB1_Libcounter(njb));
00090 #endif
00091 }
00092 else {
00093 u_int8_t major, minor, release;
00094
00095 if (NJB_Get_Firmware_Revision(njb, &major, &minor, &release) == 0) {
00096 printf(" Firmware: %u.%u.%u\n", major, minor, release);
00097 }
00098 if (NJB_Get_Hardware_Revision(njb, &major, &minor, &release) == 0) {
00099 printf(" Hardware: %u.%u.%u\n", major, minor, release);
00100 }
00101 }
00102
00103 if ((prodname = NJB_Get_Device_Name(njb, 1)) != NULL) {
00104 printf(" Product name: %s\n", prodname);
00105 } else {
00106 printf(" Error getting product name.\n");
00107 return 1;
00108 }
00109
00110
00111 auxpowstat = NJB_Get_Auxpower(njb);
00112 if (auxpowstat == -1) {
00113 printf(" Failure getting auxilary power status\n");
00114 return 1;
00115 } else if (auxpowstat == 1) {
00116 printf(" Device is on auxiliary power (AC charger or USB)\n");
00117 } else if (auxpowstat == 0) {
00118 printf(" Device is disconnected from auxiliary power\n");
00119 }
00120
00121
00122 chargestat = NJB_Get_Battery_Charging(njb);
00123 if (chargestat == -1) {
00124 printf(" Failure getting battery charging status\n");
00125 return 1;
00126 } else if (chargestat == 1) {
00127 printf(" Battery is charging\n");
00128 } else if (chargestat == 0) {
00129 printf(" Battery is not charging\n");
00130 }
00131
00132 if (njb->device_type != NJB_DEVICE_NJB1) {
00133
00134 int battery_level = NJB_Get_Battery_Level(njb);
00135 if (battery_level == -1) {
00136 printf(" Failure getting battery level\n");
00137 return 1;
00138 } else {
00139 printf(" Battery level: %d%%\n", battery_level);
00140 }
00141 }
00142
00143 key = NJB_Get_Keys(njb);
00144 while (key != NULL) {
00145 printf(" Device key: %s = %08X, %08X\n", key->key, key->value1, key->value2);
00146 key = key->next;
00147 }
00148
00149 NJB_Close(njb);
00150
00151 }
00152
00153 return 0;
00154 }
00155