Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Codec for Strings and Variable-Length Strings

Updated on 2022-02-24 GMT+08:00

Scenarios

A smoke detector provides the following functions:

  • Reporting smoke alarms (fire severity) and temperature simultaneously, or reporting the temperature separately.
  • Reporting description. The data type of description can be string (string type) or varstring (variable-length string type).
    NOTE:

    This scenario describes how to develop a codec for data in strings and data in variable-length strings. The data reporting and command delivery codecs are developed in the same way. Therefore, data reporting is used as an example and command delivery is not described.

Defining the Profile File

Define the profile file in the development space of the smoke sensor.

Developing a Codec

This section describes only the procedure for developing the codec for reporting the description (other_info). For details on how to develop the codec for reporting the smoke alarms (level) and temperature (temperature), see Codec for Multiple Data Reporting Messages.

  1. In the development space of the smoke sensor, click Codec Development.

  2. Configure a data reporting message to report the fire severity and temperature. For details, see 2.
  3. Configure a data reporting message to report only the temperature. For details, see 3.
  4. Configure a data reporting message to report the description of the string type.

    Add the messageId field to indicate the message type. In this scenario, the value 0x0 is used to identify the message that reports the fire severity and temperature, 0x1 is used to identify the message that reports only the temperature, and 0x2 is used to identify the message that reports the description (of the string type).

    Add the other_info field to indicate the description of the string type. In this scenario, set Length to 6.

  5. Configure a data reporting message to report the description of the variable-length string type.

    Add the messageId field to indicate the message type. In this scenario, the value 0x0 is used to identify the message that reports the fire severity and temperature, 0x1 is used to identify the message that reports only the temperature, and 0x3 is used to identify the message that reports the description (of the variable-length string type).

    Add the length field to indicate the length of a string. Data Type is configured based on the length of the variable-length string. If the string contains 255 or fewer characters, set this parameter to int8u.

    Add the other_info field to indicate the description of the variable-length string type. Set Length Correlation Field to length. The values of Length Correlation Field Difference and Length are automatically filled.

  6. Drag the property fields in Device Model on the right to set up a mapping with the fields in the data reporting messages.

  7. Click Save and then Deploy to deploy the codec on the IoT platform.

Testing the Codec

  1. In the development space of the smoke sensor, click Online Testing and add a virtual device to test the codec.

    Select No for Is Physical Device Available and click OK.

  2. Use the device simulator to report the description of the string type.

    For example, a hexadecimal code stream (0231) is reported. 02 indicates the messageId field and specifies that this message reports the description of the string type. 31 indicates the description and its length is one byte.

    View the data reporting result ({other_info=null}) in Application Simulator. The length of the description is less than six bytes. Therefore, the codec cannot parse the description.

    In the second hexadecimal code stream example (02313233343536), 02 indicates the messageId field and specifies that this message reports the description of the string type. 313233343536 indicates the description and its length is six bytes.

    View the data reporting result ({other_info=123456}) in Application Simulator. The length of the description is six bytes. The description is parsed successfully by the codec.

    In the third hexadecimal code stream example (023132333435363738), 02 indicates the messageId field and specifies that this message reports the description of the string type. 3132333435363738 indicates the description and its length is eight bytes.

    View the data reporting result ({other_info=123456}) in Application Simulator. The length of the description exceeds six bytes. Therefore, the first six bytes are intercepted and parsed by the codec.

    In the fourth hexadecimal code stream example (02013132333435), 02 indicates the messageId field and specifies that this message reports the description of the string type. 013132333435 indicates the description and its length is six bytes.

    View the data reporting result ({other_info=\u000112345}) in Application Simulator. In the ASCII code table, 01 indicates start of headline which cannot be represented by specific characters. Therefore, 01 is parsed to \u0001.

  3. Use the device simulator to report the description of the variable-length string type.

    For example, a hexadecimal code stream (030141) is reported. In this code stream, 03 indicates the messageId field and specifies that this message reports the description of the variable-length string type. 01 indicates the length of the description (one byte) and its length is one byte. 41 indicates the description and its length is one byte.

    View the data reporting result ({other_info=A}) in Application Simulator. A corresponds to 41 in the ASCII code table.

    In the second hexadecimal code stream example (03024142), 03 indicates the messageId field and specifies that this message reports the description of the variable-length string type. 02 indicates the length of the description (two bytes) and its length is one byte. 4142 indicates the description and its length is two bytes.

    View the data reporting result ({other_info=AB}) in Application Simulator. A corresponds to 41 and B corresponds to 42 in the ASCII code table.

    In the third hexadecimal code stream example (030341424344), 03 indicates the messageId field and specifies that this message reports the description of the variable-length string type. The second 03 indicates the length of the description (three bytes) and its length is one byte. 41424344 indicates the description and its length is four bytes.

    View the data reporting result ({other_info=ABC}) in Application Simulator. The length of the description exceeds three bytes. Therefore, the first three bytes are intercepted and parsed. In the ASCII code table, A corresponds to 41, B to 42, and C to 43.

    In the fourth hexadecimal code stream example (0304414243), 03 indicates the messageId field and specifies that this message reports the description of the variable-length string type. 04 indicates the string length (four bytes) and its length is one byte. 414243 indicates the description and its length is four bytes.

    View the data reporting result ({other_info=null}) in Application Simulator. The length of the description is less than four bytes. The codec fails to parse the description.

Summary

  • When data is a string or a variable-length string, the codec processes the data based on the ASCII code. When data is reported, the hexadecimal code stream is decoded to a string. For example, 21 is parsed to an exclamation mark (!), 31 to 1, and 41 to A. When a command is delivered, the string is encoded into a hexadecimal code stream. For example, an exclamation mark (!) is encoded into 21, 1 into 31, and A into 41.
  • When the data type of a field is varstring(variable-length string type), the field must be associated with the length field. The data type of the length field must be int.
  • For variable-length strings, the codecs for command delivery and data reporting are developed in the same way.
  • Online developed codecs encode and decode strings and variable-length strings using the ASCII hexadecimal standard table. During decoding (data reporting), if the parsing results cannot be represented by specific characters such as start of headline, start of text, and end of text, the \u+2 byte code stream values are used to indicate the results. For example, 01 is parsed to \u0001 and 02 to \u0002. If the parsing results can be represented by specific characters, specific characters are used.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback