MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / gattcOpenEvent

Function gattcOpenEvent

modules/network/ble/esp32/modBLEClient.c:960–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

958}
959
960static void gattcOpenEvent(void *the, void *refcon, uint8_t *message, uint16_t messageLength)
961{
962 struct gattc_open_evt_param *open = (struct gattc_open_evt_param *)message;
963 xsBeginHost(gBLE->the);
964 modBLEConnection connection = modBLEConnectionFindByAddress(open->remote_bda);
965 uint8_t buffer[6];
966 if (!connection)
967 xsUnknownError("connection not found");
968
969 if (ESP_GATT_OK == open->status) {
970 if (kInvalidConnectionID != connection->id) {
971 LOG_GATTC_MSG("Ignoring duplicate connect event");
972 goto bail;
973 }
974 connection->id = open->conn_id;
975
976 xsmcVars(2);
977 xsVar(0) = xsmcNewObject();
978 xsmcSetInteger(xsVar(1), open->conn_id);
979 xsmcSet(xsVar(0), xsID_connection, xsVar(1));
980 addressToBuffer(&open->remote_bda, buffer);
981 xsmcSetArrayBuffer(xsVar(1), buffer, 6);
982 xsmcSet(xsVar(0), xsID_address, xsVar(1));
983 xsmcSetInteger(xsVar(1), 0);
984 xsmcSet(xsVar(0), xsID_addressType, xsVar(1));
985 xsCall2(gBLE->obj, xsID_callback, xsStringX("onConnected"), xsVar(0));
986 }
987 else {
988#if LOG_GATTC
989 LOG_GATTC_MSG("ESP_GATTC_OPEN_EVT failed, status =");
990 LOG_GATTC_INT(open->status);
991#endif
992 if (ESP_GATT_IF_NONE != GATTC_IF(connection))
993 esp_ble_gattc_app_unregister(GATTC_IF(connection));
994 if (gAPP_ID > 1)
995 --gAPP_ID;
996 xsmcVars(2);
997 xsVar(0) = xsmcNewObject();
998 addressToBuffer(&connection->address, buffer);
999 xsmcSetArrayBuffer(xsVar(1), buffer, 6);
1000 xsmcSet(xsVar(0), xsID_address, xsVar(1));
1001 xsmcSetInteger(xsVar(1), connection->addressType);
1002 xsmcSet(xsVar(0), xsID_addressType, xsVar(1));
1003 xsCall2(connection->objConnection, xsID_callback, xsStringX("onDisconnected"), xsVar(0));
1004 xsForget(connection->objConnection);
1005 modBLEConnectionRemove(connection);
1006 }
1007bail:
1008 xsEndHost(gBLE->the);
1009}
1010
1011static void gattcCloseEvent(void *the, void *refcon, uint8_t *message, uint16_t messageLength)
1012{

Callers

nothing calls this directly

Calls 3

modBLEConnectionRemoveFunction · 0.85
addressToBufferFunction · 0.70

Tested by

no test coverage detected