]> sigrok.org Git - libsigrok.git/commitdiff
serial_bt: support the dialog DA14580 chip (seen in TC66C)
authorGerhard Sittig <redacted>
Sun, 19 Mar 2023 18:15:26 +0000 (19:15 +0100)
committerGerhard Sittig <redacted>
Sun, 19 Mar 2023 21:40:08 +0000 (22:40 +0100)
Add support for dialog DA14580 chips, accept conn=bt/dialog/$MAC specs.
These BLE chips were seen in RDTech TC66C energy meters. They appear to
send notifications without the necessity to write CCCD values.

It's yet to get determined whether it's the chip or the device firmware
which requires MTU exchange. The default value in the 400 range (near
the absolute maximum MTU for BLE communication) is rather arbitrary a
choice, needs reconsideration in the future. Users always can override
as desired.

src/libsigrok-internal.h
src/serial_bt.c

index 8147fe57427183f42c94e393cd905743f810347b..6cf1f8de4dd1c59d7378470968b43b0824133c34 100644 (file)
@@ -1621,6 +1621,7 @@ struct sr_serial_dev_inst {
                SER_BT_CONN_NRF51,      /**!< BLE, Nordic nRF51, notifications */
                SER_BT_CONN_CC254x,     /**!< BLE, TI CC254x, notifications */
                SER_BT_CONN_AC6328,     /**!< BLE, JL AC6328B, notifications */
+               SER_BT_CONN_DIALOG,     /**!< BLE, dialog DA14580, notifications */
                SER_BT_CONN_NOTIFY,     /**!< BLE, generic notifications */
                SER_BT_CONN_MAX,        /**!< sentinel */
        } bt_conn_type;
index 4dad01ff8f9410afb9dcd6921f3aa69e654bfd8f..ee46e90d0fe1281c059e71866909baabbec42fb3 100644 (file)
@@ -114,6 +114,7 @@ static const char *ser_bt_conn_names[SER_BT_CONN_MAX] = {
        [SER_BT_CONN_NRF51] = "nrf51",
        [SER_BT_CONN_CC254x] = "cc254x",
        [SER_BT_CONN_AC6328] = "ac6328",
+       [SER_BT_CONN_DIALOG] = "dialog",
        [SER_BT_CONN_NOTIFY] = "notify",
 };
 
@@ -306,6 +307,18 @@ static int ser_bt_parse_conn_spec(
                if (cccd_val)
                        *cccd_val = 0x0001;
                break;
+       case SER_BT_CONN_DIALOG:
+               if (read_hdl)
+                       *read_hdl = 23;
+               if (write_hdl)
+                       *write_hdl = 18;
+               if (cccd_hdl)
+                       *cccd_hdl = 0;
+               if (cccd_val)
+                       *cccd_val = 0x0001;
+               if (ble_mtu)
+                       *ble_mtu = 400;
+               break;
        case SER_BT_CONN_NOTIFY:
                /* All other values must be provided externally. */
                if (cccd_val)
@@ -514,6 +527,7 @@ static int ser_bt_open(struct sr_serial_dev_inst *serial, int flags)
        case SER_BT_CONN_NRF51:
        case SER_BT_CONN_CC254x:
        case SER_BT_CONN_AC6328:
+       case SER_BT_CONN_DIALOG:
        case SER_BT_CONN_NOTIFY:
                rc = sr_bt_config_notify(desc,
                        read_hdl, write_hdl, cccd_hdl, cccd_val,
@@ -550,6 +564,7 @@ static int ser_bt_open(struct sr_serial_dev_inst *serial, int flags)
        case SER_BT_CONN_NRF51:
        case SER_BT_CONN_CC254x:
        case SER_BT_CONN_AC6328:
+       case SER_BT_CONN_DIALOG:
        case SER_BT_CONN_NOTIFY:
                rc = sr_bt_connect_ble(desc);
                if (rc < 0)
@@ -628,6 +643,7 @@ static int ser_bt_write(struct sr_serial_dev_inst *serial,
        case SER_BT_CONN_NRF51:
        case SER_BT_CONN_CC254x:
        case SER_BT_CONN_AC6328:
+       case SER_BT_CONN_DIALOG:
        case SER_BT_CONN_NOTIFY:
                /*
                 * Assume that when applications call the serial layer's
@@ -695,6 +711,7 @@ static int ser_bt_read(struct sr_serial_dev_inst *serial,
                case SER_BT_CONN_NRF51:
                case SER_BT_CONN_CC254x:
                case SER_BT_CONN_AC6328:
+               case SER_BT_CONN_DIALOG:
                case SER_BT_CONN_NOTIFY:
                        dlen = sr_ser_has_queued_data(serial);
                        rc = sr_bt_check_notify(serial->bt_desc);
@@ -794,6 +811,7 @@ static int bt_source_cb(int fd, int revents, void *cb_data)
                case SER_BT_CONN_NRF51:
                case SER_BT_CONN_CC254x:
                case SER_BT_CONN_AC6328:
+               case SER_BT_CONN_DIALOG:
                case SER_BT_CONN_NOTIFY:
                        dlen = sr_ser_has_queued_data(serial);
                        rc = sr_bt_check_notify(serial->bt_desc);