feat: add remote update function
This commit is contained in:
@@ -418,8 +418,9 @@ public class RemoteUpdater : ControllerBase
|
||||
/// <param name="bitstream3">比特流文件3</param>
|
||||
/// <returns>上传结果</returns>
|
||||
[HttpPost("UploadBitstream")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ArgumentException), StatusCodes.Status400BadRequest)]
|
||||
public async ValueTask<IResult> UploadBitstreams(
|
||||
string address,
|
||||
IFormFile? goldenBitream,
|
||||
@@ -469,7 +470,7 @@ public class RemoteUpdater : ControllerBase
|
||||
}
|
||||
|
||||
logger.Info($"Device {address} Upload Bitstream Successfully");
|
||||
return TypedResults.Ok("Bitstream Upload Successfully");
|
||||
return TypedResults.Ok(true);
|
||||
}
|
||||
|
||||
private async ValueTask<Result<byte[]>> ProcessBitstream(string filePath)
|
||||
@@ -522,9 +523,10 @@ public class RemoteUpdater : ControllerBase
|
||||
/// <param name="port"> 设备端口 </param>
|
||||
/// <param name="bitstreamNum"> 比特流位号 </param>
|
||||
[HttpPost("DownloadBitstream")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool),StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> UpdateBitstream(string address, int port, int bitstreamNum)
|
||||
{
|
||||
// 检查文件
|
||||
@@ -571,9 +573,10 @@ public class RemoteUpdater : ControllerBase
|
||||
/// <param name="bitstreamNum">比特流编号</param>
|
||||
/// <returns>总共上传比特流的数量</returns>
|
||||
[HttpPost("DownloadMultiBitstreams")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(int),StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> DownloadMultiBitstreams(string address, int port, int? bitstreamNum)
|
||||
{
|
||||
// 检查文件
|
||||
@@ -630,9 +633,10 @@ public class RemoteUpdater : ControllerBase
|
||||
/// <param name="bitstreamNum">比特流编号</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("HotResetBitstream")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool),StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> HotResetBitstream(string address, int port, int bitstreamNum)
|
||||
{
|
||||
var remoteUpdater = new RemoteUpdate.RemoteUpdateClient(address, port);
|
||||
@@ -640,7 +644,7 @@ public class RemoteUpdater : ControllerBase
|
||||
|
||||
if (ret.IsSuccessful)
|
||||
{
|
||||
logger.Info($"Device {address}即可 Update bitstream successfully");
|
||||
logger.Info($"Device {address} Update bitstream successfully");
|
||||
return TypedResults.Ok(ret.Value);
|
||||
}
|
||||
else
|
||||
@@ -649,6 +653,35 @@ public class RemoteUpdater : ControllerBase
|
||||
return TypedResults.InternalServerError(ret.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
[HttpPost("GetFirmwareVersion")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(UInt32),StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ArgumentException),StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception),StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> GetFirmwareVersion(string address, int port)
|
||||
{
|
||||
var remoteUpdater = new RemoteUpdate.RemoteUpdateClient(address, port);
|
||||
var ret = await remoteUpdater.GetVersion();
|
||||
|
||||
if (ret.IsSuccessful)
|
||||
{
|
||||
logger.Info($"Device {address} get firmware version successfully");
|
||||
return TypedResults.Ok(ret.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error(ret.Error);
|
||||
return TypedResults.InternalServerError(ret.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -532,4 +532,23 @@ public class RemoteUpdateClient
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public async ValueTask<Result<UInt32>> GetVersion()
|
||||
{
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address);
|
||||
logger.Trace("Clear udp data finished");
|
||||
|
||||
{
|
||||
var ret = await UDPClientPool.ReadAddr(this.ep, RemoteUpdateClientAddr.Version, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
|
||||
var retData = ret.Value.Options.Data;
|
||||
if (retData is null || retData.Length != 4) return new(new Exception("Failed to read remote update firmware version"));
|
||||
var version = Common.Number.BytesToUInt32(retData);
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user