Explorar el Código

style:添加调试日志
module:lib_iso15765
ticket_ID:lib_iso15765

yangyongkai hace 3 años
padre
commit
374e50b508

+ 41 - 27
BleCanBoxCode/c_project_iso/application/main.c

@@ -18,7 +18,7 @@
 #define MULTI_FRAME_EN 1
 #define UINT32_DEFAULT_VAL 0xFFFFFFFF
 
-static uint8_t g_s_log_lvl = LOG_LVL_I;
+static uint8_t g_s_log_lvl = LOG_LVL_D;
 
 static uint32_t GetTickCount()
 {
@@ -161,7 +161,7 @@ static void parse_finish_callback(n_indn_t *info)
         {
             for (int i = 0; i < info->msg_sz; i++)
             {
-                printf("%02X", info->msg[i]);
+                printf("0x%02x,", info->msg[i]);
             }
         }
         printf("\r\n");
@@ -178,41 +178,52 @@ static void parse_finish_callback(n_indn_t *info)
 * Definition  | Public Functions
 ******************************************************************************/
 
+// uint8_t send_buf[] = {  
+//     0x06,0x12,0x05,0xdf,0x03,0x22,0xf1,0x01,
+
+//     0x06,0x12,0x08,0xf1,0x10,0x34,0x62,0xf1,0x01,0x01,0x01,
+//     0x06,0x12,0x08,0xf1,0x21,0x00,0x04,0x21,0x06,0x22,0x8f,
+//     0x06,0x12,0x08,0xf1,0x22,0x04,0xd2,0x01,0x00,0x00,0x10,
+//     0x06,0x12,0x08,0xf1,0x23,0x00,0x00,0x00,0x01,0x00,0x00,
+//     0x06,0x12,0x08,0xf1,0x24,0x3c,0xfb,0x04,0x00,0x00,0x06,
+//     0x06,0x12,0x08,0xf1,0x25,0x00,0x00,0x3c,0xfc,0x04,0x00,
+//         0x06,0x60,0x08,0xf1,0x10,0x34,0x62,0xf1,0x01,0x01,0x01,
+//     0x06,0x12,0x08,0xf1,0x26,0x00,0x08,0x00,0x00,0x34,0xec,
+//     0x06,0x12,0x08,0xf1,0x27,0x0d,0x00,0x00,0x08,0x00,0x00,
+//         0x06,0x60,0x08,0xf1,0x21,0x00,0x04,0x21,0x06,0x06,0x8f,
+//     0x06,0x12,0x08,0xf1,0x28,0x43,0x4e,0x0d,0x00,0x01,0xaa,
+
+//     0x06,0x60,0x08,0xf1,0x22,0x04,0xd2,0x01,0x00,0x00,0x10,
+//     0x06,0x60,0x08,0xf1,0x23,0x00,0x00,0x00,0x01,0x00,0x00,
+//     0x06,0x60,0x08,0xf1,0x24,0x36,0x15,0x01,0x02,0x00,0x06,
+//         0x06,0x29,0x08,0xf1,0x10,0x2c,0x62,0xf1,0x01,0x01,0x01,
+//     0x06,0x60,0x08,0xf1,0x25,0x00,0x00,0x36,0x16,0x01,0x02,
+//     0x06,0x60,0x08,0xf1,0x26,0x01,0x08,0x00,0x00,0x36,0x17,
+//         0x06,0x29,0x08,0xf1,0x21,0x00,0x03,0x21,0x06,0x06,0x8f,
+//     0x06,0x60,0x08,0xf1,0x27,0x01,0x07,0x00,0x05,0x00,0x00,
+//     0x06,0x60,0x08,0xf1,0x28,0x36,0x18,0x01,0x03,0x0f,0xff,
+//         0x06,0x29,0x08,0xf1,0x22,0x04,0xd2,0x01,0x00,0x00,0x10,
+        
+//     0x06,0x29,0x08,0xf1,0x03,0x7f,0x22,0x78,0xff,0xff,0xff, //连续帧中间来了个单帧.
+
+//     0x06,0x29,0x08,0xf1,0x23,0x00,0x00,0x00,0x01,0x00,0x00,
+//     0x06,0x29,0x08,0xf1,0x24,0x38,0x72,0x00,0x02,0x00,0x06,
+//     0x06,0x29,0x08,0xf1,0x25,0x00,0x00,0x38,0x73,0x00,0x03,
+//     0x06,0x29,0x08,0xf1,0x26,0x02,0x08,0x00,0x00,0x38,0x74,
+//     0x06,0x29,0x08,0xf1,0x27,0x01,0x01,0x00,0xff,0xff,0xff
+// };
 uint8_t send_buf[] = {  
-    0x06,0xf1,0x05,0xdf,0x03,0x22,0xf1,0x01,
-
     0x06,0x12,0x08,0xf1,0x10,0x34,0x62,0xf1,0x01,0x01,0x01,
+    //中间省略一个流控帧.
     0x06,0x12,0x08,0xf1,0x21,0x00,0x04,0x21,0x06,0x22,0x8f,
     0x06,0x12,0x08,0xf1,0x22,0x04,0xd2,0x01,0x00,0x00,0x10,
     0x06,0x12,0x08,0xf1,0x23,0x00,0x00,0x00,0x01,0x00,0x00,
     0x06,0x12,0x08,0xf1,0x24,0x3c,0xfb,0x04,0x00,0x00,0x06,
     0x06,0x12,0x08,0xf1,0x25,0x00,0x00,0x3c,0xfc,0x04,0x00,
-        0x06,0x60,0x08,0xf1,0x10,0x34,0x62,0xf1,0x01,0x01,0x01,
     0x06,0x12,0x08,0xf1,0x26,0x00,0x08,0x00,0x00,0x34,0xec,
     0x06,0x12,0x08,0xf1,0x27,0x0d,0x00,0x00,0x08,0x00,0x00,
-        0x06,0x60,0x08,0xf1,0x21,0x00,0x04,0x21,0x06,0x06,0x8f,
     0x06,0x12,0x08,0xf1,0x28,0x43,0x4e,0x0d,0x00,0x01,0xaa,
-
-    0x06,0x60,0x08,0xf1,0x22,0x04,0xd2,0x01,0x00,0x00,0x10,
-    0x06,0x60,0x08,0xf1,0x23,0x00,0x00,0x00,0x01,0x00,0x00,
-    0x06,0x60,0x08,0xf1,0x24,0x36,0x15,0x01,0x02,0x00,0x06,
-        0x06,0x29,0x08,0xf1,0x10,0x2c,0x62,0xf1,0x01,0x01,0x01,
-    0x06,0x60,0x08,0xf1,0x25,0x00,0x00,0x36,0x16,0x01,0x02,
-    0x06,0x60,0x08,0xf1,0x26,0x01,0x08,0x00,0x00,0x36,0x17,
-        0x06,0x29,0x08,0xf1,0x21,0x00,0x03,0x21,0x06,0x06,0x8f,
-    0x06,0x60,0x08,0xf1,0x27,0x01,0x07,0x00,0x05,0x00,0x00,
-    0x06,0x60,0x08,0xf1,0x28,0x36,0x18,0x01,0x03,0x0f,0xff,
-        0x06,0x29,0x08,0xf1,0x22,0x04,0xd2,0x01,0x00,0x00,0x10,
-        
-    0x06,0x29,0x08,0xf1,0x03,0x7f,0x22,0x78,0xff,0xff,0xff, //连续帧中间来了个单帧.
-
-    0x06,0x29,0x08,0xf1,0x23,0x00,0x00,0x00,0x01,0x00,0x00,
-    0x06,0x29,0x08,0xf1,0x24,0x38,0x72,0x00,0x02,0x00,0x06,
-    0x06,0x29,0x08,0xf1,0x25,0x00,0x00,0x38,0x73,0x00,0x03,
-    0x06,0x29,0x08,0xf1,0x26,0x02,0x08,0x00,0x00,0x38,0x74,
-    0x06,0x29,0x08,0xf1,0x27,0x01,0x01,0x00,0xff,0xff,0xff
 };
-
 void *rx_data_task(void)
 {
     uint32_t test_cnt = 0;
@@ -279,7 +290,10 @@ void *iso15765_parse_task(void)
     {
         for (int i=0; i<sizeof(data_process_handler_list)/sizeof(HANDLER_T); i++)
         {
-            iso15765_process(data_process_handler_list[i].process_handler);
+            if(UINT32_DEFAULT_VAL != data_process_handler_list[i].frame_id)
+            {
+                iso15765_process(data_process_handler_list[i].process_handler);
+            }
         }
     }
 }

+ 28 - 10
BleCanBoxCode/c_project_iso/iso15765-canbus-master/src/lib_iso15765.c

@@ -278,7 +278,7 @@ inline  static n_rslt n_pci_unpack(addr_md mode, n_pdu_t* n_pdu, uint8_t dlc, ui
 		addr_mode = N_ADM_EXTENDED;
 	}
 #if DEBUG_LOG_EN
-	LOG_D("dlc:%d,data:", dlc);
+	printf("[%s:%d],dlc:%d,data:", __FUNCTION__, __LINE__, dlc);
 	for(int i=0; i<dlc; i++)
 	{
 		printf("%02X", dt[i]);
@@ -632,7 +632,8 @@ inline static n_rslt process_timeouts(iso15765_t* ih)
 	{
 		return N_OK;
 	}
-
+	LOG_D("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());
+	LOG_D("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);
@@ -648,6 +649,7 @@ static n_rslt send_N_PCI_T_FC(iso15765_t* ih)
 	uint32_t id;
 
 	ih->out.sts |= N_S_TX_BUSY;
+	LOG_D("ih->out.sts:%d", ih->out.sts);
 	ih->fl_pdu.n_pci.pt = N_PCI_T_FC;
 	ih->fl_pdu.n_pci.bs = ih->config.bs;
 	ih->fl_pdu.n_pci.st = ih->config.stmin;
@@ -663,6 +665,7 @@ static n_rslt send_N_PCI_T_FC(iso15765_t* ih)
 	if (n_pdu_pack(ih->addr_md, &ih->fl_pdu, &id, ih->out.msg) != N_OK)
 	{
 		ih->out.sts = (stream_sts)(ih->out.sts & (~N_S_TX_BUSY));
+		LOG_D("ih->out.sts:%d", ih->out.sts);
 		return N_ERROR;
 	}
 #if DEBUG_LOG_EN
@@ -684,6 +687,7 @@ inline static void set_stream_data(n_iostream_t* ist, uint8_t cf, uint8_t wf, st
 	ist->cf_cnt = cf;
 	ist->wf_cnt = wf;
 	ist->sts = sts;
+	LOG_D("ist->sts %d", ist->sts);
 }
 
 /*
@@ -831,6 +835,8 @@ static n_rslt process_in_cf(iso15765_t* ih, canbus_frame_t* frame)
 in_cf_error:
 	ih->clbs.on_error(rslt);
 	ih->in.sts = N_S_IDLE;
+	LOG_D("ih->in.sts:0x%x", ih->in.sts);
+
 	return rslt;
 }
 
@@ -842,12 +848,16 @@ static n_rslt process_in_fc(iso15765_t* ih, canbus_frame_t* frame)
 {
 	n_rslt rslt = N_UNE_PDU;
 
+	LOG_D("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)
-	{
-		return rslt;
-	}
+	// if (ih->out.sts != N_S_TX_WAIT_FC)
+	// {
+	// 	return rslt;
+	// }
+
+	LOG_D("ih->in.pdu.n_pci.fs:%d", ih->in.pdu.n_pci.fs);
 
 	switch (ih->in.pdu.n_pci.fs)
 	{
@@ -885,6 +895,7 @@ static n_rslt process_in_fc(iso15765_t* ih, canbus_frame_t* frame)
 	set_stream_data(&ih->out, 0, 0, N_S_IDLE);
 	ih->clbs.on_error(rslt);
 	ih->in.sts = N_S_IDLE;
+	LOG_D("ih->in.sts:0x%x", ih->in.sts);
 	return rslt;
 }
 
@@ -949,6 +960,7 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 	{
 		return N_IDLE;
 	}
+	LOG_D("ih->out.sts:%d", ih->out.sts);
 
 	uint32_t id;
 	n_rslt rslt = N_ERROR;
@@ -958,14 +970,14 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 	{
 		addr_mode = N_ADM_EXTENDED;
 	}
-	pci_type tmp_tmp = N_PCI_T_UN;
+	pci_type tmp_type = N_PCI_T_UN;
 	/* Find the PCI type of the pending outbound stream */
 	ih->out.pdu.n_pci.pt = n_out_frame_type(ih);
-	tmp_tmp = n_out_frame_type(ih);
+	tmp_type = n_out_frame_type(ih);
 #if DEBUG_LOG_EN
 	LOG_D("ih->out.pdu.n_pci.pt:0x%x", ih->out.pdu.n_pci.pt);
 #endif //DEBUG_LOG_EN
-	switch (tmp_tmp)
+	switch (tmp_type)
 	{
 	case N_PCI_T_SF:
 		/* Copy all the data of the SF to the outbound stream, pack and send the canbus frame */
@@ -1005,6 +1017,7 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 		/* after this frame we expect a Flow Control then assign the correct flag before the
 		* transmission to avoid any issues and start the timer */
 		ih->out.sts = N_S_TX_WAIT_FC;
+		LOG_D("ih->out.sts:%d", ih->out.sts);
 		rslt = ih->clbs.send_frame(ih->fr_id_type, id, ih->out.fr_fmt, ih->out.fr_fmt == CBUS_FR_FRM_STD ? 8 : 64, ih->out.pdu.dt) == 0 ? N_OK : N_ERROR;
 		ih->out.last_upd.n_bs = ih->clbs.get_ms();
 		return (rslt == 0) ? N_OK : N_ERROR;
@@ -1020,6 +1033,7 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 		* and then pack the PDU to a CANBus frame */
 		ih->out.pdu.n_pci.sn = ih->out.cf_cnt & 0x0F;
 		ih->out.cf_cnt = ih->out.cf_cnt == 0xFF ? 0 : ih->out.cf_cnt + 1;
+		LOG_D("ih->out.fr_fmt:%d", ih->out.fr_fmt);
 		if (ih->out.fr_fmt == CBUS_FR_FRM_STD)
 		{
 			uint8_t max_payload = (addr_mode & 0x01) == 0 ? 7 : 6;
@@ -1033,6 +1047,7 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 			ih->out.pdu.sz = ih->out.pdu.sz >= max_payload ? max_payload : ih->out.pdu.sz;
 		}
 #if DEBUG_LOG_EN
+		LOG_D("sn:%d,cnt:%d,sz:%d",ih->out.pdu.n_pci.sn, ih->out.cf_cnt, ih->out.pdu.sz);
 		LOG_D("n_pdu_pack");
 #endif //DEBUG_LOG_EN
 		if (n_pdu_pack(ih->addr_md, &ih->out.pdu, &id, &ih->out.msg[ih->out.msg_pos]) != N_OK)
@@ -1048,6 +1063,7 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 		if (ih->out.pdu.n_pci.sn == ih->config.bs)
 		{
 			ih->out.sts = N_S_TX_WAIT_FC;
+			LOG_D("ih->out.sts:%d", ih->out.sts);
 			ih->out.last_upd.n_bs = ih->clbs.get_ms();
 		}
 		/* send the canbus frame! */
@@ -1068,9 +1084,9 @@ static n_rslt iso15765_process_out(iso15765_t* ih)
 
 iso15765_process_out_cfm:
 	ih->out.sts = N_S_IDLE;
+	LOG_D("ih->out.sts:%d", ih->out.sts);
 	ih->out.cf_cnt = 0;
 	ih->out.wf_cnt = 0;
-	//·µ»Ø¸øÉϲã½á¹û.
 	signaling(N_CONF, &ih->out, (void*)ih->clbs.cfm, 0, rslt);
 	return rslt;
 }
@@ -1159,6 +1175,7 @@ n_rslt iso15765_send(iso15765_t* instance, n_req_t* frame)
 	/* Make sure that there is no transmission in progress */
 	if (instance->out.sts != N_S_IDLE)
 	{
+		LOG_D("instance->out.sts:%d", instance->out.sts);
 		return N_TX_BUSY;
 	}
 	/* and the requested size is fitting in our outbound buffer */
@@ -1173,6 +1190,7 @@ n_rslt iso15765_send(iso15765_t* instance, n_req_t* frame)
 	memmove(instance->out.msg, frame->msg, frame->msg_sz);
 	memmove(&instance->out.pdu.n_ai, &frame->n_ai, sizeof(n_ai_t));
 	instance->out.sts = N_S_TX_BUSY;
+	LOG_D("instance->out.sts:%d", instance->out.sts);
 
 	return N_OK;
 }