diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..0065213 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,28 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/tools/add-action/main.go b/tools/add-action/main.go deleted file mode 100644 index f6c3216..0000000 --- a/tools/add-action/main.go +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2019 Rightech IoT. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - paho "github.com/eclipse/paho.mqtt.golang" - jsoniter "github.com/json-iterator/go" - log "github.com/sirupsen/logrus" - "github.com/spf13/viper" - - "github.com/Rightech/ric-edge/internal/app/core/config" -) - -const code = `const xml = require('fast-xml-parser'); -const math = require('mathjs'); - -function handle(packet) { - const time = packet.time || Date.now(); - const iso = new Date(+time).toISOString(); - const rand = Math.random(); - const x = xml.parse('10'); - console.log(new Date().toISOString(), packet); - return { iso, rand, x }; -} - -module.exports = handle; -` - -const pkg = `{ - "name":"ric-v3-5d681eb0b6a1c026ca418faf", - "private":true, - "dependencies":{ - "fast-xml-parser":"latest", - "mathjs":"6.1.0" - } -} -` - -func getPayload() []byte { - data := map[string]interface{}{ - "jsonrpc": "2.0", - "method": "add-action", - "params": map[string]string{ - "name": "ric-v3-5d681eb0b6a1c026ca418faf", - "package": pkg, - "code": code, - }, - } - - payload, err := jsoniter.ConfigFastest.Marshal(&data) - if err != nil { - panic(err) - } - - return payload -} - -func main() { - config.Setup() - - opts := paho.NewClientOptions(). - AddBroker(viper.GetString("core.mqtt.url")) - - client := paho.NewClient(opts) - defer client.Disconnect(500) - - token := client.Connect() - if token.Wait() && token.Error() != nil { - log.Error(token.Error()) - return - } - - token = client.Publish("ric-edge/action/command", 2, false, getPayload()) - if token.Wait() && token.Error() != nil { - log.Error(token.Error()) - return - } -} diff --git a/tools/ble-srv/README.md b/tools/ble-srv/README.md deleted file mode 100644 index 9df9b88..0000000 --- a/tools/ble-srv/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Info - -From [example](https://github.com/go-ble/ble/blob/147700f13610085f7387692cd6663a67c495ab87/examples/basic/server/main.go) of ble lib. - -To run execute (from project root dir): - -```bash -$ make tool_ble_srv -``` diff --git a/tools/ble-srv/count_char.go b/tools/ble-srv/count_char.go deleted file mode 100644 index db2b1c6..0000000 --- a/tools/ble-srv/count_char.go +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright 2019 Rightech IoT. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "encoding/binary" - "math" - "time" - - log "github.com/sirupsen/logrus" - - "github.com/Rightech/ric-edge/third_party/go-ble/ble" -) - -func nfHandler(typ string) ble.NotifyHandler { - return ble.NotifyHandlerFunc(func(req ble.Request, n ble.Notifier) { - cnt := uint32(0) - ticker := time.NewTicker(time.Second) - defer ticker.Stop() - - log.Printf("count: %s subscribed\n", typ) - for { - select { - case <-n.Context().Done(): - log.Printf("count: %s unsubscribed\n", typ) - return - case <-ticker.C: - log.Printf("count: %s: %d", typ, cnt) - - bs := make([]byte, 4) - binary.LittleEndian.PutUint32(bs, cnt) - - if _, err := n.Write(bs); err != nil { - // Client disconnected prematurely before unsubscription. - log.WithError(err).Errorf("count: Failed to %s", typ) - return - } - cnt++ - } - } - }) -} - -// newCountChar ... -func newCountChar() *ble.Characteristic { - var n float64 - - c := ble.NewCharacteristic(ble.MustParse("00010000-0002-1000-8000-00805F9B34FB")) - c.HandleRead(ble.ReadHandlerFunc(func(req ble.Request, rsp ble.ResponseWriter) { - log.Printf("count: Read %f", n) - - bs := make([]byte, 8) - binary.LittleEndian.PutUint64(bs, math.Float64bits(n)) - - _, err := rsp.Write(bs) - if err != nil { - log.WithError(err).Error("read: write err") - rsp.SetStatus(ble.ErrInvalidHandle) - return - } - - rsp.SetStatus(ble.ErrSuccess) - })) - - c.HandleWrite(ble.WriteHandlerFunc(func(req ble.Request, rsp ble.ResponseWriter) { - val := math.Float64frombits(binary.LittleEndian.Uint64(req.Data())) - - log.Printf("count: Write %f", val) - - n = val - - rsp.SetStatus(ble.ErrSuccess) - })) - - c.HandleNotify(nfHandler("notify")) - c.HandleIndicate(nfHandler("indicate")) - - return c -} diff --git a/tools/ble-srv/dev_darwin.go b/tools/ble-srv/dev_darwin.go deleted file mode 100644 index ce134c6..0000000 --- a/tools/ble-srv/dev_darwin.go +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright 2019 Rightech IoT. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import "github.com/Rightech/ric-edge/third_party/go-ble/ble/darwin" - -func newDevice() (*darwin.Device, error) { - return darwin.NewDevice() -} diff --git a/tools/ble-srv/dev_linux.go b/tools/ble-srv/dev_linux.go deleted file mode 100644 index bb88d8d..0000000 --- a/tools/ble-srv/dev_linux.go +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2019 Rightech IoT. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "github.com/Rightech/ric-edge/third_party/go-ble/ble/linux" -) - -func newDevice() (*linux.Device, error) { - return linux.NewDeviceWithName("ble-srv") -} diff --git a/tools/ble-srv/main.go b/tools/ble-srv/main.go deleted file mode 100644 index 4cc5290..0000000 --- a/tools/ble-srv/main.go +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2019 Rightech IoT. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package main - -import ( - "context" - "errors" - - log "github.com/sirupsen/logrus" - - "github.com/Rightech/ric-edge/internal/pkg/config" - "github.com/Rightech/ric-edge/third_party/go-ble/ble" -) - -func main() { - config.Init(nil) - - d, err := newDevice() - if err != nil { - log.Fatalf("can't new device : %s", err) - } - - ble.SetDefaultDevice(d) - - log.Info("Address: ", d.Address().String()) - - testSvc := ble.NewService(ble.MustParse("00010000-0001-1000-8000-00805F9B34FB")) - testSvc.AddCharacteristic(newCountChar()) - - if err := ble.AddService(testSvc); err != nil { - log.Fatalf("can't add service: %s", err) - } - - ctx := ble.WithSigHandler(context.WithCancel(context.Background())) - - err = ble.AdvertiseNameAndServices(ctx, "ble-srv", testSvc.UUID) - if errors.Is(err, context.Canceled) { - log.Info("canceled") - } else { - log.Error(err) - } -} diff --git a/tools/dev-env/docker-compose.yml b/tools/dev-env/docker-compose.yml deleted file mode 100644 index 80e24f3..0000000 --- a/tools/dev-env/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: '3' - -services: - mqtt: - image: eclipse-mosquitto:1.6 - ports: - - "1883:1883" - snmpd: - image: polinux/snmpd:alpine - network_mode: "host" diff --git "a/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" new file mode 100644 index 0000000..e69de29