SAME70 Weather Client Demo Example.
Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "image.h"
#include "main_wifi.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "bsp/include/nm_bsp.h"
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"
Macros | |
#define | ASCII_BS 0x7F |
ASCII char definition for backspace. More... | |
#define | ASCII_CR 13 |
ASCII char definition for carriage return. More... | |
#define | STRING_EOL "\r\n" |
#define | STRING_HEADER |
Functions | |
static void | configure_console (void) |
Configure UART console. More... | |
void | configure_rtt (void) |
RTT configuration function. More... | |
void | ili9488_draw_number (uint32_t ul_x, uint32_t ul_y, uint8_t index) |
void | ili9488_draw_temperature (uint32_t ul_x, uint32_t ul_y, char *temperature) |
int | main (void) |
Main application function. More... | |
static uint8_t | parse_weather_icon (char *pcWeather) |
static void | refresh_display () |
static void | resolve_cb (uint8_t *hostName, uint32_t hostIp) |
Callback function of IP address. More... | |
void | RTT_Handler (void) |
Interrupt handler for the RTT. More... | |
static void | socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
Callback function of TCP client socket. More... | |
static void | wifi_cb (uint8_t u8MsgType, void *pvMsg) |
Callback to get the Wi-Fi status update. More... | |
void | wifi_connect (void) |
static void | wifi_handle_events (void) |
static void | wifi_init (void) |
void | wifi_recieve_packet (void) |
static void | wifi_require_weather (char *city_name) |
Variables | |
bool | city_is_sha = true |
bool | display_is_sha = true |
struct ili9488_opt_t | g_ili9488_display_opt |
uint32_t | g_ul_sec_ticks = 0 |
static uint8_t | gau8ReceivedBuffer [MAIN_WIFI_M2M_BUFFER_SIZE] = {0} |
Receive buffer definition. More... | |
static bool | gbConnectedWifi = false |
Wi-Fi status variable. More... | |
static bool | gbContinueReceive = false |
Continue Receive status variable. More... | |
static bool | gbFinishedGetWeather = false |
Weather client status variable. More... | |
static bool | gbHostIpByName = false |
Get host IP status variable. More... | |
static bool | gbRequireWeather = false |
static bool | gbTcpConnection = false |
TCP Connection status variable. More... | |
static char | gcWeatherInfo [2048] = {0} |
uint32_t | gu32HostIp = 0 |
IP address of host. More... | |
char * | gWeatherIcon [4] |
const uint8_t | mark [11] = {'S', 'A', 'M', 'E','7', '0', 'D', 'E', 'M','O'} |
char * | pcCity = NULL |
char * | pcTemperature = NULL |
char * | pcWeather = NULL |
static char | server_host_name [] = MAIN_WEATHER_SERVER_NAME |
Server host name. More... | |
static SOCKET | tcp_client_socket = -1 |
TCP client socket handlers. More... | |
char | Temperature_seoul [30] |
char | Temperature_sha [30] |
uint8_t | ucWeatherNum = 0 |
uint8_t | ucWeatherNum_seoul |
uint8_t | ucWeatherNum_sha |
char | Weather_seoul [30] |
char | Weather_sha [30] |
#define ASCII_BS 0x7F |
ASCII char definition for backspace.
Referenced by wifi_connect().
#define ASCII_CR 13 |
ASCII char definition for carriage return.
Referenced by wifi_connect().
#define STRING_EOL "\r\n" |
#define STRING_HEADER |
Referenced by main().
|
static |
Configure UART console.
References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
void configure_rtt | ( | void | ) |
RTT configuration function.
Configure the RTT to generate a one second tick, which triggers the RTTINC interrupt.
References rtt_enable_interrupt(), and rtt_init().
Referenced by resolve_cb().
void ili9488_draw_number | ( | uint32_t | ul_x, |
uint32_t | ul_y, | ||
uint8_t | index | ||
) |
References ili9488_draw_pixel(), and p_uc_numberset48x48.
Referenced by ili9488_draw_temperature().
void ili9488_draw_temperature | ( | uint32_t | ul_x, |
uint32_t | ul_y, | ||
char * | temperature | ||
) |
References ili9488_draw_number().
Referenced by refresh_display().
int main | ( | void | ) |
Main application function.
Initialize system, UART console, network then start weather client.
References _htons, AF_INET, ili9488_opt_t::background_color, board_init(), city_is_sha, COLOR_BLACK, COLOR_CONVERT, COLOR_WHITE, configure_console(), connect(), display_is_sha, ili9488_opt_t::foreground_color, g_ili9488_display_opt, g_ul_sec_ticks, gbConnectedWifi, gbFinishedGetWeather, gbHostIpByName, gbRequireWeather, gbTcpConnection, gImage_atmel_18bit, gu32HostIp, ili9488_draw_filled_rectangle(), ili9488_draw_pixmap(), ili9488_draw_string(), ili9488_init(), ILI9488_LCD_HEIGHT, ILI9488_LCD_WIDTH, ili9488_set_foreground_color(), IOPORT_DIR_INPUT, ioport_init(), IOPORT_MODE_PULLUP, ioport_set_pin_dir(), ioport_set_pin_mode(), MAIN_SERVER_PORT, refresh_display(), in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_ERR_NO_ERROR, SOCK_STREAM, socket(), STRING_HEADER, sysclk_init(), tcp_client_socket, ili9488_opt_t::ul_height, ili9488_opt_t::ul_width, wifi_connect(), wifi_handle_events(), wifi_init(), wifi_recieve_packet(), and wifi_require_weather().
|
static |
References NULL, and pcWeather.
Referenced by wifi_recieve_packet().
|
static |
References COLOR_BLACK, COLOR_CONVERT, COLOR_WHITE, display_is_sha, gImage_seoul, gImage_shanghai, gWeatherIcon, ili9488_draw_filled_rectangle(), ili9488_draw_pixmap(), ili9488_draw_string(), ili9488_draw_temperature(), ILI9488_LCD_HEIGHT, ILI9488_LCD_WIDTH, ili9488_set_foreground_color(), Temperature_seoul, Temperature_sha, ucWeatherNum_seoul, ucWeatherNum_sha, Weather_seoul, and Weather_sha.
Referenced by main().
|
static |
Callback function of IP address.
[in] | hostName | Domain name. |
[in] | hostIp | Server IP. |
References configure_rtt(), gbHostIpByName, gu32HostIp, and IPV4_BYTE.
Referenced by wifi_init().
void RTT_Handler | ( | void | ) |
Interrupt handler for the RTT.
Display the current time on the terminal.
References g_ul_sec_ticks, and rtt_get_status().
|
static |
Callback function of TCP client socket.
[in] | sock | socket handler. |
[in] | u8Msg | Type of Socket notification |
[in] | pvMsg | A structure contains notification informations. |
References close(), g_ul_sec_ticks, gbFinishedGetWeather, gbRequireWeather, gbTcpConnection, gcWeatherInfo, tstrSocketRecvMsg::pu8Buffer, tstrSocketRecvMsg::s16BufferSize, tstrSocketConnectMsg::s8Error, SOCK_ERR_NO_ERROR, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, and tcp_client_socket.
Referenced by wifi_init().
|
static |
Callback to get the Wi-Fi status update.
[in] | u8MsgType | Type of Wi-Fi notification. |
[in] | pvMsg | A pointer to a buffer containing the notification parameters. |
References gbConnectedWifi, gethostbyname(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, m2m_wifi_request_dhcp_client(), M2M_WIFI_RESP_CON_STATE_CHANGED, server_host_name, tstrM2mWifiStateChanged::u8CurrState, and wifi_connect().
Referenced by wifi_init().
void wifi_connect | ( | void | ) |
|
static |
References m2m_wifi_handle_events(), and NULL.
Referenced by main().
|
static |
References M2M_SUCCESS, m2m_wifi_init(), nm_bsp_init(), tstrWifiInitParam::pfAppWifiCb, registerSocketCallback(), resolve_cb(), socket_cb(), socketInit(), and wifi_cb().
Referenced by main().
void wifi_recieve_packet | ( | void | ) |
References display_is_sha, gau8ReceivedBuffer, gbContinueReceive, gbTcpConnection, gcWeatherInfo, MAIN_WIFI_M2M_BUFFER_SIZE, NULL, parse_weather_icon(), pcCity, pcTemperature, pcWeather, recv(), tcp_client_socket, Temperature_seoul, Temperature_sha, ucWeatherNum, ucWeatherNum_seoul, ucWeatherNum_sha, Weather_seoul, and Weather_sha.
Referenced by main().
|
static |
References gau8ReceivedBuffer, MAIN_APP_ID, MAIN_POST_BUFFER, MAIN_PREFIX_BUFFER, MAIN_WIFI_M2M_BUFFER_SIZE, recv(), send(), and tcp_client_socket.
Referenced by main().
Referenced by main(), refresh_display(), and wifi_recieve_packet().
struct ili9488_opt_t g_ili9488_display_opt |
uint32_t g_ul_sec_ticks = 0 |
Referenced by main(), RTT_Handler(), and socket_cb().
|
static |
Receive buffer definition.
Referenced by wifi_recieve_packet(), and wifi_require_weather().
Continue Receive status variable.
Referenced by wifi_recieve_packet().
Weather client status variable.
Referenced by main(), and socket_cb().
Get host IP status variable.
Referenced by main(), and resolve_cb().
Referenced by main(), and socket_cb().
TCP Connection status variable.
Referenced by main(), socket_cb(), and wifi_recieve_packet().
|
static |
Referenced by socket_cb(), and wifi_recieve_packet().
uint32_t gu32HostIp = 0 |
IP address of host.
char* gWeatherIcon[4] |
Referenced by refresh_display().
const uint8_t mark[11] = {'S', 'A', 'M', 'E','7', '0', 'D', 'E', 'M','O'} |
Referenced by wifi_connect().
char* pcCity = NULL |
Referenced by wifi_recieve_packet().
char* pcTemperature = NULL |
Referenced by wifi_recieve_packet().
char* pcWeather = NULL |
Referenced by parse_weather_icon(), and wifi_recieve_packet().
|
static |
Server host name.
Referenced by wifi_cb().
|
static |
TCP client socket handlers.
Referenced by main(), socket_cb(), wifi_recieve_packet(), and wifi_require_weather().
char Temperature_seoul[30] |
Referenced by refresh_display(), and wifi_recieve_packet().
char Temperature_sha[30] |
Referenced by refresh_display(), and wifi_recieve_packet().
uint8_t ucWeatherNum = 0 |
Referenced by wifi_recieve_packet().
uint8_t ucWeatherNum_seoul |
Referenced by refresh_display(), and wifi_recieve_packet().
uint8_t ucWeatherNum_sha |
Referenced by refresh_display(), and wifi_recieve_packet().
char Weather_seoul[30] |
Referenced by refresh_display(), and wifi_recieve_packet().
char Weather_sha[30] |
Referenced by refresh_display(), and wifi_recieve_packet().