MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / generate

Method generate

tools/bles2gatt.js:341–607  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

339
340class NimBLEGATTFile extends ESP32GATTFile {
341 generate() {
342 let tool = this.tool;
343 let file = this.file;
344 let services = this.services;
345 file.line('/* WARNING: This file is automatically generated. Do not edit. */');
346 file.line("");
347 file.line("typedef struct {");
348 file.line("\tuint8_t service_index;");
349 file.line("\tuint8_t att_index;");
350 file.line("\tconst char *name;");
351 file.line("\tconst char *type;");
352 file.line("} char_name_table;");
353 file.line("");
354 file.line("typedef struct {");
355 file.line("\tconst uint8_t *value;");
356 file.line("\tsize_t length;");
357 file.line("} static_value;");
358 file.line("");
359 if (0 == services.length) {
360 file.line("#define service_count 0");
361 file.line("#define char_name_count 0");
362 file.line("#define max_attribute_count 0");
363 file.line("");
364 file.line("static const uint8_t attribute_counts[0] = {};");
365 file.line("static const struct ble_gatt_svc_def gatt_svr_svcs[] = {};");
366 file.line("static const char_name_table char_names[0] = {};");
367 return;
368 }
369 var attributeIndex = 0;
370 var char_names = [];
371 var maxAttributeCount = 0;
372 var attributeCounts = new Array(services.length);
373 var characteristicIndex = 0;
374 var descriptorIndex = 0;
375 services.forEach((service, index) => {
376 characteristicIndex = 0;
377 attributeIndex = 0;
378 let attributeCount = 0;
379 let characteristics = service.characteristics;
380 attributeCount += (Object.keys(characteristics).length);
381 if (4 == service.uuid.length) {
382 file.write(`static const ble_uuid16_t service${index}_uuid = BLE_UUID16_INIT(`);
383 file.write(`0x${service.uuid}`);
384 file.write(");");
385
386 }
387 else {
388 file.write(`static const ble_uuid128_t service${index}_uuid = BLE_UUID128_INIT(`);
389 file.write(buffer2hexlist(uuid128toBuffer(service.uuid)));
390 file.write(");");
391 }
392 file.line("");
393 for (let key in characteristics) {
394 let characteristic = characteristics[key];
395 if ((undefined === characteristic.permissions) && this.client)
396 characteristic.permissions = "read";
397 if ((undefined === characteristic.properties) && this.client)
398 characteristic.properties = "read";

Callers

nothing calls this directly

Calls 8

parseAccessMethod · 0.95
buffer2hexlistFunction · 0.85
uuid128toBufferFunction · 0.85
keysMethod · 0.80
typedValueToBufferFunction · 0.70
writeMethod · 0.65
lineMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected