Просмотр исходного кода

Implemented script repetition according to repeat parameter

tcpassos 2 лет назад
Родитель
Сommit
bdb039de6a

+ 2 - 0
applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -74,6 +74,8 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
     
     
     // Run the script if the file with the script has been opened
     // Run the script if the file with the script has been opened
     if(app->script != NULL) {
     if(app->script != NULL) {
+        furi_string_reset(app->text_box_store);
+        app->text_box_store_strlen = 0;
         app->script_worker = wifi_marauder_script_worker_alloc();
         app->script_worker = wifi_marauder_script_worker_alloc();
         wifi_marauder_script_worker_start(app->script_worker, app->script, wifi_marauder_script_execute_stage, app->script_worker);
         wifi_marauder_script_worker_start(app->script_worker, app->script, wifi_marauder_script_execute_stage, app->script_worker);
     }
     }

+ 8 - 8
applications/external/wifi_marauder_companion/script/wifi_marauder_script.c

@@ -9,7 +9,7 @@ WifiMarauderScript *wifi_marauder_script_alloc() {
     if (script == NULL) {
     if (script == NULL) {
         return NULL;
         return NULL;
     }
     }
-    script->name = NULL;
+    script->description = NULL;
     script->first_stage = NULL;
     script->first_stage = NULL;
     script->repeat = 1;
     script->repeat = 1;
     return script;
     return script;
@@ -17,10 +17,10 @@ WifiMarauderScript *wifi_marauder_script_alloc() {
 
 
 void _wifi_marauder_script_load_meta(WifiMarauderScript *script, cJSON *meta_section) {
 void _wifi_marauder_script_load_meta(WifiMarauderScript *script, cJSON *meta_section) {
     if (meta_section != NULL) {
     if (meta_section != NULL) {
-        // Script name
-        cJSON* name = cJSON_GetObjectItem(meta_section, "name");
-        if (name != NULL) {
-            script->name = strdup(name->valuestring);
+        // Script description
+        cJSON* description = cJSON_GetObjectItem(meta_section, "description");
+        if (description != NULL) {
+            script->description = strdup(description->valuestring);
         }
         }
         // Times the script will be repeated
         // Times the script will be repeated
         cJSON* repeat = cJSON_GetObjectItem(meta_section, "repeat");
         cJSON* repeat = cJSON_GetObjectItem(meta_section, "repeat");
@@ -28,8 +28,8 @@ void _wifi_marauder_script_load_meta(WifiMarauderScript *script, cJSON *meta_sec
             script->repeat = repeat->valueint;
             script->repeat = repeat->valueint;
         }
         }
     }
     }
-    if (script->name == NULL) {
-        script->name = "New script";
+    if (script->description == NULL) {
+        script->description = "My script";
     }
     }
 }
 }
 
 
@@ -253,6 +253,6 @@ void wifi_marauder_script_free(WifiMarauderScript *script) {
         free(current_stage);
         free(current_stage);
         current_stage = next_stage;
         current_stage = next_stage;
     }
     }
-    free(script->name);
+    free(script->description);
     free(script);
     free(script);
 }
 }

+ 1 - 1
applications/external/wifi_marauder_companion/script/wifi_marauder_script.h

@@ -78,7 +78,7 @@ typedef struct WifiMarauderScriptStageBeaconList {
 
 
 // Script
 // Script
 typedef struct WifiMarauderScript {
 typedef struct WifiMarauderScript {
-    char* name;
+    char* description;
     WifiMarauderScriptStage *first_stage;
     WifiMarauderScriptStage *first_stage;
     int repeat;
     int repeat;
 } WifiMarauderScript;
 } WifiMarauderScript;

+ 8 - 1
applications/external/wifi_marauder_companion/script/wifi_marauder_script_worker.c

@@ -15,12 +15,19 @@ WifiMarauderScriptWorker* wifi_marauder_script_worker_alloc() {
 int32_t _wifi_marauder_script_worker_task(void* worker) {
 int32_t _wifi_marauder_script_worker_task(void* worker) {
     WifiMarauderScriptWorker* script_worker = worker;
     WifiMarauderScriptWorker* script_worker = worker;
     WifiMarauderScript *script = script_worker->script;
     WifiMarauderScript *script = script_worker->script;
-    if (script != NULL) {
+    if (script == NULL) {
+        return 0;    
+    }
+
+    for (int i = 0; i < script->repeat; i++) {
         WifiMarauderScriptStage *current_stage = script->first_stage;
         WifiMarauderScriptStage *current_stage = script->first_stage;
         while (current_stage != NULL && script_worker->is_running) {
         while (current_stage != NULL && script_worker->is_running) {
             script_worker->callback(current_stage, script_worker->context);
             script_worker->callback(current_stage, script_worker->context);
             current_stage = current_stage->next_stage;
             current_stage = current_stage->next_stage;
         }
         }
+        if (!script_worker->is_running) {
+            break;
+        }
     }
     }
     return 0;
     return 0;
 }
 }