Skip to content

Commit 6e1cae5

Browse files
committed
add secret_config
1 parent fca6312 commit 6e1cae5

File tree

4 files changed

+104
-32
lines changed

4 files changed

+104
-32
lines changed

data/yaml/SC_BasicConfig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ extend_config_filename: "/yaml/SC_ExConfig.yaml" # Configuration file for th
4646
extend_config_filesize: 2048 # Buffer size for feature extensions
4747
secret_config_filename: "/yaml/SC_SecConfig.yaml" # Configuration file for the File for personal information.
4848
secret_config_filesize: 2048 # Buffer size for personal information.
49+
secret_info_show: true # Whether personal information is output to the log or not.

examples/Basic/src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ void setup() {
1414
delay(2000);
1515
config.loadConfig(SD, "/yaml/SC_BasicConfig.yaml");
1616

17+
config.getWiFiSetting();
18+
1719
}
1820

1921
void loop() {

src/Stackchan_system_config.cpp

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ void StackchanSystemConfig::setDefaultParameters() {
6464
_servo_type = 0;
6565
_servo[AXIS_X].start_degree = 90;
6666
_servo[AXIS_Y].start_degree = 90;
67+
_secret_config_show = false;
6768
_extend_config_filename = "";
6869
_extend_config_filesize = 0;
70+
_secret_config_filename = "";
71+
_secret_config_filesize = 0;
72+
6973
}
7074

7175
void StackchanSystemConfig::loadConfig(fs::FS& fs, const char *yaml_filename) {
@@ -85,12 +89,40 @@ void StackchanSystemConfig::loadConfig(fs::FS& fs, const char *yaml_filename) {
8589
// JSONファイルが見つからない場合はデフォルト値を利用します。
8690
setDefaultParameters();
8791
}
88-
if (_extend_config_filesize >= 0) {
92+
if (_secret_config_filename > 0) {
93+
loadSecretConfig(fs, _secret_config_filename.c_str(), _secret_config_filesize);
94+
}
95+
if (_extend_config_filesize > 0) {
8996
loadExtendConfig(fs, _extend_config_filename.c_str(), _extend_config_filesize);
9097
}
9198
printAllParameters();
9299
}
93100

101+
void StackchanSystemConfig::loadSecretConfig(fs::FS& fs, const char* yaml_filename, uint32_t yaml_size) {
102+
M5_LOGI("----- StackchanSecretConfig::loadConfig:%s\n", yaml_filename);
103+
File file = fs.open(yaml_filename);
104+
if (file) {
105+
DynamicJsonDocument doc(yaml_size);
106+
auto err = deserializeYml( doc, file);
107+
if (err) {
108+
M5_LOGE("yaml file read error: %s\n", yaml_filename);
109+
M5_LOGE("error%s\n", err.c_str());
110+
}
111+
if (_secret_info_show) {
112+
// 個人的な情報をログに表示する。
113+
M5_LOGI("=======================================================================================");
114+
M5_LOGI("下記の情報は公開してはいけません。(The following information must not be disclosed.)");
115+
M5_LOGI("");
116+
serializeJsonPretty(doc, Serial);
117+
setSecretSettings(doc);
118+
M5_LOGI("");
119+
printSecretParameters();
120+
M5_LOGI("ここまでの情報は公開してはいけません。(No information should be disclosed so far.)");
121+
M5_LOGI("=======================================================================================");
122+
}
123+
}
124+
}
125+
94126
void StackchanSystemConfig::setSystemConfig(DynamicJsonDocument doc) {
95127
JsonObject servo = doc["servo"];
96128
_servo[AXIS_X].pin = servo["pin"]["x"];
@@ -118,9 +150,6 @@ void StackchanSystemConfig::setSystemConfig(DynamicJsonDocument doc) {
118150
_bluetooth.starting_state = doc["bluetooth"]["starting_state"];//.as<bool>();
119151
_bluetooth.start_volume = doc["bluetooth"]["start_volume"];
120152

121-
_wifi.ssid = doc["wifi"]["ssid"].as<String>();
122-
_wifi.password = doc["wifi"]["password"].as<String>();
123-
124153
_auto_power_off_time = doc["auto_power_off_time"];
125154
_font_language_code = doc["balloon"]["font_language"].as<String>();
126155

@@ -145,10 +174,21 @@ void StackchanSystemConfig::setSystemConfig(DynamicJsonDocument doc) {
145174
_servo[AXIS_X].start_degree = 90;
146175
_servo[AXIS_Y].start_degree = 90;
147176
}
148-
177+
_secret_info_show = doc["sercret_info_show"].as<bool>();
178+
_secret_config_filename = doc["secret_config_filename"].as<String>();
179+
_secret_config_filesize = doc["secret_config_filesize"];
149180
_extend_config_filename = doc["extend_config_filename"].as<String>();
150181
_extend_config_filesize = doc["extend_config_filesize"];
182+
}
151183

184+
void StackchanSystemConfig::setSecretConfig(DynamicJsonDocument doc) {
185+
186+
_secret_config.wifi_info.ssid = doc["wifi"]["ssid"].as<String>();
187+
_secret_config.wifi_info.password = doc["wifi"]["password"].as<String>();
188+
189+
_secret_config.apikey.stt = doc["apikey"]["stt"].as<String>();
190+
_secret_config.apikey.aiservice = doc["apikey"]["aiservice"].as<String>();
191+
_secret_config.apikey.tts = doc["apikey"]["tts"].as<String>();
152192

153193
}
154194

@@ -164,39 +204,48 @@ const lgfx::IFont* StackchanSystemConfig::getFont() {
164204
}
165205

166206
void StackchanSystemConfig::printAllParameters() {
167-
M5_LOGI("servo:pin_x:%d\n", _servo[AXIS_X].pin);
168-
M5_LOGI("servo:pin_y:%d\n", _servo[AXIS_Y].pin);
169-
M5_LOGI("servo:offset_x:%d\n", _servo[AXIS_X].offset);
170-
M5_LOGI("servo:offset_y:%d\n", _servo[AXIS_Y].offset);
207+
M5_LOGI("servo:pin_x:%d", _servo[AXIS_X].pin);
208+
M5_LOGI("servo:pin_y:%d", _servo[AXIS_Y].pin);
209+
M5_LOGI("servo:offset_x:%d", _servo[AXIS_X].offset);
210+
M5_LOGI("servo:offset_y:%d", _servo[AXIS_Y].offset);
171211
for (int i=0;i<_mode_num;i++) {
172-
M5_LOGI("mode:%s\n", _servo_interval[i].mode_name);
173-
M5_LOGI("interval_min:%d\n", _servo_interval[i].interval_min);
174-
M5_LOGI("interval_max:%d\n", _servo_interval[i].interval_max);
175-
M5_LOGI("move_min:%d\n", _servo_interval[i].move_min);
176-
M5_LOGI("move_max:%d\n", _servo_interval[i].move_max);
212+
M5_LOGI("mode:%s", _servo_interval[i].mode_name);
213+
M5_LOGI("interval_min:%d", _servo_interval[i].interval_min);
214+
M5_LOGI("interval_max:%d", _servo_interval[i].interval_max);
215+
M5_LOGI("move_min:%d", _servo_interval[i].move_min);
216+
M5_LOGI("move_max:%d", _servo_interval[i].move_max);
177217
}
178-
M5_LOGI("mode_num:%d\n", _mode_num);
179-
M5_LOGI("WiFi SSID: %s\n", _wifi.ssid.c_str());
180-
M5_LOGI("WiFi PASS: %s\n", _wifi.password.c_str());
181-
M5_LOGI("Bluetooth_device_name:%s\n", _bluetooth.device_name.c_str());
182-
M5_LOGI("Bluetooth_starting_state:%s\n", _bluetooth.starting_state ? "true":"false");
183-
M5_LOGI("Bluetooth_start_volume:%d\n", _bluetooth.start_volume);
184-
M5_LOGI("auto_power_off_time:%d\n", _auto_power_off_time);
185-
M5_LOGI("font_language:%s\n", _font_language_code);
218+
M5_LOGI("mode_num:%d", _mode_num);
219+
M5_LOGI("WiFi SSID: %s", _wifi.ssid.c_str());
220+
M5_LOGI("WiFi PASS: %s", _wifi.password.c_str());
221+
M5_LOGI("Bluetooth_device_name:%s", _bluetooth.device_name.c_str());
222+
M5_LOGI("Bluetooth_starting_state:%s", _bluetooth.starting_state ? "true":"false");
223+
M5_LOGI("Bluetooth_start_volume:%d", _bluetooth.start_volume);
224+
M5_LOGI("auto_power_off_time:%d", _auto_power_off_time);
225+
M5_LOGI("font_language:%s", _font_language_code);
186226
for (int i=0;i<_lyrics_num;i++) {
187-
M5_LOGI("lyrics:%d:%s\n", i, _lyrics[i].c_str());
227+
M5_LOGI("lyrics:%d:%s", i, _lyrics[i].c_str());
188228
}
189-
M5_LOGI("led_lr:%d\n", _led_lr);
190-
M5_LOGI("led_pin:%d\n", _led_pin);
191-
M5_LOGI("use takao_base:%s\n", _takao_base ? "true":"false");
192-
M5_LOGI("ServoTypeStr:%s\n", _servo_type_str.c_str());
193-
M5_LOGI("ServoType: %d\n", _servo_type);
194-
M5_LOGI("ExtendConfigFileName: %s\n", _extend_config_filename.c_str());
195-
M5_LOGI("ExtendConfigFileSize: %d\n", _extend_config_filesize);
229+
M5_LOGI("led_lr:%d", _led_lr);
230+
M5_LOGI("led_pin:%d", _led_pin);
231+
M5_LOGI("use takao_base:%s", _takao_base ? "true":"false");
232+
M5_LOGI("ServoTypeStr:%s", _servo_type_str.c_str());
233+
M5_LOGI("ServoType: %d", _servo_type);
234+
M5_LOGI("SecretConfigFileName: %s", _secret_config_filename.c_str());
235+
M5_LOGI("SecretConfigFileSize: %d", _secret_config_filesize);
236+
M5_LOGI("ExtendConfigFileName: %s", _extend_config_filename.c_str());
237+
M5_LOGI("ExtendConfigFileSize: %d", _extend_config_filesize);
196238

197239
printExtParameters();
198240
}
199241

242+
void StackchanSystemConfig::printSecretParameters() {
243+
M5_LOGI("wifi_ssid: %s", _secret_config.wifi_info.ssid.c_str());
244+
M5_LOGI("wifi_passws: %s", _secret_config.wifi_info.password.c_str());
245+
M5_LOGI("apikey_stt: %s", _secret_config.apikey.stt.c_str());
246+
M5_LOGI("apikey_aiservice: %s", _secret_config.apikey.aiservice.c_str());
247+
M5_LOGI("apikey_tts: %s", _secret_config.apikey.tts.c_str());
248+
}
200249
void StackchanSystemConfig::loadExtendConfig(fs::FS& fs, const char* filename, uint32_t yaml_size) { };
201250
void StackchanSystemConfig::setExtendSettings(DynamicJsonDocument doc) { if ( _extend_config_filename == "" ) return; };
202251
void StackchanSystemConfig::printExtParameters(void) {};

src/Stackchan_system_config.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ typedef struct WiFi {
2727
String password;
2828
} wifi_s;
2929

30+
typedef struct APIKeys {
31+
String stt;
32+
String ai_service;
33+
String tts;
34+
} api_keys_s;
35+
36+
37+
typedef struct SecretItems {
38+
wifi_s wifi_info;
39+
api_keys_s api_key;
40+
} secret_config_s;
41+
3042
typedef struct ServoInitialParam {
3143
uint8_t pin;
3244
uint16_t offset;
@@ -55,12 +67,18 @@ class StackchanSystemConfig {
5567
bool _takao_base; // Takao_Baseを使い後ろから給電する場合にtrue
5668
String _servo_type_str;
5769
uint8_t _servo_type; // サーボの種類 (0: PWMサーボ, 1: Feetech SCS0009)
58-
wifi_s _wifi; // wifi ssid and pass
5970
String _extend_config_filename; // 使用するアプリ側で拡張した設定が必要な場合に使用
6071
uint32_t _extend_config_filesize; // 拡張設定ファイルのサイズ
72+
String _secret_config_filename; // 個人情報の設定値を定義したファイル
73+
uint32_t _secret_config_filesize; // 個人情報設定ファイルのサイズ
74+
secret_config_s _secret_config; // 個人情報の構造体
75+
bool _secret_info_show; // 個人情報をログに出すかどうか
6176
void setDefaultParameters();
6277
void setSystemConfig(DynamicJsonDocument doc);
6378

79+
void loadSecretConfig(fs::FS& fs, const char* yaml_filename, uint32_t yaml_size);
80+
void setSecretSettings(DynamicJsonDocument doc);
81+
void printSecretParameters(void);
6482
public:
6583
StackchanSystemConfig();
6684
~StackchanSystemConfig();
@@ -71,7 +89,9 @@ class StackchanSystemConfig {
7189
servo_initial_param_s* getServoInfo(uint8_t servo_axis_no) { return &_servo[servo_axis_no]; }
7290
servo_interval_s* getServoInterval(AvatarMode avatar_mode) { return &_servo_interval[avatar_mode]; }
7391
bluetooth_s* getBluetoothSetting() { return &_bluetooth; }
74-
wifi_s* getWiFiSetting() { return &_wifi; }
92+
wifi_s* getWiFiSetting() { return &_secret_config.wifi_info; }
93+
api_keys_s getAPISetting() { return &_secret_config.api_key; }
94+
secret_config_s* getSecretSetting() { return &_secret_config; }
7595
String* getLyric(uint8_t no) { return &_lyrics[no]; }
7696
uint8_t getLyrics_num() { return _lyrics_num; }
7797
uint32_t getAutoPowerOffTime() { return _auto_power_off_time; }

0 commit comments

Comments
 (0)