mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-14 19:44:05 +08:00
a6a2693a1c
* add timeout to wait_for_ack * fix ignition edge detection race condition * local_ignition -> ignition_local * gate power_save on !pigeon_active * millis_since_boot Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 21c4bfc7bedb94cce93c7e2311154e4915db9ad5
50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <termios.h>
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
|
|
#include "selfdrive/boardd/panda.h"
|
|
|
|
class Pigeon {
|
|
public:
|
|
static Pigeon* connect(Panda * p);
|
|
static Pigeon* connect(const char * tty);
|
|
virtual ~Pigeon(){};
|
|
|
|
void init();
|
|
void stop();
|
|
bool wait_for_ack();
|
|
bool wait_for_ack(const std::string &ack, const std::string &nack, int timeout_ms = 1000);
|
|
bool send_with_ack(const std::string &cmd);
|
|
virtual void set_baud(int baud) = 0;
|
|
virtual void send(const std::string &s) = 0;
|
|
virtual std::string receive() = 0;
|
|
virtual void set_power(bool power) = 0;
|
|
};
|
|
|
|
class PandaPigeon : public Pigeon {
|
|
Panda * panda = NULL;
|
|
public:
|
|
~PandaPigeon();
|
|
void connect(Panda * p);
|
|
void set_baud(int baud);
|
|
void send(const std::string &s);
|
|
std::string receive();
|
|
void set_power(bool power);
|
|
};
|
|
|
|
|
|
class TTYPigeon : public Pigeon {
|
|
int pigeon_tty_fd = -1;
|
|
struct termios pigeon_tty;
|
|
public:
|
|
~TTYPigeon();
|
|
void connect(const char* tty);
|
|
void set_baud(int baud);
|
|
void send(const std::string &s);
|
|
std::string receive();
|
|
void set_power(bool power);
|
|
};
|