static void Process_RPG_message (char *buf, int len) { RDA_RPG_message_header_t *rda_rpg_msg_header; /* The ICD msg hdr */ rda_rpg_msg_header = (RDA_RPG_message_header_t *)buf; switch (rda_rpg_msg_header->type) { case LOOPBACK_TEST_RPG_RDA: Send_data (buf, len); /* send back the loopback */ Send_RDA_loopback_msg (); break; default: /* other imcoming messages are discarded */ break; } }
/* ******************************************************************************** ** 函数名称 : main(void) ** 函数功能 : 主函数 ** 输 入 : 无 ** 输 出 : 无 ** 返 回 : 无 ******************************************************************************** */ int main(void) { RCC_Configuration(); //配置RCC GPIO_Configuration(); //配置GPIO USART1_Configuration(); //配置串口1 I2C_GPIO_Config(); //配置IIC使用端口 Delayms(10); //延时 Init_MPU3050(); //初始化MPU3050 while(1) { READ_MPU3050(); //读取MPU3050数据 DATA_printf(TX_DATA,T_X);//转换X轴数据到数组 Send_data('X'); //发送X轴数 DATA_printf(TX_DATA,T_Y);//转换Y轴数据到数组 Send_data('Y'); //发送Y轴数 DATA_printf(TX_DATA,T_Z);//转换Z轴数据到数组 Send_data('Z'); //发送Z轴数 DATA_printf(TX_DATA,T_T);//转换温度数据到数组 Send_data('T'); //发送温度数据 USART1_SendData(0X0D); //换行 USART1_SendData(0X0A); //回车 Delayms(5); //延时 } }
static void Send_playback_data () { static int cnt = 0; static char buf[NEX_MAX_PACKET_SIZE]; int msg_len; if (Data_write_status == DWS_CONGESTED) { LB_seek (Data_lb, -1, LB_CURRENT, NULL); Data_write_status = DWS_DONE; } else if (Data_write_status == DWS_WAITING) return; while (1) { msg_len = LB_read (Data_lb, buf, NEX_MAX_PACKET_SIZE, LB_NEXT); if (msg_len == LB_TO_COME) { Data_write_status = DWS_NO_DATA; return; } if (msg_len < 0) { if (msg_len == LB_EXPIRED) { LE_send_msg (GL_ERROR, "Failed in catching up with the playback"); continue; } else { LE_send_msg (GL_ERROR, "LB_read failed (%d) - wb_simulator terminates", msg_len); exit (1); } } else if (msg_len > 0) { if (Connect_state != RPG_CONNECTED) continue; if (Send_data (buf, msg_len) == 0) { cnt++; if (cnt == 1 || (cnt % 10) == 0) LE_send_msg (LE_VL2, "%d playback messages sent to RPG", cnt); Data_write_status = DWS_WAITING; return; } break; } } Data_write_status = DWS_NO_DATA; return; }
void Get_data(void) { int len; int i; (void)time(&the_time); fp = fopen("sensordata.txt","a+"); if(fp == NULL) { fprintf(stderr,"Open datafile error\n"); exit(1); } fputs(ctime(&the_time),fp); fputs("Room1 Light:\n",fp); len = sizeof(Sensor_light_Room1)/sizeof(Sensor_light_Room1[0]); Calc_data(Sensor_light_Room1,len); Write_into_file(room_info,len); for(i = 0; i < len; i++) { avge += room_info[i]; } avge /= len; fputs("Room1:\n",fp); len = sizeof(Sensor_TrainRoom1)/sizeof(Sensor_TrainRoom1[0]); Calc_data(Sensor_TrainRoom1,len); Write_into_file(room_info,len); makeup_data(1,len); //send the first two single sensor room //# single_sensor(room_info[0],4); //room_id is 4 //#Send_data(2); //#sleep(3); //single_sensor(room_info[1],5); //room_id is 5 //Send_data(2); //sleep(2); Send_data(1); //here used to send room1 data printf_info(1); sleep(3); fputs("Room2:\n",fp); len = sizeof(Sensor_TrainRoom2)/sizeof(Sensor_TrainRoom2[0]); Calc_data(Sensor_TrainRoom2,len); Write_into_file(room_info,len); // makeup_data(2,len); //Send_data(1); //room 2 data //printf_info(2); //print log info //sleep(3); fputs("Room3:\n",fp); len = sizeof(Sensor_TrainRoom3)/sizeof(Sensor_TrainRoom3[0]); Calc_data(Sensor_TrainRoom3,len); Write_into_file(room_info,len); //makeup_data(3,len); //Send_data(1); //room 3 data //printf_info(3); //sleep(3); fputs("\n",fp); fclose(fp); }
int main(int argc, char **argv) { /* Gaussian Elimination */ int my_rank; /* My process rank */ int p; /* The number of processes */ int norm; /* The number of rows */ /* calculated */ int row; /* Row number */ int col; /* Column number */ int source; /* Process sending integral */ int dest = 0; /* All messages go to 0 */ int tag = 0; MPI_Status status; void Get_data(int my_rank, int p); void Compute(int norm, int my_rank, int p); MPI_Init(&argc, &argv); /* Get my process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Find out how many processes are being used */ MPI_Comm_size(MPI_COMM_WORLD, &p); /* Timing variables */ double starttime = 0.0; double endtime = 0.0; printf("Computing Parallel via MPI.\n"); if (my_rank == 0) { /* Start Clock */ printf("\nStarting clock.\n"); starttime = MPI_Wtime(); /* Broadcast the value of N to all nodes */ MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD); /* Initialize A and B */ initialize_inputs(); /* Print input matrices */ print_inputs(); } else /* Receive the broadcast N value */ MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD); /* Updating needed data in correspoding row of A and B for each process */ Send_data(my_rank, p); /* Gauss elimination */ for (norm = 0; norm < N - 1; norm++) { int i; for (i = norm; i < N; i++) { MPI_Bcast(A[i], N, MPI_FLOAT, i%p, MPI_COMM_WORLD); MPI_Bcast(&B[i], 1, MPI_FLOAT, i%p, MPI_COMM_WORLD); } Compute(norm, my_rank, p); MPI_Barrier(MPI_COMM_WORLD); } MPI_Bcast(A[N-1], N, MPI_FLOAT, (N-1)%p, MPI_COMM_WORLD); MPI_Bcast(&B[N-1], 1, MPI_FLOAT, (N-1)%p, MPI_COMM_WORLD); if (my_rank == 0) { int row, col; /* Back substitution */ for (row = N - 1; row >= 0; row--) { X[row] = B[row]; for (col = N-1; col > row; col--) { X[row] -= A[row][col] * X[col]; } X[row] /= A[row][row]; } /* Stop Clock */ endtime = MPI_Wtime(); /* Display timing results */ printf("That tooks %f seconds.\n", endtime-starttime); /* Display output */ print_X(); } /* Shut down MPI */ MPI_Finalize(); exit(0); }
// Sending out data regulary ~ 0,25 sec period void TIM7_IRQHandler(void) { if (TIM_GetITStatus(TIM7, TIM_IT_Update) == SET) { TIM_ClearITPendingBit(TIM7, TIM_IT_Update); uint8_t received_data; // Sending out data if client started the system if(WORK == 1) { /*Temperature message: * 1 byte - START * 1 byte - HEADER * 4 byte - Length - Client needs this length * 2 byte - Data * TOTAL: 8 byte */ uint8_t message_temperature[temperature_message_length]; //Sending temperature 1 data temperature = 0; temperature = get_temperature(1); construct_temperature_message(message_temperature,temperature,ID_temp1); Send_data(message_temperature,temperature_message_length); //Sending temperature 2 data temperature = 0; temperature = get_temperature(2); //temperature = 0; construct_temperature_message(message_temperature,temperature,ID_temp2); Send_data(message_temperature,temperature_message_length); //Sending temperature 3 data temperature = 0; temperature = get_temperature(3); construct_temperature_message(message_temperature,temperature,ID_temp3); Send_data(message_temperature,temperature_message_length); //Sending temperature 4 data temperature = 0; temperature = get_temperature(4); //temperature = 0; construct_temperature_message(message_temperature,temperature,ID_temp4); Send_data(message_temperature,temperature_message_length); //free(message); /*Fan frequency message: * 1 byte - START * 1 byte - HEADER * 4 byte - Length - Client needs this length * 1 byte - Data * TOTAL: 7 byte */ uint8_t message_frequency[fan_frequency_message_length]; // Sending frequency of Fan 1 if(Fan_1_frequency == Fan_1_frequency_previous && Fan_1_frequency < 15) { Fan_1_frequency = 0; Fan_1_frequency_previous = 0; } construct_fan_frequency_message(message_frequency,Fan_1_frequency,ID_freq1); Send_data(message_frequency,fan_frequency_message_length); // Sending frequency of Fan 3 if(Fan_3_frequency == Fan_3_frequency_previous && Fan_3_frequency < 15) { Fan_3_frequency = 0; Fan_3_frequency_previous = 0; } construct_fan_frequency_message(message_frequency,Fan_3_frequency,ID_freq3); Send_data(message_frequency,fan_frequency_message_length); /*Fan PWM message: * 1 byte - START * 1 byte - HEADER * 4 byte - Length - Client needs this length * 1 byte - Data * TOTAL: 7 byte */ uint8_t message_PWM[fan_PWM_message_length]; // Sending PWM of fan 1 construct_fan_PWM_message(message_PWM,Fan_1_PWM,ID_fan_1_PWM); Send_data(message_PWM,fan_PWM_message_length); // Sending PWM of fan 3 construct_fan_PWM_message(message_PWM,Fan_3_PWM,ID_fan_3_PWM); Send_data(message_PWM,fan_PWM_message_length); } else { //If sending out data is not allowed, send halted message continuously uint8_t message_Halted[halted_message_length]; construct_halt_message(message_Halted); Send_data(message_Halted,halted_message_length); } // Processing received data while(Get_data(&received_data) == 1){ if(received_data == 0xff){ start_arrived = 1; header = 0; } else if(start_arrived){ header = received_data; start_arrived = 0; header_arrived = 1; } else if(header_arrived){ length += ((uint32_t)received_data) << (length_byte_count * 8); length_byte_count++; if(length_byte_count == 4){ header_arrived = 0; } } else if(length_byte_count == 4){ data[data_byte_count] = received_data; data_byte_count++; if(data_byte_count == length){ length_byte_count = 0; length = 0; data_byte_count = 0; Parse_message(header,data); } } } } }