Compare commits
No commits in common. "5c0f5b2127faed952ca6c71f953208a276d3914d" and "292c73e7574454ae093c86833cb97f17ed0024ce" have entirely different histories.
5c0f5b2127
...
292c73e757
|
@ -41,8 +41,6 @@ app.MapGet("/", () => "Hello World!");
|
||||||
app.MapPut("/api/SendString", Router.API.SendString);
|
app.MapPut("/api/SendString", Router.API.SendString);
|
||||||
app.MapPut("/api/SendAddrPackage", Router.API.SendAddrPackage);
|
app.MapPut("/api/SendAddrPackage", Router.API.SendAddrPackage);
|
||||||
app.MapPut("/api/SendDataPackage", Router.API.SendDataPackage);
|
app.MapPut("/api/SendDataPackage", Router.API.SendDataPackage);
|
||||||
app.MapPut("/api/jtag/RunCommand", Router.API.Jtag.RunCommand);
|
|
||||||
app.MapPut("/api/jtag/GetIDCode", Router.API.Jtag.GetDeviceIDCode);
|
|
||||||
|
|
||||||
app.Run("http://localhost:5000");
|
app.Run("http://localhost:5000");
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
<PackageReference Include="DotNext.Threading" Version="5.19.1" />
|
<PackageReference Include="DotNext.Threading" Version="5.19.1" />
|
||||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
|
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="NLog" Version="5.4.0" />
|
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@ namespace Common
|
||||||
{
|
{
|
||||||
for (var i = 0; i < length; i++)
|
for (var i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
arr[i] = Convert.ToByte((num >> ((int)(length - 1 - i) << 3)) & (0xFF));
|
arr[i] = Convert.ToByte((num >> (i << 3)) & (0xFF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<ulong> BytesToNumber(byte[] bytes, bool isRightHigh = false)
|
public static Result<ulong> BytesToNumber(byte[] bytes, bool isRightLeft = false)
|
||||||
{
|
{
|
||||||
if (bytes.Length > 8)
|
if (bytes.Length > 8)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ namespace Common
|
||||||
ulong num = 0;
|
ulong num = 0;
|
||||||
int len = bytes.Length;
|
int len = bytes.Length;
|
||||||
|
|
||||||
if (isRightHigh)
|
if (isRightLeft)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < len; i++)
|
for (var i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
|
@ -57,15 +57,13 @@ namespace Common
|
||||||
{
|
{
|
||||||
for (var i = 0; i < len; i++)
|
for (var i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
num += Convert.ToUInt64(bytes[i] << ((int)(len - 1 - i) << 3));
|
num += Convert.ToUInt64(bytes[i] << (i << 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Result<byte[]> MultiBitsToBytes(ulong bits1, uint bits1Len, ulong bits2, uint bits2Len)
|
public static Result<byte[]> MultiBitsToBytes(ulong bits1, uint bits1Len, ulong bits2, uint bits2Len)
|
||||||
{
|
{
|
||||||
return NumberToBytes(MultiBitsToNumber(bits1, bits1Len, bits2, bits2Len).Value,
|
return NumberToBytes(MultiBitsToNumber(bits1, bits1Len, bits2, bits2Len).Value,
|
||||||
|
@ -76,28 +74,10 @@ namespace Common
|
||||||
{
|
{
|
||||||
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
|
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
|
||||||
|
|
||||||
ulong num = (bits1 << Convert.ToInt32(bits2Len)) | bits2;
|
ulong num = (bits1 << (int)bits2Len) | bits2;
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result<uint> MultiBitsToNumber(uint bits1, uint bits1Len, uint bits2, uint bits2Len)
|
|
||||||
{
|
|
||||||
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
|
|
||||||
|
|
||||||
uint num = (bits1 << Convert.ToInt32(bits2Len)) | bits2;
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool BitsCheck(ulong srcBits, ulong dstBits, ulong mask = 0xFFFF_FFFF_FFFF_FFFF)
|
|
||||||
{
|
|
||||||
return (srcBits & mask) == dstBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool BitsCheck(uint srcBits, uint dstBits, uint mask = 0xFFFF_FFFF)
|
|
||||||
{
|
|
||||||
return (srcBits & mask) == dstBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Result<byte[]> StringToBytes(string str, int numBase = 16)
|
public static Result<byte[]> StringToBytes(string str, int numBase = 16)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,107 +28,12 @@ public static class JtagAddr
|
||||||
public const UInt32 WRITE_CMD = 0x10_00_00_03;
|
public const UInt32 WRITE_CMD = 0x10_00_00_03;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Jtag 状态寄存器的掩码及其确认函数
|
|
||||||
/// </summary>
|
|
||||||
public static class JtagState
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
[0] 移位数据读fifo清空,1为有效,清空后自动置0
|
|
||||||
[1] 移位数据fifo读入口-空标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
[2] 移位数据fifo读入口-满标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
[7:3] 保留
|
|
||||||
|
|
||||||
[8] 移位数据写fifo清空,1为有效,清空后自动置0
|
|
||||||
[9] 移位数据fifo写入口-空标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
[10] 移位数据fifo写入口-满标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
[15:11]保留
|
|
||||||
|
|
||||||
[16] 移位命令写fifo清空,1为有效,清空后自动置0
|
|
||||||
[17] 移位命令fifo写入口-空标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
[18] 移位命令fifo写入口-满标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
[23:19]保留
|
|
||||||
|
|
||||||
[24] CMD执行完毕标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据读fifo清空,1为有效,清空后自动置0,实际一直为零
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 READ_DATA_FIFO_CLEAR = 0b0001 << 0;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据fifo读入口-空标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 READ_DATA_FIFO_EMPTY = 0b0010 << 0;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据fifo读入口-满标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 READ_DATA_FIFO_AFULL = 0b0100 << 0;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据读fifo
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 READ_DATA_FIFO = 0b0111 << 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据写fifo清空,1为有效,清空后自动置0
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_DATA_FIFO_CLEAR = 0b0001 << 8;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据fifo写入口-空标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_DATA_FIFO_EMPTY = 0b0010 << 8;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据fifo写入口-满标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_DATA_FIFO_AFULL = 0b0100 << 8;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位数据写fifo
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_DATA_FIFO = 0b0111 << 8;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 移位命令写fifo清空,1为有效,清空后自动置0
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_CMD_FIFO_CLEAR = 0b0001 << 16;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位命令fifo写入口-空标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_CMD_FIFO_EMPTY = 0b0010 << 16;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位命令fifo写入口-满标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_CMD_FIFO_AFULL = 0b0100 << 16;
|
|
||||||
/// <summary>
|
|
||||||
/// 移位命令写fifo
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 WRITE_CMD_FIFO = 0b0111 << 16;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// CMD执行完毕标识,只读,对JTAG_STATE_REG的写不改变其值
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 CMD_EXEC_FINISH = 0b0001 << 24;
|
|
||||||
/// <summary>
|
|
||||||
/// 全部FIFO
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 ALL_FIFO = READ_DATA_FIFO | WRITE_DATA_FIFO | WRITE_CMD_FIFO;
|
|
||||||
/// <summary>
|
|
||||||
/// 全部寄存器
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 ALL_REG = READ_DATA_FIFO | WRITE_DATA_FIFO | WRITE_CMD_FIFO | CMD_EXEC_FINISH;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Command bits of Jtag
|
/// The Command bits of Jtag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class JtagCmd
|
public static class JtagCmd
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The length of JTAG_DR_XXXX
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 LEN_JTAG_DR = 10;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 旁路指令
|
/// 旁路指令
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -184,10 +89,6 @@ public static class JtagCmd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The length of CMD_JTAG_XXXX_XXXX
|
|
||||||
/// </summary>
|
|
||||||
public const UInt32 LEN_CMD_JTAG = 4;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设定JTAG默认状态为TEST_LOGIC_RESET态 (JTAG复位)
|
/// 设定JTAG默认状态为TEST_LOGIC_RESET态 (JTAG复位)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -221,56 +122,18 @@ class Jtag
|
||||||
readonly int port;
|
readonly int port;
|
||||||
readonly string address;
|
readonly string address;
|
||||||
private IPEndPoint ep;
|
private IPEndPoint ep;
|
||||||
|
private UDPServer server;
|
||||||
|
|
||||||
public Jtag(string address, int port, int outTime = 2000)
|
public Jtag(string address, int port, UDPServer udpServer, int outTime = 2000)
|
||||||
{
|
{
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
||||||
|
this.server = udpServer;
|
||||||
this.timeout = outTime;
|
this.timeout = outTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<Result<uint>> ReadFIFO(uint devAddr)
|
public async ValueTask<Result<bool>> RunCommand(uint devAddr, uint cmd, uint exRet)
|
||||||
{
|
|
||||||
var ret = false;
|
|
||||||
var opts = new SendAddrPackOptions();
|
|
||||||
|
|
||||||
opts.burstType = BurstType.FixedBurst;
|
|
||||||
opts.burstLength = 4;
|
|
||||||
opts.commandID = 0;
|
|
||||||
opts.address = devAddr;
|
|
||||||
|
|
||||||
// Read Jtag State Register
|
|
||||||
ret = await UDPClientPool.SendAddrPackAsync(ep, new SendAddrPackage(opts));
|
|
||||||
if (!ret) throw new Exception("Send Address Package Failed!");
|
|
||||||
|
|
||||||
// Wait for Ack
|
|
||||||
if (!MsgBus.IsRunning)
|
|
||||||
throw new Exception("Message Bus not Working!");
|
|
||||||
|
|
||||||
var data = await MsgBus.UDPServer.FindDataAsync(address);
|
|
||||||
if (!data.HasValue)
|
|
||||||
throw new Exception("Get None after Time out!");
|
|
||||||
|
|
||||||
var recvData = data.Value;
|
|
||||||
if (recvData.addr != address || recvData.port != port)
|
|
||||||
throw new Exception("Receive Data From Wrong Board!");
|
|
||||||
|
|
||||||
var retPack = RecvDataPackage.FromBytes(recvData.data);
|
|
||||||
if (!retPack.IsSuccessful)
|
|
||||||
throw new Exception("Not RecvDataPackage!", retPack.Error);
|
|
||||||
|
|
||||||
if (retPack.Value.Options.data is null)
|
|
||||||
throw new Exception($"Data is Null, package: {retPack.Value.Options.ToString()}");
|
|
||||||
|
|
||||||
var retPackLen = retPack.Value.Options.data.Length;
|
|
||||||
if (retPackLen != 4)
|
|
||||||
throw new Exception($"RecvDataPackage BodyData Length not Equal to 4: Total {retPackLen} bytes");
|
|
||||||
|
|
||||||
return (uint)(NumberProcessor.BytesToNumber(retPack.Value.Options.data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<RecvDataPackage>> RunCommand(uint devAddr, uint command)
|
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
var opts = new SendAddrPackOptions();
|
var opts = new SendAddrPackOptions();
|
||||||
|
@ -285,7 +148,7 @@ class Jtag
|
||||||
ret = await UDPClientPool.SendAddrPackAsync(ep, new SendAddrPackage(opts));
|
ret = await UDPClientPool.SendAddrPackAsync(ep, new SendAddrPackage(opts));
|
||||||
if (!ret) throw new Exception("Send 1st Address Package Failed!");
|
if (!ret) throw new Exception("Send 1st Address Package Failed!");
|
||||||
ret = await UDPClientPool.SendDataPackAsync(ep,
|
ret = await UDPClientPool.SendDataPackAsync(ep,
|
||||||
new SendDataPackage(NumberProcessor.NumberToBytes(command, 4).Value));
|
new SendDataPackage(NumberProcessor.NumberToBytes(cmd, 4).Value));
|
||||||
if (!ret) throw new Exception("Send Data Package Failed!");
|
if (!ret) throw new Exception("Send Data Package Failed!");
|
||||||
|
|
||||||
// Read Jtag State Register
|
// Read Jtag State Register
|
||||||
|
@ -307,88 +170,41 @@ class Jtag
|
||||||
|
|
||||||
var retPack = RecvDataPackage.FromBytes(recvData.data);
|
var retPack = RecvDataPackage.FromBytes(recvData.data);
|
||||||
if (!retPack.IsSuccessful)
|
if (!retPack.IsSuccessful)
|
||||||
throw new Exception("Not RecvDataPackage!", retPack.Error);
|
throw new Exception("Not Current RecvDataPackage!", retPack.Error);
|
||||||
|
|
||||||
|
|
||||||
return retPack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> RunCommand(uint devAddr, uint command, uint result, uint resultMask = 0xFF_FF_FF_FF)
|
|
||||||
{
|
|
||||||
var ret = false;
|
|
||||||
var retPack = await RunCommand(devAddr, command);
|
|
||||||
|
|
||||||
if (retPack.Value.Options.data is null)
|
|
||||||
throw new Exception($"Data is Null, package: {retPack.Value.Options.ToString()}");
|
|
||||||
|
|
||||||
var retPackLen = retPack.Value.Options.data.Length;
|
var retPackLen = retPack.Value.Options.data.Length;
|
||||||
if (retPackLen != 4)
|
if (retPackLen != 3)
|
||||||
throw new Exception($"RecvDataPackage BodyData Length not Equal to 4: Total {retPackLen} bytes");
|
throw new Exception($"RecvDataPackage BodyData Length not Equal to 3: Total {retPackLen} bytes");
|
||||||
|
|
||||||
if (NumberProcessor.BitsCheck(
|
if (NumberProcessor.BytesToNumber(retPack.Value.Options.data).Value == exRet)
|
||||||
NumberProcessor.BytesToNumber(retPack.Value.Options.data).Value, result, resultMask))
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> ClearAllRegisters()
|
public async ValueTask<Result<bool>> ClearAllRegisters()
|
||||||
{
|
{
|
||||||
return await RunCommand(JtagAddr.STATE, 0xFF_FF_FF_FF, 0x01_02_02_02, JtagState.ALL_REG);
|
return await RunCommand(JtagAddr.STATE, 0xFF_FF_FF_FF, 0x00_00_00_00);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> ClearWriteDataReg()
|
public async ValueTask<Result<bool>> ClearWriteDataReg()
|
||||||
{
|
{
|
||||||
return await RunCommand(JtagAddr.STATE, 0x00_00_11_00, 0x01_00_02_00, JtagState.WRITE_DATA_FIFO | JtagState.CMD_EXEC_FINISH);
|
return await RunCommand(JtagAddr.STATE, 0x00_00_11_00, 0x00_00_00_00);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> RunTest()
|
public async ValueTask<Result<bool>> RunTest()
|
||||||
{
|
{
|
||||||
return await RunCommand(
|
return await RunCommand(JtagAddr.WRITE_CMD, 0x10_00_00_00, 0x01_00_00_00);
|
||||||
JtagAddr.WRITE_CMD,
|
|
||||||
NumberProcessor.MultiBitsToNumber(JtagCmd.CMD_JTAG_RUN_TEST, JtagCmd.LEN_CMD_JTAG, 0, 28).Value,
|
|
||||||
0x01_00_00_00, JtagState.CMD_EXEC_FINISH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> DRIDcode()
|
public async ValueTask<Result<bool>> WriteIDCode()
|
||||||
{
|
{
|
||||||
return await RunCommand(
|
return await RunCommand(JtagAddr.WRITE_DATA, 0b1010000011, 0x01_00_00_00);
|
||||||
JtagAddr.WRITE_DATA,
|
|
||||||
NumberProcessor.MultiBitsToNumber(0, 22, JtagCmd.JTAG_DR_IDCODE, JtagCmd.LEN_JTAG_DR).Value, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask<Result<bool>> LoadIR()
|
public async ValueTask<Result<bool>> LoadIR()
|
||||||
{
|
{
|
||||||
return await RunCommand(
|
return await RunCommand(JtagAddr.WRITE_CMD, 0x20_00_00_0A, 0x01_00_00_00);
|
||||||
JtagAddr.WRITE_CMD,
|
|
||||||
NumberProcessor.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_IR, JtagCmd.LEN_CMD_JTAG, 10, 28).Value,
|
|
||||||
0x01_00_00_00);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<uint>> LoadDRCareo()
|
|
||||||
{
|
|
||||||
var ret = await RunCommand(
|
|
||||||
JtagAddr.WRITE_CMD,
|
|
||||||
NumberProcessor.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 32, 28).Value,
|
|
||||||
0x01_00_00_00, JtagState.CMD_EXEC_FINISH);
|
|
||||||
|
|
||||||
if (ret.Value)
|
|
||||||
return await ReadFIFO(JtagAddr.READ_DATA);
|
|
||||||
else
|
|
||||||
throw new Exception("LoadDRCareo Failed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Result<uint>> ReadIDCode()
|
|
||||||
{
|
|
||||||
var ret = false;
|
|
||||||
|
|
||||||
ret = (await ClearAllRegisters()).Value;
|
|
||||||
ret = (await RunTest()).Value;
|
|
||||||
ret = (await DRIDcode()).Value;
|
|
||||||
ret = (await LoadIR()).Value;
|
|
||||||
ret = (await ClearWriteDataReg()).Value;
|
|
||||||
return (await LoadDRCareo()).Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Common;
|
using Common;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Router
|
namespace Router
|
||||||
{
|
{
|
||||||
struct Response
|
|
||||||
{
|
|
||||||
public bool IsSuccess;
|
|
||||||
public object? Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Web API
|
/// Web API
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -26,8 +21,8 @@ namespace Router
|
||||||
{
|
{
|
||||||
var endPoint = new IPEndPoint(IPAddress.Parse(address), port);
|
var endPoint = new IPEndPoint(IPAddress.Parse(address), port);
|
||||||
var ret = await UDPClientPool.SendStringAsync(endPoint, [text]);
|
var ret = await UDPClientPool.SendStringAsync(endPoint, [text]);
|
||||||
if (ret) { return Results.Json(new Response() { IsSuccess = true }); }
|
if (ret) { return Results.Json(true); }
|
||||||
else { return Results.Json(new Response() { IsSuccess = false }); }
|
else { return Results.Json(false); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,8 +46,8 @@ namespace Router
|
||||||
|
|
||||||
var endPoint = new IPEndPoint(IPAddress.Parse(address), port);
|
var endPoint = new IPEndPoint(IPAddress.Parse(address), port);
|
||||||
var ret = await UDPClientPool.SendAddrPackAsync(endPoint, new WebProtocol.SendAddrPackage(opts));
|
var ret = await UDPClientPool.SendAddrPackAsync(endPoint, new WebProtocol.SendAddrPackage(opts));
|
||||||
if (ret) { return Results.Json(new Response() { IsSuccess = true }); }
|
if (ret) { return Results.Json(true); }
|
||||||
else { return Results.Json(new Response() { IsSuccess = false }); }
|
else { return Results.Json(false); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async ValueTask<IResult> SendDataPackage(string address, int port, string data)
|
public static async ValueTask<IResult> SendDataPackage(string address, int port, string data)
|
||||||
|
@ -60,46 +55,12 @@ namespace Router
|
||||||
var endPoint = new IPEndPoint(IPAddress.Parse(address), port);
|
var endPoint = new IPEndPoint(IPAddress.Parse(address), port);
|
||||||
var ret = await UDPClientPool.SendDataPackAsync(endPoint,
|
var ret = await UDPClientPool.SendDataPackAsync(endPoint,
|
||||||
new WebProtocol.SendDataPackage(NumberProcessor.StringToBytes(data).Value));
|
new WebProtocol.SendDataPackage(NumberProcessor.StringToBytes(data).Value));
|
||||||
if (ret) { return Results.Json(new Response() { IsSuccess = true }); }
|
if (ret) { return Results.Json(true); }
|
||||||
else { return Results.Json(new Response() { IsSuccess = false }); }
|
else { return Results.Json(false); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Jtag
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 执行一个Jtag命令
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="address"> 设备地址 </param>
|
|
||||||
/// <param name="port"> 设备端口 </param>
|
|
||||||
/// <param name="hexDevAddr"> 16进制设备目的地址(Jtag) </param>
|
|
||||||
/// <param name="hexCmd"> 16进制命令 </param>
|
|
||||||
/// <param name="hexExRet"> 16进制预期结果 </param>
|
|
||||||
/// <returns> Response </returns>
|
|
||||||
public static async ValueTask<IResult> RunCommand(string address, int port, string hexDevAddr, string hexCmd, string hexExRet)
|
|
||||||
{
|
|
||||||
var jtagCtrl = new JtagController.Jtag(address, port);
|
|
||||||
var ret = await jtagCtrl.RunCommand(Convert.ToUInt32(hexDevAddr, 16), Convert.ToUInt32(hexCmd, 16), Convert.ToUInt32(hexExRet, 16));
|
|
||||||
|
|
||||||
|
|
||||||
if (ret.IsSuccessful) { return Results.Json(new Response() { IsSuccess = true }); }
|
|
||||||
else { return Results.Json(new Response() { IsSuccess = false, Data = ret.Error }); }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取Jtag ID Code
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="address"> 设备地址 </param>
|
|
||||||
/// <param name="port"> 设备端口 </param>
|
|
||||||
/// <returns> Response </returns>
|
|
||||||
public static async ValueTask<IResult> GetDeviceIDCode(string address, int port)
|
public static async ValueTask<IResult> GetDeviceIDCode(string address, int port)
|
||||||
{
|
{
|
||||||
var jtagCtrl = new JtagController.Jtag(address, port);
|
|
||||||
var ret = await jtagCtrl.ReadIDCode();
|
|
||||||
|
|
||||||
if (ret.IsSuccessful) { return Results.Json(new Response() { IsSuccess = true, Data = ret.Value }); }
|
|
||||||
else { return Results.Json(new Response() { IsSuccess = false, Data = ret.Error }); }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,43 +49,19 @@ namespace WebProtocol
|
||||||
/// <example> 0x10_00_00_00 </example>
|
/// <example> 0x10_00_00_00 </example>
|
||||||
public UInt32 address;
|
public UInt32 address;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert to Json String
|
|
||||||
/// </summary>
|
|
||||||
/// <returns> Json String </returns>
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this);
|
return JsonConvert.SerializeObject(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Package Options which to receive from boards </summary>
|
|
||||||
public struct RecvPackOptions
|
public struct RecvPackOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Task ID
|
|
||||||
/// </summary>
|
|
||||||
public byte commandID;
|
public byte commandID;
|
||||||
/// <summary>
|
|
||||||
/// Whether is succeed to finish command
|
|
||||||
/// </summary>
|
|
||||||
public bool isSuccess;
|
public bool isSuccess;
|
||||||
/// <summary>
|
public byte[] data;
|
||||||
/// Return Data
|
|
||||||
/// </summary>
|
|
||||||
public byte[]? data;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert to Json String
|
|
||||||
/// </summary>
|
|
||||||
/// <returns> Json String </returns>
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return JsonConvert.SerializeObject(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Package which send address to write </summary>
|
|
||||||
public struct SendAddrPackage
|
public struct SendAddrPackage
|
||||||
{
|
{
|
||||||
readonly byte sign = (byte)PackSign.SendAddr;
|
readonly byte sign = (byte)PackSign.SendAddr;
|
||||||
|
@ -251,7 +227,6 @@ namespace WebProtocol
|
||||||
RecvPackOptions opts;
|
RecvPackOptions opts;
|
||||||
opts.commandID = commandID;
|
opts.commandID = commandID;
|
||||||
opts.isSuccess = Convert.ToBoolean((resp >> 1) == 0b01 ? true : false);
|
opts.isSuccess = Convert.ToBoolean((resp >> 1) == 0b01 ? true : false);
|
||||||
opts.data = null;
|
|
||||||
|
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
||||||
|
import type { AppRouter } from '../server/router';
|
||||||
|
|
||||||
|
export const client = createTRPCProxyClient<AppRouter>({
|
||||||
|
links: [
|
||||||
|
httpBatchLink({
|
||||||
|
url: 'http://localhost:3002',
|
||||||
|
// You can pass any HTTP headers you wish here
|
||||||
|
async headers() {
|
||||||
|
return {
|
||||||
|
authorization: document.cookie,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
|
@ -1,18 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div class="card card-dash shadow-xl h-screen" :class="[sidebar.isClose ? 'w-31' : 'w-80']">
|
||||||
class="card card-dash shadow-xl h-screen"
|
<div class="card-body flex relative transition-all duration-500 ease-in-out">
|
||||||
:class="[sidebar.isClose ? 'w-31' : 'w-80']"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="card-body flex relative transition-all duration-500 ease-in-out"
|
|
||||||
>
|
|
||||||
<!-- Avatar and Name -->
|
<!-- Avatar and Name -->
|
||||||
<div class="relative" :class="sidebar.isClose ? 'h-50' : 'h-20'">
|
<div class="relative" :class="sidebar.isClose ? 'h-50' : 'h-20'">
|
||||||
<!-- Img -->
|
<!-- Img -->
|
||||||
<div
|
<div class="avatar h-10 fixed top-10" :class="sidebar.isClose ? 'left-10' : 'left-7'">
|
||||||
class="avatar h-10 fixed top-10"
|
|
||||||
:class="sidebar.isClose ? 'left-10' : 'left-7'"
|
|
||||||
>
|
|
||||||
<div class="rounded-full">
|
<div class="rounded-full">
|
||||||
<img src="../assets/user.svg" alt="User" />
|
<img src="../assets/user.svg" alt="User" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,28 +18,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Toggle Button -->
|
<!-- Toggle Button -->
|
||||||
<button
|
<button class="btn btn-square rounded-lg p-2 m-3 fixed"
|
||||||
class="btn btn-square rounded-lg p-2 m-3 fixed"
|
:class="sidebar.isClose ? 'left-7 top-23' : 'left-60 top-7'" @click="sidebar.toggleSidebar">
|
||||||
:class="sidebar.isClose ? 'left-7 top-23' : 'left-60 top-7'"
|
<svg t="1741694970690" :class="sidebar.isClose ? 'rotate-0' : 'rotate-540'" class="icon" viewBox="0 0 1024 1024"
|
||||||
@click="sidebar.toggleSidebar"
|
version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4546" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
>
|
width="200" height="200">
|
||||||
<svg
|
|
||||||
t="1741694970690"
|
|
||||||
:class="sidebar.isClose ? 'rotate-0' : 'rotate-540'"
|
|
||||||
class="icon"
|
|
||||||
viewBox="0 0 1024 1024"
|
|
||||||
version="1.1"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
p-id="4546"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
width="200"
|
|
||||||
height="200"
|
|
||||||
>
|
|
||||||
<path
|
<path
|
||||||
d="M803.758 514.017c-0.001-0.311-0.013-0.622-0.018-0.933-0.162-23.974-9.386-47.811-27.743-65.903-0.084-0.082-0.172-0.157-0.256-0.239-0.154-0.154-0.296-0.315-0.451-0.468L417.861 94.096c-37.685-37.153-99.034-37.476-136.331-0.718-37.297 36.758-36.979 97.231 0.707 134.384l290.361 286.257-290.362 286.257c-37.685 37.153-38.004 97.625-0.707 134.383 37.297 36.758 98.646 36.435 136.331-0.718l357.43-352.378c0.155-0.153 0.297-0.314 0.451-0.468 0.084-0.082 0.172-0.157 0.256-0.239 18.354-18.089 27.578-41.922 27.743-65.892 0.004-0.315 0.017-0.631 0.018-0.947z"
|
d="M803.758 514.017c-0.001-0.311-0.013-0.622-0.018-0.933-0.162-23.974-9.386-47.811-27.743-65.903-0.084-0.082-0.172-0.157-0.256-0.239-0.154-0.154-0.296-0.315-0.451-0.468L417.861 94.096c-37.685-37.153-99.034-37.476-136.331-0.718-37.297 36.758-36.979 97.231 0.707 134.384l290.361 286.257-290.362 286.257c-37.685 37.153-38.004 97.625-0.707 134.383 37.297 36.758 98.646 36.435 136.331-0.718l357.43-352.378c0.155-0.153 0.297-0.314 0.451-0.468 0.084-0.082 0.172-0.157 0.256-0.239 18.354-18.089 27.578-41.922 27.743-65.892 0.004-0.315 0.017-0.631 0.018-0.947z"
|
||||||
:fill="theme.isLightTheme() ? '#828282' : '#C0C3C8'"
|
:fill="theme.isLightTheme() ? '#828282' : '#C0C3C8'" p-id="4547"></path>
|
||||||
p-id="4547"
|
|
||||||
></path>
|
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
@ -56,33 +34,15 @@
|
||||||
<ul class="menu h-full w-full">
|
<ul class="menu h-full w-full">
|
||||||
<li v-for="item in props.items" class="text-xl my-1">
|
<li v-for="item in props.items" class="text-xl my-1">
|
||||||
<a @click="router.push(item.page)">
|
<a @click="router.push(item.page)">
|
||||||
<svg
|
<svg t="1741694797806" class="icon h-[1.5em] w-[1.5em] opacity-50 mx-1" viewBox="0 0 1024 1024"
|
||||||
t="1741694797806"
|
version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2622" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
class="icon h-[1.5em] w-[1.5em] opacity-50 mx-1"
|
width="200" height="200">
|
||||||
viewBox="0 0 1024 1024"
|
<path d="M192 192m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" p-id="2623"></path>
|
||||||
version="1.1"
|
<path d="M192 512m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" p-id="2624"></path>
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
<path d="M192 832m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z" p-id="2625"></path>
|
||||||
p-id="2622"
|
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
||||||
width="200"
|
|
||||||
height="200"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M192 192m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z"
|
|
||||||
p-id="2623"
|
|
||||||
></path>
|
|
||||||
<path
|
|
||||||
d="M192 512m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z"
|
|
||||||
p-id="2624"
|
|
||||||
></path>
|
|
||||||
<path
|
|
||||||
d="M192 832m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0Z"
|
|
||||||
p-id="2625"
|
|
||||||
></path>
|
|
||||||
<path
|
<path
|
||||||
d="M864 160H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 480H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 800H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32z"
|
d="M864 160H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 480H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 800H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32z"
|
||||||
p-id="2626"
|
p-id="2626"></path>
|
||||||
></path>
|
|
||||||
</svg>
|
</svg>
|
||||||
<Transition>
|
<Transition>
|
||||||
<p class="break-keep" v-if="!sidebar.isClose">{{ item.text }}</p>
|
<p class="break-keep" v-if="!sidebar.isClose">{{ item.text }}</p>
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { client } from "@/client";
|
||||||
|
import { TRPCClientError } from "@trpc/client";
|
||||||
|
|
||||||
var bitstream = null;
|
var bitstream = null;
|
||||||
|
|
||||||
function handleFileChange(event: Event): void {
|
function handleFileChange(event: Event): void {
|
||||||
|
@ -40,7 +43,20 @@ function handleFileChange(event: Event): void {
|
||||||
console.log(bitstream);
|
console.log(bitstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadBitStream() {}
|
async function uploadBitStream() {
|
||||||
|
try {
|
||||||
|
const serverStatus = await client.api.status.query();
|
||||||
|
if (serverStatus != "OK") {
|
||||||
|
throw new Error("Server Busy...");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof TRPCClientError) {
|
||||||
|
console.error("Can't connect to Server!");
|
||||||
|
} else {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function checkFileType(file: File) { }
|
function checkFileType(file: File) { }
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="h-screen w-screen flex justify-center">
|
|
||||||
<div class="h-full w-32"></div>
|
|
||||||
|
|
||||||
<div class="h-full w-[70%] shadow-2xl">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup></script>
|
<script lang="ts" setup>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
<style scoped lang="postcss">
|
<style scoped lang="postcss">
|
||||||
@import "../assets/main.css";
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue