Configuración del filtro de mensajes
Última modificación:
Antes de comenzar a recibir o transmitir mensajes, es necesario configurar los filtros de mensajes. Si no se ha configurado ningún filtro, todos los mensajes se bloquean. Para el protocolo ISO 15765 solo está disponible un tipo de filtro, FLOW_CONTROL_FILTER. No se puede configurar para otros protocolos. Para cada ChannelID se pueden crear hasta 16 filtros FLOW_CONTROL_FILTER y hasta 10 filtros PASS_FILTER o BLOCK_FILTER. Para cada tipo de filtro seleccionado es necesario indicar los parámetros del filtro. Para FLOW_CONTROL_FILTER se indican tres parámetros pMaskMsg, pPatternMsg, pFlowControlMsg. Para PASS_FILTER o BLOCK_FILTER se indican dos parámetros pMaskMsg y pPatternMsg. La longitud de los parámetros puede ser de 1 a 12 bytes.
long PassThruStartMsgFilter(unsigned long ChannelID, unsigned long FilterType, PASSTHRU_MSG *pMaskMsg, PASSTHRU_MSG *pPatternMsg, PASSTHRU_MSG *pFlowControlMsg, unsigned long *FilterID)
| Nombre de la constante | Descripción |
|---|---|
| PASS_FILTER | Si se cumplen las condiciones del filtro definidas por sus parámetros, el mensaje se deja pasar. Este filtro no es válido para los protocolos ISO 15765. |
| BLOCK_FILTER | Si se cumplen las condiciones del filtro definidas por sus parámetros, el mensaje se bloquea. Este filtro no es válido para los protocolos ISO 15765. |
| FLOW_CONTROL_FILTER | Si se cumplen las condiciones del filtro definidas por sus parámetros, el mensaje se deja pasar. Este filtro es válido solo para los protocolos ISO 15765. |
| Código | Descripción | Posibles causas y soluciones |
|---|---|---|
| STATUS_NOERROR | La función se ejecutó correctamente | — |
| ERR_DEVICE_NOT_CONNECTED | No hay conexión con el adaptador |
|
| ERR_INVALID_DEVICE_ID | Identificador de dispositivo no válido |
|
| ERR_INVALID_CHANNEL_ID | Identificador de canal no válido |
|
| ERR_INVALID_MSG | Estructura de mensaje incorrecta |
|
| ERR_NULL_PARAMETER | Se pasó NULL en lugar de un puntero obligatorio |
|
| ERR_NOT_UNIQUE | El CAN ID ya se utiliza en otro FLOW_CONTROL_FILTER |
|
| ERR_EXCEEDED_LIMIT | Se superó el límite de filtros |
|
| ERR_MSG_PROTOCOL_ID | Incompatibilidad de protocolo |
|
| ERR_FAILED | Error indeterminado |
|
#include "j2534_lib.hpp"
// ... ChannelID obtenido de PassThruConnect ...
PASSTHRU_MSG MaskMsg, PatternMsg, FlowControlMsg;
unsigned long FilterID;
long Ret;
// Máscara: comparamos los primeros 4 bytes (CAN ID)
MaskMsg.ProtocolID = ISO15765;
MaskMsg.DataSize = 4;
memset(MaskMsg.Data, 0xFF, 4);
// Patrón: recibimos mensajes con CAN ID 0x7E8
PatternMsg.ProtocolID = ISO15765;
PatternMsg.DataSize = 4;
PatternMsg.Data[0] = 0x00;
PatternMsg.Data[1] = 0x00;
PatternMsg.Data[2] = 0x07;
PatternMsg.Data[3] = 0xE8;
// Respuesta FlowControl: enviamos al CAN ID 0x7E0
FlowControlMsg.ProtocolID = ISO15765;
FlowControlMsg.DataSize = 4;
FlowControlMsg.Data[0] = 0x00;
FlowControlMsg.Data[1] = 0x00;
FlowControlMsg.Data[2] = 0x07;
FlowControlMsg.Data[3] = 0xE0;
Ret = PassThruStartMsgFilter(ChannelID, FLOW_CONTROL_FILTER,
&MaskMsg, &PatternMsg, &FlowControlMsg, &FilterID);
if (Ret != STATUS_NOERROR)
{
// Tratamiento del error
}
// channelID obtenido anteriormente de ptConnect
val mask = PassThruMsg(
protocolID = ISO15765,
dataSize = 4,
txFlags = ISO15765_FRAME_PAD,
// Máscara para CAN ID (comparamos los 4 bytes)
data = byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte(), 0xFF.toByte())
)
val pattern = PassThruMsg(
protocolID = ISO15765,
dataSize = 4,
txFlags = ISO15765_FRAME_PAD,
// Recibimos respuestas de la ECU con CAN ID 0x7E8
data = byteArrayOf(0x00, 0x00, 0x07, 0xE8.toByte())
)
val flowControl = PassThruMsg(
protocolID = ISO15765,
dataSize = 4,
txFlags = ISO15765_FRAME_PAD,
// Enviamos FlowControl al CAN ID 0x7E0
data = byteArrayOf(0x00, 0x00, 0x07, 0xE0.toByte())
)
val resFilter = j2534.ptStartMsgFilter(channelID, FLOW_CONTROL_FILTER, mask, pattern, flowControl)
if (resFilter.status == STATUS_NOERROR) {
val filterID = resFilter.filterId
// Filtro configurado correctamente
Log.i("J2534", "Filtro FLOW_CONTROL_FILTER configurado, ID: $filterID")
} else {
// Tratamiento del error
Log.e("J2534", "Error al configurar el filtro: ${resFilter.status}")
}
from ctypes import *
# channelID obtenido anteriormente de PassThruConnect
# Creamos las estructuras de los mensajes
mask = PASSTHRU_MSG()
mask.ProtocolID = ISO15765
mask.DataSize = 4
mask.Data[0:4] = [0xFF, 0xFF, 0xFF, 0xFF]
pattern = PASSTHRU_MSG()
pattern.ProtocolID = ISO15765
pattern.DataSize = 4
pattern.Data[0:4] = [0x00, 0x00, 0x07, 0xE8]
flow_control = PASSTHRU_MSG()
flow_control.ProtocolID = ISO15765
flow_control.DataSize = 4
flow_control.Data[0:4] = [0x00, 0x00, 0x07, 0xE0]
filter_id = c_ulong()
ret = j2534.PassThruStartMsgFilter(
channel_id, FLOW_CONTROL_FILTER,
byref(mask), byref(pattern), byref(flow_control), byref(filter_id)
)
if ret == 0: # STATUS_NOERROR
print(f"Filtro configurado, ID: {filter_id.value}")
else:
print(f"Error: {ret}")
// channelID obtenido anteriormente de PassThruConnect
var mask = new PASSTHRU_MSG {
ProtocolID = ISO15765,
DataSize = 4,
Data = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }
};
var pattern = new PASSTHRU_MSG {
ProtocolID = ISO15765,
DataSize = 4,
Data = new byte[] { 0x00, 0x00, 0x07, 0xE8 }
};
var flowControl = new PASSTHRU_MSG {
ProtocolID = ISO15765,
DataSize = 4,
Data = new byte[] { 0x00, 0x00, 0x07, 0xE0 }
};
uint filterId;
int ret = J2534.PassThruStartMsgFilter(
channelId, FLOW_CONTROL_FILTER,
ref mask, ref pattern, ref flowControl, out filterId
);
if (ret == 0) // STATUS_NOERROR
{
Console.WriteLine($"Filtro configurado, ID: {filterId}");
}
#include "j2534_lib.hpp"
// ... ChannelID obtenido de PassThruConnect ...
PASSTHRU_MSG MaskMsg, PatternMsg;
unsigned long FilterID;
long Ret;
// Máscara: comparamos el primer byte (formato)
MaskMsg.ProtocolID = ISO14230;
MaskMsg.DataSize = 1;
MaskMsg.Data[0] = 0x80;
// Patrón: dejamos pasar todos los mensajes con el bit de formato = 1
PatternMsg.ProtocolID = ISO14230;
PatternMsg.DataSize = 1;
PatternMsg.Data[0] = 0x80;
Ret = PassThruStartMsgFilter(ChannelID, PASS_FILTER, &MaskMsg, &PatternMsg, NULL, &FilterID);
if (Ret != STATUS_NOERROR)
{
// Tratamiento del error
}