Newer
Older
// fits_write_key(fptr, TLOGICAL,"TTHISTORYENABLED", &intValue, "Number of images save", &FitStatus);
// fits_write_key(fptr, TSTRING, "TTTIMEHISTORYFILE", (char *)"", "Time History Filename", &FitStatus);
// fits_write_key(fptr, TINT, "TTTIMEHISTLEN", &intValue, "Number of history lines if history is enabled", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTDMMAXPOWER"]);
fits_write_key(fptr, TFLOAT, "TTDMMAXPOWER", &floatValue, "Max Power allowed to DM", &FitStatus);
fits_write_key(fptr, TSTRING, "TTBIASFILE", su::get_char_star(m_rtcKeywords["TTBIASFILE"]), "Bias File", &FitStatus);
fits_write_key(fptr, TSTRING, "TTDMFLATFILE", su::get_char_star(m_rtcKeywords["TTDMFLATFILE"]), "Flat File", &FitStatus);
if(m_pGetRtcStatus && !m_bFastSavingMode){m_rtcKeywords["TTSENSORTEMP"] = m_pGetRtcStatus("TTSENSORTEMP");}
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTSENSORTEMP"]);
fits_write_key(fptr, TFLOAT, "TTSENSORTEMP", &floatValue, "sensor temperature in degree C", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDGAINX"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDGAINX", &floatValue, "TipTilt gain on centroid X", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDGAINY"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDGAINY", &floatValue, "TipTilt gain on centroid Y", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDORIGX"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDORIGX", &floatValue, "X Origin position in [-1,1] coordinates", &FitStatus);
floatValue = su::convertStringToType<float>(m_rtcKeywords["TTCENTROIDORIGY"]);
fits_write_key(fptr, TFLOAT, "TTCENTROIDORIGY", &floatValue, "Y Origin position in [-1,1] coordinates", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTDMMODESNUM"]);
fits_write_key(fptr, TINT, "TTDMMODESNUM", &intValue, "number of modes in zonal influence matrix", &FitStatus);
fits_write_key(fptr, TSTRING, "TTPIXELGAINFILE", su::get_char_star(m_rtcKeywords["TTPIXELGAINFILE"]), "Gain factor for each pixel in which the centroid is calculated", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTPIXELENABLED"]);
fits_write_key(fptr, TLOGICAL,"TTPIXELENABLED", &intValue, "Enable saving frames on memory", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTPIXELDECIMATION"]);
fits_write_key(fptr, TINT, "TTPIXELDECIMATION", &intValue, "Frame saving decimation factor", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTDIAGENABLED"]);
fits_write_key(fptr, TLOGICAL,"TTDIAGENABLED", &intValue, "Diagnostic enabled", &FitStatus);
intValue = su::convertStringToType<int>(m_rtcKeywords["TTDIAGDECIMATION"]);
fits_write_key(fptr, TINT, "TTDIAGDECIMATION", &intValue, "TipTilt diagnostic decimation factor", &FitStatus);
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
if(m_sashaSetup[suc::InstrumentMode] == "LSS") { WCSAXES = 3;}
fits_write_key(fptr, TINT, "WCSAXES ", &WCSAXES, "Dimensionality of WCS: 2 for image, 3 for spectrum", &FitStatus);
if(WCSAXES == 2)
fits_write_key(fptr, TSTRING, "CTYPE1 ", (char *)"RA---TAN", "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "CTYPE2 ", (char *)"DEC--TAN", "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "RADESYS ", (char *)"ICRS", "reference system", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT1 ", (char *)"deg", "Unit of coordinate transformation", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT2 ", (char *)"deg", "Unit of coordinate transformation", &FitStatus);
floatValue2 = 0.0000040277777777777;
fits_write_key(fptr, TFLOAT, "CDELT1 ", &floatValue2,"Increment along axis 1 as [CUNIT1]/pxl", &FitStatus);
fits_write_key(fptr, TFLOAT, "CDELT2 ", &floatValue2,"Increment along axis 2 as [CUNIT2]/pxl", &FitStatus);
float ra_tel_deg = tenv.achieved_ra/suc::DEGREE, ra_point_offset = 0.f, ra_guide_offset = 0.f, ra_shark = 0.f;
float dec_tel_deg = tenv.achieved_dec/suc::DEGREE, dec_point_offset = 0.f, dec_guide_offset = 0.f, dec_shark = 0.f;
floatValue = ra_tel_deg + ra_point_offset + ra_guide_offset + ra_shark;
fits_write_key(fptr, TFLOAT, "CRVAL1 ", &floatValue, "RA at CRPIX1 in units CUNIT1", &FitStatus);
floatValue = dec_tel_deg + dec_point_offset + dec_guide_offset + dec_shark;
fits_write_key(fptr, TFLOAT, "CRVAL2 ", &floatValue, "DEC at CRPIX2 in units CUNIT2", &FitStatus);
floatValue = 58.1f + 885.f - xmin;
fits_write_key(fptr, TFLOAT, "CRPIX1 ", &floatValue, "Value of X Ref. pixel", &FitStatus);
floatValue = 51.5f + 1020.f - ymin;
fits_write_key(fptr, TFLOAT, "CRPIX2 ", &floatValue, "Value of Y Ref. pixel", &FitStatus);
double sign = (m_bTest01 ? 1. : -1.);
floatValue = std::cos((ih.derotator.position1 - gDrotRef + sign*tenv.parallactic_angle)*suc::DEGREE);
fits_write_key(fptr, TFLOAT, "PC1_1 ", &floatValue, "Scale in [CUNIT1]/pixel", &FitStatus);
int flip = -1;
floatValue *= flip;
fits_write_key(fptr, TFLOAT, "PC2_2 ", &floatValue, "Scale in [CUNIT2]/pixel", &FitStatus);
floatValue = std::sin((ih.derotator.position1 - gDrotRef + sign*tenv.parallactic_angle)*suc::DEGREE);
fits_write_key(fptr, TFLOAT, "PC1_2 ", &floatValue, "Rotation and skew", &FitStatus);
fits_write_key(fptr, TFLOAT, "PC2_1 ", &floatValue, "Rotation and skew", &FitStatus);
{
fits_write_key(fptr, TSTRING, "CTYPE1 ", (char *)"WAVE", "Pixel coordinate system", &FitStatus);
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
fits_write_key(fptr, TSTRING, "CTYPE2 ", (char *)"DIST", "Pixel coordinate system", &FitStatus);
// fits_write_key(fptr, TSTRING, "CTYPE3 ", strValue, "Pixel coordinate system", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT1 ", (char *)"mas", "Unit of coordinate transformation", &FitStatus);
fits_write_key(fptr, TSTRING, "CUNIT2 ", (char *)"nm", "Unit of coordinate transformation", &FitStatus);
// fits_write_key(fptr, TSTRING, "CUNIT3 ", strValue, "Unit of coordinate transformation", &FitStatus);
float crval_1 = 0.0;
float crval_2 = 800;
fits_write_key(fptr, TFLOAT, "CRVAL1 ", &crval_1, "Wavelength at CRPIX1", &FitStatus);
fits_write_key(fptr, TFLOAT, "CRVAL2 ", &crval_2, "RA at CRPIX1 in units CUNIT1", &FitStatus);
float cdelt_1 = pixscale;
float cdelt_2 = (2000-800)/2048;
fits_write_key(fptr, TFLOAT, "CDELT1 ", &cdelt_1,"Increment along axis 1 as [CUNIT1]/pxl", &FitStatus);
fits_write_key(fptr, TFLOAT, "CDELT2 ", &cdelt_2,"Increment along axis 2 as [CUNIT2]/pxl", &FitStatus);
float crpix_1 = 0;
float crpix_2 = 0;
fits_write_key(fptr, TFLOAT, "CRPIX1 ", &crpix_1, "Value of X Ref. pixel", &FitStatus);
fits_write_key(fptr, TFLOAT, "CRPIX2 ", &crpix_2, "Value of Y Ref. pixel", &FitStatus);
// fits_write_key(fptr, TFLOAT, "CRVAL3 ", &floatValue, "DEC at CRPIX2 in units CUNIT2", &FitStatus);
// fits_write_key(fptr, TFLOAT, "CD1_1 ", &floatValue, "Increment for CTYPE1", &FitStatus);
// fits_write_key(fptr, TFLOAT, "CD2_2 ", &floatValue, "Increment for CTYPE2", &FitStatus);
// fits_write_key(fptr, TFLOAT, "CD3_3 ", &floatValue, "Increment for CTYPE3", &FitStatus);
int dispAxis = 1;
fits_write_key(fptr, TINT, "DISPAXIS ", &dispAxis, "Dispersion axis (1=rows; 2=columns)", &FitStatus);
fits_write_key(fptr, TSTRING, "DISPUNIT ", (char *)"Pixel", "Units for coordinate along DISPAXIS", &FitStatus);
fits_write_key(fptr, TSTRING, "DISPWC ", strValue, "Approximate central dispersion coordinate on detector [DISPAXIS]", &FitStatus);
fits_write_key(fptr, TSTRING, "DISPDW ", strValue, "Approximate central dispersion per pixel on the detector", &FitStatus);
// TODO : Table 15 Enclosure, environment, and weather specific keywords
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
Davide Ricci
committed
// fits_write_key(fptr, TFLOAT, "DOMEPAN ", &floatValue, "Dome position angle [degrees E of N]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "DOMTEM ", &floatValue, "Dome temperature [degrees C]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "DOMHUM ", &floatValue, "Dome relative humidity [%]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "DOMDEWPT ", &floatValue, "Dome dew point [degrees C]", &FitStatus);
fits_write_record(fptr, " ------------------------------------------------------------------------", &FitStatus);
Davide Ricci
committed
// fits_write_key(fptr, TFLOAT, "ENVTEM ", &tenv.lbt_temp, "Outside temperature, C, at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVPRE ", &tenv.lbt_pressure, "Atmospheric pressure [mbar]", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVWIN ", &tenv.smt_wind_speed, "Outside wind speed (m/s) at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVDIR ", &tenv.smt_wind_dir, "(degrees) Direction of wind: E from N", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVHUM ", &tenv.lbt_humidity, "Outside relative humidity % at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVDEWPT ", &tenv.lbt_dewpoint, "Outside dew point (degrees C) at MJD-OBS", &FitStatus);
// fits_write_key(fptr, TFLOAT, "ENVTAU ", &tenv.smt_tau, "Opacity at 225 GHz, from SMT", &FitStatus);
// fits_write_key(fptr, TFLOAT, "SEEING ", &tenv.dimm_seeing, "Seeing estimate from S-H WFS", &FitStatus);
// std::string operator_comment = " no comment by operator ";
// fits_write_key(fptr, TSTRING, "WEATHER ", su::get_char_star(operator_comment), "Comment by telescope operator or observer", &FitStatus);
// fits_write_key(fptr, TFLOAT, "SEEWAV ", &floatValue, "Wavelength for seeing estimate", &FitStatus);
// fits_write_key(fptr, TFLOAT, "SEECAL ", &floatValue, "Seeing: S-H to seeing calibration curve", &FitStatus);
U8_LLOG("");
return FitStatus;
}
void SeqDataMgr::getTelescopeEnv(STelescopeEnv & env)
{
// DIMMFWHM DIMM seeing, [arcsecs] DIMMSeeing (DIMMSeeingZenith, DIMMSeeingElevation)
// DIMMFLUX DIMM mean centroid flux DIMMMeanFlux
// LBTWLINK Weather Station Link State LBTWeatherAlive (LBTWeatherAliveFront)
// LBTPRES Ambient Pressure [hPa] LBTPressure
// LBTTEMP Ambient Temperature [deg C] LBTTemp
// LBTHUM LBT Relative Humidity [percent] LBTHumidity
// LBTDWPT LBT Dew Point [deg C] LBTDewPoint
static Nice::Date lastCall;
Nice::Date currentCall = Nice::Date::now();
if(currentCall - lastCall < Nice::Time::seconds(5))return;
lbto::result res;
lbto::DDstruct ddt;
lbto::SeqDD dd;
ddt.DDname = "DIMMSeeingZenith"; //float //1
dd.push_back(ddt);
ddt.DDname = "DIMMSeeingElevation"; //float //2
ddt.DDname = "LBTWindSpeedFront"; //float //11
ddt.DDname = "LBTWindDirFront"; //float //12
ddt.DDname = "LBTWindDirFrontRaw"; //float //13
ddt.DDname = "ELPosition"; //float //15
ddt.DDname = "AZTrackingState"; //String //19
dd.push_back(ddt);
ddt.DDname = "ELTrackingState"; //String //20
ddt.DDname = "L_PresetRotMode"; //String //21
ddt.DDname = "L_AchievedRAHMS"; //String //28
ddt.DDname = "L_AchievedDECDMS"; //String //29
ddt.DDname = "L_AOReferenceRA"; //float //30
ddt.DDname = "L_AOReferenceDEC"; //float //31
ddt.DDname = "L_AOOffsetX"; //float //39 // WFS_LBTI_SX_baysidex_L_PSO_CUR 1; WFS_LBTI_SX_auxloops_L_modalplotTask_MAG
dd.push_back(ddt);
ddt.DDname = "L_AOOffsetZ"; //float //41
dd.push_back(ddt);
ddt.DDname = "L_NSRATRKRate"; //float //42
ddt.DDname = "L_NSDECTRKRate"; //float //43
dd.push_back(ddt);
ddt.DDname = "MoonAlt"; //float //44
dd.push_back(ddt);
ddt.DDname = "MoonAz"; //float //45
dd.push_back(ddt);
ddt.DDname = "LST"; //String //48
dd.push_back(ddt);
ddt.DDname = "ParAngle"; //float //49
dd.push_back(ddt);
ddt.DDname = "L_PointingModel"; //String //50
dd.push_back(ddt);
//ddt.DDname = "UTC";
//dd.push_back(ddt);
bool get_parameters = true;
int retry_counter = 0;
if(!m_iif)
{
W_LLOG("Tcs Interface not connected. Skipping getParameters");
return;
}
while(get_parameters)
{
get_parameters = false;
try
{
res = m_iif->iifGetParameter(dd);
}
catch(Basda::ServiceIsBusyException)
{
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
{
W_LLOG("Busy : retrying " << retry_counter);
}
retry_counter++;
get_parameters = true;
usleep(50000);
continue;
}
catch(const std::exception& e)
{
W_LLOG(e.what());
return;
}
catch(...)
{
std::string what = boost::current_exception_diagnostic_information();
std::string toErase = "std::exception::what :";
size_t pos = what.find(toErase);
if(pos != std::string::npos)what.erase(pos, toErase.length());
what.erase(std::remove(what.begin(), what.end(), '\n'), what.end());
std::stringstream log_msg;
log_msg << "Error trying getting DD parmateres : " << what;
W_LLOG(log_msg.str());
return;
}
}
if(res.rescode == EXIT_SUCCESS)
{
double temp;
// std::vector<std::string>::const_iterator it;
// int counter = 0;
// for(it = res.resmsg.begin(); it < res.resmsg.end(); it++)
// {
// counter++;
// U9_LLOG(counter << " ~ " << *it);
// }
env.dimm_seeing_zenith = atof(res.resmsg[1].c_str()); //f //1
env.dimm_seeing_elevation = atof(res.resmsg[2].c_str()); //f //2
env.lbt_weather_alive = (bool)atoi(res.resmsg[3].c_str()); //b //3
env.lbt_pressure = atof(res.resmsg[4].c_str()); //f //4
env.lbt_temp = atof(res.resmsg[5].c_str()); //f //5
env.lbt_humidity = atof(res.resmsg[6].c_str()); //f //6
env.lbt_dewpoint = atof(res.resmsg[7].c_str()); //f //7
env.lbt_wind_speed = atof(res.resmsg[8].c_str()); //f //8
env.lbt_wind_dir = atof(res.resmsg[9].c_str()); //f //9
env.lbt_wind_dir_raw = atof(res.resmsg[10].c_str()); //f //10
env.lbt_wind_speed_front = atof(res.resmsg[11].c_str()); //f //11
env.lbt_wind_dir_front = atof(res.resmsg[12].c_str()); //f //12
env.lbt_wind_dir_raw_front = atof(res.resmsg[13].c_str()); //f //13
env.air_mass = atof(res.resmsg[14].c_str()); //f //14
env.mcs_elevation = atof(res.resmsg[15].c_str())/3600; //f //15
env.mcs_azimuth = atof(res.resmsg[16].c_str())/3600; //f //16
env.achieved_alt = atof(res.resmsg[17].c_str()); //f //17
env.achieved_az = atof(res.resmsg[18].c_str()); //f //18
env.az_tracking_state = res.resmsg[19]; //S //19
env.el_tracking_state = res.resmsg[20]; //S //20
env.telescope_mode = res.resmsg[21]; //S //21
env.ao_mode = res.resmsg[22]; //S //22
env.epoch = atof(res.resmsg[23].c_str()); //f //23
env.target_ra = atof(res.resmsg[24].c_str()); //f //24
env.target_dec = atof(res.resmsg[25].c_str()); //f //25
env.achieved_ra = atof(res.resmsg[26].c_str()); //f //26 ?
env.achieved_dec = atof(res.resmsg[27].c_str()); //f //27 ?
env.tcs_ra = res.resmsg[28]; //S //28
env.tcs_dec = res.resmsg[29]; //S //29
env.ao_ref_ra = atof(res.resmsg[30].c_str()); //f //30
env.ao_ref_dec = atof(res.resmsg[31].c_str()); //f //31
if( res.resmsg[32] == "nan")
{
env.ao_ref_mag = -999.0f; //f //32
}
else
{
env.ao_ref_mag = atof(res.resmsg[32].c_str()); //f //32
}
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
env.guide_star_ra = atof(res.resmsg[33].c_str()); //f //33
env.guide_star_dec = atof(res.resmsg[34].c_str()); //f //34
env.target_decoffset = atof(res.resmsg[37].c_str()); //f //37 (or 35?)
env.target_raoffset = atof(res.resmsg[38].c_str()); //f //38 (or 36?)
env.ao_offsetx = atof(res.resmsg[39].c_str()); //f //39
env.ao_offsety = atof(res.resmsg[40].c_str()); //f //40
env.ao_offsetz = atof(res.resmsg[41].c_str()); //f //41
env.tel_trk_RA = atof(res.resmsg[42].c_str()); //f //42
env.tel_trk_DEC = atof(res.resmsg[43].c_str()); //f //43
env.moon_alt = atof(res.resmsg[44].c_str()); //f //44
env.moon_az = atof(res.resmsg[45].c_str()); //f //45
env.sun_alt = atof(res.resmsg[45].c_str()); //f //46
env.sun_az = atof(res.resmsg[47].c_str()); //f //47
env.lst = res.resmsg[48]; //S //48
env.parallactic_angle = atof(res.resmsg[49].c_str()); //f //49
env.pointing_model = res.resmsg[50]; //S //50
// env.utc = atof(res.resmsg[40].c_str());
//Converting string to int arr
float rad2deg = 180/M_PI;
float sec2rad = M_PI/(12*3600);
int lst_arr[4];
lst_arr[0] = atoi(env.lst.substr(0,2).c_str());
lst_arr[1] = atoi(env.lst.substr(3,2).c_str());
lst_arr[2] = atoi(env.lst.substr(6,2).c_str());
lst_arr[3] = atoi(env.lst.substr(9,5).c_str()); //5 decimal digits after ','
float lst = lst_arr[0]*3600 + lst_arr[1]*60 + lst_arr[2] + (float)lst_arr[3]/100000; //division by 100000 due to the choicheq
//U9_LLOG("____________ LST destruct: "<<lst_arr[0]<<" : "<<lst_arr[1]<<" : "<<lst_arr[2]<<" . "<<lst_arr[3]);
//Converting string to int arr
int ra_arr[4];
ra_arr[0] = atoi(env.tcs_ra.substr(0,2).c_str());
ra_arr[1] = atoi(env.tcs_ra.substr(3,2).c_str());
ra_arr[2] = atoi(env.tcs_ra.substr(6,2).c_str());
ra_arr[3] = atoi(env.tcs_ra.substr(9,5).c_str()); //5 decimal digits after ','
float ra = ra_arr[0]*3600 + ra_arr[1]*60 + ra_arr[2] + (float)ra_arr[3]/100000; //division by 100000 due to the choicheq
//U9_LLOG("____________ RA destruct: "<<ra_arr[0]<<" : "<<ra_arr[1]<<" : "<<ra_arr[2]<<" . "<<ra_arr[3]);
//Converting float val to int arr in format hh:mm:ss.sss
float ha = ra-lst;
if(ha<0) {ha = ha+24*3600;}
//U9_LLOG("____________ ha in seconds: "<<ha);
int ha_arr[4];
ha_arr[0] = ha/3600;
ha_arr[1] = ((int)ha%3600)/60;
ha_arr[2] = ((int)ha%3600)%60;
ha_arr[3] = (ha-(int)ha)*1000;
//U9_LLOG("____________ HA destruct: "<<ha_arr[0]<<" : "<<ha_arr[1]<<" : "<<ha_arr[2]<<" . "<<ha_arr[3]);
std::stringstream hour_angle;
if(ha_arr[0]<10) {hour_angle<<"0";}
hour_angle << ha_arr[0] << ":";
if(ha_arr[1]<10) {hour_angle<<"0";}
hour_angle << ha_arr[1] << ":";
if(ha_arr[2]<10) {hour_angle<<"0";}
hour_angle << ha_arr[2] << "." <<ha_arr[4];
//U9_LLOG("Hour Angle = "<<hour_angle.str());
env.hour_angle = hour_angle.str();
//Converting string to int arr
int dec_arr[4];
dec_arr[0] = atoi(env.tcs_dec.substr(0,2).c_str());
dec_arr[1] = atoi(env.tcs_dec.substr(3,2).c_str());
dec_arr[2] = atoi(env.tcs_dec.substr(6,2).c_str());
dec_arr[3] = atoi(env.tcs_dec.substr(9,2).c_str()); //2 decimal digits after ','
float dec = dec_arr[0] + dec_arr[1]/60 + dec_arr[2]/3600 + (float)dec_arr[3]/(3600*100); //division by 100 due to the choiche
//U9_LLOG("____________ DEC destruct: "<<dec_arr[0]<<" : "<<dec_arr[1]<<" : "<<dec_arr[2]<<" . "<<dec_arr[3]);
//Converting all values in rad
ha = ha*sec2rad;
dec = dec/rad2deg;
float lat = 32.701309/rad2deg;
float h = asin(cos(ha)*cos(dec)*cos(lat)+sin(dec)*sin(lat));
//U9_LLOG("_______________________ h = "<<h<<" rad ,h = "<<h*rad2deg<<" deg. _______ Zen Dist = "<<90-h*rad2deg<<" deg.");
env.zenith_dist = ceil((90-h*rad2deg)*100)/100;
}
else
{
for(unsigned int i = 0; i < res.resmsg.size(); i++)
{
U9_LLOG(res.resmsg[i]);
}
}
}
void SeqDataMgr::getMaskCombo(SInstrumentHeader & ih)
{
int coro_delimiter = ih.coro_slit_w.type.find(":");
int coro_word_len = ih.coro_slit_w.type.length()-coro_delimiter;
std::string coro_named_pos= ih.coro_slit_w.type.substr(coro_delimiter+1,coro_word_len);
int lyot_delimiter = ih.lyot_grism_w.type.find(":");
int lyot_word_len = ih.lyot_grism_w.type.length()-lyot_delimiter;
std::string lyot_named_pos= ih.lyot_grism_w.type.substr(lyot_delimiter+1,lyot_word_len);
ih.mask_comb.type = coro_named_pos+"+"+lyot_named_pos;
//U9_LLOG("Prova funzione, IH.Mask_Comb : " << ih.mask_comb.type);
std::string SeqDataMgr::GetReadoutRegion(int & xmin, int & xmax, int & ymin, int & ymax)
{
xmin = xmax = ymin = ymax = 0;
std::map<std::string, indi::IElement>::const_iterator itRegion;
const std::map<std::string, indi::IElement> & elements = sashaReadoutRegion.getElements();
itRegion = elements.find("x1");
Davide Ricci
committed
{
if(!su::getValue<int>(itRegion->second.get(), xmin)){ W_LLOG("Could not get readout region XMIN value");}
Davide Ricci
committed
}
else { W_LLOG("Could not find readout region XMIN value");}
itRegion = elements.find("x2");
if(itRegion != elements.end())
{
if(!su::getValue<int>(itRegion->second.get(), xmax)){ W_LLOG("Could not get readout region XMAX value");}
}
else { W_LLOG("Could not find readout region XMAX value");}
itRegion = elements.find("y1");
if(itRegion != elements.end())
{
if(!su::getValue<int>(itRegion->second.get(), ymin)){ W_LLOG("Could not get readout region YMIN value");}
}
else { W_LLOG("Could not find readout region YMIN value");}
itRegion = elements.find("y2");
if(itRegion != elements.end())
{
if(!su::getValue<int>(itRegion->second.get(), ymax)){ W_LLOG("Could not get readout region YMAX value");}
}
else { W_LLOG("Could not find readout region YMAX value");}
std::stringstream activeRegion;
activeRegion << "["<< xmin <<":"<< xmax <<", "<< ymin <<":"<< ymax << "]";
return activeRegion.str();
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
int SeqDataMgr::sashaEnableSave(const std::map<std::string, std::string> & _dSashaSetup)
{
// To be Implemented
U6_LLOG(__FUNCTION__ << " ~ DEPRECATED");
Ice::Int status = EXIT_SUCCESS;
#ifdef UNDEFINED
IProperty sashaSave(IProperty::Switch), recvProp;
std::map<std::string, std::string>::const_iterator itFind;
itFind = _dSashaSetup.find("SAVE");
// m_ptrIc->connect();
// NOTE while alive, indiserver does not close the connection to the client.
// U1_LLOG("Command sasha to save to file");
U1_LLOG("Command sasha to save to file");
sashaSave.setDevice("sasha_save");
sashaSave.setName("enable_save");
sashaSave.setPerm(IProperty::ReadWrite);
sashaSave.setState(IProperty::Busy);
sashaSave.add(IElement("value"));
// Switch properties can have value On or Off
sashaSave["value"].setSwitchState(IElement::Off);
U1_LLOG(sashaSave.getType());
if((su::str_tolower(itFind->second) == "true") || (itFind->second == "1"))
{
sashaSave["value"].setSwitchState(IElement::On);
}
}
//
m_ptrIc2->send_new_property_wait2(sashaSave, recvProp);
#endif
// status = m_ptrIc->close();
U8_LLOG(__FUNCTION__);
return status;
}
// Patch to get rid of the timeout problem of sasha driver. NREAD is sent whenever NDIT changes and no other parameters are sent
int SeqDataMgr::sashaEndSetup(std::map<std::string, std::string> & _dTimeoutSetup, bool ndit_changed)
{
U6_LLOG(__FUNCTION__);
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
if(ndit_changed && _dTimeoutSetup.empty())
{
IProperty & prop = m_sashaProps.find("NREADS")->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
if(elements.find("value") != elements.end())
{
_dTimeoutSetup["NREADS"] = prop["value"].getValue();
}
else
{
std::stringstream log_msg;
log_msg << "Error : IProperty \"" << prop.getDevice() << "." << prop.getName() << "\" from INDI Server has changed";
E_LLOG(log_msg.str());
throw(std::runtime_error(log_msg.str()));
}
}
std::map<std::string, std::string>::iterator itSetup;
int num_properties = _dTimeoutSetup.size();
int counter = 0, sent_properties = 0;
try
{
for(itSetup = _dTimeoutSetup.begin(); itSetup != _dTimeoutSetup.end(); itSetup++)
{
if(m_getFitsAbortFlag)break;
counter++;
IProperty & prop = m_sashaProps.find(itSetup->first)->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
bool bPropError = false, bSetProperty = false;
if(elements.find("value") != elements.end())
{
if(m_bForcePropertySet || itSetup->second != prop["value"].getValue())
{
prop["value"].setValue<int>(su::convertStringToType<int>(itSetup->second));
bSetProperty = true;
}
}
else
bPropError = true;
if(bPropError)
{
std::stringstream log_msg;
log_msg << "Error : IProperty \"" << prop.getDevice() << "." << prop.getName() << "\" from INDI Server has changed";
E_LLOG(log_msg.str());
throw(std::runtime_error(log_msg.str()));
}
else if(bSetProperty || (ndit_changed && sent_properties == 0 && counter == num_properties))
if(!bSetProperty && (ndit_changed && sent_properties == 0 && counter == num_properties))
{
U9_LLOG("Sending property " << itSetup->first << " to make camera driver recalculate exposure duration");
}
m_sashaPropsSet[itSetup->first] = false;
SendNewProperty(prop);
sent_properties++;
}
}
bool wait_result = false;
wait_result = WaitSetMessages(60000000);
if(!wait_result)status = EXIT_FAILURE;
}
catch(...)
{
E_LLOG(__FUNCTION__);
U8_LLOG("");
throw;
}
U8_LLOG("");
return status;
}
int SeqDataMgr::sashaSetup(const std::map<std::string, std::string> & _dSashaExpose)
{
U6_LLOG(__FUNCTION__);
int status = EXIT_SUCCESS;
m_exposeMutex.lock();
for(itSashaSetup = m_sashaSetup.begin(); itSashaSetup != m_sashaSetup.end(); itSashaSetup++)
{
if(itSashaSetup->first == suc::InstrumentMode)
{
itSashaSetup->second = "GEN";
}
itSashaSetup->second.clear();
}
std::map<std::string, std::string>::const_iterator itSetup;
for(itSetup = _dSashaExpose.begin(); itSetup != _dSashaExpose.end(); itSetup++)
{
U9_LLOG("Keyword : " << itSetup->first << "; Value : " << itSetup->second);
{
std::stringstream log_msg;
log_msg << "Keyword not allowed in sashaExpose : " << itSetup->first;
E_LLOG(log_msg.str());
throw(std::invalid_argument(log_msg.str()));
}
bool bForceTimeoutRefresh = false;
bool ndit_changed = false;
checkContinuousFlag();
std::map<std::string, std::string> incomingSetup = _dSashaExpose;
std::map<std::string, std::string> timeoutSetup;
timeoutSetup = su::extract_setup(m_timeoutSetup, incomingSetup);
for(itSetup = incomingSetup.begin(); itSetup != incomingSetup.end(); itSetup++)
{
if(m_getFitsAbortFlag)break;
if(itSetup->first == "DIT" || itSetup->first == "InstrumentMode")
{
}
else
{
// U9_LLOG("setup : " << itSetup->first << ":" << itSetup->second);
IProperty & prop = m_sashaProps.find(itSetup->first)->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
bool bPropError = false, bSetProperty = false;
if(itSetup->first == "SAVE")
{
bool bSave = true;
su::get_bool_from_setup(_dSashaExpose, "SAVE", bSave);
std::map<std::string, indi::IElement>::const_iterator itEl;
if(elements.find("value") != elements.end())
{
indi::IElement::SwitchStateType switch_state = (bSave ? IElement::On : IElement::Off);
if(m_bForcePropertySet || prop["value"].getSwitchState() != switch_state)
{
prop["value"].setSwitchState(switch_state);
// U9_LLOG("Setting : " << "value" << " to " << bSave);
bSetProperty = true;
}
}
else
bPropError = true;
}
else if(itSetup->first == "OBJECTNAME")
{
if(elements.find("value") != elements.end())
{
std::string current_name = prop["value"].getValue();
if(m_bForcePropertySet || current_name != itSetup->second)
{
prop["value"].setValue(itSetup->second);
bSetProperty = true;
else
bPropError = true;
}
// else if(itSetup->first == "NCOADDS")
// {
// if(elements.find("num_coadds") != elements.end())
// prop["num_coadds"].setValue<int>(su::convertStringToType<int>(itSetup->second));
// else
// bPropError = true;
// }
else if(itSetup->first == "READOUT")
{
if(elements.find("value") != elements.end())
if(m_bForcePropertySet || prop["value"].getValue() != itSetup->second)
{
prop["value"].setValue(itSetup->second);
bSetProperty = true;
}
}
else
bPropError = true;
}
else
{
if(elements.find("value") != elements.end())
{
// int value = su::convertStringToType<int>(prop["value"].getValue());
if(m_bForcePropertySet || itSetup->second != prop["value"].getValue())
if(itSetup->first == "NDIT")ndit_changed = true;
prop["value"].setValue<int>(su::convertStringToType<int>(itSetup->second));
bSetProperty = true;
}
}
else
bPropError = true;
}
if(bPropError)
{
std::stringstream log_msg;
log_msg << "Error : IProperty \"" << prop.getDevice() << "." << prop.getName() << "\" from INDI Server has changed";
E_LLOG(log_msg.str());
throw(std::runtime_error(log_msg.str()));
}
else if(bSetProperty)
{
m_sashaPropsSet[itSetup->first] = false;
SendNewProperty(prop);
}
}
}
{
const std::map<std::string, indi::IElement> elements = sashaObjName.getElements();
if(elements.find("value") != elements.end())
{
m_sashaPropsSet["OBJECTNAME"] = false;
sashaObjName["value"].setValue(m_TcsPreset.object_name);
SendNewProperty(sashaObjName);
}
}
bool wait_result = false;
wait_result = WaitSetMessages(60000000);
if(!wait_result)status = EXIT_FAILURE;
int status2 = sashaEndSetup(timeoutSetup, ndit_changed);
if(status == EXIT_FAILURE || status2 == EXIT_FAILURE)status = EXIT_FAILURE;
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
}
catch(...)
{
m_exposeMutex.unlock();
U8_LLOG("");
throw;
}
m_exposeMutex.unlock();
U8_LLOG(__FUNCTION__ << " exiting");
return status;
}
int SeqDataMgr::sashaSetFrequency(const std::map<std::string, std::string> & _dSashaExpose)
{
U6_LLOG(__FUNCTION__);
int status = EXIT_SUCCESS;
m_exposeMutex.lock();
try
{
std::map<std::string, std::string>::const_iterator itSetup;
itSetup = _dSashaExpose.find("FREQUENCY");
if(itSetup != _dSashaExpose.end())
{
IProperty & prop = m_sashaProps.find(itSetup->first)->second;
const std::map<std::string, indi::IElement> elements = prop.getElements();
if(elements.find("value") != elements.end())
{
if(m_bForcePropertySet || prop["value"].getValue() != itSetup->second)
{
prop["value"].setValue(itSetup->second);
m_sashaPropsSet[itSetup->first] = false;
SendNewProperty(prop);
//camera reinitializes and readout region is reset
m_sashaPropsSet["READOUT"] = false;
WaitSetMessages(60000000);
}
}
else
{
U9_LLOG("Error: frequency property from INDI server has changed");
}
}
}
catch(...)
{
m_exposeMutex.unlock();
U8_LLOG("");
throw;
}
m_exposeMutex.unlock();
U8_LLOG(__FUNCTION__ << " exiting");
return status;
}
int SeqDataMgr::checkContinuousFlag()
{
int status = EXIT_SUCCESS;
if(!(sashaExposeProp["value"].getSwitchState() == IElement::Off))
{
m_sashaPropsSet["STOP"] = false;
sashaStop["value"].setSwitchState(IElement::On);
SendNewProperty(sashaStop);
m_sashaPropsSet["EXPOSE"] = false;
U6_LLOG(__FUNCTION__ << " ~ Clearing Expose Property");
WaitSetMessages(10000000);
m_sashaPropsSet["EXPOSE"] = false;
WaitSetMessages(10000000);
}
// if(!(sashaEnableCont["value"].getSwitchState() == IElement::Off))
// enable_cont property is resetted every time because is sometimes found misaligned with the one on the indi server
{
m_sashaPropsSet["CONTINUOUS"] = false;
sashaEnableCont["value"].setSwitchState(IElement::Off);
SendNewProperty(sashaEnableCont);
WaitSetMessages(10000000);
}
return status;
}
int SeqDataMgr::sashaExpose(std::vector<std::string> & out_files)
{
U6_LLOG(__FUNCTION__);
int status = EXIT_SUCCESS;
m_exposeMutex.lock();
Davide Ricci
committed
m_getFitsAbortFlag = 0;
checkContinuousFlag();
m_last_generated_files.clear();
if(m_bSaveOnlyExposedFiles && !m_getFitsAbortFlag)
{
sashaBlob.setBLOBEnable(IProperty::Also);
SendNewProperty(sashaBlob);
}
bool wait_result = false;
wait_result = WaitSetMessages(60000000);
if(!m_getFitsAbortFlag)
{
m_sashaPropsSet["EXPOSE"] = false;
sashaExposeProp["value"].setSwitchState(IElement::On);
SendNewProperty(sashaExposeProp);
m_ExpectedBlobs = su::convertStringToType<int>(sashaNumSeqs["value"].getValue());
m_bInstrumentSetupUpdated = false;
updateInstrumentHeader();
wait_result = WaitSetMessages(30000000);
}
if(!m_getFitsAbortFlag)
{
wait_result = WaitStartAcquireOff(600000000);//ExtimateTiming());
m_bBlobArrived = false;
}
if(m_bSaveOnlyExposedFiles)
{
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
sashaBlob.setBLOBEnable(IProperty::Never);
SendNewProperty(sashaBlob);
}
if(!wait_result)status = EXIT_FAILURE;
if(m_getFitsAbortFlag)
{
throw(std::runtime_error("Error acquisition aborted by user"));
}
}
catch(...)
{
m_exposeMutex.unlock();
if(m_getFitsAbortFlag)m_getFitsAbortFlag--;
U8_LLOG("");
throw;
}
if(m_getFitsAbortFlag)m_getFitsAbortFlag--;
m_exposeMutex.unlock();
out_files = m_last_generated_files;
m_last_generated_files.clear();
U8_LLOG(__FUNCTION__ << " exiting");
return status;
}
void SeqDataMgr::abortExposure()
{
m_getFitsAbortFlag = 1;
SendNewProperty(sashaStop);
}
bool SeqDataMgr::WaitSetMessages(int timeout)
{
bool wait_sets = true;
int waited_time = 0;
int sleep_time = 1000;
std::stringstream log_msg;
while(wait_sets)
{
usleep(sleep_time);
waited_time += sleep_time;
sleep_time = 49000*(waited_time == 1000) + 50000*(waited_time > 1000);
std::map<std::string, bool>::iterator itSet;
for(itSet = m_sashaPropsSet.begin(); itSet != m_sashaPropsSet.end(); itSet++)
{
if(!itSet->second)break;
}
wait_sets = itSet != m_sashaPropsSet.end();
if(waited_time >= timeout)
{
log_msg << __FUNCTION__ << " ~ Timed Out waiting for : ";
for(itSet = m_sashaPropsSet.begin(); itSet != m_sashaPropsSet.end(); itSet++)
{
if(!itSet->second)
log_msg << itSet->first << " ~ ";
}
if(m_bReceivedEof)
{
E_LLOG("Received EOF");
U8_LLOG("");
throw(std::runtime_error("Indi Server signaled EoF"));
}
if(m_getFitsAbortFlag)break;
}
if(waited_time > 1000)
{
U6_LLOG(__FUNCTION__);
if(!log_msg.str().empty()){E_LLOG(log_msg.str());};
U8_LLOG(__FUNCTION__ << " ~ Exiting; waited " << waited_time/1000.f << "ms");
}
return !wait_sets;
}
bool SeqDataMgr::WaitStartAcquireOff(unsigned int timeout)
{
U6_LLOG(__FUNCTION__);
bool wait_result = true;
unsigned int waited_time = 0;
while(wait_result)
{
usleep(200000);
waited_time += 200;
wait_result = !(sashaExposeProp["value"].getSwitchState() == IElement::Off);
if(waited_time >= timeout)
{
E_LLOG(__FUNCTION__ << " ~ Timed Out");
break;
}
if((waited_time % 300000) == 0)
{
U9_LLOG(__FUNCTION__ << " ~ Waiting " << waited_time/1000.f << "/" << timeout/1000.f << "s");
}
if(m_getFitsAbortFlag)break;
if(m_bReceivedEof)
{
E_LLOG("Received EOF");
U8_LLOG("");
throw(std::runtime_error("Indi Server signaled EoF"));
}
}
U8_LLOG(__FUNCTION__ << " ~ Exiting; waited " << waited_time << "ms");
return !wait_result;
}
bool SeqDataMgr::WaitBLOB(unsigned int timeout)
{
U6_LLOG(__FUNCTION__);
bool wait_result = true;
unsigned int waited_time = 0;
while(wait_result)
{
usleep(200000);
waited_time += 200;
wait_result = !(m_bBlobArrived == true);
if(wait_result && waited_time >= timeout)
{
E_LLOG(__FUNCTION__ << " ~ Timed Out");