using Flir.Atlas.Live.Device;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Thermo.Active.Model;
using Thermo.Active.Model.DTOModels.ThWarmers;
using Thermo.Cam.Utils;
namespace Thermo.Active.Thermocamera
{
public class ThermoCamComunicator
{
#region Protected Fields
///
/// Classe gestione ThermoCam (oggetti Image, metodi processing...)
///
protected TCContr TCamLive = new TCContr(BASE_PATH, BASE_PATH);
#endregion Protected Fields
#region Public Fields
public static readonly string BASE_PATH = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
///
/// Indica se la camera sia connessa
///
public bool CameraIsConnected = false;
#endregion Public Fields
#region Public Constructors
///
/// Init classe
///
/// Indica aabilitazione a live straming vs load dati storici
public ThermoCamComunicator(bool isLive)
{
// init classe controllo camera
TCamLive = new TCContr($"{Constants.WEBSITE_DIRECTORY}\\{Constants.THERMO_DATA_FOLDER}", $"{BASE_PATH}\\{Constants.CONFIG_DIRECTORY}");
// aggancio evento connesisone/disconnessione
TCamLive.eh_CameraConnStatusChanged += TCamLive_eh_CameraConnStatusChanged;
// avvio classe gestione thermocamera...
TCamLive.tryReloadConf();
if (isLive)
{
// SOLO PER IL LIVE --> cerco camera
TCamLive.discoveryCamera();
}
}
private void TCamLive_eh_CameraConnStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e)
{
// salvo stato connessione
CameraIsConnected = e.Status == ConnectionStatus.Connected;
}
#endregion Public Constructors
#region Protected Methods
///
/// Rilettura da file di tutti i dati
///
/// Nome set file (originale + colorized + dati temperatura)
///
protected bool loadData(string fileName)
{
bool done = false;
try
{
done = TCamLive.fileLoad(fileName);
}
catch
{ }
return done;
}
#endregion Protected Methods
#region Public Methods
///
/// chiusura metodi legati a ThermoCam (discovery e connessione)
///
public void Dispose()
{
TCamLive.stopDiscovery();
TCamLive.DisconnectCamera();
TCamLive.DisposeCamera();
}
///
/// Restituisce lettura di tutti i punti richiesti (es centroidi riscaldi)
///
/// Nome dei dati da leggere, se "" --> live
/// Dictionary id richiesta + punto (es canali + relativi punti medi come centro calcolato della resistenza di riferimento del canale)
/// Dizionario temperature come id + valore double in °C
///
public bool readMultiTemperatures(string setName, Dictionary points, out List temp)
{
temp = new List();
// converto la richiesta in una lista di punti di misura...
List reqData = points.Select(item => new MeasurePoint()
{
Id = item.Key,
Coords = new System.Drawing.Point(item.Value.X, item.Value.Y),
Temperature = 0
}).ToList();
bool done = false;
if (string.IsNullOrEmpty(setName) || setName == "_live")
{
done = true;
}
else
{
// carico file vari...
done = TCamLive.fileLoad(setName);
}
try
{
temp = TCamLive.getPointsTemperature(false, reqData);
}
catch
{ }
// fatto!
return true;
}
///
/// Richiesta di acquisizione immagine FLIR (restituisce nome con cui sono stati salvati file)
///
///
public string takePicture()
{
string imgName = "";
try
{
// effettua chiamata x scattare immagine e SALVARE
TCamLive.takePicture();
TCamLive.calculateTarget();
imgName = TCamLive.fileSave();
}
catch
{ }
return imgName;
}
#endregion Public Methods
}
}