#ifndef PKTLOG_H_INCLUDED
#define PKTLOG_H_INCLUDED

#include <stdint.h>

#include "kernel.h"

// Capture of packets that carry more than the pad's report, for drivers with
// a data validator (the Xbox 360 wireless receiver). See doc.Rumble.

#define PKTLOG_BYTES   32   // most bytes kept per packet

// Called from the upcall handler for each packet read from a slot, with the
// whole packet (up to PKTLOG_BYTES). Packets the validator rejected are kept
// when they differ from the last one rejected; valid packets are kept when
// anything outside the report body [body_start, body_start + body_len)
// differs from the last one kept. Only OS_AddCallBack is used, so this is
// safe in the handler.
void pktlog_note(uint32_t slot, const uint8_t *data, uint32_t len, int valid, uint32_t body_start, uint32_t body_len);

// Print up to max of the slot's most recent kept packets, oldest first, for
// *USBJoystick_Debug; returns how many non-input packets the slot has sent.
uint32_t pktlog_print(uint32_t slot, uint32_t max);

// Forget a slot's history (device removed).
void pktlog_reset(uint32_t slot);

// Module dying: cancel the Reporter callback.
void pktlog_shutdown(void);

// Sends new kept packets to Reporter (CMHG generic veneer).
_kernel_oserror *pktlog_callback_handler(_kernel_swi_regs *r, void *pw);

#endif
