67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
#include <stdint.h>
|
|
|
|
#include "host/ble_att.h"
|
|
#include "host/ble_gatt.h"
|
|
#include "os/os_mbuf.h"
|
|
#include "esp_log.h"
|
|
|
|
#include "gatt_svcs.h"
|
|
#include "BLE_UUID.h"
|
|
|
|
static struct char_pres_format current_char_pres_format = {
|
|
.format = FORMAT_UINT32,
|
|
.exponent = -3,
|
|
.unit = AMPERE_UNIT_UUID,
|
|
.namespc = 1,
|
|
.descrH = NSP_DESC_MAIN & 0xff,
|
|
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
|
};
|
|
|
|
static struct char_pres_format raw_voltage_char_pres_format = {
|
|
.format = FORMAT_UINT32,
|
|
.exponent = -3,
|
|
.unit = VOLTS_UNIT_UUID,
|
|
.namespc = 1,
|
|
.descrH = NSP_DESC_MAIN & 0xff,
|
|
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
|
};
|
|
|
|
int gatt_char_access_cs(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg){
|
|
int rc = 0;
|
|
|
|
switch(ctxt->op){
|
|
case BLE_GATT_ACCESS_OP_READ_CHR:
|
|
;
|
|
uint32_t data = 12;
|
|
rc = os_mbuf_append(ctxt->om, &data, sizeof(data));
|
|
break;
|
|
case BLE_GATT_ACCESS_OP_READ_DSC:
|
|
ESP_LOGI("CHAR ACCESS", "char pres size %d", sizeof(current_char_pres_format));
|
|
rc = os_mbuf_append(ctxt->om, ¤t_char_pres_format, CHAR_PRESENTATION_FORMAT_SIZE);
|
|
break;
|
|
}
|
|
|
|
return rc ? BLE_ATT_ERR_INSUFFICIENT_RES : 0;
|
|
}
|
|
|
|
int gatt_char_access_ev(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg){
|
|
int rc = 0;
|
|
|
|
switch(ctxt->op){
|
|
case BLE_GATT_ACCESS_OP_READ_CHR:
|
|
;
|
|
uint16_t* handles = arg;
|
|
|
|
int id = -1;
|
|
for(int i = 0; i < EV_CHRS_NUM; i++) if(handles[i] == attr_handle) id = i;
|
|
uint32_t data = id;
|
|
rc = os_mbuf_append(ctxt->om, &data, sizeof(data));
|
|
break;
|
|
case BLE_GATT_ACCESS_OP_READ_DSC:
|
|
rc = os_mbuf_append(ctxt->om, &raw_voltage_char_pres_format, CHAR_PRESENTATION_FORMAT_SIZE);
|
|
break;
|
|
}
|
|
|
|
return rc ? BLE_ATT_ERR_INSUFFICIENT_RES : 0;
|
|
}
|