目录
一、如何自动生成代码
二、借鉴之处
一、如何自动生成代码
准备:
.gny——geny工程
.dbc——CAN 信号矩阵
.cdd——诊断文件
.cfg文件——工程文件宏定义
1.1 打开gny文件
1.2 导入dbc文件
根据dbc文件更新can消息
channel0,configurable options,Acceptance Filter Configuration,optimize
Rx Signals编辑,Add需要接收的信号
1.3 导入cdd文件
1.4 导入cfg文件
在configurable options中选择user Config File, 设置生成代码路径
1.5 生成代码
二、借鉴之处
appdesc.c
desc.h 应用层定义
drv_par.h 物理驱动层
nmb_cfg.h 网络管理配置信息
tp_cfg.h 传输层参数配置信息
v_inc.h 定义文件版本
v_par.h 定义软件版本信息
ccl_cfg.h 定义外部接口
基本流程如下:
/*session id*/
typedef struct DescStateInfoTag
{DescStateGroup stateSession : 2;DescStateGroup stateGap_0 : 6;
} DescStateInfo;/*service id*/
typedef vuint8 DescMsgItem;
DescMsgItem g_descSidMap[];typedef struct
{DescBitType reqHeadByteSpec :8; /* Each bit represents sub-function/identifier - 0: identifier; 1: any subfunction */
#if defined(DESC_ENABLE_SUB_SVC_USAGE)DescBitType reqHeadExLen :4; /* Request HeadEx length up to 7 Byte */DescBitType resHeadExLen :4; /* Response HeadEx length up to 7 Byte */
#endif
#if defined (DESC_ENABLE_ADDR_METHOD_CHECK)DescBitType reqType :2; /* 0x01: Phys 0x02: Func */DescBitType resOnReq :2; /* 0x01: Phys 0x02: Func */
#endifDescBitType suppPosRes :1; /* 0x00: No 0x01: Yes */DescBitType isReqHeadExtEchoed:1; /* 0x00: No 0x01: Yes */DescBitType hasSubFunction :1; /* 0x00: No 0x01: Yes */
#if (kDescNumSvcHeadConstGapBits > 0)DescBitType svcHeadPlaceHolder:kDescNumSvcHeadConstGapBits; /* Gap holder */
#endif
#if defined (DESC_ENABLE_AUTO_STATES)
# if defined (DESC_ENABLE_ALL_STATEGROUPS_SID_CHECK)DescStateInfo checkState;
# else
# if (kDescNumStateSession > 0)DescStateGroup checkSessionState :kDescNumStateSession;/* State group Session on SId level */
# if (kDescNumSvcHeadSessionGapBits > 0)DescBitType sessionPlaceHolder:kDescNumSvcHeadSessionGapBits; /* Gap holder */
# endif
# endif
# endif
#endif
#if defined (DESC_ENABLE_MIN_REQ_LEN_CHECK) && \defined (DESC_ENABLE_SUB_SVC_USAGE)vuint8 minReqLength;
#endif
#if defined (DESC_ENABLE_MULTI_VARIANT)DescVariantMask variantMask;
#endif
/* First item in Service Instance table */DescMemSvcInstIndex svcInstFirstItem;DescMemSvcInstHeadExtIndex svcInstHeadExtFirstItem;
} DescSvcHead;
/* Table of service ID relevant information. */
V_MEMROM0 static V_MEMROM1 DescSvcHead V_MEMROM2 g_descSvcHead[kDescSvcHeadNumItems] =
{{ 0x01, 1, 1, 1, 1, 1, 0x00, { 0x03, 0x00 }, 2, 0, 0 } /* $10 */, { 0x01, 0, 0, 0, 1, 0, 0x00, { 0x03, 0x00 }, 4, 2, 2 } /* $14 */, { 0x01, 1, 1, 1, 1, 1, 0x00, { 0x03, 0x00 }, 2, 3, 2 } /* $19 */, { 0x01, 0, 0, 0, 1, 0, 0x00, { 0x03, 0x00 }, 1, 9, 8 } /* $22 */, { 0x01, 1, 1, 1, 1, 1, 0x00, { 0x02, 0x00 }, 2, 10, 8 } /* $28 */, { 0x07, 2, 2, 0, 1, 0, 0x00, { 0x03, 0x00 }, 4, 12, 10 } /* $2E */, { 0x01, 0, 0, 1, 1, 1, 0x00, { 0x03, 0x00 }, 1, 22, 30 } /* $31 */, { 0x01, 1, 1, 1, 1, 1, 0x00, { 0x03, 0x00 }, 2, 23, 30 } /* $3E */, { 0x00, 0, 0, 0, 1, 0, 0x00, { 0x03, 0x00 }, 1, 24, 31 } /* $FF */
};typedef struct
{DescMsgLen reqLen;
#if defined (DESC_ENABLE_ADDR_METHOD_CHECK)DescMsgAddInfo msgAddInfo;
#endif
#if defined (DESC_ENABLE_AUTO_STATES)DescStateInfo checkState;
# if (kDescStateGroupNumTransition > 0)DescSetStateIndex setStateIndex;
# endif
#endif /* DESC_ENABLE_AUTO_STATES */
#if defined (DESC_ENABLE_MULTI_VARIANT)DescVariantMask variantMask;
#endif
#if defined (DESC_ENABLE_PREHANDLER_USAGE)DescPreHandlerIndex preHandlerRef;
#endif
#if defined (DESC_ENABLE_POSTHANDLER_USAGE)DescPostHandlerIndex postHandlerRef;
#endifDescMainHandler mainHandler;
} DescSvcInst;/* Table of sub-service protocol information. */
V_MEMROM0 static V_MEMROM1 DescMsgItem V_MEMROM2 g_descSvcInstHeadExt[kDescSvcInstHeadExtNumItems] =
{0x01, 0x03 /* $10 */, 0x01, 0x02, 0x03, 0x04, 0x05, 0x0A /* $19 */, 0x00, 0x03 /* $28 */, 0x10, 0x41, 0x10, 0x42, 0x10, 0x43, 0x10, 0x44, 0x10, 0x66, 0x10, 0x67, 0x10, 0x68, 0x10, 0x69 /* $2E */, 0x10, 0x6A, 0x10, 0x6B /* $2E */, 0x00 /* $3E */
};/* Table of all RIDs' */
V_MEMROM0 static V_MEMROM1 vuint16 V_MEMROM2 g_descRidLookUpTable[kDescNumRids] =
{0x0201, 0x0202, 0x0203, 0x0204, 0x0205, 0x0221, 0x0225, 0x0226, 0x0227
};
/* Table of RIDs' sub-function to control type mapping. */
V_MEMROM0 static V_MEMROM1 vuint8 V_MEMROM2 g_descRidSubFuncToCtrlTypeMap[4] =
{27, 0, 1, 2
};
/* Table of all RIDs' properties. */
V_MEMROM0 static V_MEMROM1 DescRidTinyInfo V_MEMROM2 g_descRIDInfo[kDescNumRids] =
{{ { 0x03, 0x00 }, { 0x01, 0x01, 0 } } /* $0202 */,
};typedef struct
{DescMsgLen reqDataLen; /* contains the RID and the request parameters' length only*/DescRidTinyInfo tinyInfo;
#if defined (DESC_ENABLE_RID_POSTHANDLER_USAGE)DescPostHandlerIndex postHandlerRef;
#endifDescMainHandler mainHandler;
} DescRidInst;