fix: mother board reactive problem
This commit is contained in:
parent
1eded97c76
commit
c39f688115
|
@ -20,9 +20,7 @@ update:
|
||||||
|
|
||||||
# 生成Restful API到网页客户端
|
# 生成Restful API到网页客户端
|
||||||
gen-api:
|
gen-api:
|
||||||
cd server && dotnet run &
|
npm run gen-api
|
||||||
npx nswag openapi2tsclient /input:http://localhost:5000/swagger/v1/swagger.json /output:src/APIClient.ts
|
|
||||||
pkill server
|
|
||||||
|
|
||||||
# 构建服务器,包含win与linux平台
|
# 构建服务器,包含win与linux平台
|
||||||
[working-directory: "server"]
|
[working-directory: "server"]
|
||||||
|
|
|
@ -8,44 +8,6 @@ using WebProtocol;
|
||||||
|
|
||||||
namespace server.Controllers;
|
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>
|
/// <summary>
|
||||||
/// UDP API
|
/// UDP API
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -524,9 +486,9 @@ public class RemoteUpdater : ControllerBase
|
||||||
/// <param name="bitstreamNum"> 比特流位号 </param>
|
/// <param name="bitstreamNum"> 比特流位号 </param>
|
||||||
[HttpPost("DownloadBitstream")]
|
[HttpPost("DownloadBitstream")]
|
||||||
[EnableCors("Users")]
|
[EnableCors("Users")]
|
||||||
[ProducesResponseType(typeof(bool),StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
public async ValueTask<IResult> UpdateBitstream(string address, int port, int bitstreamNum)
|
public async ValueTask<IResult> UpdateBitstream(string address, int port, int bitstreamNum)
|
||||||
{
|
{
|
||||||
// 检查文件
|
// 检查文件
|
||||||
|
@ -543,7 +505,7 @@ public class RemoteUpdater : ControllerBase
|
||||||
if (!fileBytes.IsSuccessful) return TypedResults.InternalServerError(fileBytes.Error);
|
if (!fileBytes.IsSuccessful) return TypedResults.InternalServerError(fileBytes.Error);
|
||||||
|
|
||||||
// 下载比特流
|
// 下载比特流
|
||||||
var remoteUpdater = new RemoteUpdate.RemoteUpdateClient(address, port);
|
var remoteUpdater = new RemoteUpdateClient.RemoteUpdater(address, port);
|
||||||
var ret = await remoteUpdater.UpdateBitstream(bitstreamNum, fileBytes.Value);
|
var ret = await remoteUpdater.UpdateBitstream(bitstreamNum, fileBytes.Value);
|
||||||
|
|
||||||
if (ret.IsSuccessful)
|
if (ret.IsSuccessful)
|
||||||
|
@ -574,9 +536,9 @@ public class RemoteUpdater : ControllerBase
|
||||||
/// <returns>总共上传比特流的数量</returns>
|
/// <returns>总共上传比特流的数量</returns>
|
||||||
[HttpPost("DownloadMultiBitstreams")]
|
[HttpPost("DownloadMultiBitstreams")]
|
||||||
[EnableCors("Users")]
|
[EnableCors("Users")]
|
||||||
[ProducesResponseType(typeof(int),StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
public async ValueTask<IResult> DownloadMultiBitstreams(string address, int port, int? bitstreamNum)
|
public async ValueTask<IResult> DownloadMultiBitstreams(string address, int port, int? bitstreamNum)
|
||||||
{
|
{
|
||||||
// 检查文件
|
// 检查文件
|
||||||
|
@ -603,7 +565,7 @@ public class RemoteUpdater : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下载比特流
|
// 下载比特流
|
||||||
var remoteUpdater = new RemoteUpdate.RemoteUpdateClient(address, port);
|
var remoteUpdater = new RemoteUpdateClient.RemoteUpdater(address, port);
|
||||||
{
|
{
|
||||||
var ret = await remoteUpdater.UploadBitstreams(bitstreams[0], bitstreams[1], bitstreams[2], bitstreams[3]);
|
var ret = await remoteUpdater.UploadBitstreams(bitstreams[0], bitstreams[1], bitstreams[2], bitstreams[3]);
|
||||||
if (!ret.IsSuccessful) return TypedResults.InternalServerError(ret.Error);
|
if (!ret.IsSuccessful) return TypedResults.InternalServerError(ret.Error);
|
||||||
|
@ -634,12 +596,12 @@ public class RemoteUpdater : ControllerBase
|
||||||
/// <returns>操作结果</returns>
|
/// <returns>操作结果</returns>
|
||||||
[HttpPost("HotResetBitstream")]
|
[HttpPost("HotResetBitstream")]
|
||||||
[EnableCors("Users")]
|
[EnableCors("Users")]
|
||||||
[ProducesResponseType(typeof(bool),StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
public async ValueTask<IResult> HotResetBitstream(string address, int port, int bitstreamNum)
|
public async ValueTask<IResult> HotResetBitstream(string address, int port, int bitstreamNum)
|
||||||
{
|
{
|
||||||
var remoteUpdater = new RemoteUpdate.RemoteUpdateClient(address, port);
|
var remoteUpdater = new RemoteUpdateClient.RemoteUpdater(address, port);
|
||||||
var ret = await remoteUpdater.HotResetBitstream(bitstreamNum);
|
var ret = await remoteUpdater.HotResetBitstream(bitstreamNum);
|
||||||
|
|
||||||
if (ret.IsSuccessful)
|
if (ret.IsSuccessful)
|
||||||
|
@ -662,12 +624,12 @@ public class RemoteUpdater : ControllerBase
|
||||||
/// <returns>[TODO:return]</returns>
|
/// <returns>[TODO:return]</returns>
|
||||||
[HttpPost("GetFirmwareVersion")]
|
[HttpPost("GetFirmwareVersion")]
|
||||||
[EnableCors("Users")]
|
[EnableCors("Users")]
|
||||||
[ProducesResponseType(typeof(UInt32),StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(UInt32), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
public async ValueTask<IResult> GetFirmwareVersion(string address, int port)
|
public async ValueTask<IResult> GetFirmwareVersion(string address, int port)
|
||||||
{
|
{
|
||||||
var remoteUpdater = new RemoteUpdate.RemoteUpdateClient(address, port);
|
var remoteUpdater = new RemoteUpdateClient.RemoteUpdater(address, port);
|
||||||
var ret = await remoteUpdater.GetVersion();
|
var ret = await remoteUpdater.GetVersion();
|
||||||
|
|
||||||
if (ret.IsSuccessful)
|
if (ret.IsSuccessful)
|
||||||
|
@ -681,7 +643,111 @@ public class RemoteUpdater : ControllerBase
|
||||||
return TypedResults.InternalServerError(ret.Error);
|
return TypedResults.InternalServerError(ret.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class DDSController : ControllerBase
|
||||||
|
{
|
||||||
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address">[TODO:parameter]</param>
|
||||||
|
/// <param name="port">[TODO:parameter]</param>
|
||||||
|
/// <param name="channelNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="waveNum">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
[HttpPost("SetWaveNum")]
|
||||||
|
[EnableCors("Users")]
|
||||||
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
|
public async ValueTask<IResult> SetWaveNum(string address, int port, int channelNum, int waveNum)
|
||||||
|
{
|
||||||
|
var dds = new DDSClient.DDS(address, port);
|
||||||
|
|
||||||
|
var ret = await dds.SetWaveNum(channelNum, waveNum);
|
||||||
|
if (ret.IsSuccessful)
|
||||||
|
{
|
||||||
|
logger.Info($"Device {address} set output wave num successfully");
|
||||||
|
return TypedResults.Ok(ret.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error(ret.Error);
|
||||||
|
return TypedResults.InternalServerError(ret.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address">[TODO:parameter]</param>
|
||||||
|
/// <param name="port">[TODO:parameter]</param>
|
||||||
|
/// <param name="channelNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="waveNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="step">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
[HttpPost("SetFreq")]
|
||||||
|
[EnableCors("Users")]
|
||||||
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
|
public async ValueTask<IResult> SetFreq(string address, int port, int channelNum, int waveNum, UInt32 step)
|
||||||
|
{
|
||||||
|
var dds = new DDSClient.DDS(address, port);
|
||||||
|
|
||||||
|
var ret = await dds.SetFreq(channelNum, waveNum, step);
|
||||||
|
if (ret.IsSuccessful)
|
||||||
|
{
|
||||||
|
logger.Info($"Device {address} set output freqency successfully");
|
||||||
|
return TypedResults.Ok(ret.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error(ret.Error);
|
||||||
|
return TypedResults.InternalServerError(ret.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address">[TODO:parameter]</param>
|
||||||
|
/// <param name="port">[TODO:parameter]</param>
|
||||||
|
/// <param name="channelNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="waveNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="phase">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
[HttpPost("SetPhase")]
|
||||||
|
[EnableCors("Users")]
|
||||||
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||||
|
public async ValueTask<IResult> SetPhase(string address, int port, int channelNum, int waveNum, int phase)
|
||||||
|
{
|
||||||
|
var dds = new DDSClient.DDS(address, port);
|
||||||
|
|
||||||
|
var ret = await dds.SetPhase(channelNum, waveNum, phase);
|
||||||
|
if (ret.IsSuccessful)
|
||||||
|
{
|
||||||
|
logger.Info($"Device {address} set output phase successfully");
|
||||||
|
return TypedResults.Ok(ret.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error(ret.Error);
|
||||||
|
return TypedResults.InternalServerError(ret.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,170 @@
|
||||||
|
using System.Net;
|
||||||
|
using DotNext;
|
||||||
|
|
||||||
|
namespace DDSClient;
|
||||||
|
|
||||||
|
static class DDSAddr
|
||||||
|
{
|
||||||
|
/*地址定义:(以2路输出,4波形存储为例)
|
||||||
|
00 R/W CHANNEL0 wave_sel
|
||||||
|
01 R/W CHANNEL0 STORE0 freq_ctrl
|
||||||
|
02 R/W CHANNEL0 STORE1 freq_ctrl
|
||||||
|
03 R/W CHANNEL0 STORE2 freq_ctrl
|
||||||
|
04 R/W CHANNEL0 STORE3 freq_ctrl
|
||||||
|
05 R/W CHANNEL0 STORE0 phase_ctrl
|
||||||
|
06 R/W CHANNEL0 STORE1 phase_ctrl
|
||||||
|
07 R/W CHANNEL0 STORE2 phase_ctrl
|
||||||
|
08 R/W CHANNEL0 STORE3 phase_ctrl
|
||||||
|
09 R/W CHANNEL0 dds_wr_enable
|
||||||
|
0A WO CHANNEL0 data
|
||||||
|
|
||||||
|
10 R/W CHANNEL1 wave_sel
|
||||||
|
11 R/W CHANNEL1 STORE0 freq_ctrl
|
||||||
|
12 R/W CHANNEL1 STORE1 freq_ctrl
|
||||||
|
13 R/W CHANNEL1 STORE2 freq_ctrl
|
||||||
|
14 R/W CHANNEL1 STORE3 freq_ctrl
|
||||||
|
15 R/W CHANNEL1 STORE0 phase_ctrl
|
||||||
|
16 R/W CHANNEL1 STORE1 phase_ctrl
|
||||||
|
17 R/W CHANNEL1 STORE2 phase_ctrl
|
||||||
|
18 R/W CHANNEL1 STORE3 phase_ctrl
|
||||||
|
19 R/W CHANNEL1 dds_wr_enable
|
||||||
|
1A WO CHANNEL1 data
|
||||||
|
*/
|
||||||
|
public const UInt32 Base = 0x4000_0000;
|
||||||
|
public static readonly ChannelAddr[] Channel = { new ChannelAddr(0x00), new ChannelAddr(0x10) };
|
||||||
|
|
||||||
|
public class ChannelAddr
|
||||||
|
{
|
||||||
|
private readonly UInt32 Offset;
|
||||||
|
public readonly UInt32 WaveSelect;
|
||||||
|
public readonly UInt32[] FreqCtrl;
|
||||||
|
public readonly UInt32[] PhaseCtrl;
|
||||||
|
public readonly UInt32 WriteEnable;
|
||||||
|
public readonly UInt32 WriteData;
|
||||||
|
|
||||||
|
public ChannelAddr(UInt32 offset)
|
||||||
|
{
|
||||||
|
this.Offset = offset;
|
||||||
|
this.WaveSelect = Base + Offset + 0x00;
|
||||||
|
this.FreqCtrl = new UInt32[]
|
||||||
|
{
|
||||||
|
Base + offset + 0x01,
|
||||||
|
Base + offset + 0x02,
|
||||||
|
Base + offset + 0x03,
|
||||||
|
Base + offset + 0x04
|
||||||
|
};
|
||||||
|
this.PhaseCtrl = new UInt32[] {
|
||||||
|
Base + Offset + 0x05,
|
||||||
|
Base + Offset + 0x06,
|
||||||
|
Base + Offset + 0x07,
|
||||||
|
Base + Offset + 0x08
|
||||||
|
};
|
||||||
|
this.WriteEnable = Base + Offset + 0x09;
|
||||||
|
this.WriteData = Base + Offset + 0x0A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
public class DDS
|
||||||
|
{
|
||||||
|
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
readonly int timeout = 2000;
|
||||||
|
|
||||||
|
readonly int port;
|
||||||
|
readonly string address;
|
||||||
|
private IPEndPoint ep;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address">[TODO:parameter]</param>
|
||||||
|
/// <param name="port">[TODO:parameter]</param>
|
||||||
|
/// <param name="timeout">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
public DDS(string address, int port, int timeout = 2000)
|
||||||
|
{
|
||||||
|
if (timeout < 0)
|
||||||
|
throw new ArgumentException("Timeout couldn't be negative", nameof(timeout));
|
||||||
|
this.address = address;
|
||||||
|
this.port = port;
|
||||||
|
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
|
||||||
|
this.timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channelNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="waveNum">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
public async ValueTask<Result<bool>> SetWaveNum(int channelNum, int waveNum)
|
||||||
|
{
|
||||||
|
if (channelNum < 0 || channelNum > 1) return new(new ArgumentException(
|
||||||
|
$"Channel number should be 0 ~ 1 instead of {channelNum}", nameof(channelNum)));
|
||||||
|
if (waveNum < 0 || waveNum > 3) return new(new ArgumentException(
|
||||||
|
$"Wave number should be 0 ~ 3 instead of {waveNum}", nameof(waveNum)));
|
||||||
|
|
||||||
|
await MsgBus.UDPServer.ClearUDPData(this.address);
|
||||||
|
logger.Trace("Clear udp data finished");
|
||||||
|
|
||||||
|
var ret = await UDPClientPool.WriteAddr(
|
||||||
|
this.ep, DDSAddr.Channel[channelNum].WaveSelect, (UInt32)waveNum, this.timeout);
|
||||||
|
if (!ret.IsSuccessful)
|
||||||
|
return new(ret.Error);
|
||||||
|
return ret.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channelNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="waveNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="step">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
public async ValueTask<Result<bool>> SetFreq(int channelNum, int waveNum, UInt32 step)
|
||||||
|
{
|
||||||
|
if (channelNum < 0 || channelNum > 1) return new(new ArgumentException(
|
||||||
|
$"Channel number should be 0 ~ 1 instead of {channelNum}", nameof(channelNum)));
|
||||||
|
if (waveNum < 0 || waveNum > 3) return new(new ArgumentException(
|
||||||
|
$"Wave number should be 0 ~ 3 instead of {waveNum}", nameof(waveNum)));
|
||||||
|
|
||||||
|
await MsgBus.UDPServer.ClearUDPData(this.address);
|
||||||
|
logger.Trace("Clear udp data finished");
|
||||||
|
|
||||||
|
var ret = await UDPClientPool.WriteAddr(
|
||||||
|
this.ep, DDSAddr.Channel[channelNum].FreqCtrl[waveNum], step, this.timeout);
|
||||||
|
if (!ret.IsSuccessful)
|
||||||
|
return new(ret.Error);
|
||||||
|
return ret.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// [TODO:description]
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channelNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="waveNum">[TODO:parameter]</param>
|
||||||
|
/// <param name="phase">[TODO:parameter]</param>
|
||||||
|
/// <returns>[TODO:return]</returns>
|
||||||
|
public async ValueTask<Result<bool>> SetPhase(int channelNum, int waveNum, int phase)
|
||||||
|
{
|
||||||
|
if (channelNum < 0 || channelNum > 1) return new(new ArgumentException(
|
||||||
|
$"Channel number should be 0 ~ 1 instead of {channelNum}", nameof(channelNum)));
|
||||||
|
if (waveNum < 0 || waveNum > 3) return new(new ArgumentException(
|
||||||
|
$"Wave number should be 0 ~ 3 instead of {waveNum}", nameof(waveNum)));
|
||||||
|
if (phase < 0 || phase > 4096) return new(new ArgumentException(
|
||||||
|
$"Phase should be 0 ~ 4096 instead of {phase}", nameof(phase)));
|
||||||
|
|
||||||
|
await MsgBus.UDPServer.ClearUDPData(this.address);
|
||||||
|
logger.Trace("Clear udp data finished");
|
||||||
|
|
||||||
|
var ret = await UDPClientPool.WriteAddr(
|
||||||
|
this.ep, DDSAddr.Channel[channelNum].PhaseCtrl[waveNum], (UInt32)phase, this.timeout);
|
||||||
|
if (!ret.IsSuccessful)
|
||||||
|
return new(ret.Error);
|
||||||
|
return ret.Value;
|
||||||
|
}
|
||||||
|
}
|
240
src/APIClient.ts
240
src/APIClient.ts
|
@ -1000,6 +1000,246 @@ export class RemoteUpdaterClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class DDSClient {
|
||||||
|
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||||
|
private baseUrl: string;
|
||||||
|
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
|
||||||
|
|
||||||
|
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||||
|
this.http = http ? http : window as any;
|
||||||
|
this.baseUrl = baseUrl ?? "http://localhost:5000";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [TODO:description]
|
||||||
|
* @param address (optional) [TODO:parameter]
|
||||||
|
* @param port (optional) [TODO:parameter]
|
||||||
|
* @param channelNum (optional) [TODO:parameter]
|
||||||
|
* @param waveNum (optional) [TODO:parameter]
|
||||||
|
* @return [TODO:return]
|
||||||
|
*/
|
||||||
|
setWaveNum(address: string | undefined, port: number | undefined, channelNum: number | undefined, waveNum: number | undefined): Promise<boolean> {
|
||||||
|
let url_ = this.baseUrl + "/api/DDS/SetWaveNum?";
|
||||||
|
if (address === null)
|
||||||
|
throw new Error("The parameter 'address' cannot be null.");
|
||||||
|
else if (address !== undefined)
|
||||||
|
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||||
|
if (port === null)
|
||||||
|
throw new Error("The parameter 'port' cannot be null.");
|
||||||
|
else if (port !== undefined)
|
||||||
|
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||||
|
if (channelNum === null)
|
||||||
|
throw new Error("The parameter 'channelNum' cannot be null.");
|
||||||
|
else if (channelNum !== undefined)
|
||||||
|
url_ += "channelNum=" + encodeURIComponent("" + channelNum) + "&";
|
||||||
|
if (waveNum === null)
|
||||||
|
throw new Error("The parameter 'waveNum' cannot be null.");
|
||||||
|
else if (waveNum !== undefined)
|
||||||
|
url_ += "waveNum=" + encodeURIComponent("" + waveNum) + "&";
|
||||||
|
url_ = url_.replace(/[?&]$/, "");
|
||||||
|
|
||||||
|
let options_: RequestInit = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||||
|
return this.processSetWaveNum(_response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected processSetWaveNum(response: Response): Promise<boolean> {
|
||||||
|
const status = response.status;
|
||||||
|
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||||
|
if (status === 200) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result200: any = null;
|
||||||
|
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||||
|
|
||||||
|
return result200;
|
||||||
|
});
|
||||||
|
} else if (status === 400) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result400: any = null;
|
||||||
|
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result400 = ArgumentException.fromJS(resultData400);
|
||||||
|
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||||
|
});
|
||||||
|
} else if (status === 500) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result500: any = null;
|
||||||
|
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result500 = Exception.fromJS(resultData500);
|
||||||
|
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||||
|
});
|
||||||
|
} else if (status !== 200 && status !== 204) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Promise.resolve<boolean>(null as any);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [TODO:description]
|
||||||
|
* @param address (optional) [TODO:parameter]
|
||||||
|
* @param port (optional) [TODO:parameter]
|
||||||
|
* @param channelNum (optional) [TODO:parameter]
|
||||||
|
* @param waveNum (optional) [TODO:parameter]
|
||||||
|
* @param step (optional) [TODO:parameter]
|
||||||
|
* @return [TODO:return]
|
||||||
|
*/
|
||||||
|
setFreq(address: string | undefined, port: number | undefined, channelNum: number | undefined, waveNum: number | undefined, step: number | undefined): Promise<boolean> {
|
||||||
|
let url_ = this.baseUrl + "/api/DDS/SetFreq?";
|
||||||
|
if (address === null)
|
||||||
|
throw new Error("The parameter 'address' cannot be null.");
|
||||||
|
else if (address !== undefined)
|
||||||
|
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||||
|
if (port === null)
|
||||||
|
throw new Error("The parameter 'port' cannot be null.");
|
||||||
|
else if (port !== undefined)
|
||||||
|
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||||
|
if (channelNum === null)
|
||||||
|
throw new Error("The parameter 'channelNum' cannot be null.");
|
||||||
|
else if (channelNum !== undefined)
|
||||||
|
url_ += "channelNum=" + encodeURIComponent("" + channelNum) + "&";
|
||||||
|
if (waveNum === null)
|
||||||
|
throw new Error("The parameter 'waveNum' cannot be null.");
|
||||||
|
else if (waveNum !== undefined)
|
||||||
|
url_ += "waveNum=" + encodeURIComponent("" + waveNum) + "&";
|
||||||
|
if (step === null)
|
||||||
|
throw new Error("The parameter 'step' cannot be null.");
|
||||||
|
else if (step !== undefined)
|
||||||
|
url_ += "step=" + encodeURIComponent("" + step) + "&";
|
||||||
|
url_ = url_.replace(/[?&]$/, "");
|
||||||
|
|
||||||
|
let options_: RequestInit = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||||
|
return this.processSetFreq(_response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected processSetFreq(response: Response): Promise<boolean> {
|
||||||
|
const status = response.status;
|
||||||
|
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||||
|
if (status === 200) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result200: any = null;
|
||||||
|
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||||
|
|
||||||
|
return result200;
|
||||||
|
});
|
||||||
|
} else if (status === 400) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result400: any = null;
|
||||||
|
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result400 = ArgumentException.fromJS(resultData400);
|
||||||
|
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||||
|
});
|
||||||
|
} else if (status === 500) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result500: any = null;
|
||||||
|
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result500 = Exception.fromJS(resultData500);
|
||||||
|
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||||
|
});
|
||||||
|
} else if (status !== 200 && status !== 204) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Promise.resolve<boolean>(null as any);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [TODO:description]
|
||||||
|
* @param address (optional) [TODO:parameter]
|
||||||
|
* @param port (optional) [TODO:parameter]
|
||||||
|
* @param channelNum (optional) [TODO:parameter]
|
||||||
|
* @param waveNum (optional) [TODO:parameter]
|
||||||
|
* @param phase (optional) [TODO:parameter]
|
||||||
|
* @return [TODO:return]
|
||||||
|
*/
|
||||||
|
setPhase(address: string | undefined, port: number | undefined, channelNum: number | undefined, waveNum: number | undefined, phase: number | undefined): Promise<boolean> {
|
||||||
|
let url_ = this.baseUrl + "/api/DDS/SetPhase?";
|
||||||
|
if (address === null)
|
||||||
|
throw new Error("The parameter 'address' cannot be null.");
|
||||||
|
else if (address !== undefined)
|
||||||
|
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||||
|
if (port === null)
|
||||||
|
throw new Error("The parameter 'port' cannot be null.");
|
||||||
|
else if (port !== undefined)
|
||||||
|
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||||
|
if (channelNum === null)
|
||||||
|
throw new Error("The parameter 'channelNum' cannot be null.");
|
||||||
|
else if (channelNum !== undefined)
|
||||||
|
url_ += "channelNum=" + encodeURIComponent("" + channelNum) + "&";
|
||||||
|
if (waveNum === null)
|
||||||
|
throw new Error("The parameter 'waveNum' cannot be null.");
|
||||||
|
else if (waveNum !== undefined)
|
||||||
|
url_ += "waveNum=" + encodeURIComponent("" + waveNum) + "&";
|
||||||
|
if (phase === null)
|
||||||
|
throw new Error("The parameter 'phase' cannot be null.");
|
||||||
|
else if (phase !== undefined)
|
||||||
|
url_ += "phase=" + encodeURIComponent("" + phase) + "&";
|
||||||
|
url_ = url_.replace(/[?&]$/, "");
|
||||||
|
|
||||||
|
let options_: RequestInit = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||||
|
return this.processSetPhase(_response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected processSetPhase(response: Response): Promise<boolean> {
|
||||||
|
const status = response.status;
|
||||||
|
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||||
|
if (status === 200) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result200: any = null;
|
||||||
|
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||||
|
|
||||||
|
return result200;
|
||||||
|
});
|
||||||
|
} else if (status === 400) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result400: any = null;
|
||||||
|
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result400 = ArgumentException.fromJS(resultData400);
|
||||||
|
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||||
|
});
|
||||||
|
} else if (status === 500) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
let result500: any = null;
|
||||||
|
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||||
|
result500 = Exception.fromJS(resultData500);
|
||||||
|
return throwException("A server side error occurred.", status, _responseText, _headers, result500);
|
||||||
|
});
|
||||||
|
} else if (status !== 200 && status !== 204) {
|
||||||
|
return response.text().then((_responseText) => {
|
||||||
|
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Promise.resolve<boolean>(null as any);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class DataClient {
|
export class DataClient {
|
||||||
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
|
|
|
@ -152,7 +152,7 @@ const emit = defineEmits<{
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// 控制折叠面板状态
|
// 控制折叠面板状态
|
||||||
const generalPropsExpanded = ref(true);
|
const generalPropsExpanded = ref(false);
|
||||||
const componentPropsExpanded = ref(true);
|
const componentPropsExpanded = ref(true);
|
||||||
|
|
||||||
// 更新组件属性方法
|
// 更新组件属性方法
|
||||||
|
|
|
@ -45,18 +45,10 @@
|
||||||
|
|
||||||
<CollapsibleSection title="组件功能" v-model:isExpanded="componentCapsExpanded" status="default" class="mt-4">
|
<CollapsibleSection title="组件功能" v-model:isExpanded="componentCapsExpanded" status="default" class="mt-4">
|
||||||
<div v-if="componentData && componentData.type">
|
<div v-if="componentData && componentData.type">
|
||||||
<component
|
<component v-if="capabilityComponent" :is="capabilityComponent" v-bind="componentData.attrs" />
|
||||||
v-if="capabilityComponent"
|
<div v-else class="text-gray-400">该组件没有提供特殊功能</div>
|
||||||
:is="capabilityComponent"
|
|
||||||
v-bind="componentData.attrs"
|
|
||||||
/>
|
|
||||||
<div v-else class="text-gray-400">
|
|
||||||
该组件没有提供特殊功能
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="text-gray-400">
|
|
||||||
选择元件以查看其功能
|
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="text-gray-400">选择元件以查看其功能</div>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
|
|
||||||
<!-- 未来可以在这里添加更多的分区 -->
|
<!-- 未来可以在这里添加更多的分区 -->
|
||||||
|
@ -98,7 +90,7 @@ const props = defineProps<{
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// 控制各个属性分区的展开状态
|
// 控制各个属性分区的展开状态
|
||||||
const propertySectionExpanded = ref(true); // 基本属性区域默认展开
|
const propertySectionExpanded = ref(false); // 基本属性区域默认展开
|
||||||
const pinsSectionExpanded = ref(false); // 引脚配置区域默认折叠
|
const pinsSectionExpanded = ref(false); // 引脚配置区域默认折叠
|
||||||
const componentCapsExpanded = ref(true); // 组件功能区域默认展开
|
const componentCapsExpanded = ref(true); // 组件功能区域默认展开
|
||||||
const wireSectionExpanded = ref(false); // 连线管理区域默认折叠
|
const wireSectionExpanded = ref(false); // 连线管理区域默认折叠
|
||||||
|
@ -225,10 +217,10 @@ async function getExposedCapabilities(componentType: string) {
|
||||||
// 动态导入组件
|
// 动态导入组件
|
||||||
const module = await import(`./equipments/${componentType}.vue`);
|
const module = await import(`./equipments/${componentType}.vue`);
|
||||||
const Component = module.default;
|
const Component = module.default;
|
||||||
|
|
||||||
// 创建一个临时div作为挂载点
|
// 创建一个临时div作为挂载点
|
||||||
const tempDiv = document.createElement('div');
|
const tempDiv = document.createElement("div");
|
||||||
|
|
||||||
// 创建临时应用实例并挂载组件
|
// 创建临时应用实例并挂载组件
|
||||||
let exposedMethods: any = null;
|
let exposedMethods: any = null;
|
||||||
const app = createApp({
|
const app = createApp({
|
||||||
|
@ -239,33 +231,36 @@ async function getExposedCapabilities(componentType: string) {
|
||||||
// 获取组件实例暴露的方法
|
// 获取组件实例暴露的方法
|
||||||
exposedMethods = el;
|
exposedMethods = el;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 挂载应用
|
// 挂载应用
|
||||||
const vm = app.mount(tempDiv);
|
const vm = app.mount(tempDiv);
|
||||||
|
|
||||||
// 确保实例已创建并获取到暴露的方法
|
// 确保实例已创建并获取到暴露的方法
|
||||||
await new Promise(resolve => setTimeout(resolve, 0));
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
// 检查是否有getCapabilities方法
|
// 检查是否有getCapabilities方法
|
||||||
if (exposedMethods && typeof exposedMethods.getCapabilities === 'function') {
|
if (
|
||||||
|
exposedMethods &&
|
||||||
|
typeof exposedMethods.getCapabilities === "function"
|
||||||
|
) {
|
||||||
// 获取能力组件定义
|
// 获取能力组件定义
|
||||||
const CapabilityComponent = exposedMethods.getCapabilities();
|
const CapabilityComponent = exposedMethods.getCapabilities();
|
||||||
|
|
||||||
// 卸载应用,清理DOM
|
// 卸载应用,清理DOM
|
||||||
app.unmount();
|
app.unmount();
|
||||||
tempDiv.remove();
|
tempDiv.remove();
|
||||||
|
|
||||||
return CapabilityComponent;
|
return CapabilityComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 卸载应用,清理DOM
|
// 卸载应用,清理DOM
|
||||||
app.unmount();
|
app.unmount();
|
||||||
tempDiv.remove();
|
tempDiv.remove();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`获取${componentType}能力页面失败:`, error);
|
console.error(`获取${componentType}能力页面失败:`, error);
|
||||||
|
@ -280,26 +275,31 @@ watch(
|
||||||
if (newComponentData && newComponentData.type) {
|
if (newComponentData && newComponentData.type) {
|
||||||
try {
|
try {
|
||||||
// 首先尝试从实例中获取暴露的方法
|
// 首先尝试从实例中获取暴露的方法
|
||||||
const capsComponent = await getExposedCapabilities(newComponentData.type);
|
const capsComponent = await getExposedCapabilities(
|
||||||
|
newComponentData.type,
|
||||||
|
);
|
||||||
|
|
||||||
if (capsComponent) {
|
if (capsComponent) {
|
||||||
capabilityComponent.value = markRaw(capsComponent);
|
capabilityComponent.value = markRaw(capsComponent);
|
||||||
console.log(`已从实例加载${newComponentData.type}组件的能力页面`);
|
console.log(`已从实例加载${newComponentData.type}组件的能力页面`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果实例方法获取失败,回退到模块导出方法
|
// 如果实例方法获取失败,回退到模块导出方法
|
||||||
const module = await import(`./equipments/${newComponentData.type}.vue`);
|
const module = await import(
|
||||||
|
`./equipments/${newComponentData.type}.vue`
|
||||||
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(module.default && typeof module.default.getCapabilities === "function") ||
|
(module.default &&
|
||||||
|
typeof module.default.getCapabilities === "function") ||
|
||||||
typeof module.getCapabilities === "function"
|
typeof module.getCapabilities === "function"
|
||||||
) {
|
) {
|
||||||
const getCapsFn =
|
const getCapsFn =
|
||||||
typeof module.getCapabilities === "function"
|
typeof module.getCapabilities === "function"
|
||||||
? module.getCapabilities
|
? module.getCapabilities
|
||||||
: module.default.getCapabilities;
|
: module.default.getCapabilities;
|
||||||
|
|
||||||
const moduleCapComponent = getCapsFn();
|
const moduleCapComponent = getCapsFn();
|
||||||
if (moduleCapComponent) {
|
if (moduleCapComponent) {
|
||||||
capabilityComponent.value = markRaw(moduleCapComponent);
|
capabilityComponent.value = markRaw(moduleCapComponent);
|
||||||
|
@ -307,7 +307,7 @@ watch(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
capabilityComponent.value = null;
|
capabilityComponent.value = null;
|
||||||
console.log(`组件${newComponentData.type}没有提供getCapabilities方法`);
|
console.log(`组件${newComponentData.type}没有提供getCapabilities方法`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -318,7 +318,7 @@ watch(
|
||||||
capabilityComponent.value = null;
|
capabilityComponent.value = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
// 修改hasComponentCaps计算属性
|
// 修改hasComponentCaps计算属性
|
||||||
|
|
|
@ -6,26 +6,27 @@
|
||||||
<!-- Input File -->
|
<!-- Input File -->
|
||||||
<fieldset class="fieldset w-full">
|
<fieldset class="fieldset w-full">
|
||||||
<legend class="fieldset-legend text-sm">选择或拖拽上传文件</legend>
|
<legend class="fieldset-legend text-sm">选择或拖拽上传文件</legend>
|
||||||
<input
|
<input type="file" ref="fileInput" class="file-input w-full" @change="handleFileChange" />
|
||||||
type="file"
|
|
||||||
ref="fileInput"
|
|
||||||
class="file-input w-full"
|
|
||||||
@change="handleFileChange"
|
|
||||||
/>
|
|
||||||
<label class="fieldset-label">文件最大容量: {{ maxMemory }}MB</label>
|
<label class="fieldset-label">文件最大容量: {{ maxMemory }}MB</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<!-- Upload Button -->
|
<!-- Upload Button -->
|
||||||
<div class="card-actions w-full">
|
<div class="card-actions w-full">
|
||||||
<button @click="handleClick" class="btn btn-primary grow">
|
<button @click="handleClick" class="btn btn-primary grow" :disabled="isUploading">
|
||||||
{{ buttonText }}
|
<div v-if="isUploading">
|
||||||
|
<span class="loading loading-spinner"></span>
|
||||||
|
下载中...
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
{{ buttonText }}
|
||||||
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, useTemplateRef, onMounted } from "vue";
|
import { computed, ref, useTemplateRef, onMounted } from "vue";
|
||||||
import { useDialogStore } from "@/stores/dialog";
|
import { useDialogStore } from "@/stores/dialog";
|
||||||
import { isNull, isUndefined } from "lodash";
|
import { isNull, isUndefined } from "lodash";
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ const emits = defineEmits<{
|
||||||
|
|
||||||
const dialog = useDialogStore();
|
const dialog = useDialogStore();
|
||||||
|
|
||||||
|
const isUploading = ref(false);
|
||||||
const buttonText = computed(() => {
|
const buttonText = computed(() => {
|
||||||
return isUndefined(props.downloadEvent) ? "上传" : "上传并下载";
|
return isUndefined(props.downloadEvent) ? "上传" : "上传并下载";
|
||||||
});
|
});
|
||||||
|
@ -93,6 +95,7 @@ async function handleClick(event: Event): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload - 修改这里,传递bitstream.value而不是bitstream
|
// Upload - 修改这里,传递bitstream.value而不是bitstream
|
||||||
|
isUploading.value = true;
|
||||||
try {
|
try {
|
||||||
const ret = await props.uploadEvent(event, bitstream.value);
|
const ret = await props.uploadEvent(event, bitstream.value);
|
||||||
if (isUndefined(props.downloadEvent)) {
|
if (isUndefined(props.downloadEvent)) {
|
||||||
|
@ -117,6 +120,8 @@ async function handleClick(event: Event): Promise<void> {
|
||||||
dialog.error("下载失败");
|
dialog.error("下载失败");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isUploading.value = false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,25 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div class="motherboard-container" :style="{
|
||||||
class="motherboard-container"
|
width: width + 'px',
|
||||||
:style="{
|
height: height + 'px',
|
||||||
width: width + 'px',
|
position: 'relative',
|
||||||
height: height + 'px',
|
}">
|
||||||
position: 'relative',
|
<svg xmlns="http://www.w3.org/2000/svg" :width="width" :height="height" :viewBox="`0 0 800 600`"
|
||||||
}"
|
class="motherboard-svg">
|
||||||
>
|
<image href="../equipments/svg/motherboard.svg" width="100%" height="100%" preserveAspectRatio="xMidYMid meet" />
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
:width="width"
|
|
||||||
:height="height"
|
|
||||||
:viewBox="`0 0 800 600`"
|
|
||||||
class="motherboard-svg"
|
|
||||||
>
|
|
||||||
<image
|
|
||||||
href="../equipments/svg/motherboard.svg"
|
|
||||||
width="100%"
|
|
||||||
height="100%"
|
|
||||||
preserveAspectRatio="xMidYMid meet"
|
|
||||||
/>
|
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -27,13 +14,13 @@
|
||||||
<script setup lang="tsx">
|
<script setup lang="tsx">
|
||||||
import MotherBoardCaps from "./MotherBoardCaps.vue";
|
import MotherBoardCaps from "./MotherBoardCaps.vue";
|
||||||
import { useEquipments } from "@/stores/equipments";
|
import { useEquipments } from "@/stores/equipments";
|
||||||
import {ref, computed, defineComponent, watch } from "vue";
|
import { ref, computed, defineComponent, watchEffect } from "vue";
|
||||||
|
|
||||||
// 主板特有属性
|
// 主板特有属性
|
||||||
interface MotherBoardProps {
|
export interface MotherBoardProps {
|
||||||
size?: number;
|
size?: number;
|
||||||
jtagAddr?: string;
|
boardAddr?: string;
|
||||||
jtagPort?: string;
|
boardPort?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<MotherBoardProps>(), getDefaultProps());
|
const props = withDefaults(defineProps<MotherBoardProps>(), getDefaultProps());
|
||||||
|
@ -44,11 +31,11 @@ const height = computed(() => 600 * props.size);
|
||||||
|
|
||||||
const eqps = useEquipments();
|
const eqps = useEquipments();
|
||||||
|
|
||||||
const bitstreamFile = ref<File | null> ();
|
const bitstreamFile = ref<File | null>();
|
||||||
|
|
||||||
watch([props.jtagAddr, props.jtagPort], () => {
|
watchEffect(() => {
|
||||||
eqps.jtagIPAddr = props.jtagAddr;
|
eqps.setAddr(props.boardAddr);
|
||||||
eqps.jtagPort = props.jtagPort;
|
eqps.setPort(props.boardPort);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 向外暴露方法
|
// 向外暴露方法
|
||||||
|
@ -63,21 +50,11 @@ defineExpose({
|
||||||
// 返回组件定义而不是直接返回JSX
|
// 返回组件定义而不是直接返回JSX
|
||||||
return defineComponent({
|
return defineComponent({
|
||||||
name: "MotherBoardCaps",
|
name: "MotherBoardCaps",
|
||||||
props: {
|
setup() {
|
||||||
jtagAddr: {
|
|
||||||
type: String,
|
|
||||||
default: props.jtagAddr,
|
|
||||||
},
|
|
||||||
jtagPort: {
|
|
||||||
type: String,
|
|
||||||
default: props.jtagPort,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setup(props) {
|
|
||||||
return () => (
|
return () => (
|
||||||
<MotherBoardCaps
|
<MotherBoardCaps
|
||||||
jtagAddr={props.jtagAddr}
|
jtagAddr={eqps.boardAddr}
|
||||||
jtagPort={props.jtagPort}
|
jtagPort={eqps.boardPort.toString()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -87,12 +64,14 @@ defineExpose({
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="tsx">
|
<script lang="tsx">
|
||||||
|
const eqps = useEquipments();
|
||||||
// 添加一个静态方法来获取默认props
|
// 添加一个静态方法来获取默认props
|
||||||
export function getDefaultProps() {
|
export function getDefaultProps(): MotherBoardProps {
|
||||||
|
console.log(`board监听改动: ${eqps.boardAddr}:${eqps.boardPort}`);
|
||||||
return {
|
return {
|
||||||
size: 1,
|
size: 1,
|
||||||
jtagAddr: "127.0.0.1",
|
boardAddr: eqps.boardAddr,
|
||||||
jtagPort: "1234",
|
boardPort: eqps.boardPort.toString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,31 +1,23 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h1 class="font-bold text-center text-2xl">Jtag</h1>
|
<h1 class="font-bold text-center text-2xl">Jtag</h1>
|
||||||
<div class="flex">
|
<div class="flex flex-col">
|
||||||
<p class="grow">IDCode: {{ jtagIDCode }}</p>
|
<p class="grow">Jtag Addr: {{ props.jtagAddr }}</p>
|
||||||
<button class="btn btn-circle w-8 h-8" :onclick="getIDCode">
|
<p class="grow">Jtag Port: {{ props.jtagPort }}</p>
|
||||||
<svg
|
<div class="flex justify-between grow">
|
||||||
class="icon opacity-70"
|
<p>IDCode: 0x{{ jtagIDCode.toString(16).padStart(8, "0") }}</p>
|
||||||
viewBox="0 0 1024 1024"
|
<button class="btn btn-circle w-8 h-8" :onclick="getIDCode">
|
||||||
version="1.1"
|
<svg class="icon opacity-70" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
p-id="4865" width="200" height="200">
|
||||||
p-id="4865"
|
<path
|
||||||
width="200"
|
d="M894.481158 505.727133c0 49.589418-9.711176 97.705276-28.867468 143.007041-18.501376 43.74634-44.98454 83.031065-78.712713 116.759237-33.728172 33.728172-73.012897 60.211337-116.759237 78.712713-45.311998 19.156292-93.417623 28.877701-143.007041 28.877701s-97.695043-9.721409-142.996808-28.877701c-43.756573-18.501376-83.031065-44.98454-116.76947-78.712713-33.728172-33.728172-60.211337-73.012897-78.712713-116.759237-19.156292-45.301765-28.867468-93.417623-28.867468-143.007041 0-49.579185 9.711176-97.695043 28.867468-142.996808 18.501376-43.74634 44.98454-83.031065 78.712713-116.759237 33.738405-33.728172 73.012897-60.211337 116.76947-78.712713 45.301765-19.166525 93.40739-28.877701 142.996808-28.877701 52.925397 0 104.008842 11.010775 151.827941 32.745798 46.192042 20.977777 86.909395 50.79692 121.016191 88.608084 4.389984 4.860704 8.646937 9.854439 12.781094 14.97097l0-136.263453c0-11.307533 9.168824-20.466124 20.466124-20.466124 11.307533 0 20.466124 9.15859 20.466124 20.466124l0 183.64253c0 5.433756-2.148943 10.632151-5.986341 14.46955-3.847631 3.837398-9.046027 5.996574-14.479783 5.996574l-183.64253-0.020466c-11.307533 0-20.466124-9.168824-20.466124-20.466124 0-11.307533 9.168824-20.466124 20.466124-20.466124l132.293025 0.020466c-3.960195-4.952802-8.063653-9.782807-12.289907-14.479783-30.320563-33.605376-66.514903-60.098773-107.549481-78.753645-42.467207-19.289322-87.850837-29.072129-134.902456-29.072129-87.195921 0-169.172981 33.9533-230.816946 95.597265-61.654198 61.654198-95.597265 143.621025-95.597265 230.816946s33.943067 169.172981 95.597265 230.816946c61.643965 61.654198 143.621025 95.607498 230.816946 95.607498s169.172981-33.9533 230.816946-95.607498c61.654198-61.643965 95.597265-143.621025 95.597265-230.816946 0-11.2973 9.168824-20.466124 20.466124-20.466124C885.322567 485.261009 894.481158 494.429833 894.481158 505.727133z"
|
||||||
height="200"
|
p-id="4866"></path>
|
||||||
>
|
</svg>
|
||||||
<path
|
</button>
|
||||||
d="M894.481158 505.727133c0 49.589418-9.711176 97.705276-28.867468 143.007041-18.501376 43.74634-44.98454 83.031065-78.712713 116.759237-33.728172 33.728172-73.012897 60.211337-116.759237 78.712713-45.311998 19.156292-93.417623 28.877701-143.007041 28.877701s-97.695043-9.721409-142.996808-28.877701c-43.756573-18.501376-83.031065-44.98454-116.76947-78.712713-33.728172-33.728172-60.211337-73.012897-78.712713-116.759237-19.156292-45.301765-28.867468-93.417623-28.867468-143.007041 0-49.579185 9.711176-97.695043 28.867468-142.996808 18.501376-43.74634 44.98454-83.031065 78.712713-116.759237 33.738405-33.728172 73.012897-60.211337 116.76947-78.712713 45.301765-19.166525 93.40739-28.877701 142.996808-28.877701 52.925397 0 104.008842 11.010775 151.827941 32.745798 46.192042 20.977777 86.909395 50.79692 121.016191 88.608084 4.389984 4.860704 8.646937 9.854439 12.781094 14.97097l0-136.263453c0-11.307533 9.168824-20.466124 20.466124-20.466124 11.307533 0 20.466124 9.15859 20.466124 20.466124l0 183.64253c0 5.433756-2.148943 10.632151-5.986341 14.46955-3.847631 3.837398-9.046027 5.996574-14.479783 5.996574l-183.64253-0.020466c-11.307533 0-20.466124-9.168824-20.466124-20.466124 0-11.307533 9.168824-20.466124 20.466124-20.466124l132.293025 0.020466c-3.960195-4.952802-8.063653-9.782807-12.289907-14.479783-30.320563-33.605376-66.514903-60.098773-107.549481-78.753645-42.467207-19.289322-87.850837-29.072129-134.902456-29.072129-87.195921 0-169.172981 33.9533-230.816946 95.597265-61.654198 61.654198-95.597265 143.621025-95.597265 230.816946s33.943067 169.172981 95.597265 230.816946c61.643965 61.654198 143.621025 95.607498 230.816946 95.607498s169.172981-33.9533 230.816946-95.607498c61.654198-61.643965 95.597265-143.621025 95.597265-230.816946 0-11.2973 9.168824-20.466124 20.466124-20.466124C885.322567 485.261009 894.481158 494.429833 894.481158 505.727133z"
|
</div>
|
||||||
p-id="4866"
|
|
||||||
></path>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<UploadCard
|
<UploadCard class="bg-base-200" :upload-event="uploadBitstream" :download-event="downloadBitstream">
|
||||||
class="bg-base-200"
|
|
||||||
:upload-event="uploadBitstream"
|
|
||||||
:download-event="downloadBitstream"
|
|
||||||
>
|
|
||||||
</UploadCard>
|
</UploadCard>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -35,7 +27,7 @@ import { JtagClient } from "@/APIClient";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import UploadCard from "@/components/UploadCard.vue";
|
import UploadCard from "@/components/UploadCard.vue";
|
||||||
import { useDialogStore } from "@/stores/dialog";
|
import { useDialogStore } from "@/stores/dialog";
|
||||||
import { toNumber, toString } from "lodash";
|
import { isUndefined, toNumber } from "lodash";
|
||||||
import { ref, computed, watch } from "vue";
|
import { ref, computed, watch } from "vue";
|
||||||
|
|
||||||
interface CapsProps {
|
interface CapsProps {
|
||||||
|
@ -43,21 +35,20 @@ interface CapsProps {
|
||||||
jtagPort?: string;
|
jtagPort?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<CapsProps>(), {
|
const props = withDefaults(defineProps<CapsProps>(), {});
|
||||||
jtagAddr: "127.0.0.1",
|
|
||||||
jtagPort: "1234",
|
|
||||||
});
|
|
||||||
|
|
||||||
const jtagController = new JtagClient();
|
const jtagController = new JtagClient();
|
||||||
const dialog = useDialogStore();
|
const dialog = useDialogStore();
|
||||||
|
|
||||||
// 使用传入的属性或默认值
|
// 使用传入的属性或默认值
|
||||||
const jtagIDCode = ref("");
|
const jtagIDCode = ref(0);
|
||||||
const boardAddress = computed(() => props.jtagAddr);
|
const boardAddress = computed(() => props.jtagAddr);
|
||||||
const boardPort = computed(() => toNumber(props.jtagPort));
|
const boardPort = computed(() =>
|
||||||
|
isUndefined(props.jtagPort) ? undefined : toNumber(props.jtagPort),
|
||||||
|
);
|
||||||
|
|
||||||
async function uploadBitstream(event: Event, bitstream: File) {
|
async function uploadBitstream(event: Event, bitstream: File) {
|
||||||
if (!boardAddress.value || !boardPort.value) {
|
if (!isUndefined(boardAddress.value) || !isUndefined(boardPort.value)) {
|
||||||
dialog.error("开发板地址或端口空缺");
|
dialog.error("开发板地址或端口空缺");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +106,7 @@ async function getIDCode() {
|
||||||
boardAddress.value,
|
boardAddress.value,
|
||||||
boardPort.value,
|
boardPort.value,
|
||||||
);
|
);
|
||||||
jtagIDCode.value = toString(resp);
|
jtagIDCode.value = resp;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.error("获取IDCode错误");
|
dialog.error("获取IDCode错误");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
@ -1,21 +1,37 @@
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { isUndefined } from 'lodash';
|
import { isString, isUndefined, toNumber } from 'lodash';
|
||||||
|
import z from "zod"
|
||||||
|
import { isNumber } from 'mathjs';
|
||||||
|
|
||||||
export const useEquipments = defineStore('equipments', () => {
|
export const useEquipments = defineStore('equipments', () => {
|
||||||
const jtagIPAddr = ref("127.0.0.1")
|
const boardAddr = ref("127.0.0.1")
|
||||||
const jtagPort = ref("1234")
|
const boardPort = ref(1234)
|
||||||
|
function setAddr(address: string) {
|
||||||
|
if (z.string().ip("4").safeParse(address).success)
|
||||||
|
boardAddr.value = address;
|
||||||
|
}
|
||||||
|
function setPort(port: string | number) {
|
||||||
|
|
||||||
|
if (isString(port) && port.length != 0) {
|
||||||
|
const portNumber = toNumber(port);
|
||||||
|
if (z.number().nonnegative().max(65535).safeParse(portNumber).success)
|
||||||
|
boardPort.value = portNumber;
|
||||||
|
}
|
||||||
|
else if (isNumber(port)) {
|
||||||
|
if (z.number().nonnegative().max(65535).safeParse(port).success)
|
||||||
|
boardPort.value = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
const jtagBitstream = ref<File | undefined>()
|
const jtagBitstream = ref<File | undefined>()
|
||||||
const remoteUpdateIPAddr = ref("127.0.0.1")
|
|
||||||
const remoteUpdatePort = ref("1234")
|
|
||||||
const remoteUpdateBitstream = ref<File | undefined>()
|
const remoteUpdateBitstream = ref<File | undefined>()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
jtagIPAddr,
|
boardAddr,
|
||||||
jtagPort,
|
boardPort,
|
||||||
|
setAddr,
|
||||||
|
setPort,
|
||||||
jtagBitstream,
|
jtagBitstream,
|
||||||
remoteUpdateIPAddr,
|
|
||||||
remoteUpdatePort,
|
|
||||||
remoteUpdateBitstream,
|
remoteUpdateBitstream,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue