aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan <yanxk.fnst@fujitsu.com>2024-02-19 18:52:17 +0800
committerYan <yanxk.fnst@fujitsu.com>2024-02-19 18:52:17 +0800
commit9de8a16162dcae3da11700df3e9ef18571c08969 (patch)
tree252decaf23aff97c3be516d55e56c022d5ab71da
parentf92a01ae9502b09bd84c4c8b9bde585df533814a (diff)
cgi: dynamic web display
provide cgi files and makefile help generate the web pages dynamically. Change-Id: I804aa5a62bd9f6741a938e282a4a623b7e80b5af Signed-off-by: Yan <yanxk.fnst@fujitsu.com>
-rw-r--r--ui/cgi/Makefile25
-rw-r--r--ui/cgi/iframe_env.c37
-rw-r--r--ui/cgi/trigger_alarm.c45
-rw-r--r--ui/cgi/trigger_fan.c45
4 files changed, 152 insertions, 0 deletions
diff --git a/ui/cgi/Makefile b/ui/cgi/Makefile
new file mode 100644
index 0000000..17cbc77
--- /dev/null
+++ b/ui/cgi/Makefile
@@ -0,0 +1,25 @@
+CFLAGS= -Wall -I../../include -DDEBUG_LOG -g
+CFLAGS+= -I/home/ubuntu/yanxk/cross_compile_source/cgic
+
+LDFLAGS= -lcgic
+LDFLAGS+= -L/home/ubuntu/yanxk/cross_compile_source/cgic
+
+TARGET= iframe_env.cgi \
+ trigger_alarm.cgi \
+ trigger_fan.cgi
+
+.PHONY: all
+
+all: $(TARGET)
+
+iframe_env.cgi: iframe_env.c
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+ mv ./iframe_env.cgi ../../build
+
+trigger_fan.cgi: trigger_fan.c
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+ mv ./trigger_fan.cgi ../../build
+
+trigger_alarm.cgi: trigger_alarm.c
+ $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+ mv ./trigger_alarm.cgi ../../build
diff --git a/ui/cgi/iframe_env.c b/ui/cgi/iframe_env.c
new file mode 100644
index 0000000..61d0b22
--- /dev/null
+++ b/ui/cgi/iframe_env.c
@@ -0,0 +1,37 @@
+/*
+ * File Name: iframe_env.c
+ * Workflow: fullfill HTML iframe
+ * Return Value: 0 always
+ */
+
+/* Header files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+
+#include "cgic.h"
+#include "proto.h"
+
+/* cgiMain, main in cgic.h */
+int cgiMain() {
+ key_t shm_key;
+ int shm_id;
+ SHM_STRUCT *p_shm_struct;
+
+ shm_key = ftok("/usr/bin/boa", 'm');
+ shm_id = shmget(shm_key, sizeof(SHM_STRUCT), 0600);
+
+ p_shm_struct = shmat(shm_id, NULL, 0);
+
+ cgiHeaderContentType("text/html");
+ fprintf(cgiOut, "<HTML>\n");
+ fprintf(cgiOut, "<head><meta http-equiv=\"refresh\" content=\"5\"></head>\n");
+ fprintf(cgiOut, "<BODY bgcolor=\"green\">\n");
+ fprintf(cgiOut, "<h1>Temperature:\t%d</h1>\n", p_shm_struct->tempNow);
+ fprintf(cgiOut, "<h1>Humidity:\t%d</h1>\n", p_shm_struct->humiNow);
+ fprintf(cgiOut, "</BODY></HTML>\n");
+
+ return 0;
+} \ No newline at end of file
diff --git a/ui/cgi/trigger_alarm.c b/ui/cgi/trigger_alarm.c
new file mode 100644
index 0000000..8f19de5
--- /dev/null
+++ b/ui/cgi/trigger_alarm.c
@@ -0,0 +1,45 @@
+/*
+ * File Name: trigger_alarm.c
+ * Workflow: on click send msg to MQ
+ * Return Value: 0 always
+ */
+
+/* Header files */
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+
+#include "cgic.h"
+#include "proto.h"
+
+/* cgiMain, main in cgic.h */
+int cgiMain() {
+ char alarm_switch_bit = '0';
+ MQ_STRUCT *p_mq_struct = malloc(sizeof(MQ_STRUCT));
+ key_t msg_key;
+ int msg_id;
+
+ cgiFormString("alarm_switch", &alarm_switch_bit, 1);
+ memset(p_mq_struct, '\0', sizeof(MQ_STRUCT));
+
+ p_mq_struct->mtype = 21L;
+ switch (alarm_switch_bit) {
+ case '0':
+ p_mq_struct->tswitch = 0;
+ break;
+ case '1':
+ p_mq_struct->tswitch = 1;
+ break;
+ }
+
+ msg_key = ftok("/usr/bin/boa", 'q');
+ msg_id = msgget(msg_key, 0600);
+
+ msgsnd(msg_id, p_mq_struct, sizeof(MQ_STRUCT) - sizeof(long), 0);
+
+ free(p_mq_struct);
+
+ return 0;
+}
diff --git a/ui/cgi/trigger_fan.c b/ui/cgi/trigger_fan.c
new file mode 100644
index 0000000..8a939d5
--- /dev/null
+++ b/ui/cgi/trigger_fan.c
@@ -0,0 +1,45 @@
+/*
+ * File Name: trigger_fan.c
+ * Workflow: on click send msg to MQ
+ * Return Value: 0 always
+ */
+
+/* Header files */
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+
+#include "cgic.h"
+#include "proto.h"
+
+/* cgiMain, main in cgic.h */
+int cgiMain() {
+ char fan_switch_bit = '0';
+ MQ_STRUCT *p_mq_struct = malloc(sizeof(MQ_STRUCT));
+ key_t msg_key;
+ int msg_id;
+
+ cgiFormString("fan_switch", &fan_switch_bit, 1);
+ memset(p_mq_struct, '\0', sizeof(MQ_STRUCT));
+
+ p_mq_struct->mtype = 20L;
+ switch (fan_switch_bit) {
+ case '0':
+ p_mq_struct->tswitch = 0;
+ break;
+ case '1':
+ p_mq_struct->tswitch = 1;
+ break;
+ }
+
+ msg_key = ftok("/usr/bin/boa", 'q');
+ msg_id = msgget(msg_key, 0600);
+
+ msgsnd(msg_id, p_mq_struct, sizeof(MQ_STRUCT) - sizeof(long), 0);
+
+ free(p_mq_struct);
+
+ return 0;
+}