Skip to content

Commit

Permalink
Merge branch 'idf5'
Browse files Browse the repository at this point in the history
  • Loading branch information
meatpiHQ committed Sep 30, 2023
2 parents 1977cac + 8fef5c5 commit f76bb54
Show file tree
Hide file tree
Showing 18 changed files with 2,410 additions and 823 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"idf.adapterTargetName": "esp32c3",
"idf.portWin": "COM14",
"idf.flashType": "UART",
"files.associations": {
"ftp.h": "c"
}
}
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
cmake_minimum_required(VERSION 3.5)


set(PROJECT_PREF "wican-fw")
set(PROJECT_VER "v180_hv300")
# set(PROJECT_PREF "wican-fw")
# set(PROJECT_VER "v250_hv300")
#set(PROJECT_VER "v155_hv210")

#set(PROJECT_PREF "wican-fw-usb")
#set(PROJECT_VER "v180_hv150")
set(PROJECT_PREF "wican-fw-usb")
set(PROJECT_VER "v250_hv150")

set(PROJECT_VERU ${PROJECT_VER})
set(PROJECT_BIN "${PROJECT_PREF}_${PROJECT_VERU}")
Expand Down
19 changes: 11 additions & 8 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES )

set(COMPONENT_SRCS "main.c" "comm_server.c" "config_server.c" "realdash.c" "slcan.c" "can.c" "ble.c" "wifi_network.c" "gvret.c" "sleep_mode.c" "wc_uart.c" "elm327.c" "mqtt.c")
set(COMPONENT_ADD_INCLUDEDIRS "")

register_component()
# See the build system documentation in IDF programming guide
# for more information about component CMakeLists.txt files.
set(srcs "main.c" "comm_server.c" "config_server.c" "realdash.c" "slcan.c" "can.c" "ble.c" "wifi_network.c" "gvret.c" "wc_uart.c" "elm327.c" "mqtt.c" "sleep_mode.c" "ftp.c")
set(requires esp_timer esp_wifi nvs_flash fatfs vfs driver esp-tls esp_adc esp_eth log app_update esp_http_server bt spiffs freertos mqtt json)
idf_component_register(
SRCS "ftp.c" "${srcs}" # list the source files of this component
INCLUDE_DIRS # optional, add here public include directories
PRIV_INCLUDE_DIRS # optional, add here private include directories
REQUIRES "${requires}" # optional, list the public requirements (component names)
PRIV_REQUIRES # optional, list the private requirements
)
10 changes: 5 additions & 5 deletions main/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"

#include "esp_timer.h"
#include "esp_bt.h"

#include "esp_gap_ble_api.h"
Expand Down Expand Up @@ -105,7 +105,7 @@ static esp_ble_adv_params_t heart_rate_adv_params = {
.adv_int_min = 0x100,
.adv_int_max = 0x100,
.adv_type = ADV_TYPE_IND,
.own_addr_type = BLE_ADDR_TYPE_RANDOM,
.own_addr_type = BLE_ADDR_TYPE_RPA_PUBLIC,
.channel_map = ADV_CHNL_ALL,
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
Expand Down Expand Up @@ -411,7 +411,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
/* The app will receive this evt when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
show the passkey number to the user to confirm it with the number displayed by peer device. */
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, true);
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_NC_REQ_EVT, the passkey Notify number:%d", param->ble_security.key_notif.passkey);
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_NC_REQ_EVT, the passkey Notify number:%" PRIu32, param->ble_security.key_notif.passkey);
break;
case ESP_GAP_BLE_SEC_REQ_EVT:
/* send the positive(true) security response to the peer device to accept the security request.
Expand All @@ -420,7 +420,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
break;
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: ///the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
///show the passkey number to the user to input it in the peer device.
ESP_LOGI(GATTS_TABLE_TAG, "The passkey Notify number:%06d", param->ble_security.key_notif.passkey);
ESP_LOGI(GATTS_TABLE_TAG, "The passkey Notify number:%" PRIu32, param->ble_security.key_notif.passkey);
break;
case ESP_GAP_BLE_KEY_EVT:
//shows the ble key info share with peer device to the user.
Expand Down Expand Up @@ -812,7 +812,7 @@ void ble_init(QueueHandle_t *xTXp_Queue, QueueHandle_t *xRXp_Queue, uint8_t conn
strcpy((char*)dev_name, (char*)uid);
conn_led = connected_led;
ble_pass_key = passkey;
ESP_LOGW(GATTS_TABLE_TAG, "ble passkey: %d", ble_pass_key);
ESP_LOGW(GATTS_TABLE_TAG, "ble passkey: %lu", ble_pass_key);
}

if(xBle_TX_Queue == NULL)
Expand Down
2 changes: 1 addition & 1 deletion main/comm_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void tcp_server_task(void *pvParameters)
ESP_LOGE(TAG, "IPPROTO: %d", addr_family);
goto CLEAN_UP;
}
ESP_LOGI(TAG, "Socket bound, port %d", server_port);
ESP_LOGI(TAG, "Socket bound, port %lu", server_port);

if(!udp_enable)
{
Expand Down
119 changes: 111 additions & 8 deletions main/config_server.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main/config_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ char *config_server_get_mqtt_url(void);
int32_t config_server_get_mqtt_port(void);
char *config_server_get_mqtt_user(void);
char *config_server_get_mmqtt_pass(void);
char *config_server_get_mqtt_canflt(void);
15 changes: 8 additions & 7 deletions main/elm327.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <ctype.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_timer.h"
#include "esp_event.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
Expand Down Expand Up @@ -461,7 +462,7 @@ static char* elm327_set_timeout(const char* command_str)
elm327_config.req_timeout = 0x32;
}

ESP_LOGI(TAG, "elm327_config.req_timeout: %d", elm327_config.req_timeout);
ESP_LOGI(TAG, "elm327_config.req_timeout: %lu", elm327_config.req_timeout);

return (char*)ok_str;
}
Expand Down Expand Up @@ -522,7 +523,7 @@ static char* elm327_input_voltage(const char* command_str)
}
else
{
sprintf(volt, "%.1f",0);
sprintf(volt, "%.1f",0.0f);
}
return (char*)volt;
}
Expand Down Expand Up @@ -852,11 +853,11 @@ static int8_t elm327_request(char *cmd, char *rsp, QueueHandle_t *queue)
{
if(rx_frame.extd == 0)
{
sprintf((char*)rsp, "%03X%02X", rx_frame.identifier&0xFFF,rx_frame.data[0]);
sprintf((char*)rsp, "%03lX%02X", rx_frame.identifier&0xFFF,rx_frame.data[0]);
}
else
{
sprintf((char*)rsp, "%08X%02X", rx_frame.identifier&TWAI_EXTD_ID_MASK,rx_frame.data[0]);
sprintf((char*)rsp, "%08lX%02X", rx_frame.identifier&TWAI_EXTD_ID_MASK,rx_frame.data[0]);
}

}
Expand Down Expand Up @@ -891,7 +892,7 @@ static int8_t elm327_request(char *cmd, char *rsp, QueueHandle_t *queue)
else
{
xwait_time -= (((esp_timer_get_time() - txtime)/1000)/portTICK_PERIOD_MS);
ESP_LOGI(TAG, "xwait_time: %d", xwait_time);
ESP_LOGI(TAG, "xwait_time: %lu" , xwait_time);
if(xwait_time > (elm327_config.req_timeout*4.096))
{
xwait_time = 0;
Expand All @@ -905,7 +906,7 @@ static int8_t elm327_request(char *cmd, char *rsp, QueueHandle_t *queue)
}
}

ESP_LOGW(TAG, "Response time: %u", (uint32_t)((esp_timer_get_time() - txtime)/1000));
ESP_LOGW(TAG, "Response time: %" PRIu32, (uint32_t)((esp_timer_get_time() - txtime)/1000));

if(rsp_found == 0)
{
Expand Down
6 changes: 3 additions & 3 deletions main/gvret.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ void gvert_tmr_set_start(void)
xSemaphoreGive(xgvert_tmr_semaphore);
}

uint32_t gvert_tmr_get()
int64_t gvert_tmr_get()
{
int64_t ret = 0;
xSemaphoreTake(xgvert_tmr_semaphore, portMAX_DELAY);
ret = esp_timer_get_time() - gvert_tmr_start_time;
xSemaphoreGive(xgvert_tmr_semaphore);

return (uint32_t)ret;
return (int64_t)ret;
}

static void periodic_timer_callback(void* arg)
Expand All @@ -93,7 +93,7 @@ uint8_t checksumCalc(uint8_t *buffer, int length)
void gvert_setup(EEPROMSettings *settings)
{
can_disable();
ESP_LOGI(__func__, "settings->CAN0Speed: %u", settings->CAN0Speed);
ESP_LOGI(__func__, "settings->CAN0Speed: %lu", settings->CAN0Speed);
for(uint8_t i = 0; i < sizeof(can_speed)/sizeof(uint32_t); i++)
{
if(can_speed[i] == settings->CAN0Speed)
Expand Down
17 changes: 8 additions & 9 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
Expand All @@ -29,6 +29,7 @@
#include "driver/gpio.h"
#include "esp_log.h"
#include <string.h>
#include "esp_timer.h"
#include "comm_server.h"
#include "lwip/sockets.h"
#include "driver/twai.h"
Expand All @@ -49,6 +50,8 @@
#include "wc_uart.h"
#include "elm327.h"
#include "mqtt.h"
#include "esp_mac.h"
#include "ftp.h"

#define TAG __func__
#define TX_GPIO_NUM 0
Expand Down Expand Up @@ -218,9 +221,9 @@ static void can_rx_task(void *pvParameters)
process_led(0);
if(esp_timer_get_time() - time_old > 1000*1000)
{
uint32_t free_heap = heap_caps_get_free_size(HEAP_CAPS);
time_old = esp_timer_get_time();
ESP_LOGI(TAG, "free_heap: %u", free_heap);
// uint32_t free_heap = heap_caps_get_free_size(HEAP_CAPS);
// time_old = esp_timer_get_time();
// ESP_LOGI(TAG, "free_heap: %lu", free_heap);
// ESP_LOGI(TAG, "msg %u/sec", num_msg);
// num_msg = 0;
}
Expand Down Expand Up @@ -496,11 +499,7 @@ void app_main(void)

gpio_set_level(PWR_LED_GPIO_NUM, 1);
esp_ota_mark_app_valid_cancel_rollback();
// while(1)
// {
// ESP_LOGI(TAG, "free heap : %d", xPortGetFreeHeapSize());
// vTaskDelay(pdMS_TO_TICKS(2000));
// }

esp_log_level_set("*", ESP_LOG_NONE);
}

Loading

0 comments on commit f76bb54

Please sign in to comment.