Sfoglia il codice sorgente

两个板子调试流控帧有问题

yykai95 3 anni fa
parent
commit
4682bce812

+ 29 - 29
BleCanBoxCode/STM32F103RCT6/MOD/Src/mod_candataprocess.c

@@ -102,7 +102,7 @@ static iso15765_t handler0 =
     .clbs.indn = parse_finish_callback,
     .config.stmin = 0x3,
     .config.bs = 0x0f,
-    .config.n_bs = 100,
+    .config.n_bs = 500,
     .config.n_cr = 3
 };
 
@@ -116,7 +116,7 @@ static iso15765_t handler1 =
     .clbs.indn = parse_finish_callback,
     .config.stmin = 0x3,
     .config.bs = 0x0f,
-    .config.n_bs = 100,
+    .config.n_bs = 500,
     .config.n_cr = 3
 };
 
@@ -130,7 +130,7 @@ static iso15765_t handler2 =
     .clbs.indn = parse_finish_callback,
     .config.stmin = 0x3,
     .config.bs = 0x0f,
-    .config.n_bs = 100,
+    .config.n_bs = 500,
     .config.n_cr = 3
 };
 
@@ -144,7 +144,7 @@ static iso15765_t handler3 =
     .clbs.indn = parse_finish_callback,
     .config.stmin = 0x3,
     .config.bs = 0x0f,
-    .config.n_bs = 100,
+    .config.n_bs = 500,
     .config.n_cr = 3
 };
 
@@ -213,31 +213,31 @@ void MOD_CanPutDataToIso15765Parse(uint8_t* can_data, uint8_t data_len)
                 SYS_Hex2str(can_frame.dt, can_frame.dlc));
 
     // //开始往队列中放入数据
-    // uint8_t find_frame_id_flag = 0;
-    // for(int i=0; i<sizeof(data_process_handler_list)/sizeof(HANDLER_T); i++)
-    // {
-    //     //先找下这个id有没有在列表里面,如果在的话就放进去,如果不在的话就重新找新的放入
-    //     if(data_process_handler_list[i].frame_id == can_frame.id)
-    //     {
-    //         LOG_D("find frame_id");
-    //         find_frame_id_flag = 1;
-    //         iso15765_enqueue(data_process_handler_list[i].process_handler, &can_frame);
-    //     }
-    // }
-    // if(0 == find_frame_id_flag)
-    // {
-    //     //这个frame_id不在之前发过的历史列表里面,那找个新的放进去
-    //     for(int j=0; j<sizeof(data_process_handler_list)/sizeof(HANDLER_T); j++)
-    //     {
-    //         if(UINT32_DEFAULT_VAL == data_process_handler_list[j].frame_id)
-    //         {
-    //             LOG_D("not find frame_id, now set %d", j);
-    //             data_process_handler_list[j].frame_id = can_frame.id;
-    //             iso15765_enqueue(data_process_handler_list[j].process_handler, &can_frame);
-    //             break;
-    //         }
-    //     }
-    // }
+    uint8_t find_frame_id_flag = 0;
+    for(int i=0; i<sizeof(data_process_handler_list)/sizeof(HANDLER_T); i++)
+    {
+        //先找下这个id有没有在列表里面,如果在的话就放进去,如果不在的话就重新找新的放入
+        if(data_process_handler_list[i].frame_id == can_frame.id)
+        {
+            DLOG_I("find frame_id");
+            find_frame_id_flag = 1;
+            iso15765_enqueue(data_process_handler_list[i].process_handler, &can_frame);
+        }
+    }
+    if(0 == find_frame_id_flag)
+    {
+        //这个frame_id不在之前发过的历史列表里面,那找个新的放进去
+        for(int j=0; j<sizeof(data_process_handler_list)/sizeof(HANDLER_T); j++)
+        {
+            if(UINT32_DEFAULT_VAL == data_process_handler_list[j].frame_id)
+            {
+                DLOG_I("not find frame_id, now set %d", j);
+                data_process_handler_list[j].frame_id = can_frame.id;
+                iso15765_enqueue(data_process_handler_list[j].process_handler, &can_frame);
+                break;
+            }
+        }
+    }
 
 }
 /******************ISO15765**********************************/

+ 26 - 19
BleCanBoxCode/STM32F103RCT6/Middle/iso15765-canbus-master/src/lib_iso15765.c

@@ -38,7 +38,9 @@ SOFTWARE.
 /******************************************************************************
 * Enumerations, structures & Variables
 ******************************************************************************/
-#define  DEBUG_LOG_EN 0
+#define  DEBUG_LOG_EN 1
+#define  LOG_D  DLOG_I
+#define  LOG_E  DLOG_I
 /* Structs used by the service to inform the user(upper layer) of an event */
 static n_indn_t sgn_indn,sf_indn;
 static n_ff_indn_t sgn_ff_indn;
@@ -139,7 +141,7 @@ inline static uint8_t n_get_dt_offset(addr_md address, pci_type pci, uint16_t da
 		addr_mode = N_ADM_EXTENDED;
 	}
 
-	uint8_t offset = (addr_mode & 0x01); //固定为1.
+	uint8_t offset = (addr_mode & 0x01); //????1.
 
 	switch (pci)
 	{
@@ -287,21 +289,21 @@ inline  static n_rslt n_pci_unpack(addr_md mode, n_pdu_t* n_pdu, uint8_t dlc, ui
 #endif //DEBUG_LOG_EN
 	if (n_pdu != NULL && dt != NULL)
 	{
-		uint8_t offs = (addr_mode & 0x01); //固定为1.
-		n_pdu->n_pci.pt = (pci_type)((dt[0 + offs] & 0xF0) >> 4); //判断是首帧流控帧?
+		uint8_t offs = (addr_mode & 0x01); //????1.
+		n_pdu->n_pci.pt = (pci_type)((dt[0 + offs] & 0xF0) >> 4); //?ж????????????
 #if DEBUG_LOG_EN
 		LOG_D("n_pdu->n_pci.pt:0x%x", n_pdu->n_pci.pt);
 #endif 
 		switch (n_pdu->n_pci.pt)
 		{
-		case N_PCI_T_SF: //单帧
-			n_pdu->n_pci.dl = dlc <= 8 ? (dt[0 + offs] & 0x0F) : (dt[1 + offs]); //计算返回应用的payload的长度.单帧dlc长度可以大于8么.?
+		case N_PCI_T_SF: //???
+			n_pdu->n_pci.dl = dlc <= 8 ? (dt[0 + offs] & 0x0F) : (dt[1 + offs]); //??????????payload?????.???dlc??????????8?.?
 			result = N_OK;
 #if DEBUG_LOG_EN
 			LOG_D("N_PCI_T_SF,n_pdu->n_pci.dl:%d", n_pdu->n_pci.dl);
 #endif //DEBUG_LOG_EN			
 			break;
-		case N_PCI_T_FF: //首帧
+		case N_PCI_T_FF: //???
 			n_pdu->n_pci.dl = (dt[0 + offs] & 0x0F) << 8 | dt[1 + offs];
 			n_pdu->sz = dlc - (2 + offs);
 			result = N_OK;
@@ -309,7 +311,7 @@ inline  static n_rslt n_pci_unpack(addr_md mode, n_pdu_t* n_pdu, uint8_t dlc, ui
 			LOG_D("N_PCI_T_FF,n_pdu->n_pci.dl:%d,n_pdu->sz:%d", n_pdu->n_pci.dl, n_pdu->sz);
 #endif //DEBUG_LOG_EN			
 			break;
-		case N_PCI_T_FC: //流控帧
+		case N_PCI_T_FC: //?????
 			n_pdu->n_pci.fs = dt[0 + offs] & 0x0F;
 			n_pdu->n_pci.bs = dt[1 + offs];
 			n_pdu->n_pci.st = dt[2 + offs];
@@ -319,7 +321,7 @@ inline  static n_rslt n_pci_unpack(addr_md mode, n_pdu_t* n_pdu, uint8_t dlc, ui
 			LOG_D("N_PCI_T_FF,n_pdu->n_pci.fs:%d,n_pdu->n_pci.bs:%d,n_pdu->n_pci.st:%d,n_pdu->sz:%d", n_pdu->n_pci.fs,n_pdu->n_pci.bs,n_pdu->n_pci.st,n_pdu->sz);
 #endif //DEBUG_LOG_EN			
 			break;
-		case N_PCI_T_CF: //连续帧
+		case N_PCI_T_CF: //?????
 			n_pdu->n_pci.sn = (dt[0 + offs] & 0x0F);
 			n_pdu->sz = dlc - (1 + offs);
 			result = N_OK;
@@ -543,8 +545,8 @@ inline static n_rslt n_pdu_unpack(addr_md mode, n_pdu_t* n_pdu, uint32_t id, uin
 		return N_UNE_PDU;
 	}
 
-	n_pci_unpack(mode, n_pdu, dlc, dt);  //获取帧类型和payload长度.
-	n_pdu_unpack_dt(mode, n_pdu, dt);    //拷贝数据.
+	n_pci_unpack(mode, n_pdu, dlc, dt);  //?????????payload????.
+	n_pdu_unpack_dt(mode, n_pdu, dt);    //????????.
 #if DEBUG_LOG_EN
 	LOG_D("n_pdu_unpack_finish");
 #endif //DEBUG_LOG_EN
@@ -577,7 +579,7 @@ inline static void signaling(signal_tp tp, n_iostream_t* strm, void(*cb)(void*),
 #if DEBUG_LOG_EN
 			LOG_D("send event to upper,N_INDN,strm->sts:0x%x", strm->sts);
 #endif //DEBUG_LOG_EN
-			cb(&sgn_indn);//抛到上层.
+			cb(&sgn_indn);//??????.
 			break;
 		case N_SF_INDN: 
 			sf_indn.rslt = sgn_rslt;
@@ -591,7 +593,7 @@ inline static void signaling(signal_tp tp, n_iostream_t* strm, void(*cb)(void*),
 #if DEBUG_LOG_EN
 			LOG_D("send event to upper,N_SF_INDN,strm->sts:0x%x", strm->sts);
 #endif //DEBUG_LOG_EN
-			cb(&sf_indn);//抛到上层.
+			cb(&sf_indn);//??????.
 			break;
 		case N_FF_INDN:
 			sgn_ff_indn.fr_fmt = strm->fr_fmt;
@@ -632,7 +634,8 @@ inline static n_rslt process_timeouts(iso15765_t* ih)
 	{
 		return N_OK;
 	}
-
+	DLOG_I("sts:%d,last_upd.n_bs:%d,config_n_bs:%d,get_ms:%d", ih->out.sts, ih->out.last_upd.n_bs, ih->config.n_bs, ih->clbs.get_ms());
+	DLOG_I("n_bs timeout");
 	/* if timeout occures then reset the counters and report to the upper layer */
 	ih->out.cf_cnt = 0x0;
 	signaling(N_INDN, &ih->out, (void*)ih->clbs.indn, ih->out.msg_sz, N_TIMEOUT_Bs);
@@ -726,7 +729,7 @@ static n_rslt process_in_ff(iso15765_t* ih, canbus_frame_t* frame)
 
 	/* Copy all data, init the CFrames reception parameters and send a FC */
 	memmove(ih->in.msg, ih->in.pdu.dt, ih->in.pdu.sz);
-	ih->in.msg_sz = ih->in.pdu.n_pci.dl; //记录总长度
+	ih->in.msg_sz = ih->in.pdu.n_pci.dl; //????????
 	ih->in.msg_pos = ih->in.pdu.sz;
 #if DEBUG_LOG_EN	
 	LOG_D("msg_sz:%d,msg_pos:%d", ih->in.msg_sz, ih->in.msg_pos);
@@ -751,7 +754,7 @@ static n_rslt process_in_sf(iso15765_t* ih, canbus_frame_t* frame)
 	* N_USData.indication, with <N_Result> set to N_UNEXP_PDU, to the upper layer, and
 	* process the SF N_PDU as the start of a new reception.*/
 #if DEBUG_LOG_EN
-	LOG_D("ih->in.sts:0x%x", ih->in.sts); //这个初始值是IDLE是从哪设置的?
+	LOG_D("ih->in.sts:0x%x", ih->in.sts); //?????????IDLE???????????
 #endif //DEBUG_LOG_EN
 // 	if ((ih->in.sts & N_S_RX_BUSY) != 0)
 // 	{
@@ -761,9 +764,9 @@ static n_rslt process_in_sf(iso15765_t* ih, canbus_frame_t* frame)
 // 		ih->clbs.on_error(N_UNE_PDU);
 // 		signaling(N_INDN, &ih->in, (void*)ih->clbs.indn, ih->in.msg_sz, N_UNE_PDU);
 // 	}
-	memmove(&ih->in.sf_msg[0], ih->in.pdu.sf_dt, ih->in.pdu.n_pci.dl);//拷贝payload.
+	memmove(&ih->in.sf_msg[0], ih->in.pdu.sf_dt, ih->in.pdu.n_pci.dl);//????payload.
 	// ih->in.sts = N_S_IDLE;
-	//往上层抛出事件.
+	//???????????.
 	signaling(N_SF_INDN, &ih->in, (void*)ih->clbs.indn, ih->in.pdu.n_pci.dl, N_OK);
 	return N_OK;
 }
@@ -842,6 +845,8 @@ static n_rslt process_in_fc(iso15765_t* ih, canbus_frame_t* frame)
 {
 	n_rslt rslt = N_UNE_PDU;
 
+	DLOG_I("ih->out.sts:%d", ih->out.sts);
+
 	/* According to (ref: iso15765-2 p.26) if we are not expecting FC frame
 	* we should ignore it */
 	if (ih->out.sts != N_S_TX_WAIT_FC)
@@ -849,6 +854,8 @@ static n_rslt process_in_fc(iso15765_t* ih, canbus_frame_t* frame)
 		return rslt;
 	}
 
+	DLOG_I("ih->in.pdu.n_pci.fs:%d", ih->in.pdu.n_pci.fs);
+
 	switch (ih->in.pdu.n_pci.fs)
 	{
 	case N_WAIT:
@@ -1070,7 +1077,7 @@ iso15765_process_out_cfm:
 	ih->out.sts = N_S_IDLE;
 	ih->out.cf_cnt = 0;
 	ih->out.wf_cnt = 0;
-	//返回给上层结果.
+	//??????????.
 	signaling(N_CONF, &ih->out, (void*)ih->clbs.cfm, 0, rslt);
 	return rslt;
 }