import asyncio
from gateway import Gateway

async def emit_heartbeats(gateway: Gateway) -> None:
    while True:
        await gateway.send_message(
            target_id=0,
            sender_id=27,
            protocol=0,
            payload=bytes(8),
        )
        await asyncio.sleep(2)


async def main() -> None:
    gateway = Gateway(channel="can0")

    try:
        gateway.start_receiving()
        print("Listening for CAN packets...")
        # The notifier logs incoming packets while this task sends heartbeats.
        await emit_heartbeats(gateway)
    finally:
        gateway.shutdown()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass
