001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package org.wpilib.hardware.hal.can; 006 007/** Represents a CAN message read from a stream. */ 008public class CANStreamMessage { 009 /** The message data. */ 010 public final byte[] data = new byte[64]; 011 012 /** The length of the data received (0-64 bytes). */ 013 public int length; 014 015 /** The flags of the message. */ 016 public int flags; 017 018 /** Timestamp message was received, in milliseconds (based off of CLOCK_MONOTONIC). */ 019 public long timestamp; 020 021 /** The message ID. */ 022 public int messageId; 023 024 /** Default constructor. */ 025 public CANStreamMessage() {} 026 027 /** 028 * API used from JNI to set the data. 029 * 030 * @param length Length of packet in bytes. 031 * @param messageId CAN message ID of the message. 032 * @param flags Message flags. 033 * @param timestamp CAN frame timestamp in microseconds. 034 * @return Buffer containing CAN frame. 035 */ 036 @SuppressWarnings("PMD.MethodReturnsInternalArray") 037 public byte[] setStreamData(int length, int flags, int messageId, long timestamp) { 038 this.messageId = messageId; 039 this.flags = flags; 040 this.length = length; 041 this.timestamp = timestamp; 042 return data; 043 } 044}