Skip to content

Commit bccfc3d

Browse files
authored
Support Arduino IDE1 portable SDK (#149)
- supported portable SDK for Windows & Linux - added SHA-256 digital signature for Windows OS executables Verification: - verified on arduino-1.8.19-windows IDE - verified on arduino-1.8.19-linux64 IDE
1 parent 18830fb commit bccfc3d

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

Ameba_misc/Ameba_tools/ino_validation/version_c/ino_validation/ino_validation.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ const char* input2header(const char* input);
9292
void resetJSON(const char* input);
9393

9494
void listExampleDir(char* basePath, char* examplePath);
95+
/* Function to search for a keyword in a path and return the path up to that keyword */
96+
char* findKeywordPath(const char* path, const char* keyword);
9597

9698

9799
/* Declear global vairables */
@@ -105,6 +107,7 @@ const char* key_amb_header = "#include";
105107
const char* key_amb_customized = "CUSTOMIZED";
106108
const char* key_json = "build";
107109
const char* key_amb = "Arduino15";
110+
const char* key_portable = "portable";
108111
const char* key_ino = ".ino";
109112
const char* ext_json = ".json";
110113
const char* ext_cpp = ".cpp";
@@ -116,20 +119,23 @@ const char* filename_txt = "ino_validation.txt";
116119
/* Declear common file paths */
117120
#ifdef _WIN32
118121
char* path_arduino15_add = "\\AppData\\Local\\Arduino15\\";
122+
char* path_arduino15_add_portable = ""; // TODO: added for portable
119123
char* path_ambpro2_add = "\\packages\\realtek\\hardware\\AmebaPro2\\";
120124
char* path_model_add = "\\variants\\common_nn_models\\";
121125
char* path_library_add = "\\libraries\\";
122126
char* path_txtfile_add = "\\misc\\";
123127
char* backspace = "\\";
124128
#elif __linux__
125129
char* path_arduino15_add = "/.arduino15/";
130+
char* path_arduino15_add_portable = ""; // TODO: added for portable
126131
char* path_ambpro2_add = "/packages/realtek/hardware/AmebaPro2/";
127132
char* path_model_add = "/variants/common_nn_models/";
128133
char* path_library_add = "/libraries/";
129134
char* path_txtfile_add = "/misc/";
130135
char* backspace = "/";
131136
#else
132137
char* path_arduino15_add = "/Library/Arduino15/";
138+
char* path_arduino15_add_portable = ""; // TODO: added for portable
133139
char* path_ambpro2_add = "/packages/realtek/hardware/AmebaPro2/";
134140
char* path_model_add = "/variants/common_nn_models/";
135141
char* path_library_add = "/libraries/";
@@ -173,8 +179,12 @@ int main(int argc, char* argv[]) {
173179
strcpy(path_root, getenv("HOME"));
174180
strcpy(path_arduino15, getenv("HOME"));
175181
#endif
176-
177-
strcat(path_arduino15, path_arduino15_add);
182+
if (strstr(path_tools, "portable")) {
183+
strcpy(path_arduino15, findKeywordPath(path_tools, key_portable));
184+
}
185+
else {
186+
strcat(path_arduino15, path_arduino15_add);
187+
}
178188
strcpy(path_pro2, path_arduino15);
179189
strcat(path_pro2, path_ambpro2_add);
180190
strcpy(path_model, path_pro2);
@@ -216,6 +226,29 @@ int main(int argc, char* argv[]) {
216226
// -------------------------------
217227
// Functions
218228
// -------------------------------
229+
230+
// Function to search for a keyword in a path and return the path up to that keyword
231+
char* findKeywordPath(const char* path, const char* keyword) {
232+
static char result[1024]; // Static buffer for the result
233+
char* found;
234+
235+
// Search for the keyword in the path
236+
found = strstr(path, keyword);
237+
if (found != NULL) {
238+
// Calculate the length up to the end of the keyword
239+
int length = found - path + strlen(keyword);
240+
// Copy the relevant part of the path to the result
241+
strncpy(result, path, length);
242+
// Null-terminate the result string
243+
result[length] = '\0';
244+
return result;
245+
}
246+
else {
247+
// Return NULL if the keyword is not found
248+
return NULL;
249+
}
250+
}
251+
219252
int isDirExists(const char* path) {
220253
DIR* dir;
221254
struct dirent* entry;
@@ -365,6 +398,7 @@ const char* dirName(const char* directory_path) {
365398
DIR* directory = opendir(directory_path);
366399
const char* sdk_name = "";
367400
// check dir validation
401+
368402
if (directory) {
369403
while ((entry = readdir(directory)) != NULL) {
370404
#ifdef __APPLE__

Ameba_misc/Ameba_tools/nn_model_update/version_c/nn_model_update/nn_model_update.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ const char* pathTempJSON(const char* directory_path, const char* ext, const char
103103
cJSON* loadJSONFile(const char* directory_path);
104104
/* Function to update JSON */
105105
int writeJSON(const char* f_path);
106+
/* Function to search for a keyword in a path and return the path up to that keyword */
107+
char* findKeywordPath(const char* path, const char* keyword);
106108

107109

108110
/* Declear global vairables */
@@ -116,6 +118,7 @@ const char* key_amb_header = "#include";
116118
const char* key_amb_customized = "CUSTOMIZED";
117119
const char* key_json = "build";
118120
const char* key_amb = "Arduino15";
121+
const char* key_portable = "portable";
119122
const char* key_ino = ".ino";
120123
const char* ext_json = ".json";
121124
const char* key_amb_default = "DEFAULT";
@@ -127,20 +130,23 @@ const char* dir_example = "NA";
127130
/* Declear common file paths */
128131
#ifdef _WIN32
129132
char* path_arduino15_add = "\\AppData\\Local\\Arduino15";
133+
char* path_arduino15_add_portable = ""; // TODO: added for portable
130134
char* path_ambpro2_add = "\\packages\\realtek\\hardware\\AmebaPro2\\";
131135
char* path_model_add = "\\variants\\common_nn_models";
132136
char* path_library_add = "\\libraries\\";
133137
char* path_txtfile_add = "\\misc\\";
134138
char* backspace = "\\";
135139
#elif __linux__
136140
char* path_arduino15_add = "/.arduino15";
141+
char* path_arduino15_add_portable = ""; // TODO: added for portable
137142
char* path_ambpro2_add = "/packages/realtek/hardware/AmebaPro2/";
138143
char* path_model_add = "/variants/common_nn_models";
139144
char* path_library_add = "/libraries/";
140145
char* path_txtfile_add = "/misc/";
141146
char* backspace = "/";
142147
#else
143148
char* path_arduino15_add = "/Library/Arduino15";
149+
char* path_arduino15_add_portable = ""; // TODO: added for portable
144150
char* path_ambpro2_add = "/packages/realtek/hardware/AmebaPro2/";
145151
char* path_model_add = "/variants/common_nn_models";
146152
char* path_library_add = "/libraries/";
@@ -184,7 +190,13 @@ int main(int argc, char* argv[]) {
184190
strcpy(path_root, getenv("HOME"));
185191
strcpy(path_arduino15, getenv("HOME"));
186192
#endif
187-
strcat(path_arduino15, path_arduino15_add);
193+
// Handle portable root
194+
if (strstr(path_tools, "portable")) {
195+
strcpy(path_arduino15, findKeywordPath(path_tools, key_portable));
196+
}
197+
else {
198+
strcat(path_arduino15, path_arduino15_add);
199+
}
188200
strcpy(path_pro2, path_arduino15);
189201
strcat(path_pro2, path_ambpro2_add);
190202
strcpy(path_model, path_pro2);
@@ -227,6 +239,27 @@ int main(int argc, char* argv[]) {
227239
//extern int mkdir(char* filename);
228240
#endif
229241

242+
char* findKeywordPath(const char* path, const char* keyword) {
243+
static char result[1024]; // Static buffer for the result
244+
char* found;
245+
246+
// Search for the keyword in the path
247+
found = strstr(path, keyword);
248+
if (found != NULL) {
249+
// Calculate the length up to the end of the keyword
250+
int length = found - path + strlen(keyword);
251+
// Copy the relevant part of the path to the result
252+
strncpy(result, path, length);
253+
// Null-terminate the result string
254+
result[length] = '\0';
255+
return result;
256+
}
257+
else {
258+
// Return NULL if the keyword is not found
259+
return NULL;
260+
}
261+
}
262+
230263
void copyFile(const char* sourcePath, const char* destinationPath) {
231264
FILE* sourceFile;
232265
FILE* destinationFile;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)