# my-source **Repository Path**: preciousun/my-source ## Basic Information - **Project Name**: my-source - **Description**: j1939协议解析报文 - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2026-02-18 - **Last Updated**: 2026-02-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README <<<<<<< HEAD <<<<<<< HEAD ======= >>>>>>> bef428d9dfccad791c3cac72c984d5fdb6c33547 # my-source #### 介绍 j1939协议解析报文 #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) <<<<<<< HEAD ======= # j1939报文解析 ### 一.applications #### -Src ##### 1.bsp_can.c --- can底层 ##### 2.set_frameInfo ---设置要发送帧的信息(修改帧内容) ##### 3.command_frame ---所有要发送的帧 #### -Inc #### -main.c ##### --- bsp_can_init ##### ---J1939_Config_Init ### 二.Demo(解析一帧遥控命令帧) #### 1.定义遥控命令帧的帧格式 (set_frameInfo.h) ```c /* 遥控命令帧 */ typedef struct { struct control_byte { j1939_uint8_t reserved : 1; // 预留位 j1939_uint8_t main_contact_status : 1; // 充电回路主接触器状态 j1939_uint8_t power_distribution_contact_status : 1; // 功率分配回路接触器状态 j1939_uint8_t voltage_output_range : 1; // 电压输出范围选择 j1939_uint8_t operation_instructions : 4; // 操作指令 }control_byte; struct group_byte { j1939_uint8_t eight_group : 1; //第八组 j1939_uint8_t Seven_group : 1; //第七组 j1939_uint8_t six_group : 1; //第六组 j1939_uint8_t fifty_group : 1; //第五组 j1939_uint8_t four_group : 1; //第四组 j1939_uint8_t three_group : 1; //第三组 j1939_uint8_t two_group : 1; //第二组 j1939_uint8_t one_group : 1; //第一组 }group_byte; j1939_uint16_t set_vdc; //给定电压 j1939_uint16_t set_current; //给定电流 j1939_uint16_t battery_vdc; //电池电压 } ChargingControlInfo; enum cmd { QUICK_START = 0x01, //快速开机(绝缘检测阶段使用) STOP_CHARG, //停止充电 SOFT_START, //软启开机(预启动阶段使用) ADDRESS, //显示地址(显示模块通信地址) PARM_REVISE, //参数修改 }cmd; ``` #### 2.设置遥控命令帧的帧信息 (在此处修改帧内容) (set_frameInfo.c) ```c /* * 设置遥控命令帧信息 */ ChargingControlInfo control_info; void set_charging_param(void) { control_info.control_byte.reserved = 0; //预留位 control_info.control_byte.main_contact_status = 1; //充电回路主接触器状态(闭合) control_info.control_byte.power_distribution_contact_status = 1;//功率分配回路接触器状态(闭合) control_info.control_byte.voltage_output_range = 1; //电压输出范围选择(高电压段) control_info.control_byte.operation_instructions = 0x01; //操作指令(快速开机) control_info.group_byte.eight_group = 0; //第八组 control_info.group_byte.Seven_group = 0; //第七组 control_info.group_byte.six_group = 0; //第六组 control_info.group_byte.fifty_group = 0; //第五组 control_info.group_byte.four_group = 0; //第四组 control_info.group_byte.three_group = 0; //第三组 control_info.group_byte.two_group = 1; //第二组 control_info.group_byte.one_group = 1; //第一组 control_info.set_vdc = 0x1F4; //给定电压 50V control_info.set_current = 0x12C; //给定电流 3A control_info.battery_vdc = 0x1F4; //电池电压 50V } ``` #### 3.发送一帧遥控命令帧 (command_frame.c) ```c //遥控命令帧(固定分组模式) int j1939_GDCMD_FixedGroup(void) { J1939_MESSAGE _msg; set_charging_param(); /*****发送数据(参考J1939的ID组成填充下面)***/ _msg.j1939_pid.DataPage = 0; _msg.j1939_pid.Priority = J1939_PROPRIETARY_PRIORITY; _msg.j1939_pid.PDUSpecific = 0x80; //PDU1格式下 -- 目标地址 _msg.j1939_pid.DataLength = 8; //数据长度 _msg.j1939_pid.PDUFormat = 0x01; //指定PDU格式 < 240为 PDU1 _msg.j1939_pid.Data[0] = (control_info.control_byte.reserved << 7) | (control_info.control_byte.main_contact_status << 6) | (control_info.control_byte.power_distribution_contact_status << 5) | (control_info.control_byte.voltage_output_range << 4) | (control_info.control_byte.operation_instructions); _msg.j1939_pid.Data[1] = control_info.group_byte.one_group; _msg.j1939_pid.Data[2] = control_info.set_vdc & 0xFF; //存入低八位 _msg.j1939_pid.Data[3] = (control_info.set_vdc >> 8) & 0xFF; //存入高八位 _msg.j1939_pid.Data[4] = control_info.set_current & 0xFF; _msg.j1939_pid.Data[5] = (control_info.set_current >> 8) & 0xFF; _msg.j1939_pid.Data[6] = control_info.battery_vdc & 0xFF; _msg.j1939_pid.Data[7] = (control_info.battery_vdc >> 8) & 0xFF; while (J1939_Send_Message( &_msg, Select_CAN_NODE_1) != RC_SUCCESS); return SUCCESS; } ``` >>>>>>> 54f8185 (使用j1939协议解析报文) ======= >>>>>>> bef428d9dfccad791c3cac72c984d5fdb6c33547