I have answered a few questions I have submitted in blog posts and csdn. I found a solution code later:
Now we need to use C # As a WebServices interface for C ++ to call.
WebServices has been defined (only one of the simplest web methods is described here, and security verification is omitted ):
Void process (byte [] request, out byte [] Response) (this parameter cannot be changed)
Parameter description: the type of the received parameter byte []. The output parameter byte []. Based on the received request parameter, I return the result data respone.
The request/response package format is as follows:
That is to say, the C ++ solution must follow this package format, because the C ++ protocol and the Bluetooth communication protocol have been defined, you can only use this format to unpack.
I have little knowledge about the transmission of such data packets before, and I don't know how to group packets:
For example:
Receives a parameter packet request: Request Code (102), packet length (5), request packet data ("12 ")
Use logic to process returned data packets: Response Code (200), packet length (30), response package data ("I Am a persion ")
What I want to ask now is:
1. How to decompress the request data packet into a string to obtain the desired Parameter
2. How to make up a data packet of my returned data (response code, package length, response package data) and send it to the C ++ side?
3. Experts explain to me how to convert a data packet into a data packet.
In the past two days, I have probably asked what C # buffer [] data is used for data transfer, but I have never used it !! Another way is to use arraylist. copyto () to set data.
Press into buffer [], but these technologies are not quite clear
I thought that if I forcibly convert the response data into byte [] strings, it would not work if I thought about it later.
Questioner:
Leiming-Beginner level 1
Question added:After the problem is solved, paste the following code:
// Package compression process
String datacontent = "abcdefg Chinese people on earth"; // packet content
Int16 pack_len = (int16) (datacontent. length * 2 + 2 + 2); // packet length (response code length + Length + packet length)
Int16 backcode = 101; // response code
Byte [] Buf = new byte [pack_len]; // defines the byte array
Buf [0] = (byte) (backcode> 8); // shift the Buf [0] to store a high response code
Buf [1] = (byte) (backcode & 0xff); // use Buf [1] to save the low response code through and operations
Buf [2] = (byte) (pack_len> 8); // Buf [2] High Length
Buf [3] = (byte) (pack_len & 0xff); // Buf [3] low package Length
Byte [] databyte = system. Text. encoding. Unicode. getbytes (datacontent); // data packet content byte
Databyte. copyto (BUF, 4); // press the packet byte [] into the Buf array.
// Unpacking process
Int16 ubackcode = (int16) (BUF [0] & 0xff) <8) | (BUF [1] & 0xff); // get response code
Int16 u_pack_len = (int16) (BUF [2] & 0xff) <8) | (BUF [3] & 0xff); // get the package Length
String udatacontent = "";
Int templenght = datacontent. length * 2;
Byte [] temp = new byte [templenght];
Array. Copy (BUF, 4, temp, 0, templenght-1); // define the data packet content in the byte [] array to a temporary Array
Udatacontent = system. Text. encoding. Unicode. getstring (temp); // get the data packet content through conversion