#include "upper_com.h" #include "mbcrc.h" #include "system_general_para.h" #include "main.h" #include "system_mem_para.h" #include "uart.h" #include "upper_com_data_pro.h" UC_RECV_PARA_T __attribute__ ((aligned (4))) uc_recv_para_g = {.uc_recv_flag = RESET}; UC_RECV_DATA_UNION_T uc_respond_data_g; // UC_PROTOCOL_HEAD_T uc_protocol_head_g; __IO static UC_LOGIN_STATUS uc_login_state_g = UC_UNKNOWN; //µÇ¼״̬ __IO uint8_t uc_return_flag_g = 0; //½á¹û±ê־λ __IO static ErrorStatus_STM32 uc_rw_result_g = ERROR_1; //¶Áд½á¹û static uint16_t local_random_code_g = 0; /*µÇ¼½ÓÊÕ´¦Àí*/ UC_LOGIN_STATUS Upper_ComputerLoginRecvHandler(UC_RECV_DATA_UNION_T *uc_recv_data_union_p,UC_RECV_DATA_UNION_T *uc_respond_data_p) { UC_LOGIN_STATUS return_status = UC_OK; if ((uc_recv_data_union_p->uc_protocol_head_s.plant_number[0] == equipment_basic_inf_g.manufactuer_code[0])&&(uc_recv_data_union_p->uc_protocol_head_s.plant_number[1]==equipment_basic_inf_g.manufactuer_code[1])) //ÓÐЧ³§¼Ò´úÂë { } else { return_status = UC_PLANT_NUM_ERR; } //?ÃÜÂëÑéÖ¤ if(uc_recv_data_union_p->uc_protocol_head_s.uc_admin==UC_SUPPER_ADMIN) { //²»ÐèÒªÑéÖ¤ÃÜÂë }else if(uc_recv_data_union_p->uc_protocol_head_s.uc_admin==UC_MANAGE_USER) { // }else if(uc_recv_data_union_p->uc_protocol_head_s.uc_admin==UC_ADVANCED_USER) { }else if(uc_recv_data_union_p->uc_protocol_head_s.uc_admin==UC_GENERAL_USER) { }else { return_status = UC_UNKNOWN; } if(return_status == UC_OK) { __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä } uc_respond_data_p->uc_protocol_head_s.random_number = local_random_code_g = UC_RANDOM_CREATED; uc_respond_data_p->uc_protocol_head_s.data_field_length = 1; uc_respond_data_p->uc_recv_buf[ uc_respond_data_p->uc_protocol_head_s.data_field_length -1+UC_PROTOCOL_HEAD_LENGTH] = return_status; return return_status; } //Ó¦´ð·¢ËÍ void Upper_ComputerRespond(UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint16_t send_crc_check = 0,crc_len =uc_respond_data_p->uc_protocol_head_s.data_field_length + UC_PROTOCOL_HEAD_LENGTH; uc_respond_data_p->uc_protocol_head_s.data_field_length = BSWAP_16(uc_respond_data_p->uc_protocol_head_s.data_field_length); send_crc_check = usMBCRC16(0xFFFF,(uint8_t *)uc_respond_data_p, crc_len); uc_respond_data_p->uc_recv_buf[crc_len] = send_crc_check >> 8; //¸ßλ uc_respond_data_p->uc_recv_buf[crc_len + 1] = send_crc_check &0xff; UARTx_SendData_Normal(UART0,(uint8_t *)uc_respond_data_p,crc_len + 2); } //µÇÈëÖ¡Ó¦´ð void Upper_ComputerLoginRespond(UC_RECV_DATA_UNION_T *uc_respond_data_p) { Upper_ComputerRespond(uc_respond_data_p); } /*Êý¾Ý¶Áд֡´¦Àí*/ void Upper_ComputerReadWriteHandler(UC_RECV_DATA_UNION_T *uc_recv_data_union_p,UC_RECV_DATA_UNION_T *uc_respond_data_p) { uint16_t data_category_ID; uint8_t *data_p; if (uc_login_state_g == UC_OK && local_random_code_g == uc_recv_data_union_p->uc_protocol_head_s.random_number) { data_category_ID= BSWAP_16(uc_recv_data_union_p->uc_protocol_head_s.data_table_id); data_p = uc_recv_data_union_p->uc_recv_buf + UC_PROTOCOL_HEAD_LENGTH +sizeof (uc_recv_data_union_p->uc_protocol_head_s.data_table_id); switch(data_category_ID)//?ÐèÒªÍêÉÆ { case EQUIPMENT_BASIC_INF_ID : COM_equipment_basic_inf_handle(uc_recv_data_union_p->uc_protocol_head_s.cmd_code,data_category_ID,data_p,uc_respond_data_p) ;break; // case MAIN_EQUIPM_HARDWARE_SOFTWARE_INF_ID : COM_main_equipment_hardware_software_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case LCD_EQUIPM_HARDWARE_SOFTWARE_INF_ID : COM_lcd_equipment_hardware_software_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case WIRELESS_EQUIPM_HARDWARE_SOFTWARE_INF_ID : COM_wireless_equipment_hardware_software_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case PRE_EQUIPM_HARDWARE_SOFTWARE_INF_ID : COM_pre_equipment_hardware_software_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case TEM_EQUIPM_HARDWARE_SOFTWARE_INF_ID : COM_tem_equipment_hardware_software_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case SONIC_SENSOR_EQUIPM_HARDWARE_SOFTWARE_INF_ID : COM_sonic_sensor_equipment_hardware_software_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case REALTIME_DATA_ID : COM_realtime_data_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case STATISTICAL_DATA_ID : COM_statistical_data_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case DEVICE_SIZE_INF_ID : COM_device_size_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case ULTRASONIC_SENSOR_TRIGE_LEVEL_ID : COM_ultrasonic_sensor_trige_level_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case ULTRASONIC_SENSOR_TRIGE_LEVEL_REAL_ID : COM_ultrasonic_sensor_real_trige_level_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case POSITIVE_FLOW_POINT_CORRECT_ID : COM_positive_flow_correct_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case POSITIVE_REAL_FLOW_POINT_CORRECT_ID : COM_positive_real_flow_correct_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case POSITIVE_FLOW_POINT_SECOND_ID : COM_positive_flow_correct_second_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case POSITIVE_REAL_FLOW_POINT_SECOND_ID : COM_positive_real_flow_correct_second_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case POSITIVE_FLOW_POINT_OTHER_ID : COM_positive_flow_correct_other_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case REVERSE_FLOW_POINT_CORRECT_ID : COM_reverse_flow_correct_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case REVERSE_REAL_FLOW_POINT_CORRECT_ID : COM_reverse_real_flow_correct_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case REVERSE_FLOW_POINT_SECOND_ID : COM_reverse_flow_correct_second_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case REVERSE_REAL_FLOW_POINT_SECOND_ID : COM_reverse_real_flow_correct_second_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case REVERSE_FLOW_POINT_OTHER_ID : COM_reverse_flow_correct_other_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case ASSIST_ALGORITHM_PARA_CONFIG_ID : COM_assist_algorithm_para_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case AA_REAL_CH_DEVIATION_ID : COM_AA_real_ch_deviation_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case AA_TIME_DIFF_OFFSET_ID : COM_AA_time_diff_offset_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case FLOW_LIMIT_ID : COM_flow_limit_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case PRESSURE_PARA_ID : COM_pressure_para_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case TEMPERATURE_PARA_ID : COM_temperature_para_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case FLOW_TEM_PRE_ID : COM_flow_pre_tem_para_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case LOW_PULSE_PARA_ID : COM_low_pluse_para_out_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case ELECTRIC_CURRENT_LOOP_ID : COM_electric_current_loop_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case DEVICE_MODBUS_BTL_ID : COM_device_modbus_btl_set_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case DEVICE_PASSWORD_ID : COM_device_password_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case MEASURE_FREEZ_PARA_ID : COM_measure_freez_para_inf_handle(WriteOrRead,com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case NETWORK_COM_PARA_ID : COM_network_com_para_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case NETWORK_COM_APN_INFO_ID : COM_network_com_apn_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case BATTERY_PARA_ID : COM_battery_para_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case ULTRASONIC_SENSOR_ABNORMAL_PARA_ID : COM_ultrasonic_sensor_abnormal_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case HIGH_PLUSE_PARA_ID : COM_high_pluse_para_out_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case SYNTHESIZE_FUN_1_ID : COM_synthesize_fun_1_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case SYSTEM_STATUS_WORD_ID : COM_system_status_word_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case SYSTEM_FUNCTION_CTRL_WORD_ID : COM_system_function_ctrl_word_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case SYSTEM_ALARM_CTRL_WORD_ID : COM_system_alarm_ctrl_word_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case SYSTEM_ALARM_REPORT_CTRL_WORD_ID : COM_system_alarm_report_ctrl_word_inf_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case DEVICE_REAL_TIME_ID : COM_time_set_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case DEBUG_STATE_SET_ID : COM_debug_state_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case DEBUG_PARA_SET_ID : COM_debug_para_set_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case ORIGINAL_WAVEFORM_DATA_READ_ID : COM_original_para_set_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case USER_PASSWORD_MODIFY_ID : COM_user_password_set_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; // case PARA_INIT_ID : COM_para_init_handle(WriteOrRead, com_frame_receive_inf_in.data_category_ID,(DataPtr +2)) ;break; default : break; } } } void upperComPro(void) { //?DMA½ÓÊÕÊý¾ÝÅÐ¶Ï //Ö¡¸ñʽ½âÎöÅÐ¶Ï if ((uc_recv_para_g.uc_recv_flag ==SET)&&(uc_recv_para_g.uc_recv_length > UC_PROTOCOL_HEAD_LENGTH )&&(uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.frame_start_code == UC_FRAME_HEAD_CODE)) { uint16_t ex_crc_len = uc_recv_para_g.uc_recv_length - 2; uint16_t recv_crc_check = uc_recv_para_g.uc_recv_buf_union.uc_recv_buf[ex_crc_len] << 8 | uc_recv_para_g.uc_recv_buf_union.uc_recv_buf[ex_crc_len + 1]; //½ÓÊÕÊý¾ÝcrcÑéÖ¤£¨ÑéÖ¤Êý¾ÝÊÇ·ñÍêÕû£© if (recv_crc_check == usMBCRC16(0xFFFF,uc_recv_para_g.uc_recv_buf_union.uc_recv_buf, ex_crc_len)) { /*Ô¤ÏȰѷµ»ØÊý¾Ý²¿·ÖÖ¡Í·ÄÚÈݸ³Öµ*/ arrayA_2_arrayB(uc_recv_para_g.uc_recv_buf_union.uc_recv_buf , uc_respond_data_g.uc_recv_buf, UC_PROTOCOL_HEAD_LENGTH, LITTLE_ENDIAN) ; uc_respond_data_g.uc_protocol_head_s.password_protocol_ver[0] = UC_PROTOCOL_VER>>8; uc_respond_data_g.uc_protocol_head_s.password_protocol_ver[1] = UC_PROTOCOL_VER&0xff; /*Õë¶ÔÖ¡Í·µÄ´óС¶Ëת»»*/ // uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.plant_number = BSWAP_16(uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.plant_number); // uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.password_protocol_ver = BSWAP_16(uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.password_protocol_ver); // uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.random_number = BSWAP_16(uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.random_number); uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length = BSWAP_16(uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.data_field_length); switch (uc_recv_para_g.uc_recv_buf_union.uc_recv_buf[9]) //¿ØÖÆÂë { case UC_CMD_LOGIN: uc_login_state_g = Upper_ComputerLoginRecvHandler(&uc_recv_para_g.uc_recv_buf_union,&uc_respond_data_g); Upper_ComputerLoginRespond(&uc_respond_data_g); break; case UC_CMD_EXIT: local_random_code_g = 0; uc_login_state_g = UC_UNKNOWN; __SYS_DELAY_SEC_TIME_SET_(UC_active_time,0);//ÇåÁ㼤»îʱ¼ä break; case UC_CMD_WRITE: //µÇ¼³É¹¦ÇÒÔÚ¼¤»î״̬ÇÒËæ»úÂëÏàͬ if (uc_login_state_g == UC_OK && local_random_code_g == uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.random_number) { Upper_ComputerReadWriteHandler(&uc_recv_para_g.uc_recv_buf_union,&uc_respond_data_g); Upper_ComputerLoginRespond(&uc_respond_data_g); __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä } break; case UC_CMD_READ: if (uc_login_state_g == UC_OK && local_random_code_g == uc_recv_para_g.uc_recv_buf_union.uc_protocol_head_s.random_number) { Upper_ComputerReadWriteHandler(&uc_recv_para_g.uc_recv_buf_union,&uc_respond_data_g); Upper_ComputerLoginRespond(&uc_respond_data_g); __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä } break; case UC_CMD_GET_LOG_RECENT: //°´×î½ü break; case UC_CMD_GET_LOG_TIME: //?°´Ê±¼ä // if (uc_login_state_g == UC_OK && local_random_code_g == uc_rec_para_p->uc_recv_buf_union.uc_protocol_head_s.random_number) // { // uc_rw_result_g = Upper_ComputerLogProcess(Upper_ComputerPermissionsGet(uc_rec_para_p->uc_recv_buf_union.uc_recv_buf[2]), // &uc_rec_para_p->uc_recv_buf_union.uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH], // &uc_temp_result_buffer[0][UC_PROTOCOL_HEAD_LENGTH + UC_DATA_TABLE_BYTES_LENGTH + UC_LOG_NUM_AND_FLAG_LENGTH]); // __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä // } break; case UC_CMD_IAP://? // uc_rw_result_g = Upper_ComputerIapProcess(uc_table_id, &uc_rec_para_p->uc_recv_buf_union.uc_recv_buf[UC_PROTOCOL_HEAD_LENGTH + UC_DATA_TABLE_BYTES_LENGTH]); // __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä break; default: break; } } } if (uc_recv_para_g.uc_recv_flag ==SET) { uc_recv_para_g.uc_recv_flag = RESET; //ÖØÆô´®¿ÚDMA½ÓÊÕ memset(uc_recv_para_g.uc_recv_buf_union.uc_recv_buf, 0, uc_recv_para_g.uc_recv_length); //Ó¦´ðÍêºóÇå¿Õ½ÓÊÕ } }