157 lines
5.1 KiB
C#
157 lines
5.1 KiB
C#
using CMS_CORE_Library.Models;
|
|
using Thermo.Active.Model.DTOModels;
|
|
using Thermo.Active.NC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
using static CMS_CORE_Library.Models.DataStructures;
|
|
using static Thermo.Active.Config.ServerConfig;
|
|
using static Thermo.Active.Model.Constants;
|
|
using Thermo.Active.Model.DTOModels.Recipe;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/warmers")]
|
|
public class WarmersController : ApiController
|
|
{
|
|
[Route("channels"), HttpGet]
|
|
public IHttpActionResult GetCurrentWarmersChannels()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
return NotFound();
|
|
|
|
CmsError cmsError = ncAdapter.ReadWarmers(out Dictionary<int, DTOWarmers> currWarmers);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(currWarmers);
|
|
}
|
|
}
|
|
[Route("resistances"), HttpGet]
|
|
public IHttpActionResult GetCurrentWarmersResistances()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
return NotFound();
|
|
|
|
CmsError cmsError = ncAdapter.GetWarmersResistances(out Dictionary<int, Model.ConfigModels.RiskResistModel> currWarmers);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
return Ok(currWarmers);
|
|
}
|
|
}
|
|
|
|
|
|
[Route("update"), HttpPut]
|
|
public IHttpActionResult WriteSetpoints(Dictionary<int, double> channelsList)
|
|
{
|
|
// scrive su CHp da ricetta oppure da override x parametri utente...
|
|
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
#if false
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
return NotFound();
|
|
|
|
// read recipe!
|
|
CmsError cmsError = ncAdapter.ReadFullRecipe(out Dictionary<string, DTORecipeParam> prevRecipe);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
|
|
Dictionary<string, DTORecipeParam> updtRecipe = new Dictionary<string, DTORecipeParam>();
|
|
|
|
foreach (var item in parametersList)
|
|
{
|
|
if (prevRecipe.ContainsKey(item.Key))
|
|
{
|
|
// aggiorno il valore HMI nel parametro
|
|
var currParam = prevRecipe[item.Key];
|
|
currParam.SetpointHMI = item.Value;
|
|
// salvo (1 parametro, potrei fare N...)
|
|
updtRecipe.Add(item.Key, currParam);
|
|
}
|
|
else
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
|
|
// scrivo sul PLC
|
|
ncAdapter.WriteRecipeParams(updtRecipe);
|
|
#endif
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Confirm recipe modification (parameters: HMI --> PLC)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("confirm"), HttpPut]
|
|
public IHttpActionResult ConfirmEdit()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
#if false
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
return NotFound();
|
|
|
|
// scrivo sul PLC il comando conferma!
|
|
CmsError cmsError = ncAdapter.ConfirmRecipeData(true);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
#endif
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cancel recipe modification (parameters: PLC --> HMI)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("cancel"), HttpPut]
|
|
public IHttpActionResult CancelEdit()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
#if false
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
return NotFound();
|
|
|
|
// scrivo sul PLC il comando annula!
|
|
CmsError cmsError = ncAdapter.ConfirmRecipeData(false);
|
|
if (cmsError.IsError())
|
|
return BadRequest(cmsError.localizationKey);
|
|
#endif
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |