|
/**
|
|
* @brief init DCDC
|
|
* @date 17/10/2011
|
|
* @author F.BLANC LAAS-CNRS
|
|
*
|
|
*/
|
|
|
|
|
|
#include "asynctmr.h"
|
|
#include <utility.h>
|
|
#include "inst.h"
|
|
#include "var.h"
|
|
/**
|
|
* @brief fatal error
|
|
* @param string error
|
|
* @date 17/10/2011
|
|
*
|
|
*/
|
|
void fatal_error (char msg[])
|
|
{
|
|
MessagePopup ("Error", msg);
|
|
exit(-1);
|
|
}
|
|
|
|
/**
|
|
* @brief init main
|
|
* @param [in] name of file UIR
|
|
* @return 0
|
|
* @date 19/10/2012
|
|
*
|
|
*/
|
|
int init_main (char uir[])
|
|
{
|
|
char chn_nom_LOG[MAX_PATHNAME_LEN];
|
|
char chemin_nom[MAX_PATHNAME_LEN];
|
|
char message_LOG[256];
|
|
char message[256];
|
|
if ((T_panel[PANEL_TOP].panel = LoadPanel (0, uir, P_TOP)) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_ABOUT].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_ABOUT)) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_LOG].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_LOG )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_PORT].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_PORT )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_CYCLE].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_CYCLE )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_BATT].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_BATT )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_MEASURE].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_MEASURE )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_GRAPH].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_GRAPH )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((T_panel[PANEL_INFO].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_INFO )) < 0)
|
|
fatal_error("bad UIR");
|
|
if ((barre_de_menu = LoadMenuBar (T_panel[PANEL_TOP].panel, uir, MENUBAR2)) < 0)
|
|
fatal_error("bad UIR");
|
|
// fichier log
|
|
GetDir (chn_nom_LOG);
|
|
|
|
if(strstr(chn_nom_LOG,DIR_PROGRAMFILE)!=NULL)
|
|
{
|
|
strcpy( chn_nom_LOG, DIR_PROGRAMDATA);
|
|
MakeDir(chn_nom_LOG);
|
|
|
|
}
|
|
sprintf (chn_nom_LOG, "%s\\%s", chn_nom_LOG,"banc_mesures.log");
|
|
file_LOG= fopen (chn_nom_LOG, "a");
|
|
if(file_LOG==NULL)
|
|
{
|
|
save_LOG("Save file init");
|
|
save_LOG(chn_nom_LOG);
|
|
save_LOG(" FAIL");
|
|
|
|
}
|
|
save_LOG("----------------------------------------------------------------------------------------------------------------");
|
|
save_LOG("RUN Battery test");
|
|
sprintf (message_LOG," version CVI : %s",VERSION);
|
|
save_LOG(message_LOG);
|
|
GetCtrlVal (T_panel[PANEL_ABOUT].panel,P_ABOUT_VERSION_UIR,message);
|
|
sprintf (message_LOG," version UIR : %s",message);
|
|
save_LOG(message_LOG);
|
|
|
|
SetCtrlVal (T_panel[PANEL_ABOUT].panel,P_ABOUT_VERSION,VERSION);
|
|
DisplayPanel (T_panel[PANEL_TOP].panel);
|
|
DisplayPanel (T_panel[PANEL_LOG].panel);
|
|
//XML
|
|
save_LOG("initialization parameters from consigne file");
|
|
GetDir (chemin_nom);
|
|
if(strstr(chemin_nom,DIR_PROGRAMFILE)!=NULL)
|
|
{
|
|
strcpy( chemin_nom, DIR_PROGRAMDATA);
|
|
MakeDir(chemin_nom);
|
|
|
|
}
|
|
sprintf (chemin_nom, "%s\\%s", chemin_nom,"consigne.xml");
|
|
if(load_consigne_xml(chemin_nom))
|
|
{
|
|
save_LOG(" FAIL");
|
|
Ctrl.mode_loop=0;
|
|
Ctrl.nb_loop=0;
|
|
Ctrl.vminstop=1;
|
|
sprintf(Ctrl.name_Batt,"");
|
|
}else
|
|
{
|
|
save_LOG(" OK");
|
|
}
|
|
save_LOG("initialization parameters from XML file");
|
|
if(load_xml())
|
|
{
|
|
save_LOG(" FAIL");
|
|
init_usine ();
|
|
Ctrl.mode=MODE_EDIT;
|
|
|
|
}else
|
|
{
|
|
save_LOG(" OK");
|
|
init_panel();
|
|
init_instrument ();
|
|
init_panel_Measure(1);
|
|
DisplayPanel(T_panel[PANEL_MEASURE].panel);
|
|
}
|
|
|
|
Ctrl.cycle=1;
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_CYCLE].panel,P_CYCLE_H_CYCLE,ATTR_MAX_VALUE, Ctrl.nb_cycle);
|
|
//TIMER
|
|
save_LOG("initialization CVI_TIMER OFF");
|
|
Ctrl.timer_id=NewAsyncTimer (1.0, -1, 0, CVI_timer, 0);
|
|
return 0;
|
|
|
|
}
|
|
/**
|
|
* @brief init panel MEASURE
|
|
* @param dimmed
|
|
* @return 0
|
|
* @date 05/10/2011
|
|
*
|
|
*/
|
|
int init_panel_Measure(int dimmed)
|
|
{
|
|
fnct_Ctrl_mode(Ctrl.mode);
|
|
|
|
if(instrument[INST_POWER].present==1)
|
|
{
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,ATTR_DIMMED, dimmed);
|
|
}
|
|
if( instrument[INST_SMU].present==1)
|
|
{
|
|
//LOAD
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,ATTR_DIMMED, dimmed);
|
|
//POWER
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,ATTR_DIMMED, dimmed);
|
|
//PM
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_IN,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_IN,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_IN,ATTR_VISIBLE, 1);
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_OUT,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_OUT,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_OUT,ATTR_VISIBLE, 1);
|
|
|
|
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_IN,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_IN,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_IN,ATTR_DIMMED, dimmed);
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_OUT,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_OUT,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_OUT,ATTR_DIMMED, dimmed);
|
|
|
|
}
|
|
if( instrument[INST_LOAD].present==1)
|
|
{
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,ATTR_DIMMED, dimmed);
|
|
}
|
|
if( instrument[INST_SAS].present==1)
|
|
{
|
|
|
|
}
|
|
if( instrument[INST_PM].present==1)
|
|
{
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_IN,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_IN,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_IN,ATTR_VISIBLE, 1);
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_OUT,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_OUT,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_OUT,ATTR_VISIBLE, 1);
|
|
|
|
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_IN,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_IN,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_IN,ATTR_DIMMED, dimmed);
|
|
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V_OUT,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I_OUT,ATTR_DIMMED, dimmed);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_Ah_OUT,ATTR_DIMMED, dimmed);
|
|
}
|
|
if(((Ctrl.mode==MODE_SMU) && (instrument[INST_SMU].present==1)) ||
|
|
((Ctrl.mode==MODE_POWER_LOAD) && (instrument[INST_POWER].present==1) && (instrument[INST_LOAD].present==1)) ||
|
|
((Ctrl.mode==MODE_POWER_LOAD_PM) && (instrument[INST_POWER].present==1) && (instrument[INST_LOAD].present==1) && (instrument[INST_PM].present==1)))
|
|
{
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_START,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_START, ATTR_DIMMED, 0);
|
|
SetMenuBarAttribute (barre_de_menu, MENUBAR2_CONF_SIMUL, ATTR_DIMMED, 1);
|
|
}
|
|
if(instrument[INST_TEMP].present==1 )
|
|
{
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_TEMP_BATT,ATTR_VISIBLE, 1);
|
|
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_TEMP_EXT,ATTR_VISIBLE, 1);
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief init close main
|
|
* @param [in] name of file UIR
|
|
* @return 0
|
|
* @date 17/10/2011
|
|
*
|
|
*/
|
|
int init_close (void)
|
|
{
|
|
int i;
|
|
char message_LOG[1024];
|
|
char chemin_nom[MAX_PATHNAME_LEN];
|
|
save_LOG("CVI_TIMER OFF");
|
|
test_LOG(SetAsyncTimerAttribute (Ctrl.timer_id,ASYNC_ATTR_ENABLED,0 ));//desactivation timer
|
|
save_LOG("STOP GUI");
|
|
save_LOG("Save XML");
|
|
GetDir (chemin_nom);
|
|
if(strstr(chemin_nom,DIR_PROGRAMFILE)!=NULL)
|
|
{
|
|
strcpy( chemin_nom, DIR_PROGRAMDATA);
|
|
MakeDir(chemin_nom);
|
|
|
|
}
|
|
sprintf (chemin_nom, "%s\\%s", chemin_nom,"consigne.xml");
|
|
save_consigne_xml(chemin_nom);
|
|
for(i=0;i<MAX_PANEL;i++)
|
|
{
|
|
GetPanelAttribute (T_panel[i].panel, ATTR_TOP, &T_panel[i].top);
|
|
GetPanelAttribute (T_panel[i].panel, ATTR_LEFT,&T_panel[i].left);
|
|
GetPanelAttribute (T_panel[i].panel, ATTR_HEIGHT, &T_panel[i].height);
|
|
GetPanelAttribute (T_panel[i].panel, ATTR_WIDTH,&T_panel[i].width);
|
|
}
|
|
test_LOG(save_xml());
|
|
|
|
for(i=0;i<MAX_INSTRUMENT;i++)
|
|
{
|
|
if (instrument[i].present)
|
|
{
|
|
sprintf (message_LOG,"CLOSE IVI %s",instrument[i].port.instrDescr);
|
|
save_LOG(message_LOG);
|
|
if(i!=INST_TEMP)
|
|
test_LOG(inst_close (instrument[i].port.handle)); //fermeture setion visa
|
|
else
|
|
//close com
|
|
;
|
|
}
|
|
}
|
|
save_LOG("****************************************************************************************************************");
|
|
fclose (file_LOG);
|
|
return 0;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief init instrunemt
|
|
* @param [in] num_intrument
|
|
* @return 0
|
|
* @date 23/09/2011
|
|
*
|
|
*/
|
|
int init_type_inst(int inst)
|
|
{
|
|
|
|
char message_LOG [256];
|
|
char *ptr,*str;
|
|
int ic;
|
|
if(instrument[inst].port.language==SCPI)
|
|
{
|
|
ic=0;
|
|
str= strchr (instrument[inst].port.instrDescr,',' );
|
|
for(ptr=instrument[inst].port.instrDescr;ptr<str;ptr++)
|
|
instrument[inst].constructeur[ic++]=*ptr;
|
|
|
|
str=strchr (++ptr,',' );
|
|
ic=0;
|
|
for(;ptr<str;ptr++)
|
|
instrument[inst].model[ic++]=*ptr;
|
|
str=strchr (++ptr,',' );
|
|
ic=0;
|
|
for(;ptr<str;ptr++)
|
|
instrument[inst].num_serie[ic++]=*ptr;
|
|
str=strchr (++ptr,'/' );
|
|
ic=0;
|
|
for(;ptr<str;ptr++)
|
|
instrument[inst].date_CAL[ic++]=*ptr;
|
|
save_LOG("+++");
|
|
sprintf (message_LOG," %s ",instrument[inst].constructeur);
|
|
save_LOG(message_LOG);
|
|
sprintf (message_LOG," %s ",instrument[inst].model);
|
|
save_LOG(message_LOG);
|
|
sprintf (message_LOG," %s ",instrument[inst].num_serie);
|
|
save_LOG(message_LOG);
|
|
sprintf (message_LOG," %s ",instrument[inst].date_CAL);
|
|
save_LOG(message_LOG);
|
|
}else if(instrument[inst].port.language==ARPS)
|
|
{
|
|
sprintf (message_LOG," %s ",instrument[inst].port.instrDescr);
|
|
save_LOG(message_LOG);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief init instrument
|
|
* @param
|
|
* @return 0
|
|
* @date 14/12/2010
|
|
*
|
|
*/
|
|
int init_instrument (void)
|
|
{
|
|
|
|
int i;
|
|
for(i=0;i<MAX_INSTRUMENT;i++)
|
|
{
|
|
switch (i)
|
|
{
|
|
case INST_POWER :
|
|
if(Ctrl.mode==MODE_POWER_LOAD||Ctrl.mode==MODE_POWER_LOAD_PM)
|
|
init_POWER(INST_POWER);
|
|
break;
|
|
case INST_LOAD :
|
|
if(Ctrl.mode==MODE_POWER_LOAD||Ctrl.mode==MODE_POWER_LOAD_PM)
|
|
init_LOAD(INST_LOAD);
|
|
break;
|
|
case INST_SMU :
|
|
if(Ctrl.mode==MODE_SMU)
|
|
init_SMU(INST_SMU);
|
|
break;
|
|
// case INST_SAS :
|
|
// init_SAS(INST_SAS);
|
|
// break;
|
|
case INST_PM :
|
|
if(Ctrl.mode==MODE_POWER_LOAD_PM)
|
|
init_PM(INST_PM);
|
|
break;
|
|
case INST_TEMP :
|
|
init_TEMP(INST_TEMP);
|
|
break;
|
|
}
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief init usine
|
|
* @param
|
|
* @return 0
|
|
* @date 16/10/2012
|
|
*
|
|
*/
|
|
int init_usine (void)
|
|
{
|
|
int i;
|
|
GetDir (Ctrl.racine);
|
|
init_reset_panel();
|
|
for(i=0;i<MAX_INSTRUMENT;i++)
|
|
{
|
|
init_port(&instrument[i].port);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|