static int handle_ble_init_service_bas(struct ble_init_svc_req *msg, struct _ble_service_cb *p_cb) { struct ble_init_service_rsp *resp; struct _bt_gatt_ccc *ccc = bas_attrs[BLVL_CCC_HANDLE_IDX].user_data; int status; /* use CCCD value for ble service specific purpose to save ram. * notif & indication use the 2 LSBs. Allow battery updated by default */ ccc->value = BLE_SVC_BAS_NOTIF_SUP_ON; status = bt_gatt_register((struct bt_gatt_attr *)bas_attrs, ARRAY_SIZE(bas_attrs)); resp = ble_alloc_init_service_rsp(msg); if (status) resp->status = BLE_STATUS_ERROR; cfw_send_message(resp); #ifdef CONFIG_SERVICES_BLE_BAS_USE_BAT cfw_register_svc_available(_ble_cb.client, BATTERY_SERVICE_ID, &_ble_cb); #endif return 0; }
void test_scenario_init(cfw_client_t * cfw_client) { client = cfw_client; test_fw_set_handler(test_handle_message, NULL); cfw_register_svc_available(client, SOC_GPIO_SERVICE_ID, NULL); }
bool sensor_svc_open_sensor_core_svc(void *p_queue, void (*cb)(void *), void *cb_param) { #if defined(SENSOR_SERVICE) && (SENSOR_SERVICE == QRK_SENSOR_SERVICE) core_connected_cb = cb; core_connected_cb_data = cb_param; #endif p_client = cfw_client_init(p_queue, sensor_core_svc_rsp_handle, "Score_tst"); if (!p_client) return false; cfw_register_svc_available(p_client, ARC_SC_SVC_ID, NULL); return true; }
BleStatus ble_client_init(ble_client_gap_event_cb_t gap_event_cb, void *gap_event_param, ble_client_gatts_event_cb_t gatts_event_cb, void *gatts_event_param) { BleStatus status; uint32_t delay_until; cfw_platform_nordic_init(); client_handle = cfw_init(cfw_get_service_queue(), ble_core_client_handle_message, NULL); sync.response = 0; if (cfw_register_svc_available(client_handle, BLE_CORE_SERVICE_ID, NULL)) return BLE_STATUS_ERROR; /* Wait for response messages */ wait_for_condition(sync.response, status); if (status != BLE_STATUS_SUCCESS) return status; /* We need to wait for ~1 ms before continuing */ delay_until = get_uptime_32k() + TIMEOUT_TICKS_1MS; while (get_uptime_32k() < delay_until); sync.response = 0; cfw_open_service(client_handle, BLE_CORE_SERVICE_ID, NULL); /* Wait for response messages */ wait_for_condition(sync.response, status); if (status != BLE_STATUS_SUCCESS) return status; ble_client_gap_event_cb = gap_event_cb; ble_client_gap_event_param = gap_event_param; ble_client_gatts_event_cb = gatts_event_cb; ble_client_gatts_event_param = gatts_event_param; return sync.status; }
svc_client_handle_t * cproxy_connect(int service_id, void(*cb)(struct cfw_message *, void*), void *data) { svc_client_handle_t *sh = NULL; /* Allocate a service handle structure */ struct _svc_cnx *cnx = balloc(sizeof(*cnx), NULL); cnx->cb = cb; cnx->data = data; cnx->sh = NULL; cnx->src_port = 0; cnx->service_id = service_id; cfw_register_svc_available(_proxy_handle, cnx->service_id, cnx); uint32_t start = get_time_ms(); while (!(sh = cnx->sh) && (get_time_ms() < (start + 100))) { queue_process_message(_queue); } return sh; }
void cfw_open_service_helper_evt(cfw_client_t *client, uint16_t service_id, int *events, int event_count, void (*cb)(cfw_service_conn_t *, void *), void *cb_data) { _cfw_client_t *c = (_cfw_client_t *)client; struct conn_helper_data *data = (struct conn_helper_data *) balloc( sizeof(struct conn_helper_data) + event_count * sizeof(int), NULL); data->service_id = service_id; data->event_count = event_count; data->cb = cb; data->cb_data = cb_data; memcpy(data->events, events, event_count * sizeof(int)); list_add(&c->helper_list, &data->list); cfw_register_svc_available(client, service_id, data); }
void main(int argc, char** argv) { int loops = 0; void * cfw_channel; if (argc > 1) { baud_rate = baudrate_to_termios(strtol(argv[1], NULL, 0)); } else { baud_rate = baudrate_to_termios(0); /* forcing 115200 */ } /* Set the remote CPU handlers */ set_cpu_message_sender(CPU_ID_BLE, linux_ipc_send_message); set_cpu_message_sender(CPU_ID_ARC, linux_ipc_send_message); set_cpu_message_sender(CPU_ID_HOST, linux_ipc_send_message); set_cpu_free_handler(CPU_ID_BLE, linux_ipc_free); set_cpu_free_handler(CPU_ID_ARC, linux_ipc_free); set_cpu_free_handler(CPU_ID_HOST, linux_ipc_free); set_cpu_id(CPU_ID_QUARK); int uart_fd = wait_client(SOCKET_NAME, UART_PORT); printf("Client connected on %d\n", uart_fd); uart_ipc_init(uart_fd); fd_set fds; FD_ZERO(&fds); struct timeval tv; _server_cb.queue = queue_create(10, NULL); cfw_service_mgr_init(_server_cb.queue); /* We use the main task queue to support most services */ set_service_queue(_server_cb.queue); _server_cb.client = (cfw_client_t *)cfw_client_init(_server_cb.queue, srv_client_handle_msg, &_server_cb); /* get informed on new services */ cfw_register_svc_available(_server_cb.client, BLE_CORE_SERVICE_ID, &_server_cb); /* some test services */ test_service_init(_server_cb.queue, TEST_SERVICE_ID); /* ble service */ ble_cfw_service_init(_server_cb.queue); cfw_channel = ipc_uart_channel_open(0, ipc_uart_message_cback); linux_ipc_set_channel(cfw_channel); while(1) { FD_SET(uart_fd, &fds); FD_SET(0, &fds); tv.tv_sec = 1; tv.tv_usec = 0; int ret = select(uart_fd + 1, &fds, NULL, NULL, &tv); if (ret == -1) { perror("select()"); } else if (ret) { if (FD_ISSET(0, &fds)) { } else if(FD_ISSET(uart_fd, &fds)) { uart_ipc_handle_data(uart_fd); } } else { printf("."); #ifdef CONFIG_BLE_CORE_TEST test_ble_service_update_battery_level(battery_level--); if (battery_level == 10) battery_level = 100; #endif } cfw_process(_server_cb.queue); } }