Lesen von CAN Frames vorbereitet
This commit is contained in:
@@ -41,6 +41,20 @@ int Can_OpenInterface(int iMotorIndex, const char * ifacename)
|
||||
return 3;
|
||||
}
|
||||
|
||||
// socket auf nicht-blockierend umstellen
|
||||
int fcntl_flags = fcntl(intf_data[iMotorIndex].socket, F_GETFL, 0);
|
||||
if (fcntl_flags < 0)
|
||||
{
|
||||
printf("Could not get file descriptor flags!\n");
|
||||
return 4;
|
||||
}
|
||||
fcntl_flags |= O_NONBLOCK;
|
||||
if (fcntl(intf_data[iMotorIndex].socket, F_SETFL, fcntl_flags) < 0)
|
||||
{
|
||||
printf("Could not set file descriptor flags (set socket none-blocking)!\n");
|
||||
return 5;
|
||||
}
|
||||
|
||||
printf("Interface %s (motor %d) opened!\n", ifacename, iMotorIndex);
|
||||
|
||||
return 0;
|
||||
@@ -177,3 +191,53 @@ void Can_TransmitMotorPower(int iMotorIndex)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// @brief Read data from CAN interface
|
||||
/// @param iMotorIndex
|
||||
void Can_ReadData(int iMotorIndex)
|
||||
{
|
||||
ssize_t nbytes = 0;
|
||||
struct can_frame frame;
|
||||
|
||||
// wir wollen immer alle verfügbaren Frames lesen
|
||||
while ((nbytes = read(intf_data[iMotorIndex].socket, &frame, sizeof(frame))) > 0)
|
||||
{
|
||||
canid_t pgn = frame.can_id & 0x00FFFF00;
|
||||
|
||||
switch(pgn)
|
||||
{
|
||||
case 0x00F00300: // PGN 61443 "Electronic Engine Controller 2"
|
||||
// haben wir selber gesendet -> ignorieren
|
||||
break;
|
||||
|
||||
case 0x00F00500: // PGN 61445 "Electronic Transmission Controller 2"
|
||||
// haben wir selber gesendet -> ignorieren
|
||||
break;
|
||||
|
||||
case 0x00FF1300: // PGN 65299 "Manufacturer PGN"
|
||||
// hier finden wir die Zustände der Schalter
|
||||
Can_Read_Manu_PGN(iMotorIndex, &frame);
|
||||
break;
|
||||
|
||||
case 0x00FF1400: // PGN 65300 "Manufacturer PGN 2"
|
||||
// hier bekommen wir die Leistung des Motors angezeigt
|
||||
Can_Read_Manu_PGN2(iMotorIndex, &frame);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Read PGN 65299
|
||||
/// @param frame
|
||||
void Can_Read_Manu_PGN(int iMotorIndex, struct can_frame *frame)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// @brief Read PGN 65300
|
||||
/// @param frame
|
||||
void Can_Read_Manu_PGN2(int iMotorIndex, struct can_frame *frame)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user