void bacnetHandleMaxMin(int id_bacnet_line,unsigned long value) { time_t ts_cur,ts_min,ts_max; int d_cur,m_cur,y_cur,d_min,m_min,y_min,d_max,m_max,y_max; struct tm *tm_cur; struct tm *tm_min; struct tm *tm_max; bool tostore; MYSQL *conn; ts_cur=time(NULL); tm_cur=localtime(&ts_cur); d_cur=tm_cur->tm_mday; m_cur=tm_cur->tm_mon; y_cur=tm_cur->tm_year; tostore=FALSE; ts_min=bacnetTable[id_bacnet_line].ts_min; tm_min=localtime(&ts_min); d_min=tm_min->tm_mday; m_min=tm_min->tm_mon; y_min=tm_min->tm_year; ts_max=bacnetTable[id_bacnet_line].ts_max; tm_max=localtime(&ts_max); d_max=tm_max->tm_mday; m_max=tm_max->tm_mon; y_max=tm_max->tm_year; if((value>bacnetTable[id_bacnet_line].value_max) ||(d_cur!=d_max) ||(m_cur!=m_max) ||(y_cur!=y_max)) { tostore=TRUE; bacnetTable[id_bacnet_line].ts_max=ts_cur; bacnetTable[id_bacnet_line].value_max=value; } if((value<bacnetTable[id_bacnet_line].value_min) ||(d_cur!=d_min) ||(m_cur!=m_min) ||(y_cur!=y_min)) { tostore=TRUE; bacnetTable[id_bacnet_line].ts_min=ts_cur; bacnetTable[id_bacnet_line].value_min=value; } if(tostore) { conn=mysqlConnect(); if(!conn) return; storeBacnetLine(id_bacnet_line,conn); mysql_close(conn); } }
/** * Creates a basic MySQL object using the given logger */ MySQLHandler::MySQLHandler (Logger *new_logger) { connection = NULL; mysql_mutex = PTHREAD_MUTEX_INITIALIZER; query_mutex = PTHREAD_MUTEX_INITIALIZER; logger = new_logger; logger->log (" MYSQL: Object created, attempting to connect.\n"); mysqlConnect (); }
int storeAlarm(int adId,int systemId,int channelId,char *msg) { char query[255]; int out=0; MYSQL *conn=mysqlConnect(); sprintf(query,"call insertAlarm(%d,%d,%d,'%s')",adId,systemId,channelId,msg); if(mysql_query(conn,query)!=0) my_printf("%s\n%s\n",query,mysql_error(conn)); out=mysql_affected_rows(conn); mysql_close(conn); return out; }
void readSystemDefaults() { MYSQL_RES *result; MYSQL_ROW row; int state; char query[255]; MYSQL *conn; conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return; } //READ SYSTEM DEFAULTS strcpy(query,"SELECT record_data_time,localita,nome,reboot_time,offset_effe FROM system_ini"); state = mysql_query(conn, query); if( state != 0 ) { printf("%s\n",mysql_error(conn)); my_printf("%s - %s\n",query,mysql_error(conn)); termination_handler(2); } result = mysql_store_result(conn); if( ( row = mysql_fetch_row(result)) != NULL ) { RECORDDATATIME=60*atoi(row[0]); if(row[1]) strcpy(LOCALITA,row[1]); else strcpy(LOCALITA,""); if(row[2]) strcpy(NOME,row[2]); else strcpy(NOME,""); MAXATTEMPTS=atoi(row[3])/2; OFFSET_EFFE=atoi(row[4]); } mysql_free_result(result); mysql_close(conn); //END READ SYSTEM DEFAULTS }
void updateBacnet(int id_bacnet_device) { int state; int id; MYSQL_RES *result; MYSQL_ROW row; char query[255]; int i; MYSQL *conn=mysqlConnect(); id=id_bacnet_deviceToId(id_bacnet_device); if(id==-1) return; if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return; } bacnetDevices[id].enabled=0; //preventing bacnet to work while in update sprintf(query,"SELECT bacnet_devices.address,bacnet_devices.port,bacnet_devices.enabled" " FROM bacnet_devices " " WHERE bacnet_devices.id=%d",id_bacnet_device); state = mysql_query(conn,query); if( state != 0 ) my_printf("%s\n",mysql_error(conn)); result = mysql_store_result(conn); if (( row = mysql_fetch_row(result)) != NULL ) { if(row[0]) strcpy(bacnetDevices[id].address,row[0]); else strcpy(bacnetDevices[id].address,""); bacnetDevices[id].port=atoi(row[1]); bacnetDevices[id].enabled=atoi(row[2]); if(bacnetDevices[id].enabled) bacnetDevices[id].enabled=2; //force restart } mysql_free_result(result); mysql_close(conn); }
void valueInRange(int adId,int systemId,int channelId) /*-------------------------------------------- * ritorno da allarme * int adId 0=analogico, 1=digitale, 2=digital_out, 3=mm ecc * int systemId device number * int channelId channel number * -----------------------------------------*/ { char query[255]; MYSQL *conn=mysqlConnect(); if(!conn) return; sprintf(query,"UPDATE alarms SET inattivo=1 " "WHERE board_type='%d' AND device_id='%d' AND ch_id='%d'" ,adId,systemId,channelId); if(mysql_query(conn,query)!=0) my_printf("%s\n%s\n",query,mysql_error(conn)); mysql_close(conn); }
void storeBacnetTable(int id_bacnet_device) { int i; MYSQL *conn=mysqlConnect(); if(!conn) return; for(i=0;i<NUMBACNETLINES;i++) { if((bacnetDevices[bacnetDeviceToId(id_bacnet_device)].enabled) &&(bacnetTable[i].id_bacnet_device==id_bacnet_device) &&(bacnetTable[i].id!=-1) &&(bacnetTable[i].value_valid) &&(time(NULL)-bacnetTable[i].stored_time>=bacnetTable[i].record_data_time)) { storeBacnetLine(i,conn); usleep(1000); } } mysql_close(conn); }
void storeDigitalTable(int device_num) { int i; MYSQL *conn=mysqlConnect(); if(!conn) return; for(i=0;i<DIGITALCHANNELS;i++) { if(((device_num==0)||(digitalTable[i].device_num==device_num)) &&(systems[systemNumToId(digitalTable[i].device_num,NUMSYSTEMS)].enabled) &&(digitalTable[i].enabled) &&(digitalTable[i].id_digital!=-1) &&(digitalTable[i].value_valid) &&(time(NULL)-digitalTable[i].stored_time>=digitalTable[i].record_data_time)) { storeDigitalLine(i,conn); usleep(1000); } } mysql_close(conn); }
int main(int argc, char *argv[]) { int i; connection=mysqlConnect(); NUMCEIABIGATEWAYS=0; if(loadCEIABI(0)) { killAllSystems(); exit(0); } for(i=0;i<NUMCEIABIGATEWAYS;i++) { printf("%d %s\n",CEIABIGateways[i].id_CEIABI_gateway,CEIABIGateways[i].address); printf("\n"); } printf("pid: %d\n",getpid()); doCEIABI(0); }
void storeEvent(int event_type,int device_num,int ch_num,int ch_id,char *msg) /*-------------------------------------------- * salva evento su tabella events * int event_type 1=irrigazione, 2=circuito_irrigazione * int id id da tabella db * int device_num * int ch_num * int ch_id * char *msg messaggio * -----------------------------------------*/ { char *query; MYSQL *conn=mysqlConnect(); if(!conn) return; query=(char *)malloc(strlen(msg)+255); sprintf(query,"INSERT INTO events(data,event_type,device_num,ch_num,ch_id,msg) " "VALUES (NOW(),'%d','%d','%d','%d','%s')",event_type,device_num,ch_num,ch_id,msg); if(mysql_query(conn,query)!=0) my_printf("%s\n%s\n",query,mysql_error(conn)); free(query); mysql_close(conn); }
int loadScenariBgBnTable(bool onlyupdate) { MYSQL_RES *result; MYSQL_ROW row; int state; int i,k; int idRow; int out; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return (1); } state = mysql_query(conn, "SELECT id_digital_out,attivo,ritardo," "giorno " "FROM scenari_giorno_notte " "ORDER BY id"); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } result = mysql_store_result(conn); SCENARIBGBNCOUNT=mysql_num_rows(result); if(!onlyupdate) { if(SCENARIBGBNCOUNT) { my_printf("get_shared_memory_segment: scenariBgBnTable\n"); scenariBgBnTable=(struct scenariBgBnLine *)get_shared_memory_segment(SCENARIBGBNCOUNT * sizeof(struct scenariPresenzeLine), &SHMSCENARIBGBNID, "/dev/zero"); if(!scenariBgBnTable) die("scenariBgBnTable - get_shared_memory_segment\n"); } else scenariBgBnTable=0; my_printf("get_shared_memory_segment: buonGiornoAttivo\n"); buonGiornoAttivo=(char *)get_shared_memory_segment(1, &SHMSCENARIBGATTIVOID, "/dev/zero"); if(!buonGiornoAttivo) die("buonGiornoAttivo - get_shared_memory_segment\n"); my_printf("get_shared_memory_segment: buonaNotteAttivo\n"); buonaNotteAttivo=(char *)get_shared_memory_segment(1, &SHMSCENARIBNATTIVOID, "/dev/zero"); if(!buonaNotteAttivo) die("buonaNotteAttivo - get_shared_memory_segment\n"); } initializeScenariBgBnTable(); *buonGiornoAttivo=0; *buonaNotteAttivo=0; idRow=0; while( ( row = mysql_fetch_row(result)) != NULL ) { scenariBgBnTable[idRow].id_digital_out=atoi(row[0]); scenariBgBnTable[idRow].attivo=atoi(row[1]); scenariBgBnTable[idRow].ritardo=atoi(row[2]); scenariBgBnTable[idRow].bg=atoi(row[3]); idRow++; } mysql_free_result(result); mysql_close(conn); return(0); }
int updateBacnetChannel(int id) { MYSQL_RES *result; MYSQL_ROW row; int state; int i; int idRow; char query[512]; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return (-1); } i=id_bacnet_lineToId(id); if(i==-1) return(-1); sprintf(query,"SELECT bacnet_inputs.object_type," "bacnet_inputs.object_instance," "bacnet_inputs.description," "bacnet_inputs.hi_low_msg," "bacnet_inputs.low_hi_msg," "bacnet_inputs.is_alarm," "bacnet_inputs.alarm_msg," "bacnet_inputs.record_data_time " " FROM bacnet_inputs" " WHERE bacnet_inputs.id='%d'",id); state = mysql_query(conn, query); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(-1); } result = mysql_store_result(conn); if(mysql_num_rows(result)!=1) return -1; while( ( row = mysql_fetch_row(result)) != NULL ) { bacnetTable[i].object_type=atoi(row[0]); bacnetTable[i].object_instance=atoi(row[1]); if(row[2]) strcpy(bacnetTable[i].description,row[2]); else strcpy(bacnetTable[i].description,""); if(bacnetTable[i].object_type==3) { if(row[3]) strcpy(bacnetTable[i].hi_low_msg,row[3]); else strcpy(bacnetTable[i].hi_low_msg,""); if(row[4]) strcpy(bacnetTable[i].low_hi_msg,row[4]); else strcpy(bacnetTable[i].low_hi_msg,""); bacnetTable[i].is_alarm=atoi(row[5]); if(row[6]) strcpy(bacnetTable[i].alarm_msg,row[6]); else strcpy(bacnetTable[i].alarm_msg,""); bacnetTable[i].record_data_time=(atoi(row[7])!=-1?60*atoi(row[7]):RECORDDATATIME); } else { strcpy(bacnetTable[i].hi_low_msg,""); strcpy(bacnetTable[i].low_hi_msg,""); bacnetTable[i].is_alarm=FALSE; strcpy(bacnetTable[i].alarm_msg,""); } } mysql_free_result(result); mysql_close(conn); return(0); }
int loadIntrusione() { MYSQL_RES *result; MYSQL_ROW row; int state; int i,j,k,n; int idRow; int out; int n_ss; int id_sistema; char descrizione[30]; unsigned char enabled; int id_digital; int id_digital_out; int id_ai_sottosistema; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return (1); } // sistemi state = mysql_query(conn, "SELECT ai_sistemi.id_sistema," "ai_sistemi.descrizione,ai_sistemi.enabled," "count(ai_sottosistemi.id_ai_sottosistema) AS n_ss " "FROM ai_sistemi LEFT JOIN ai_sottosistemi " "ON ai_sistemi.id_sistema=ai_sottosistemi.id_ai_sistema " "GROUP BY ai_sistemi.id_sistema"); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } result = mysql_store_result(conn); NUM_AI_SISTEMI=mysql_num_rows(result); if(NUM_AI_SISTEMI==0) return; my_printf("get_shared_memory_segment: ai_sistemi\n"); ai_sistemi=(struct ai_system_node *)get_shared_memory_segment (NUM_AI_SISTEMI * sizeof(struct system), &SHMAISYSTEMS, "/dev/zero"); if(!ai_sistemi) die("ai_sistemi - get_shared_memory_segment\n"); idRow=0; while( ( row = mysql_fetch_row(result)) != NULL ) { id_sistema=atoi(row[0]); if(row[1]) strcpy(descrizione,row[1]); else strcpy(descrizione,""); enabled=atoi(row[2]); n_ss=atoi(row[3]); ai_sistemi[idRow].id_sistema=id_sistema; strcpy(ai_sistemi[idRow].descrizione,descrizione); ai_sistemi[idRow].enabled=enabled; ai_sistemi[idRow].n_ss=n_ss; ai_sistemi[idRow].ss_active=0; ai_sistemi[idRow].active=0; ai_sistemi[idRow].ss_nodes=(struct ai_sottosistema *)malloc(n_ss*sizeof(struct ai_sottosistema)); for(i=0;i<n_ss;i++) ai_sistemi[idRow].ss_nodes[i].id_ai_sottosistema=-1; idRow++; } mysql_free_result(result); // sottosistemi state = mysql_query(conn, "SELECT ai_sistemi.id_sistema, " "ai_sottosistemi.id_ai_sottosistema, ai_sottosistemi.descrizione, " "COUNT( ai_sottosistemi_input_output.id_ai_input_output ) as c " "FROM ai_sistemi LEFT JOIN ai_sottosistemi " "ON ai_sistemi.id_sistema = ai_sottosistemi.id_ai_sistema " "LEFT JOIN ai_sottosistemi_input_output " "ON ai_sottosistemi.id_ai_sottosistema = " "ai_sottosistemi_input_output.id_ai_sottosistema " "WHERE ai_sottosistemi.id_ai_sottosistema IS NOT NULL " "GROUP BY ai_sottosistemi.id_ai_sottosistema"); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } result = mysql_store_result(conn); while( ( row = mysql_fetch_row(result)) != NULL ) { id_sistema=atoi(row[0]); id_ai_sottosistema=atoi(row[1]); if(row[2]) strcpy(descrizione,row[2]); else strcpy(descrizione,""); n=atoi(row[3]); for(i=0;i<NUM_AI_SISTEMI;i++) if(ai_sistemi[i].id_sistema==id_sistema) break; if(i<NUM_AI_SISTEMI) { for(k=0;k<ai_sistemi[i].n_ss;k++) if(ai_sistemi[i].ss_nodes[k].id_ai_sottosistema==-1) break; if(k<ai_sistemi[i].n_ss) { ai_sistemi[i].ss_nodes[k].id_ai_sottosistema=id_ai_sottosistema; strcpy(ai_sistemi[i].ss_nodes[k].descrizione,descrizione); ai_sistemi[i].ss_nodes[k].n_in=n; ai_sistemi[i].ss_nodes[k].ai_input_nodes= (struct ai_input_node **)malloc(n*sizeof(struct ai_input_node *)); for(j=0;j<n;j++) ai_sistemi[i].ss_nodes[k].ai_input_nodes[j]=0; } } } // canali state = mysql_query(conn, "SELECT ai_sistemi.id_sistema, " "ai_input_output.id_digital, ai_input_output.id_digital_out, " "ai_sottosistemi_input_output.id_ai_sottosistema " "FROM ai_sistemi " "LEFT JOIN ai_input_output " "ON ai_sistemi.id_sistema = ai_input_output.id_sistema " "LEFT JOIN ai_sottosistemi " "ON ai_sistemi.id_sistema = ai_sottosistemi.id_ai_sistema " "LEFT JOIN ai_sottosistemi_input_output " "ON ai_input_output.id_ai_input_output = ai_sottosistemi_input_output.id_ai_input_output " "AND ai_sottosistemi.id_ai_sottosistema = ai_sottosistemi_input_output.id_ai_sottosistema "); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } result = mysql_store_result(conn); idRow=0; while( ( row = mysql_fetch_row(result)) != NULL ) { id_sistema=atoi(row[0]); id_digital=atoi(row[1]); id_digital_out=atoi(row[2]); id_ai_sottosistema=atoi(row[3]?row[3]:"0"); addNode(id_sistema,id_digital,id_digital_out,id_ai_sottosistema); idRow++; } mysql_free_result(result); printAI(); mysql_close(conn); return(0); }
/** * Perform a query (returns a result set) */ MYSQL_RES* MySQLHandler::mysqlQuery (const char *format, ...) { lock (query_mutex); // Check to make sure we have a connection and then perform the query if (connection) { // Builds the query va_list args; va_start (args, format); char query[512]; memset (query, 0, strlen (query)); vsnprintf (query, 512, format, args); MYSQL_RES* temp_result_set; logger->debugf (DEBUG_DETAILED, " MYSQL DEBUG 3: mysqlQuery called with, %s.\n", query); lock (mysql_mutex); if (mysql_query (connection, query)) { logger->debugf (DEBUG_MINIMAL, " MYSQL DEBUG 1: Query failed, %s.\n", mysql_error (connection)); // If the server has disconnected, reconnect and try again if ((mysql_errno (connection) == CR_SERVER_GONE_ERROR) || (mysql_errno (connection) == CR_SERVER_LOST)) { release (mysql_mutex); mysqlDisconnect (); mysqlConnect (); lock (mysql_mutex); if (mysql_query (connection, query)) { logger->debugf (DEBUG_MINIMAL, " MYSQL DEBUG 1: Query failed again after reconnect, %s.\n", mysql_error (connection)); va_end(args); release (mysql_mutex); release (query_mutex); return NULL; } } else { va_end(args); release (mysql_mutex); release (query_mutex); return NULL; } } temp_result_set = mysql_store_result (connection); va_end(args); release (mysql_mutex); release (query_mutex); return temp_result_set; } else { release (query_mutex); logger->log (" MYSQL: Failed to perform the query because there was no connection.\n"); return NULL; } }
void loadAllSystems() { int i=0,j=0,k,l; struct timeval tim; double t1; int knx_ch_in; int knx_ch_out; MYSQL *conn; panels=NULL; NUMPANELS=0; NUMSMSDEVICES=0; NUMSMSNUMBERS=0; NUMKNXCHANNELS=0; ANALOGCHANNELS=0; DIGITALCHANNELS=0; DIGITALOUTCHANNELS=0; READINGCHANNELS=0; SCENARIPRESENZECOUNT=0; SCENARIBGBNCOUNT=0; IRRIGAZIONECIRCUITS=0; IRRIGAZIONESYSTEMS=0; MAXATTEMPTS=5; OFFSET_EFFE=0; LOCALITA[30]; RECORDDATATIME=300; RNDSEED=0; NUMBACNETDEVICES=0; NUMBACNETLINES=0; NUMCEIABIGATEWAYS=0; gettimeofday(&tim, NULL); t1=tim.tv_sec+(tim.tv_usec/1000000.0); //MYSQL STUFF conn=mysqlConnect(); if( conn == NULL ) { my_printf("error connecting: %s\n",mysql_error(conn)); termination_handler(2); } //READ SYSTEM DEFAULTS (needs mysql); my_printf("reading system defaults\n"); readSystemDefaults(); //READ EFFEMERIDI (needs mysql); my_printf("reading effemeridi\n"); readEffemeridi(); mysql_close(conn); if(loadSMS(0)) termination_handler(2); if(loadSystemTable(0)) termination_handler(2); if(loadMultimeterTable(0)) termination_handler(2); if(loadKnx(0)) termination_handler(2); if(loadBacnet(0)) termination_handler(2); if(loadCEIABI(0)) termination_handler(2); /* for(i=0;i<NUMMULTIMETERS;i++) { my_printf("%d %s\n",multimeters[i].multimeter_num,multimeters[i].address); for(j=0;j<multimeters[i].in_bytes_1_length;j++) my_printf("%x ",multimeters[i].in_bytes_1[j]); my_printf("\n"); for(j=0;j<multimeters[i].in_bytes_2_length;j++) my_printf("%x ",multimeters[i].in_bytes_2[j]); my_printf("\n"); } */ TOTALSYSTEMS=NUMSYSTEMS+NUMMULTIMETERS+ NUMKNXGATEWAYS+NUMBACNETDEVICES+NUMCEIABIGATEWAYS; pid=(int *)malloc((TOTALSYSTEMS) * sizeof(int)); deviceToid=(int ***)malloc(6*sizeof(int **)); deviceToid[ANALOG]=(int **)malloc(NUMSYSTEMS * sizeof(int *)); //analog deviceToid[DIGITAL]=(int **)malloc(NUMSYSTEMS * sizeof(int *)); //digital deviceToid[DIGITAL_OUT]=(int **)malloc(NUMSYSTEMS * sizeof(int *)); //digital_out deviceToid[MULTIMETER]=(int **)malloc(NUMMULTIMETERS * sizeof(int *)); //mm deviceToid[KNX_IN]=(int **)malloc(NUMKNXGATEWAYS * sizeof(int *)); //knx_in deviceToid[KNX_OUT]=(int **)malloc(NUMKNXGATEWAYS * sizeof(int *)); //knx_out deviceToid[BACNET]=(int **)malloc(NUMBACNETDEVICES * sizeof(int *)); //bacnet deviceToid[CEIABI]=(int **)malloc(NUMCEIABIGATEWAYS * sizeof(int *)); //ceiabi for(i=0;i<NUMSYSTEMS;i++) { deviceToid[ANALOG][i]=(int *)malloc(systems[i].in_ch_an*sizeof(int)); for(k=0;k<systems[i].in_ch_an;k++) deviceToid[ANALOG][i][k]=-1; deviceToid[DIGITAL][i]=(int *)malloc(systems[i].in_ch_d*sizeof(int)); for(k=0;k<systems[i].in_ch_d;k++) deviceToid[DIGITAL][i][k]=-1; deviceToid[DIGITAL_OUT][i]=(int *)malloc(systems[i].out_ch_d*sizeof(int)); for(k=0;k<systems[i].out_ch_d;k++) deviceToid[DIGITAL_OUT][i][k]=-1; } for(i=0;i<NUMMULTIMETERS;i++) { deviceToid[MULTIMETER][i]=(int *)malloc((multimeters[i].out_ch_1+multimeters[i].out_ch_2)*sizeof(int)); for(k=0;k<multimeters[i].out_ch_1+multimeters[i].out_ch_2;k++) deviceToid[MULTIMETER][i][k]=-1; } for(i=0;i<NUMKNXGATEWAYS;i++) { deviceToid[KNX_IN][i]=(int *)malloc((knxGateways[i].ch_in)*sizeof(int)); for(k=0;k<knxGateways[i].ch_in;k++) deviceToid[KNX_IN][i][k]=-1; deviceToid[KNX_OUT][i]=(int *)malloc((knxGateways[i].ch_out)*sizeof(int)); for(k=0;k<knxGateways[i].ch_out;k++) deviceToid[KNX_OUT][i][k]=-1; } knx_ch_in=0; knx_ch_out=0; for(k=0;k<NUMKNXCHANNELS;k++) { l=id_knx_gatewayToId(knxTable[k].id_knx_gateway); if(l!=-1) { if(knxTable[k].input_output==1) { deviceToid[KNX_IN][l][knx_ch_in]=k; knx_ch_in++; } else { deviceToid[KNX_OUT][l][knx_ch_out]=k; knx_ch_out++; } } } for(i=0;i<NUMBACNETDEVICES;i++) { deviceToid[BACNET][i]=(int *)malloc(bacnetDevices[i].in_ch*sizeof(int)); for(k=0;k<bacnetDevices[i].in_ch;k++) deviceToid[BACNET][i][k]=-1; } for(i=0;i<NUMCEIABIGATEWAYS;i++) { deviceToid[CEIABI][i]=(int *)malloc(CEIABIGateways[i].in_ch*sizeof(int)); for(k=0;k<CEIABIGateways[i].in_ch;k++) deviceToid[CEIABI][i][k]=-1; } /* my_printf("ANALOGCHANNELS - DIGITALCHANNELS - DIGITALOUTCHANNELS - READINGCHANNELS\n"); my_printf("%d - %d - %d - %d\n",ANALOGCHANNELS,DIGITALCHANNELS,DIGITALOUTCHANNELS,READINGCHANNELS); */ if(loadDigitalOutTable(0)) termination_handler(2); if(loadScenariPresenzeTable(0)) termination_handler(2); if(loadScenariBgBnTable(0)) termination_handler(2); if(loadDigitalTable(0)) termination_handler(2); if(loadAnalogTable(0)) termination_handler(2); if(loadReadingTable(0)) termination_handler(2); if(loadIrrigazioneTables(0,0)) termination_handler(2); if(loadIntrusione()) termination_handler(2); /* my_printf("--- PANELS ---\n"); loadPanels(); for(i=0;i<NUMPANELS;i++) for(j=0;j<16;j++) my_printf("%d %d %d\n",i,j,panels[i][j]); my_printf("--- ANALOG ---\n"); for(i=0;i<NUMSYSTEMS;i++) for(j=0;j<systems[i].in_ch_an;j++) if(analogTable[deviceToid[0][i][j]].id_analog!=-1) my_printf("%d %d %d %s %d\n",analogTable[deviceToid[0][i][j]].id_analog, analogTable[deviceToid[0][i][j]].device_num, analogTable[deviceToid[0][i][j]].ch_num, analogTable[deviceToid[0][i][j]].description, analogTable[deviceToid[0][i][j]].enabled); my_printf("--- DIGITAL ---\n"); for(i=0;i<NUMSYSTEMS;i++) for(j=0;j<systems[i].in_ch_d;j++) if(digitalTable[deviceToid[1][i][j]].id_digital!=-1) my_printf("%d %d %s %d\n",digitalTable[deviceToid[1][i][j]].device_num, digitalTable[deviceToid[1][i][j]].ch_num, digitalTable[deviceToid[1][i][j]].description, digitalTable[deviceToid[1][i][j]].enabled); my_printf("--- DIGITALOUT ---\n"); for(i=0;i<NUMSYSTEMS;i++) for(j=0;j<systems[i].out_ch_d;j++) if(digitalOutTable[deviceToid[2][i][j]].id_digital_out!=-1) my_printf("%d %d %d %s %d %d - %d %d\n", digitalOutTable[deviceToid[2][i][j]].id_digital_out, digitalOutTable[deviceToid[2][i][j]].device_num, digitalOutTable[deviceToid[2][i][j]].ch_num, digitalOutTable[deviceToid[2][i][j]].description, digitalOutTable[deviceToid[2][i][j]].def, digitalOutTable[deviceToid[2][i][j]].value, digitalOutTable[deviceToid[2][i][j]].po_delay, digitalOutTable[deviceToid[2][i][j]].on_time); my_printf("--- MM ---\n"); for(i=0;i<NUMMULTIMETERS;i++) for(j=0;j<multimeters[i].out_ch_1+multimeters[i].out_ch_2;j++) if(readingTable[deviceToid[3][i][j]].id_reading!=-1) my_printf("%d %d %d %s %d\n",readingTable[deviceToid[3][i][j]].id_reading, readingTable[deviceToid[3][i][j]].multimeter_num, readingTable[deviceToid[3][i][j]].ch_num, readingTable[deviceToid[3][i][j]].description, readingTable[deviceToid[3][i][j]].enabled); my_printf("--- KNX IN ---\n"); for(i=0;i<NUMKNXGATEWAYS;i++) for(j=0;j<knxGateways[i].ch_in;j++) if(knxTable[deviceToid[4][i][j]].id_knx_line!=-1) my_printf("%d %d %s %c %s %d\n",knxTable[deviceToid[4][i][j]].id_knx_line, knxTable[deviceToid[4][i][j]].id_knx_gateway, knxTable[deviceToid[4][i][j]].group_address, knxTable[deviceToid[4][i][j]].data_type, knxTable[deviceToid[4][i][j]].description, knxTable[deviceToid[4][i][j]].enabled); my_printf("--- KNX ALL ---\n"); for(i=0;i<NUMKNXGATEWAYS;i++) for(j=0;j<knxGateways[i].ch_in+knxGateways[i].ch_out;j++) my_printf("%d %d %s %c %s %d\n",knxTable[j].id_knx_line, knxTable[j].id_knx_gateway, knxTable[j].group_address, knxTable[j].data_type, knxTable[j].description, knxTable[j].enabled); my_printf("--- KNX OUT ---\n"); for(i=0;i<NUMKNXGATEWAYS;i++) for(j=0;j<knxGateways[i].ch_out;j++) if(knxTable[deviceToid[5][i][j]].id_knx_line!=-1) my_printf("%d %d %s %c %s\n",knxTable[deviceToid[5][i][j]].id_knx_line, knxTable[deviceToid[5][i][j]].id_knx_gateway, knxTable[deviceToid[5][i][j]].group_address, knxTable[deviceToid[5][i][j]].data_type, knxTable[deviceToid[5][i][j]].description); my_printf("--- SCENARIPRESENZE ---\n"); for(i=0;i<SCENARIPRESENZECOUNT;i++) my_printf("%d %d %d %d %d %d %d\n",scenariPresenzeTable[i].id_digital_out, scenariPresenzeTable[i].attivo, scenariPresenzeTable[i].ciclico, scenariPresenzeTable[i].tempo_on, scenariPresenzeTable[i].tempo_off, scenariPresenzeTable[i].ora_ini, scenariPresenzeTable[i].ora_fine); my_printf("--- SCENARIBGBN ---\n"); for(i=0;i<SCENARIBGBNCOUNT;i++) my_printf("%d %d %d %d\n",scenariBgBnTable[i].id_digital_out, scenariBgBnTable[i].attivo, scenariBgBnTable[i].ritardo, scenariBgBnTable[i].bg); my_printf("--- IRRIGAZIONE ---\n"); for(i=0;i<IRRIGAZIONESYSTEMS;i++) my_printf("%d %d %d %d %d %d %d\n", irrigazioneTable[i].id_irrigazione, irrigazioneTable[i].ora_start, irrigazioneTable[i].ripetitivita, irrigazioneTable[i].tempo_off, irrigazioneTable[i].id_digital_out, irrigazioneTable[i].num_circuiti, IRRIGAZIONECIRCUITS); for(i=0;i<IRRIGAZIONECIRCUITS;i++) { if(irrigazioneCircuitiTable[i].id_irrigazione!=-1) my_printf("%d %d %d %d %d\n", irrigazioneCircuitiTable[i].id_irrigazione, irrigazioneCircuitiTable[i].circuito, irrigazioneCircuitiTable[i].id_digital_out, irrigazioneCircuitiTable[i].durata, irrigazioneCircuitiTable[i].validita); } my_printf("--- SMS ---\n"); for(i=0;i<NUMSMSDEVICES;i++) my_printf("%d %s %d %s\n", sms_devices[i].id_sms_device, sms_devices[i].address, sms_devices[i].port, sms_devices[i].description); for(i=0;i<NUMSMSNUMBERS;i++) my_printf("%d %s %s\n", sms_numbers[i].id_sms_number, sms_numbers[i].name, sms_numbers[i].number); my_printf("--- BACNET ---\n"); for(i=0;i<NUMBACNETDEVICES;i++) my_printf("%d %s %d %s %d %d %d %d\n", bacnetDevices[i].id, bacnetDevices[i].address, bacnetDevices[i].port, bacnetDevices[i].description, bacnetDevices[i].enabled, bacnetDevices[i].status, bacnetDevices[i].sockfd, bacnetDevices[i].failures); my_printf("--- BACNET_INPUT ---\n"); for(i=0;i<NUMBACNETLINES;i++) my_printf("%d %d %d %d %s %s %s %d %s %d\n", bacnetTable[i].id, bacnetTable[i].id_bacnet_device, bacnetTable[i].object_type, bacnetTable[i].object_instance, bacnetTable[i].description, bacnetTable[i].hi_low_msg, bacnetTable[i].low_hi_msg, bacnetTable[i].is_alarm, bacnetTable[i].alarm_msg, bacnetTable[i].value); */ my_printf("pid: %d\n",getpid()); gettimeofday(&tim, NULL); my_printf("%.6f seconds to initialise\n",(tim.tv_sec+(tim.tv_usec/1000000.0))-t1); //FINE MYSQL STUFF }
int loadScenariPresenzeTable(bool onlyupdate) { MYSQL_RES *result; MYSQL_ROW row; int state; int i,k; int idRow; int out; char query[255]; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return (1); } strcpy(query,"SELECT id_digital_out,attivo,ciclico," "tempo_on,tempo_off,ora_ini,ora_fine " "FROM scenari_presenze " "ORDER BY id"); state = mysql_query(conn, query); if( state != 0 ) { my_printf("%s - %s\n",query,mysql_error(conn)); return(1); } result = mysql_store_result(conn); SCENARIPRESENZECOUNT=mysql_num_rows(result); if(!onlyupdate) { if(SCENARIPRESENZECOUNT>0) { my_printf("get_shared_memory_segment: scenariPresenzeTable\n"); scenariPresenzeTable=(struct scenariPresenzeLine *)get_shared_memory_segment(SCENARIPRESENZECOUNT * sizeof(struct scenariPresenzeLine), &SHMSCENARIPRESENZEID, "/dev/zero"); if(!scenariPresenzeTable) die("scenariPresenzeTable - get_shared_memory_segment\n"); } else scenariPresenzeTable=0; my_printf("get_shared_memory_segment: scenariPresenzeAttivo\n"); scenariPresenzeAttivo=(char *)get_shared_memory_segment(2, &SHMSCENARIPRESENZEATTIVOID, "/dev/zero"); if(!scenariPresenzeAttivo) die("scenariPresenzeAttivo - get_shared_memory_segment\n"); } initializeScenariPresenzeTable(); *scenariPresenzeAttivo=0; idRow=0; while( ( row = mysql_fetch_row(result)) != NULL ) { scenariPresenzeTable[idRow].id_digital_out=atoi(row[0]); scenariPresenzeTable[idRow].attivo=atoi(row[1]); scenariPresenzeTable[idRow].ciclico=atoi(row[2]); scenariPresenzeTable[idRow].tempo_on=atoi(row[3]); scenariPresenzeTable[idRow].tempo_off=atoi(row[4]); scenariPresenzeTable[idRow].ora_ini=h2i(row[5]); scenariPresenzeTable[idRow].ora_fine=h2i(row[6]); idRow++; } mysql_free_result(result); mysql_close(conn); return(0); }
int loadDigitalTable(bool onlyupdate) { MYSQL_RES *result; MYSQL_ROW row; int state; int i,k; int idRow; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return (-1); } if(!onlyupdate) { if(DIGITALCHANNELS>0) { my_printf("get_shared_memory_segment: digitalTable\n"); digitalTable=(struct digitalLine *)get_shared_memory_segment(DIGITALCHANNELS * sizeof(struct digitalLine), &SHMDIGITALID, "/dev/zero"); if(!digitalTable) die("digitalTable - get_shared_memory_segment\n"); } else digitalTable=0; my_printf("get_shared_memory_segment: id_digital_pioggia\n"); id_digital_pioggia=(int *)get_shared_memory_segment(sizeof(int), &SHMPIOGGIA, "/dev/zero"); if(!id_digital_pioggia) die("id_digital_pioggia - get_shared_memory_segment\n"); } initializeDigitalTable(); state = mysql_query(conn, "SELECT digital.id_digital,digital.form_label," "digital.description,digital.label,digital.sinottico," "digital.device_num,digital.ch_num,digital.printer," "digital.time_delay_on,digital.time_delay_off," "digital.alarm_value,digital.msg_on,digital.msg_off," "digital.enabled,digital.sms,digital.msg_is_event,on_value, " "digital.record_data_time " "FROM digital JOIN system ON digital.device_num=system.device_num " "WHERE system.removed=0 AND digital.ch_num!=0" " ORDER BY digital.device_num, digital.ch_num"); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } result = mysql_store_result(conn); *id_digital_pioggia=-1; idRow=0; while( ( row = mysql_fetch_row(result)) != NULL ) { i=systemNumToId(atoi(row[5]),NUMSYSTEMS); if((i!=-1) && (atoi(row[6])<=systems[i].in_ch_d)) { if(!onlyupdate) deviceToid[1][i][atoi(row[6]) - 1]=idRow; else idRow=deviceToid[1][i][atoi(row[6]) - 1]; digitalTable[idRow].id_digital=atoi(row[0]); if(row[1]) safecpy(digitalTable[idRow].form_label,row[1]); else safecpy(digitalTable[idRow].form_label,""); if(row[2]) safecpy(digitalTable[idRow].description,row[2]); else safecpy(digitalTable[idRow].description,""); if(row[3]) safecpy(digitalTable[idRow].label,row[3]); else safecpy(digitalTable[idRow].label,""); if(row[4]) safecpy(digitalTable[idRow].sinottico,row[4]); else safecpy(digitalTable[idRow].sinottico,""); digitalTable[idRow].device_num=atoi(row[5]); digitalTable[idRow].ch_num=atoi(row[6]); digitalTable[idRow].printer=atoi(row[7]); digitalTable[idRow].time_delay_on=atoi(row[8]); digitalTable[idRow].time_delay_off=atoi(row[9]); digitalTable[idRow].alarm_value=atoi(row[10]); if(row[11]) safecpy(digitalTable[idRow].msg_on,row[11]); else safecpy(digitalTable[idRow].msg_on,""); if(row[12]) safecpy(digitalTable[idRow].msg_off,row[12]); else safecpy(digitalTable[idRow].msg_off,""); digitalTable[idRow].enabled=atoi(row[13]); digitalTable[idRow].sms=atoi(row[14]); digitalTable[idRow].msg_is_event=atoi(row[15]); digitalTable[idRow].on_value=atoi(row[16]); digitalTable[idRow].record_data_time=(atoi(row[17])!=-1?60*atoi(row[17]):RECORDDATATIME); if(strstr(strtoupper(digitalTable[idRow].label),"PIOGGIA")) *id_digital_pioggia=idRow; idRow++; } } mysql_free_result(result); if(!onlyupdate) { for(i=0;i<NUMSYSTEMS;i++) for(k=0;k<systems[i].in_ch_d;k++) if(deviceToid[1][i][k]==-1) { deviceToid[1][i][k]=idRow; idRow++; } if(idRow!=DIGITALCHANNELS) my_printf("there's a problem with digital channels\n"); } mysql_close(conn); return(0); }
void loadPanels() { int curPanel=0; MYSQL_RES *result; MYSQL_ROW row; int state; int i,j; int temp; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return; } temp=NUMPANELS; NUMPANELS=0; for(i=0;i<temp;i++) free(panels[i]); if(panels) free(panels); panels=NULL; state = mysql_query(conn, "SELECT max(panel_num) FROM panel"); if( state != 0 ) my_printf("%s\n",mysql_error(conn)); result = mysql_store_result(conn); if( ( row = mysql_fetch_row(result)) != NULL ) NUMPANELS=atoi(row[0]); // my_printf("%d\n",NUMPANELS); mysql_free_result(result); panels=(int **)malloc(NUMPANELS); for(i=0;i<NUMPANELS;i++) { panels[i]=(int *)malloc(16*sizeof(int)); for(j=0;j<16;j++) panels[i][j]=0; } state = mysql_query(conn, "SELECT panel_num,id_analog FROM panel ORDER BY panel_num,id"); if( state != 0 ) my_printf("%s\n",mysql_error(conn)); result = mysql_store_result(conn); i=0; while( ( row = mysql_fetch_row(result)) != NULL ) { if(atoi(row[0])!=curPanel) { curPanel=atoi(row[0]); i=0; } panels[curPanel-1][i]=atoi(row[1]); i++; } mysql_free_result(result); mysql_close(conn); }
void updateDigitalChannel(int id_digital) { int state; MYSQL_RES *result; MYSQL_ROW row; char query[255]; int i,j; int deviceId; MYSQL *conn=mysqlConnect(); sprintf(query,"SELECT form_label,description,label," "sinottico,printer," "time_delay_on,time_delay_off," "alarm_value,msg_on,msg_off,enabled," "device_num,ch_num,sms,msg_is_event,on_value,record_data_time " "FROM digital " "WHERE id_digital=%d",id_digital); state = mysql_query(conn,query); if( state != 0 ) my_printf("%s\n",mysql_error(conn)); result = mysql_store_result(conn); if (( row = mysql_fetch_row(result)) != NULL ) { j=id_digitalToId(id_digital);//source deviceId=systemNumToId(atoi(row[10]),NUMSYSTEMS); if(atoi(row[11])>0) i=deviceToid[1][deviceId][atoi(row[11])-1];//dest else i=-1; if(i!=-1) //destination index exists { digitalTable[i].id_digital=id_digital; if(j!=-1) //source index exists { if(systems[deviceId].sockfd!=-1) //dest device active { digitalTable[i].value_valid=digitalTable[j].value_valid; digitalTable[i].value=digitalTable[j].value; digitalTable[i].value1=digitalTable[j].value1; digitalTable[i].value2=digitalTable[j].value2; digitalTable[i].value3=digitalTable[j].value3; digitalTable[i].value4=digitalTable[j].value4; digitalTable[i].time_delay_on_cur=digitalTable[j].time_delay_on_cur; digitalTable[i].time_delay_off_cur=digitalTable[j].time_delay_off_cur; digitalTable[i].record_data_time=digitalTable[j].record_data_time; } else //dest device not active resetDigitalValues(i); if(j!=i) { digitalTable[j].id_digital=-1; digitalTable[j].enabled=0; resetDigitalValues(j); } } //source index does not exist else resetDigitalValues(i); if(row[0]) safecpy(digitalTable[i].form_label,row[0]); else strcpy(digitalTable[i].form_label,""); if(row[1]) safecpy(digitalTable[i].description,row[1]); else strcpy(digitalTable[i].description,""); if(row[2]) safecpy(digitalTable[i].label,row[2]); else strcpy(digitalTable[i].label,""); if(row[3]) safecpy(digitalTable[i].sinottico,row[3]); else strcpy(digitalTable[i].sinottico,""); digitalTable[i].printer=atoi(row[4]); digitalTable[i].time_delay_on=atoi(row[5]); digitalTable[i].time_delay_off=atoi(row[6]); digitalTable[i].alarm_value=atoi(row[7]); if(row[8]) safecpy(digitalTable[i].msg_on,row[8]); else strcpy(digitalTable[i].msg_on,""); if(row[9]) safecpy(digitalTable[i].msg_off,row[9]); else strcpy(digitalTable[i].msg_off,""); digitalTable[i].enabled=atoi(row[10]); digitalTable[i].device_num=atoi(row[11]); digitalTable[i].ch_num=atoi(row[12]); digitalTable[i].sms=atoi(row[13]); digitalTable[i].msg_is_event=atoi(row[14]); digitalTable[i].on_value=atoi(row[15]); digitalTable[i].record_data_time=(atoi(row[16])!=-1?60*atoi(row[16]):RECORDDATATIME); } else //canale di destinazione=0 { if(j!=-1) //era associato { digitalTable[j].id_digital=-1; digitalTable[j].enabled=0; resetDigitalValues(j); } } } mysql_free_result(result); mysql_close(conn); }
int loadBacnet(bool reload) { MYSQL_RES *result; MYSQL_RES *resultLines; MYSQL_ROW row; int state; int i,k; int idRow; char query[512]; char querylines[512]; MYSQL *conn=mysqlConnect(); if( conn == NULL ) { my_printf("%s\n",mysql_error(conn)); return (1); } strcpy(query,"SELECT bacnet_devices.id," "bacnet_devices.address," "bacnet_devices.port," "bacnet_devices.description," "bacnet_devices.enabled" " FROM bacnet_devices" " ORDER BY bacnet_devices.id"); state = mysql_query(conn, query); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } result = mysql_store_result(conn); strcpy(querylines,"SELECT bacnet_inputs.id," "bacnet_inputs.id_bacnet_device," "bacnet_inputs.object_type," "bacnet_inputs.object_instance," "bacnet_inputs.description," "bacnet_inputs.hi_low_msg," "bacnet_inputs.low_hi_msg," "bacnet_inputs.is_alarm," "bacnet_inputs.alarm_msg," "bacnet_inputs.record_data_time " " FROM bacnet_inputs" " ORDER BY bacnet_inputs.id"); state = mysql_query(conn, querylines); if( state != 0 ) { my_printf("%s\n",mysql_error(conn)); return(1); } resultLines = mysql_store_result(conn); if(reload) { if(shmdt(bacnetDevices)) my_perror("shmdt"); shmctl(SHMBACNETDEVICESID, IPC_RMID, &shmid_struct); if(shmdt(bacnetTable)) my_perror("shmdt"); shmctl(SHMBACNETTABLEID, IPC_RMID, &shmid_struct); } NUMBACNETDEVICES=mysql_num_rows(result); NUMBACNETLINES=mysql_num_rows(resultLines); if(NUMBACNETDEVICES&&NUMBACNETLINES) { my_printf("get_shared_memory_segment: bacnetDevices\n"); bacnetDevices=(struct bacnetDevice *)get_shared_memory_segment(NUMBACNETDEVICES * sizeof(struct bacnetDevice), &SHMBACNETDEVICESID, "/dev/zero"); if(!bacnetDevices) die("bacnetDevices - get_shared_memory_segment\n"); my_printf("get_shared_memory_segment: bacnetTable\n"); bacnetTable=(struct bacnetLine *)get_shared_memory_segment(NUMBACNETLINES * sizeof(struct bacnetLine), &SHMBACNETTABLEID, "/dev/zero"); if(!bacnetTable) die("bacnetTable - get_shared_memory_segment\n"); } else { bacnetTable=0; bacnetDevices=0; } i=0; while( ( row = mysql_fetch_row(result)) != NULL ) { bacnetDevices[i].id=atoi(row[0]); if(row[1]) strcpy(bacnetDevices[i].address,row[1]); else strcpy(bacnetDevices[i].address,""); bacnetDevices[i].port=atoi(row[2]); if(row[3]) strcpy(bacnetDevices[i].description,row[3]); else strcpy(bacnetDevices[i].description,""); bacnetDevices[i].enabled=atoi(row[4]); bacnetDevices[i].status='0'; if(!reload) { if(bacnetDevices[i].enabled) bacnetDevices[i].status='1'; else bacnetDevices[i].status='d'; } bacnetDevices[i].failures=0; bacnetDevices[i].sockfd=0; bacnetDevices[i].ok=TRUE; bacnetDevices[i].in_ch=0; i++; } mysql_free_result(result); i=0; while( ( row = mysql_fetch_row(resultLines)) != NULL ) { bacnetTable[i].id=atoi(row[0]); bacnetTable[i].id_bacnet_device=atoi(row[1]); k=id_bacnet_deviceToId(bacnetTable[i].id_bacnet_device); if(k!=-1) bacnetDevices[k].in_ch++; bacnetTable[i].object_type=atoi(row[2]); bacnetTable[i].object_instance=atoi(row[3]); if(row[4]) strcpy(bacnetTable[i].description,row[4]); else strcpy(bacnetTable[i].description,""); if(bacnetTable[i].object_type==3) { if(row[5]) strcpy(bacnetTable[i].hi_low_msg,row[5]); else strcpy(bacnetTable[i].hi_low_msg,""); if(row[6]) strcpy(bacnetTable[i].low_hi_msg,row[6]); else strcpy(bacnetTable[i].low_hi_msg,""); bacnetTable[i].is_alarm=atoi(row[7]); if(row[8]) strcpy(bacnetTable[i].alarm_msg,row[8]); else strcpy(bacnetTable[i].alarm_msg,""); bacnetTable[i].record_data_time=(atoi(row[9])!=-1?60*atoi(row[9]):RECORDDATATIME); } else { strcpy(bacnetTable[i].hi_low_msg,""); strcpy(bacnetTable[i].low_hi_msg,""); bacnetTable[i].is_alarm=FALSE; strcpy(bacnetTable[i].alarm_msg,""); } bacnetTable[i].value=0xffffffff; bacnetTable[i].value_valid=FALSE; bacnetTable[i].value_min=0; bacnetTable[i].value_max=0; bacnetTable[i].ts_min=0; bacnetTable[i].ts_max=0; bacnetTable[i].stored_time=time(NULL); i++; } mysql_free_result(resultLines); mysql_close(conn); return(0); }