mirror of
https://github.com/pvvx/RTL00_WEB.git
synced 2025-07-31 20:31:05 +00:00
update
This commit is contained in:
parent
34d3652711
commit
39f77eb92b
1844 changed files with 899433 additions and 7 deletions
81
USDK/component/common/example/bcast/example_bcast.c
Normal file
81
USDK/component/common/example/bcast/example_bcast.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
|
||||
static void example_bcast_thread(void *param)
|
||||
{
|
||||
int socket = -1;
|
||||
int broadcast = 1;
|
||||
struct sockaddr_in bindAddr;
|
||||
uint16_t port = 49152;
|
||||
unsigned char packet[1024];
|
||||
|
||||
// Create socket
|
||||
if((socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
printf("ERROR: socket failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Set broadcast socket option
|
||||
if(setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) < 0){
|
||||
printf("ERROR: setsockopt failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Set the bind address
|
||||
memset(&bindAddr, 0, sizeof(bindAddr));
|
||||
bindAddr.sin_family = AF_INET;
|
||||
bindAddr.sin_port = htons(port);
|
||||
bindAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
if(bind(socket, (struct sockaddr *) &bindAddr, sizeof(bindAddr)) < 0){
|
||||
printf("ERROR: bind failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
while(1) {
|
||||
// Receive broadcast
|
||||
int packetLen;
|
||||
struct sockaddr from;
|
||||
struct sockaddr_in *from_sin = (struct sockaddr_in*) &from;
|
||||
socklen_t fromLen = sizeof(from);
|
||||
|
||||
if((packetLen = recvfrom(socket, &packet, sizeof(packet), 0, &from, &fromLen)) >= 0) {
|
||||
uint8_t *ip = (uint8_t *) &from_sin->sin_addr.s_addr;
|
||||
uint16_t from_port = ntohs(from_sin->sin_port);
|
||||
printf("recvfrom - %d bytes from %d.%d.%d.%d:%d\n", packetLen, ip[0], ip[1], ip[2], ip[3], from_port);
|
||||
}
|
||||
|
||||
// Send broadcast
|
||||
if(packetLen > 0) {
|
||||
int sendLen;
|
||||
struct sockaddr to;
|
||||
struct sockaddr_in *to_sin = (struct sockaddr_in*) &to;
|
||||
to_sin->sin_family = AF_INET;
|
||||
to_sin->sin_port = htons(port);
|
||||
to_sin->sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if((sendLen = sendto(socket, packet, packetLen, 0, &to, sizeof(struct sockaddr))) < 0)
|
||||
printf("ERROR: sendto broadcast\n");
|
||||
else
|
||||
printf("sendto - %d bytes to broadcast:%d\n", sendLen, port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
err:
|
||||
printf("ERROR: broadcast example failed\n");
|
||||
close(socket);
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
void example_bcast(void)
|
||||
{
|
||||
if(xTaskCreate(example_bcast_thread, ((const char*)"example_bcast_thread"), 2048, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
6
USDK/component/common/example/bcast/example_bcast.h
Normal file
6
USDK/component/common/example/bcast/example_bcast.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_BCAST_H
|
||||
#define EXAMPLE_BCAST_H
|
||||
|
||||
void example_bcast(void);
|
||||
|
||||
#endif /* EXAMPLE_BCAST_H */
|
||||
28
USDK/component/common/example/bcast/readme.txt
Normal file
28
USDK/component/common/example/bcast/readme.txt
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
LWIP BROADCAST EXAMPLE
|
||||
|
||||
Description:
|
||||
Listen broadcast message on port 49152.
|
||||
Send packet with the content of received packet to broadcast address.
|
||||
|
||||
Configuration:
|
||||
[lwipopts.h]
|
||||
#define LWIP_UDP 1
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_BCAST 1
|
||||
|
||||
Execution:
|
||||
Can make automatical Wi-Fi connection when booting by using wlan fast connect example.
|
||||
A broadcast example thread will be started automatically when booting.
|
||||
|
||||
Test:
|
||||
1. Prepare a NB and connect to the same AP Ameba connected.
|
||||
2. NB: iperf -c 192.168.1.255 -t 60 -i 1 -p 49152 -u
|
||||
3. The recv/send messages should be printed out on Ameba console.
|
||||
4. Use sniffer to make sure the packets send from Ameba are broadcast messages.
|
||||
|
||||
Note:
|
||||
If you encounter some message like:
|
||||
ERROR: sendto broadcast
|
||||
[Driver]: skb_unavailable=1 in last 2 seconds
|
||||
It means that the skb buffer is not enough for the massive UDP packets to be sent.
|
||||
If you want to prevent the error you can add some delay time between sending packets or enlarge the skb buffer configuration.
|
||||
84
USDK/component/common/example/cJSON/cJSON_example.c
Normal file
84
USDK/component/common/example/cJSON/cJSON_example.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "cmsis_os.h"
|
||||
#include <cJSON.h>
|
||||
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
|
||||
/* The data structure for this example
|
||||
|
||||
{
|
||||
"Motion_Sensor" : "i",
|
||||
"Light" : {
|
||||
"Red" : "0",
|
||||
"Green" : "0",
|
||||
"Blue" : "0",
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
static void gen_json_data(int i, int r, int g, int b)
|
||||
{
|
||||
|
||||
|
||||
cJSON_Hooks memoryHook;
|
||||
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
|
||||
|
||||
cJSON *IOTJSObject = NULL, *colorJSObject = NULL;
|
||||
char *iot_json = NULL;
|
||||
|
||||
if((IOTJSObject = cJSON_CreateObject()) != NULL) {
|
||||
|
||||
cJSON_AddItemToObject(IOTJSObject, "Motion_Sensor", cJSON_CreateNumber(i));
|
||||
cJSON_AddItemToObject(IOTJSObject, "Light", colorJSObject = cJSON_CreateObject());
|
||||
|
||||
cJSON_AddItemToObject(colorJSObject, "Red", cJSON_CreateNumber(r));
|
||||
cJSON_AddItemToObject(colorJSObject, "Green", cJSON_CreateNumber(g));
|
||||
cJSON_AddItemToObject(colorJSObject, "Blue", cJSON_CreateNumber(b));
|
||||
|
||||
iot_json = cJSON_Print(IOTJSObject);
|
||||
cJSON_Delete(IOTJSObject);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void handle_json_data(char *iot_json)
|
||||
{
|
||||
cJSON_Hooks memoryHook;
|
||||
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
|
||||
|
||||
cJSON *IOTJSObject, *sensorJSObject, *lightJSObject, *redJSObject, *greenJSObject, *blueJSObject;
|
||||
int sensor_data, red, green, blue;
|
||||
|
||||
if((IOTJSObject = cJSON_Parse(iot_json)) != NULL) {
|
||||
sensorJSObject = cJSON_GetObjectItem(IOTJSObject, "Motion_Sensor");
|
||||
if(sensorJSObject)
|
||||
sensor_data = sensorJSObject->valueint;
|
||||
|
||||
lightJSObject = cJSON_GetObjectItem(IOTJSObject, "Light");
|
||||
|
||||
if(lightJSObject){
|
||||
redJSObject = cJSON_GetObjectItem(lightJSObject, "Red");
|
||||
greenJSObject = cJSON_GetObjectItem(lightJSObject, "Green");
|
||||
blueJSObject = cJSON_GetObjectItem(lightJSObject, "Blue");
|
||||
|
||||
if(redJSObject)
|
||||
red = redJSObject->valueint;
|
||||
if(greenJSObject)
|
||||
green = greenJSObject->valueint;
|
||||
if(blueJSObject)
|
||||
blue = blueJSObject->valueint;
|
||||
}
|
||||
|
||||
cJSON_Delete(IOTJSObject);
|
||||
}
|
||||
}
|
||||
16
USDK/component/common/example/dct/README.txt
Normal file
16
USDK/component/common/example/dct/README.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
DCT example
|
||||
|
||||
Description:
|
||||
This example shows device configuration table API usage, and user can use DCT api to replace file system.
|
||||
|
||||
Configuration:
|
||||
1. [platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_DCT 1
|
||||
|
||||
Execution:
|
||||
it will show:
|
||||
variable0: value0
|
||||
variable1: value1
|
||||
Delete variable0 success.
|
||||
Remaining amount: 61
|
||||
if DCT is correctly used.
|
||||
85
USDK/component/common/example/dct/example_dct.c
Normal file
85
USDK/component/common/example/dct/example_dct.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <basic_types.h>
|
||||
#include <platform_opts.h>
|
||||
#include <dct/dct.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_DCT
|
||||
|
||||
#define DCT_BEGIN_ADDR 0x100000 /*!< DCT begin address of flash, ex: 0x100000 = 1M */
|
||||
#define MODULE_NUM 6 /*!< max number of module */
|
||||
#define VARIABLE_NAME_SIZE 32 /*!< max size of the variable name */
|
||||
#define VARIABLE_VALUE_SIZE 32 /*!< max size of the variable value */
|
||||
|
||||
static char example_dct_module[] = "dct_test_module";
|
||||
static char example_dct_variable0[] = "variable0";
|
||||
static char example_dct_variable1[] = "variable1";
|
||||
static char example_dct_value0[] = "value0";
|
||||
static char example_dct_value1[] = "value1";
|
||||
|
||||
void example_dct_thread(void* param){
|
||||
int32_t ret = -1;
|
||||
dct_handle_t dct_handle;
|
||||
char value[16];
|
||||
|
||||
// format DCT, use for the first time
|
||||
ret = dct_format(DCT_BEGIN_ADDR, MODULE_NUM, VARIABLE_NAME_SIZE, VARIABLE_VALUE_SIZE, 1);
|
||||
|
||||
// initial DCT
|
||||
ret = dct_init(DCT_BEGIN_ADDR);
|
||||
|
||||
// register module
|
||||
ret = dct_register_module(example_dct_module);
|
||||
|
||||
// open module
|
||||
ret = dct_open_module(&dct_handle, example_dct_module);
|
||||
|
||||
if(ret == DCT_SUCCESS){
|
||||
// set test variable 0
|
||||
ret = dct_set_variable(&dct_handle, example_dct_variable0, example_dct_value0);
|
||||
|
||||
// set test variable 1
|
||||
ret = dct_set_variable(&dct_handle, example_dct_variable1, example_dct_value1);
|
||||
|
||||
// get value of test variable 0
|
||||
memset(value, 0, sizeof(value));
|
||||
ret = dct_get_variable(&dct_handle, example_dct_variable0, value, sizeof(value));
|
||||
if(ret == DCT_SUCCESS)
|
||||
printf("%s: %s\n", example_dct_variable0, value);
|
||||
|
||||
// get value of test variable 1
|
||||
memset(value, 0, sizeof(value));
|
||||
ret = dct_get_variable(&dct_handle, example_dct_variable1, value, sizeof(value));
|
||||
if(ret == DCT_SUCCESS)
|
||||
printf("%s: %s\n", example_dct_variable1, value);
|
||||
|
||||
// delete test variable 0
|
||||
ret = dct_delete_variable(&dct_handle, example_dct_variable0);
|
||||
|
||||
// get value of test variable 0
|
||||
memset(value, 0, sizeof(value));
|
||||
ret = dct_get_variable(&dct_handle, example_dct_variable0, value, sizeof(value));
|
||||
if(ret == DCT_ERR_NOT_FIND)
|
||||
printf("Delete %s success.\n", example_dct_variable0);
|
||||
|
||||
// get variable remaining amount
|
||||
ret = dct_remain_variable(&dct_handle);
|
||||
if(ret > 0)
|
||||
printf("Remaining variable amount:%d\n", ret);
|
||||
|
||||
// close module
|
||||
ret = dct_close_module(&dct_handle);
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
void example_dct(void)
|
||||
{
|
||||
if(xTaskCreate(example_dct_thread, ((const char*)"example_dct_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(example_dct_thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
#endif // #if CONFIG_DCT
|
||||
7
USDK/component/common/example/dct/example_dct.h
Normal file
7
USDK/component/common/example/dct/example_dct.h
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef _EXAMPLE_DCT_H
|
||||
#define _EXAMPLE_DCT_H
|
||||
|
||||
void example_dct(void);
|
||||
|
||||
#endif /* _EXAMPLE_DCT_H */
|
||||
|
||||
164
USDK/component/common/example/eap/example_eap.c
Normal file
164
USDK/component/common/example/eap/example_eap.c
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
#include <platform_opts.h>
|
||||
#include <eap/example_eap.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_EAP
|
||||
|
||||
// get config arguments from wifi_eap_config.c
|
||||
extern char *eap_target_ssid;
|
||||
extern char *eap_identity;
|
||||
extern char *eap_password;
|
||||
extern const unsigned char *eap_ca_cert;
|
||||
extern const unsigned char *eap_client_cert;
|
||||
extern const unsigned char *eap_client_key;
|
||||
extern char *eap_client_key_pwd;
|
||||
|
||||
void example_eap_config(void){
|
||||
eap_target_ssid = "Test_eap";
|
||||
eap_identity = "guest2";
|
||||
eap_password = "test2";
|
||||
|
||||
/*
|
||||
Set client cert is only used for EAP-TLS connection.
|
||||
If you are not using EAP-TLS method, no need to set eap_client_cert and eap_client_key value. (leave them to NULL value)
|
||||
*/
|
||||
/*
|
||||
eap_client_cert = \
|
||||
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||
"MIIC9TCCAd0CAQIwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNVBAYTAkZSMQ8wDQYD\r\n" \
|
||||
"VQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhhbXBs\r\n" \
|
||||
"ZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQGA1UE\r\n" \
|
||||
"AxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzE0MTEzNjMy\r\n" \
|
||||
"WhcNMTcwMzE0MTEzNjMyWjBxMQswCQYDVQQGEwJGUjEPMA0GA1UECBMGUmFkaXVz\r\n" \
|
||||
"MRUwEwYDVQQKEwxFeGFtcGxlIEluYy4xGTAXBgNVBAMUEHVzZXJAZXhhbXBsZS5j\r\n" \
|
||||
"b20xHzAdBgkqhkiG9w0BCQEWEHVzZXJAZXhhbXBsZS5jb20wgZ8wDQYJKoZIhvcN\r\n" \
|
||||
"AQEBBQADgY0AMIGJAoGBAODvCWRRjVQnUyQS/OqHS8MA94Dc5UOtLagKTOMJayB5\r\n" \
|
||||
"3MZyreWBkNg6sDfDG6OSD9tkVzwcp8CtZNflJc3i+d+nAnPM+kJedPJN5YVO+uwc\r\n" \
|
||||
"+K+QObH7fEOq8hnFIvOtYOfnMAxQKaVIKk0EOqqQv06BDvLyxoDCZNpAn4NQ8ZkR\r\n" \
|
||||
"AgMBAAEwDQYJKoZIhvcNAQEEBQADggEBAItqpmFftRu8ugTy4fRFwpjJNUuMRe83\r\n" \
|
||||
"Pm5Dv3V/byCHHdmIy0UI+6ZiMEtYrpvz4ZPgk0BDeytYooT7/kEUb8niQ64bDLYo\r\n" \
|
||||
"NcXctCmn5fjyX2M6Z3lQXCxX0XdFiukWlR21w4HO0nx7OJjrcjdpP9Tyk/kzCFl7\r\n" \
|
||||
"pblIavkfSmFtcxzcp0IoCupkUjFkA+MftZF82eQx4bE0jjiw2KgGwnzyYAdgtFXv\r\n" \
|
||||
"Ednj3ZyOuTlOQNGJgLQxyHooEJ/Tol/8p9EO5S6eQaHgZhbGP3AZ3SWV5oA0e6eT\r\n" \
|
||||
"D5JXti/LhyZhcbbJFawGXFI96ZOpHJ0EW12Osx/21oqmMp12AotS5Vw=\r\n" \
|
||||
"-----END CERTIFICATE-----\r\n";
|
||||
eap_client_key = \
|
||||
"-----BEGIN RSA PRIVATE KEY-----\r\n" \
|
||||
"Proc-Type: 4,ENCRYPTED\r\n" \
|
||||
"DEK-Info: DES-EDE3-CBC,79675299AD6E2237\r\n" \
|
||||
"\r\n" \
|
||||
"ZYY2hv1PYEsrhYbCip98XNpS6XxbntynEEp6aO9UgWeQ4I1pNOUptPUE+yNhbA7X\r\n" \
|
||||
"59ueT3yzx5L2ObImlJ3eIEvWq+iB8DdcPqFAo3c4dgfw/wPEhmxVPKvIyDQfaEuA\r\n" \
|
||||
"kWUno6b07n5uLTpQjIXQSdMTMYjYS+yPQy7ONC/vl/Ce+RMzrQAZkp5xcNNarUpl\r\n" \
|
||||
"2J1D2t+eRih/zRrgeVXztMiW2uyIT5a0IPoeBTPkPVb00kWYzn8eT9doN/ZCyr83\r\n" \
|
||||
"mv/uXF5ZOHnSNleOn1NiCZ8Uu3SHnmGhMBBMI75OghpEezQQCmtefYvtRxzGjMVB\r\n" \
|
||||
"UoRIlbATAleUjk3bmqRxfA2QZJj/GFWc9grxEerHWrdThSQ0w+fvwKBjTmEtUO2+\r\n" \
|
||||
"stKBJQi9RKFq4naM8UhtxojHIscXCx/wKrRZHS4QJYOQYelzfhTRUuTf3Czm/iTh\r\n" \
|
||||
"MQvX7dITNlLE3SW2MjzHb2ON9qUaKVnQPk53DO1zYgoxgDbQrw6FXDNMtYVv8SYf\r\n" \
|
||||
"JJZp66jGX6e1t4ziPHVqlDi5D2nWQ2DPNHO/rsoydA7icncKsC0iVzeUm7XgesxD\r\n" \
|
||||
"QEZoQIQDVS1aRE7qJCk9S2Hfe5Gfqnrp4110YuN/4khjMW2cOCKa/Yjgjyy2QQXT\r\n" \
|
||||
"nn6dBAeSWGzRM059VzhOyls5FIfnJIisZvF3JG518SzBU/YUGHEVN1XsfDS2M9/q\r\n" \
|
||||
"VkqhJ8/vbmIddKGeYULYW+xs3LvU1hnWiOodd9tuSeg5PxAbkJsV1nW06mVkgBqA\r\n" \
|
||||
"zqqEvwvY+6+9QW4PClKNKSocvM6yC+uhRi0sOZ+ckOv7f+uuMyw5FQ==\r\n" \
|
||||
"-----END RSA PRIVATE KEY-----\r\n";
|
||||
eap_client_key_pwd = "testca";
|
||||
*/
|
||||
eap_client_cert = \
|
||||
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||
"MIIC9zCCAd8CAQMwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNVBAYTAkZSMQ8wDQYD\r\n" \
|
||||
"VQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhhbXBs\r\n" \
|
||||
"ZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQGA1UE\r\n" \
|
||||
"AxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzE1MDgwNzEx\r\n" \
|
||||
"WhcNMTcwMzE1MDgwNzExWjBzMQswCQYDVQQGEwJGUjEPMA0GA1UECBMGUmFkaXVz\r\n" \
|
||||
"MRUwEwYDVQQKEwxFeGFtcGxlIEluYy4xGjAYBgNVBAMUEXVzZXIyQGV4YW1wbGUu\r\n" \
|
||||
"Y29tMSAwHgYJKoZIhvcNAQkBFhF1c2VyMkBleGFtcGxlLmNvbTCBnzANBgkqhkiG\r\n" \
|
||||
"9w0BAQEFAAOBjQAwgYkCgYEAqESlV4OYfBcIgZ+Cs8mWpiBjhvKoa0/kIe7saqhC\r\n" \
|
||||
"e5q4snox0jdkUpLcc4vOs3vQ7ZGnimqTltA9oF6XNUzTWW4vlJTKEfrCWK085l7c\r\n" \
|
||||
"DHFvHavH3E6vuP71lI7jq4PLXbo2TvZK+uBul4ozjzVWihaZBtz8eLHq446h/D/p\r\n" \
|
||||
"kzkCAwEAATANBgkqhkiG9w0BAQQFAAOCAQEAAfhVAIkNdeeUNJud720uUHVnIcxz\r\n" \
|
||||
"GXWI+Svi1qchuTEnRNhLwXmnE+A0WWSHyfdR6FvzdT3xtz3K50iOif8jY2gCGkSK\r\n" \
|
||||
"8RjKr97228SwbrGO9y9+dYIjH1uz9cBpoVKcpzdsWpKObrDPDYyReHSWo99jM2+O\r\n" \
|
||||
"vfJxnBw4PLiBj7Q0/dpd6o4JXyp7Cxa0mB4/+cZqjCzzuKfuK3WP7j6laMCV6mg4\r\n" \
|
||||
"wRZ528IdwDqB7OOqsDm1PVQM8vzny9PM6ikWUCRTVNQJN8RDLkrHR3FRjy15YLdt\r\n" \
|
||||
"yOfDqVnT/z0wGBaxnNziSJjqPGHPpRi4bJFGXwXOhtknKmciKzfj9/npoQ==\r\n" \
|
||||
"-----END CERTIFICATE-----\r\n";
|
||||
eap_client_key = \
|
||||
"-----BEGIN RSA PRIVATE KEY-----\r\n" \
|
||||
"MIICXQIBAAKBgQCoRKVXg5h8FwiBn4KzyZamIGOG8qhrT+Qh7uxqqEJ7mriyejHS\r\n" \
|
||||
"N2RSktxzi86ze9DtkaeKapOW0D2gXpc1TNNZbi+UlMoR+sJYrTzmXtwMcW8dq8fc\r\n" \
|
||||
"Tq+4/vWUjuOrg8tdujZO9kr64G6XijOPNVaKFpkG3Px4serjjqH8P+mTOQIDAQAB\r\n" \
|
||||
"AoGARI+LyweshssfxSkIKVc3EcNaqi6PHwJzUrw2ChM624AkR1xwllXJg7ehKVdK\r\n" \
|
||||
"xmjprRLO8CASuL1qjsBb3fTKnBl+sIVxIFS0AI4Y3ri8VUKbangvSsI7pCzAFry7\r\n" \
|
||||
"p1gmy9WWRV2ZEa+dV8xcrjb3bloT7hcdeLehgBCvExJIQM0CQQDXlSAKdW3AhYyj\r\n" \
|
||||
"1A+pfyBSGxJbpSwNyyWgwHIHHjxendxmdUbrc8EbAu1eNKbP58TLgdCZsKcMonAv\r\n" \
|
||||
"MY1Y2/nnAkEAx9CrUaCU8pJqXTRypM5JtexLKnYMJhpnA9uUILBQOq4Oe0eruyF5\r\n" \
|
||||
"SaSxhyJYXY491ahWYPF0PTb3jkUhoN+l3wJBAJZthjgGDJlEFwjSFkOtYz4nib3N\r\n" \
|
||||
"GVpeoFj1MBvrazCScpJDz0LIOLzCZCNSFfwIu3dNk+NKMqZMSn+D0h9pD40CQQC5\r\n" \
|
||||
"K9n4NXaTLbjAU2CC9mE85JPr76XmkcUxwAWQHZTcLH1jJdIyAx1hb+zNLLjzSmRn\r\n" \
|
||||
"Yi9ae6ibKhtUjyBQ87HFAkA2Bb3z7NUx+AA2g2HZocFZFShBxylACyQkl8FAFZtf\r\n" \
|
||||
"osudmKdFQHyAWuBMex4tpz/OLTqJ1ecL1JQeC7OvlpEX\r\n" \
|
||||
"-----END RSA PRIVATE KEY-----\r\n";
|
||||
|
||||
/*
|
||||
Verify server's certificate is an optional feature.
|
||||
If you want to use it please make sure ENABLE_EAP_SSL_VERIFY_SERVER in platform_opts.h is set to 1,
|
||||
and the eap_ca_cert is set correctly.
|
||||
*/
|
||||
eap_ca_cert = \
|
||||
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||
"MIIEpzCCA4+gAwIBAgIJAPvZaozpdfjkMA0GCSqGSIb3DQEBCwUAMIGTMQswCQYD\r\n" \
|
||||
"VQQGEwJGUjEPMA0GA1UECBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTAT\r\n" \
|
||||
"BgNVBAoTDEV4YW1wbGUgSW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBs\r\n" \
|
||||
"ZS5jb20xJjAkBgNVBAMTHUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4X\r\n" \
|
||||
"DTE2MDMxNDExMjU0OVoXDTE2MDQxMzExMjU0OVowgZMxCzAJBgNVBAYTAkZSMQ8w\r\n" \
|
||||
"DQYDVQQIEwZSYWRpdXMxEjAQBgNVBAcTCVNvbWV3aGVyZTEVMBMGA1UEChMMRXhh\r\n" \
|
||||
"bXBsZSBJbmMuMSAwHgYJKoZIhvcNAQkBFhFhZG1pbkBleGFtcGxlLmNvbTEmMCQG\r\n" \
|
||||
"A1UEAxMdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0GCSqGSIb3\r\n" \
|
||||
"DQEBAQUAA4IBDwAwggEKAoIBAQC9pireu0aCDLNfMaGv3vId7RXjUhQwSK0jV2Oc\r\n" \
|
||||
"SyvlKWH3P/N+5kLrP2iL6SCzyETVDXZ0vOsAMjcBF0zHp16prXV0d51cTUqeWBb0\r\n" \
|
||||
"I5UnGxleIuuOfSg8zLUJoBWZPqLv++eZ5WgOKHt7SXocjvg7TU5t/TMB0Y8OCz3H\r\n" \
|
||||
"CW2vJ/XKMgMA9HDUu4g57cJu88i1JPRpyFaz/HIQBc7+UNb9z+q09uTZKWTmEMqi\r\n" \
|
||||
"E2U0EEIs7EtbxnOze1/8C4XNlmztrEdwvu6UEBU/TFkUoh9M646NkkBK7wP9n9pv\r\n" \
|
||||
"T0nPQRJiiCrICzVqUtlEi9lIKpbBSMbQ0KzrGF7lGTgm4rz9AgMBAAGjgfswgfgw\r\n" \
|
||||
"HQYDVR0OBBYEFIVyecka74kvOKIW0BjlTc/B+a2NMIHIBgNVHSMEgcAwgb2AFIVy\r\n" \
|
||||
"ecka74kvOKIW0BjlTc/B+a2NoYGZpIGWMIGTMQswCQYDVQQGEwJGUjEPMA0GA1UE\r\n" \
|
||||
"CBMGUmFkaXVzMRIwEAYDVQQHEwlTb21ld2hlcmUxFTATBgNVBAoTDEV4YW1wbGUg\r\n" \
|
||||
"SW5jLjEgMB4GCSqGSIb3DQEJARYRYWRtaW5AZXhhbXBsZS5jb20xJjAkBgNVBAMT\r\n" \
|
||||
"HUV4YW1wbGUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5ggkA+9lqjOl1+OQwDAYDVR0T\r\n" \
|
||||
"BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAZYHM26sxbKOckVqJJ1QY0U2QFlGP\r\n" \
|
||||
"1GYd8v27znxdnRmSonDvv3GjFfhwoyDk0JUuxkK/33ikCxihrgoO/EQTY9BV2OpW\r\n" \
|
||||
"qkB1PDtb3i5ZRNvfjmW0pVA4p+GmdTGaEE5pTlcVnorzVrUeFKaZakb+IDFYzmeF\r\n" \
|
||||
"xp8B3Bb5wvinDligLOaJnSlgS8QeeIab9HZfaVTTuPmVK6zE6D54Y0dJPnykvDdE\r\n" \
|
||||
"cGN0FC+migfilFjJgkDJ0r78nwes55L8zjoofiZuO03rrHww6ARc3v1jYzAufddk\r\n" \
|
||||
"QTiZHgjlMQb2XXMmXLn8kBgoDnqkXFNe8j0h8uxIJSrjOoIyn1h1wvX5/w==\r\n" \
|
||||
"-----END CERTIFICATE-----\r\n";
|
||||
|
||||
}
|
||||
|
||||
static void example_eap_thread(void *method){
|
||||
example_eap_config();
|
||||
|
||||
if(strcmp(method, "tls") == 0){
|
||||
// tls must present client_cert, client_key
|
||||
eap_start("tls");
|
||||
}
|
||||
else if(strcmp(method, "peap") == 0){
|
||||
eap_start("peap");
|
||||
}
|
||||
else if(strcmp(method, "ttls") == 0){
|
||||
eap_start("ttls");
|
||||
}
|
||||
else
|
||||
printf("Invalid method\n");
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_eap(char *method){
|
||||
if(xTaskCreate(example_eap_thread, ((const char*)"example_eap_thread"), 1024, method, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate failed\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_EXAMPLE_EAP */
|
||||
9
USDK/component/common/example/eap/example_eap.h
Normal file
9
USDK/component/common/example/eap/example_eap.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef EXAMPLE_EAP_H
|
||||
#define EXAMPLE_EAP_H
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "platform_opts.h"
|
||||
|
||||
void example_eap(char *method);
|
||||
|
||||
#endif
|
||||
34
USDK/component/common/example/eap/readme.txt
Normal file
34
USDK/component/common/example/eap/readme.txt
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
802.1X EAP METHOD SUPPLICANT EXAMPLE
|
||||
|
||||
Description:
|
||||
Use 802.1X EAP methods to connect to AP and authenticate with backend radius server.
|
||||
Current supported methods are EAP-TLS, PEAPv0/EAP-MSCHAPv2, and EAP-TTLS/MSCHAPv2.
|
||||
|
||||
Configuration:
|
||||
Modify the argument of example_eap() in example_entry.c to set which EAP methods you want to use.
|
||||
Modify the connection config (ssid, identity, password, cert) in example_eap_config() of example_eap.c based on your server's setting.
|
||||
[FreeRTOSConfig.h]
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 70 * 1024 ) )
|
||||
[platform_opts.h]
|
||||
# define CONFIG_EXAMPLE_EAP 1
|
||||
|
||||
// Turn on/off the specified method
|
||||
# define CONFIG_ENABLE_PEAP 1
|
||||
# define CONFIG_ENABLE_TLS 1
|
||||
# define CONFIG_ENABLE_TTLS 1
|
||||
|
||||
// If you want to verify the certificate of radius server, turn this on
|
||||
# define ENABLE_EAP_SSL_VERIFY_SERVER 1
|
||||
|
||||
Execution:
|
||||
An EAP connection thread will be started automatically when booting.
|
||||
|
||||
Note:
|
||||
Please make sure the lib_wps, polarssl, ssl_ram_map are also builded.
|
||||
|
||||
If the connection failed, you can try the following directions to make it work:
|
||||
1. Make sure the config_rsa.h of PolarSSL include the SSL/TLS cipher suite supported by radius server.
|
||||
2. Set a larger value to SSL_MAX_CONTENT_LEN in config_rsa.h
|
||||
3. Increase the FreeRTOS heap in FreeRTOSConfig.h, for example you can increase the heap to 80kbytes:
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 80 * 1024 ) )
|
||||
4. Try to change using SW crypto instead of HW crypto.
|
||||
39
USDK/component/common/example/example_entry.c
Normal file
39
USDK/component/common/example/example_entry.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include <platform_opts.h>
|
||||
#include "main.h"
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#include "uart_atcmd/example_uart_atcmd.h"
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_MDNS
|
||||
#include <mdns/example_mdns.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
Preprocessor of example
|
||||
*/
|
||||
void pre_example_entry(void)
|
||||
{
|
||||
//
|
||||
#if defined(CONFIG_EXAMPLE_WLAN_FAST_CONNECT) && CONFIG_EXAMPLE_WLAN_FAST_CONNECT && !CONFIG_EXAMPLE_UART_ATCMD
|
||||
example_wlan_fast_connect();
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_MDNS
|
||||
example_mdns();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
All of the examples are disabled by default for code size consideration
|
||||
The configuration is enabled in platform_opts.h
|
||||
*/
|
||||
void example_entry(void)
|
||||
{
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
example_uart_atcmd();
|
||||
#endif
|
||||
}
|
||||
8
USDK/component/common/example/example_entry.h
Normal file
8
USDK/component/common/example/example_entry.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef __EXAMPLE_ENTRY_H__
|
||||
#define __EXAMPLE_ENTRY_H__
|
||||
|
||||
|
||||
void example_entry(void);
|
||||
void pre_example_entry(void);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_ENTRY_H__
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include <platform_opts.h>
|
||||
#include <get_beacon_frame/example_get_beacon_frame.h>
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
typedef int (*get_beacon_frame_func_ptr)(BEACON_INFO_T beacon_frame);
|
||||
extern get_beacon_frame_func_ptr get_beacon_frame_callback;
|
||||
|
||||
int get_beacon_frame_func(BEACON_INFO_T beacon_frame)
|
||||
{
|
||||
printf("\nbeacon frame_ctl = %02x %02x\n",beacon_frame.frame_ctl[0],beacon_frame.frame_ctl[1]);
|
||||
printf("\nbeacon duration_id = %02x %02x\n",beacon_frame.duration_id[0],beacon_frame.duration_id[1]);
|
||||
printf("\nbeacon addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",\
|
||||
beacon_frame.addr1[0],beacon_frame.addr1[1],beacon_frame.addr1[2],beacon_frame.addr1[3],beacon_frame.addr1[4],beacon_frame.addr1[5]);
|
||||
printf("\nbeacon addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",\
|
||||
beacon_frame.addr2[0],beacon_frame.addr2[1],beacon_frame.addr2[2],beacon_frame.addr2[3],beacon_frame.addr2[4],beacon_frame.addr2[5]);
|
||||
printf("\nbeacon addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",\
|
||||
beacon_frame.addr3[0],beacon_frame.addr3[1],beacon_frame.addr3[2],beacon_frame.addr3[3],beacon_frame.addr3[4],beacon_frame.addr3[5]);
|
||||
printf("\nbeacon seq_ctl = %02x %02x\n",beacon_frame.seq_ctl[0],beacon_frame.seq_ctl[1]);
|
||||
printf("\nbeacon timestamp = %02x %02x %02x %02x %02x %02x %02x %02x\n",\
|
||||
beacon_frame.timestamp[0],beacon_frame.timestamp[1],beacon_frame.timestamp[2],beacon_frame.timestamp[3],beacon_frame.timestamp[4],beacon_frame.timestamp[5],beacon_frame.timestamp[6],beacon_frame.timestamp[7]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_beacon_frame_thread(void *param)
|
||||
{
|
||||
vTaskDelay(10000);//a rough time for waiting wifi connected
|
||||
//Register callback function until wifi connected
|
||||
get_beacon_frame_callback = get_beacon_frame_func;
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
void example_get_beacon_frame(void)
|
||||
{
|
||||
if(xTaskCreate(get_beacon_frame_thread, ((const char*)"get_beacon_frame_thread"), 256, NULL, tskIDLE_PRIORITY , NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(get_beacon_frame_thread) failed", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef __EXAMPLE_GET_BEACON_FRAME_H__
|
||||
#define __EXAMPLE_GET_BEACON_FRAME_H__
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
typedef struct beacon_info_str{
|
||||
//802.11 MAC header
|
||||
unsigned char frame_ctl[2];
|
||||
unsigned char duration_id[2];
|
||||
unsigned char addr1[6];
|
||||
unsigned char addr2[6];
|
||||
unsigned char addr3[6];
|
||||
unsigned char seq_ctl[2];
|
||||
//802.11 beacon IE
|
||||
unsigned char timestamp[8];
|
||||
}BEACON_INFO_T;
|
||||
|
||||
void example_get_beacon_frame(void);
|
||||
int get_beacon_frame_func(BEACON_INFO_T beacon_frame);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_GET_BEACON_FRAME_H__
|
||||
13
USDK/component/common/example/get_beacon_frame/readme.txt
Normal file
13
USDK/component/common/example/get_beacon_frame/readme.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
GET BEACON FRAME EXAMPLE
|
||||
|
||||
Description:
|
||||
Get beacon frame information in station mode
|
||||
|
||||
Configuration:
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_GET_BEACON_FRAME 1
|
||||
|
||||
Execution:
|
||||
Call example_get_beacon_frame() to create get beacon frame thread.
|
||||
It can collect the beacon of AP in the air.
|
||||
|
||||
38
USDK/component/common/example/googlenest/example.html
Normal file
38
USDK/component/common/example/googlenest/example.html
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="https://cdn.firebase.com/js/client/2.1.1/firebase.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Realtek Google Nest API example</h1>
|
||||
<hr />
|
||||
|
||||
|
||||
<h3 style="text-align:center;margin-left:auto;margin-right:auto;">Data To Device</h3>
|
||||
|
||||
<h4>Input the value of RGB to change the state of light:</h4>
|
||||
<p>Red <input type="text" id="redInput" placeholder="Red" />
|
||||
Green <input type="text" id="greenInput" placeholder="Green" />
|
||||
Blue <input type="text" id="blueInput" placeholder="Blue" />
|
||||
<input type="button" value="submit" name="submit" onClick="submit()" />
|
||||
</p>
|
||||
|
||||
<script>
|
||||
var myDataRef = new Firebase('https://your_firebase_address.firebaseio.com/light');
|
||||
function submit()
|
||||
{
|
||||
var red = $('#redInput').val();
|
||||
var green = $('#greenInput').val();
|
||||
var blue = $('#blueInput').val();
|
||||
myDataRef.set({
|
||||
Red: red,
|
||||
Green: green,
|
||||
Blue: blue
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
185
USDK/component/common/example/googlenest/example_google.c
Normal file
185
USDK/component/common/example/googlenest/example_google.c
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
#include "cmsis_os.h"
|
||||
#include "diag.h"
|
||||
#include "wifi_conf.h"
|
||||
#include "wifi_ind.h"
|
||||
#include "google/google_nest.h"
|
||||
|
||||
|
||||
#include <googlenest/example_google.h>
|
||||
#include "cJSON.h"
|
||||
|
||||
osThreadId google_thread_id;
|
||||
#define malloc pvPortMalloc
|
||||
#define free vPortFree
|
||||
|
||||
void google_data_retrieve(char *response_buf);
|
||||
|
||||
void google_data_retrieve(char *response_buf) {
|
||||
//printf("\r\n\r\n\r\nResponse_buf:\r\n%s\r\n", response_buf);
|
||||
char *event = NULL;
|
||||
char *delims = "\n";
|
||||
char *data = NULL, *backup = NULL;
|
||||
char *info = NULL;
|
||||
cJSON_Hooks memoryHook;
|
||||
|
||||
event = strtok_r(response_buf, delims, &backup);
|
||||
data = strtok_r( NULL, delims, &backup );
|
||||
|
||||
if (!strncmp(data, "data: ", strlen("data: "))){
|
||||
info = data + strlen("data: ");
|
||||
if(info != NULL){
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
|
||||
cJSON *infoJSObject, *pathJSObject, *dataJSObject;
|
||||
cJSON *redJSObject, *greenJSObject, *blueJSObject;
|
||||
char *red, *green, *blue;
|
||||
|
||||
|
||||
if((infoJSObject = cJSON_Parse(info)) != NULL) {
|
||||
pathJSObject = cJSON_GetObjectItem(infoJSObject, "path");
|
||||
dataJSObject = cJSON_GetObjectItem(infoJSObject, "data");
|
||||
if(dataJSObject != NULL) {
|
||||
|
||||
redJSObject = cJSON_GetObjectItem(dataJSObject, "Red");
|
||||
greenJSObject = cJSON_GetObjectItem(dataJSObject, "Green");
|
||||
blueJSObject = cJSON_GetObjectItem(dataJSObject, "Blue");
|
||||
|
||||
if(redJSObject)
|
||||
red = redJSObject->valuestring;
|
||||
|
||||
if(greenJSObject)
|
||||
green = greenJSObject->valuestring;
|
||||
|
||||
if(blueJSObject)
|
||||
blue = blueJSObject->valuestring;
|
||||
|
||||
printf("\n\rThe latest RGB information: RGB(%s, %s, %s)\n\r", red, green, blue);
|
||||
|
||||
cJSON_Delete(dataJSObject);
|
||||
}
|
||||
cJSON_Delete(infoJSObject);
|
||||
}
|
||||
else
|
||||
printf("\r\nCannot parse the message to JSON!\r\n");
|
||||
|
||||
}
|
||||
else
|
||||
printf("\r\n This is the keep alive message or cannot get the information!\r\n");
|
||||
}
|
||||
else
|
||||
printf("\r\nData structure may wrong!\r\n");
|
||||
}
|
||||
|
||||
|
||||
void gn_todevice_start(void) {
|
||||
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_host = HOST_ADDR;
|
||||
char *googlenest_uri = "light.json";
|
||||
|
||||
printf("\r\nStart connecting to Google Nest Server...\r\n");
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
|
||||
reconnect:
|
||||
if(gn_connect(&googlenest, googlenest_host, GN_PORT) == 0) {
|
||||
printf("\r\n Connection is OK!\r\n");
|
||||
|
||||
google_retrieve_data_hook_callback(google_data_retrieve);
|
||||
if(gn_stream(&googlenest, googlenest_uri) != 0){
|
||||
printf("\r\n Connection is fail! \r\n Start Reconnecting...\r\n");
|
||||
goto reconnect;
|
||||
}
|
||||
|
||||
gn_close(&googlenest);
|
||||
|
||||
}
|
||||
else{
|
||||
printf("\r\n Connection is fail! \r\n\r\n\r\n\r\nStart Reconnecting...\r\n");
|
||||
goto reconnect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void gn_fromdevice_start(void) {
|
||||
googlenest_context googlenest;
|
||||
char *googlenest_uri = "MotionSensor.json";
|
||||
cJSON_Hooks memoryHook;
|
||||
int j = 0;
|
||||
|
||||
memoryHook.malloc_fn = malloc;
|
||||
memoryHook.free_fn = free;
|
||||
cJSON_InitHooks(&memoryHook);
|
||||
printf("\r\nStart connecting to Google Nest Server!\r\n");
|
||||
|
||||
while(1) {
|
||||
memset(&googlenest, 0, sizeof(googlenest_context));
|
||||
if(gn_connect(&googlenest, HOST_ADDR, GN_PORT) == 0) {
|
||||
cJSON *MSJSObject;
|
||||
char *data;
|
||||
|
||||
if((MSJSObject = cJSON_CreateObject()) != NULL) {
|
||||
cJSON_AddItemToObject(MSJSObject, "MotionSenser", cJSON_CreateNumber(j++));
|
||||
data = cJSON_Print(MSJSObject);
|
||||
cJSON_Delete(MSJSObject);
|
||||
}
|
||||
|
||||
if(gn_put(&googlenest, googlenest_uri, data) == 0)
|
||||
printf("\n\rUpdate the Motion Sensor's data to %d\n\r", (j-1));
|
||||
free(data);
|
||||
gn_close(&googlenest);
|
||||
}
|
||||
else{
|
||||
printf("\n\rConnection failed!\n\r");
|
||||
break;
|
||||
}
|
||||
|
||||
vTaskDelay(5 * configTICK_RATE_HZ);
|
||||
}
|
||||
}
|
||||
|
||||
void gn_fromdevice_task(void *arg) {
|
||||
int i;
|
||||
|
||||
printf("\n\r\n\r\n\r\n\r<<<<<<Waiting for 2 mins to connect Wi-Fi>>>>>>>\n\r\n\r\n\r\n\r");
|
||||
for (i = 0; i<120; i++)
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
gn_fromdevice_start();
|
||||
}
|
||||
|
||||
void gn_todevice_task(void *arg) {
|
||||
int i;
|
||||
|
||||
printf("\n\r\n\r\n\r\n\r<<<<<<Waiting for 2 mins to connect Wi-Fi>>>>>>>\n\r\n\r\n\r\n\r");
|
||||
for (i = 0; i<120; i++)
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
gn_todevice_start();
|
||||
}
|
||||
|
||||
void example_google(char *type) {
|
||||
|
||||
|
||||
if(strcmp(type, "FromDevice") == 0){
|
||||
osThreadDef_t google_thread;
|
||||
google_thread.instances = 1;
|
||||
google_thread.name = "google thread";
|
||||
google_thread.stacksize = 4096;
|
||||
google_thread.pthread = (os_pthread)gn_fromdevice_task;
|
||||
google_thread.tpriority = tskIDLE_PRIORITY+6;
|
||||
google_thread_id = osThreadCreate(&google_thread, NULL);
|
||||
}
|
||||
else if(strcmp(type, "ToDevice") == 0){
|
||||
osThreadDef_t google_thread;
|
||||
google_thread.instances = 1;
|
||||
google_thread.name = "google thread";
|
||||
google_thread.stacksize = 4096;
|
||||
google_thread.pthread = (os_pthread)gn_todevice_task;
|
||||
google_thread.tpriority = tskIDLE_PRIORITY+6;
|
||||
google_thread_id = osThreadCreate(&google_thread, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
10
USDK/component/common/example/googlenest/example_google.h
Normal file
10
USDK/component/common/example/googlenest/example_google.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef GOOGLE_THREAD_H
|
||||
#define GOOGLE_THREAD_H
|
||||
|
||||
#define HOST_ADDR "your_firebase_address.firebaseio.com"
|
||||
#define GN_PORT 443
|
||||
|
||||
void example_google(char *type);
|
||||
|
||||
|
||||
#endif
|
||||
98
USDK/component/common/example/mcast/example_mcast.c
Normal file
98
USDK/component/common/example/mcast/example_mcast.c
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
extern struct netif xnetif[];
|
||||
|
||||
static void example_mcast_thread(void *param)
|
||||
{
|
||||
#if LWIP_IGMP
|
||||
int err = 0;
|
||||
int socket = -1;
|
||||
char *group_ip = "224.0.0.251";
|
||||
uint16_t port = 5353;
|
||||
|
||||
// Set NETIF_FLAG_IGMP flag for netif which should process IGMP messages
|
||||
xnetif[0].flags |= NETIF_FLAG_IGMP;
|
||||
|
||||
if((socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
printf("ERROR: socket - AF_INET, SOCK_DGRAM\n");
|
||||
err = -1;
|
||||
}
|
||||
|
||||
// Add multicast group membership on this interface
|
||||
if(err == 0) {
|
||||
struct ip_mreq imr;
|
||||
imr.imr_multiaddr.s_addr = inet_addr(group_ip);
|
||||
imr.imr_interface.s_addr = INADDR_ANY;
|
||||
err = setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(imr));
|
||||
if(err < 0) printf("ERROR: setsockopt - IP_ADD_MEMBERSHIP\n");
|
||||
}
|
||||
|
||||
// Specify outgoing interface too
|
||||
if(err == 0) {
|
||||
struct in_addr intfAddr;
|
||||
intfAddr.s_addr = INADDR_ANY;
|
||||
err = setsockopt(socket, IPPROTO_IP, IP_MULTICAST_IF, &intfAddr, sizeof(struct in_addr));
|
||||
if(err < 0) printf("ERROR: setsockopt - IP_MULTICAST_IF\n");
|
||||
}
|
||||
|
||||
// And start listening for packets
|
||||
if(err == 0) {
|
||||
struct sockaddr_in bindAddr;
|
||||
bindAddr.sin_family = AF_INET;
|
||||
bindAddr.sin_port = htons(port);
|
||||
bindAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
err = bind(socket, (struct sockaddr *) &bindAddr, sizeof(bindAddr));
|
||||
if(err < 0) printf("ERROR: bind\n");
|
||||
}
|
||||
|
||||
if(err == 0) {
|
||||
unsigned char packet[1024];
|
||||
|
||||
while(1) {
|
||||
// Receive multicast
|
||||
int packetLen;
|
||||
struct sockaddr from;
|
||||
struct sockaddr_in *from_sin = (struct sockaddr_in*) &from;
|
||||
socklen_t fromLen = sizeof(from);
|
||||
|
||||
if((packetLen = recvfrom(socket, &packet, sizeof(packet), 0, &from, &fromLen)) >= 0) {
|
||||
uint8_t *ip = (uint8_t *) &from_sin->sin_addr.s_addr;
|
||||
uint16_t from_port = ntohs(from_sin->sin_port);
|
||||
printf("recvfrom - %d bytes from %d.%d.%d.%d:%d\n", packetLen, ip[0], ip[1], ip[2], ip[3], from_port);
|
||||
}
|
||||
|
||||
// Send multicast
|
||||
if(packetLen > 0) {
|
||||
int sendLen;
|
||||
struct sockaddr to;
|
||||
struct sockaddr_in *to_sin = (struct sockaddr_in*) &to;
|
||||
to_sin->sin_family = AF_INET;
|
||||
to_sin->sin_port = htons(port);
|
||||
to_sin->sin_addr.s_addr = inet_addr(group_ip);
|
||||
|
||||
if((sendLen = sendto(socket, packet, packetLen, 0, &to, sizeof(struct sockaddr))) < 0)
|
||||
printf("ERROR: sendto %s\n", group_ip);
|
||||
else
|
||||
printf("sendto - %d bytes to %s:%d\n", sendLen, group_ip, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(socket != -1) {
|
||||
close(socket);
|
||||
}
|
||||
#else
|
||||
printf("\nSHOULD ENABLE LWIP_IGMP\n");
|
||||
#endif
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_mcast(void)
|
||||
{
|
||||
if(xTaskCreate(example_mcast_thread, ((const char*)"example_mcast_thread"), 2048, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
6
USDK/component/common/example/mcast/example_mcast.h
Normal file
6
USDK/component/common/example/mcast/example_mcast.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_MCAST_H
|
||||
#define EXAMPLE_MCAST_H
|
||||
|
||||
void example_mcast(void);
|
||||
|
||||
#endif /* EXAMPLE_MCAST_H */
|
||||
17
USDK/component/common/example/mcast/readme.txt
Normal file
17
USDK/component/common/example/mcast/readme.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
LWIP MULTICAST EXAMPLE
|
||||
|
||||
Description:
|
||||
Join multicast group of 224.0.0.251 and listen on port 5353.
|
||||
Send packet with the content of received packet to multicast group of 224.0.0.251.
|
||||
|
||||
Configuration:
|
||||
[lwipopts.h]
|
||||
#define LWIP_UDP 1
|
||||
#define LWIP_IGMP 1
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_MCAST 1
|
||||
|
||||
Execution:
|
||||
Can make automatical Wi-Fi connection when booting by using wlan fast connect example.
|
||||
A multicast example thread will be started automatically when booting.
|
||||
|
||||
55
USDK/component/common/example/mdns/example_mdns.c
Normal file
55
USDK/component/common/example/mdns/example_mdns.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include <mDNS/mDNS.h>
|
||||
|
||||
#include <lwip_netconf.h>
|
||||
#include <lwip/netif.h>
|
||||
extern struct netif xnetif[];
|
||||
|
||||
static void example_mdns_thread(void *param)
|
||||
{
|
||||
DNSServiceRef dnsServiceRef = NULL;
|
||||
TXTRecordRef txtRecord;
|
||||
unsigned char txt_buf[100]; // use fixed buffer for text record to prevent malloc/free
|
||||
|
||||
// Delay to wait for IP by DHCP
|
||||
vTaskDelay(10000);
|
||||
|
||||
printf("\nmDNS Init\n");
|
||||
if(mDNSResponderInit() == 0) {
|
||||
printf("mDNS Register service\n");
|
||||
TXTRecordCreate(&txtRecord, sizeof(txt_buf), txt_buf);
|
||||
TXTRecordSetValue(&txtRecord, "text1", strlen("text1_content"), "text1_content");
|
||||
TXTRecordSetValue(&txtRecord, "text2", strlen("text2_content"), "text2_content");
|
||||
dnsServiceRef = mDNSRegisterService("ameba", "_service1._tcp", "local", 5000, &txtRecord);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
printf("wait for 30s ... \n");
|
||||
vTaskDelay(30*1000);
|
||||
|
||||
printf("mDNS Update service\n");
|
||||
TXTRecordCreate(&txtRecord, sizeof(txt_buf), txt_buf);
|
||||
TXTRecordSetValue(&txtRecord, "text1", strlen("text1_content_new"), "text1_content_new");
|
||||
mDNSUpdateService(dnsServiceRef, &txtRecord, 0);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
printf("wait for 30s ... \n");
|
||||
vTaskDelay(30*1000);
|
||||
|
||||
if(dnsServiceRef)
|
||||
mDNSDeregisterService(dnsServiceRef);
|
||||
|
||||
// deregister service before mdns deinit is not necessary
|
||||
// mDNS deinit will also deregister all services
|
||||
printf("mDNS Deinit\n");
|
||||
mDNSResponderDeinit();
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_mdns(void)
|
||||
{
|
||||
if(xTaskCreate(example_mdns_thread, ((const char*)"example_mdns_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
6
USDK/component/common/example/mdns/example_mdns.h
Normal file
6
USDK/component/common/example/mdns/example_mdns.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_MDNS_H
|
||||
#define EXAMPLE_MDNS_H
|
||||
|
||||
void example_mdns(void);
|
||||
|
||||
#endif /* EXAMPLE_MDNS_H */
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
#if LWIP_SOCKET
|
||||
|
||||
#define MAX_SOCKETS 10
|
||||
#define SELECT_TIMEOUT 10
|
||||
#define SERVER_PORT 5000
|
||||
#define LISTEN_QLEN 2
|
||||
|
||||
static void example_socket_select_thread(void *param)
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
int server_fd = -1;
|
||||
int socket_used[10];
|
||||
|
||||
memset(socket_used, 0, sizeof(socket_used));
|
||||
|
||||
if((server_fd = socket(AF_INET, SOCK_STREAM, 0)) >= 0) {
|
||||
socket_used[server_fd] = 1;
|
||||
}
|
||||
else {
|
||||
printf("socket error\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons(SERVER_PORT);
|
||||
server_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
if(bind(server_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)) != 0) {
|
||||
printf("bind error\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(listen(server_fd, LISTEN_QLEN) != 0) {
|
||||
printf("listen error\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
int socket_fd;
|
||||
unsigned char buf[512];
|
||||
fd_set read_fds;
|
||||
struct timeval timeout;
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
timeout.tv_sec = SELECT_TIMEOUT;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
for(socket_fd = 0; socket_fd < MAX_SOCKETS; socket_fd ++)
|
||||
if(socket_used[socket_fd])
|
||||
FD_SET(socket_fd, &read_fds);
|
||||
|
||||
if(select(MAX_SOCKETS, &read_fds, NULL, NULL, &timeout)) {
|
||||
for(socket_fd = 0; socket_fd < MAX_SOCKETS; socket_fd ++) {
|
||||
if(socket_used[socket_fd] && FD_ISSET(socket_fd, &read_fds)) {
|
||||
if(socket_fd == server_fd) {
|
||||
struct sockaddr_in client_addr;
|
||||
unsigned int client_addr_size = sizeof(client_addr);
|
||||
int fd = accept(server_fd, (struct sockaddr *) &client_addr, &client_addr_size);
|
||||
|
||||
if(fd >= 0) {
|
||||
printf("accept socket fd(%d)\n", fd);
|
||||
socket_used[fd] = 1;
|
||||
}
|
||||
else {
|
||||
printf("accept error\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
int read_size = read(socket_fd, buf, sizeof(buf));
|
||||
|
||||
if(read_size > 0) {
|
||||
write(socket_fd, buf, read_size);
|
||||
}
|
||||
else {
|
||||
printf("socket fd(%d) disconnected\n", socket_fd);
|
||||
socket_used[socket_fd] = 0;
|
||||
close(socket_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("TCP server: no data in %d seconds\n", SELECT_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
if(server_fd >= 0)
|
||||
close(server_fd);
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_socket_select(void)
|
||||
{
|
||||
if(xTaskCreate(example_socket_select_thread, ((const char*)"example_socket_select_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
#endif // LWIP_SOCKET
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_SOCKET_SELECT_H
|
||||
#define EXAMPLE_SOCKET_SELECT_H
|
||||
|
||||
void example_socket_select(void);
|
||||
|
||||
#endif /* EXAMPLE_SOCKET_SELECT_H */
|
||||
13
USDK/component/common/example/socket_select/readme.txt
Normal file
13
USDK/component/common/example/socket_select/readme.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
LWIP SOCKET SELECT EXAMPLE
|
||||
|
||||
Description:
|
||||
TCP server listens on port 5000 and handle socket by select().
|
||||
|
||||
Configuration:
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_SOCKET_SELECT 1
|
||||
|
||||
Execution:
|
||||
Can make automatical Wi-Fi connection when booting by using wlan fast connect example.
|
||||
A socket select example thread will be started automatically when booting.
|
||||
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <platform/platform_stdlib.h>
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
#include <polarssl/config.h>
|
||||
#include <polarssl/memory.h>
|
||||
#include <polarssl/ssl.h>
|
||||
|
||||
#define SERVER_HOST "192.168.13.27"
|
||||
#define SERVER_PORT 443
|
||||
#define RESOURCE "/dummy100k.bin"
|
||||
|
||||
static unsigned int arc4random(void)
|
||||
{
|
||||
unsigned int res = xTaskGetTickCount();
|
||||
static unsigned int seed = 0xDEADB00B;
|
||||
|
||||
seed = ((seed & 0x007F00FF) << 7) ^
|
||||
((seed & 0x0F80FF00) >> 8) ^ // be sure to stir those low bits
|
||||
(res << 13) ^ (res >> 9); // using the clock too!
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
static void get_random_bytes(void *buf, size_t len)
|
||||
{
|
||||
unsigned int ranbuf;
|
||||
unsigned int *lp;
|
||||
int i, count;
|
||||
count = len / sizeof(unsigned int);
|
||||
lp = (unsigned int *) buf;
|
||||
|
||||
for(i = 0; i < count; i ++) {
|
||||
lp[i] = arc4random();
|
||||
len -= sizeof(unsigned int);
|
||||
}
|
||||
|
||||
if(len > 0) {
|
||||
ranbuf = arc4random();
|
||||
memcpy(&lp[i], &ranbuf, len);
|
||||
}
|
||||
}
|
||||
|
||||
static int my_random(void *p_rng, unsigned char *output, size_t output_len)
|
||||
{
|
||||
get_random_bytes(output, output_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void example_ssl_download_thread(void *param)
|
||||
{
|
||||
int server_fd = -1, ret;
|
||||
struct sockaddr_in server_addr;
|
||||
ssl_context ssl;
|
||||
|
||||
// Delay to wait for IP by DHCP
|
||||
vTaskDelay(10000);
|
||||
printf("\nExample: SSL download\n");
|
||||
|
||||
memory_set_own(pvPortMalloc, vPortFree);
|
||||
memset(&ssl, 0, sizeof(ssl_context));
|
||||
|
||||
if((ret = net_connect(&server_fd, SERVER_HOST, SERVER_PORT)) != 0) {
|
||||
printf("ERROR: net_connect ret(%d)\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if((ret = ssl_init(&ssl)) != 0) {
|
||||
printf("ERRPR: ssl_init ret(%d)\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ssl_set_endpoint(&ssl, SSL_IS_CLIENT);
|
||||
ssl_set_authmode(&ssl, SSL_VERIFY_NONE);
|
||||
ssl_set_rng(&ssl, my_random, NULL);
|
||||
ssl_set_bio(&ssl, net_recv, &server_fd, net_send, &server_fd);
|
||||
|
||||
if((ret = ssl_handshake(&ssl)) != 0) {
|
||||
printf("ERROR: ssl_handshake ret(-0x%x)", -ret);
|
||||
goto exit;
|
||||
}
|
||||
else {
|
||||
unsigned char buf[2048];
|
||||
int read_size = 0, resource_size = 0, content_len = 0, header_removed = 0;
|
||||
|
||||
printf("SSL ciphersuite %s\n", ssl_get_ciphersuite(&ssl));
|
||||
sprintf(buf, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", RESOURCE, SERVER_HOST);
|
||||
ssl_write(&ssl, buf, strlen(buf));
|
||||
|
||||
while((read_size = ssl_read(&ssl, buf, sizeof(buf))) > 0) {
|
||||
if(header_removed == 0) {
|
||||
char *header = strstr(buf, "\r\n\r\n");
|
||||
|
||||
if(header) {
|
||||
char *body, *content_len_pos;
|
||||
|
||||
body = header + strlen("\r\n\r\n");
|
||||
*(body - 2) = 0;
|
||||
header_removed = 1;
|
||||
printf("\nHTTP Header: %s\n", buf);
|
||||
read_size = read_size - ((unsigned char *) body - buf);
|
||||
|
||||
content_len_pos = strstr(buf, "Content-Length: ");
|
||||
if(content_len_pos) {
|
||||
content_len_pos += strlen("Content-Length: ");
|
||||
*(strstr(content_len_pos, "\r\n")) = 0;
|
||||
content_len = atoi(content_len_pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("ERROR: HTTP header\n");
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
printf("read resource %d bytes\n", read_size);
|
||||
resource_size += read_size;
|
||||
}
|
||||
|
||||
printf("final read size = %d bytes\n", read_size);
|
||||
printf("http content-length = %d bytes, download resource size = %d bytes\n", content_len, resource_size);
|
||||
}
|
||||
|
||||
exit:
|
||||
if(server_fd != -1)
|
||||
net_close(server_fd);
|
||||
|
||||
ssl_free(&ssl);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_ssl_download(void)
|
||||
{
|
||||
if(xTaskCreate(example_ssl_download_thread, ((const char*)"example_ssl_download_thread"), 2048, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_SSL_DOWNLOAD_H
|
||||
#define EXAMPLE_SSL_DOWNLOAD_H
|
||||
|
||||
void example_ssl_download(void);
|
||||
|
||||
#endif /* EXAMPLE_SSL_DOWNLOAD_H */
|
||||
16
USDK/component/common/example/ssl_download/readme.txt
Normal file
16
USDK/component/common/example/ssl_download/readme.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
SSL DOWNLOAD EXAMPLE
|
||||
|
||||
Description:
|
||||
Download file from Web server via https.
|
||||
|
||||
Configuration:
|
||||
Modify SSL_MAX_CONTENT_LEN in SSL config and configTOTAL_HEAP_SIZE in freertos config for large size file
|
||||
Modify SERVER_HOST, SERVER_PORT and RESOURCE in example_ssl_download.c based on your SSL server
|
||||
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_SSL_DOWNLOAD 1
|
||||
|
||||
Execution:
|
||||
Can make automatical Wi-Fi connection when booting by using wlan fast connect example.
|
||||
A ssl download example thread will be started automatically when booting.
|
||||
|
||||
612
USDK/component/common/example/uart_atcmd/example_uart_atcmd.c
Normal file
612
USDK/component/common/example/uart_atcmd/example_uart_atcmd.c
Normal file
|
|
@ -0,0 +1,612 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "platform_opts.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "platform/platform_stdlib.h"
|
||||
#include "semphr.h"
|
||||
#include "device.h"
|
||||
#include "serial_api.h"
|
||||
#include "at_cmd/log_service.h"
|
||||
#include "uart_atcmd/example_uart_atcmd.h"
|
||||
#include "flash_api.h"
|
||||
#include "device_lock.h"
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "freertos_pmu.h"
|
||||
#endif
|
||||
#include "osdep_api.h"
|
||||
#include "osdep_service.h"
|
||||
#include "serial_ex_api.h"
|
||||
#include "at_cmd/atcmd_wifi.h"
|
||||
#include "at_cmd/atcmd_lwip.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
#ifdef USE_FLASH_EEP
|
||||
#include "flash_eep.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
|
||||
typedef int (*init_done_ptr)(void);
|
||||
extern init_done_ptr p_wlan_init_done_callback;
|
||||
extern char log_buf[LOG_SERVICE_BUFLEN];
|
||||
extern xSemaphoreHandle log_rx_interrupt_sema;
|
||||
extern void serial_rx_fifo_level(serial_t *obj, SerialFifoLevel FifoLv);
|
||||
extern int atcmd_wifi_restore_from_flash(void);
|
||||
extern int atcmd_lwip_restore_from_flash(void);
|
||||
|
||||
serial_t at_cmd_sobj;
|
||||
char at_string[ATSTRING_LEN];
|
||||
//xSemaphoreHandle at_printf_sema;
|
||||
_Sema uart_at_dma_tx_sema;
|
||||
unsigned char gAT_Echo = 1; // default echo on
|
||||
|
||||
#define UART_AT_MAX_DELAY_TIME_MS 20
|
||||
|
||||
#define UART_AT_DATA UART_SETTING_SECTOR
|
||||
#define BACKUP_SECTOR FLASH_SYSTEM_DATA_ADDR-0x1000
|
||||
|
||||
#define UART_AT_USE_DMA_TX 0
|
||||
|
||||
void atcmd_update_partition_info(AT_PARTITION id, AT_PARTITION_OP ops, u8 *data, u16 len){
|
||||
#ifdef USE_FLASH_EEP
|
||||
if(id == AT_PARTITION_UART || id == AT_PARTITION_LWIP || id == AT_PARTITION_WIFI) {
|
||||
if(ops == AT_PARTITION_READ) flash_read_cfg(data, id, len);
|
||||
else if (ops == AT_PARTITION_WRITE) flash_write_cfg(data, id, len);
|
||||
else if (ops == AT_PARTITION_ERASE) flash_write_cfg(data, id, 0);
|
||||
}
|
||||
#else
|
||||
flash_t flash;
|
||||
int size, offset, i;
|
||||
u32 read_data;
|
||||
|
||||
switch(id){
|
||||
case AT_PARTITION_UART:
|
||||
size = UART_CONF_DATA_SIZE;
|
||||
offset = UART_CONF_DATA_OFFSET;
|
||||
break;
|
||||
case AT_PARTITION_WIFI:
|
||||
size = WIFI_CONF_DATA_SIZE;
|
||||
offset = WIFI_CONF_DATA_OFFSET;
|
||||
break;
|
||||
case AT_PARTITION_LWIP:
|
||||
size = LWIP_CONF_DATA_SIZE;
|
||||
offset = LWIP_CONF_DATA_OFFSET;
|
||||
break;
|
||||
case AT_PARTITION_ALL:
|
||||
size = 0x1000;
|
||||
offset = 0;
|
||||
break;
|
||||
default:
|
||||
printf("partition id is invalid!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
if(id == AT_PARTITION_ALL && ops == AT_PARTITION_ERASE){
|
||||
flash_erase_sector(&flash, UART_SETTING_SECTOR);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(ops == AT_PARTITION_READ){
|
||||
flash_stream_read(&flash, UART_SETTING_SECTOR+offset, len, data);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
//erase BACKUP_SECTOR
|
||||
flash_erase_sector(&flash, UART_SETTING_BACKUP_SECTOR);
|
||||
|
||||
if(ops == AT_PARTITION_WRITE){
|
||||
// backup new data
|
||||
flash_stream_write(&flash, UART_SETTING_BACKUP_SECTOR+offset, len, data);
|
||||
}
|
||||
|
||||
//backup front data to backup sector
|
||||
for(i = 0; i < offset; i += sizeof(read_data)){
|
||||
flash_read_word(&flash, UART_SETTING_SECTOR + i, &read_data);
|
||||
flash_write_word(&flash, UART_SETTING_BACKUP_SECTOR + i,read_data);
|
||||
}
|
||||
|
||||
//backup rear data
|
||||
for(i = (offset + size); i < 0x1000; i += sizeof(read_data)){
|
||||
flash_read_word(&flash, UART_SETTING_SECTOR + i, &read_data);
|
||||
flash_write_word(&flash, UART_SETTING_BACKUP_SECTOR + i,read_data);
|
||||
}
|
||||
|
||||
//erase UART_SETTING_SECTOR
|
||||
flash_erase_sector(&flash, UART_SETTING_SECTOR);
|
||||
|
||||
//retore data to UART_SETTING_SECTOR from UART_SETTING_BACKUP_SECTOR
|
||||
for(i = 0; i < 0x1000; i+= sizeof(read_data)){
|
||||
flash_read_word(&flash, UART_SETTING_BACKUP_SECTOR + i, &read_data);
|
||||
flash_write_word(&flash, UART_SETTING_SECTOR + i,read_data);
|
||||
}
|
||||
|
||||
//erase BACKUP_SECTOR
|
||||
flash_erase_sector(&flash, UART_SETTING_BACKUP_SECTOR);
|
||||
|
||||
exit:
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
int read_uart_atcmd_setting_from_system_data(UART_LOG_CONF* uartconf)
|
||||
{
|
||||
// flash_t flash;
|
||||
UART_LOG_CONF conf;
|
||||
bool load_default = _TRUE;
|
||||
|
||||
// device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
// flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), (u8 *)&conf);
|
||||
atcmd_update_partition_info(AT_PARTITION_UART, AT_PARTITION_READ, (u8 *)&conf, sizeof(UART_LOG_CONF));
|
||||
do{
|
||||
if(conf.FlowControl != AUTOFLOW_DISABLE && conf.FlowControl != AUTOFLOW_ENABLE)
|
||||
break;
|
||||
|
||||
if(conf.DataBits != 5
|
||||
&& conf.DataBits != 6
|
||||
&& conf.DataBits != 7
|
||||
&& conf.DataBits != 8) //5, 6, 7, 8
|
||||
break;
|
||||
|
||||
if(conf.Parity != ParityNone && conf.Parity != ParityOdd && conf.Parity != ParityEven)
|
||||
break;
|
||||
|
||||
if(conf.StopBits != 1 && conf.StopBits != 2)
|
||||
break;
|
||||
|
||||
load_default = _FALSE;
|
||||
}while(0);
|
||||
|
||||
if(load_default == _TRUE){
|
||||
// load default setting
|
||||
uartconf->BaudRate = DEFAULT_BAUDRATE;
|
||||
uartconf->DataBits = 8;
|
||||
uartconf->Parity = ParityNone;
|
||||
uartconf->StopBits = 1;
|
||||
uartconf->FlowControl = AUTOFLOW_DISABLE;
|
||||
}
|
||||
else{
|
||||
uartconf->BaudRate = conf.BaudRate;
|
||||
uartconf->DataBits = conf.DataBits;
|
||||
uartconf->Parity = conf.Parity;
|
||||
uartconf->StopBits = conf.StopBits;
|
||||
uartconf->FlowControl = conf.FlowControl;
|
||||
}
|
||||
// device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
printf("\r\nAT_UART_CONF: %d,%d,%d,%d,%d\r\n",
|
||||
uartconf->BaudRate,
|
||||
uartconf->DataBits,
|
||||
uartconf->StopBits,
|
||||
uartconf->Parity,
|
||||
uartconf->FlowControl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_uart_atcmd_setting_to_system_data(UART_LOG_CONF* uartconf)
|
||||
{
|
||||
#if 0
|
||||
flash_t flash;
|
||||
|
||||
u8 data1[sizeof(UART_LOG_CONF)];
|
||||
u8 data2[sizeof(UART_LOG_CONF)];
|
||||
|
||||
u32 data,i;
|
||||
|
||||
memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), data1);
|
||||
|
||||
if(memcmp(data1,data2,sizeof(UART_LOG_CONF)) == 0){
|
||||
flash_stream_write(&flash, UART_AT_DATA, sizeof(UART_LOG_CONF),(u8*)uartconf);
|
||||
}else{
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
|
||||
// backup log uart configuration
|
||||
flash_stream_write(&flash, BACKUP_SECTOR, sizeof(UART_LOG_CONF),(u8*)uartconf);
|
||||
|
||||
//backup system data to backup sector
|
||||
for(i = sizeof(UART_LOG_CONF); i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, UART_AT_DATA + i, &data);
|
||||
flash_write_word(&flash, BACKUP_SECTOR + i,data);
|
||||
}
|
||||
//erase system data
|
||||
flash_erase_sector(&flash, UART_AT_DATA);
|
||||
//write data back to system data
|
||||
for(i = 0; i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, BACKUP_SECTOR + i, &data);
|
||||
flash_write_word(&flash, UART_AT_DATA + i,data);
|
||||
}
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
#else
|
||||
atcmd_update_partition_info(AT_PARTITION_UART, AT_PARTITION_WRITE, (u8 *)uartconf, sizeof(UART_LOG_CONF));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reset_uart_atcmd_setting(){
|
||||
#if 0
|
||||
flash_t flash;
|
||||
|
||||
u8 data1[sizeof(UART_LOG_CONF)];
|
||||
u8 data2[sizeof(UART_LOG_CONF)];
|
||||
|
||||
u32 data,i;
|
||||
|
||||
memset(data2, 0xFF, sizeof(UART_LOG_CONF));
|
||||
|
||||
//Get upgraded image 2 addr from offset
|
||||
device_mutex_lock(RT_DEV_LOCK_FLASH);
|
||||
flash_stream_read(&flash, UART_AT_DATA,sizeof(UART_LOG_CONF), data1);
|
||||
|
||||
if(memcmp(data1,data2,sizeof(UART_LOG_CONF)) == 0){
|
||||
;
|
||||
}else{
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
|
||||
// erase uart configuration
|
||||
flash_stream_write(&flash, BACKUP_SECTOR, sizeof(UART_LOG_CONF),(u8*)data2);
|
||||
//backup system data to backup sector
|
||||
for(i = sizeof(UART_LOG_CONF); i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, UART_AT_DATA + i, &data);
|
||||
flash_write_word(&flash, BACKUP_SECTOR + i,data);
|
||||
}
|
||||
//erase system data
|
||||
flash_erase_sector(&flash, UART_AT_DATA);
|
||||
//write data back to system data
|
||||
for(i = 0; i < 0x1000; i+= 4){
|
||||
flash_read_word(&flash, BACKUP_SECTOR + i, &data);
|
||||
flash_write_word(&flash, UART_AT_DATA + i,data);
|
||||
}
|
||||
//erase backup sector
|
||||
flash_erase_sector(&flash, BACKUP_SECTOR);
|
||||
}
|
||||
device_mutex_unlock(RT_DEV_LOCK_FLASH);
|
||||
#else
|
||||
#ifdef USE_FLASH_EEP
|
||||
flash_write_cfg(NULL, AT_PARTITION_UART, 0);
|
||||
flash_write_cfg(NULL, AT_PARTITION_WIFI, 0);
|
||||
flash_write_cfg(NULL, AT_PARTITION_LWIP, 0);
|
||||
#else
|
||||
atcmd_update_partition_info(AT_PARTITION_ALL, AT_PARTITION_ERASE, NULL, 0);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
#include "gpio_irq_api.h"
|
||||
#define UART_AT_RX_WAKE UART_RX
|
||||
void gpio_uart_at_rx_irq_callback (uint32_t id, gpio_irq_event event)
|
||||
{
|
||||
/* WAKELOCK_LOGUART is also handled in log service.
|
||||
* It is release after a complete command is sent.
|
||||
**/
|
||||
//acquire_wakelock(WAKELOCK_LOGUART);
|
||||
}
|
||||
|
||||
void uart_at_rx_wakeup()
|
||||
{
|
||||
gpio_irq_t gpio_rx_wake;
|
||||
#ifdef RTL8711AM
|
||||
#if (UART_AT_RX_WAKE!=PA_0)||(UART_AT_RX_WAKE!=PE_3)
|
||||
#error "Set pin rx_wakeup!"
|
||||
#endif
|
||||
#endif
|
||||
gpio_irq_init(&gpio_rx_wake, UART_AT_RX_WAKE, gpio_uart_at_rx_irq_callback, 0);
|
||||
gpio_irq_set(&gpio_rx_wake, IRQ_FALL, 1); // Falling Edge Trigger
|
||||
gpio_irq_enable(&gpio_rx_wake);
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_atcmd_reinit(UART_LOG_CONF* uartconf){
|
||||
serial_baud(&at_cmd_sobj,uartconf->BaudRate);
|
||||
serial_format(&at_cmd_sobj, uartconf->DataBits, (SerialParity)uartconf->Parity, uartconf->StopBits);
|
||||
|
||||
// set flow control, only support RTS and CTS concurrent mode
|
||||
// rxflow and tx flow is fixed by hardware
|
||||
#define rxflow UART_RTS
|
||||
#define txflow UART_CTS
|
||||
if(uartconf->FlowControl){
|
||||
pin_mode(txflow, PullDown); //init CTS in low
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlRTSCTS, rxflow, txflow);
|
||||
}
|
||||
else
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlNone, rxflow, txflow);
|
||||
}
|
||||
|
||||
void uart_at_send_string(char *str)
|
||||
{
|
||||
unsigned int i=0;
|
||||
while (str[i] != '\0') {
|
||||
serial_putc(&at_cmd_sobj, str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
static void uart_at_send_buf_done(uint32_t id)
|
||||
{
|
||||
//serial_t *sobj = (serial_t *)id;
|
||||
|
||||
RtlUpSemaFromISR(&uart_at_dma_tx_sema);
|
||||
}
|
||||
#endif
|
||||
|
||||
void uart_at_send_buf(u8 *buf, u32 len)
|
||||
{
|
||||
unsigned char *st_p=buf;
|
||||
if(!len || (!buf)){
|
||||
return;
|
||||
}
|
||||
#if UART_AT_USE_DMA_TX
|
||||
int ret;
|
||||
while(RtlDownSema(&uart_at_dma_tx_sema) == pdTRUE){
|
||||
ret = serial_send_stream_dma(&at_cmd_sobj, st_p, len);
|
||||
if(ret != HAL_OK){
|
||||
RtlUpSema(&uart_at_dma_tx_sema);
|
||||
return;
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
while(len){
|
||||
serial_putc(&at_cmd_sobj, *st_p);
|
||||
st_p++;
|
||||
len--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
void uart_at_lock(void)
|
||||
{
|
||||
RtlDownSema(&at_printf_sema);
|
||||
}
|
||||
|
||||
void uart_at_unlock(void)
|
||||
{
|
||||
RtlUpSema(&at_printf_sema);
|
||||
}
|
||||
|
||||
void uart_at_lock_init(){
|
||||
RtlInitSema(&at_printf_sema, 1);
|
||||
}
|
||||
*/
|
||||
void uart_irq(uint32_t id, SerialIrq event)
|
||||
{
|
||||
serial_t *sobj = (serial_t *)id;
|
||||
unsigned char rc=0;
|
||||
static unsigned char temp_buf[LOG_SERVICE_BUFLEN] = "\0";
|
||||
static unsigned int buf_count = 0;
|
||||
static unsigned char combo_key = 0;
|
||||
static u32 last_tickcnt = 0; //to check if any data lost
|
||||
static bool is_data_cmd = _FALSE; // to mark if it's a data command
|
||||
static u32 data_sz = 0, data_cmd_sz =0; // command will send to log handler until "data_cmd_sz" characters are received
|
||||
|
||||
if(event == RxIrq) {
|
||||
rc = serial_getc(sobj);
|
||||
|
||||
if(atcmd_lwip_is_tt_mode()){
|
||||
log_buf[atcmd_lwip_tt_datasize++] = rc;
|
||||
atcmd_lwip_tt_lasttickcnt = xTaskGetTickCountFromISR();
|
||||
if(atcmd_lwip_tt_datasize == 1)
|
||||
rtw_up_sema_from_isr((_Sema *)&atcmd_lwip_tt_sema);
|
||||
return;
|
||||
}
|
||||
|
||||
if(buf_count == 4){
|
||||
// if this is a data command with hex data, then '\n' should not be treated
|
||||
// as the end of command
|
||||
if(strncmp(temp_buf, "ATPT", C_NUM_AT_CMD)==0){
|
||||
is_data_cmd = _TRUE;
|
||||
}
|
||||
}
|
||||
if(buf_count > C_NUM_AT_CMD && is_data_cmd == _TRUE){
|
||||
if(data_cmd_sz == 0){
|
||||
if(data_sz == 0){
|
||||
if(rc == ','){
|
||||
//first delimeter, ATxx=[sz],....
|
||||
char str[10]={0};
|
||||
char size_pos = C_NUM_AT_CMD + C_NUM_AT_CMD_DLT;
|
||||
memcpy(str, &temp_buf[size_pos], buf_count-size_pos);
|
||||
data_sz = atoi(str); //get data size
|
||||
}
|
||||
}else{
|
||||
if(rc == ':'){ //data will start after this delimeter ':'
|
||||
strncpy(log_buf, (char *)temp_buf, buf_count);
|
||||
memset(temp_buf,'\0',buf_count);
|
||||
last_tickcnt = xTaskGetTickCountFromISR();
|
||||
data_cmd_sz = buf_count + 1 + data_sz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(data_cmd_sz){
|
||||
if((!gAT_Echo) && (rtw_systime_to_ms(xTaskGetTickCountFromISR() - last_tickcnt) > UART_AT_MAX_DELAY_TIME_MS)){
|
||||
uart_at_send_string("\r\nERROR:data timeout\r\n\n# ");
|
||||
memset(log_buf, 0, buf_count);
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
return;
|
||||
}
|
||||
last_tickcnt = xTaskGetTickCountFromISR();
|
||||
log_buf[buf_count++]=rc;
|
||||
if(gAT_Echo == 1){
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
if(buf_count >= data_cmd_sz){
|
||||
log_buf[data_cmd_sz - data_sz - 1] = '\0'; //for log service handler parse to get command parameter, replace ":" with "\0"
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
rtw_up_sema_from_isr((_Sema *)&log_rx_interrupt_sema);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (rc == KEY_ESC) {
|
||||
combo_key = 1;
|
||||
}
|
||||
else if (combo_key == 1){
|
||||
if (rc == KEY_LBRKT) {
|
||||
combo_key = 2;
|
||||
}
|
||||
else{
|
||||
combo_key = 0;
|
||||
}
|
||||
}
|
||||
else if (combo_key == 2){
|
||||
//if ((rc=='A')|| rc=='B'){//up and down
|
||||
//}
|
||||
combo_key=0;
|
||||
}
|
||||
else if(rc == KEY_ENTER){
|
||||
if(buf_count>0){
|
||||
memset(log_buf,'\0',LOG_SERVICE_BUFLEN);
|
||||
strncpy(log_buf,(char *)&temp_buf[0],buf_count);
|
||||
rtw_up_sema_from_isr((_Sema *)&log_rx_interrupt_sema);
|
||||
memset(temp_buf,'\0',buf_count);
|
||||
is_data_cmd = _FALSE;
|
||||
data_sz = 0;
|
||||
data_cmd_sz = 0;
|
||||
buf_count=0;
|
||||
last_tickcnt = 0;
|
||||
}else{
|
||||
uart_at_send_string(STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
}
|
||||
else if(rc == KEY_BS){
|
||||
if(buf_count>0){
|
||||
buf_count--;
|
||||
temp_buf[buf_count] = '\0';
|
||||
if(gAT_Echo == 1){
|
||||
serial_putc(sobj, rc);
|
||||
serial_putc(sobj, ' ');
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
// skip characters until "A"
|
||||
if((buf_count == 0) && (rc != 'A')){
|
||||
if(gAT_Echo == 1){
|
||||
uart_at_send_string("\r\nERROR:command should start with 'A'"STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(buf_count < (LOG_SERVICE_BUFLEN - 1)){
|
||||
temp_buf[buf_count] = rc;
|
||||
buf_count++;
|
||||
if(gAT_Echo == 1){
|
||||
serial_putc(sobj, rc);
|
||||
}
|
||||
}
|
||||
else if(buf_count == (LOG_SERVICE_BUFLEN - 1)){
|
||||
temp_buf[buf_count] = '\0';
|
||||
if(gAT_Echo == 1){
|
||||
uart_at_send_string("\r\nERROR:exceed size limit"STR_END_OF_ATCMD_RET);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uart_atcmd_main(void)
|
||||
{
|
||||
UART_LOG_CONF uartconf;
|
||||
|
||||
read_uart_atcmd_setting_from_system_data(&uartconf);
|
||||
serial_init(&at_cmd_sobj, UART_TX, UART_RX);
|
||||
serial_baud(&at_cmd_sobj,uartconf.BaudRate);
|
||||
serial_format(&at_cmd_sobj, uartconf.DataBits, (SerialParity)uartconf.Parity, uartconf.StopBits);
|
||||
serial_rx_fifo_level(&at_cmd_sobj, FifoLvHalf);
|
||||
// set flow control, only support RTS and CTS concurrent mode
|
||||
// rxflow and tx flow is fixed by hardware
|
||||
#define rxflow UART_RTS
|
||||
#define txflow UART_CTS
|
||||
if(uartconf.FlowControl){
|
||||
pin_mode(txflow, PullDown); //init CTS in low
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlRTSCTS, rxflow, txflow);
|
||||
}
|
||||
else
|
||||
serial_set_flow_control(&at_cmd_sobj, FlowControlNone, rxflow, txflow);
|
||||
|
||||
/*uart_at_lock_init();*/
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
RtlInitSema(&uart_at_dma_tx_sema, 1);
|
||||
#endif
|
||||
|
||||
#if UART_AT_USE_DMA_TX
|
||||
serial_send_comp_handler(&at_cmd_sobj, (void*)uart_at_send_buf_done, (uint32_t)&at_cmd_sobj);
|
||||
#endif
|
||||
|
||||
serial_irq_handler(&at_cmd_sobj, uart_irq, (uint32_t)&at_cmd_sobj);
|
||||
serial_irq_set(&at_cmd_sobj, RxIrq, 1);
|
||||
|
||||
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
|
||||
uart_at_rx_wakeup();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void uart_atcmd_thread(void *param)
|
||||
{
|
||||
p_wlan_init_done_callback = NULL;
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
ConfigDebugErr = -1;
|
||||
ConfigDebugInfo = ~_DBG_SPI_FLASH_;
|
||||
ConfigDebugWarn = -1;
|
||||
CfgSysDebugErr = -1;
|
||||
CfgSysDebugInfo = -1;
|
||||
CfgSysDebugWarn = -1;
|
||||
#endif
|
||||
atcmd_wifi_restore_from_flash();
|
||||
atcmd_lwip_restore_from_flash();
|
||||
vTaskDelay(20); //rtw_msleep_os(20);
|
||||
uart_atcmd_main();
|
||||
at_printf("\r\nAT COMMAND READY");
|
||||
if(atcmd_lwip_is_tt_mode())
|
||||
at_printf(STR_END_OF_ATDATA_RET);
|
||||
else
|
||||
at_printf(STR_END_OF_ATCMD_RET);
|
||||
_AT_DBG_MSG(AT_FLAG_COMMON, AT_DBG_ALWAYS, STR_END_OF_ATCMD_RET);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
int uart_atcmd_module_init(void){
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
printf("Time at start %d ms.\n", xTaskGetTickCount());
|
||||
#endif
|
||||
if(xTaskCreate(uart_atcmd_thread, ((const char*)"uart_atcmd_thread"), 1024, NULL, tskIDLE_PRIORITY + 1 , NULL) != pdPASS) // tskIDLE_PRIORITY + 1
|
||||
printf("\n\r%s xTaskCreate(uart_atcmd_thread) failed", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void example_uart_atcmd(void)
|
||||
{
|
||||
//if(xTaskCreate(uart_atcmd_thread, ((const char*)"uart_atcmd_thread"), 1024, NULL, tskIDLE_PRIORITY + 1 , NULL) != pdPASS)
|
||||
// printf("\n\r%s xTaskCreate(uart_atcmd_thread) failed", __FUNCTION__);
|
||||
p_wlan_init_done_callback = uart_atcmd_module_init;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
#ifndef __EXAMPLE_UART_ATCMD_H__
|
||||
#define __EXAMPLE_UART_ATCMD_H__
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "osdep_api.h"
|
||||
|
||||
|
||||
#if defined(RTL8710AF)
|
||||
// RTL8710AF
|
||||
#define UART_TX PA_4 // PC_3
|
||||
#define UART_RX PA_0 // PC_0
|
||||
#define UART_RTS PA_2 // PC_2
|
||||
#define UART_CTS PA_1 // PC_1
|
||||
|
||||
#elif 0 // defined(RTL8711AM)
|
||||
// RTL8711AM
|
||||
#define UART_TX PA_7
|
||||
#define UART_RX PA_6 // no Interrupt!
|
||||
#define UART_RTS PA_3
|
||||
#define UART_CTS PA_5
|
||||
|
||||
#elif 0 // else
|
||||
// RTL8711AM + RTL8710AF
|
||||
#define UART_TX PC_3
|
||||
#define UART_RX PC_0 // no Interrupt!
|
||||
#define UART_RTS PC_2
|
||||
#define UART_CTS PC_1
|
||||
|
||||
#elif defined(RTL8711AM)
|
||||
// RTL8711AM + RTL8710AF
|
||||
#define UART_TX PE_0
|
||||
#define UART_RX PE_3
|
||||
#define UART_RTS PE_1
|
||||
#define UART_CTS PE_2
|
||||
|
||||
#endif
|
||||
|
||||
#define KEY_ENTER 0xd
|
||||
#define KEY_BS 0x8
|
||||
#define KEY_ESC 0x1B
|
||||
#define KEY_LBRKT 0x5B
|
||||
|
||||
void uart_at_lock(void);
|
||||
void uart_at_unlock(void);
|
||||
void uart_at_send_string(char *str);
|
||||
void uart_at_send_buf(u8 *buf, u32 len);
|
||||
void example_uart_atcmd(void);
|
||||
|
||||
#include "at_cmd/atcmd_wifi.h"
|
||||
|
||||
void uart_atcmd_reinit(UART_LOG_CONF* uartconf);
|
||||
int write_uart_atcmd_setting_to_system_data(UART_LOG_CONF* uartconf);
|
||||
|
||||
extern u8 key_2char2num(u8 hch, u8 lch);
|
||||
static void at_hex2str(const u8 *start, u32 size, u8 *out, u32 out_size)
|
||||
{
|
||||
int index, index2;
|
||||
u8 *buf, *line;
|
||||
|
||||
if(!start ||(size==0)||(!out)||(out_size==0))
|
||||
return;
|
||||
|
||||
buf = (u8*)start;
|
||||
line = (u8*)out;
|
||||
for (index = 0, index2=0; (index < size)&&(index2<out_size); index++, index2+=2)
|
||||
{
|
||||
sprintf((char *)line+index2, "%02x", (u8) buf[index]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
static void at_str2hex(const u8 *start, u32 size, u8 *out, u32 out_size)
|
||||
{
|
||||
int index, index2;
|
||||
u8 *buf, *line;
|
||||
|
||||
if(!start ||(size==0))
|
||||
return;
|
||||
|
||||
buf = (u8*)start;
|
||||
line = (u8*)out;
|
||||
|
||||
for (index=0, index2=0; index<size; index+=2, index2++){
|
||||
line[index2] = key_2char2num(buf[index], buf[index+1]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif //#if CONFIG_EXAMPLE_UART_ATCMD
|
||||
#endif //#ifndef __EXAMPLE_UART_ATCMD_H__
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
#include "example_uart_update.h"
|
||||
|
||||
int is_update_image_enable(gpio_t *gpio_uart_update_eable)
|
||||
{
|
||||
|
||||
HAL_GPIO_PIN GPIO_Pin;
|
||||
u32 active_state;
|
||||
// gpio_t gpio_uart_update_eable;
|
||||
int ret = 0;
|
||||
#if 0
|
||||
GPIO_Pin.pin_name = 0xC4;
|
||||
//low active
|
||||
GPIO_Pin.pin_mode = DIN_PULL_HIGH;
|
||||
active_state = GPIO_PIN_LOW;
|
||||
|
||||
HAL_GPIO_Init(&GPIO_Pin);
|
||||
|
||||
if (HAL_GPIO_ReadPin(&GPIO_Pin) == active_state)
|
||||
ret = 0;
|
||||
else
|
||||
ret = 1;
|
||||
|
||||
HAL_GPIO_DeInit(&GPIO_Pin);
|
||||
#else
|
||||
gpio_init(gpio_uart_update_eable, PIN_NAME);
|
||||
gpio_dir(gpio_uart_update_eable, PIN_INPUT); // Direction: Input
|
||||
gpio_mode(gpio_uart_update_eable, PullUp); // Pull-High
|
||||
// ret = gpio_read(&gpio_uart_update_eable);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
void example_uart_update_thread(void *param)
|
||||
{
|
||||
int count = 0;
|
||||
gpio_t gpio_uart_update_eable;
|
||||
|
||||
is_update_image_enable(&gpio_uart_update_eable);
|
||||
//polling MAX_WAIT_TIME*50ms
|
||||
while(count <= MAX_WAIT_TIME)
|
||||
{
|
||||
printf(" waitting update enable\r\n");
|
||||
if(gpio_read(&gpio_uart_update_eable) == 0){
|
||||
printf(" update image enabled!\r\n");
|
||||
uart_ymodem();
|
||||
break;
|
||||
}
|
||||
else{
|
||||
RtlMsleepOS(50);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_uart_update(void)
|
||||
{
|
||||
if(xTaskCreate(example_uart_update_thread, ((const char*)"example_uart_update_thread"), 512, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef UART_UPDATE_H
|
||||
#define UART_UPDATE_H
|
||||
|
||||
#include "PinNames.h"
|
||||
#include "gpio_api.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "osdep_api.h"
|
||||
|
||||
#define PIN_NAME PC_2
|
||||
#define MAX_WAIT_TIME 100
|
||||
|
||||
void example_uart_update();
|
||||
int is_update_image_enable(gpio_t *gpio_uart_update_eable);
|
||||
extern int uart_ymodem(void);
|
||||
|
||||
#endif
|
||||
|
||||
586
USDK/component/common/example/uvc/example_uvc.c
Normal file
586
USDK/component/common/example/uvc/example_uvc.c
Normal file
|
|
@ -0,0 +1,586 @@
|
|||
|
||||
/*
|
||||
* V4L2 video capture example
|
||||
*/
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "example_uvc.h"
|
||||
#include "videodev2.h"
|
||||
#include "uvcvideo.h"
|
||||
#include "v4l2_driver.h"
|
||||
#include "mjpeg/mjpeg.h"
|
||||
#include "rtsp/rtsp_api.h"
|
||||
#include "sockets.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
#include "uvc_intf.h"
|
||||
|
||||
#include "section_config.h"
|
||||
SDRAM_DATA_SECTION struct rtp_object rtp_payload[VIDEO_MAX_FRAME];
|
||||
|
||||
struct rtp_payload_queue payload_queue;
|
||||
|
||||
void example_uvc(void)
|
||||
{
|
||||
/*init payload queue*/
|
||||
INIT_LIST_HEAD(&payload_queue.wait_queue);
|
||||
INIT_LIST_HEAD(&payload_queue.done_queue);
|
||||
RtlMutexInit(&payload_queue.wait_mutex);
|
||||
RtlMutexInit(&payload_queue.done_mutex);
|
||||
RtlInitSema(&payload_queue.wait_sema, 0);
|
||||
RtlInitSema(&payload_queue.done_sema, 0);
|
||||
payload_queue.flush_err = 0;
|
||||
uvc_stream_init();
|
||||
}
|
||||
|
||||
void uvc_entry_handle(void *param)
|
||||
{
|
||||
int i, ret, cnt;
|
||||
struct stream_context *stream_ctx = (struct stream_context *)param;
|
||||
struct uvc_buf_context buf;
|
||||
struct rtp_object *payload;
|
||||
|
||||
/*initialize rtp payload*/
|
||||
for(i = 0; i < VIDEO_MAX_FRAME; i++)
|
||||
{
|
||||
if(rtp_init_payload(stream_ctx, &rtp_payload[i]) < 0)
|
||||
{
|
||||
for(; i>=0; i--)
|
||||
{
|
||||
rtp_uninit_payload(stream_ctx, &rtp_payload[i]);
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
if(uvc_set_param(stream_ctx, UVC_FORMAT_MJPEG, 640, 480, 30)<0)
|
||||
goto exit;
|
||||
|
||||
if(uvc_stream_on(stream_ctx)<0)
|
||||
goto exit;
|
||||
|
||||
/*do buffer queue & dequeue inside the loop*/
|
||||
payload_queue.flush_err = 0;
|
||||
while(!(payload_queue.flush_err))
|
||||
{
|
||||
memset(&buf, 0, sizeof(struct uvc_buf_context));
|
||||
ret = uvc_dqbuf(stream_ctx, &buf);
|
||||
if(buf.index < 0)
|
||||
continue;//empty buffer retrieved
|
||||
if((uvc_buf_check(&buf)<0)||(ret < 0)){
|
||||
RTSP_ERROR("\n\rbuffer error!");
|
||||
ret = -ENOENT;
|
||||
goto exit;
|
||||
}
|
||||
rtp_payload[buf.index].index = buf.index;
|
||||
if(rtp_fill_payload(stream_ctx, &rtp_payload[buf.index], buf.data, buf.len) < 0)
|
||||
goto exit;
|
||||
|
||||
/*add rtp_payload into payload queue*/
|
||||
RtlDownMutex(&payload_queue.wait_mutex);
|
||||
list_add_tail(&rtp_payload[buf.index].rtp_list, &payload_queue.wait_queue);
|
||||
RtlUpMutex(&payload_queue.wait_mutex);
|
||||
RtlUpSema(&payload_queue.wait_sema);
|
||||
|
||||
//check if any rtp payload is queued in done_queue
|
||||
while(RtlDownSemaWithTimeout(&payload_queue.done_sema, 5)==0)
|
||||
{
|
||||
if(payload_queue.flush_err)
|
||||
goto exit;
|
||||
}
|
||||
if(!list_empty(&payload_queue.done_queue))
|
||||
{
|
||||
RtlDownMutex(&payload_queue.done_mutex);
|
||||
payload = list_first_entry(&payload_queue.done_queue, struct rtp_object, rtp_list);
|
||||
if(payload == NULL)
|
||||
{
|
||||
RtlUpMutex(&payload_queue.done_mutex);
|
||||
continue;
|
||||
}
|
||||
list_del_init(&payload->rtp_list);
|
||||
RtlUpMutex(&payload_queue.done_mutex);
|
||||
|
||||
buf.index = payload->index;
|
||||
buf.data = payload->data;
|
||||
buf.len = payload->len;
|
||||
|
||||
ret = uvc_qbuf(stream_ctx, &buf);
|
||||
if (ret < 0){
|
||||
RTSP_ERROR("\n\rread_frame mmap method enqueue buffer failed");
|
||||
ret = -ENOENT;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
uvc_stream_off(stream_ctx);
|
||||
uvc_stream_free(stream_ctx);
|
||||
|
||||
for(i = 0; i < VIDEO_MAX_FRAME; i++)
|
||||
{
|
||||
rtp_uninit_payload(stream_ctx, &rtp_payload[i]);
|
||||
}
|
||||
|
||||
//free payload_queue memory
|
||||
INIT_LIST_HEAD(&payload_queue.wait_queue);
|
||||
INIT_LIST_HEAD(&payload_queue.done_queue);
|
||||
RtlMutexFree(&payload_queue.wait_mutex);
|
||||
RtlMutexFree(&payload_queue.done_mutex);
|
||||
RtlFreeSema(&payload_queue.wait_sema);
|
||||
RtlFreeSema(&payload_queue.done_sema);
|
||||
|
||||
printf("\n\rstream free success, delete task...");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uvc_rtp_init(struct rtsp_context *rtsp_ctx);
|
||||
void uvc_rtsp_handle(void *param)
|
||||
{
|
||||
struct stream_context *stream_ctx = (struct stream_context *)param;
|
||||
struct rtsp_context *rtsp_ctx;
|
||||
u8 *request_header; //buffer to hold rtsp request
|
||||
struct sockaddr_in server_addr, client_addr;
|
||||
int client_socket;
|
||||
socklen_t client_addr_len = sizeof(struct sockaddr_in);
|
||||
|
||||
fd_set read_fds;
|
||||
struct timeval timeout;
|
||||
int ok;
|
||||
rtsp_ctx = malloc(sizeof(struct rtsp_context));
|
||||
if(rtsp_ctx == NULL)
|
||||
{
|
||||
RTSP_ERROR("\n\rrtsp context is NULL");
|
||||
goto exit;
|
||||
}
|
||||
request_header = malloc(512);
|
||||
if(request_header == NULL)
|
||||
{
|
||||
RTSP_ERROR("\n\rallocate request header buffer failed");
|
||||
goto exit;
|
||||
}
|
||||
// Delay to wait for IP by DHCP
|
||||
vTaskDelay(500);
|
||||
/*init rtsp context to unicast udp mode*/
|
||||
if(rtsp_context_init(rtsp_ctx) < 0)
|
||||
goto exit;
|
||||
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_addr.s_addr = *(uint32_t *)(rtsp_ctx->connect_ctx.server_ip)/*htonl(INADDR_ANY)*/;
|
||||
server_addr.sin_port = htons(rtsp_ctx->connect_ctx.port);
|
||||
|
||||
if(bind(rtsp_ctx->connect_ctx.socket_id, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
||||
RTSP_ERROR("\n\rCannot bind stream socket");
|
||||
goto exit;
|
||||
}
|
||||
listen(rtsp_ctx->connect_ctx.socket_id, 1);
|
||||
printf("\n\rrtsp context initialized!");
|
||||
|
||||
stream_ctx->protoCtx = (void *)rtsp_ctx;
|
||||
rtsp_ctx->stream_ctx = (void *)stream_ctx;
|
||||
|
||||
/*start rtp task*/
|
||||
uvc_rtp_init(rtsp_ctx);
|
||||
|
||||
|
||||
while(stream_ctx->allowStream)
|
||||
{
|
||||
FD_ZERO(&read_fds);
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
FD_SET(rtsp_ctx->connect_ctx.socket_id, &read_fds);
|
||||
if(select(1, &read_fds, NULL, NULL, &timeout))
|
||||
{
|
||||
client_socket = accept(rtsp_ctx->connect_ctx.socket_id,(struct sockaddr *)&client_addr, &client_addr_len);
|
||||
if(client_socket < 0)
|
||||
{
|
||||
RTSP_ERROR("client_socket error:%d\r\n", client_socket);
|
||||
close(client_socket);
|
||||
continue;
|
||||
}
|
||||
*(rtsp_ctx->connect_ctx.remote_ip + 3) = (unsigned char) (client_addr.sin_addr.s_addr >> 24);
|
||||
*(rtsp_ctx->connect_ctx.remote_ip + 2) = (unsigned char) (client_addr.sin_addr.s_addr >> 16);
|
||||
*(rtsp_ctx->connect_ctx.remote_ip + 1) = (unsigned char) (client_addr.sin_addr.s_addr >> 8);
|
||||
*(rtsp_ctx->connect_ctx.remote_ip) = (unsigned char) (client_addr.sin_addr.s_addr );
|
||||
|
||||
while(stream_ctx->allowStream)
|
||||
{
|
||||
|
||||
|
||||
read(client_socket, request_header, 512);
|
||||
rtsp_readheader(request_header);
|
||||
if(*request_header == 0)
|
||||
{
|
||||
|
||||
//Do I need to send error response to client?
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
rtsp_getparam(rtsp_ctx, request_header);
|
||||
switch(rtsp_ctx->rtsp_cmd)
|
||||
{
|
||||
|
||||
case(CMD_OPTIONS):
|
||||
RTSP_PRINTF("\n\rReceive options command!");
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
break;
|
||||
|
||||
rtsp_cmd_options(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend OPTIONS response failed!");
|
||||
goto exit;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case(CMD_DESCRIBE):
|
||||
RTSP_PRINTF("\n\rReceive describe command!");
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
break;
|
||||
|
||||
rtsp_cmd_describe(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend DESCRIBE response failed!");
|
||||
goto exit;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case(CMD_SETUP):
|
||||
RTSP_PRINTF("\n\rReceive setup command!");
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
break;
|
||||
|
||||
//fill transport parameter
|
||||
rtsp_cmd_setup(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend SETUP response failed!");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
if(rtsp_ctx->state == RTSP_INIT)
|
||||
{
|
||||
|
||||
rtsp_ctx->state = RTSP_READY;
|
||||
RTSP_PRINTF("\n\rstate changed from RTSP_INIT to RTSP_READY");
|
||||
};
|
||||
break;
|
||||
|
||||
|
||||
case(CMD_TEARDOWN):
|
||||
RTSP_PRINTF("\n\rReceive teardown command!");
|
||||
rtsp_ctx->state = RTSP_INIT;
|
||||
rtsp_cmd_teardown(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend TEARDOWN response failed!");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RTSP_PRINTF("\n\rstreaming teardown, state changed back to RTSP_INIT");
|
||||
/*have to wait until rtp server reinit*/
|
||||
vTaskDelay(1000);
|
||||
goto out;
|
||||
break;
|
||||
|
||||
|
||||
case(CMD_PLAY):
|
||||
RTSP_PRINTF("\n\rReceive play command!");
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
break;
|
||||
|
||||
rtsp_cmd_play(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend PLAY response failed!");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
if(rtsp_ctx->state == RTSP_READY)
|
||||
{
|
||||
|
||||
rtsp_ctx->state = RTSP_PLAYING;
|
||||
RTSP_PRINTF("\n\rstate changed from RTSP_READY to RTSP_PLAYING");
|
||||
rtsp_ctx->is_rtp_start = 1;
|
||||
RtlUpSema(&rtsp_ctx->start_rtp_sema);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case(CMD_PAUSE):
|
||||
RTSP_PRINTF("\n\rReceive pause command!");
|
||||
rtsp_cmd_pause(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend PAUSE response failed!");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
{
|
||||
|
||||
rtsp_ctx->state = RTSP_READY;
|
||||
RTSP_PRINTF("\n\rstate changed from RTSP_PLAYING to RTSP_READY");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rReceive unrecognized command!");
|
||||
rtsp_cmd_error(rtsp_ctx);
|
||||
ok = write(client_socket, rtsp_ctx->response, strlen(rtsp_ctx->response));
|
||||
if (ok <= 0)
|
||||
{
|
||||
|
||||
|
||||
RTSP_ERROR("\n\rsend ERROR response failed!");
|
||||
goto exit;
|
||||
}
|
||||
rtsp_ctx->state = RTSP_INIT;
|
||||
}
|
||||
if((rtsp_ctx->is_rtp_start == 0) && (rtsp_ctx->state == RTSP_PLAYING))
|
||||
{
|
||||
|
||||
|
||||
rtsp_ctx->state = RTSP_INIT;
|
||||
RtlUpSema(&rtsp_ctx->start_rtp_sema);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
out:
|
||||
rtsp_ctx->state = RTSP_INIT;
|
||||
close(client_socket);
|
||||
}
|
||||
|
||||
}
|
||||
exit:
|
||||
if((rtsp_ctx->is_rtp_start) == 1){
|
||||
RtlUpSema(&rtsp_ctx->start_rtp_sema);
|
||||
}
|
||||
printf("\n\rrtsp -> Available heap 0x%x\n", xPortGetFreeHeapSize());
|
||||
close(client_socket);
|
||||
close(rtsp_ctx->connect_ctx.socket_id);
|
||||
if(request_header != NULL)
|
||||
free(request_header);
|
||||
/*wait until rtp task being destroyed*/
|
||||
while((rtsp_ctx->is_rtp_start))
|
||||
{
|
||||
vTaskDelay(100);
|
||||
}
|
||||
rtsp_context_free(rtsp_ctx);
|
||||
if(rtsp_ctx != NULL)
|
||||
free(rtsp_ctx);
|
||||
RTSP_ERROR("\n\rkill rtsp server thread!");
|
||||
//printf("Available heap 0x%x\n", xPortGetFreeHeapSize());
|
||||
//thread must be killed after server socket is terminated
|
||||
vTaskDelete(NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void uvc_rtp_udp_init(struct stream_context *stream_ctx)
|
||||
{
|
||||
|
||||
struct rtsp_context *rtsp_ctx = (struct rtsp_context *)stream_ctx->protoCtx;
|
||||
struct uvc_buf_context buf;
|
||||
struct rtp_object *payload;
|
||||
struct sockaddr_in rtp_addr;
|
||||
int rtp_socket;
|
||||
int i, ret;
|
||||
socklen_t addrlen = sizeof(struct sockaddr_in);
|
||||
int rtp_port;
|
||||
/* varibles for recording statistic use*/
|
||||
unsigned int cnt, total, total_time, time1, time2, time3;
|
||||
cnt = total = total_time = time1 = time2 = time3 = 0;
|
||||
/*init rtp socket*/
|
||||
rtp_socket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
rtp_port = rtsp_ctx->transport.serverport_min;
|
||||
memset(&rtp_addr, 0, addrlen);
|
||||
rtp_addr.sin_family = AF_INET;
|
||||
rtp_addr.sin_addr.s_addr = *(uint32_t *)(rtsp_ctx->connect_ctx.server_ip);
|
||||
rtp_addr.sin_port = htons((u16)rtp_port);
|
||||
if (bind(rtp_socket,(struct sockaddr *)&rtp_addr, addrlen)<0) {
|
||||
RTSP_ERROR("bind failed\r\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
restart:
|
||||
while((stream_ctx->isProcess)&&(rtsp_ctx->state == RTSP_PLAYING))
|
||||
{
|
||||
if(RtlDownSemaWithTimeout(&payload_queue.wait_sema, 5)==0)
|
||||
continue;
|
||||
time1 = time3;
|
||||
time2 = xTaskGetTickCount();
|
||||
/*send rtp payload*/
|
||||
if(!list_empty(&payload_queue.wait_queue))
|
||||
{
|
||||
RtlDownMutex(&payload_queue.wait_mutex);
|
||||
payload = list_first_entry(&payload_queue.wait_queue, struct rtp_object, rtp_list);
|
||||
if(payload == NULL)
|
||||
{
|
||||
RtlUpMutex(&payload_queue.wait_mutex);
|
||||
continue;
|
||||
}
|
||||
list_del_init(&payload->rtp_list);
|
||||
RtlUpMutex(&payload_queue.wait_mutex);
|
||||
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
{
|
||||
|
||||
payload->connect_ctx.socket_id = rtp_socket;
|
||||
payload->connect_ctx.port = (u16)rtsp_ctx->transport.clientport_min;
|
||||
payload->connect_ctx.server_ip = rtsp_ctx->connect_ctx.server_ip;
|
||||
payload->connect_ctx.remote_ip = rtsp_ctx->connect_ctx.remote_ip;
|
||||
|
||||
ret = rtp_udp_send(stream_ctx, payload);
|
||||
}
|
||||
|
||||
//dequeue the this buffer from payload_queue
|
||||
RtlDownMutex(&payload_queue.done_mutex);
|
||||
list_add_tail(&payload->rtp_list, &payload_queue.done_queue);
|
||||
RtlUpMutex(&payload_queue.done_mutex);
|
||||
RtlUpSema(&payload_queue.done_sema);
|
||||
|
||||
time3 = xTaskGetTickCount();
|
||||
cnt ++;
|
||||
total += payload->len;
|
||||
total_time += (time3-time1);
|
||||
if(cnt == 100)
|
||||
{
|
||||
/* print statistics info */
|
||||
/*1.average frame size(kB) T:2.time waited for next frame sending start(ms)-3.udp sending time(ms) 4.frame rate(fps)*/
|
||||
printf("\n\r%dkB T:%d-%d %dfps", (total/102400), (time2 - time1), (time3 - time2), (100000/total_time));
|
||||
cnt = 0;
|
||||
total = 0;
|
||||
total_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
mdelay(1000);
|
||||
if(rtsp_ctx->state == RTSP_READY)
|
||||
{
|
||||
goto restart;
|
||||
}
|
||||
|
||||
exit:
|
||||
close(rtp_socket);
|
||||
}
|
||||
|
||||
void uvc_rtp_tcp_init(struct stream_context *stream_ctx)
|
||||
{
|
||||
}
|
||||
|
||||
void uvc_rtp_multi_init(struct stream_context *stream_ctx)
|
||||
{
|
||||
}
|
||||
|
||||
void uvc_rtp_handle(void *param)
|
||||
{
|
||||
struct stream_context *stream_ctx = (struct stream_context *)param;
|
||||
struct rtsp_context *rtsp_ctx = (struct rtsp_context *)stream_ctx->protoCtx;
|
||||
|
||||
/*go down when rtsp state change to playing*/
|
||||
while(1)
|
||||
{
|
||||
RtlDownSema(&rtsp_ctx->start_rtp_sema);
|
||||
/*check rtp cast mode*/
|
||||
if(rtsp_ctx->state == RTSP_PLAYING)
|
||||
{
|
||||
printf("\n\rrtp start...");
|
||||
switch(rtsp_ctx->transport.castMode)
|
||||
{
|
||||
case(UNICAST_UDP_MODE):
|
||||
uvc_rtp_udp_init(stream_ctx);
|
||||
break;
|
||||
case(MULTICAST_MODE):
|
||||
uvc_rtp_tcp_init(stream_ctx);
|
||||
break;
|
||||
case(UNICAST_TCP_MODE):
|
||||
uvc_rtp_multi_init(stream_ctx);
|
||||
break;
|
||||
default:
|
||||
RTSP_ERROR("\r\n unknown streaming mode! Go back to RTSP_INIT state\n");
|
||||
rtsp_ctx->is_rtp_start = 0;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
|
||||
break;
|
||||
}
|
||||
printf("\n\rrtp stop...");
|
||||
}
|
||||
rtsp_ctx->is_rtp_start = 0;
|
||||
RTSP_ERROR("\n\rkill rtp server thread!");
|
||||
//printf("Available heap 0x%x\n", xPortGetFreeHeapSize());
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
int uvc_rtp_init(struct rtsp_context *rtsp_ctx)
|
||||
{
|
||||
struct stream_context *stream_ctx = (struct stream_context *)rtsp_ctx->stream_ctx;
|
||||
|
||||
if(xTaskCreate(uvc_rtp_handle, ((const signed char*)"uvc_rtp_handle"), 2048, (void *)stream_ctx, tskIDLE_PRIORITY + 2, NULL) != pdPASS) {
|
||||
RTSP_ERROR("\r\n uvc_rtp_handle: Create Task Error\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uvc_task_init(void * param)
|
||||
{
|
||||
|
||||
/*entry to start uvc streaming -- dequeue uvc buffer*/
|
||||
if(xTaskCreate(uvc_entry_handle, ((const signed char*)"uvc_entry_handle"), 1024, param, tskIDLE_PRIORITY + 2, NULL) != pdPASS) {
|
||||
UVC_ERROR("\r\n uvc_entry_handle: Create Task Error\n");
|
||||
}
|
||||
|
||||
/*entry to start rtsp server*/
|
||||
#if UVC_RTSP_EN
|
||||
if(xTaskCreate(uvc_rtsp_handle, ((const signed char*)"uvc_rtsp_handle"), 4096, param, tskIDLE_PRIORITY + 2, NULL) != pdPASS) {
|
||||
RTSP_ERROR("\r\n uvc_rtsp_handle: Create Task Error\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/************************************************************end of rtsp/rtp with motion-jpeg************************************************/
|
||||
25
USDK/component/common/example/uvc/example_uvc.h
Normal file
25
USDK/component/common/example/uvc/example_uvc.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef EXAMPLE_UVC_H
|
||||
#define EXAMPLE_UVC_H
|
||||
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "platform_opts.h"
|
||||
#include "dlist.h"
|
||||
#include "osdep_api.h"
|
||||
|
||||
#define UVC_RTSP_EN 1
|
||||
|
||||
//example structure to handle rtp_object operation in queue
|
||||
struct rtp_payload_queue
|
||||
{
|
||||
struct list_head wait_queue;
|
||||
_Mutex wait_mutex;
|
||||
struct list_head done_queue;
|
||||
_Mutex done_mutex;
|
||||
_Sema wait_sema; //up it whenever a rtp payload queue in wait_queue
|
||||
_Sema done_sema; //up it whenever a rtp payload queue in done_queue
|
||||
int flush_err;
|
||||
};
|
||||
|
||||
void example_uvc(void);
|
||||
|
||||
#endif /* EXAMPLE_UVC_H */
|
||||
8
USDK/component/common/example/uvc/readme.txt
Normal file
8
USDK/component/common/example/uvc/readme.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
THis is an example for USB Video Capture specifically for motion-jpeg capturing.
|
||||
|
||||
Please MAKE SURE to reserve enough heap size for UVC by raising configTOTAL_HEAP_SIZE in freeRTOSconfig.h & turning off some functions (e.g. WPS, JDSMART, ATcmd for internal and system) since image frame storing could consume quite large memory space.
|
||||
|
||||
TO switch on UVC example, make sure CONFIG_USB_EN is enabled (in platform_autoconf.h) & set CONFIG_EXAMPLE_UVC to 1 (in platform_opts.h).
|
||||
|
||||
TO combine uvc with rtsp server, make sure wlan module is enabled & set UVC_WLAN_TRANSFER to 1 (in example_uvc.h).
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/** @file
|
||||
|
||||
This example demonstrate how to implement wifi fast reconnection
|
||||
**/
|
||||
#include <platform_opts.h>
|
||||
#if defined(CONFIG_EXAMPLE_WLAN_FAST_CONNECT) && CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
#include <wlan_fast_connect/example_wlan_fast_connect.h>
|
||||
|
||||
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include "flash_api.h"
|
||||
#include <lwip_netconf.h>
|
||||
#ifdef USE_FLASH_EEP
|
||||
#include "flash_eep.h"
|
||||
#include "feep_config.h"
|
||||
#endif
|
||||
|
||||
write_reconnect_ptr p_write_reconnect_ptr;
|
||||
|
||||
extern void fATW0(void *arg);
|
||||
extern void fATW1(void *arg);
|
||||
extern void fATW2(void *arg);
|
||||
extern void fATWC(void *arg);
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* wifi connection indication trigger this function to save current
|
||||
* wifi profile in flash
|
||||
*
|
||||
* Condition:
|
||||
* CONFIG_EXAMPLE_WLAN_FAST_CONNECT flag is set
|
||||
*/
|
||||
|
||||
int wlan_write_reconnect_data_to_flash(u8 *data, uint32_t len)
|
||||
{
|
||||
if(data == NULL || len < sizeof(struct wlan_fast_reconnect)) return -1;
|
||||
DBG_8195A("WiFi connected at start %d ms\n", xTaskGetTickCount());
|
||||
#ifdef USE_FLASH_EEP
|
||||
flash_write_cfg(data, FEEP_ID_WIFI_CFG, sizeof(struct wlan_fast_reconnect));
|
||||
#else
|
||||
struct wlan_fast_reconnect read_data = {0};
|
||||
flash_t flash;
|
||||
if(!data) return -1;
|
||||
flash_stream_read(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (u8 *) &read_data);
|
||||
|
||||
//wirte it to flash if different content: SSID, Passphrase, Channel, Security type
|
||||
if(memcmp(data, (u8 *) &read_data, sizeof(struct wlan_fast_reconnect)) != 0) {
|
||||
DBG_8195A(" %s():not the same ssid/passphrase/channel, write new profile to flash\n", __func__);
|
||||
flash_erase_sector(&flash, FAST_RECONNECT_DATA);
|
||||
flash_stream_write(&flash, FAST_RECONNECT_DATA, len, (uint8_t *) data);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* After wifi init done, waln driver call this function to check whether
|
||||
* auto-connect is required.
|
||||
*
|
||||
* This function read previous saved wlan profile in flash and execute connection.
|
||||
*
|
||||
* Condition:
|
||||
* CONFIG_EXAMPLE_WLAN_FAST_CONNECT flag is set
|
||||
*/
|
||||
//scan_buf_arg scan_buf;
|
||||
|
||||
int wlan_init_done_callback()
|
||||
{
|
||||
flash_t flash;
|
||||
struct wlan_fast_reconnect *data;
|
||||
uint32_t channel;
|
||||
uint8_t pscan_config;
|
||||
char key_id[2] = {0};
|
||||
// wifi_disable_powersave();
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
//setup reconnection flag
|
||||
// u8 mode;
|
||||
// if(wifi_get_autoreconnect(&mode) > 0 && mode != 1)
|
||||
wifi_set_autoreconnect(1); // (not work if lib_wlan_mp.a ?)
|
||||
#endif
|
||||
DBG_8195A("WiFi Init after %d ms\n", xTaskGetTickCount());
|
||||
data = (struct wlan_fast_reconnect *)rtw_zmalloc(sizeof(struct wlan_fast_reconnect));
|
||||
if(data) {
|
||||
#ifdef USE_FLASH_EEP
|
||||
if (flash_read_cfg(data, FEEP_ID_WIFI_CFG, sizeof(struct wlan_fast_reconnect)) == sizeof(struct wlan_fast_reconnect)) {
|
||||
#else
|
||||
flash_stream_read(&flash, FAST_RECONNECT_DATA, sizeof(struct wlan_fast_reconnect), (uint8_t *)data);
|
||||
if(*((uint32_t *) data) != ~0x0) {
|
||||
#endif
|
||||
#if 1 // not use AT
|
||||
#if 0
|
||||
//set partial scan for entering to listen beacon quickly
|
||||
channel = data->channel & 0xFF;
|
||||
pscan_config = PSCAN_ENABLE |PSCAN_FAST_SURVEY; // PSCAN_SIMPLE_CONFIG |
|
||||
if(wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1) < 0)
|
||||
printf("Wifi set partial scan channel fail!\n");
|
||||
// rtw_network_info_t *wifi;
|
||||
// SC_connect_to_candidate_AP
|
||||
// SC_parse_scan_result_and_connect();
|
||||
if (wifi_connect(
|
||||
NULL,
|
||||
0,
|
||||
data->psk_essid,
|
||||
data->security_type,
|
||||
data->psk_passphrase,
|
||||
RTW_SECURITY_OPEN,
|
||||
NULL) == RTW_SUCCESS) {
|
||||
#else
|
||||
//set partial scan for entering to listen beacon quickly
|
||||
channel = data->channel & 0xFF;
|
||||
pscan_config = PSCAN_ENABLE |PSCAN_FAST_SURVEY; // PSCAN_SIMPLE_CONFIG |
|
||||
if(wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1) < 0)
|
||||
printf("Wifi set partial scan channel fail!\n");
|
||||
// channel = data->channel & 0xFF;
|
||||
wifi_set_channel(1); //channel);
|
||||
// wifi_set_channel_plan(channel);
|
||||
// pscan_config = PSCAN_ENABLE | PSCAN_FAST_SURVEY; // PSCAN_SIMPLE_CONFIG |
|
||||
// wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1);
|
||||
// DiagPrintf("\nScan end at start %d ms.\n", xTaskGetTickCount());
|
||||
// u8 bssid[ETH_ALEN] = { 0x1a,0xfe,0x34,0x99,0xad,0x1d };
|
||||
u8 bssid[ETH_ALEN] = { 0xbc,0xae,0xc5,0xeb,0x09,0x90 };
|
||||
|
||||
// if (wifi_connect(data->psk_essid, data->security_type, data->psk_passphrase, strlen(data->psk_essid), strlen(data->psk_passphrase), RTW_SECURITY_OPEN, NULL) == RTW_SUCCESS) {
|
||||
if (wifi_connect(
|
||||
bssid,
|
||||
1,
|
||||
data->psk_essid,
|
||||
data->security_type,
|
||||
data->psk_passphrase,
|
||||
data->channel>>28,
|
||||
NULL) == RTW_SUCCESS) {
|
||||
#endif
|
||||
// DBG_8195A("WiFi connected at start %dms\n", xTaskGetTickCount());
|
||||
#if CONFIG_LWIP_LAYER
|
||||
#ifdef USE_FLASH_EEP
|
||||
dhcp_cfg *p = (dhcp_cfg *)&data;
|
||||
p->mode = 3;
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
struct netif * pnetif = &xnetif[0];
|
||||
if(flash_read_cfg(p, FEEP_ID_DHCP_CFG, sizeof(dhcp_cfg)) > 1) {
|
||||
rtl_printf("Read dhcp_config: mode = %d, ip:%p, msk:%p, gw:%p\n", p->mode, p->ip, p->mask, p->gw);
|
||||
if(p->mode == 2) {
|
||||
netif_set_addr(pnetif, (ip_addr_t *)&p->ip, (ip_addr_t *)&p->mask, (ip_addr_t *)&p->gw);
|
||||
dhcps_init(pnetif);
|
||||
}
|
||||
else if(p->mode) LwIP_DHCP(0, DHCP_START);
|
||||
}
|
||||
else LwIP_DHCP(0, DHCP_START);
|
||||
if(p->mode == 3 && pnetif->ip_addr.addr != 0) {
|
||||
p->mode = 2;
|
||||
p->ip = pnetif->ip_addr.addr;
|
||||
p->gw = pnetif->gw.addr;
|
||||
p->mask = pnetif->netmask.addr;
|
||||
flash_write_cfg(p, FEEP_ID_DHCP_CFG, sizeof(dhcp_cfg));
|
||||
rtl_printf("Write dhcp_config: mode = %d, ip:%p, msk:%p, gw:%p\n", p->mode, p->ip, p->mask, p->gw);
|
||||
}
|
||||
#else
|
||||
LwIP_DHCP(0, DHCP_START);
|
||||
#endif //#if USE_FLASH_EEP
|
||||
#endif //#if CONFIG_LWIP_LAYER
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
connect_start();
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
// flash_read_cfg(psk_essid, 0x5731, sizeof(psk_essid));
|
||||
memcpy(psk_essid, data->psk_essid, sizeof(data->psk_essid));
|
||||
// flash_read_cfg(psk_passphrase, 0x5732, sizeof(psk_passphrase));
|
||||
memcpy(psk_passphrase, data->psk_passphrase, sizeof(data->psk_passphrase));
|
||||
// flash_read_cfg(wpa_global_PSK, 0x5733, sizeof(wpa_global_PSK));
|
||||
memcpy(wpa_global_PSK, data->wpa_global_PSK, sizeof(data->wpa_global_PSK));
|
||||
//set partial scan for entering to listen beacon quickly
|
||||
pscan_config = PSCAN_ENABLE | PSCAN_FAST_SURVEY;
|
||||
channel = data->channel & 0xFF;
|
||||
wifi_set_pscan_chan((uint8_t *)&channel, &pscan_config, 1);
|
||||
//set wifi connect
|
||||
switch(data->security_type){
|
||||
case RTW_SECURITY_OPEN:
|
||||
fATW0((char*)psk_essid);
|
||||
break;
|
||||
case RTW_SECURITY_WEP_PSK:
|
||||
fATW0((char*)psk_essid);
|
||||
fATW1((char*)psk_passphrase);
|
||||
sprintf(key_id,"%d",(char) (data->channel>>28));
|
||||
fATW2(key_id);
|
||||
break;
|
||||
case RTW_SECURITY_WPA_TKIP_PSK:
|
||||
case RTW_SECURITY_WPA2_AES_PSK:
|
||||
fATW0((char*)psk_essid);
|
||||
fATW1((char*)psk_passphrase);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
fATWC(NULL);
|
||||
#endif // use AT
|
||||
}
|
||||
rtw_mfree(data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void example_wlan_fast_connect()
|
||||
{
|
||||
// Call back from wlan driver after wlan init done
|
||||
p_wlan_init_done_callback = wlan_init_done_callback;
|
||||
|
||||
// Call back from application layer after wifi_connection success
|
||||
p_write_reconnect_ptr = wlan_write_reconnect_data_to_flash;
|
||||
|
||||
}
|
||||
|
||||
#endif // defined(CONFIG_EXAMPLE_WLAN_FAST_CONNECT) && CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef __EXAMPLE_FAST_RECONNECTION_H__
|
||||
#define __EXAMPLE_FAST_RECONNECTION_H__
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright(c) 2007 - 2015 Realtek Corporation. All rights reserved.
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
#include "FreeRTOS.h"
|
||||
#include <autoconf.h>
|
||||
#include "main.h"
|
||||
|
||||
#define IW_PASSPHRASE_MAX_SIZE 64
|
||||
//#define FAST_RECONNECT_DATA (0x80000 - 0x1000)
|
||||
#define NDIS_802_11_LENGTH_SSID 32
|
||||
#define A_SHA_DIGEST_LEN 20
|
||||
|
||||
|
||||
struct wlan_fast_reconnect {
|
||||
unsigned char psk_essid[NDIS_802_11_LENGTH_SSID + 4];
|
||||
unsigned char psk_passphrase[IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
unsigned char wpa_global_PSK[A_SHA_DIGEST_LEN * 2];
|
||||
uint32_t channel;
|
||||
uint32_t security_type;
|
||||
#if ATCMD_VER == ATVER_2
|
||||
uint8_t enable;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef int (*wlan_init_done_ptr)(void);
|
||||
typedef int (*write_reconnect_ptr)(uint8_t *data, uint32_t len);
|
||||
|
||||
|
||||
//Variable
|
||||
extern unsigned char psk_essid[NET_IF_NUM][NDIS_802_11_LENGTH_SSID+4];
|
||||
extern unsigned char psk_passphrase[NET_IF_NUM][IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
extern unsigned char wpa_global_PSK[NET_IF_NUM][A_SHA_DIGEST_LEN * 2];
|
||||
extern unsigned char psk_passphrase64[IW_PASSPHRASE_MAX_SIZE + 1];
|
||||
|
||||
//Function
|
||||
extern wlan_init_done_ptr p_wlan_init_done_callback;
|
||||
extern write_reconnect_ptr p_write_reconnect_ptr;
|
||||
|
||||
void example_wlan_fast_connect(void);
|
||||
|
||||
#endif //#ifndef __EXAMPLE_FAST_RECONNECTION_H__
|
||||
111
USDK/component/common/example/xml/example_xml.c
Normal file
111
USDK/component/common/example/xml/example_xml.c
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <platform_stdlib.h>
|
||||
#include "xml.h"
|
||||
|
||||
static void example_xml_thread(void *param)
|
||||
{
|
||||
/* Create XML document
|
||||
* <Home:Light xmlns:Home="http://www.home.com" xmlns="http://www.device.com" fw_ver="1.0.0">
|
||||
* <Power>on</Power>
|
||||
* <Color>
|
||||
* <Red>255</Red>
|
||||
* <Green>255</Green>
|
||||
* <Blud>255</Blue>
|
||||
* </Color>
|
||||
* </Home:Light>
|
||||
*/
|
||||
struct xml_node *light_node, *power_node, *color_node, *red_node, *green_node, *blue_node;
|
||||
|
||||
// Creates element with (prefix, tag name, namespace uri), add element and text node as child
|
||||
light_node = xml_new_element("Home", "Light", "http://www.home.com");
|
||||
power_node = xml_new_element(NULL, "Power", NULL);
|
||||
xml_add_child(power_node, xml_new_text("on"));
|
||||
color_node = xml_new_element(NULL, "Color", NULL);
|
||||
red_node = xml_new_element(NULL, "Red", NULL);
|
||||
xml_add_child(red_node, xml_new_text("255"));
|
||||
green_node = xml_new_element(NULL, "Green", NULL);
|
||||
xml_add_child(green_node, xml_new_text("255"));
|
||||
blue_node = xml_new_element(NULL, "Blue", NULL);
|
||||
xml_add_child(blue_node, xml_new_text("255"));
|
||||
xml_add_child(light_node, power_node);
|
||||
xml_add_child(light_node, color_node);
|
||||
xml_add_child(color_node, red_node);
|
||||
xml_add_child(color_node, green_node);
|
||||
xml_add_child(color_node, blue_node);
|
||||
|
||||
// Add or modify attributes
|
||||
xml_set_attribute(light_node, "xmlns", "http://www.device.com");
|
||||
xml_set_attribute(light_node, "fw_ver", "1.0.0");
|
||||
|
||||
// Dump XML document to memory buffer, equal to xml_dump_tree_ex(node, NULL, 0, 0);
|
||||
char *dump_buf = xml_dump_tree(light_node);
|
||||
printf("\n%s\n", dump_buf);
|
||||
// Free dump buffer
|
||||
xml_free(dump_buf);
|
||||
// Dump XML document to memory buffer with prolog, new line, aligment
|
||||
dump_buf = xml_dump_tree_ex(light_node, "<?xml version=\"1.0\"?>", 1, 4);
|
||||
printf("\n%s\n", dump_buf);
|
||||
xml_free(dump_buf);
|
||||
|
||||
// Delete XML tree to free memory
|
||||
xml_delete_tree(light_node);
|
||||
|
||||
/* Parse XML document */
|
||||
char *doc = "\
|
||||
<?xml version=\"1.0\"?>\
|
||||
<!--sensor example-->\
|
||||
<Home:Sensor>\
|
||||
<Thermostat>\
|
||||
<Mode>auto</Mode>\
|
||||
<Temperature unit=\"celsius\">25.5</Temperature>\
|
||||
</Thermostat>\
|
||||
</Home:Sensor>";
|
||||
|
||||
// Parse document buffer to XML tree. Prolog will be dropped
|
||||
struct xml_node *root = xml_parse(doc, strlen(doc));
|
||||
|
||||
if(root) {
|
||||
dump_buf = xml_dump_tree_ex(root, NULL, 1, 4);
|
||||
printf("\n%s\n", dump_buf);
|
||||
xml_free(dump_buf);
|
||||
|
||||
// Search by XPath, prefix and name in path should be matched
|
||||
struct xml_node_set *set = xml_find_path(root, "/Home:Sensor/Thermostat/Temperature");
|
||||
|
||||
if(set->count) {
|
||||
printf("\nFind %d element by %s\n", set->count, "/Home:Sensor/Thermostat/Temperature");
|
||||
|
||||
// Get XML tree search result 0
|
||||
struct xml_node *temperature_node = set->node[0];
|
||||
|
||||
if(xml_is_text(temperature_node->child)) {
|
||||
// Get text
|
||||
printf("Temperature[0] is %s\n", temperature_node->child->text);
|
||||
}
|
||||
|
||||
// Get attribute
|
||||
char *unit = xml_get_attribute(temperature_node, "unit");
|
||||
printf("Unit is \"%s\"\n", unit);
|
||||
// Free attribute search result
|
||||
xml_free(unit);
|
||||
}
|
||||
|
||||
// Delete XML tree search result to free memory
|
||||
xml_delete_set(set);
|
||||
|
||||
xml_delete_tree(root);
|
||||
}
|
||||
else {
|
||||
printf("Xml parse failed\n");
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void example_xml(void)
|
||||
{
|
||||
if(xTaskCreate(example_xml_thread, ((const char*)"example_xml_thread"), 1024, NULL, tskIDLE_PRIORITY + 1, NULL) != pdPASS)
|
||||
printf("\n\r%s xTaskCreate(init_thread) failed", __FUNCTION__);
|
||||
}
|
||||
|
||||
6
USDK/component/common/example/xml/example_xml.h
Normal file
6
USDK/component/common/example/xml/example_xml.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef EXAMPLE_XML_H
|
||||
#define EXAMPLE_XML_H
|
||||
|
||||
void example_xml(void);
|
||||
|
||||
#endif /* EXAMPLE_XML_H */
|
||||
13
USDK/component/common/example/xml/readme.txt
Normal file
13
USDK/component/common/example/xml/readme.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
XML EXAMPLE
|
||||
|
||||
Description:
|
||||
The creation of a light XML document is used as the example of XML document generation.
|
||||
The processing of a sensor XML document is used as the example of XML document parsing.
|
||||
|
||||
Configuration:
|
||||
[platform_opts.h]
|
||||
#define CONFIG_EXAMPLE_XML 1
|
||||
|
||||
Execution:
|
||||
An XML example thread will be started automatically when booting.
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue