微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Dart BLE 描述以便于编码?

如何解决Dart BLE 描述以便于编码?

一个架构问题: 我有一个带有许多变量的 BLE 设备......并且可以从 XML 中引入这些变量,例如

<!--Automation IO-->
  <service advertise="false" id="automation_io" name="Automation IO" requirement="mandatory" sourceId="BLE" type="primary" uuid="1815">
    <informativeText>Abstract:  The Automation IO service is used to expose the analog inputs/outputs and digital input/outputs of a generic IO module (IOM).  </informativeText>
    
    <!--Output-->
    <characteristic id="Output" name="Output" sourceId="xxx" uuid="1230">
      <informativeText>Summary:  The Digital characteristic is used to expose and change the state of an IO Module's digital signals.  </informativeText>
      <value length="1" type="user" variable_length="false">0</value>
      <properties indicate="false" indicate_requirement="optional" notify="true" notify_requirement="optional" read="true" read_requirement="optional"/>
    </characteristic>
        
    <!--Electronicstemp-->
    <characteristic id="Electronicstemp" name="Electronicstemp" sourceId="xxx" uuid="1235">
      <informativeText>Summary:  The Digital characteristic is used to expose and change the state of an IO Module's digital signals.  </informativeText>
      <value length="2" type="user" variable_length="false">23</value>
      <properties notify="true" notify_requirement="mandatory" read="true" read_requirement="mandatory"/>
    </characteristic>
    
    <!--MaxElectronicstemp-->
    <characteristic id="MaxElectronicstemp" name="MaxElectronicstemp" sourceId="xxx" uuid="123E">
      <informativeText>Summary:  The Digital characteristic is used to expose and change the state of an IO Module's digital signals.  </informativeText>
      <value length="2" type="user" variable_length="false">23</value>
      <properties notify="true" notify_requirement="mandatory" read="true" read_requirement="mandatory"/>
    </characteristic>
    
    <!--SelfTest-->
    <characteristic id="SelfTest" name="SelfTest" sourceId="xxx" uuid="1236">
      <informativeText>Summary:  The Digital characteristic is used to expose and change the state of an IO Module's digital signals.  </informativeText>
      <value length="1" type="user" variable_length="false">00</value>
      <properties indicate="false" indicate_requirement="optional" notify="true" notify_requirement="optional" read="true" read_requirement="optional" write="true" write_no_response="true" write_no_response_requirement="optional" write_requirement="optional"/>
    </characteristic>
 ...

问题是如何将它变成最适合 FlutterBlue 等的东西。

现在我有

class Intercom{
  static const PatchTo = "665c1cbc-2c88-4ae1-9ccf-9dbc8a9e5440";
  static const PhoneBook = "78805e56-f8b7-4f30-a056-2ece9f4f70a9";
  static const AllCall = "2ac8";
  static const StatusWord = "1239";
...
}

{
    BluetoothCharacteristic patchto =
        bleFindChar(services,Intercom.PatchTo)!;
    await patchto.write([0xFF,0xFF]);
}

所以问题: 最好保持这种方式 - 这样我就可以向 Class Intercom 添加越来越多的内容(如数据格式、tostring 等)...

还是分开?

也许 Intercom 应该从 FlutterBlue 派生出来并吸收所有东西,这样我就可以轻松地说 Intercom.PatchTo(0xFFFF)

有没有办法将 XML 文件加载到 Flutter 项目中并将其自身呈现为数据结构,或者我是否需要编写一个小的 Python 脚本来获取 XML 并从中制作一个 .dart 文件

解决方法

xml 包允许您在 Dart(和 Flutter)中解析、遍历、查询、转换和构建 XML 文档。包描述中的教程解释了如何加载 XML 文件和提取数据。欢迎在 StackOverflow 或 GitHub 上发布更具体的问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。