12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Wit.SDK.Utils;
- namespace Wit.SDK.Modular.Sensor.Utils
- {
-
-
-
- public class WitCanProtocolUtils
- {
-
-
-
-
-
-
- public static int GetFrameId(int id, int frameFormat, int frmaeType)
- {
- int frameId = frameFormat == 1 ? id << 3 | 0x04 : id <<= 21;
- if (frmaeType == 1) { frameId |= 0x02; }
- return frameId;
- }
- #region 获得读写命令
-
-
-
-
-
-
-
- public static byte[] GetStandWrite(int canId, byte reg, short value)
- {
-
- List<byte> byteList = new List<byte>();
-
- byte[] dataFrame = new byte[] { 0xff, 0xaa, reg, (byte)(value), (byte)(value >> 8) };
-
- byteList.AddRange(Encoding.Default.GetBytes("AT"));
-
- int frameId = GetFrameId(canId, 0, 0);
- byteList.AddRange(BitConverter.GetBytes(frameId));
-
- byteList.AddRange(new byte[] { (byte)(dataFrame.Length >> 8), (byte)(dataFrame.Length) });
-
- byteList.AddRange(dataFrame);
-
- byteList.AddRange(Encoding.Default.GetBytes("\r\n"));
- return byteList.ToArray();
- }
-
-
-
-
-
-
-
- public static byte[] GetStandRead(int canId, byte reg)
- {
-
- List<byte> byteList = new List<byte>();
-
- byte[] dataFrame = new byte[] { 0xff, 0xaa, 0x27, reg, 00 };
-
- byteList.AddRange(Encoding.Default.GetBytes("AT"));
-
- int frameId = GetFrameId(canId, 0, 0);
- byteList.AddRange(BitConverter.GetBytes(frameId));
-
- byteList.AddRange(new byte[] { (byte)(dataFrame.Length >> 8),(byte)(dataFrame.Length) });
-
- byteList.AddRange(dataFrame);
-
- byteList.AddRange(Encoding.Default.GetBytes("\r\n"));
- return byteList.ToArray();
- }
- #endregion
- }
- }
|