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

Method generate

tools/bles2gatt.js:696–911  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

694
695class QCA4020GATTFile extends GATTFile {
696 generate() {
697 let tool = this.tool;
698 let file = this.file;
699 let services = this.services;
700 file.line('/* WARNING: This file is automatically generated. Do not edit. */');
701 file.line("");
702 file.line("typedef struct {");
703 file.line("\tuint8_t service_index;");
704 file.line("\tuint8_t att_index;");
705 file.line("\tuint8_t encrypted;");
706 file.line("\tconst char *name;");
707 file.line("\tconst char *type;");
708 file.line("} char_name_table;");
709 file.line("");
710 if (0 == services.length) {
711 file.line("#define service_count 0");
712 file.line("#define char_name_count 0");
713 file.line("#define max_attribute_count 0");
714 file.line("");
715 file.line("static qapi_BLE_GATT_Service_Attribute_Entry_t ServiceTable[0][0] = {};");
716 file.line("static const uint8_t attribute_counts[0] = {};");
717 file.line("static const char_name_table char_names[0] = {};");
718 return;
719 }
720 var attributeIndex = 0;
721 var char_names = [];
722 var maxAttributeCount = 0;
723 var attributeCounts = new Array(services.length);
724 var characteristicIndex = 0;
725 var did_cccd = 0;
726
727 services.forEach((service, index) => {
728 let attributeCount = 1;
729 let characteristics = service.characteristics;
730 attributeCount += (Object.keys(characteristics).length * 2);
731 for (let key in characteristics) {
732 let characteristic = characteristics[key];
733 if ((undefined === characteristic.permissions) && this.client)
734 characteristic.permissions = "read";
735 if ((undefined === characteristic.properties) && this.client)
736 characteristic.properties = "read";
737 let properties = characteristic.properties;
738 if (properties.includes("notify") || properties.includes("indicate")) {
739 ++attributeCount;
740 characteristic._notify = true;
741 if (!did_cccd) {
742 did_cccd = true;
743 file.line("static qapi_BLE_GATT_Characteristic_Descriptor_16_Entry_t cccd = {{0x02, 0x29}, 2, NULL};");
744 file.line("");
745 }
746 }
747 }
748 if (attributeCount > maxAttributeCount)
749 maxAttributeCount = attributeCount;
750 attributeCounts[index] = attributeCount;
751 if (4 == service.uuid.length) {
752 file.write(`static qapi_BLE_GATT_Primary_Service_16_Entry_t service${index} = {{`);
753 file.write(buffer2hexlist(uuid16toBuffer(parseInt(service.uuid, 16))));

Callers

nothing calls this directly

Calls 11

parsePropertiesMethod · 0.95
isEncryptedMethod · 0.95
parsePermissionsMethod · 0.95
buffer2hexlistFunction · 0.85
uuid16toBufferFunction · 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