mirror of https://github.com/commaai/panda.git
35 lines
831 B
C
35 lines
831 B
C
|
#include "ets_sys.h"
|
||
|
#include "osapi.h"
|
||
|
#include "gpio.h"
|
||
|
#include "os_type.h"
|
||
|
#include "user_interface.h"
|
||
|
#include "espconn.h"
|
||
|
|
||
|
#include "driver/uart.h"
|
||
|
|
||
|
#define ELM_PORT 35000
|
||
|
|
||
|
static struct espconn elm_conn;
|
||
|
static esp_tcp elm_proto;
|
||
|
|
||
|
static void ICACHE_FLASH_ATTR elm_rx_cb(void *arg, char *data, uint16_t len) {
|
||
|
uart0_tx_buffer(data, len);
|
||
|
}
|
||
|
|
||
|
void ICACHE_FLASH_ATTR elm_tcp_connect_cb(void *arg) {
|
||
|
struct espconn *conn = (struct espconn *)arg;
|
||
|
espconn_set_opt(&elm_conn, ESPCONN_NODELAY);
|
||
|
espconn_regist_recvcb(conn, elm_rx_cb);
|
||
|
}
|
||
|
|
||
|
void ICACHE_FLASH_ATTR elm327_init() {
|
||
|
// control listener
|
||
|
elm_proto.local_port = ELM_PORT;
|
||
|
elm_conn.type = ESPCONN_TCP;
|
||
|
elm_conn.state = ESPCONN_NONE;
|
||
|
elm_conn.proto.tcp = &elm_proto;
|
||
|
espconn_regist_connectcb(&elm_conn, elm_tcp_connect_cb);
|
||
|
espconn_accept(&elm_conn);
|
||
|
}
|
||
|
|