Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
596 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using IoTClient.Common.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace IoTClient.Tests.TempTest | ||
{ | ||
public class temp | ||
{ | ||
[Fact] | ||
public void test() | ||
{ | ||
var str = "03 00 00 1D 02 F0 80 32 03 00 00 00 01 00 02 00 1F 00 00 04 01 FF 04 00 04 00 00 00 00"; | ||
//var b = str.Split(" ").Select(t => Convert.ToByte(t, 16)).ToArray(); | ||
|
||
var aa = DataConvert.StringToByteArray(str); | ||
var bb = DataConvert.ByteArrayToString(aa); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace IoTClient.Common.Helpers | ||
{ | ||
/// <summary> | ||
/// 数据转换 | ||
/// </summary> | ||
public static class DataConvert | ||
{ | ||
/// <summary> | ||
/// 字节数组转16进制字符 | ||
/// </summary> | ||
/// <param name="byteArray"></param> | ||
/// <returns></returns> | ||
public static string ByteArrayToString(byte[] byteArray) | ||
{ | ||
return string.Join(" ", byteArray.Select(t => t.ToString("X2"))); | ||
} | ||
|
||
/// <summary> | ||
/// 16进制字符串转字节数组 | ||
/// </summary> | ||
/// <param name="str"></param> | ||
/// <returns></returns> | ||
public static byte[] StringToByteArray(string str) | ||
{ | ||
return str.Split(' ').Where(t => t?.Length == 2).Select(t => Convert.ToByte(t, 16)).ToArray(); | ||
} | ||
} | ||
} |
Oops, something went wrong.