From ec0d19df2a093c876bda6876f364756443e7bfa5 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期五, 16 九月 2022 10:49:58 +0800
Subject: [PATCH] V1.3

---
 源码/核心板/Src/application/dw_app.c |   91 +++++++++++++++++++++++++++++++++------------
 1 files changed, 66 insertions(+), 25 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
index 4f01d7a..10f64f3 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
@@ -317,7 +317,26 @@
 u8 anclost_times=0;
 u8 exsistbase_list[MAX_NEARBASE_NUM],report_num,get_newbase=0;
 u16 temp_sync_timer1,temp_sync_timer2;
+ double firstpath_power,firstpath_power2, rx_power,rec_firstpath_power;
+  double f1, f2, r1, r2;
+uint16_t F1,F2,F3,N,C;
+double B = 131072;
+double A = 121.74;
+double min_power;
+ dwt_rxdiag_t d1;
+double LOS(dwt_rxdiag_t *dia) {
+     F1 = dia->firstPathAmp1;
+     F2 = dia->firstPathAmp2;
+     F3 = dia->firstPathAmp3;
+     N = dia->rxPreamCount;
+     C = dia->maxGrowthCIR;
+    
+    firstpath_power=10* log10((F1*F1+F2*F2+F3*F3)/(N*N))-A;
+    rx_power=10*log10(C*B/(N*N))-A;
 
+ //   min_power =  - 10 * log10((F1 *F1 + F2 * F2 + F3 * F3) / (C *B));
+    return min_power;
+  }
  void NearPoll(void)
 {
 	static u8 mainbase_lost_count=0,flag_finalsend,flag_rxon;
@@ -438,6 +457,7 @@
 									}
 									TIM3->CNT=tmp_time;
 								}
+                                    if(g_com_map[DEV_ROLE])
 									current_slotnum=temp_sync_timer1/g_com_map[COM_INTERVAL];
 //									if(tagslotpos>max_slotpos)
 //										tagslotpos=tagslotpos%(max_slotpos+1);
@@ -465,6 +485,9 @@
 									dwt_writetxdata(28+nearbase_num*4, tx_nearfinal_msg, 0);//将发送数据写入DW1000
 									dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度
 									memcpy(&rec_tagpos_binary,&rx_buffer[NEARMSG_EMPTYSLOTPOS_INDEX],4);
+                                    dwt_readdiagnostics(&d1);
+                                    LOS(&d1);
+                                    tx_nearfinal_msg[TAGRXPOWER_IDX] = -(int)firstpath_power;
 								if(temp_dist!=0x1ffff)
 									{
 										g_Resttimer=0;
@@ -835,26 +858,7 @@
 				dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
 			}
 }
- double firstpath_power, rx_power,rec_firstpath_power;
-  double f1, f2, r1, r2;
-uint16_t F1,F2,F3,N,C;
-double B = 131072;
-double A = 121.74;
-double min_power;
- dwt_rxdiag_t d1;
-double LOS(dwt_rxdiag_t *dia) {
-     F1 = dia->firstPathAmp1;
-     F2 = dia->firstPathAmp2;
-     F3 = dia->firstPathAmp3;
-     N = dia->rxPreamCount;
-     C = dia->maxGrowthCIR;
-    
-    firstpath_power=10* log10((F1*F1+F2*F2+F3*F3)/(N*N))-A;
-    rx_power=10*log10(C*B/(N*N))-A;
 
- //   min_power =  - 10 * log10((F1 *F1 + F2 * F2 + F3 * F3) / (C *B));
-    return min_power;
-  }
 u16 smallcar_idlist[10]={0x4052,0x4032,0x4055,0x4034,0x4016,0x4010,0x4036,0x4027,0x4024,0x4047};
 extern u16 dist_threshold;
 u8 misdist_num[TAG_NUM_IN_SYS],seize_anchor,getrange_success=0;
@@ -885,7 +889,11 @@
 				memcpy(&tx_nearresp_msg[DIST_IDX], &tagdist_list[taglist_pos], 4);
 			}
 			motorstate =0;
-		if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE2])
+		
+            if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE1]||tagdist_list[taglist_pos]==0)
+			{
+				motorstate =0;
+			}else if(tagdist_list[taglist_pos]<g_com_map[ALARM_DISTANCE2])
 			{
 				if(flag_tag_distsmooth[taglist_pos])
 				{motorstate =2;
@@ -900,7 +908,7 @@
 					motorstate =0;
 				}
 			}
-      tx_nearresp_msg[GROUP_ID_IDX] = group_id;
+            tx_nearresp_msg[GROUP_ID_IDX] = group_id;
 			tx_nearresp_msg[MAINBASE_INDEX]=flag_syncbase;
 			tx_nearresp_msg[MESSAGE_TYPE_IDX]=NEAR_RESPONSE;
 			tx_nearresp_msg[MOTORSTATE_INDEX]=motorstate;//(remotesend_state<<4)|motorstate;
@@ -966,7 +974,7 @@
 					//dist_cm=33000;
 					getrange_success = 1;
 					
-					LED0_BLINK; //每成功一次通讯则闪烁一次
+					//LED0_BLINK; //每成功一次通讯则闪烁一次
 					dis_after_filter=dist_cm;
 					hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]*10;
 
@@ -987,7 +995,7 @@
 						}
 					if(abs(hex_dist-his_dist[taglist_pos])<dist_threshold||misdist_num[taglist_pos]>3)
 					{
-						
+						u8 error_flag = 0;
                         g_Resttimer=0;
                         IWDG_Feed();
 						#ifdef TDFILTER
@@ -1000,7 +1008,7 @@
 						#endif
 						misdist_num[taglist_pos]=0;
 					tagdist_list[taglist_pos] = filter_dist;	
-					his_dist[taglist_pos]=hex_dist;	
+					
                         if(hex_dist>0)
 						{
                             g_Tagdist[taglist_pos]=hex_dist/10;	
@@ -1022,7 +1030,40 @@
 					usart_send[16] = rx_power;
 					checksum = Checksum_u16(&usart_send[2],17);
 					memcpy(&usart_send[19],&checksum,2);
-					UART_PushFrame(usart_send,21);
+                    firstpath_power2 = rx_buffer[TAGRXPOWER_IDX];
+                            firstpath_power = -(int)firstpath_power;
+                    if(firstpath_power2>firstpath_power)
+                    {
+                        if(firstpath_power2>93)
+                        {
+                            printf("错误1:被测模块接收损坏\r\n");
+                            error_flag = 1;
+                        }
+                        if(firstpath_power<84)
+                        {
+                            printf("错误2:功率过大\r\n");
+                            error_flag = 1;
+                        }
+                    }else{
+                        if(firstpath_power>93)
+                        {
+                            printf("错误3:被测模块发射损坏\r\n");
+                            error_flag = 1;
+                        }
+                        if(firstpath_power2<84)
+                        {
+                            printf("错误2:功率过大\r\n");
+                            error_flag = 1;
+                        }
+                    }
+                    if(error_flag == 0&&his_dist[taglist_pos]!=hex_dist)
+                    {
+                        LED0_BLINK; 
+                        printf("通过\r\n");
+                    }
+                    his_dist[taglist_pos]=hex_dist;	
+                    printf("包序:%d。距离:%d cm。接收强度: %d。发射强度:%d强度合格范围(大于83小于94)\r\n",frame_seq_nb2,g_Tagdist[taglist_pos],(int)firstpath_power,(int)firstpath_power2);
+					//UART_PushFrame(usart_send,21);
 				#else		
 					memcpy(&usart_send_anc[4+6*anc_report_num],&tag_id_recv,2);
 					memcpy(&usart_send_anc[6+6*anc_report_num],&tagdist_list[taglist_pos],4);

--
Gitblit v1.9.3