introduce get_message_by_id
This commit is contained in:
49
gdigi.c
49
gdigi.c
@@ -268,6 +268,21 @@ static gint get_message_id(GString *msg)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GString *get_message_by_id(MessageID id)
|
||||||
|
{
|
||||||
|
GString *data = NULL;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (data)
|
||||||
|
g_string_free(data, TRUE);
|
||||||
|
data = read_data();
|
||||||
|
} while (get_message_id(data) != id);
|
||||||
|
|
||||||
|
unpack_message(data);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
void append_value(GString *msg, guint value)
|
void append_value(GString *msg, guint value)
|
||||||
{
|
{
|
||||||
/* check how many bytes long the value is */
|
/* check how many bytes long the value is */
|
||||||
@@ -375,13 +390,7 @@ GStrv query_preset_names(gchar bank)
|
|||||||
send_message(REQUEST_PRESET_NAMES, &bank, 1);
|
send_message(REQUEST_PRESET_NAMES, &bank, 1);
|
||||||
|
|
||||||
/* read reply */
|
/* read reply */
|
||||||
do {
|
data = get_message_by_id(RECEIVE_PRESET_NAMES);
|
||||||
if (data)
|
|
||||||
g_string_free(data, TRUE);
|
|
||||||
data = read_data();
|
|
||||||
} while (get_message_id(data) != RECEIVE_PRESET_NAMES);
|
|
||||||
|
|
||||||
unpack_message(data);
|
|
||||||
|
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
if (data->len >= 10) {
|
if (data->len >= 10) {
|
||||||
@@ -413,11 +422,7 @@ GString *get_current_preset()
|
|||||||
send_message(REQUEST_PRESET, "\x04\x00", 3);
|
send_message(REQUEST_PRESET, "\x04\x00", 3);
|
||||||
|
|
||||||
/* read reply */
|
/* read reply */
|
||||||
data = read_data();
|
data = get_message_by_id(RECEIVE_PRESET_PARAMETERS);
|
||||||
g_string_free(data, TRUE);
|
|
||||||
|
|
||||||
data = read_data();
|
|
||||||
unpack_message(data);
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -451,15 +456,7 @@ static void request_device_configuration()
|
|||||||
|
|
||||||
send_message(REQUEST_DEVICE_CONFIGURATION, NULL, 0);
|
send_message(REQUEST_DEVICE_CONFIGURATION, NULL, 0);
|
||||||
|
|
||||||
GString *data = NULL;
|
GString *data = get_message_by_id(RECEIVE_DEVICE_CONFIGURATION);
|
||||||
|
|
||||||
do {
|
|
||||||
if (data)
|
|
||||||
g_string_free(data, TRUE);
|
|
||||||
data = read_data();
|
|
||||||
} while (get_message_id(data) != RECEIVE_DEVICE_CONFIGURATION);
|
|
||||||
|
|
||||||
unpack_message(data);
|
|
||||||
|
|
||||||
if (data->len > 14) {
|
if (data->len > 14) {
|
||||||
os_major = data->str[8];
|
os_major = data->str[8];
|
||||||
@@ -652,15 +649,7 @@ static void modifier_linkable_list()
|
|||||||
|
|
||||||
send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2);
|
send_message(REQUEST_MODIFIER_LINKABLE_LIST, "\x00\x01", 2);
|
||||||
|
|
||||||
GString *data = NULL;
|
GString *data = get_message_by_id(RECEIVE_MODIFIER_LINKABLE_LIST);
|
||||||
|
|
||||||
do {
|
|
||||||
if (data)
|
|
||||||
g_string_free(data, TRUE);
|
|
||||||
data = read_data();
|
|
||||||
} while (get_message_id(data) != RECEIVE_MOFIFIER_LINKABLE_LIST);
|
|
||||||
|
|
||||||
unpack_message(data);
|
|
||||||
|
|
||||||
unsigned char *str = (unsigned char*)data->str;
|
unsigned char *str = (unsigned char*)data->str;
|
||||||
|
|
||||||
|
|||||||
7
gdigi.h
7
gdigi.h
@@ -553,7 +553,7 @@ enum {
|
|||||||
PRESETS_EXTERNAL = 6
|
PRESETS_EXTERNAL = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
typedef enum {
|
||||||
REQUEST_WHO_AM_I = 0x01,
|
REQUEST_WHO_AM_I = 0x01,
|
||||||
RECEIVE_WHO_AM_I = 0x02,
|
RECEIVE_WHO_AM_I = 0x02,
|
||||||
|
|
||||||
@@ -584,7 +584,7 @@ enum {
|
|||||||
MOVE_PRESET = 0x39,
|
MOVE_PRESET = 0x39,
|
||||||
|
|
||||||
REQUEST_MODIFIER_LINKABLE_LIST = 0x3A,
|
REQUEST_MODIFIER_LINKABLE_LIST = 0x3A,
|
||||||
RECEIVE_MOFIFIER_LINKABLE_LIST = 0x3B,
|
RECEIVE_MODIFIER_LINKABLE_LIST = 0x3B,
|
||||||
|
|
||||||
REQUEST_PARAMETER_VALUE = 0x40,
|
REQUEST_PARAMETER_VALUE = 0x40,
|
||||||
RECEIVE_PARAMETER_VALUE = 0x41,
|
RECEIVE_PARAMETER_VALUE = 0x41,
|
||||||
@@ -605,10 +605,11 @@ enum {
|
|||||||
|
|
||||||
ACK = 0x7E,
|
ACK = 0x7E,
|
||||||
NACK = 0x7F
|
NACK = 0x7F
|
||||||
};
|
} MessageID;
|
||||||
|
|
||||||
void send_message(gint procedure, gchar *data, gint len);
|
void send_message(gint procedure, gchar *data, gint len);
|
||||||
void append_value(GString *msg, guint value);
|
void append_value(GString *msg, guint value);
|
||||||
|
GString *get_message_by_id(MessageID id);
|
||||||
void set_option(guint id, guint position, guint value);
|
void set_option(guint id, guint position, guint value);
|
||||||
void switch_preset(guint bank, guint x);
|
void switch_preset(guint bank, guint x);
|
||||||
void store_preset_name(int x, const gchar *name);
|
void store_preset_name(int x, const gchar *name);
|
||||||
|
|||||||
Reference in New Issue
Block a user