BigW Consortium Gitlab

Commit 25fb3e36 by Gabor

lv_app_wifi/gsm: save/load config.

parent 81138609
......@@ -79,6 +79,8 @@ static void tcp_transf_cb(gsm_state_t state, const char * txt);
static void win_title_refr(void);
static void save_conf(lv_app_inst_t * app);
/**********************
* STATIC VARIABLES
**********************/
......@@ -100,6 +102,10 @@ static lv_app_dsc_t my_app_dsc =
static lv_app_inst_t * app_act_com;
static char def_apn[128];
static char def_ip[32];
static char def_port[16];
/**********************
* MACROS
**********************/
......@@ -114,10 +120,58 @@ static lv_app_inst_t * app_act_com;
*/
const lv_app_dsc_t * lv_app_gsm_init(void)
{
#ifdef LV_APP_GSM_CONF_PATH
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_GSM_CONF_PATH, FS_MODE_RD);
if(res == FS_RES_NOT_EX) {
res = fs_open(&f, LV_APP_GSM_CONF_PATH, FS_MODE_WR | FS_MODE_RD);
if(res == FS_RES_OK) {
const char * def_conf = "apn\n100.101.102.103\n1234";
fs_write(&f, def_conf, strlen(def_conf) + 1, NULL);
fs_seek(&f, 0);
}
}
gsmmng_set_last_apn(LV_APP_GSM_APN_DEF);
gsmmng_set_last_tcp(LV_APP_GSM_IP_DEF, LV_APP_GSM_PORT_DEF);
if(res == FS_RES_OK) {
volatile char buf[256];
volatile uint32_t rn;
fs_read(&f, (char *)buf, sizeof(buf) - 1, (uint32_t *)&rn);
volatile uint16_t i;
volatile uint16_t j = 0;
volatile uint8_t line_cnt = 0;
for(i = 0; i < rn; i++) {
if(buf[i] != '\n') {
if(line_cnt == 0) def_apn[j] = buf[i];
if(line_cnt == 1) def_ip[j] = buf[i];
if(line_cnt == 2) def_port[j] = buf[i];
j++;
} else {
if(line_cnt == 0) def_apn[j] = '\0';
if(line_cnt == 1) def_ip[j] = '\0';
if(line_cnt == 2) def_port[j] = '\0';
j = 0;
line_cnt ++;
}
}
fs_close(&f);
} else {
lv_app_notice_add("SD card error");
}
#else
strcpy(def_apn, LV_APP_GSM_APN_DEF);
strcpy(def_ip, LV_APP_GSM_IP_DEF);
strcpy(def_port, LV_APP_GSM_PORT_DEF);
#endif
#if LV_APP_GSM_AUTO_CONNECT != 0
gsmmng_set_last_apn(def_apn);
gsmmng_set_last_tcp(def_ip, def_port);
#endif
ptask_create(gsm_state_monitor_task, GSM_MONITOR_PERIOD, PTASK_PRIO_LOW, NULL);
return &my_app_dsc;
......@@ -137,9 +191,9 @@ static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
my_app_data_t * adata = app->app_data;
strcpy(adata->set_apn, LV_APP_GSM_APN_DEF);
strcpy(adata->set_ip, LV_APP_GSM_IP_DEF);
strcpy(adata->set_port, LV_APP_GSM_PORT_DEF);
strcpy(adata->set_apn, def_apn);
strcpy(adata->set_ip, def_ip);
strcpy(adata->set_port, def_port);
}
/**
......@@ -293,7 +347,8 @@ static lv_action_res_t netw_con_rel_action(lv_obj_t * btn, lv_dispi_t* dispi)
gsmmng_set_last_apn(adata->set_apn);
gsmmng_set_last_tcp(adata->set_ip, adata->set_port);
gsmmng_reconnect();
lv_app_notice_add("Connecting to GSM network\n%s, %s:%s",
save_conf(app);
lv_app_notice_add("Connecting to GSM network\n%s\n %s:%s",
adata->set_apn, adata->set_ip, adata->set_port);
return LV_ACTION_RES_OK;
}
......@@ -402,5 +457,21 @@ static void win_title_refr(void)
}
}
static void save_conf(lv_app_inst_t * app)
{
#ifdef LV_APP_GSM_CONF_PATH
my_app_data_t * adata = app->app_data;
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_GSM_CONF_PATH, FS_MODE_WR);
if(res == FS_RES_OK) {
char buf[256];
sprintf(buf,"%s\n%s\n%s", adata->set_apn, adata->set_ip, adata->set_port);
fs_write(&f, buf, strlen(buf) + 1, NULL);
fs_close(&f);
}
#endif
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
......@@ -14,6 +14,7 @@
#include "misc/os/ptask.h"
#include "hal/systick/systick.h"
#include "misc/comm/wifimng.h"
#include "misc/fs/fat32/integer.h"
#include <stdio.h>
/*********************
......@@ -89,6 +90,8 @@ static void tcp_transf_cb(wifi_state_t state, const char * txt);
static void win_title_refr(void);
static void save_conf(lv_app_inst_t * app);
/**********************
* STATIC VARIABLES
**********************/
......@@ -108,6 +111,11 @@ static lv_app_dsc_t my_app_dsc =
.win_data_size = sizeof(my_win_data_t),
};
static char def_ssid[64];
static char def_pwd[64];
static char def_ip[32];
static char def_port[16];
static char ssid_list[SSID_LIST_MAX_LENGTH];
static lv_app_inst_t * app_act_com;
......@@ -126,10 +134,61 @@ static lv_app_inst_t * app_act_com;
const lv_app_dsc_t * lv_app_wifi_init(void)
{
strcpy(ssid_list, "");
#ifdef LV_APP_WIFI_CONF_PATH
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_WIFI_CONF_PATH, FS_MODE_RD);
if(res == FS_RES_NOT_EX) {
res = fs_open(&f, LV_APP_WIFI_CONF_PATH, FS_MODE_WR | FS_MODE_RD);
if(res == FS_RES_OK) {
const char * def_conf = "ssid\npwd\n100.101.102.103\n1234";
fs_write(&f, def_conf, strlen(def_conf) + 1, NULL);
fs_seek(&f, 0);
}
}
if(res == FS_RES_OK) {
volatile char buf[256];
volatile uint32_t rn;
fs_read(&f, (char *)buf, sizeof(buf) - 1, (uint32_t *)&rn);
volatile uint16_t i;
volatile uint16_t j = 0;
volatile uint8_t line_cnt = 0;
for(i = 0; i < rn; i++) {
if(buf[i] != '\n') {
if(line_cnt == 0) def_ssid[j] = buf[i];
if(line_cnt == 1) def_pwd[j] = buf[i];
if(line_cnt == 2) def_ip[j] = buf[i];
if(line_cnt == 3) def_port[j] = buf[i];
j++;
} else {
if(line_cnt == 0) def_ssid[j] = '\0';
if(line_cnt == 1) def_pwd[j] = '\0';
if(line_cnt == 2) def_ip[j] = '\0';
if(line_cnt == 3) def_port[j] = '\0';
j = 0;
line_cnt ++;
}
}
fs_close(&f);
} else {
lv_app_notice_add("SD card error");
}
#else
strcpy(def_ssid, LV_APP_WIFI_SSID_DEF);
strcpy(def_pwd, LV_APP_WIFI_PWD_DEF);
strcpy(def_ip, LV_APP_WIFI_IP_DEF);
strcpy(def_port, LV_APP_WIFI_PORT_DEF);
#endif
#if LV_APP_WIFI_AUTO_CONNECT != 0
wifimng_set_last_netw(LV_APP_WIFI_SSID_DEF, LV_APP_WIFI_PWD_DEF);
wifimng_set_last_tcp(LV_APP_WIFI_IP_DEF, LV_APP_WIFI_PORT_DEF);
wifimng_set_last_netw(def_ssid, def_pwd);
wifimng_set_last_tcp(def_ip, def_port);
#endif
ptask_create(wifi_state_monitor_task, WIFI_MONITOR_PERIOD, PTASK_PRIO_LOW, NULL);
......@@ -151,10 +210,10 @@ static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
my_app_data_t * adata = app->app_data;
strcpy(adata->set_ssid, LV_APP_WIFI_SSID_DEF);
strcpy(adata->set_pwd, LV_APP_WIFI_PWD_DEF);
strcpy(adata->set_ip, LV_APP_WIFI_IP_DEF);
strcpy(adata->set_port, LV_APP_WIFI_PORT_DEF);
strcpy(adata->set_ssid, def_ssid);
strcpy(adata->set_pwd, def_pwd);
strcpy(adata->set_ip, def_ip);
strcpy(adata->set_port, def_port);
adata->last_msg_dp = NULL;
adata->last_msg_size = 0;
}
......@@ -340,6 +399,7 @@ static lv_action_res_t netw_con_rel_action(lv_obj_t * btn, lv_dispi_t* dispi)
wifimng_set_last_netw(adata->set_ssid, adata->set_pwd);
wifimng_set_last_tcp(adata->set_ip, adata->set_port);
wifimng_reconnect();
save_conf(app);
lv_app_notice_add("Connecting to WiFi network\n%s, %s:%s",
adata->set_ssid, adata->set_ip, adata->set_port);
return LV_ACTION_RES_OK;
......@@ -513,5 +573,21 @@ static void win_title_refr(void)
}
}
static void save_conf(lv_app_inst_t * app)
{
#ifdef LV_APP_WIFI_CONF_PATH
my_app_data_t * adata = app->app_data;
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_WIFI_CONF_PATH, FS_MODE_WR);
if(res == FS_RES_OK) {
char buf[256];
sprintf(buf,"%s\n%s\n%s\n%s", adata->set_ssid, adata->set_pwd, adata->set_ip, adata->set_port);
fs_write(&f, buf, strlen(buf) + 1, NULL);
fs_close(&f);
}
#endif
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
......@@ -244,31 +244,44 @@
#define LV_APP_FILES_CHUNK_MAX_SIZE 1024 /*Max chunk size when the user sets it*/
#endif /*USE_LV_APP_FILES != 0*/
/*Benchmark*/
#define USE_LV_APP_BENCHMARK 1
#if USE_LV_APP_BENCHMARK != 0
/*No settings*/
#endif
/*WiFi (requires hal/wifi)*/
#define USE_LV_APP_WIFI 0
/*WiFi*/
#define USE_LV_APP_WIFI 1
#if USE_LV_APP_WIFI != 0
#define LV_APP_WIFI_SSID_DEF "my_ssid"
#define LV_APP_WIFI_PWD_DEF "my_pasword"
#define LV_APP_WIFI_IP_DEF "10.11.12.13"
#define LV_APP_WIFI_PORT_DEF "5555"
#define LV_APP_WIFI_CONF_PATH "S:/wifi_conf.txt" /*Save config. here. Comment to use def. value*/
#ifndef LV_APP_WIFI_CONF_PATH
#define LV_APP_WIFI_SSID_DEF "ssid"
#define LV_APP_WIFI_PWD_DEF "pwd"
#define LV_APP_WIFI_IP_DEF "100.101.102.103"
#define LV_APP_WIFI_PORT_DEF "1234"
#endif /*LV_APP_WIFI_CONF_PATH*/
#define LV_APP_WIFI_AUTO_CONNECT 1 /*Try to connect at start up to the deafult SSID and IP:PORT*/
#endif /*USE_LV_APP_WIFI != 0*/
/*GSM (requires hal/gsm)*/
#define USE_LV_APP_GSM 0
/*GSM*/
#define USE_LV_APP_GSM 1
#if USE_LV_APP_GSM != 0
#define LV_APP_GSM_APN_DEF "my_apn"
#define LV_APP_GSM_IP_DEF "10.11.12.13"
#define LV_APP_GSM_PORT_DEF "5555"
#define LV_APP_GSM_AUTO_CONNECT 1 /*Try to connect at start up with the deafult APN and IP:PORT*/
#define LV_APP_GSM_CONF_PATH "S:/gsm_conf.txt" /*Save config. here. Comment to use def. value*/
#ifndef LV_APP_GSM_CONF_PATH
#define LV_APP_GSM_APN_DEF "apn"
#define LV_APP_GSM_IP_DEF "101.102.103.104"
#define LV_APP_GSM_PORT_DEF "1234"
#endif /*LV_APP_GSM_CONF_PATH*/
#define LV_APP_GSM_AUTO_CONNECT 1 /*Try to connect at start up with the deafult APN and IP:PORT*/
#endif /*USE_LV_APP_GSM != 0*/
/*Ethernet*/
#define USE_LV_APP_ETHERNET 1
#if USE_LV_APP_ETHERNET != 0
/*No settings*/
#endif /*USE_LV_APP_ETHERNET != 0*/
#endif /*LV_APP_ENABLE != 0*/
#endif /*LV_CONF_H*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment