Browse Source

add beginning of gps code plus other tweaks

ugv_io
Alex Mikhalev 6 years ago
parent
commit
ee1525ee74
  1. 2
      main/u8g2_esp32_hal.c
  2. 67
      main/ugv_main.c

2
main/u8g2_esp32_hal.c

@ -10,7 +10,7 @@
#include "u8g2_esp32_hal.h" #include "u8g2_esp32_hal.h"
static const char * TAG = "u8g2_hal"; static const char * TAG = "u8g2_hal";
static const unsigned int I2C_TIMEOUT_MS = 10; static const unsigned int I2C_TIMEOUT_MS = 100;
static spi_device_handle_t handle_spi; // SPI handle. static spi_device_handle_t handle_spi; // SPI handle.
static i2c_cmd_handle_t handle_i2c; // I2C handle. static i2c_cmd_handle_t handle_i2c; // I2C handle.

67
main/ugv_main.c

@ -12,11 +12,8 @@
const char *TAG = "uas-ugv"; const char *TAG = "uas-ugv";
// U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, 16, 15, 4);
u8g2_t u8g2; u8g2_t u8g2;
// SPIClass lora_spi(VSPI);
#define LORA_SCK 5 #define LORA_SCK 5
#define LORA_MISO 19 #define LORA_MISO 19
#define LORA_MOSI 27 #define LORA_MOSI 27
@ -56,9 +53,69 @@ void setup_oled(void) {
u8g2_SetPowerSave(&u8g2, false); u8g2_SetPowerSave(&u8g2, false);
} }
#define GPS_UART UART_NUM_1
const size_t GPS_BUF_SIZE = 1024;
const char NMEA_OUTPUT_RMCGGA[] =
"$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n";
const char NMEA_SET_UPDATE_1HZ[] = "$PMTK220,1000*1F\r\n";
const char NMEA_Q_RELEASE[] = "$PMTK605*31\r\n";
static void gps_task(void *arg) {
ESP_LOGI(TAG, "gps_task start");
uint8_t * data = malloc(GPS_BUF_SIZE);
size_t read_bytes;
esp_err_t ret;
uart_write_bytes(GPS_UART, NMEA_OUTPUT_RMCGGA, sizeof(NMEA_OUTPUT_RMCGGA));
ret = uart_wait_tx_done(GPS_UART, 1000);
ESP_LOGI(TAG, "sent output rmc and gga: %d", ret);
uart_write_bytes(GPS_UART, NMEA_SET_UPDATE_1HZ, sizeof(NMEA_SET_UPDATE_1HZ));
ret = uart_wait_tx_done(GPS_UART, 1000);
ESP_LOGI(TAG, "sent update 1hz: %d", ret);
vTaskDelay(pdMS_TO_TICKS(100));
uart_write_bytes(GPS_UART, NMEA_Q_RELEASE, sizeof(NMEA_Q_RELEASE));
ret = uart_wait_tx_done(GPS_UART, 1000);
ESP_LOGI(TAG, "sent q release: %d", ret);
while (true) {
read_bytes =
uart_read_bytes(GPS_UART, data, GPS_BUF_SIZE, pdMS_TO_TICKS(100));
if (read_bytes > 0) {
ESP_LOGI(TAG, "gps data: %.*s", read_bytes, data);
}
}
}
void setup_gps(void) {
uart_config_t gps_uart_config;
// gps_uart_config.baud_rate = 9600;
gps_uart_config.baud_rate = 57600;
gps_uart_config.data_bits = UART_DATA_8_BITS;
gps_uart_config.parity = UART_PARITY_DISABLE;
gps_uart_config.stop_bits = UART_STOP_BITS_1;
gps_uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
gps_uart_config.rx_flow_ctrl_thresh = 122;
gps_uart_config.use_ref_tick = false;
ret = uart_param_config(GPS_UART, &gps_uart_config);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "uart_param_config: %d", ret);
return;
}
uart_set_pin(GPS_UART, 17, 23, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
ret = uart_driver_install(GPS_UART, 1024, 0, 8, NULL, 0);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "uart_driver_install: %d", ret);
return;
}
ESP_LOGI(TAG, "gps uart configured");
xTaskCreate(&gps_task, "gps_task", 2 * 1024, NULL, 1, NULL);
}
void setup(void) { void setup(void) {
ESP_LOGI(TAG, "setup"); ESP_LOGI(TAG, "setup");
esp_err_t ret;
setup_gps();
setup_oled(); setup_oled();
sx127x_config_t lora_config = SX127X_CONFIG_DEFAULT; sx127x_config_t lora_config = SX127X_CONFIG_DEFAULT;
@ -68,7 +125,7 @@ void setup(void) {
lora_config.sync_word = 0x34; lora_config.sync_word = 0x34;
lora_config.crc = SX127X_CRC_ENABLED; lora_config.crc = SX127X_CRC_ENABLED;
esp_err_t ret = sx127x_init(&lora_config, &lora); ret = sx127x_init(&lora_config, &lora);
if (ret != ESP_OK) { if (ret != ESP_OK) {
const char *err_name = esp_err_to_name(ret); const char *err_name = esp_err_to_name(ret);
ESP_LOGE(TAG, "LoRa init failed: %s", err_name); ESP_LOGE(TAG, "LoRa init failed: %s", err_name);
@ -91,7 +148,7 @@ void setup(void) {
void loraTask(void *params) { void loraTask(void *params) {
char tx_buf[20]; char tx_buf[20];
const size_t tx_buf_len = (sizeof(tx_buf) / sizeof(tx_buf[0])); const size_t tx_buf_len = (sizeof(tx_buf) / sizeof(tx_buf[0]));
TickType_t send_period = pdMS_TO_TICKS(1000); TickType_t send_period = pdMS_TO_TICKS(2000);
TickType_t current_time = xTaskGetTickCount(); TickType_t current_time = xTaskGetTickCount();
TickType_t next_send = current_time + send_period; TickType_t next_send = current_time + send_period;
while (true) { while (true) {

Loading…
Cancel
Save