-
Notifications
You must be signed in to change notification settings - Fork 2
/
id2pgn.c
44 lines (42 loc) · 1.5 KB
/
id2pgn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include "canid_type.h"
typedef unsigned int uint;
typedef unsigned char uchar;
int main() {
uint id;
uint P; // 优先级
uint R; // 保留位
uint DP; // 数据页
uint PF; // PDU格式
uint PS; // 特定PDU
uint SA; // 源地址
uint GE = 0; // 群拓展
uint PGN = 0;// 参数群编号
uint DA; // 目标地址
printf("Please input CAN frame's Extended ID : 0x");
scanf("%08x",&id);
printf("Get CAN frame's ID : 0x%08x (%d)\n",id, id);
SA = (id & SA_MASK_CAN_ID)>>SA_SHIFT_CAN_ID;
PS = (id & PS_MASK_CAN_ID)>>PS_SHIFT_CAN_ID;
PF = (id & PF_MASK_CAN_ID)>>PF_SHIFT_CAN_ID;
DP = (id & DP_MASK_CAN_ID)>>DP_SHIFT_CAN_ID;
R = (id & R_MASK_CAN_ID) >>R_SHIFT_CAN_ID;
P = (id & P_MASK_CAN_ID) >>P_SHIFT_CAN_ID;
printf("|---|-|-|--------|--------|--------|\n");
printf("| | | | | | |\n");
printf("| P |R|D| PF | PS | SA |\n");
printf("| | |P| | | |\n");
printf(" %1d %-1d %-1d %-6d %-6d %-6d \n",P,R,DP,PF,PS,SA);
// 群拓展根据PF数值决定
if (PF >= GE_THRESHOLD) {
GE = PS;
printf("PF >= %d , so GE = PS : %d\n", GE_THRESHOLD, GE);
} else {
GE = 0;
DA = PS;
printf("PF < %d , so GE : %d, DA = PS : %d\n", GE_THRESHOLD, GE , DA);
}
PGN = 0;
PGN |= (GE << GE_SHIFT_PGN) | (PF << PF_SHIFT_PGN) | (DP << DP_SHIFT_PGN) | (R << R_SHIFT_PGN);
printf("PGN : 0x%x(%d)\n", PGN,PGN);
}