Skip to content

Commit

Permalink
make aivs monitor stable & add service in rootfs
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui committed Jan 27, 2024
1 parent e391aae commit d86744e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/apps/aivs-monitor/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CURL *curl;
struct curl_slist *headers = NULL;
int current_round = 0;
int thread_processed_rount = 0;
const char *instruction_json_path = "/tmp/mico_aivs_lab/instruction.log";

void speaker_pause() {
// ubus call mediaplayer player_play_operation {\"action\":\"pause\"}
Expand Down Expand Up @@ -108,8 +109,15 @@ void mute_speaker_thread(void *arg) {
printf("mute speaker thread exit\n");
}

void wait_for_message_file_ready() {
// wait for message file ready
while (access(instruction_json_path, F_OK) != 0) {
usleep(1000 * 1000);
}
}

int main() {
const char *instruction_json_path = "/tmp/mico_aivs_lab/instruction.log";
wait_for_message_file_ready();

FILE *json_file = fopen(instruction_json_path, "r");
fseek(json_file, 0, SEEK_END);
Expand Down Expand Up @@ -179,4 +187,4 @@ int main() {
curl_easy_cleanup(curl);

return 0;
}
}
1 change: 1 addition & 0 deletions src/pack/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.bin
rootfs.img
tmp
root
4 changes: 4 additions & 0 deletions src/pack/pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ for patch in $PATCHES; do
patch -p1 < $patch
done

if [ -d $BASE_DIR/root ]; then
rsync -av $BASE_DIR/root/ .
fi

popd

mksquashfs squashfs-root rootfs.img -comp xz -b 256K -noappend && mv rootfs.img $BASE_DIR/rootfs.img
Expand Down
33 changes: 33 additions & 0 deletions src/pack/patches/002.aivs-monitor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/etc/init.d/aivs_monitor b/etc/init.d/aivs_monitor
new file mode 100755
index 0000000..b4a6bf4
--- /dev/null
+++ b/etc/init.d/aivs_monitor
@@ -0,0 +1,19 @@
+#!/bin/sh /etc/rc.common
+
+START=85
+USE_PROCD=1
+DEBUG=0
+
+start_service() {
+ procd_open_instance
+ procd_set_param command /usr/bin/aivs-monitor
+ procd_set_param stdout 0
+ procd_set_param stderr 0
+ procd_set_param respawn 3600 5 0
+ procd_close_instance
+}
+
+stop_service() {
+ procd_kill "aivs-monitor"
+ kill -9 `ps|grep "/usr/bin/aivs-monitor"|grep -v grep|awk '{print $1}'`
+}
diff --git a/etc/rc.d/S99aivs-monitor b/etc/rc.d/S99aivs-monitor
new file mode 120000
index 0000000..3a68593
--- /dev/null
+++ b/etc/rc.d/S99aivs-monitor
@@ -0,0 +1 @@
+../init.d/aivs_monitor
\ No newline at end of file

0 comments on commit d86744e

Please sign in to comment.