Skip to content

Commit

Permalink
Merge pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
zaddach committed Aug 15, 2022
2 parents be481ee + a3c008f commit 490d7d9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
13 changes: 10 additions & 3 deletions based.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 };
Expand Down
14 changes: 13 additions & 1 deletion based.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
46 changes: 42 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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' },
Expand All @@ -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 }
};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 490d7d9

Please sign in to comment.