diff --git a/based.c b/based.c index b36ee1b..23bf923 100644 --- a/based.c +++ b/based.c @@ -331,9 +331,7 @@ int get_device_status(socktype_t sock, char name[MAX_NAME_LEN + 1], enum PromptL *level = NC_DNE; } - static const uint8_t ack2[] = { 0x01, 0x01, 0x06, 0x00 }; - uint8_t buffer2[sizeof(ack2)]; - return read_check(sock, buffer2, sizeof(buffer2), ack2, NULL); + return status; } int set_pairing(socktype_t sock, enum Pairing pairing) { @@ -344,6 +342,15 @@ int set_pairing(socktype_t sock, enum Pairing pairing) { return write_check(sock, send_buf, sizeof(send_buf), ack, sizeof(ack)); } +int set_self_voice(socktype_t sock, enum SelfVoice selfvoice) { + static uint8_t send_buf[] = { 0x01, 0x0b, 0x02, 0x02, 0x01, ANY, 0x38 }; + static uint8_t ack[] = { 0x01, 0x0b, 0x03, 0x03, 0x01, ANY, 0x0f}; + + send_buf[5] = selfvoice; + ack[5] = selfvoice; + return write_check(sock, send_buf, sizeof(send_buf), ack, sizeof(ack)); +} + int get_firmware_version(socktype_t sock, char version[VER_STR_LEN]) { static const uint8_t send_buf[] = { 0x00, 0x05, 0x01, 0x00 }; static const uint8_t ack[] = { 0x00, 0x05, 0x03, 0x05 }; diff --git a/based.h b/based.h index 35d6aa8..00e7793 100644 --- a/based.h +++ b/based.h @@ -12,7 +12,7 @@ #define MAX_NUM_DEVICES 8 #define MAX_BT_PACK_LEN 0x1000 #define VER_STR_LEN 6 -#define VP_MASK 0x20 +#define VP_MASK 0x7F enum NoiseCancelling { NC_HIGH = 0x01, @@ -39,9 +39,13 @@ enum PromptLanguage { PL_PT = 0x27, PL_ZH = 0x28, PL_KO = 0x29, + PL_PL = 0x2B, + PL_RU = 0x2A, PL_NL = 0x2e, PL_JA = 0x2f, PL_SV = 0x32 + + }; enum Pairing { @@ -60,6 +64,13 @@ enum DevicesConnected { DC_TWO = 0x03 }; +enum SelfVoice { + SV_OFF = 0x0, + SV_HIGH = 0x1, + SV_MEDIUM = 0x2, + SV_LOW = 0x3, +}; + struct Device { bdaddr_t address; enum DeviceStatus status; @@ -79,6 +90,7 @@ int get_device_status(socktype_t sock, char name[MAX_NAME_LEN + 1], enum PromptL enum AutoOff *minutes, enum NoiseCancelling *level); int set_pairing(socktype_t sock, enum Pairing pairing); int get_firmware_version(socktype_t sock, char version[VER_STR_LEN]); +int get_firmware_version(socktype_t sock, char version[VER_STR_LEN]); int get_serial_number(socktype_t sock, char serial[0x100]); int get_battery_level(socktype_t sock, unsigned int *level); int get_device_info(socktype_t sock, bdaddr_t address, struct Device *device); diff --git a/main.c b/main.c index d117bfb..0f51c14 100644 --- a/main.c +++ b/main.c @@ -62,6 +62,9 @@ static void usage() { "\t\tRemove the device at address from the pairing list.\n" "\t--device-id\n" "\t\tPrint the device id followed by the index revision.\n" + "\t-e, --self-voice\n" + "\t\tChange the self voice level.\n" + "\t\tlevel: high, medium, low, off\n" , program_name); } @@ -98,7 +101,11 @@ static int do_set_prompt_language(socktype_t sock, const char *arg) { pl = PL_ZH; } else if (strcmp(arg, "ko") == 0) { pl = PL_KO; - } else if (strcmp(arg, "nl") == 0) { + } else if (strcmp(arg, "pl") == 0) { + pl = PL_PL; + } else if (strcmp(arg, "ru") == 0) { + pl = PL_RU; + } else if (strcmp(arg, "nl") == 0) { pl = PL_NL; } else if (strcmp(arg, "ja") == 0) { pl = PL_JA; @@ -200,7 +207,7 @@ static int do_get_device_status(socktype_t sock) { char *print; printf("Name: %s\n", name); - switch (pl | VP_MASK) { + switch (pl & VP_MASK) { case PL_EN: print = "en"; break; @@ -234,8 +241,15 @@ static int do_get_device_status(socktype_t sock) { case PL_SV: print = "sv"; break; + case PL_RU: + print = "ru"; + break; + case PL_PL: + print = "pl"; + break; default: - return 1; + print = "unknown"; + break; } printf("Language: %s\n", print); printf("Voice Prompts: %s\n", pl & VP_MASK ? "on" : "off"); @@ -284,6 +298,26 @@ static int do_set_pairing(socktype_t sock, const char *arg) { return set_pairing(sock, p); } +static int do_set_self_voice(socktype_t sock, const char *arg) { + enum SelfVoice p; + + if (strcmp(arg, "high") == 0) { + p = SV_HIGH; + } else if (strcmp(arg, "medium") == 0) { + p = SV_MEDIUM; + } else if (strcmp(arg, "low") == 0) { + p = SV_LOW; + } else if (strcmp(arg, "off") == 0) { + p = SV_OFF; + } else { + fprintf(stderr, "Invalid self voice argument: %s\n", arg); + usage(); + return 1; + } + + return set_self_voice(sock, p); +} + static int do_get_firmware_version(socktype_t sock) { char version[VER_STR_LEN]; int status = get_firmware_version(sock, version); @@ -429,7 +463,7 @@ static int do_send_packet(socktype_t sock, const char *arg) { } int main(int argc, char *argv[]) { - static const char *short_opt = "hn:l:v:o:c:dp:fsba"; + static const char *short_opt = "hn:l:v:o:c:e:dp:fsba"; static const struct option long_opt[] = { { "help", no_argument, NULL, 'h' }, { "name", required_argument, NULL, 'n' }, @@ -447,6 +481,7 @@ int main(int argc, char *argv[]) { { "disconnect-device", required_argument, NULL, 3 }, { "remove-device", required_argument, NULL, 4 }, { "device-id", no_argument, NULL, 5 }, + { "self-voice", required_argument, NULL, 'e' }, { "send-packet", required_argument, NULL, 1 }, { 0, 0, 0, 0 } }; @@ -575,6 +610,9 @@ int main(int argc, char *argv[]) { case 'a': status = do_get_paired_devices(sock); break; + case 'e': + status = do_set_self_voice(sock, optarg); + break; case 2: status = do_connect_device(sock, optarg); break;