| | |
| | | #include "upper_com.h" |
| | | #include "mbcrc.h" |
| | | #include "mbcrc1.h" |
| | | #include "system_general_para.h" |
| | | #include "main.h" |
| | | #include "system_mem_para.h" |
| | | #include "uart.h" |
| | | #include "upper_com_data_pro.h" |
| | | #include "mb.h" |
| | | #include "upper_com_iap_pro.h" |
| | | |
| | | UC_RECV_PARA_T __attribute__ ((aligned (4))) uc_recv_para_g = {.uc_recv_flag = RESET}; |
| | | |
| | |
| | | __IO static ErrorStatus_STM32 uc_rw_result_g = ERROR_1; //¶Áд½á¹û |
| | | |
| | | static uint16_t local_random_code_g = 0; |
| | | |
| | | |
| | | void up_comm_uart_enable(void) |
| | | { |
| | | uint32_t BaudRate; |
| | | eMBParity ParityBit; |
| | | UART_StopBitTypeDef StopBit; |
| | | switch(up_comm_para_g.baudrate_code ){ |
| | | case BAUDRATE_1200:BaudRate = 1200; break; |
| | | case BAUDRATE_2400:BaudRate = 2400; break; |
| | | case BAUDRATE_4800:BaudRate = 4800; break; |
| | | case BAUDRATE_9600:BaudRate = 9600; break; |
| | | case BAUDRATE_19200:BaudRate = 19200; break; |
| | | case BAUDRATE_56000:BaudRate = 56000; break; |
| | | case BAUDRATE_57600:BaudRate = 57600; break; |
| | | case BAUDRATE_115200:BaudRate = 115200; break; |
| | | default:BaudRate = 9600; break; |
| | | } |
| | | switch(up_comm_para_g.parity_bit ){ |
| | | case PARITY_NONE:ParityBit = MB_PAR_NONE; break; |
| | | case PARITY_ODD:ParityBit = MB_PAR_ODD; break; |
| | | case PARITY_EVEN:ParityBit = MB_PAR_EVEN; break; |
| | | default:ParityBit = MB_PAR_NONE; break; |
| | | } |
| | | |
| | | // RS485_read_data_uart_Init(BaudRate,ParityBit,OneBit); |
| | | // RS485_read_data_RX_DMA_CH3_Init(); |
| | | |
| | | //ÒòΪÐèÒª¼æÈÝmodbus£¬ËùÒÔ¸ÄΪµ÷ÓÃmodbusÖеijõʼ»¯ |
| | | eMBInit( MB_RTU, up_comm_para_g.slave_address, 0, BaudRate, ParityBit); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | void up_comm_RX_DMA_check(UC_RECV_PARA_T * uc_recv_para_p) |
| | | { |
| | | uint16_t timeout_cnt = 0,dma_recv_cnt; |
| | | uint32_t dma_mar_reg_read = DMA_CHxMAR_Read(UP_COMM_DMA_CHX); |
| | | |
| | | if(dma_mar_reg_read != (uint32)up_comm_recv_buff){ |
| | | delay_ms(2); |
| | | while(dma_mar_reg_read != DMA_CHxMAR_Read(UP_COMM_DMA_CHX)){ |
| | | dma_mar_reg_read = DMA_CHxMAR_Read(UP_COMM_DMA_CHX); |
| | | delay_ms(2); |
| | | if(timeout_cnt++ > 100) |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | return ; |
| | | |
| | | dma_recv_cnt = dma_mar_reg_read - (uint32)up_comm_recv_buff; |
| | | if( (dma_recv_cnt>0)&&(dma_recv_cnt <= UP_COMM_RECV_BUFF_LEN_MAX)) |
| | | { |
| | | if((dma_recv_cnt >= UP_COMM_RECV_BUFF_LEN_MAX) || (dma_recv_cnt >= UC_RECV_LEN_MAX) ) |
| | | return; |
| | | |
| | | uc_recv_para_p->uc_recv_length = dma_recv_cnt; |
| | | arrayA_2_arrayB(up_comm_recv_buff , uc_recv_para_p->uc_recv_buf_union.uc_recv_buf, dma_recv_cnt, LITTLE_ENDIAN) ; |
| | | uc_recv_para_p->uc_recv_flag = SET;//½ÓÊÕÍê³É |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | //ÃÜÂëÑéÖ¤ |
| | | //?ÃÜÂëÑéÖ¤ |
| | | if(uc_recv_data_union_p->uc_protocol_head_s.uc_admin==UC_SUPPER_ADMIN) |
| | | { |
| | | //²»ÐèÒªÑéÖ¤ÃÜÂë |
| | |
| | | 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); |
| | | UP_COMM_RE_SEND_EN; |
| | | UC_SEND_NORMAL((uint8_t *)uc_respond_data_p,crc_len + 2); |
| | | UP_COMM_RE_RECV_EN; |
| | | } |
| | | |
| | | |
| | |
| | | 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) |
| | | { |
| | | uc_respond_data_p->uc_protocol_head_s.data_table_id = uc_recv_data_union_p->uc_protocol_head_s.data_table_id; |
| | | 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) |
| | | 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 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 DEVICE_REAL_TIME_ID : COM_time_set_handle(uc_recv_data_union_p->uc_protocol_head_s.cmd_code,data_category_ID,data_p,uc_respond_data_p) ;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; |
| | |
| | | |
| | | void upperComPro(void) |
| | | { |
| | | //DMA½ÓÊÕÊý¾ÝÅÐ¶Ï |
| | | //½ÓÊÕÊý¾ÝÅÐ¶Ï |
| | | if(__SYS_STATUS_BYTES_GET(power_state) == SET){ |
| | | up_comm_RX_DMA_check(&uc_recv_para_g); //Í⹩µçϲŴ¦Àí½ÓÊÕ |
| | | } |
| | | |
| | | |
| | | //Ö¡¸ñʽ½âÎöÅÐ¶Ï |
| | | /*Ö¡¸ñʽ½âÎöÅжϣ¬´Ë´¦¼æÈÝmodbusÐÒ飬µÚÒ»¸ö×Ö½ÚÈç¹ûÊÇ0x68´ú±íÉÏλ»úÐÒ飬·Ç0x68ÔÙ½øÈëmodbus´¦Àí*/ |
| | | 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; |
| | |
| | | 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); |
| | | Upper_ComputerRespond(&uc_respond_data_g); |
| | | __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä |
| | | } |
| | | break; |
| | |
| | | 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); |
| | | Upper_ComputerRespond(&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: //°´Ê±¼ä |
| | | 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]); |
| | | // &uc_temp_result_buffer[0][UC_PROTOCOL_HEAD_LENGTH + UC_PROTOCOL_TABLE_ID_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);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä |
| | | case UC_CMD_IAP://? |
| | | Upper_ComputerIapHandler(&uc_recv_para_g.uc_recv_buf_union,&uc_respond_data_g); |
| | | Upper_ComputerRespond(&uc_respond_data_g); |
| | | __SYS_DELAY_SEC_TIME_SET_(UC_active_time,UC_ACTIVE_TIME);//ÉèÖü¤»îʱ¼ä//ÖØÖü¤»îʱ¼ä |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | //ÉÏλ»ú³¬Ê±´¦Àí£¬µ±³¤Ê±¼äûÓн»»¥Ê±£¬Ëæ»úÂëʧЧ£¬ÐèÒªÖØÐµÇÈë²ÅÄܼÌÐøÊ¹Óà |
| | | if(__SYS_DELAY_SEC_FLAG_GET(UC_active_time) == SET){ |
| | | __SYS_DELAY_SEC_FLAG_CLEAR_(UC_active_time); |
| | | |
| | | local_random_code_g = 0; |
| | | } |
| | | |
| | | |
| | | //½øÈëmodbus´¦Àí |
| | | if ((uc_recv_para_g.uc_recv_flag ==SET)&&(uc_recv_para_g.uc_recv_length > 7 )&&(uc_recv_para_g.uc_recv_buf_union.uc_recv_buf[0] != UC_FRAME_HEAD_CODE)) |
| | | { |
| | | if(xMBRTUReceiveCheck( uc_recv_para_g.uc_recv_buf_union.uc_recv_buf,uc_recv_para_g.uc_recv_length ) == TRUE ) |
| | | eMBPoll(); |
| | | } |
| | | |
| | | |
| | | 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); //Ó¦´ðÍêºóÇå¿Õ½ÓÊÕ |
| | | memset(uc_recv_para_g.uc_recv_buf_union.uc_recv_buf, 0, sizeof(uc_recv_para_g.uc_recv_buf_union.uc_recv_buf)); //Ó¦´ðÍêºóÇå¿Õ½ÓÊÕ |
| | | up_comm_RX_DMA_CH2_reload(); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |