int main(void) { int lines = 0; struct Line* head = 0; struct Line* tail = 0; while(1) { usleep(4000000) ; FILE* log; if( ( log = fopen( "/home/peter/log/log_cpu_temperature.txt", "w")) == 0) { exit(-1); } int err = 0; if( ( err = get_cpu_temperature( AMD_FX_4100_tempInfo)) < 0) { fprintf( log, "error get_cpu_temperature:%d\n", err); exit( -1); } if( lines == MAX_LINE_COUNT) { struct Line* new_head = head->pred; free( head); head = new_head; head->next = 0; --lines; } struct Line* new_line = (Line*)malloc( sizeof(Line)); struct tm* gmt; time_t now = time(0); gmt = gmtime( &now); char buff[50]; strftime ( new_line->line, sizeof( new_line->line), "%Y-%m-%d %H:%M:%S, ", gmt); sprintf( buff, "temp1: %.4lf, temp2: %.4lf, temp3: %.4lf", AMD_FX_4100_tempInfo[0], AMD_FX_4100_tempInfo[1], AMD_FX_4100_tempInfo[2]); strcat( new_line->line, buff); new_line->next = tail; if( tail) tail->pred = new_line; new_line->pred = 0; tail = new_line; ++lines; if( lines == 1) head = new_line; for( struct Line* pl = head; ; pl = pl->pred) { if( fprintf( log, "%s\n", pl->line) < 0) exit(-1); if( pl->pred == 0) break; } fclose( log); } return 0; }
void flying_status_return() { uint8 *fa = (uint8*)(get_flying_attitude()); uint8 buf[145]; uint16 crc_value; buf[0] = CTRL_FRAME_START1; buf[1] = CTRL_FRAME_START2; buf[2] = get_aircraft_no()&0xFF; buf[3] = get_aircraft_no()>>8; *(uint32*)(buf+4) = 0x91; buf[8] = 1; buf[9] = 1; buf[10] = CTRL_FRAME_TYPE_FLY_STATUS; // compiler add 4bytes between float data and double data for flying_attitude struct // so we have to copy separately memcpy(buf+11,fa,60); memcpy(buf+71,fa+64,36); *(uint32*)(buf+107) = get_sonar_data(); buf[111] = 0; buf[112] = 0; // next waypoint memcpy(buf+113,(uint8 *)(&ppwm),20);//pwm output buf[133] = get_flying_status()&0xFF; buf[134] = get_flying_status()>>8; buf[135] = 0; // gps status buf[136] = 0; // imu status buf[137] = 0; // AP status :cpu1 or cpu2 buf[138] = get_input_voltage()&0xFF; buf[139] = 0; buf[140] = get_cpu_temperature()/1000; buf[141] = 0; crc_value=crc_checksum16(buf, 142); buf[142] = crc_value&0xFF; buf[143] = crc_value>>8; buf[144] = CTRL_FRAME_END; control_cmd_send(buf, 145); }
int main(int argc, char * const argv[]){ /* Parse the command line arguments */ MFC.fork = TRUE; parse_options(argc, argv); signal(SIGHUP,Signal_Handler); /* hangup signal */ signal(SIGTERM,Signal_Handler); /* software termination signal from kill */ struct timespec timx,tim1; openlog("mfc-daemon", LOG_PID, LOG_DAEMON); MFC.syslog = TRUE; /* check machine and pidfile*/ MFC.total_cpus = check_cpu(); MFC.total_fans = check_fan(); check_pidfile(); write_pidfile(); MFC.pidfile = TRUE; if (MFC.fork) { start_daemon(); } int fan; for (fan = 1; fan <= MFC.total_fans; ++fan) { write_fan_manual(fan, 1); } tim1.tv_sec = TV_SEC; tim1.tv_nsec = TV_NSEC; //init int wr_manual=0; int change_number=0; int old_fan_speed=-1; INFO("Start"); int temp = get_cpu_temperature(); int old_temp_change = 0; int fan_speed=GET_FAN_SPEED(temp); fan_speed=set_min_max_fan_speed(fan_speed); for (fan = 1; fan <= MFC.total_fans; ++fan) { write_fan_speed(fan, fan_speed); } while (1){ wr_manual++; if (wr_manual==9){ for (fan = 1; fan <= MFC.total_fans; ++fan) { write_fan_manual(fan, 1); } wr_manual=0; } temp = get_cpu_temperature(); int diff = abs(temp - old_temp_change); if (diff >= 2){ // temp = average of both cpu's fan_speed=GET_FAN_SPEED(temp); fan_speed=set_min_max_fan_speed(fan_speed); if (fan_speed!=old_fan_speed){ for (fan = 1; fan <= MFC.total_fans; ++fan) { write_fan_speed(fan, fan_speed); } change_number=log_fan_speed(fan_speed,change_number,temp); old_fan_speed=fan_speed; } old_temp_change = temp; } if (nanosleep(&tim1,&timx) == -1){ QUIT_DAEMON("Error nanosleep"); } } }
int main(int argc, char** argv) { const uint8_t MAGIC_BYTE = 0x11; const uint8_t VERSION = 0x02; struct sockaddr_in saddr; int status; char hostname[255]; parse_options(argc, argv); if(gethostname(hostname, sizeof(hostname))) { perror("Infocast: gethostname"); exit(1); } int hlen = strlen(hostname) + 1; int len = 512; char* message = (char*)malloc(len); while(1) { unsigned char lanMacAddress[6]; unsigned char wifiMacAddress[6]; uint32_t ipLan, ipWLan; int8_t bat = (int8_t)(get_battery_info() * 100); uint8_t wifiStrength = get_wifi_quality(); uint8_t cpuTemp = get_cpu_temperature(); get_ip_address("eth0", ipLan, lanMacAddress); get_ip_address("wlan0", ipWLan, wifiMacAddress); char* start = message; *start = MAGIC_BYTE; start++; *start = VERSION; start++; WRITE(&ipLan, sizeof(ipLan)); WRITE(&ipWLan, sizeof(ipWLan)); WRITE(&bat, sizeof(bat)); WRITE(&cpuTemp, sizeof(cpuTemp)); WRITE(&wifiStrength, sizeof(wifiStrength)); WRITE(lanMacAddress, sizeof(lanMacAddress)); WRITE(wifiMacAddress, sizeof(wifiMacAddress)); memcpy(start, hostname, hlen); start += hlen; /* * We have to do this every iteration because we want see the Nao also * when a new interface becomes ready. For example eth0 gets an IP address * This should be no problem. Creating a socket is cheap. */ std::list<int> sockList = open_send_multicast_socket(saddr, multicast_ip.c_str(), multicast_port); for(std::list<int>::iterator it = sockList.begin(); it != sockList.end(); ++it) { int sock = *it; status = sendto(sock, message, start - message, 0, (struct sockaddr*)&saddr,sizeof(saddr)); close(sock); if(status < 0) perror("Infocast: sendto"); } sleep(5); } }
void flying_status_return(int transmit_data) { flying_attitude_s *fa = get_flying_attitude(); uint8 buf[256]; uint16 crc_value; int pressure; buf[0] = CTRL_FRAME_START1; buf[1] = CTRL_FRAME_START2; buf[2] = get_aircraft_no()&0xFF; buf[3] = get_aircraft_no()>>8; *(uint16*)(buf+4) = 0x91; buf[6] = 1; buf[7] = 0; buf[8] = 1; buf[9] = 0; buf[10] = CTRL_FRAME_TYPE_FLY_STATUS; *((float *)(buf+11))=fa->roll; *((float *)(buf+15))=fa->pitch; *((float *)(buf+19))=fa->yaw; *((float *)(buf+23))=fa->gx; *((float *)(buf+27))=fa->gy; *((float *)(buf+31))=fa->gz; *((float *)(buf+35)) =fa->ax; *((float *)(buf+39))=fa->ay; *((float *)(buf+43))=fa->az; *((uint32 *)(buf+47))=fa->g_time; *((int *)(buf+51))=fa->vn; *((int *)(buf+55))=fa->ve; *((int *)(buf+59))=fa->vd; *(( int *)(buf+63))=fa->heading; *(( int *)(buf+67))=fa->b_h; *((double *)(buf+71))=fa->lat; *((double *)(buf+79))=fa->Long; *((double *)(buf+87))=fa->g_h; *((float *)(buf+95))=fa->vx; *((float *)(buf+99))=fa->vy; *((float *)(buf+103))=fa->vz; sonar_data=get_sonar_data(); *(uint32*)(buf+107) = sonar_data; buf[111] = gepoint.id & 0xFF ; buf[112] = gepoint.id >> 8 ;// next waypoint read_rc_data(rc_data); if(get_flying_status() == AIRCRAFT_MANUAL_MODE){ memcpy(buf+113,rc_data,14); }else memcpy(buf+113,(uint8 *)(&ppwm),20);//pwm output *(uint16*)(buf+131) = ppwm.c[9]; buf[133] = get_flying_status()&0xFF; buf[134] = get_flying_status()>>8; buf[135] = 0; // gps status buf[136] = 0; // imu status buf[137] = 0; // AP status :cpu1 or cpu2 working_status.input_voltage = get_input_voltage(); working_status.engine_voltage = get_monitor_voltage(); working_status.cpu_temprature = get_cpu_temperature(); buf[138] = working_status.input_voltage&0xFF;//AP power buf[139] = working_status.engine_voltage&0xFF;//UAV power buf[140] = working_status.cpu_temprature/1000; buf[141] = 0; if(transmit_data){ crc_value=crc_checksum16(buf, 142); buf[142] = crc_value&0xFF; buf[143] = crc_value>>8; buf[144] = CTRL_FRAME_END; control_cmd_send(buf, 145); } *(uint16*)(buf+4) = 0xAF; memcpy(buf+142,rc_data,14); pressure = get_altimeter(); *(uint16*)(buf+154)= pressure>>16; *(uint16*)(buf+156)= pressure&0xffff; *(uint16*)(buf+158)=time_estimation.data_return; *(uint16*)(buf+160)=time_estimation.algorithm; crc_value=crc_checksum16(buf, 172); buf[172] = crc_value&0xFF; buf[173] = crc_value>>8; buf[174] = CTRL_FRAME_END; fwrite(buf,175,1,fp_fly_status); }