feat: backend finish boundary scan web api
This commit is contained in:
parent
351a230107
commit
4885447c2b
|
@ -9,6 +9,7 @@ lerna-debug.log*
|
|||
|
||||
node_modules
|
||||
.DS_Store
|
||||
.vscode
|
||||
dist
|
||||
**/wwwroot
|
||||
dist-ssr
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
|
||||
isSelfContained := "false"
|
||||
|
||||
@_show-dir:
|
||||
|
@ -16,7 +17,7 @@ clean:
|
|||
|
||||
update:
|
||||
npm install
|
||||
cd server && dotnet restore
|
||||
dotnet restore ./server/server.csproj
|
||||
git submodule update --init --remote --recursive
|
||||
|
||||
# 生成Restful API到网页客户端
|
||||
|
@ -44,7 +45,7 @@ dev: dev-server
|
|||
|
||||
# 测试服务器
|
||||
dev-server: _show-dir
|
||||
cd server && dotnet run --watch
|
||||
dotnet run --watch --project ./server/server.csproj
|
||||
|
||||
# 运行网页客户端
|
||||
dev-web:
|
||||
|
|
|
@ -19,14 +19,14 @@ public class BoundaryScanRegs
|
|||
/// </summary>
|
||||
[JsonProperty("cell_number")]
|
||||
[JsonRequired]
|
||||
public int? CellNumber { get; set; }
|
||||
public int CellNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
[JsonProperty("cell_name")]
|
||||
[JsonRequired]
|
||||
public string? CellName { get; set; }
|
||||
public string CellName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
|
@ -124,17 +124,42 @@ public class Parser
|
|||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public Optional<List<BoundaryScanRegs.CellEntry>> GetBoundaryLogicalPorts()
|
||||
public Optional<List<BoundaryScanRegs.CellEntry>> GetBoundaryPorts()
|
||||
{
|
||||
var registers = this.BoundaryRegsDesp["registers"]?.ToList();
|
||||
if (registers is null) return new();
|
||||
|
||||
var cellList = registers.Where((item) =>
|
||||
var cellList = new List<BoundaryScanRegs.CellEntry>();
|
||||
foreach (var item in registers)
|
||||
{
|
||||
var cell = item.ToObject<BoundaryScanRegs.CellEntry>();
|
||||
if (cell is null) return new();
|
||||
cellList.Add(cell);
|
||||
}
|
||||
|
||||
return cellList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public Optional<List<BoundaryScanRegs.CellEntry>> GetBoundaryLogicalPorts()
|
||||
{
|
||||
var registers = this.BoundaryRegsDesp["registers"]?.ToList().Where((item)=>{
|
||||
return item["port_id"] is not null;
|
||||
});
|
||||
if (cellList is null) return new();
|
||||
if (registers is null) return new();
|
||||
|
||||
var cellList = new List<BoundaryScanRegs.CellEntry>();
|
||||
foreach (var item in registers)
|
||||
{
|
||||
var cell = item.ToObject<BoundaryScanRegs.CellEntry>();
|
||||
if (cell is null) return new();
|
||||
cellList.Add(cell);
|
||||
}
|
||||
|
||||
return cellList;
|
||||
}
|
||||
|
||||
// public Result<string> GetLogicalPorts()
|
||||
|
|
|
@ -338,12 +338,12 @@ public class JtagController : ControllerBase
|
|||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
[HttpPost("BoundaryScan")]
|
||||
[HttpPost("BoundaryScanAllPorts")]
|
||||
[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)
|
||||
public async ValueTask<IResult> BoundaryScanAllPorts(string address, int port)
|
||||
{
|
||||
var jtagCtrl = new JtagClient.Jtag(address, port);
|
||||
var ret = await jtagCtrl.BoundaryScan();
|
||||
|
@ -356,6 +356,31 @@ public class JtagController : ControllerBase
|
|||
|
||||
return TypedResults.Ok(ret.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
[HttpPost("BoundaryScanLogicalPorts")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> BoundaryScanLogicalPorts(string address, int port)
|
||||
{
|
||||
var jtagCtrl = new JtagClient.Jtag(address, port);
|
||||
var ret = await jtagCtrl.BoundaryScanLogicalPorts();
|
||||
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>
|
||||
|
@ -750,94 +775,25 @@ public class DDSController : ControllerBase
|
|||
}
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// [ApiController]
|
||||
// [Route("api/[controller]")]
|
||||
// public class BsdlParserController : ControllerBase
|
||||
// {
|
||||
// private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
//
|
||||
// const string BSDL_PATH = "bsdl";
|
||||
//
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// /// <param name="address">[TODO:parameter]</param>
|
||||
// /// <param name="file">[TODO:parameter]</param>
|
||||
// /// <returns>[TODO:return]</returns>
|
||||
// [EnableCors("Users")]
|
||||
// [HttpPost("UploadBsdlModelFile")]
|
||||
// public async ValueTask<IResult> UploadBsdlModelFile(string address, IFormFile file)
|
||||
// {
|
||||
// if (file == null || file.Length == 0)
|
||||
// return TypedResults.BadRequest("未选择文件");
|
||||
//
|
||||
// // 生成安全的文件名(避免路径遍历攻击)
|
||||
// var fileName = Path.GetRandomFileName();
|
||||
// var uploadsFolder = Path.Combine(Environment.CurrentDirectory, $"{BSDL_PATH}/{address}");
|
||||
//
|
||||
// // 如果存在文件,则删除原文件再上传
|
||||
// if (Directory.Exists(uploadsFolder))
|
||||
// {
|
||||
// Directory.Delete(uploadsFolder, true);
|
||||
// }
|
||||
// Directory.CreateDirectory(uploadsFolder);
|
||||
//
|
||||
// var filePath = Path.Combine(uploadsFolder, fileName);
|
||||
//
|
||||
// using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
// {
|
||||
// await file.CopyToAsync(stream);
|
||||
// }
|
||||
//
|
||||
// logger.Info($"Device {address} Upload Bitstream Successfully");
|
||||
// return TypedResults.Ok(true);
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// /// <param name="address">[TODO:parameter]</param>
|
||||
// /// <returns>[TODO:return]</returns>
|
||||
// [EnableCors("Users")]
|
||||
// [HttpGet("GetLogicalPortsDescription")]
|
||||
// public IResult GetLogicalPortsDescription(string address)
|
||||
// {
|
||||
// // 检查文件
|
||||
// var fileDir = Path.Combine(Environment.CurrentDirectory, $"{BSDL_PATH}/{address}");
|
||||
// if (!Directory.Exists(fileDir))
|
||||
// return TypedResults.BadRequest("Empty bitstream, Please upload it first");
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// // 读取文件
|
||||
// var filePath = Directory.GetFiles(fileDir)[0];
|
||||
//
|
||||
// // 下载比特流
|
||||
// var parser = new BsdlParser.Parser(filePath);
|
||||
// var ret = parser.GetLogicalPorts();
|
||||
//
|
||||
// if (ret.IsSuccessful)
|
||||
// {
|
||||
// logger.Info($"Device {address} Update bitstream successfully");
|
||||
// return TypedResults.Ok(ret.Value);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// logger.Error(ret.Error);
|
||||
// return TypedResults.InternalServerError(ret.Error);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// catch (Exception error)
|
||||
// {
|
||||
// return TypedResults.InternalServerError(error);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class BsdlParserController : ControllerBase
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
[EnableCors("Development")]
|
||||
[HttpGet("GetBoundaryLogicalPorts")]
|
||||
public IResult GetBoundaryLogicalPorts()
|
||||
{
|
||||
var parser = new BsdlParser.Parser();
|
||||
var ret = parser.GetBoundaryLogicalPorts();
|
||||
if (ret.IsNull) return TypedResults.InternalServerError("Get Null");
|
||||
return TypedResults.Ok(ret.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.Net;
|
||||
using BsdlParser;
|
||||
using DotNext;
|
||||
using Newtonsoft.Json;
|
||||
using WebProtocol;
|
||||
|
@ -818,8 +819,24 @@ public class Jtag
|
|||
return bitArray;
|
||||
}
|
||||
|
||||
// public async ValueTask<Result<BitArray>> BoundaryScanLogicalPorts()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public async ValueTask<Result<Dictionary<string, bool>>> BoundaryScanLogicalPorts()
|
||||
{
|
||||
var bitArray = await BoundaryScan();
|
||||
if (!bitArray.IsSuccessful) return new(bitArray.Error);
|
||||
|
||||
var paser = new BsdlParser.Parser();
|
||||
var cellList = paser.GetBoundaryLogicalPorts();
|
||||
if (cellList.IsNull) return new(new Exception("Get boundary logical ports failed"));
|
||||
|
||||
var portStatus = new Dictionary<string, bool>();
|
||||
foreach (var cell in cellList.Value) {
|
||||
portStatus.Add(cell.PortID ?? "UnknownPortID", bitArray.Value[cell.CellNumber]);
|
||||
}
|
||||
|
||||
return portStatus;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue