blob: 37877c602317121ae8948f9f0b02e779ca1babd6 [file] [log] [blame]
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.automotive.can@1.0;
/**
* CAN message ID.
*
* Does not include any flags like RTR nor ERR, only a plain 11-bit
* or 29-bit identifier, as defined in CAN 1.x/2.0x.
*
* Unused bits must be set to zero.
*/
typedef uint32_t CanMessageId;
/**
* CAN message being sent or received.
*/
struct CanMessage {
CanMessageId id;
/**
* CAN message payload, as defined in CAN 1.x and CAN 2.x standards.
*
* The length of the payload vector directly translates to the length
* of the data frame (i.e. includes any padding bytes), so it may be in
* a range of:
* - 0-8 bytes for standard CAN;
* - up to 64 bytes for CAN FD.
* ISO TP is not supported directly for now.
*/
vec<uint8_t> payload;
/**
* Time in nanoseconds since boot.
*
* Ignored for outgoing messages.
*/
uint64_t timestamp;
/**
* A request to proactively pull certain data from other ECU in CAN network.
*
* For details please refer to CAN standard.
*
* If this flag is set, payload must be empty.
*/
bool remoteTransmissionRequest;
};
/**
* Single filter rule for CAN messages.
*
* A filter is satisfied if:
* ((receivedId & mask) == (id & mask)) == !inverted
*
* In order for set of filters to match, at least one non-inverted filters must match (if there is
* one) and all inverted filters must match. In other words:
* - a single matching non-inverted filter makes the whole set matching;
* - a single non-matching inverted filter makes the whole set non-matching.
*/
struct CanMessageFilter {
CanMessageId id;
uint32_t mask;
bool inverted;
};
enum Result : uint8_t {
OK,
UNKNOWN_ERROR,
PAYLOAD_TOO_LONG,
INTERFACE_DOWN,
TRANSMISSION_FAILURE,
INVALID_ARGUMENTS,
};
/**
* @see ICanMessageListener#onError
*/
enum ErrorEvent : uint8_t {
UNKNOWN_ERROR,
/** A problem with CAN interface HW. */
HARDWARE_ERROR,
/** TX buffer overflow: client is sending too many packets. */
TX_OVERFLOW,
/** RX buffer overflow: client is not reading packets fast enough. */
RX_OVERFLOW,
/** Received malformed input. */
MALFORMED_INPUT,
/** Bus overload: there is too much traffic on the bus. */
BUS_OVERLOAD,
/** Bus error: shorted Hi/Lo line, bus off etc. */
BUS_ERROR,
};