forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-05-14 ec1ec68ba7d175f39f5d4e066663cf29fa7c262a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#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; 
    
    UC_SEND_NORMAL((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); //Ó¦´ðÍêºóÇå¿Õ½ÓÊÕ
        
    }
    
}