libnjb: handshake.c

libnjb 2.2.7

handshake.c
#include "common.h"
int main (int argc, char **argv)
{
njb_t njbs[NJB_MAX_DEVICES];
njb_t *njb;
int i, n, opt, debug;
extern char *optarg;
u_int8_t sdmiid[16];
debug = 0;
while ( (opt= getopt(argc, argv, "D:")) != -1 ) {
switch (opt) {
case 'D':
debug= atoi(optarg);
break;
default:
fprintf(stderr, "usage: handshake [ -D debuglvl ]\n");
return 1;
}
}
if ( debug ) NJB_Set_Debug(debug);
if (NJB_Discover(njbs, 0, &n) == -1) {
fprintf(stderr, "could not locate any jukeboxes\n");
return 1;
}
if ( n == 0 ) {
fprintf(stderr, "No NJB devices found\n");
return 1;
}
printf("Found %u devices.\n", n);
for (i = 0; i < n; i++) {
njb_keyval_t *key;
int j;
int chargestat;
int auxpowstat;
const char *devname;
const char *prodname;
njb = &njbs[i];
printf("Device %u: ", i+1);
printf("\n Player device type: ");
njb = &njbs[i];
if (NJB_Open(njb) == -1) {
NJB_Error_Dump(njb, stderr);
return 1;
}
if ((devname = NJB_Get_Device_Name(njb, 0)) != NULL) {
printf("%s\n", devname);
} else {
printf("Error getting device name.\n");
return 1;
}
/* Ping the device */
NJB_Ping(njb);
/* Retrieve the device ID */
if (NJB_Get_SDMI_ID(njb, (u_int8_t *) &sdmiid) == 0) {
printf(" Jukebox SDMI ID: ");
for (j = 0; j < 16; j++) {
printf("%02X", sdmiid[j]);
}
printf("\n");
} else {
printf(" Error getting SDMI ID.\n");
}
if (njb->device_type == NJB_DEVICE_NJB1) {
u_int8_t major, minor, release;
if (NJB_Get_Firmware_Revision(njb, &major, &minor, &release) == 0) {
printf(" Firmware: %u.%u\n", major, minor);
}
#ifdef __WIN32__
printf(" Library counter: %I64u\n", NJB_Get_NJB1_Libcounter(njb));
#else
printf(" Library counter: %llu\n", NJB_Get_NJB1_Libcounter(njb));
#endif
}
else {
u_int8_t major, minor, release;
if (NJB_Get_Firmware_Revision(njb, &major, &minor, &release) == 0) {
printf(" Firmware: %u.%u.%u\n", major, minor, release);
}
if (NJB_Get_Hardware_Revision(njb, &major, &minor, &release) == 0) {
printf(" Hardware: %u.%u.%u\n", major, minor, release);
}
}
if ((prodname = NJB_Get_Device_Name(njb, 1)) != NULL) {
printf(" Product name: %s\n", prodname);
} else {
printf(" Error getting product name.\n");
return 1;
}
/* Auxiliary power status */
auxpowstat = NJB_Get_Auxpower(njb);
if (auxpowstat == -1) {
printf(" Failure getting auxilary power status\n");
return 1;
} else if (auxpowstat == 1) {
printf(" Device is on auxiliary power (AC charger or USB)\n");
} else if (auxpowstat == 0) {
printf(" Device is disconnected from auxiliary power\n");
}
/* Battery charging status */
chargestat = NJB_Get_Battery_Charging(njb);
if (chargestat == -1) {
printf(" Failure getting battery charging status\n");
return 1;
} else if (chargestat == 1) {
printf(" Battery is charging\n");
} else if (chargestat == 0) {
printf(" Battery is not charging\n");
}
if (njb->device_type != NJB_DEVICE_NJB1) {
/* This is only well implemented for the series 3 devices. */
int battery_level = NJB_Get_Battery_Level(njb);
if (battery_level == -1) {
printf(" Failure getting battery level\n");
return 1;
} else {
printf(" Battery level: %d%%\n", battery_level);
}
}
key = NJB_Get_Keys(njb);
while (key != NULL) {
printf(" Device key: %s = %08X, %08X\n", key->key, key->value1, key->value2);
key = key->next;
}
NJB_Close(njb);
}
return 0;
}
NJB_Discover
int NJB_Discover(njb_t *njbs, int limit, int *n)
Definition: procedure.c:108
NJB_Open
int NJB_Open(njb_t *njb)
Definition: procedure.c:130
NJB_Get_Auxpower
int NJB_Get_Auxpower(njb_t *njb)
Definition: procedure.c:3366
NJB_Close
void NJB_Close(njb_t *njb)
Definition: procedure.c:184
njb_keyval_struct::key
char key[5]
Definition: libnjb.h:418
NJB_Get_Battery_Level
int NJB_Get_Battery_Level(njb_t *njb)
Definition: procedure.c:3294
njb_struct
Definition: libnjb.h:182
NJB_Ping
void NJB_Ping(njb_t *njb)
Definition: procedure.c:3131
NJB_Get_SDMI_ID
int NJB_Get_SDMI_ID(njb_t *njb, u_int8_t *sdmiid)
Definition: procedure.c:3411
NJB_DEVICE_NJB1
#define NJB_DEVICE_NJB1
Definition: libnjb.h:72
NJB_Get_Battery_Charging
int NJB_Get_Battery_Charging(njb_t *njb)
Definition: procedure.c:3328
NJB_Get_Hardware_Revision
int NJB_Get_Hardware_Revision(njb_t *njb, u_int8_t *major, u_int8_t *minor, u_int8_t *release)
Definition: procedure.c:3542
NJB_Get_Device_Name
const char * NJB_Get_Device_Name(njb_t *njb, int type)
Definition: procedure.c:3456
njb_struct::device_type
int device_type
Definition: libnjb.h:189
NJB_Get_Keys
njb_keyval_t * NJB_Get_Keys(njb_t *njb)
Definition: procedure.c:3166
NJB_Get_NJB1_Libcounter
u_int64_t NJB_Get_NJB1_Libcounter(njb_t *njb)
Definition: procedure.c:3203
NJB_MAX_DEVICES
#define NJB_MAX_DEVICES
Definition: libnjb.h:60
NJB_Get_Firmware_Revision
int NJB_Get_Firmware_Revision(njb_t *njb, u_int8_t *major, u_int8_t *minor, u_int8_t *release)
Definition: procedure.c:3509
njb_keyval_struct
Definition: libnjb.h:417
njb_keyval_struct::next
njb_keyval_t * next
Definition: libnjb.h:422
njb_keyval_struct::value2
u_int32_t value2
Definition: libnjb.h:420
NJB_Set_Debug
void NJB_Set_Debug(int debug_flags)
Definition: procedure.c:2819
NJB_Error_Dump
void NJB_Error_Dump(njb_t *njb, FILE *fp)
Definition: njb_error.c:418
njb_keyval_struct::value1
u_int32_t value1
Definition: libnjb.h:419