RF-Ranmmbock library Reviews 3-udp transmission and reception using a template manner 2

Part defects: variable length data transmission and reception

Using another keyword text sending binary manner (all frames protocol spliced ​​together in a certain order)

 

Key words:

Client Sends Binary

Client Receives Binary

Server Sends Binary

Server Receives Binary

DMIdata the Message Sent
    [the Arguments] QueryCmd} {$ $ $ {} {ExpectLen ExpectData}
    [Documentation] implemented method of using the transmission binary parameter $ {QueryCmd} $ {ExpectData} is a hexadecimal constant need to add 0x, $ { decimal ExpectLen}
    $} {dataLength_Ev the Evaluate the eval ( '. 1. 1 + + + 1'd ExpectLen} {$')
    $ {dataLength_hex the Convert the to Hex $}} {dataLength_Ev length = 2
    $ {QueryCmd_int the to the Convert Integer} $ {16} QueryCmd
    $ {QueryCmd_hex} the Convert the To Hex $ {QueryCmd_int} length = 2
    $ {ExpectLen_hex} the Convert the To Hex $ {ExpectLen} length = 2
    $ {ExpectData_int} the Convert the To Integer $ {ExpectData} 16
    $ {length_hex} the Evaluate the eval ( '$ { * 2} ExpectLen ')
    $ {} ExpectData_hex ExpectData_int the Convert the To Hex $ {$} = {length} length_hex
    ${SendMsg}    Set Variable    00${dataLength_hex}01520000${QueryCmd_hex}${ExpectLen_hex}${ExpectData_hex}ff
    ${SendMsg_by}    Convert To Bytes    ${SendMsg}    hex
    Client Sends Binary    ${SendMsg_by}    name=dmiclient

important point:

1. Due To test parameter passing unity, the article displays the input parameters are passed 0x hexadecimal, so the interface is passed in time, also we need to be unified, but does not require string concatenation of the prefix 0x , so the need to remove by transformation 0x

2. After the string concatenation to a length of 2 hexadecimal, we need to be converted by the Convert To Bytes as bytes \ x01 of the situation to send, otherwise it will error

3. Such socketTool displayed in hexadecimal mode

Send it finished ~ ~ ~

BB

the Message DMIdata the receive
    [the Arguments] $ {QueryCmd} $ {timeout}
    [Documentation] needs to be received back data string, the parameter $ {QueryCmd} hex with 0x
    ... if the direct yield hexadecimal to 00, it will appear to be empty, can not be parsed
    ... so that data sent back in claim dmi string format
    ... handles
    ... 1. Comparative whether the returned data transmitted coincides with the command number (0x00)
    . .. 2. Comparative data is returned 05
    ... return an error value 3. Print
    $} = {RevMsg Client Receives Binary name = dmiclient timeout = timeout} $ {
    $ {} RevMsg_1 the Evaluate ",." the Join ([ '$ {RevMsg}' [2 * I: 2 * (I +. 1)] for I in Range (len ( '$ {RevMsg}') / 2)])
    $ {RevMsg_2} the Evaluate '$ {RevMsg_1}'. Split ( ",")
    $ {} int the To the Convert Integer RevMsg_2} {$ [. 7] 16
    $ {hex the Convert the To hex $ {}} int = 0x prefix length = 2
    $ {$ Of Be Equal Should QueryCmd} {} hex
    Should of Be Equal RevMsg_2} {$ [. 6] 05
    log specific print error Return Value: $ {RevMsg_2} [7: ]

important point:

1. Because if normal software to send hexadecimal data I found 00, receiving this keyword directly appear empty, checked, the keyword received data is received in accordance with ascii code, when receiving Null Byte time will not receive, it is in fact the method is not suitable. A temporary solution is to allow developers to directly return the string to me directly check the string

2. string received, it needs to be divided, and takes a value corresponding to the position, to be verified

 

 

Benefits: No need to develop protocols, templates

Difficulties: string concatenation (input parameters required in a different way to transfer various transformations required)

Nausea point: ascii code is received, if received 00 hexadecimal data directly is empty, that receives NUll byte, can not be decoded (vomiting blood)

 

Guess you like

Origin www.cnblogs.com/xiaodouzhou-123/p/11202093.html