Browse Source

Add the sysex_identify function

The `sysex_identify' function sends a Identity Request message to
the connected device and interprets the answer to fill a device
information structure.
master
Damien Goutte-Gattat 10 years ago
parent
commit
5e3ed2e005
  1. 44
      src/sysex.c
  2. 12
      src/sysex.h

44
src/sysex.c

@ -20,7 +20,7 @@
#include <config.h>
#endif
#include <midi.h>
#include <sysex.h>
ssize_t
sysex_read(midi_io_t *midi, unsigned char *data, size_t len)
@ -78,3 +78,45 @@ sysex_query(midi_io_t *midi,
return n;
}
int
sysex_identify(midi_io_t *midi, midi_device_id_t *devid)
{
ssize_t n;
unsigned char reply[64], *p;
unsigned char query[] = { 0xF0, /* SysEx message begin */
0x7E, /* Non-realtime message */
0x7F, /* SysEx channel (Any) */
0x06, /* General information */
0x01, /* Identity request */
0xF7 /* SysEx message end */ };
if ( (n = sysex_query(midi, query, sizeof(query),
reply, sizeof(reply))) < 0 )
return n;
if ( n != 15 && n != 17 ) /* invalid reply length */
return 0;
if ( reply[1] != 0x7E || reply[3] != 0x06 || reply[4] != 0x02 )
/* invalid reply */
return 0;
p = &reply[5];
devid->manufacturer = *p++;
if ( devid->manufacturer == 0x00 ) { /* extended manufacturer ID */
devid->manufacturer = *p++;
devid->manufacturer += *p++ << 8;
}
devid->family = *p++;
devid->family += *p++ << 8;
devid->model = *p++;
devid->model += *p++ << 8;
devid->version = *p++;
devid->version += *p++ << 8;
devid->version += *p++ << 16;
devid->version += *p++ << 24;
return 1;
}

12
src/sysex.h

@ -21,6 +21,14 @@
#include <midi.h>
typedef struct midi_device_id
{
unsigned int manufacturer;
unsigned int family;
unsigned int model;
unsigned int version;
} midi_device_id_t;
#ifdef __cpluscplus
extern "C" {
#endif
@ -31,6 +39,10 @@ sysex_read(midi_io_t *, unsigned char *, size_t);
ssize_t
sysex_query(midi_io_t *, unsigned char *, size_t, unsigned char *, size_t);
int
sysex_identify(midi_io_t *, midi_device_id_t *);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save