consolidate some O commands

This commit is contained in:
Dave Hansen 2011-03-25 15:34:24 -07:00
parent 7c91594691
commit c9d03037fb
3 changed files with 31 additions and 40 deletions

View file

@ -498,7 +498,7 @@ void fill_with_int(struct var_byte_response *arg, int fill)
{
// TODO bounds check the int
arg->len = 1;
arg->bytes[0].response = fill;
arg->bytes[0] = fill;
}
#define ENDLESS_ENABLED_BIT 0x80
@ -515,7 +515,7 @@ u8 __get_endless_percentage(void)
struct var_byte_response *rsp;
card_info_cmd(ENDLESS);
rsp = eyefi_buf;
result = rsp->bytes[0].response;
result = rsp->bytes[0];
return result;
}
@ -553,47 +553,43 @@ void print_endless(void)
printf(", triggers at %d%% full\n", percent);
}
void O_int_set(enum card_info_subcommand subcommand, int set_to)
{
struct card_config_cmd cmd;
cmd.O = 'O';
cmd.subcommand = subcommand;
fill_with_int(&cmd.arg, set_to);
write_to(REQM, &cmd, 3);
wait_for_response();
}
int o_int_get(enum card_info_subcommand subcommand)
{
struct var_byte_response *rsp;
card_info_cmd(subcommand);
rsp = eyefi_buf;
return rsp->bytes[0];
}
void wlan_disable(int do_disable)
{
/*
* This is complete voodoo to me. I've only ever seen
* a single example of this, so it's hard to figure out
* the structure at all.
*/
char new_cmd[] = {'O', 0x0a, do_disable};
write_to(REQM, &new_cmd[0], 3);
wait_for_response();
O_int_set(WLAN_ENABLED, do_disable);
}
int wlan_enabled(void)
{
struct var_byte_response *rsp;
card_info_cmd(WLAN_ENABLED);
rsp = eyefi_buf;
return rsp->bytes[0].response;
return o_int_get(WLAN_ENABLED);
}
enum transfer_mode fetch_transfer_mode(void)
{
struct var_byte_response *rsp;
card_info_cmd(TRANSFER_MODE);
rsp = eyefi_buf;
return rsp->bytes[0].response;
return o_int_get(TRANSFER_MODE);
}
void set_transfer_mode(enum transfer_mode transfer_mode)
{
/*
* I think these 'O' commands are the "set" version
* of the little 'o' commands which are "gets".
*
* I think the 0x1 here is the length of the next
* argument.
*/
char new_cmd[] = {'O', TRANSFER_MODE, 0x1, transfer_mode};
write_to(REQM, &new_cmd[0], 4);
wait_for_response();
O_int_set(TRANSFER_MODE, transfer_mode);
}
void print_transfer_status(void)

View file

@ -155,13 +155,9 @@ struct pascal_string {
u8 value[32];
} __attribute__((packed));
struct byte_response {
u8 response;
};
struct var_byte_response {
u8 len;
struct byte_response bytes[16383];
u8 bytes[EYEFI_BUF_SIZE-1];
};
/*
@ -177,6 +173,7 @@ enum card_info_subcommand {
LOG_LEN = 7,
WLAN_ENABLED = 10,
UPLOAD_PENDING= 11, // {0x1, STATE}
HOTSPOT_ENABLE= 12, // {0x1, STATE}
CONNECTED_TO = 13, // Currently connected Wifi network
UPLOAD_STATUS = 14, // current uploading file info
UNKNOWN_15 = 15, // always returns {0x01, 0x1d} as far as I've seen

View file

@ -122,10 +122,9 @@ int try_connection_to(char *essid, char *ascii_password)
char rsp = '\0';
ret = -1;
for (i=0; i < 200; i++) {
struct byte_response *r;
char *rsp_ptr = eyefi_response();
issue_noarg_command('s');
r = eyefi_response();
rsp = r->response;
rsp = *rsp_ptr;
char *state = net_test_state_name(rsp);
debug_printf(3, "net state: 0x%02x name: '%s'\n", rsp, state);
if (rsp == last_rsp) {
@ -136,7 +135,7 @@ int try_connection_to(char *essid, char *ascii_password)
eyefi_printf("\nTesting connecion to '%s' (%d): %s", essid, rsp, state);
last_rsp = rsp;
}
if (!strcmp("success", state)) {
ret = 0;
break;
@ -218,7 +217,6 @@ void handle_transfer_mode(char *arg)
void handle_endless(char *arg)
{
char *state;
if (arg) {
int percentage;
if (!strcmp(arg, "enable")) {
@ -243,9 +241,9 @@ void handle_wifi_onoff(char *arg)
{
char *state;
if (arg) {
if (!strcmp(arg, "enabled")) {
if (!strcmp(arg, "enable")) {
wlan_disable(0);
} else if (!strcmp(arg, "disabled")) {
} else if (!strcmp(arg, "disable")) {
wlan_disable(1);
} else {
printf("unknown wifi state, ignoring: '%s'\n", arg);