Initial commit.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
commit
53509e30ba
|
@ -0,0 +1,3 @@
|
|||
[submodule "lib/nanopb"]
|
||||
path = lib/nanopb
|
||||
url = https://github.com/nanopb/nanopb.git
|
|
@ -0,0 +1,23 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(esp_nano_hosted)
|
||||
|
||||
set(NH_SOURCES
|
||||
"proto/esp_hosted_config.pb.c"
|
||||
"src/nh_ctrl_api.c"
|
||||
)
|
||||
|
||||
set(NH_INCLUDES
|
||||
"include"
|
||||
"proto"
|
||||
)
|
||||
|
||||
set(NH_LIBS
|
||||
"protobuf-nanopb-static"
|
||||
)
|
||||
|
||||
add_subdirectory(lib/nanopb)
|
||||
|
||||
add_library(${PROJECT_NAME} ${NH_SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${NH_INCLUDES})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${NH_LIBS})
|
|
@ -0,0 +1,73 @@
|
|||
#ifndef NH_CTRL_API_H
|
||||
#define NH_CTRL_API_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
NH_RET_SUCCESS = 0,
|
||||
NH_RET_FAIL = 1,
|
||||
NH_RET_TIMEOUT = 2,
|
||||
} nh_ret_t;
|
||||
|
||||
/* OSA */
|
||||
typedef void *nh_osa_semaphore_t;
|
||||
typedef nh_ret_t (*nh_osa_semaphore_create_t)(void *handle, nh_osa_semaphore_t *sem);
|
||||
typedef nh_ret_t (*nh_osa_semaphore_take_t)(void *handle, nh_osa_semaphore_t sem, uint32_t timeout_msec);
|
||||
typedef nh_ret_t (*nh_osa_semaphore_give_t)(void *handle, nh_osa_semaphore_t sem);
|
||||
|
||||
typedef nh_ret_t (*nh_osa_buf_allocate_t)(void *handle, uint8_t **buf, uint32_t buf_size);
|
||||
typedef nh_ret_t (*nh_osa_buf_free_t)(void *handle, uint8_t *buf);
|
||||
|
||||
/* OPS */
|
||||
typedef nh_ret_t (*nh_ops_spi_xfer_t)(void *handle, uint8_t *tx_data, uint16_t *rx_data, uint16_t len);
|
||||
typedef nh_ret_t (*nh_ops_hs_poll_t)(void *handle);
|
||||
typedef nh_ret_t (*nh_ops_drdy_read_t)(void *handle, bool *rdy);
|
||||
|
||||
/* Event callbacks */
|
||||
typedef void (*nh_cb_init_t)(void *handle);
|
||||
typedef void (*nh_cb_heartbeat_t)(void *handle);
|
||||
typedef void (*nh_cb_sta_disconn_from_ap_t)(void *handle);
|
||||
typedef void (*nh_cb_sta_disconn_from_soft_ap_t)(void *handle);
|
||||
|
||||
typedef struct {
|
||||
nh_osa_buf_allocate_t buf_allocate;
|
||||
nh_osa_buf_free_t buf_free;
|
||||
nh_osa_semaphore_create_t sem_create;
|
||||
nh_osa_semaphore_take_t sem_take;
|
||||
nh_osa_semaphore_give_t sem_give;
|
||||
} nh_ctrl_api_osa_t;
|
||||
|
||||
typedef struct {
|
||||
nh_ops_spi_xfer_t xfer;
|
||||
nh_ops_hs_poll_t handshake_poll;
|
||||
nh_ops_drdy_read_t data_ready_read;
|
||||
} nh_ctrl_api_ops_t;
|
||||
|
||||
typedef struct {
|
||||
nh_cb_init_t init;
|
||||
nh_cb_heartbeat_t heartbeat;
|
||||
nh_cb_sta_disconn_from_ap_t sta_disconn_from_ap;
|
||||
nh_cb_sta_disconn_from_soft_ap_t sta_disconn_from_soft_ap;
|
||||
} nh_ctrl_api_cb_t;
|
||||
|
||||
typedef struct {
|
||||
nh_ctrl_api_osa_t osa;
|
||||
nh_ctrl_api_ops_t ops;
|
||||
nh_ctrl_api_cb_t cb;
|
||||
void *user_data;
|
||||
|
||||
/* Private states */
|
||||
uint8_t *p_buf_tx;
|
||||
uint8_t *p_buf_rx;
|
||||
bool p_flag_request; /* !! Guarded by: p_semaphore_request */
|
||||
nh_osa_semaphore_t p_semaphore_event;
|
||||
nh_osa_semaphore_t p_semaphore_request;
|
||||
nh_osa_semaphore_t p_semaphore_response;
|
||||
} nh_ctrl_api_t;
|
||||
|
||||
nh_ret_t nh_ctrl_api_init(nh_ctrl_api_t *api);
|
||||
void nh_ctrl_api_task(nh_ctrl_api_t *api);
|
||||
void nh_ctrl_api_inject_data_ready(nh_ctrl_api_t *api);
|
||||
|
||||
#endif // NH_CTRL_API_H
|
|
@ -0,0 +1 @@
|
|||
Subproject commit b97aa657a706d3ba4a9a6ccca7043c9d6fe41cba
|
|
@ -0,0 +1,150 @@
|
|||
/* Automatically generated nanopb constant definitions */
|
||||
/* Generated by nanopb-0.4.8-dev */
|
||||
|
||||
#include "esp_hosted_config.pb.h"
|
||||
#if PB_PROTO_HEADER_VERSION != 40
|
||||
#error Regenerate this file with the current version of nanopb generator.
|
||||
#endif
|
||||
|
||||
PB_BIND(ScanResult, ScanResult, AUTO)
|
||||
|
||||
|
||||
PB_BIND(ConnectedSTAList, ConnectedSTAList, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_GetMacAddress, CtrlMsg_Req_GetMacAddress, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_GetMacAddress, CtrlMsg_Resp_GetMacAddress, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_GetMode, CtrlMsg_Req_GetMode, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_GetMode, CtrlMsg_Resp_GetMode, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_SetMode, CtrlMsg_Req_SetMode, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_SetMode, CtrlMsg_Resp_SetMode, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_GetStatus, CtrlMsg_Req_GetStatus, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_GetStatus, CtrlMsg_Resp_GetStatus, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_SetMacAddress, CtrlMsg_Req_SetMacAddress, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_SetMacAddress, CtrlMsg_Resp_SetMacAddress, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_GetAPConfig, CtrlMsg_Req_GetAPConfig, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_GetAPConfig, CtrlMsg_Resp_GetAPConfig, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_ConnectAP, CtrlMsg_Req_ConnectAP, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_ConnectAP, CtrlMsg_Resp_ConnectAP, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_GetSoftAPConfig, CtrlMsg_Req_GetSoftAPConfig, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_GetSoftAPConfig, CtrlMsg_Resp_GetSoftAPConfig, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_StartSoftAP, CtrlMsg_Req_StartSoftAP, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_StartSoftAP, CtrlMsg_Resp_StartSoftAP, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_ScanResult, CtrlMsg_Req_ScanResult, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_ScanResult, CtrlMsg_Resp_ScanResult, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_SoftAPConnectedSTA, CtrlMsg_Req_SoftAPConnectedSTA, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_SoftAPConnectedSTA, CtrlMsg_Resp_SoftAPConnectedSTA, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_OTABegin, CtrlMsg_Req_OTABegin, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_OTABegin, CtrlMsg_Resp_OTABegin, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_OTAWrite, CtrlMsg_Req_OTAWrite, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_OTAWrite, CtrlMsg_Resp_OTAWrite, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_OTAEnd, CtrlMsg_Req_OTAEnd, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_OTAEnd, CtrlMsg_Resp_OTAEnd, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_VendorIEData, CtrlMsg_Req_VendorIEData, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_SetSoftAPVendorSpecificIE, CtrlMsg_Req_SetSoftAPVendorSpecificIE, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_SetSoftAPVendorSpecificIE, CtrlMsg_Resp_SetSoftAPVendorSpecificIE, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_SetWifiMaxTxPower, CtrlMsg_Req_SetWifiMaxTxPower, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_SetWifiMaxTxPower, CtrlMsg_Resp_SetWifiMaxTxPower, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_GetWifiCurrTxPower, CtrlMsg_Req_GetWifiCurrTxPower, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_GetWifiCurrTxPower, CtrlMsg_Resp_GetWifiCurrTxPower, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Req_ConfigHeartbeat, CtrlMsg_Req_ConfigHeartbeat, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Resp_ConfigHeartbeat, CtrlMsg_Resp_ConfigHeartbeat, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Event_ESPInit, CtrlMsg_Event_ESPInit, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Event_Heartbeat, CtrlMsg_Event_Heartbeat, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Event_StationDisconnectFromAP, CtrlMsg_Event_StationDisconnectFromAP, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg_Event_StationDisconnectFromESPSoftAP, CtrlMsg_Event_StationDisconnectFromESPSoftAP, AUTO)
|
||||
|
||||
|
||||
PB_BIND(CtrlMsg, CtrlMsg, 2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,432 @@
|
|||
syntax = "proto3";
|
||||
|
||||
/* Enums similar to ESP IDF */
|
||||
enum Ctrl_VendorIEType {
|
||||
Beacon = 0;
|
||||
Probe_req = 1;
|
||||
Probe_resp = 2;
|
||||
Assoc_req = 3;
|
||||
Assoc_resp = 4;
|
||||
}
|
||||
|
||||
enum Ctrl_VendorIEID {
|
||||
ID_0 = 0;
|
||||
ID_1 = 1;
|
||||
}
|
||||
|
||||
enum Ctrl_WifiMode {
|
||||
NONE = 0;
|
||||
STA = 1;
|
||||
AP = 2;
|
||||
APSTA = 3;
|
||||
}
|
||||
|
||||
enum Ctrl_WifiBw {
|
||||
BW_Invalid = 0;
|
||||
HT20 = 1;
|
||||
HT40 = 2;
|
||||
}
|
||||
|
||||
enum Ctrl_WifiPowerSave {
|
||||
PS_Invalid = 0;
|
||||
MIN_MODEM = 1;
|
||||
MAX_MODEM = 2;
|
||||
}
|
||||
|
||||
enum Ctrl_WifiSecProt {
|
||||
Open = 0;
|
||||
WEP = 1;
|
||||
WPA_PSK = 2;
|
||||
WPA2_PSK = 3;
|
||||
WPA_WPA2_PSK = 4;
|
||||
WPA2_ENTERPRISE = 5;
|
||||
WPA3_PSK = 6;
|
||||
WPA2_WPA3_PSK = 7;
|
||||
}
|
||||
|
||||
/* enums for Control path */
|
||||
enum Ctrl_Status {
|
||||
Connected = 0;
|
||||
Not_Connected = 1;
|
||||
No_AP_Found = 2;
|
||||
Connection_Fail = 3;
|
||||
Invalid_Argument = 4;
|
||||
Out_Of_Range = 5;
|
||||
}
|
||||
|
||||
|
||||
enum CtrlMsgType {
|
||||
MsgType_Invalid = 0;
|
||||
Req = 1;
|
||||
Resp = 2;
|
||||
Event = 3;
|
||||
MsgType_Max = 4;
|
||||
}
|
||||
|
||||
enum CtrlMsgId {
|
||||
MsgId_Invalid = 0;
|
||||
|
||||
/** Request Msgs **/
|
||||
Req_Base = 100;
|
||||
|
||||
Req_GetMACAddress = 101;
|
||||
Req_SetMacAddress = 102;
|
||||
Req_GetWifiMode = 103;
|
||||
Req_SetWifiMode = 104;
|
||||
|
||||
Req_GetAPScanList = 105;
|
||||
Req_GetAPConfig = 106;
|
||||
Req_ConnectAP = 107;
|
||||
Req_DisconnectAP = 108;
|
||||
|
||||
Req_GetSoftAPConfig = 109;
|
||||
Req_SetSoftAPVendorSpecificIE = 110;
|
||||
Req_StartSoftAP = 111;
|
||||
Req_GetSoftAPConnectedSTAList = 112;
|
||||
Req_StopSoftAP = 113;
|
||||
|
||||
Req_SetPowerSaveMode = 114;
|
||||
Req_GetPowerSaveMode = 115;
|
||||
|
||||
Req_OTABegin = 116;
|
||||
Req_OTAWrite = 117;
|
||||
Req_OTAEnd = 118;
|
||||
|
||||
Req_SetWifiMaxTxPower = 119;
|
||||
Req_GetWifiCurrTxPower = 120;
|
||||
|
||||
Req_ConfigHeartbeat = 121;
|
||||
/* Add new control path command response before Req_Max
|
||||
* and update Req_Max */
|
||||
Req_Max = 122;
|
||||
|
||||
/** Response Msgs **/
|
||||
Resp_Base = 200;
|
||||
|
||||
Resp_GetMACAddress = 201;
|
||||
Resp_SetMacAddress = 202;
|
||||
Resp_GetWifiMode = 203;
|
||||
Resp_SetWifiMode = 204;
|
||||
|
||||
Resp_GetAPScanList = 205;
|
||||
Resp_GetAPConfig = 206;
|
||||
Resp_ConnectAP = 207;
|
||||
Resp_DisconnectAP = 208;
|
||||
|
||||
Resp_GetSoftAPConfig = 209;
|
||||
Resp_SetSoftAPVendorSpecificIE = 210;
|
||||
Resp_StartSoftAP = 211;
|
||||
Resp_GetSoftAPConnectedSTAList = 212;
|
||||
Resp_StopSoftAP = 213;
|
||||
|
||||
Resp_SetPowerSaveMode = 214;
|
||||
Resp_GetPowerSaveMode = 215;
|
||||
|
||||
Resp_OTABegin = 216;
|
||||
Resp_OTAWrite = 217;
|
||||
Resp_OTAEnd = 218;
|
||||
|
||||
Resp_SetWifiMaxTxPower = 219;
|
||||
Resp_GetWifiCurrTxPower = 220;
|
||||
|
||||
Resp_ConfigHeartbeat = 221;
|
||||
/* Add new control path command response before Resp_Max
|
||||
* and update Resp_Max */
|
||||
Resp_Max = 222;
|
||||
|
||||
/** Event Msgs **/
|
||||
Event_Base = 300;
|
||||
Event_ESPInit = 301;
|
||||
Event_Heartbeat = 302;
|
||||
Event_StationDisconnectFromAP = 303;
|
||||
Event_StationDisconnectFromESPSoftAP = 304;
|
||||
/* Add new control path command notification before Event_Max
|
||||
* and update Event_Max */
|
||||
Event_Max = 305;
|
||||
}
|
||||
|
||||
/* internal supporting structures for CtrlMsg */
|
||||
message ScanResult {
|
||||
bytes ssid = 1;
|
||||
uint32 chnl = 2;
|
||||
int32 rssi = 3;
|
||||
bytes bssid = 4;
|
||||
Ctrl_WifiSecProt sec_prot = 5;
|
||||
}
|
||||
|
||||
message ConnectedSTAList {
|
||||
bytes mac = 1;
|
||||
int32 rssi = 2;
|
||||
}
|
||||
|
||||
|
||||
/* Control path structures */
|
||||
/** Req/Resp structure **/
|
||||
message CtrlMsg_Req_GetMacAddress {
|
||||
int32 mode = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_GetMacAddress {
|
||||
bytes mac = 1;
|
||||
int32 resp = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_GetMode {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_GetMode {
|
||||
int32 mode = 1;
|
||||
int32 resp = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_SetMode {
|
||||
int32 mode = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_SetMode {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_GetStatus {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_GetStatus {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_SetMacAddress {
|
||||
bytes mac = 1;
|
||||
int32 mode = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_SetMacAddress {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_GetAPConfig {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_GetAPConfig {
|
||||
bytes ssid = 1;
|
||||
bytes bssid = 2;
|
||||
int32 rssi = 3;
|
||||
int32 chnl = 4;
|
||||
Ctrl_WifiSecProt sec_prot = 5;
|
||||
int32 resp = 6;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_ConnectAP {
|
||||
string ssid = 1;
|
||||
string pwd = 2;
|
||||
string bssid = 3;
|
||||
bool is_wpa3_supported = 4;
|
||||
int32 listen_interval = 5;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_ConnectAP {
|
||||
int32 resp = 1;
|
||||
bytes mac = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_GetSoftAPConfig {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_GetSoftAPConfig {
|
||||
bytes ssid = 1;
|
||||
bytes pwd = 2;
|
||||
int32 chnl = 3;
|
||||
Ctrl_WifiSecProt sec_prot = 4;
|
||||
int32 max_conn = 5;
|
||||
bool ssid_hidden = 6;
|
||||
int32 bw = 7;
|
||||
int32 resp = 8;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_StartSoftAP {
|
||||
string ssid = 1;
|
||||
string pwd = 2;
|
||||
int32 chnl = 3;
|
||||
Ctrl_WifiSecProt sec_prot = 4;
|
||||
int32 max_conn = 5;
|
||||
bool ssid_hidden = 6;
|
||||
int32 bw = 7;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_StartSoftAP {
|
||||
int32 resp = 1;
|
||||
bytes mac = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_ScanResult {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_ScanResult {
|
||||
uint32 count = 1;
|
||||
repeated ScanResult entries = 2;
|
||||
int32 resp = 3;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_SoftAPConnectedSTA {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_SoftAPConnectedSTA {
|
||||
uint32 num = 1;
|
||||
repeated ConnectedSTAList stations = 2;
|
||||
int32 resp = 3;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_OTABegin {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_OTABegin {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_OTAWrite {
|
||||
bytes ota_data = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_OTAWrite {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_OTAEnd {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_OTAEnd {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_VendorIEData {
|
||||
int32 element_id = 1;
|
||||
int32 length = 2;
|
||||
bytes vendor_oui = 3;
|
||||
int32 vendor_oui_type = 4;
|
||||
bytes payload = 5;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_SetSoftAPVendorSpecificIE {
|
||||
bool enable = 1;
|
||||
Ctrl_VendorIEType type = 2;
|
||||
Ctrl_VendorIEID idx = 3;
|
||||
CtrlMsg_Req_VendorIEData vendor_ie_data = 4;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_SetSoftAPVendorSpecificIE {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_SetWifiMaxTxPower {
|
||||
int32 wifi_max_tx_power = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_SetWifiMaxTxPower {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_GetWifiCurrTxPower {
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_GetWifiCurrTxPower {
|
||||
int32 wifi_curr_tx_power = 1;
|
||||
int32 resp = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Req_ConfigHeartbeat {
|
||||
bool enable = 1;
|
||||
int32 duration = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg_Resp_ConfigHeartbeat {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
/** Event structure **/
|
||||
message CtrlMsg_Event_ESPInit {
|
||||
bytes init_data = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Event_Heartbeat {
|
||||
int32 hb_num = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Event_StationDisconnectFromAP {
|
||||
int32 resp = 1;
|
||||
}
|
||||
|
||||
message CtrlMsg_Event_StationDisconnectFromESPSoftAP {
|
||||
int32 resp = 1;
|
||||
bytes mac = 2;
|
||||
}
|
||||
|
||||
message CtrlMsg {
|
||||
/* msg_type could be req, resp or Event */
|
||||
CtrlMsgType msg_type = 1;
|
||||
|
||||
/* msg id */
|
||||
CtrlMsgId msg_id = 2;
|
||||
|
||||
/* union of all msg ids */
|
||||
oneof payload {
|
||||
/** Requests **/
|
||||
CtrlMsg_Req_GetMacAddress req_get_mac_address = 101;
|
||||
CtrlMsg_Req_SetMacAddress req_set_mac_address = 102;
|
||||
CtrlMsg_Req_GetMode req_get_wifi_mode = 103;
|
||||
CtrlMsg_Req_SetMode req_set_wifi_mode = 104;
|
||||
|
||||
CtrlMsg_Req_ScanResult req_scan_ap_list = 105;
|
||||
CtrlMsg_Req_GetAPConfig req_get_ap_config = 106;
|
||||
CtrlMsg_Req_ConnectAP req_connect_ap = 107;
|
||||
CtrlMsg_Req_GetStatus req_disconnect_ap = 108;
|
||||
|
||||
CtrlMsg_Req_GetSoftAPConfig req_get_softap_config = 109;
|
||||
CtrlMsg_Req_SetSoftAPVendorSpecificIE req_set_softap_vendor_specific_ie = 110;
|
||||
CtrlMsg_Req_StartSoftAP req_start_softap = 111;
|
||||
CtrlMsg_Req_SoftAPConnectedSTA req_softap_connected_stas_list = 112;
|
||||
CtrlMsg_Req_GetStatus req_stop_softap = 113;
|
||||
|
||||
CtrlMsg_Req_SetMode req_set_power_save_mode = 114;
|
||||
CtrlMsg_Req_GetMode req_get_power_save_mode = 115;
|
||||
|
||||
CtrlMsg_Req_OTABegin req_ota_begin = 116;
|
||||
CtrlMsg_Req_OTAWrite req_ota_write = 117;
|
||||
CtrlMsg_Req_OTAEnd req_ota_end = 118;
|
||||
|
||||
CtrlMsg_Req_SetWifiMaxTxPower req_set_wifi_max_tx_power = 119;
|
||||
CtrlMsg_Req_GetWifiCurrTxPower req_get_wifi_curr_tx_power = 120;
|
||||
CtrlMsg_Req_ConfigHeartbeat req_config_heartbeat = 121;
|
||||
|
||||
/** Responses **/
|
||||
CtrlMsg_Resp_GetMacAddress resp_get_mac_address = 201;
|
||||
CtrlMsg_Resp_SetMacAddress resp_set_mac_address = 202;
|
||||
CtrlMsg_Resp_GetMode resp_get_wifi_mode = 203;
|
||||
CtrlMsg_Resp_SetMode resp_set_wifi_mode = 204;
|
||||
|
||||
CtrlMsg_Resp_ScanResult resp_scan_ap_list = 205;
|
||||
CtrlMsg_Resp_GetAPConfig resp_get_ap_config = 206;
|
||||
CtrlMsg_Resp_ConnectAP resp_connect_ap = 207;
|
||||
CtrlMsg_Resp_GetStatus resp_disconnect_ap = 208;
|
||||
|
||||
CtrlMsg_Resp_GetSoftAPConfig resp_get_softap_config = 209;
|
||||
CtrlMsg_Resp_SetSoftAPVendorSpecificIE resp_set_softap_vendor_specific_ie = 210;
|
||||
CtrlMsg_Resp_StartSoftAP resp_start_softap = 211;
|
||||
CtrlMsg_Resp_SoftAPConnectedSTA resp_softap_connected_stas_list = 212;
|
||||
CtrlMsg_Resp_GetStatus resp_stop_softap = 213;
|
||||
|
||||
CtrlMsg_Resp_SetMode resp_set_power_save_mode = 214;
|
||||
CtrlMsg_Resp_GetMode resp_get_power_save_mode = 215;
|
||||
|
||||
CtrlMsg_Resp_OTABegin resp_ota_begin = 216;
|
||||
CtrlMsg_Resp_OTAWrite resp_ota_write = 217;
|
||||
CtrlMsg_Resp_OTAEnd resp_ota_end = 218;
|
||||
CtrlMsg_Resp_SetWifiMaxTxPower resp_set_wifi_max_tx_power = 219;
|
||||
CtrlMsg_Resp_GetWifiCurrTxPower resp_get_wifi_curr_tx_power = 220;
|
||||
CtrlMsg_Resp_ConfigHeartbeat resp_config_heartbeat = 221;
|
||||
|
||||
/** Notifications **/
|
||||
CtrlMsg_Event_ESPInit event_esp_init = 301;
|
||||
CtrlMsg_Event_Heartbeat event_heartbeat = 302;
|
||||
CtrlMsg_Event_StationDisconnectFromAP event_station_disconnect_from_AP = 303;
|
||||
CtrlMsg_Event_StationDisconnectFromESPSoftAP event_station_disconnect_from_ESP_SoftAP = 304;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
#include "nh_ctrl_api.h"
|
||||
|
||||
#include "esp_hosted_config.pb.h"
|
||||
|
||||
#define NH_XFER_BUF_SIZE 1600
|
||||
|
||||
#define NH_SEMAPHORE_EVENT_TIMEOUT 1000
|
||||
#define NH_SEMAPHORE_REQ_TIMEOUT 5000
|
||||
|
||||
nh_ret_t nh_ctrl_api_init(nh_ctrl_api_t *api) {
|
||||
nh_ret_t ret = NH_RET_SUCCESS;
|
||||
|
||||
/* Create semaphore for input events (Data Ready, Ctrl API call) */
|
||||
ret = api->osa.sem_create(api->user_data, &api->p_semaphore_event);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Create semaphore for control API requests, we can support maximum 1 control API request at any given time */
|
||||
ret = api->osa.sem_create(api->user_data, &api->p_semaphore_request);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Create semaphore for control API responses */
|
||||
ret = api->osa.sem_create(api->user_data, &api->p_semaphore_response);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* TODO: Determine the initial value of each semaphores. */
|
||||
|
||||
/* Allocate TX and RX buffers, we should minimalize the malloc-free counts to reduce memory fragmentation */
|
||||
ret = api->osa.buf_allocate(api->user_data, &api->p_buf_tx, NH_XFER_BUF_SIZE);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = api->osa.buf_allocate(api->user_data, &api->p_buf_rx, NH_XFER_BUF_SIZE);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NH_RET_SUCCESS;
|
||||
}
|
||||
|
||||
void nh_ctrl_api_task(nh_ctrl_api_t *api) {
|
||||
nh_ret_t ret = NH_RET_SUCCESS;
|
||||
|
||||
ret = api->osa.sem_take(api->user_data, api->p_semaphore_event, NH_SEMAPHORE_EVENT_TIMEOUT);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
/* Failed to acquire semaphore due to error or timed out */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Acquired semaphore, could be an event or a request, or both. */
|
||||
}
|
||||
|
||||
nh_ret_t nh_ctrl_api_get_mac(nh_ctrl_api_t *api, uint8_t *mac) {
|
||||
nh_ret_t ret;
|
||||
|
||||
ret = api->osa.sem_take(api->user_data, api->p_semaphore_request, NH_SEMAPHORE_REQ_TIMEOUT);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
/* Failed to take the request semaphore in time, maybe due to another request in under way */
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* TODO: Encode the request */
|
||||
CtrlMsg_Req_GetMacAddress req = CtrlMsg_Req_GetMacAddress_init_zero;
|
||||
req.mode = Ctrl_WifiMode_STA;
|
||||
|
||||
api->p_flag_request = true;
|
||||
ret = api->osa.sem_give(api->user_data, api->p_semaphore_event);
|
||||
if (ret != NH_RET_SUCCESS) {
|
||||
goto give_sem_and_exit;
|
||||
}
|
||||
|
||||
ret = api->osa.sem_take(api->user_data, api->p_semaphore_response, NH_SEMAPHORE_REQ_TIMEOUT);
|
||||
if(ret != NH_RET_SUCCESS) {
|
||||
goto give_sem_and_exit;
|
||||
}
|
||||
|
||||
give_sem_and_exit:
|
||||
api->osa.sem_give(api->user_data, api->p_semaphore_request);
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue