add: 为逻辑分析仪添加了深度、预存储深度、通道组设置
This commit is contained in:
@@ -45,7 +45,18 @@ public class LogicAnalyzerController : ControllerBase
|
||||
/// 全局触发模式
|
||||
/// </summary>
|
||||
public GlobalCaptureMode GlobalMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 捕获深度
|
||||
/// </summary>
|
||||
public int CaptureLength { get; set; } = 2048 * 32;
|
||||
/// <summary>
|
||||
/// 预采样深度
|
||||
/// </summary>
|
||||
public int PreCaptureLength { get; set; } = 2048;
|
||||
/// <summary>
|
||||
/// 有效通道
|
||||
/// </summary>
|
||||
public AnalyzerChannelDiv ChannelDiv { get; set; } = AnalyzerChannelDiv.EIGHT;
|
||||
/// <summary>
|
||||
/// 信号触发配置列表
|
||||
/// </summary>
|
||||
@@ -77,7 +88,7 @@ public class LogicAnalyzerController : ControllerBase
|
||||
return null;
|
||||
|
||||
var board = boardRet.Value.Value;
|
||||
return new Analyzer(board.IpAddr, board.Port, 2);
|
||||
return new Analyzer(board.IpAddr, board.Port, 0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -208,8 +219,8 @@ public class LogicAnalyzerController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
if (signalIndex < 0 || signalIndex > 7)
|
||||
return BadRequest("信号索引必须在0-7之间");
|
||||
if (signalIndex < 0 || signalIndex > 31)
|
||||
return BadRequest("信号索引必须在0-31之间");
|
||||
|
||||
var analyzer = GetAnalyzer();
|
||||
if (analyzer == null)
|
||||
@@ -231,6 +242,48 @@ public class LogicAnalyzerController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置深度、预采样深度、有效通道
|
||||
/// </summary>
|
||||
/// <param name="capture_length">深度</param>
|
||||
/// <param name="pre_capture_length">预采样深度</param>
|
||||
/// <param name="channel_div">有效通道(0-[1],1-[2],2-[4],3-[8],4-[16],5-[32])</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetCaptureParams")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> SetCaptureParams(int capture_length, int pre_capture_length, AnalyzerChannelDiv channel_div)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (capture_length < 0 || capture_length > 2048*32)
|
||||
return BadRequest("采样深度设置错误");
|
||||
if (pre_capture_length < 0 || pre_capture_length >= capture_length)
|
||||
return BadRequest("预采样深度必须小于捕获深度");
|
||||
|
||||
var analyzer = GetAnalyzer();
|
||||
if (analyzer == null)
|
||||
return BadRequest("用户未绑定有效的实验板");
|
||||
|
||||
var result = await analyzer.SetCaptureParams(capture_length, pre_capture_length, channel_div);
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error($"设置深度、预采样深度、有效通道失败: {result.Error}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "设置深度、预采样深度、有效通道失败");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "设置深度、预采样深度、有效通道失败时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "操作失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量配置捕获参数
|
||||
/// </summary>
|
||||
@@ -264,8 +317,8 @@ public class LogicAnalyzerController : ControllerBase
|
||||
// 设置信号触发模式
|
||||
foreach (var signalConfig in config.SignalConfigs)
|
||||
{
|
||||
if (signalConfig.SignalIndex < 0 || signalConfig.SignalIndex > 7)
|
||||
return BadRequest($"信号索引{signalConfig.SignalIndex}超出范围0-7");
|
||||
if (signalConfig.SignalIndex < 0 || signalConfig.SignalIndex > 31)
|
||||
return BadRequest($"信号索引{signalConfig.SignalIndex}超出范围0-31");
|
||||
|
||||
var signalResult = await analyzer.SetSignalTrigMode(
|
||||
signalConfig.SignalIndex, signalConfig.Operator, signalConfig.Value);
|
||||
@@ -276,6 +329,14 @@ public class LogicAnalyzerController : ControllerBase
|
||||
$"设置信号{signalConfig.SignalIndex}触发模式失败");
|
||||
}
|
||||
}
|
||||
// 设置深度、预采样深度、有效通道
|
||||
var paramsResult = await analyzer.SetCaptureParams(
|
||||
config.CaptureLength, config.PreCaptureLength, config.ChannelDiv);
|
||||
if (!paramsResult.IsSuccessful)
|
||||
{
|
||||
logger.Error($"设置深度、预采样深度、有效通道失败: {paramsResult.Error}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "设置深度、预采样深度、有效通道失败");
|
||||
}
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
@@ -330,7 +391,7 @@ public class LogicAnalyzerController : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> GetCaptureData()
|
||||
public async Task<IActionResult> GetCaptureData(int capture_length = 2048 * 32)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -338,7 +399,7 @@ public class LogicAnalyzerController : ControllerBase
|
||||
if (analyzer == null)
|
||||
return BadRequest("用户未绑定有效的实验板");
|
||||
|
||||
var result = await analyzer.ReadCaptureData();
|
||||
var result = await analyzer.ReadCaptureData(capture_length);
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error($"读取捕获数据失败: {result.Error}");
|
||||
|
||||
Reference in New Issue
Block a user