Toby Chui 3 tahun lalu
induk
melakukan
f94499b248
16 mengubah file dengan 445 tambahan dan 0 penghapusan
  1. 5 0
      go.mod
  2. 2 0
      go.sum
  3. TEMPAT SAMPAH
      lab6.exe
  4. 142 0
      main.go
  5. TEMPAT SAMPAH
      res/light_off.png
  6. TEMPAT SAMPAH
      res/light_off.psd
  7. TEMPAT SAMPAH
      res/light_on.png
  8. TEMPAT SAMPAH
      res/light_on.psd
  9. TEMPAT SAMPAH
      res/switch.png
  10. TEMPAT SAMPAH
      res/switch.psd
  11. 26 0
      ssOutput.txt
  12. 106 0
      startOutput.txt
  13. 164 0
      web/index.html
  14. TEMPAT SAMPAH
      web/light_off.png
  15. TEMPAT SAMPAH
      web/light_on.png
  16. TEMPAT SAMPAH
      web/switch.png

+ 5 - 0
go.mod

@@ -0,0 +1,5 @@
+module lab6
+
+go 1.15
+
+require github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e

+ 2 - 0
go.sum

@@ -0,0 +1,2 @@
+github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e h1:z780M7mCrdt6KiICeW9SGirvQjxDlrVU+n99FO93nbI=
+github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=

TEMPAT SAMPAH
lab6.exe


+ 142 - 0
main.go

@@ -0,0 +1,142 @@
+package main
+
+import (
+	"bufio"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"io/ioutil"
+	"math/rand"
+	"net/http"
+	"os"
+	"strconv"
+	"strings"
+	"time"
+)
+
+var lamp0IsOn bool = false
+var lamp1IsOn bool = false
+
+var emulatedServiceStated []int = []int{0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 1, 0, 1}
+
+type GlobalStatus struct {
+	Lamp0 bool
+	Lamp1 bool
+}
+
+func main() {
+	//Create a local webserver
+	go func() {
+		fs := http.FileServer(http.Dir("./web"))
+		http.Handle("/", fs)
+		http.HandleFunc("/~/mn-cse/mn-name/sm_sensor_1", oprHandler)
+		http.HandleFunc("/getStatus", statusHandler)
+
+		http.ListenAndServe(":8282", nil)
+	}()
+
+	input := ""
+	for input != "exit" {
+		input = StringPrompt("osgi> ")
+		EmulateInput(input)
+	}
+
+}
+
+func EmulateInput(input string) {
+	if input == "ss" {
+		fakeSSOutput, _ := ioutil.ReadFile("ssOutput.txt")
+		output := string(fakeSSOutput)
+		lines := strings.Split(output, "\n")
+		for i := 31; i < 57; i++ {
+			status := "RESOLVED"
+			if emulatedServiceStated[i-31] == 0 {
+
+			} else if emulatedServiceStated[i-31] == 1 {
+				status = "ACTIVE  "
+			} else if emulatedServiceStated[i-31] == 2 {
+				status = "STARTING"
+			}
+			fmt.Println(strconv.Itoa(i) + "          " + status + "     " + lines[i-31])
+		}
+	} else if input == "start 41" {
+		fakeStartOutput, _ := ioutil.ReadFile("startOutput.txt")
+		output := string(fakeStartOutput)
+		lines := strings.Split(output, "\n")
+		for i := 0; i < len(lines); i++ {
+			if strings.TrimSpace(lines[i]) == "" {
+				//Give it a break to emulate loading
+				delayTime := rand.Intn(500-200) + 200
+				time.Sleep(time.Duration(delayTime) * time.Millisecond)
+				fmt.Println("")
+			} else {
+				fmt.Println(lines[i])
+			}
+		}
+
+		//Start the UI thread (Blocking)
+		/*
+			debug := true
+			w := webview.New(debug)
+			defer w.Destroy()
+			w.SetTitle("Sample Simulated IPE")
+			w.SetSize(497, 570, webview.HintFixed)
+			w.Navigate("http://127.0.0.1:8282")
+			w.Run()
+		*/
+		select {}
+	}
+}
+
+func StringPrompt(label string) string {
+	var s string
+	r := bufio.NewReader(os.Stdin)
+	for {
+		fmt.Fprint(os.Stderr, label+" ")
+		s, _ = r.ReadString('\n')
+		if s != "" {
+			break
+		}
+	}
+	return strings.TrimSpace(s)
+}
+
+func statusHandler(w http.ResponseWriter, r *http.Request) {
+	currentStatus := GlobalStatus{
+		lamp0IsOn,
+		lamp1IsOn,
+	}
+
+	js, _ := json.Marshal(currentStatus)
+	w.Write(js)
+}
+
+func oprHandler(w http.ResponseWriter, r *http.Request) {
+
+}
+
+func mv(r *http.Request, getParamter string, postMode bool) (string, error) {
+	if postMode == false {
+		//Access the paramter via GET
+		keys, ok := r.URL.Query()[getParamter]
+
+		if !ok || len(keys[0]) < 1 {
+			//log.Println("Url Param " + getParamter +" is missing")
+			return "", errors.New("GET paramter " + getParamter + " not found or it is empty")
+		}
+
+		// Query()["key"] will return an array of items,
+		// we only want the single item.
+		key := keys[0]
+		return string(key), nil
+	} else {
+		//Access the parameter via POST
+		r.ParseForm()
+		x := r.Form.Get(getParamter)
+		if len(x) == 0 || x == "" {
+			return "", errors.New("POST paramter " + getParamter + " not found or it is empty")
+		}
+		return string(x), nil
+	}
+
+}

TEMPAT SAMPAH
res/light_off.png


TEMPAT SAMPAH
res/light_off.psd


TEMPAT SAMPAH
res/light_on.png


TEMPAT SAMPAH
res/light_on.psd


TEMPAT SAMPAH
res/switch.png


TEMPAT SAMPAH
res/switch.psd


+ 26 - 0
ssOutput.txt

@@ -0,0 +1,26 @@
+org.eclipse.om2m.core.servIce_1.1.0.20211227-1156
+org.eclipse.om2m.dal_1.1.0.20211227-1156
+org.eclipse.om2m.dal.drtver.samptc_1.1.0.20211227-1156
+org.eclipse.om2m.datamapping.jax6_1.1.0.20211227-1156
+org.eclipse.om2m.datanapping.service_1.1.0.20211227-1156
+org.eclipse.om2m.flexcontainer.service_1.2.0.20211227-1156
+org.eclipse.om2m.hue.apt_1.1.0.20211227-1156
+org.eclipse.om2m.hueAmpl_1.1.0.20211227-8821
+org.eclipse.om2m.interworking.service_1.1.0.20211227-1156
+org.eclipse.om2m.ipe.dal_1.1.0.20211227-1156
+org.eclipse.om2m.ipe.sample_1.1.0.20211227-1156
+org.eclipse.om2m.ipe.sample.sdt_1.1.0.20281203-1156
+org.eclipse.om2m.ipe.sdt_1.1.0.28201203-1156
+org.eclipse.om2m.perststence.ecltpseltnk_1.1.0.20211227-1156
+org.eclipse.om2m.perststence.morgodb_1.1.0.20211227-1156
+org.eclipse.om2m.perststence.servtce_1.1.8.20211227-1156
+org.eclipse.om2m.sample.test_ipe2_1.0.0.20211227-1156
+org.eclipse.om2m.sdt.4011.1.0.20211227-1156
+org.eclipse.om2m.sdt.home_1.1.0.20202203-1156
+org.eclipse.om2m.sdt.home.drtver_1.1.0.20211227-1156
+org.eclipse.om2m.sdt.home.hue_1.1.0.20211227-1156
+org.eclipse.om2m.sdt.home.nocked.devices_1.1.0.20211227-1156
+org.eclipse.om2m.testsutte.flexcontainer_1.1.48.20261203-1156
+org.eclipse.om2m.webapp.resourcesbrowser.json_1.1.0.20211227-1156
+org.eclipse.osgt.servtces_3.4.0.v20140312-2051
+org.ops4j.pax.conftgmanager_0.2.3

+ 106 - 0
startOutput.txt

@@ -0,0 +1,106 @@
+INFO] - org.eclipse.omM.binding.http.RestHttpClient 
+Headers:
+Accept: application/Ant
+X-MM-Origin: adsin:admin
+Content-Type: application/xml
+
+[INFO] • org.eclipse.om2m.binding.http.RestSttpClient Http Client response: ResponsePrtntttve [ 
+Http Client response: ResponsePrtntttve [ 
+responseStatusCode.5600
+to=adnin:admin
+from./sn-cse
+contentTypeAtext/platn;charset=t0E-8,
+content (Only first 1006 caracters).
+IPE Internal Error
+
+
+[INFO] - org.eclipse.omM.core.comn.Resttlient 
+ResponsePrinittve [
+responseStatustode.S000
+toadmin:adnin
+from./nn-cse
+contenttype=text/plain;charset.ufF-8,
+content (Only first ieee caracters).
+IPE Internal Error
+
+ResourceController to be used (ContentInstanteController) 
+[INFO) - org.eclipse.oran.core.controller.controller. 
+Clear and close transaction
+[INFO] org.eclipse.on2n.core.roucer.Router
+Response in Router= ResponsePrtntttve [ 
+responsestatusCode•2001
+to=adnin:adnin
+from=inn-cse
+location./nn-cse/cln-917759604,
+content (Only first 1000 caracters)=. 
+org.ectlpse.oran.connons.resource.ContentInstanceg4e4af60b
+
+[INFO] - org.ecltpse.on2n.core.router.Router
+Received request to Router: RequestPrtnittve (operation-1, 
+tos/nn-cse,
+froluadmtniadntn,
+resourceType=2, 
+content.org.ectlpse.on2m.connons.resource.AWbilf0d64, 
+recurnContentType=appltcation/obj, 
+requestContentType=appltcatton/obj,
+
+,tokens=null]
+[INFO] • org.eclipse.on2n.core.router.Router 
+Request handling in the current CSE: /mn-cse 
+[INFO] • org.ecltpse.on2n.core. outer.Router 
+ResourceController to be used (Controller)
+
+R•M2N-Origin: adntn:admin 
+content-Type: application/xml
+
+[INFO] - org.eclipse.on2m.core.router.Router
+Response to Router= ResponsePrinitive [
+responseStatusCode=2001
+to=adntn:adntn
+fromgrin-cse
+locationspin-cse/cnt-2S9557313,
+content (Only first 1000 caracters)= 
+org.eclipse.on2n.connons.resource.ContainerflUe3005
+
+[INFO] - org.eclipse.on2m.core.router.Ronter
+Received request in Router: RequestPrtmtttve [operational, 
+toqnn-cse/nn-name/tANP_Att/DESCRIPTOR,
+fron=adminradnin,
+resourceType=4, 
+contentvorg.eclipse.on2n.comnons.resource.ContentInstanceeiSf0057, 
+returnContentType=application/ob],
+requestContentType=application/obl,
+
+.tokens=null]
+[INFO] • org.eclipse.om2m.core.router.Router.
+Request handling in the current CSC: /nn-cse/nn-nane/tAMP_Att/DESCRIPTOR 
+[INFO] - org.eclipse.om2n.core. outer.Rovter
+ResourceController to be used [ tentInstanceController]
+INFO - or..eclbse.om2m.bindins.htt•.Restlitt• tient
+
+IPE Internal Error
+
+
+[INFO] - org.eclipse.om2m.core.comm.RestClient 
+esponsePrimitiye[
+responseStatusCode.S000
+to=adntn:adntn
+from=/mn-cse
+contentType=text/plain;charset=UTF-8,
+content (Only first 1000 caracters)=
+IPE internal Error
+]
+
+[WARN] - org.eclipse.om2m.core.notifier.Notifier
+noble to notify, increase fatted nottfs(2) for subscription /nn-cse/sub-879362361 
+[INFO] - org.eclipse.om2m.core.controller.Controller
+[INFO] - org.eclipse.om2m.core.controller.Controller
+tear and close transaction
+[INFO] - org.eclipse.om2m.core.router.Router
+desponse in Router= ResponsePrimitive [
+responseStatusCode=2001
+to=iadmin:admin
+from/mn-cse
+location=/mn-cse/ctn-947304420,
+content (Only first 1000 caracters)= 
+org.eclipse.om2m.commons.resource.ContentInstance@49d0c674

+ 164 - 0
web/index.html

@@ -0,0 +1,164 @@
+<html>
+    <head>
+        <!-- Tocas UI:CSS 與元件 -->
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.css">
+        <!-- Tocas JS:模塊與 JavaScript 函式 -->
+        <script src="https://cdnjs.cloudflare.com/ajax/libs/tocas-ui/2.3.3/tocas.js"></script>
+        <script
+			  src="https://code.jquery.com/jquery-3.6.0.min.js"
+			  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
+			  crossorigin="anonymous"></script>
+        <style>
+            body{
+                background-color: #ededed;
+            }
+            .leftContainer{
+                border: 1px solid black;
+                padding: 5px;
+                margin: 12px;
+                height: 250px;
+            }
+            
+            .javainput{
+                -webkit-box-shadow: inset 5px 5px 4px -5px rgba(105,105,105,0.71); 
+                box-shadow: inset 5px 5px 4px -5px rgba(105,105,105,0.71);
+                font-size: 26px;
+                padding-top: 4px;
+                padding-left: 5px;
+                
+                margin-top: 16px;
+                font-weight: bold;
+                
+            }
+
+            .double.javainput{
+                width: 40px;
+                margin-left: 18px;
+            }
+
+            .single.javainput{
+                width: 30px;
+                margin-left: 28px;
+            }
+
+            .javabutton{
+                background: rgb(229,234,243);
+                background: linear-gradient(180deg, rgba(229,234,243,1) 0%, rgba(243,249,252,1) 27%, rgba(196,214,231,1) 100%);
+                padding: 1px;
+                width: 100px;
+                margin-top: 6px;
+                -webkit-box-shadow: inset 5px 5px 4px -5px rgba(105,105,105,0.71); 
+                box-shadow: inset 5px 5px 4px -5px rgba(105,105,105,0.71);
+                border: 1px solid rgb(175, 175, 175);
+                font-size: 90%;
+                font-weight: bold;
+                text-align: center;
+            }
+
+            .switchFrame{
+                background: rgb(229,234,243);
+                background: linear-gradient(180deg, rgba(229,234,243,1) 0%, rgba(243,249,252,1) 27%, rgba(196,214,231,1) 100%);
+                width: calc(100% - 20px);
+                height: 220px;
+                margin-top: 200px;
+                border: 1px solid rgb(158, 158, 158);
+                padding: 12px;
+                padding-top: 25px;
+            }
+
+            .onofftext{
+                padding-top: 30px;
+                margin-left: -12px;
+                font-style: italic;
+                font-weight: bold;
+            }
+
+            .bulbSwitch{
+                background: rgb(229,234,243);
+                background: linear-gradient(180deg, rgba(229,234,243,1) 0%, rgba(243,249,252,1) 27%, rgba(196,214,231,1) 100%);
+                width: calc(100% - 22px);
+                margin-top: 30px;
+                height: 170px;
+                border: 1px solid rgb(158, 158, 158);
+                padding-top: 1px;
+            }
+            .bulbSwitchOffsetText {
+                padding-top: 24px;
+                margin-left: 12px;
+                font-style: italic;
+                font-weight: bold;
+                font-size: 1.1em;
+                transform: scale(1.2, 1);
+            }
+
+            .bulb{
+                max-height: 240px;
+                padding-top: 8px;
+                padding-right: 12px;
+            }
+
+            .switch{
+                margin-left: 5px;
+                margin-top: 5px;
+            }
+        </style>
+    </head>
+    <body>
+        <div class="ts grid">
+            <div class="ten wide column">
+                <div class="leftContainer">
+                    <div class="ts grid">
+                        <div class="eight wide column">
+                            <img id="bulb0" class="ts image bulb" src="light_off.png">
+                        </div>
+                        <div class="eight wide column">
+                            <div class="bulbSwitch">
+                                <img id="bulb0switch" class="ts image bulb switch" src="switch.png">
+                                <p class="bulbSwitchOffsetText">Switch LAMP...</p>
+                            </div>
+                           
+                        </div>
+                    </div>
+                </div>
+                <div class="leftContainer">
+                    <div class="ts grid">
+                        <div class="eight wide column">
+                            <img id="bulb1" class="ts image bulb" src="light_off.png">
+                        </div>
+                        <div class="eight wide column">
+                            <div class="bulbSwitch">
+                                <img id="bulb1switch" class="ts image bulb switch" src="switch.png">
+                                <p class="bulbSwitchOffsetText">Switch LAMP...</p>
+                            </div>
+                           
+                        </div>
+                    </div>    
+                </div>
+            </div>
+            <div class="six wide column">
+                <div class="switchFrame" align="center">
+                    <img id="power" class="ts image" src="switch.png">
+                    <p class="onofftext">Switch All</p>
+                </div>
+            </div>
+        </div>
+        <script>
+            setInterval(function(){
+                $.get("./getStatus", function(data){
+                    data = JSON.parse(data);
+                    if (data.Lamp0 == true){
+                        $("#bulb0").attr("src", "light_on.png");
+                    }else{
+                        $("#bulb0").attr("src", "light_off.png");
+                    }
+
+                    if (data.Lamp1 == true){
+                        $("#bulb1").attr("src", "light_on.png");
+                    }else{
+                        $("#bulb1").attr("src", "light_off.png");
+                    }
+                });
+            }, 300);
+        </script>
+    </body>
+</html>

TEMPAT SAMPAH
web/light_off.png


TEMPAT SAMPAH
web/light_on.png


TEMPAT SAMPAH
web/switch.png