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

Method parseAccess

tools/bles2gatt.js:608–692  ·  view source on GitHub ↗
(permissions, properties, type="characteristic")

Source from the content-addressed store, hash-verified

606 file.line("");
607 }
608 parseAccess(permissions, properties, type="characteristic") {
609 const BLE_GATT_CHR_F_BROADCAST = 0x0001;
610 const BLE_GATT_CHR_F_READ = 0x0002;
611 const BLE_GATT_CHR_F_WRITE_NO_RSP = 0x0004;
612 const BLE_GATT_CHR_F_WRITE = 0x0008;
613 const BLE_GATT_CHR_F_NOTIFY = 0x0010;
614 const BLE_GATT_CHR_F_INDICATE = 0x0020;
615 const BLE_GATT_CHR_F_AUTH_SIGN_WRITE = 0x0040;
616 const BLE_GATT_CHR_F_RELIABLE_WRITE = 0x0080;
617 const BLE_GATT_CHR_F_AUX_WRITE = 0x0100;
618 const BLE_GATT_CHR_F_READ_ENC = 0x0200;
619 const BLE_GATT_CHR_F_READ_AUTHEN = 0x0400;
620 const BLE_GATT_CHR_F_READ_AUTHOR = 0x0800;
621 const BLE_GATT_CHR_F_WRITE_ENC = 0x1000;
622 const BLE_GATT_CHR_F_WRITE_AUTHEN = 0x2000;
623 const BLE_GATT_CHR_F_WRITE_AUTHOR = 0x4000;
624
625 const BLE_GATT_DESC_F_READ = 0x01;
626 const BLE_GATT_DESC_F_WRITE = 0x02;
627 const BLE_GATT_DESC_F_READ_ENC = 0x04;
628 const BLE_GATT_DESC_F_READ_AUTHEN = 0x08;
629 const BLE_GATT_DESC_F_READ_AUTHOR = 0x10;
630 const BLE_GATT_DESC_F_WRITE_ENC = 0x20;
631 const BLE_GATT_DESC_F_WRITE_AUTHEN = 0x40;
632 const BLE_GATT_DESC_F_WRITE_AUTHOR = 0x80;
633
634 const isCharacteristic = (type == "characteristic");
635
636 let flags = 0;
637 properties.forEach(p => {
638 switch(p.trim()) {
639 case "read":
640 flags |= (isCharacteristic ? BLE_GATT_CHR_F_READ : BLE_GATT_DESC_F_READ);
641 break;
642 case "write":
643 flags |= (isCharacteristic ? BLE_GATT_CHR_F_WRITE : BLE_GATT_DESC_F_WRITE);
644 break;
645 case "writeNoResponse":
646 flags |= BLE_GATT_CHR_F_WRITE_NO_RSP;
647 break;
648 case "notify":
649 flags |= BLE_GATT_CHR_F_NOTIFY;
650 break;
651 case "indicate":
652 flags |= BLE_GATT_CHR_F_INDICATE;
653 break;
654 case "extended":
655 flags |= BLE_GATT_CHR_F_AUX_WRITE;
656 break;
657 default:
658 throw new Error("unknown property");
659 }
660 });
661 let readPerms = 0;
662 let writePerms = 0;
663 permissions.forEach(p => {
664 switch(p.trim()) {
665 case "read":

Callers 1

generateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected