async def add_new_characteristic(self, service_uuid: str, char_uuid: str, properties: GattCharacteristicsFlags, value: Optional[bytearray], permissions: int): """ Generate a new characteristic to be associated with the server Parameters ---------- service_uuid : str The string representation of the uuid of the service to associate the new characteristic with char_uuid : str The string representation of the uuid of the new characteristic properties : GattCharacteristicsFlags The flags for the characteristic value : Optional[bytearray] The initial value for the characteristic permissions : int The permissions for the characteristic """ charguid: Guid = Guid.Parse(char_uuid) serverguid: Guid = Guid.Parse(service_uuid) ReadParameters: GattLocalCharacteristicParameters = ( GattLocalCharacteristicParameters() ) ReadParameters.CharacteristicProperties = properties ReadParameters.ReadProtectionLevel = permissions characteristic_result: GattLocalCharacteristicResult = ( await wrap_IAsyncOperation( IAsyncOperation[GattLocalCharacteristicResult]( self.services.get(str(serverguid), None) .obj.CreateCharacteristicAsync( charguid, ReadParameters) ), return_type=GattLocalCharacteristicResult) ) newChar: GattLocalCharacteristic = characteristic_result.Characteristic newChar.ReadRequested += self.read_characteristic newChar.WriteRequested += self.write_characteristic newChar.SubscribedClientsChanged += self.subscribe_characteristic bleak_characteristic: BlessGATTCharacteristicDotNet = ( BlessGATTCharacteristicDotNet(obj=newChar) ) service: BleakGATTServiceDotNet = self.services.get(str(serverguid)) service.add_characteristic(bleak_characteristic)
async def add_new_characteristic( self, service_uuid: str, char_uuid: str, properties: GATTCharacteristicProperties, value: Optional[bytearray], permissions: GATTAttributePermissions, ): """ Generate a new characteristic to be associated with the server Parameters ---------- service_uuid : str The string representation of the uuid of the service to associate the new characteristic with char_uuid : str The string representation of the uuid of the new characteristic properties : GATTCharacteristicProperties The flags for the characteristic value : Optional[bytearray] The initial value for the characteristic permissions : GATTAttributePermissions The permissions for the characteristic """ serverguid: Guid = Guid.Parse(service_uuid) service: BlessGATTServiceDotNet = self.services[str(serverguid)] characteristic: BlessGATTCharacteristicDotNet = BlessGATTCharacteristicDotNet( char_uuid, properties, permissions, value) await characteristic.init(service) characteristic.obj.ReadRequested += self.read_characteristic characteristic.obj.WriteRequested += self.write_characteristic characteristic.obj.SubscribedClientsChanged += self.subscribe_characteristic service.add_characteristic(characteristic)
async def init(self, service: BlessGATTService): """ Initialize the DotNet GattLocalCharacteristic object Parameters ---------- service : BlessGATTServiceDotNet The service to assign the characteristic to """ charguid: Guid = Guid.Parse(self._uuid) char_parameters: GattLocalCharacteristicParameters = ( GattLocalCharacteristicParameters()) char_parameters.CharacteristicProperties = self._properties.value char_parameters.ReadProtectionLevel = ( BlessGATTCharacteristicDotNet.permissions_to_protection_level( self._permissions, True)) char_parameters.WriteProtectionLevel = ( BlessGATTCharacteristicDotNet.permissions_to_protection_level( self._permissions, False)) characteristic_result: GattLocalCharacteristicResult = ( await wrap_IAsyncOperation( IAsyncOperation[GattLocalCharacteristicResult]( service.obj.CreateCharacteristicAsync( charguid, char_parameters)), return_type=GattLocalCharacteristicResult, )) gatt_char: GattLocalCharacteristic = characteristic_result.Characteristic super(BlessGATTCharacteristic, self).__init__(obj=gatt_char)
async def add_new_service(self, uuid: str): """ Generate a new service to be associated with the server Parameters ---------- uuid : str The string representation of the UUID of the service to be added """ logger.debug("Creating a new service with uuid: {}".format(uuid)) guid: Guid = Guid.Parse(uuid) spr: GattServiceProviderResult = await wrap_IAsyncOperation( IAsyncOperation[GattServiceProviderResult]( GattServiceProvider.CreateAsync(guid) ), return_type=GattServiceProviderResult) self.service_provider: GattServiceProvider = spr.ServiceProvider new_service: GattLocalService = self.service_provider.Service bleak_service = BleakGATTServiceDotNet(obj=new_service) logger.debug("Adding service to server with uuid {}".format(uuid)) self.services[uuid] = bleak_service
async def init(self, server: "BaseBlessServer"): """ Initialize the GattLocalService Object Parameters ---------- server: BlessServerDotNet The server to assign the service to """ dotnet_server: "BlessServerDotNet" = cast("BlessServerDotNet", server) guid: Guid = Guid.Parse(self._uuid) service_provider_result: GattServiceProviderResult = await wrap_IAsyncOperation( IAsyncOperation[GattServiceProviderResult]( GattServiceProvider.CreateAsync(guid)), return_type=GattServiceProviderResult, ) self.service_provider: GattServiceProvider = ( service_provider_result.ServiceProvider) self.service_provider.AdvertisementStatusChanged += dotnet_server._status_update new_service: GattLocalService = self.service_provider.Service self.obj = new_service
import traceback from os.path import isdir, isfile, join import os import System.Guid as Guid from System.Collections.ObjectModel import ObservableCollection from System.IO import FileInfo, Path from System import Array, Object import clr clr.AddReference("System.Core") import System clr.ImportExtensions(System.Linq) STEAM_PLUGIN_GUID = Guid.Parse("CB91DFC9-B977-43BF-8E70-55F46E410FAB") SHORTCUT_DEFAULTS = { "allowoverlay": 1, "allowdesktopconfig": 1, "shortcutpath": "", "ishidden": 0, "openvr": 0, "tags": {}, "lastplaytime": 0, "devkit": 0, "devkitgameid": "", } SHORTCUTS_VDF = join(STEAM_USERDATA, "config", "shortcuts.vdf")
async def test_init(self): start_event: threading.Event = threading.Event() def advertisement_status_changed( sender: GattServiceProvider, args: GattServiceProviderAdvertisementStatusChangedEventArgs, ): if args.Status == 2: start_event.set() def read(sender: GattLocalCharacteristic, args: GattReadRequestedEventArgs): deferral: Deferral = args.GetDeferral() value = self.val writer: DataWriter = DataWriter() writer.WriteBytes(value) request: GattReadRequest = sync_async_wrap(GattReadRequest, args.GetRequestAsync) request.RespondWithValue(writer.DetachBuffer()) deferral.Complete() def write(sender: GattLocalCharacteristic, args: GattWriteRequestedEventArgs): deferral: Deferral = args.GetDeferral() request: GattWriteRequest = sync_async_wrap( GattWriteRequest, args.GetRequestAsync) reader: DataReader = DataReader.FromBuffer(request.Value) n_bytes: int = reader.UnconsumedBufferLength value: bytearray = bytearray() for n in range(0, n_bytes): next_byte: int = reader.ReadByte() value.append(next_byte) self.val = value if request.Option == GattWriteOption.WriteWithResponse: request.Respond() deferral.Complete() def subscribe(sender: GattLocalCharacteristic, args: Object): self._subscribed_clients = list(sender.SubscribedClients) # Create service service_uuid: str = str(uuid.uuid4()) service_guid: Guid = Guid.Parse(service_uuid) ServiceProviderResult: GattServiceProviderResult = ( await wrap_IAsyncOperation(IAsyncOperation[GattServiceProviderResult]( GattServiceProvider.CreateAsync(service_guid)), return_type=GattServiceProviderResult)) service_provider: GattServiceProvider = ( ServiceProviderResult.ServiceProvider) service_provider.AdvertisementStatusChanged += ( advertisement_status_changed) new_service: GattLocalService = service_provider.Service # Add a characteristic char_uuid: str = str(uuid.uuid4()) char_guid: Guid = Guid.Parse(char_uuid) properties: GATTCharacteristicProperties = ( GATTCharacteristicProperties.read | GATTCharacteristicProperties.write | GATTCharacteristicProperties.notify) permissions: GATTAttributePermissions = ( GATTAttributePermissions.readable | GATTAttributePermissions.writeable) ReadParameters: GattLocalCharacteristicParameters = ( GattLocalCharacteristicParameters()) ReadParameters.CharacteristicProperties = properties.value ReadParameters.ReadProtectionLevel = permissions.value characteristic_result: GattLocalCharacteristicResult = ( await wrap_IAsyncOperation( IAsyncOperation[GattLocalCharacteristicResult]( new_service.CreateCharacteristicAsync( char_guid, ReadParameters)), return_type=GattLocalCharacteristicResult, )) newChar: GattLocalCharacteristic = characteristic_result.Characteristic newChar.ReadRequested += read newChar.WriteRequested += write newChar.SubscribedClientsChanged += subscribe # Ensure we're not advertising assert service_provider.AdvertisementStatus != 2 # Advertise adv_parameters: GattServiceProviderAdvertisingParameters = ( GattServiceProviderAdvertisingParameters()) adv_parameters.IsDiscoverable = True adv_parameters.IsConnectable = True service_provider.StartAdvertising(adv_parameters) # Check start_event.wait() assert service_provider.AdvertisementStatus == 2 # We shouldn't be connected assert len(self._subscribed_clients) < 1 print("\nPlease connect now" + "and subscribe to the characteristic {}...".format(char_uuid)) await aioconsole.ainput("Press enter when ready...") assert len(self._subscribed_clients) > 0 # Read test rng: np.random._generator.Generator = np.random.default_rng() hex_val: str = "".join(rng.choice(self.hex_words, 2, replace=False)) self.val = bytearray( int(f"0x{hex_val}", 16).to_bytes(length=int(np.ceil(len(hex_val) / 2)), byteorder="big")) print("Trigger a read and enter the hex value you see below") entered_value = await aioconsole.ainput("Value: ") assert entered_value == hex_val # Write test hex_val = "".join(rng.choice(self.hex_words, 2, replace=False)) print(f"Set the characteristic to the following: {hex_val}") await aioconsole.ainput("Press enter when ready...") str_val: str = "".join([hex(x)[2:] for x in self.val]).upper() assert str_val == hex_val # Notify test hex_val = "".join(rng.choice(self.hex_words, 2, replace=False)) self.val = bytearray( int(f"0x{hex_val}", 16).to_bytes(length=int(np.ceil(len(hex_val) / 2)), byteorder="big")) print("A new value will be sent") await aioconsole.ainput("Press enter to receive the new value...") with BleakDataWriter(self.val) as writer: newChar.NotifyValueAsync(writer.detach_buffer()) new_value: str = await aioconsole.ainput("Enter the New value: ") assert new_value == hex_val # unsubscribe print("Unsubscribe from the characteristic") await aioconsole.ainput("Press enter when ready...") assert len(self._subscribed_clients) < 1 # Stop Advertising service_provider.StopAdvertising()
return [(xs1[0], y1, xs1[1], y1, xs1[1], y2, xs1[0], y2)] + operate( (xs1[1:], y1), (xs2[1:], y2)) else: return [(xs1[0], y1, xs1[1], y1, xs1[1], y2, xs1[0], y2)] def operate1(row1, row2): print("== " + str(row1) + " " + str(row2)) # SCRIPT # select object #objId = rs.GetObject("Select the surface", preselect = True, select = True) #objId = "48a4e368-b082-4929-b4f9-da80ee50404a" a = sc.doc.Objects.FindId(Guid.Parse(objId)) print(a) #rs.EnableRedraw(False) # make matrix m = make_matrix(10, get_normalized_series(17)) # iterate matrix d = iterate(m) for comb in d: params1 = rs.SurfaceParameter(objId, [comb[0], comb[1]]) params2 = rs.SurfaceParameter(objId, [comb[2], comb[3]]) params3 = rs.SurfaceParameter(objId, [comb[4], comb[5]]) params4 = rs.SurfaceParameter(objId, [comb[6], comb[7]]) p1 = rs.SurfaceEvaluate(objId, params1, 0)