網頁

2017年6月10日 星期六

DIY - ESP8266:ESP8266 SDK ESPCONN 網路介面參數(三十四)

DIY - ESP8266:ESP8266 SDK ESPCONN 網路介面參數(三十四):

除了網路的 應用程式介面(Application Programming Interface / API)外,還有結構體(Data Structures),在使用 SDK API 時是需要知道結構體的,因為執行程式目的是進行指令工作或收發資料數據,而程式執行時是需要提取或儲存數據來作不同的任務,例如是使用 TCP 或 UDP 來收發資料數據等等,所以是清楚了解參數的內容和定義。

C++ Data Types
Data Structures (結構): 
結構是一種使用者自定的型態,可以存放不同資料型態的資料體,每個資料體被稱為結構的成員。 
• struct espconn 
• struct esp_tcp 
• struct esp_udp
• struct remot_info 
struct espconn_packet
struct mdns_info
 
ESP8266 ESPCONN Structures
// ESPCONN Structures
struct espconn {
enum espconn_type type;       //Type of the espconn (TCP, UDP)
enum espconn_state state;      //Current state of the ESPCONN
union {
esp_tcp *tcp;
esp_udp *udp;
} proto;

ESP8266 ESPCONN TCP Structures:
// TCP Structures
typedef struct _esp_tcp {
int remote_port;
int local_port;
uint8 local_ip[4];
uint8 remote_ip[4];
espconn_connect_callback connect_callback;
espconn_reconnect_callback reconnect_callback;
espconn_connect_callback disconnect_callback;
espconn_connect_callback write_finish_fn;
} esp_tcp;

ESP8266 ESPCONN UDP Structures
// UDP Structures
typedef struct _esp_udp {
int remote_port;
int local_port;
uint8 local_ip[4];
uint8 remote_ip[4];
} esp_udp;

ESP8266 ESPCONN Remote Information Structures
// Remote Information Structures
typedef struct _remot_info{
        enum espconn_state state;
        int remote_port;
        uint8 remote_ip[4];
}remot_info;

ESP8266 ESPCONN Packet Structures
// ESPCONN Packet Structures
struct espconn_packet{
        uint16 sent_length;          /* sent length successful*/
        uint16 snd_buf_size;              /* Available buffer size for sending  */
        uint16 snd_queuelen;             /* Available buffer space for sending */
        uint16 total_queuelen;            /* total Available buffer space for sending */
        uint32 packseqno;           /* seqno to be sent */
        uint32 packseq_nxt;                /* seqno expected */
        uint32 packnum;
};

ESP8266 ESPCONN MDNS Information Structures:
// ESPCONN MDNS Information Structures
struct mdns_info {
        char *host_name;
        char *server_name;
        uint16 server_port;
        unsigned long ipAddr;
        char *txt_data[10];
};

Enumerations(列舉): 
列舉(Enumeration)是以關鍵字 enum 開始加上一個列舉名稱,並以大括號括住要群組管理的常數,大括號內每一個元素稱為列舉元(enumerator),預設上列舉元從第一個開始的實際數值是 0,然後依次遞增。

ESP8266 ESPCONN Option Descriptor:
// ESPCONN Option Descriptor
enum espconn_option{
ESPCONN_START         = 0x00
ESPCONN_REUSEADDR       = 0x01
ESPCONN_NODELAY   = 0x02
ESPCONN_COPY           = 0x04
ESPCONN_KEEPALIVE = 0x08
ESPCONN_END
}

ESP8266 ESPCONN Level Descriptor
// ESPCONN Level Descriptor
enum espconn_level{
ESPCONN_KEEPIDLE,
ESPCONN_KEEPINTVL,
ESPCONN_KEEPCNT
}

ESP8266 ESPCONN Status Descriptor:
// ESPCONN Status Descriptor
// Current state of the espconn. Non-TCP espconn are always in state ESPCONN_NONE
enum espconn_state {
ESPCONN_NONE,
ESPCONN_WAIT,
ESPCONN_LISTEN,
ESPCONN_CONNECT,
ESPCONN_WRITE,
ESPCONN_READ,
ESPCONN_CLOSE
};

ESP8266 ESPCONN Type
// ESPCONN Protocol family and type of the espconn
enum espconn_type {
ESPCONN_INVALID = 0,
ESPCONN_TCP = 0x10,  // ESPCONN_TCP Group
ESPCONN_UDP = 0x20, // ESPCONN_UDP Group
};

Macros(巨集): 
巨集是根據一系列預定義的規則替換一定的文字模式。 
• #define ESPCONN_OK 0 
• #define ESPCONN_MEM -1 
• #define ESPCONN_TIMEOUT -3 
• #define ESPCONN_RTE -4 
• #define ESPCONN_INPROGRESS -5 
• #define ESPCONN_MAXNUM -7 
• #define ESPCONN_ABRT -8 
• #define ESPCONN_RST -9 
• #define ESPCONN_CLSD -10 
• #define ESPCONN_CONN -11 
• #define ESPCONN_ARG -12 
• #define ESPCONN_IF -14 
• #define ESPCONN_ISCONN -15

2017年 6月 10日 天氣報告
氣溫:29.4@ 21:00
相對濕度:百分之 82%
天氣:天色大致良好

沒有留言:

張貼留言