revise calculate_checksum

This commit is contained in:
Tomasz Moń
2009-02-25 20:19:21 +01:00
parent 84e9ab0e01
commit c0ac97d4e2
2 changed files with 22 additions and 15 deletions

14
HACKING
View File

@@ -40,13 +40,13 @@ There seems to be two possible ways to figure that out.
1st - when 4th bit is also active, and first value byte is 03
then add 80 to value
So for above example:
ID = 3009 (hex) = 12297 (decimal)
Position = 0
One of possible values is 0. Usually value range is 0 to 99,
albeit in some cases it's different - you have to check what values can
X-Edit assign (there doesn't seem to be any sanity check in firmware)
This is especially needed for IDs that set some effect type.
So for above example:
ID = 3009 (hex) = 12297 (decimal)
Position = 0
One of possible values is 0. Usually value range is 0 to 99,
albeit in some cases it's different - you have to check what values can
X-Edit assign (there doesn't seem to be any sanity check in firmware)
This is especially needed for IDs that set some effect type.
2) Save preset patch
Patches seem to be simple XML files.

23
gdigi.c
View File

@@ -62,14 +62,21 @@ char calculate_checksum(gchar *array, int length, int check)
{
int x;
char checksum;
checksum = 0;
checksum = 0x07;
for (x = 0; x<length; x++) {
if (x == check) continue;
checksum ^= array[x];
}
return checksum;
}
/*
opens MIDI device
Returns TRUE on error
*/
gboolean open_device()
{
int err;
@@ -166,7 +173,7 @@ void set_option(guint id, guint position, guint value)
option[12] = value;
option[14] = 0xF7;
option[13] = calculate_checksum(option, 15, 13) ^ 0x07;
option[13] = calculate_checksum(option, 15, 13);
send_data(option, 15);
} else if (value <= 0xFF) {
@@ -179,7 +186,7 @@ void set_option(guint id, guint position, guint value)
option[13] = (value & 0x007F);
option[15] = 0xF7;
option[14] = calculate_checksum(option, 16, 14) ^ 0x07;
option[14] = calculate_checksum(option, 16, 14);
send_data(option, 16);
} else if (value <= 0xFFFF) {
@@ -193,7 +200,7 @@ void set_option(guint id, guint position, guint value)
option[14] = ((value & 0x007F));
option[16] = 0xF7;
option[15] = calculate_checksum(option, 17, 15) ^ 0x07;
option[15] = calculate_checksum(option, 17, 15);
send_data(option, 17);
} else if (value <= 0xFFFFFF) {
@@ -208,7 +215,7 @@ void set_option(guint id, guint position, guint value)
option[15] = ((value & 0x00007F));
option[17] = 0xF7;
option[16] = calculate_checksum(option, 18, 16) ^ 0x07;
option[16] = calculate_checksum(option, 18, 16);
send_data(option, 18);
}
@@ -240,7 +247,7 @@ void switch_user_preset(int x)
static char switch_preset[] = {0x00, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x5E, 0x02, 0x39, 0x00, 0x01 /* bank = user */, 0x00 /* no */, 0x04, 0x00, 0x00, 0x01, 0x00 /* confirm */, 0xF7};
switch_preset[11] = x;
switch_preset[16] = calculate_checksum(switch_preset, sizeof(switch_preset), 16) ^ 0x07;
switch_preset[16] = calculate_checksum(switch_preset, sizeof(switch_preset), 16);
send_data(switch_preset, sizeof(switch_preset));
}
@@ -251,7 +258,7 @@ void switch_system_preset(int x)
static char switch_preset[] = {0x00, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x5E, 0x02, 0x39, 0x00, 0x00 /* bank = system */, 0x00 /* no */, 0x04, 0x00, 0x00, 0x01, 0x00 /* confirm */, 0xF7};
switch_preset[11] = x;
switch_preset[16] = calculate_checksum(switch_preset, sizeof(switch_preset), 16) ^ 0x07;
switch_preset[16] = calculate_checksum(switch_preset, sizeof(switch_preset), 16);
send_data(switch_preset, sizeof(switch_preset));
}
@@ -356,7 +363,7 @@ void set_preset_name(int x, gchar *name)
set_name[12+a+b] = 0x00;
set_name[12+a+2+b] = 0xF7;
set_name[12+a+1+b] = calculate_checksum(set_name, 12+a+3+b, 12+a+1+b) ^ 0x07;
set_name[12+a+1+b] = calculate_checksum(set_name, 12+a+3+b, 12+a+1+b);
send_data(set_name, 13+a+3+b);
}