#include "stdafx.h" #ifdef OLIVIA_COMPILA #include "olv_reco.h" #include "olv_reco_thr.h" #include "olv_geom.h" #include "olv_sens_ws.h" #include "ini_file.h" /** * @file olv_reco.cpp * Archivo de definiciones y variables de la utilidad de recogida de residuos del programa Olivia. */ Colv_reco::Colv_reco(COlivia *olv) : Colv_limp(olv) { this->olv = olv; thr_reco = new Colv_reco_thr(this); //rellena_campos(); t_vaci=t_sal=0; kg_max=kg_reco_def=0; anch_vehi=0; giro_vehi=OLV_LIMP_GIRO_VEHIC; memset(coor_plant,0,3*sizeof(double)); nod_instal=nod_plant=-1; ptos_vaci=NULL; dens_frac=150; info_carg=NULL; // } Colv_reco::~Colv_reco(void) { cancela(); delete(thr_reco); if(ptos_vaci) free(ptos_vaci); if(info_carg) free(info_carg); if(ord_sec_plan) { if(ord_sec_plan[1].ctnod[0] && ord_sec_plan[1].ctnod[0]==ord_sec_plan[0].ctnod[0]) ord_sec_plan[1].ctnod[0]=NULL; //solo libera la segunda parte parte, el destructor de limp hace el resto if(ord_sec_plan[1].ctnod[0]) { ord_sec_plan[1].libera(0,conjs.n); free(ord_sec_plan[1].ctnod[0]); } ord_sec_plan[1].ctnod[0]=NULL; } } //************************************************************************************* /** * Termina las tareas */ void Colv_reco::cancela() { thr_reco->termina_th(); } //************************************************************************************* /** * Inicia las variables que son propias de limpieza */ void Colv_reco::inicia_limp() { res_circ=OLV_RES_RECOGER_SOLO_LADO_Y_GIROS; t_tto=t_vaci; //ang_lim = giro_vehi*OLV_PI/180; tipo_ambit=OLV_AMB_PUN; v_despl=0; uds_tto=OliviaDef::GeneralDef::OlvTipTtoMin; } //************************************************************************************* /** * Rellena los campos de la dbf */ void Colv_reco::rellena_campos() { camps_r.campo_uds[0]=0; camps_r.campo_capa[0]=0; camps_r.campo_kgcont[0]=0; Colv_limp::rellena_campos(); rellena_campos_sens(); } //************************************************************************************* /** * Pone las opciones de configuración de lo que recibe por el socket */ int Colv_reco::pon_config(char *config_) { int j; char *token; char config[2048]; if(!config) return 0; strcpy_s(config,2048,config_); j=Colv_limp::pon_config(config); //los parámetros son: token = strtok(config, OliviaDef::GeneralDef::EjecGeoParamSep); //avanza al siguiente token, el primero indica "\CONFIGURACION" token = strtok(NULL, OliviaDef::GeneralDef::EjecGeoParamSep); while (token != NULL) { if(strstr(token,OliviaDef::GeneralDef::GR_kgM)) { if(!olv->dame_param(token, &kg_max)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_dens)) { if(!olv->dame_param(token, &dens_frac)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_camp_uds)) { if(!olv->dame_param(token, camps_r.campo_uds,sizeof(camps_r.campo_uds))) break; if (strlen(camps_r.campo_uds) > OLV_MAX_COL_SHP)//10 porque el shp solo pasa con 10 caracteres en los nombres de columna camps_r.campo_uds[OLV_MAX_COL_SHP] = 0; } else if(strstr(token,OliviaDef::GeneralDef::GR_camp_kgrec)) { if(!olv->dame_param(token, camps_r.campo_kgcont,sizeof(camps_r.campo_kgcont))) break; if (strlen(camps_r.campo_kgcont) > OLV_MAX_COL_SHP)//10 porque el shp solo pasa con 10 caracteres en los nombres de columna camps_r.campo_kgcont[OLV_MAX_COL_SHP] = 0; } else if(strstr(token,OliviaDef::GeneralDef::GR_camp_cap)) { if(!olv->dame_param(token, camps_r.campo_capa,sizeof(camps_r.campo_capa))) break; if (strlen(camps_r.campo_capa) > OLV_MAX_COL_SHP)//10 porque el shp solo pasa con 10 caracteres en los nombres de columna camps_r.campo_capa[OLV_MAX_COL_SHP] = 0; } else if(strstr(token,OliviaDef::GeneralDef::GR_kgrecog)) { if(!olv->dame_param(token, &kg_reco_def)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_tvc)) { if(!olv->dame_param(token, &t_vaci)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_tdca)) { if(!olv->dame_param(token, &t_descarg)) break; t_descarg=t_descarg*60;//porque viene en minutos } else if(strstr(token,OliviaDef::GeneralDef::GR_tsal)) { if(!olv->dame_param(token, &t_sal)) break; t_sal=t_sal*60;//porque viene en minutos } else if(strstr(token,OliviaDef::GeneralDef::GR_anc)) { if(!olv->dame_param(token, &anch_vehi)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_gir)) { if(!olv->dame_param(token, &giro_vehi)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_descx)) { if(!olv->dame_param(token, &coor_plant[0])) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_descy)) { if(!olv->dame_param(token, &coor_plant[1])) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_carga_cont)) { if(!olv->dame_param(token, &info_sens.porc_lim)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_sens_modo)) { if(!olv->dame_param(token, &info_sens.modo_pet)) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_sens_url)) { if(!olv->dame_param(token, info_sens.url,sizeof(info_sens.url))) break; for(int i=0;info_sens.url[i]; i++ ) { if(info_sens.url[i]=='\\') info_sens.url[i]='/'; } } else if(strstr(token,OliviaDef::GeneralDef::GR_sens_id)) { if(!olv->dame_param(token, info_sens.camps.id,sizeof(info_sens.camps.id))) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_sens_fecha)) { if(!olv->dame_param(token, info_sens.fecha_ini,sizeof(info_sens.fecha_ini))) break; } else if(strstr(token,OliviaDef::GeneralDef::GR_sens_fechaf)) { if(!olv->dame_param(token, info_sens.fecha_fin,sizeof(info_sens.fecha_fin))) break; } else if(strstr(token, OliviaDef::GeneralDef::GR_lateral)) { if(!olv->dame_param(token, &lateral)) break; } else { token = strtok(NULL, OliviaDef::GeneralDef::EjecGeoParamSep); continue; } token = strtok(NULL, OliviaDef::GeneralDef::EjecGeoParamSep); j++; } strcpy_s(olv->paths.path_res_rut,MAX_PATH,olv->paths.path_data); strcpy_s(olv->paths.path_res_pt,MAX_PATH,olv->paths.path_data); inicia_limp(); return j; } //************************************************************************************* /** * Inicia las tareas de la utilidad de limpieza viaria */ BOOL Colv_reco::inicia() { //arranca el thread thr_reco->inicia_th(); //empieza importando thr_reco->encola(thr_reco->OLV_LIMP_EV_ABRE_DAT,NULL,FALSE); return TRUE; } //************************************************************************************* void Colv_reco::dame_cost( double ltot, int ia, float *cost, float *cost2 ) { Colv_limp::dame_cost(ltot,ia,cost,cost2); //sustituye el caso de que sea contenedor if((iaso[ia].flgs & OLV_LIMP_FLG_AMB) && (tipo_ambit==OLV_AMB_PUN)) { *cost=*cost2=(float)(t_tto*iaso[ia].inf_r.uds); //en segundos, el tiempo que tarda en vaciar un contenedor, por el número de contenedores } } //************************************************************************************* /** * Rellena los campos del método POST para lectura de los sensores */ void Colv_reco::rellena_campos_sens() { //info para el cuerpo del envío post sprintf_s(info_sens.camps.fn,OLV_MAX_CAMP_HTTP,"fn"); sprintf_s(info_sens.camps.id,OLV_MAX_CAMP_HTTP,"id"); sprintf_s(info_sens.camps.usr,OLV_MAX_CAMP_HTTP,"usr"); sprintf_s(info_sens.camps.pwd,OLV_MAX_CAMP_HTTP,"pwd"); sprintf_s(info_sens.camps.startdate,OLV_MAX_CAMP_HTTP,"startdate"); sprintf_s(info_sens.camps.enddate,OLV_MAX_CAMP_HTTP,"enddate"); //el envío del POST al web service sprintf_s(info_sens.fn_cont_status,OLV_MAX_URL,"get_container_status"); sprintf_s(info_sens.usr,OLV_MAX_CAMP_HTTP,"VSM"); sprintf_s(info_sens.pwd,OLV_MAX_CAMP_HTTP,"VSM2017"); sprintf_s(info_sens.url,OLV_MAX_URL,"http://localiza.info/Utilidades/APIManager.aspx"); //la respuesta del servicio en JSON sprintf_s(info_sens.camps_json.histo,OLV_MAX_CAMP_HTTP_LONG,"HistoricalFillingData"); sprintf_s(info_sens.camps_json.id,OLV_MAX_CAMP_HTTP_LONG,"ContainerID"); sprintf_s(info_sens.camps_json.porc,OLV_MAX_CAMP_HTTP_LONG,"FillingPercentage"); sprintf_s(info_sens.camps_json.resp_code,OLV_MAX_CAMP_HTTP_LONG,"ResponseCode"); sprintf_s(info_sens.camps_json.resp_code_err,OLV_MAX_CAMP_HTTP_LONG,"ERROR"); sprintf_s(info_sens.camps_json.resp_data,OLV_MAX_CAMP_HTTP_LONG,"ResponseData"); CTime tt = CTime::GetCurrentTime(); sprintf_s(info_sens.fecha_fin,OLV_MAX_CAMP_HTTP_LONG,"%04d-%02d-%02dT%02d%%%%3A00%02d%%%%3A00%02d",tt.GetYear(),tt.GetMonth(),tt.GetDay(), tt.GetHour(),tt.GetMinute(),tt.GetSecond());//"2017-10-19T13:44:00"); tt = tt - CTimeSpan(0,1,0,0); //una hora menos sprintf_s(info_sens.fecha_ini,OLV_MAX_CAMP_HTTP_LONG,"%04d-%02d-%02dT%02d%%%%3A00%02d%%%%3A00%02d",tt.GetYear(),tt.GetMonth(),tt.GetDay(), tt.GetHour(),tt.GetMinute(),tt.GetSecond());//"2017-10-19T13:44:00"); info_sens.modo_pet=OLV_SENS_PET_UNICO; info_sens.porc_lim= 0; if(olv->paths.path_cfg_geo[0]) { if(!lee_campos_sens_ini(olv->paths.path_cfg_geo)) guarda_campos_sens_ini(olv->paths.path_cfg_geo); } } //************************************************************************************* BOOL Colv_reco::lee_campos_sens_ini(char *path) { Cini_file ini; int ig; if(!ini.lee(path)) return FALSE; ig=ini.get_grupo(OLV_RECO_GRUPO_SENS); if(ig<0) return FALSE;//no existe grupo //leer campos del ini ini.dame_valor(ig,OLV_RECO_PARAM_FN,info_sens.camps.fn,"fn"); ini.dame_valor(ig,OLV_RECO_PARAM_ID,info_sens.camps.id,"id"); ini.dame_valor(ig,OLV_RECO_PARAM_USR,info_sens.camps.usr,"usr"); ini.dame_valor(ig,OLV_RECO_PARAM_PWD,info_sens.camps.pwd,"pwd"); ini.dame_valor(ig,OLV_RECO_PARAM_STRD,info_sens.camps.startdate,"startdate"); ini.dame_valor(ig,OLV_RECO_PARAM_ENDD,info_sens.camps.enddate,"enddate"); ini.dame_valor(ig,OLV_RECO_PARAM_FN_STAT,info_sens.fn_cont_status,"get_container_status"); ini.dame_valor(ig,OLV_RECO_PARAM_USR_USR,info_sens.usr,"VSM"); ini.dame_valor(ig,OLV_RECO_PARAM_PWD_PWD,info_sens.pwd,"VSM2017"); ini.dame_valor(ig,OLV_RECO_PARAM_JS_ID,info_sens.camps_json.id,"ContainerID"); ini.dame_valor(ig,OLV_RECO_PARAM_JS_HISTO,info_sens.camps_json.histo,"HistoricalFillingData"); ini.dame_valor(ig,OLV_RECO_PARAM_JS_PORC,info_sens.camps_json.porc,"FillingPercentage"); ini.dame_valor(ig,OLV_RECO_PARAM_JS_R_CODE,info_sens.camps_json.resp_code,"ResponseCode"); ini.dame_valor(ig,OLV_RECO_PARAM_JS_R_CODE_ERR,info_sens.camps_json.resp_code_err,"ERROR"); ini.dame_valor(ig,OLV_RECO_PARAM_JS_R_DATA,info_sens.camps_json.resp_data,"ResponseData"); return TRUE; } //************************************************************************************* BOOL Colv_reco::guarda_campos_sens_ini(char *path) { Cini_file ini; int ig =ini.add_grupo(OLV_RECO_GRUPO_SENS); if(ig<0) return FALSE; ini.add(ig,OLV_RECO_PARAM_FN,info_sens.camps.fn); ini.add(ig,OLV_RECO_PARAM_ID,info_sens.camps.id); ini.add(ig,OLV_RECO_PARAM_USR,info_sens.camps.usr); ini.add(ig,OLV_RECO_PARAM_PWD,info_sens.camps.pwd); ini.add(ig,OLV_RECO_PARAM_STRD,info_sens.camps.startdate); ini.add(ig,OLV_RECO_PARAM_ENDD,info_sens.camps.enddate); ini.add(ig,OLV_RECO_PARAM_FN_STAT,info_sens.fn_cont_status); ini.add(ig,OLV_RECO_PARAM_USR_USR,info_sens.usr); ini.add(ig,OLV_RECO_PARAM_PWD_PWD,info_sens.pwd); ini.add(ig,OLV_RECO_PARAM_JS_ID,info_sens.camps_json.id); ini.add(ig,OLV_RECO_PARAM_JS_HISTO,info_sens.camps_json.histo); ini.add(ig,OLV_RECO_PARAM_JS_PORC,info_sens.camps_json.porc); ini.add(ig,OLV_RECO_PARAM_JS_R_CODE,info_sens.camps_json.resp_code); ini.add(ig,OLV_RECO_PARAM_JS_R_CODE_ERR,info_sens.camps_json.resp_code_err); ini.add(ig,OLV_RECO_PARAM_JS_R_DATA,info_sens.camps_json.resp_data); if(!ini.guarda(path)) return FALSE; return TRUE; } //************************************************************************************* #endif