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
|
node_modules
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vscode
|
||||||
dist
|
dist
|
||||||
**/wwwroot
|
**/wwwroot
|
||||||
dist-ssr
|
dist-ssr
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]
|
||||||
isSelfContained := "false"
|
isSelfContained := "false"
|
||||||
|
|
||||||
@_show-dir:
|
@_show-dir:
|
||||||
|
@ -16,7 +17,7 @@ clean:
|
||||||
|
|
||||||
update:
|
update:
|
||||||
npm install
|
npm install
|
||||||
cd server && dotnet restore
|
dotnet restore ./server/server.csproj
|
||||||
git submodule update --init --remote --recursive
|
git submodule update --init --remote --recursive
|
||||||
|
|
||||||
# 生成Restful API到网页客户端
|
# 生成Restful API到网页客户端
|
||||||
|
@ -44,7 +45,7 @@ dev: dev-server
|
||||||
|
|
||||||
# 测试服务器
|
# 测试服务器
|
||||||
dev-server: _show-dir
|
dev-server: _show-dir
|
||||||
cd server && dotnet run --watch
|
dotnet run --watch --project ./server/server.csproj
|
||||||
|
|
||||||
# 运行网页客户端
|
# 运行网页客户端
|
||||||
dev-web:
|
dev-web:
|
||||||
|
|
|
@ -19,14 +19,14 @@ public class BoundaryScanRegs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("cell_number")]
|
[JsonProperty("cell_number")]
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public int? CellNumber { get; set; }
|
public int CellNumber { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// [TODO:description]
|
/// [TODO:description]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("cell_name")]
|
[JsonProperty("cell_name")]
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public string? CellName { get; set; }
|
public string CellName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// [TODO:description]
|
/// [TODO:description]
|
||||||
|
@ -124,17 +124,42 @@ public class Parser
|
||||||
/// [TODO:description]
|
/// [TODO:description]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>[TODO:return]</returns>
|
/// <returns>[TODO:return]</returns>
|
||||||
public Optional<List<BoundaryScanRegs.CellEntry>> GetBoundaryLogicalPorts()
|
public Optional<List<BoundaryScanRegs.CellEntry>> GetBoundaryPorts()
|
||||||
{
|
{
|
||||||
var registers = this.BoundaryRegsDesp["registers"]?.ToList();
|
var registers = this.BoundaryRegsDesp["registers"]?.ToList();
|
||||||
if (registers is null) return new();
|
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;
|
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()
|
// public Result<string> GetLogicalPorts()
|
||||||
|
|
|
@ -338,12 +338,12 @@ public class JtagController : ControllerBase
|
||||||
/// <param name="address">[TODO:parameter]</param>
|
/// <param name="address">[TODO:parameter]</param>
|
||||||
/// <param name="port">[TODO:parameter]</param>
|
/// <param name="port">[TODO:parameter]</param>
|
||||||
/// <returns>[TODO:return]</returns>
|
/// <returns>[TODO:return]</returns>
|
||||||
[HttpPost("BoundaryScan")]
|
[HttpPost("BoundaryScanAllPorts")]
|
||||||
[EnableCors("Users")]
|
[EnableCors("Users")]
|
||||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
[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 jtagCtrl = new JtagClient.Jtag(address, port);
|
||||||
var ret = await jtagCtrl.BoundaryScan();
|
var ret = await jtagCtrl.BoundaryScan();
|
||||||
|
@ -356,6 +356,31 @@ public class JtagController : ControllerBase
|
||||||
|
|
||||||
return TypedResults.Ok(ret.Value);
|
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>
|
/// <summary>
|
||||||
|
@ -750,94 +775,25 @@ public class DDSController : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// /// <summary>
|
/// <summary>
|
||||||
// /// [TODO:description]
|
/// [TODO:description]
|
||||||
// /// </summary>
|
/// </summary>
|
||||||
// [ApiController]
|
[ApiController]
|
||||||
// [Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
// public class BsdlParserController : ControllerBase
|
public class BsdlParserController : ControllerBase
|
||||||
// {
|
{
|
||||||
// private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
//
|
|
||||||
// const string BSDL_PATH = "bsdl";
|
[EnableCors("Development")]
|
||||||
//
|
[HttpGet("GetBoundaryLogicalPorts")]
|
||||||
// /// <summary>
|
public IResult GetBoundaryLogicalPorts()
|
||||||
// /// [TODO:description]
|
{
|
||||||
// /// </summary>
|
var parser = new BsdlParser.Parser();
|
||||||
// /// <param name="address">[TODO:parameter]</param>
|
var ret = parser.GetBoundaryLogicalPorts();
|
||||||
// /// <param name="file">[TODO:parameter]</param>
|
if (ret.IsNull) return TypedResults.InternalServerError("Get Null");
|
||||||
// /// <returns>[TODO:return]</returns>
|
return TypedResults.Ok(ret.Value);
|
||||||
// [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>
|
/// <summary>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using BsdlParser;
|
||||||
using DotNext;
|
using DotNext;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WebProtocol;
|
using WebProtocol;
|
||||||
|
@ -818,8 +819,24 @@ public class Jtag
|
||||||
return bitArray;
|
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