Skip to content

Commit

Permalink
Fully move from "cb" (callback) to "evt" (event) approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jul 1, 2018
1 parent a182ed7 commit eabd081
Show file tree
Hide file tree
Showing 48 changed files with 334 additions and 297 deletions.
Binary file modified dev/VisualStudio/esp_dev_os/Debug/vc141.idb
Binary file not shown.
18 changes: 9 additions & 9 deletions dev/VisualStudio/esp_dev_os/esp_dev_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,30 @@ main_thread(void* arg) {
static espr_t
esp_evt(esp_evt_t* evt) {
switch (evt->type) {
case ESP_CB_INIT_FINISH: {
case ESP_EVT_INIT_FINISH: {
esp_restore(0);
esp_set_at_baudrate(115200, 0);
esp_hostname_set("esp_device", 0);
break;
}
case ESP_CB_RESET: {
case ESP_EVT_RESET: {
printf("Device reset!\r\n");
break;
}
#if ESP_CFG_MODE_ACCESS_POINT
case ESP_CB_AP_CONNECTED_STA: {
case ESP_EVT_AP_CONNECTED_STA: {
esp_mac_t* mac = esp_evt_ap_connected_sta_get_mac(evt);
printf("New station connected to ESP's AP with MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",
mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], mac->mac[4], mac->mac[5]);
break;
}
case ESP_CB_AP_DISCONNECTED_STA: {
case ESP_EVT_AP_DISCONNECTED_STA: {
esp_mac_t* mac = esp_evt_ap_disconnected_sta_get_mac(evt);
printf("Station disconnected from ESP's AP with MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n",
mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], mac->mac[4], mac->mac[5]);
break;
}
case ESP_CB_AP_IP_STA: {
case ESP_EVT_AP_IP_STA: {
esp_mac_t* mac = esp_evt_ap_ip_sta_get_mac(evt);
esp_ip_t* ip = esp_evt_ap_ip_sta_get_ip(evt);
printf("Station received IP address from ESP's AP with MAC: %02X:%02X:%02X:%02X:%02X:%02X and IP: %d.%d.%d.%d\r\n",
Expand All @@ -185,16 +185,16 @@ esp_conn_evt(esp_evt_t* evt) {
"\r\n";

switch (evt->type) {
case ESP_CB_CONN_ACTIVE: {
case ESP_EVT_CONN_ACTIVE: {
printf("Connection active!\r\n");
esp_conn_send(esp_evt_conn_active_get_conn(evt), data, sizeof(data) - 1, NULL, 0);
break;
}
case ESP_CB_CONN_DATA_SENT: {
case ESP_EVT_CONN_DATA_SENT: {
printf("Connection data sent!\r\n");
break;
}
case ESP_CB_CONN_DATA_RECV: {
case ESP_EVT_CONN_DATA_RECV: {
esp_pbuf_p pbuf = esp_evt_conn_data_recv_get_buff(evt);
esp_conn_p conn = esp_evt_conn_data_recv_get_conn(evt);
printf("\r\nConnection data received: %d / %d bytes\r\n",
Expand All @@ -204,7 +204,7 @@ esp_conn_evt(esp_evt_t* evt) {
esp_conn_recved(conn, pbuf);
break;
}
case ESP_CB_CONN_CLOSED: {
case ESP_EVT_CONN_CLOSED: {
printf("Connection closed!\r\n");
esp_conn_start(NULL, ESP_CONN_TYPE_TCP, "majerle.eu", 80, NULL, esp_conn_evt, 0);
break;
Expand Down
1 change: 1 addition & 0 deletions dev/VisualStudio/esp_dev_os/esp_dev_os.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<ClCompile Include="..\..\..\snippets\netconn_server.c" />
<ClCompile Include="..\..\..\snippets\station_manager.c" />
<ClCompile Include="..\..\..\src\api\esp_netconn.c" />
<ClCompile Include="..\..\..\src\api\esp_rest_client.c" />
<ClCompile Include="..\..\..\src\apps\http_server\esp_http_server.c" />
<ClCompile Include="..\..\..\src\apps\http_server\esp_http_server_fs.c" />
<ClCompile Include="..\..\..\src\apps\http_server\esp_http_server_fs_win32.c" />
Expand Down
3 changes: 3 additions & 0 deletions dev/VisualStudio/esp_dev_os/esp_dev_os.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,8 @@
<ClCompile Include="..\..\..\src\esp\esp_mdns.c">
<Filter>Source Files\ESP CORE</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\api\esp_rest_client.c">
<Filter>Source Files\ESP API</Filter>
</ClCompile>
</ItemGroup>
</Project>
Binary file modified dev/VisualStudio/esp_dev_os/log_file.txt
Binary file not shown.
34 changes: 17 additions & 17 deletions dev/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) {
while (1);
}

static espr_t esp_cb(esp_cb_t* cb);
static espr_t esp_evt(esp_evt_t* evt);

/**
* \brief Initialization thread for entire process
Expand All @@ -89,7 +89,7 @@ init_thread(void const* arg) {
HAL_NVIC_SetPriority(EXTI3_IRQn, 2, 4);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);

esp_init(esp_cb, 1); /* Init ESP stack */
esp_init(esp_evt, 1); /* Init ESP stack */

if (is_device_present()) {
printf("Device connected...starting with reset!\r\n");
Expand Down Expand Up @@ -142,47 +142,47 @@ init_thread(void const* arg) {

/**
* \brief Global ESP callback for general info
* \param[in] cb: Pointer to callback data
* \param[in] evt: Pointer to callback data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
esp_cb(esp_cb_t* cb) {
switch (cb->type) {
case ESP_CB_RESET: {
esp_evt(esp_evt_t* evt) {
switch (esp_evt_get_type(evt)) {
case ESP_EVT_RESET: {
printf("Device reset!\r\n");
break;
}
case ESP_CB_INIT_FINISH: {
case ESP_EVT_INIT_FINISH: {
break;
}
#if ESP_CFG_MODE_STATION
case ESP_CB_STA_LIST_AP: {
case ESP_EVT_STA_LIST_AP: {
printf("List AP finished!\r\n");
break;
}
case ESP_CB_WIFI_GOT_IP: {
case ESP_EVT_WIFI_GOT_IP: {
printf("WIFI got IP!\r\n");
break;
}
case ESP_CB_WIFI_CONNECTED: {
case ESP_EVT_WIFI_CONNECTED: {
printf("WIFI connected!\r\n");
break;
}
case ESP_CB_WIFI_DISCONNECTED: {
case ESP_EVT_WIFI_DISCONNECTED: {
printf("WIFI disconnected!\r\n");
break;
}
#endif /* ESP_CFG_MODE_STATION */
case ESP_CB_CONN_ACTIVE: {
printf("Connection active, time: %d, conn: %p\r\n", (int)esp_sys_now(), cb->cb.conn_active_closed.conn);
case ESP_EVT_CONN_ACTIVE: {
printf("Connection active, time: %d, conn: %p\r\n", (int)esp_sys_now(), evt->evt.conn_active_closed.conn);
break;
}
case ESP_CB_CONN_POLL: {
printf("Connection poll, time: %d, conn: %p\r\n", (int)esp_sys_now(), cb->cb.conn_poll.conn);
case ESP_EVT_CONN_POLL: {
printf("Connection poll, time: %d, conn: %p\r\n", (int)esp_sys_now(), evt->evt.conn_poll.conn);
break;
}
case ESP_CB_CONN_CLOSED: {
printf("Connection closed, time: %d, conn: %p\r\n", (int)esp_sys_now(), cb->cb.conn_poll.conn);
case ESP_EVT_CONN_CLOSED: {
printf("Connection closed, time: %d, conn: %p\r\n", (int)esp_sys_now(), evt->evt.conn_poll.conn);
break;
}
default:
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/_example_conn_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ uint8_t req_data[] = ""
* \brief Connection callback function
* Called on several connection events, such as connected, closed, data received, data sent, ...
* \param[in] evt: ESP callback event
*/
*/
static espr_t
conn_evt(esp_evt_t* evt) {
esp_conn_p conn = esp_conn_get_from_evt(evt); /* Get connection from current event */
if (conn == NULL) {
return espERR; /* Return error at this point as this should never happen! */
}

switch (evt->type) {
switch (esp_evt_get_type(evt)) {
/*
* A new connection just became active
*/
case ESP_CB_CONN_ACTIVE: {
case ESP_EVT_CONN_ACTIVE: {
printf("Connection active!\r\n");

/*
Expand All @@ -35,7 +35,7 @@ conn_evt(esp_evt_t* evt) {
/*
* Connection closed event
*/
case ESP_CB_CONN_CLOSED: {
case ESP_EVT_CONN_CLOSED: {
printf("Connection closed!\r\n");
if (evt->evt.conn_active_closed.forced) { /* Was it forced by user? */
printf("Connection closed by user\r\n");
Expand All @@ -47,7 +47,7 @@ conn_evt(esp_evt_t* evt) {
/*
* Data received on connection
*/
case ESP_CB_CONN_DATA_RECV: {
case ESP_EVT_CONN_DATA_RECV: {
esp_pbuf_p pbuf = cb->evt.conn_data_recv.buff; /* Get data buffer */

/*
Expand Down
8 changes: 2 additions & 6 deletions docs/examples/_example_evt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
*/
espr_t
esp_callback_function(esp_evt_t* evt) {
switch (evt->type) { /* Check event type */
case ESP_CB_RESET: { /* Reset detected on ESP device */
switch (esp_evt_get_type(evt)) {
case ESP_EVT_RESET: { /* Reset detected on ESP device */
/* Option 1 */
if (esp_evt_reset_is_forced(evt)) { /* Check if forced by user */
printf("Reset forced by user!\r\n");
}
/* Option 2 */
if (esp->evt.evt.reset.forced) { /* Check if forced by user */
printf("Reset forced by user!\r\n");
}
break;
}
default: break;
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/_example_mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mqtt_thread(void const* arg) {
*/
static void
mqtt_evt(mqtt_client_t* client, mqtt_evt_t* evt) {
switch (evt->type) {
switch (esp_evt_get_type(evt)) {
/*
* Connect event
* Called if user successfully connected to MQTT server
Expand Down
12 changes: 6 additions & 6 deletions examples/stm32f723e-discovery/netconn_server_rtos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void USART_Printf_Init(void);
static void init_thread(void const* arg);
osThreadDef(init_thread, init_thread, osPriorityNormal, 0, 512);

static espr_t esp_callback_func(esp_cb_t* cb);
static espr_t esp_callback_func(esp_evt_t* evt);

/**
* \brief Program entry point
Expand Down Expand Up @@ -94,17 +94,17 @@ init_thread(void const* arg) {

/**
* \brief Event callback function for ESP stack
* \param[in] cb: Event information with data
* \param[in] evt: Event information with data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
esp_callback_func(esp_cb_t* cb) {
switch (cb->type) {
case ESP_CB_INIT_FINISH: {
esp_callback_func(esp_evt_t* evt) {
switch (esp_evt_get_type(evt)) {
case ESP_EVT_INIT_FINISH: {
printf("Library initialized!\r\n");
break;
}
case ESP_CB_RESET: {
case ESP_EVT_RESET: {
printf("Device reset detected!\r\n");
break;
}
Expand Down
12 changes: 6 additions & 6 deletions examples/stm32f769i-discovery/netconn_server_rtos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void USART_Printf_Init(void);
static void init_thread(void const* arg);
osThreadDef(init_thread, init_thread, osPriorityNormal, 0, 512);

static espr_t esp_callback_func(esp_cb_t* cb);
static espr_t esp_callback_func(esp_evt_t* evt);

/**
* \brief Program entry point
Expand Down Expand Up @@ -94,17 +94,17 @@ init_thread(void const* arg) {

/**
* \brief Event callback function for ESP stack
* \param[in] cb: Event information with data
* \param[in] evt: Event information with data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
esp_callback_func(esp_cb_t* cb) {
switch (cb->type) {
case ESP_CB_INIT_FINISH: {
esp_callback_func(esp_evt_t* evt) {
switch (esp_evt_get_type(evt)) {
case ESP_EVT_INIT_FINISH: {
printf("Library initialized!\r\n");
break;
}
case ESP_CB_RESET: {
case ESP_EVT_RESET: {
printf("Device reset detected!\r\n");
break;
}
Expand Down
36 changes: 18 additions & 18 deletions examples/stm32l496g-discovery/client_rtos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static void USART_Printf_Init(void);
static void init_thread(void const* arg);
osThreadDef(init_thread, init_thread, osPriorityNormal, 0, 512);

static espr_t esp_callback_func(esp_cb_t* cb);
static espr_t conn_callback_func(esp_cb_t* cb);
static espr_t esp_callback_func(esp_evt_t* evt);
static espr_t conn_callback_func(esp_evt_t* evt);

/**
* \brief Program entry point
Expand Down Expand Up @@ -109,20 +109,20 @@ uint8_t req_data[] = ""

/**
* \brief Event callback function for connection-only
* \param[in] cb: Event information with data
* \param[in] evt: Event information with data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
conn_callback_func(esp_cb_t* cb) {
conn_callback_func(esp_evt_t* evt) {
esp_conn_p conn;
espr_t res;

conn = esp_conn_get_from_evt(cb); /* Get connection handle from event */
conn = esp_conn_get_from_evt(evt); /* Get connection handle from event */
if (conn == NULL) {
return espERR;
}
switch (cb->type) { /* Check event type */
case ESP_CB_CONN_ACTIVE: { /* Connection just active */
switch (esp_evt_get_type(evt)) {
case ESP_EVT_CONN_ACTIVE: { /* Connection just active */
printf("Connection active!\r\n");
res = esp_conn_send(conn, req_data, sizeof(req_data) - 1, NULL, 0); /* Start sending data in non-blocking mode */
if (res == espOK) {
Expand All @@ -133,20 +133,20 @@ conn_callback_func(esp_cb_t* cb) {
}
break;
}
case ESP_CB_CONN_CLOSED: { /* Connection closed */
if (esp_evt_conn_closed_is_forced(cb)) {
case ESP_EVT_CONN_CLOSED: { /* Connection closed */
if (esp_evt_conn_closed_is_forced(evt)) {
printf("Connection closed by client!\r\n");
} else {
printf("Connection closed by remote side!\r\n");
}
break;
}
case ESP_CB_CONN_DATA_SENT: { /* Data successfully sent to remote side */
case ESP_EVT_CONN_DATA_SENT: { /* Data successfully sent to remote side */
printf("Data sent successfully...waiting to receive data from remote side...\r\n");
break;
}
case ESP_CB_CONN_DATA_RECV: { /* Data received from remote side */
esp_pbuf_p pbuf = esp_evt_conn_data_recv_get_buff(cb);
case ESP_EVT_CONN_DATA_RECV: { /* Data received from remote side */
esp_pbuf_p pbuf = esp_evt_conn_data_recv_get_buff(evt);
esp_conn_recved(conn, pbuf); /* Notify stack about received pbuf */
printf("Received %d bytes on connection..\r\n", (int)esp_pbuf_length(pbuf, 1));
break;
Expand All @@ -158,21 +158,21 @@ conn_callback_func(esp_cb_t* cb) {

/**
* \brief Event callback function for ESP stack
* \param[in] cb: Event information with data
* \param[in] evt: Event information with data
* \return espOK on success, member of \ref espr_t otherwise
*/
static espr_t
esp_callback_func(esp_cb_t* cb) {
switch (cb->type) {
case ESP_CB_INIT_FINISH: {
esp_callback_func(esp_evt_t* evt) {
switch (esp_evt_get_type(evt)) {
case ESP_EVT_INIT_FINISH: {
printf("Library initialized!\r\n");
break;
}
case ESP_CB_RESET_FINISH: {
case ESP_EVT_RESET_FINISH: {
printf("Device reset sequence finished!\r\n");
break;
}
case ESP_CB_RESET: {
case ESP_EVT_RESET: {
printf("Device reset detected!\r\n");
break;
}
Expand Down
Loading

0 comments on commit eabd081

Please sign in to comment.