Page 1 of 1

Cod - Classic Bluetooth

Posted: Sat Mar 26, 2022 2:20 pm
by KHOAPHAM
Dear,
I have a query. What does ":" mean? And how can I assign value for each member of struct? I'm trying to set class of device for my Classic Bluetooth Application. But I'm stucked here. Can anyone help me. Thanks in advance.

Code: Select all

typedef struct {
    uint32_t      reserved_2: 2;                    /*!< undefined */
    uint32_t      minor: 6;                         /*!< minor class */
    uint32_t      major: 5;                         /*!< major class */
    uint32_t      service: 11;                      /*!< service class */
    uint32_t      reserved_8: 8;                    /*!< undefined */
} esp_bt_cod_t;

Re: Cod - Classic Bluetooth

Posted: Sun Mar 27, 2022 12:57 am
by ESP_Sprite
https://www.tutorialspoint.com/cprogram ... fields.htm

You can use them as if they were a regular member of a struct.

Re: Cod - Classic Bluetooth

Posted: Sun Mar 27, 2022 9:53 am
by KHOAPHAM
Thank you, but I could not set minor and major. The code is below. Is it correct?

Code: Select all

esp_bt_cod_t cod;
        cod.reserved_2 = 0;
		cod.minor = 0b00001;
		cod.major = 0b00010;
		cod.reserved_8 = 0;
		cod.service = 0;
        ret = esp_bt_gap_set_cod(cod,ESP_BT_INIT_COD);

Re: Cod - Classic Bluetooth

Posted: Mon Mar 28, 2022 1:05 am
by ESP_Sprite
That should work on the struct side of things, but I'm not sure if Xtensa-GCC (or any other GCC aside from the AVR one, for that matter) understands binary numbers. Suggest you try e.g. 0x2 instead of 0b00010.

Re: Cod - Classic Bluetooth

Posted: Mon Mar 28, 2022 3:08 am
by KHOAPHAM
It doesn't work..

Re: Cod - Classic Bluetooth

Posted: Mon Mar 28, 2022 3:21 am
by KHOAPHAM
I solved it. I put the code before setting device name and gap scan mode. It worked now. Thanks alot for your help.