10 changed files with 280 additions and 51 deletions
-
50app/MDK-ARM/app.uvguix.29643
-
46app/MDK-ARM/app.uvoptx
-
17app/MDK-ARM/app.uvprojx
-
122src/config.c
-
21src/config.h
-
3src/port.c
-
0src/protocol.c
-
60src/protocol.h
-
9src/usermain.c
-
3src/zboard.h
50
app/MDK-ARM/app.uvguix.29643
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,122 @@ |
|||
#include "config.h" |
|||
|
|||
#include "../app/Middlewares/Third_Party/LwIP/src/include/lwip/inet.h" |
|||
#include "../iflytop_microcontroller/sdk/stm32/stm32sdk.h" |
|||
#include "lwip.h" |
|||
#include "protocol.h" |
|||
#include "zboard.h" |
|||
|
|||
#define TAG "CONFIG" |
|||
|
|||
static config_t s_config; |
|||
|
|||
// static nvs_handle s_nvs_handle; // NVS是esp32中的,相当于flash |
|||
static bool s_is_first_init = false; |
|||
|
|||
typedef int8_t i8; |
|||
typedef uint8_t u8; |
|||
typedef int16_t i16; |
|||
typedef uint16_t u16; |
|||
typedef int32_t i32; |
|||
typedef uint32_t u32; |
|||
typedef int64_t i64; |
|||
typedef uint64_t u64; |
|||
|
|||
// #define INIT_CONFIG(type, name, markname) \ |
|||
// type name = 0; \ |
|||
// err = nvs_get_##type(s_nvs_handle, markname, &name); \ |
|||
// if (err == ESP_OK && !refresh_config) { \ |
|||
// s_config.name = name; \ |
|||
// } else { \ |
|||
// s_is_first_init = true; \ |
|||
// ESP_LOGI(TAG, "reconfig config %s", #name); \ |
|||
// err = nvs_set_##type(s_nvs_handle, markname, s_config.name); \ |
|||
// if (err != ESP_OK) { \ |
|||
// ESP_LOGE(TAG, "nvs set %s fail,error %d", #name, err); \ |
|||
// } \ |
|||
// } |
|||
|
|||
// #define UPDATE_CONFIG(type, name, markname) \ |
|||
// type name = 0; \ |
|||
// err = nvs_get_##type(s_nvs_handle, markname, &name); \ |
|||
// if (err == ESP_OK) { \ |
|||
// if (s_config.name != name) { \ |
|||
// err = nvs_set_##type(s_nvs_handle, markname, s_config.name); \ |
|||
// if (err != ESP_OK) { \ |
|||
// ESP_LOGE(TAG, "nvs set %s fail,error %d", #name, err); \ |
|||
// } else { \ |
|||
// ESP_LOGI(TAG, "update config %s -> %d", #name, s_config.name); \ |
|||
// } \ |
|||
// } \ |
|||
// } else { \ |
|||
// ESP_LOGE(TAG, "nvs_get %s fail %d", #name, err); \ |
|||
// } |
|||
|
|||
void config_init() { |
|||
#if 1 |
|||
IP4_ADDR((ip4_addr_t *)&s_config.ip, 192, 168, 1, 10); |
|||
IP4_ADDR((ip4_addr_t *)&s_config.gw, 192, 168, 1, 1); |
|||
IP4_ADDR((ip4_addr_t *)&s_config.netmask, 255, 255, 255, 0); |
|||
s_config.localport = SERVICE_PORT; |
|||
s_config.obtaining_ip_mode = OBTAINING_IP_MODE_DHCP; // dhcp |
|||
s_config.mask = 1; // |
|||
|
|||
#endif |
|||
|
|||
// esp_err_t err = nvs_flash_init(); |
|||
|
|||
// if (err == ESP_ERR_NVS_NO_FREE_PAGES) { |
|||
// ESP_ERROR_CHECK(nvs_flash_erase()); |
|||
// err = nvs_flash_init(); |
|||
// } |
|||
|
|||
// if (err != ESP_ERR_NVS_NO_FREE_PAGES) { |
|||
// esp_err_t err = nvs_open("app_config", NVS_READWRITE, &s_nvs_handle); |
|||
// if (err == ESP_OK) { |
|||
// bool refresh_config = false; |
|||
// INIT_CONFIG(u32, ip, "ip"); |
|||
// INIT_CONFIG(u32, gw, "gw"); |
|||
// INIT_CONFIG(u32, netmask, "netmask"); |
|||
// INIT_CONFIG(u32, localport, "localport"); |
|||
// INIT_CONFIG(u32, sound_report_times, "srt"); |
|||
// INIT_CONFIG(u32, obtaining_ip_mode, "oim"); |
|||
// INIT_CONFIG(u32, sound_magnification_factors, "smf"); |
|||
// } else { |
|||
// } |
|||
|
|||
// } else { |
|||
// ESP_LOGE(TAG, "nvs flash init fail %d", err); |
|||
// } |
|||
// nvs_close(s_nvs_handle); |
|||
|
|||
/*dumpconfig*/ |
|||
config_dump_config(); |
|||
} |
|||
bool config_is_first_init() { return s_is_first_init; } |
|||
void config_dump_config() { |
|||
ZLOGI(TAG, "=================config================"); |
|||
ZLOGI(TAG, "= config obtaining_ip_mode %u", s_config.obtaining_ip_mode); |
|||
ZLOGI(TAG, "= config ip %s", inet_ntoa(s_config.ip)); |
|||
ZLOGI(TAG, "= config gw: %s", inet_ntoa(s_config.gw)); |
|||
ZLOGI(TAG, "= config netmask: %s", inet_ntoa(s_config.netmask)); |
|||
ZLOGI(TAG, "= config localport: %u", s_config.localport); |
|||
} |
|||
// void config_update() { |
|||
// esp_err_t err = nvs_open("app_config", NVS_READWRITE, &s_nvs_handle); |
|||
// if (err == ESP_OK) { |
|||
// UPDATE_CONFIG(u32, ip, "ip"); |
|||
// UPDATE_CONFIG(u32, gw, "gw"); |
|||
// UPDATE_CONFIG(u32, netmask, "netmask"); |
|||
// UPDATE_CONFIG(u32, localport, "localport"); |
|||
// UPDATE_CONFIG(u32, sound_report_times, "srt"); |
|||
// UPDATE_CONFIG(u32, obtaining_ip_mode, "oim"); |
|||
// UPDATE_CONFIG(u32, sound_magnification_factors, "smf"); |
|||
|
|||
// } else { |
|||
// } |
|||
|
|||
// nvs_close(s_nvs_handle); |
|||
|
|||
// config_dump_config(); |
|||
// } |
|||
config_t *config_get() { return &s_config; } |
@ -0,0 +1,21 @@ |
|||
#pragma once |
|||
#include <stdint.h> |
|||
#include <stdbool.h> |
|||
typedef struct { |
|||
|
|||
uint32_t mask; |
|||
uint32_t obtaining_ip_mode; |
|||
|
|||
uint32_t ip; |
|||
uint32_t gw; |
|||
uint32_t netmask; |
|||
uint32_t localport; |
|||
|
|||
// uint32_t |
|||
} config_t; |
|||
|
|||
void config_init(); |
|||
void config_update(); |
|||
void config_dump_config(); |
|||
config_t *config_get(); |
|||
bool config_is_first_init() ; |
@ -0,0 +1,60 @@ |
|||
#pragma once |
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
#pragma pack(push, 1) |
|||
typedef struct { |
|||
|
|||
uint8_t packet_type; |
|||
uint8_t minus_packet_type; |
|||
|
|||
uint8_t index; |
|||
uint8_t action_type; |
|||
uint32_t reg; |
|||
|
|||
union { |
|||
uint32_t regvalue; |
|||
uint8_t url[200]; //这里仅仅是一个占位符 |
|||
struct { |
|||
uint32_t regvalue; |
|||
uint32_t error; |
|||
} receipt; |
|||
} value; |
|||
} protocol_header_t; |
|||
#pragma pack(pop) |
|||
|
|||
#define PROTOCOL_HEADER 0xAA |
|||
#define PROTOCOL_HEADER_MINUS 0x55 |
|||
|
|||
#define PROTOCOL_PACKET_TYPE_READ 1 |
|||
#define PROTOCOL_PACKET_TYPE_WRITE 0 |
|||
|
|||
/** |
|||
* @brief |
|||
*/ |
|||
|
|||
/** |
|||
* @brief REG |
|||
*/ |
|||
#define REG_RESTART_DEVICE 0 |
|||
#define REG_REPORT_VOICE 1 |
|||
#define REG_REPORT_VOICE_REPECT_TIMES 2 |
|||
#define REG_OBTAINING_IP_MODE 3 |
|||
#define REG_STATIC_IP 4 |
|||
#define REG_IP_MASK 5 |
|||
#define REG_ROUTER_IP 6 |
|||
#define REG_SOUND_AMPLIFY_FACTOR 10 |
|||
|
|||
#define REG_INTER_OTA_BY_HTTP 102 |
|||
|
|||
#define OBTAINING_IP_MODE_DHCP 0 |
|||
#define OBTAINING_IP_MODE_STATIC 1 |
|||
|
|||
/** |
|||
* @brief ERRORCODE |
|||
* 错误码在遇到位置错误时,直接将ESP32返回的错误上报给上位机 |
|||
*/ |
|||
|
|||
#define ERROR_CODE_SUCCESS 0 |
|||
#define ERROR_CODE_PACKET_PARAMETER_ERROR 7301 |
|||
// #define ERROR_CODE_SUM_CHECK_ERROR 7301 |
|||
// #define ERROR_CODE_PACKET_PATTERN_ERROR 7301 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue