feat: asp serve frontend static files
This commit is contained in:
@@ -8,6 +8,44 @@ using WebProtocol;
|
||||
|
||||
namespace server.Controllers;
|
||||
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// public class HomeController : ControllerBase
|
||||
// {
|
||||
// private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
//
|
||||
// string INDEX_HTML_PATH = Path.Combine(Environment.CurrentDirectory, "index.html");
|
||||
//
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// /// <returns>[TODO:return]</returns>
|
||||
// [HttpGet("/")]
|
||||
// public IResult Index()
|
||||
// {
|
||||
// return TypedResults.Content("Hello", "text/html");
|
||||
// }
|
||||
//
|
||||
// // [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
// // public IResult Error()
|
||||
// // {
|
||||
// // return TypedResults.Ok();
|
||||
// // }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// /// <returns>[TODO:return]</returns>
|
||||
// [HttpGet("/hello")]
|
||||
// [HttpPost("/hello")]
|
||||
// public IActionResult Hello()
|
||||
// {
|
||||
// string randomString = Guid.NewGuid().ToString();
|
||||
// return this.Ok($"Hello World! GUID: {randomString}");
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// UDP API
|
||||
/// </summary>
|
||||
@@ -346,6 +384,32 @@ public class JtagController : ControllerBase
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <param name="portNum">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
[HttpPost("BoundaryScan")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> BoundaryScan(string address, int port, int portNum)
|
||||
{
|
||||
var jtagCtrl = new JtagClient.Jtag(address, port);
|
||||
var ret = await jtagCtrl.BoundaryScan(portNum);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
if (ret.Error is ArgumentException)
|
||||
return TypedResults.BadRequest(ret.Error);
|
||||
else return TypedResults.InternalServerError(ret.Error);
|
||||
}
|
||||
|
||||
return TypedResults.Ok(ret.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -368,6 +368,21 @@ public class JtagStatusReg
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public class JtagBoundaryRegister
|
||||
{
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public int PortNum { get; set; }
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public UInt32[] PortStatus { get; set; } = new UInt32[] { };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jtag控制器
|
||||
/// </summary>
|
||||
@@ -730,13 +745,13 @@ public class Jtag
|
||||
return true;
|
||||
}
|
||||
|
||||
async ValueTask<Result<UInt32>> LoadDRCareOutput(UInt32 bytesLen)
|
||||
async ValueTask<Result<UInt32>> LoadDRCareOutput(UInt32 UInt32Num)
|
||||
{
|
||||
if (bytesLen > Math.Pow(2, 28)) return new(new Exception("Length is over 2^(28 - 3)"));
|
||||
if (UInt32Num > Math.Pow(2, 23)) return new(new Exception("Length is over 2^(28 - 5)"));
|
||||
|
||||
var ret = await WriteFIFO(
|
||||
JtagAddr.WRITE_CMD,
|
||||
Common.Number.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 8 * bytesLen, 28).Value,
|
||||
Common.Number.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 32 * UInt32Num, 28).Value,
|
||||
0x01_00_00_00, JtagState.CMD_EXEC_FINISH);
|
||||
|
||||
if (ret.Value)
|
||||
@@ -745,6 +760,31 @@ public class Jtag
|
||||
return new(new Exception("LoadDRCareo Failed!"));
|
||||
}
|
||||
|
||||
async ValueTask<Result<UInt32[]>> LoadDRCareOutputArray(UInt32 UInt32Num)
|
||||
{
|
||||
if (UInt32Num > Math.Pow(2, 23)) return new(new Exception("Length is over 2^(28 - 5)"));
|
||||
|
||||
var ret = await WriteFIFO(
|
||||
JtagAddr.WRITE_CMD,
|
||||
Common.Number.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 32 * UInt32Num, 28).Value,
|
||||
0x01_00_00_00, JtagState.CMD_EXEC_FINISH);
|
||||
|
||||
if (ret.Value)
|
||||
{
|
||||
var array = new UInt32[UInt32Num];
|
||||
for (int i = 0; i < UInt32Num; i++)
|
||||
{
|
||||
var retData = await ReadFIFO(JtagAddr.READ_DATA);
|
||||
if (!retData.IsSuccessful)
|
||||
return new(new Exception("Read FIFO failed when Load DR"));
|
||||
array[i] = retData.Value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
else
|
||||
return new(new Exception("LoadDRCareo Failed!"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取 JTAG 设备的 ID 代码
|
||||
/// </summary>
|
||||
@@ -774,7 +814,7 @@ public class Jtag
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Clear Write Registers Failed"));
|
||||
|
||||
var retData = await LoadDRCareOutput(4);
|
||||
var retData = await LoadDRCareOutput(1);
|
||||
if (!retData.IsSuccessful)
|
||||
{
|
||||
return new(new Exception("Get ID Code Failed"));
|
||||
@@ -812,11 +852,9 @@ public class Jtag
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Clear Write Registers Failed"));
|
||||
|
||||
var retData = await LoadDRCareOutput(4);
|
||||
var retData = await LoadDRCareOutput(1);
|
||||
if (!retData.IsSuccessful)
|
||||
{
|
||||
return new(new Exception("Read Status Reg Failed"));
|
||||
}
|
||||
|
||||
return retData.Value;
|
||||
}
|
||||
@@ -901,4 +939,46 @@ public class Jtag
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="portNum">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public async ValueTask<Result<JtagBoundaryRegister>> BoundaryScan(int portNum)
|
||||
{
|
||||
if (portNum <= 0)
|
||||
return new(new ArgumentException("The number of port couldn't be negative", nameof(portNum)));
|
||||
|
||||
// Clear Data
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address);
|
||||
|
||||
logger.Trace($"Clear up udp server {this.address} receive data");
|
||||
|
||||
Result<bool> ret;
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
|
||||
ret = await RunTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
||||
|
||||
logger.Trace("Jtag initialize");
|
||||
|
||||
ret = await ExecRDCmd(JtagCmd.JTAG_DR_SAMPLE);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_JRST Failed"));
|
||||
|
||||
var retData = await LoadDRCareOutputArray(((uint)(portNum % 32 == 0 ? portNum / 32 : portNum / 32 + 1)));
|
||||
if (!retData.IsSuccessful)
|
||||
return new(new Exception("Read Status Reg Failed"));
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
|
||||
return new JtagBoundaryRegister() { PortNum = portNum, PortStatus = retData.Value };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user