frame padding c++ example

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

frame padding c++ example

Post by elpimous12 » Tue 3. May 2022, 18:57

Hello the team, hello all.
I need, in my project, to replace unused bytes 0x00 to 0x50.
frame example : 0100001f010000000000000000000000000070785a698a55000090785a698a55000090785a698a55000000000000000000000000000000000000000000000000
Could I find anywhere, a simple c++ example?
Thanks the team.
Vincent

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: frame padding c++ example

Post by elpimous12 » Tue 3. May 2022, 21:19

For example, the last 20 bytes...

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: frame padding c++ example

Post by PEAK-Support » Thu 5. May 2022, 11:00

Sorry - but we do not know what you are talking about...

- Which API
- Which Function

A CAN Frame do not look like you descripe. A CAN Frame have a ID, MsgType, DLC/LEN, and some Databytes (or none)
If you want support - aks in a way that all understand what you exact talking about
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: frame padding c++ example

Post by elpimous12 » Thu 5. May 2022, 15:40

Hello, sorry for explication..
Testing again
In my c++ code, Ubuntu 20.04, pcanbasic api, Peak M2,

I built a frame FD, containing 32 bytes.

_tx_msg.id = 0x8000 | id;
_tx_msg.length = 32;
// Write Mode
_tx_msg.data[0] = 0x01; // Write uint8 (0x00) | Write 1 register (0x01)
_tx_msg.data[1] = 0x00; // Register to write: MODE
_tx_msg.data[2] = 0x0A; // Value to write: POSITION MODE
// Write command
_tx_msg.data[3] = 0x0C; // Write floats
_tx_msg.data[4] = 0x06; // Write 6 registers
_tx_msg.data[5] = 0x20; // Starting register: POSITION_COMM, VELOCITY_COMM, FFTORQUE_COMM, KP_SCALE, KD_SCALE, MAX_TORQUE
// Query
_tx_msg.data[30] = 0x1F; // Read floats (0x1C) | Read 3 registers (0x03)
_tx_msg.data[31] = 0x01; // Starting register: POSITION, VELOCITY, TORQUE

Data[6-29] are feeded anywhere else.

When I read this frame, I read a 64bytes frame, with the last 32 bytes as 0x00

The controller must read unused bytes as 0x50 and not 0x00

Can I limit frame to my need : 32 bytes? Or can I pad : replace the last 0x00 to 0x50 (any code example?)

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: frame padding c++ example

Post by PEAK-Support » Thu 5. May 2022, 15:57

When you read or write a CAN Frame from the PCAN-Basic API, you always have to check:

- return value of the read / write Function - must be CAN_ERROR_OK
- the Message Type must be corect (sending) or must be checked (reading)
- The DLC or LEN (DLC is not the same as LEN when using CAN-FD !! See Documentation !!) must fit

You only use the DataBytes that are valid - see DLC/LEN ! it is a differnet !

Code: Select all

// Represents a PCAN message from a FD capable hardware
//
typedef struct tagTPCANMsgFD
{
    DWORD             ID;       // 11/29-bit message identifier
    TPCANMessageType  MSGTYPE;  // Type of the message
    BYTE              DLC;      // Data Length Code of the message (0..15)
    BYTE              DATA[64]; // Data of the message (DATA[0]..DATA[63])
} TPCANMsgFD;

Code: Select all

// Represents a PCAN message
//
typedef struct tagTPCANMsg
{
    DWORD             ID;      // 11/29-bit message identifier
    TPCANMessageType  MSGTYPE; // Type of the message
    BYTE              LEN;     // Data Length Code of the message (0..8)
    BYTE              DATA[8]; // Data of the message (DATA[0]..DATA[7])
} TPCANMsg;
Here a sample code to convert from DLC (0..15) to real Data Bytes LEN (0..64)

Code: Select all

int GetLengthFromDLC(BYTE dlc)
{
	switch (dlc)
	{
	case 9: return 12;
	case 10: return 16;
	case 11: return 20;
	case 12: return 24;
	case 13: return 32;
	case 14: return 48;
	case 15: return 64;
	default: return dlc;
	}
}
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: frame padding c++ example

Post by elpimous12 » Fri 6. May 2022, 13:46

Perfect. Thanks the team

Post Reply