panda/boardesp/elm327.c

35 lines
831 B
C
Raw Normal View History

2017-04-07 09:11:36 +08:00
#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);
}