diff --git a/backend/ats/package.json b/backend/ats/package.json index 165193a9..8de38735 100644 --- a/backend/ats/package.json +++ b/backend/ats/package.json @@ -14,7 +14,7 @@ "ts-jest": "^29.0.3", "ts-node": "^10.9.1", "ts-protoc-gen": "0.15.0", - "typescript": "4.9.3" + "typescript": "4.8.4" }, "dependencies": { "@grpc/grpc-js": "^1.7.2", diff --git a/backend/ats/spec/block_pb.d.ts b/backend/ats/spec/block_pb.d.ts index 956a5061..4c5994af 100644 --- a/backend/ats/spec/block_pb.d.ts +++ b/backend/ats/spec/block_pb.d.ts @@ -129,7 +129,7 @@ export interface BlockIdMap { HASHIMOTO_B1: 31; HASHIMOTO_B2: 32; HACHIOJI_B1: 41; - HASHIOJI_B2: 42; + HACHIOJI_B2: 42; } export const BlockId: BlockIdMap; diff --git a/backend/ats/spec/block_pb.js b/backend/ats/spec/block_pb.js index a1f29699..86d12774 100644 --- a/backend/ats/spec/block_pb.js +++ b/backend/ats/spec/block_pb.js @@ -821,7 +821,7 @@ proto.BlockId = { HASHIMOTO_B1: 31, HASHIMOTO_B2: 32, HACHIOJI_B1: 41, - HASHIOJI_B2: 42 + HACHIOJI_B2: 42 }; goog.object.extend(exports, proto); diff --git a/backend/ats/yarn.lock b/backend/ats/yarn.lock index 9992ad9d..eb447448 100644 --- a/backend/ats/yarn.lock +++ b/backend/ats/yarn.lock @@ -2509,10 +2509,10 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -typescript@4.9.3: - version "4.9.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db" - integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA== +typescript@4.8.4: + version "4.8.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" + integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== update-browserslist-db@^1.0.9: version "1.0.10" diff --git a/backend/auto_operation/requirements.txt b/backend/auto_operation/requirements.txt index 078158d8..51aae66a 100644 --- a/backend/auto_operation/requirements.txt +++ b/backend/auto_operation/requirements.txt @@ -1,7 +1,7 @@ bidict==0.22.0 click==8.1.3 dnspython==2.2.1 -eventlet==0.33.1 +eventlet==0.33.2 Flask==2.2.2 Flask-Cors==3.0.10 Flask-SocketIO==5.3.1 @@ -22,5 +22,5 @@ types-protobuf==3.20.4.5 types-Flask-Cors Werkzeug==2.2.2 zope.event==4.5.0 -zope.interface==5.5.1 +zope.interface==5.5.2 grpcio-tools==1.50.0 diff --git a/backend/auto_operation/spec/block_pb2.py b/backend/auto_operation/spec/block_pb2.py index f061ec7b..b7b651ef 100644 --- a/backend/auto_operation/spec/block_pb2.py +++ b/backend/auto_operation/spec/block_pb2.py @@ -13,7 +13,7 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x62lock.proto\"J\n\rBlockAndState\x12\x19\n\x07\x62lockId\x18\x03 \x01(\x0e\x32\x08.BlockId\x12\x1e\n\x05state\x18\x02 \x01(\x0e\x32\x0f.BlockStateEnum\"8\n\x17UpdateBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18UpdateBlockStateResponse\"8\n\x17NotifyBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18NotifyBlockStateResponse*S\n\x0e\x42lockStateEnum\x12\x16\n\x12\x42LOCKSTATE_UNKNOWN\x10\x00\x12\x13\n\x0f\x42LOCKSTATE_OPEN\x10\x01\x12\x14\n\x10\x42LOCKSTATE_CLOSE\x10\x02*\xbc\x02\n\x07\x42lockId\x12\x0b\n\x07unknown\x10\x00\x12\x0f\n\x0bshinjuku_b1\x10\x01\x12\x0f\n\x0bshinjuku_b2\x10\x02\x12\x12\n\x0esakurajosui_b1\x10\x0b\x12\x12\n\x0esakurajosui_b2\x10\x0c\x12\x12\n\x0esakurajosui_b3\x10\r\x12\x12\n\x0esakurajosui_b4\x10\x0e\x12\x12\n\x0esakurajosui_b5\x10\x0f\x12\x12\n\x0esakurajosui_b6\x10\x10\x12\x0c\n\x08\x63hofu_b1\x10\x15\x12\x0c\n\x08\x63hofu_b2\x10\x16\x12\x0c\n\x08\x63hofu_b3\x10\x17\x12\x0c\n\x08\x63hofu_b4\x10\x18\x12\x0c\n\x08\x63hofu_b5\x10\x19\x12\x10\n\x0chashimoto_b1\x10\x1f\x12\x10\n\x0chashimoto_b2\x10 \x12\x0f\n\x0bhachioji_b1\x10)\x12\x0f\n\x0bhashioji_b2\x10*2^\n\x11\x42lockStateManager\x12I\n\x10UpdateBlockState\x12\x18.UpdateBlockStateRequest\x1a\x19.UpdateBlockStateResponse\"\x00\x32\x63\n\x16\x42lockStateNotification\x12I\n\x10NotifyBlockState\x12\x18.NotifyBlockStateRequest\x1a\x19.NotifyBlockStateResponse\"\x00\x42\x08Z\x06./specb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x62lock.proto\"J\n\rBlockAndState\x12\x19\n\x07\x62lockId\x18\x03 \x01(\x0e\x32\x08.BlockId\x12\x1e\n\x05state\x18\x02 \x01(\x0e\x32\x0f.BlockStateEnum\"8\n\x17UpdateBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18UpdateBlockStateResponse\"8\n\x17NotifyBlockStateRequest\x12\x1d\n\x05state\x18\x01 \x01(\x0b\x32\x0e.BlockAndState\"\x1a\n\x18NotifyBlockStateResponse*S\n\x0e\x42lockStateEnum\x12\x16\n\x12\x42LOCKSTATE_UNKNOWN\x10\x00\x12\x13\n\x0f\x42LOCKSTATE_OPEN\x10\x01\x12\x14\n\x10\x42LOCKSTATE_CLOSE\x10\x02*\xbc\x02\n\x07\x42lockId\x12\x0b\n\x07unknown\x10\x00\x12\x0f\n\x0bshinjuku_b1\x10\x01\x12\x0f\n\x0bshinjuku_b2\x10\x02\x12\x12\n\x0esakurajosui_b1\x10\x0b\x12\x12\n\x0esakurajosui_b2\x10\x0c\x12\x12\n\x0esakurajosui_b3\x10\r\x12\x12\n\x0esakurajosui_b4\x10\x0e\x12\x12\n\x0esakurajosui_b5\x10\x0f\x12\x12\n\x0esakurajosui_b6\x10\x10\x12\x0c\n\x08\x63hofu_b1\x10\x15\x12\x0c\n\x08\x63hofu_b2\x10\x16\x12\x0c\n\x08\x63hofu_b3\x10\x17\x12\x0c\n\x08\x63hofu_b4\x10\x18\x12\x0c\n\x08\x63hofu_b5\x10\x19\x12\x10\n\x0chashimoto_b1\x10\x1f\x12\x10\n\x0chashimoto_b2\x10 \x12\x0f\n\x0bhachioji_b1\x10)\x12\x0f\n\x0bhachioji_b2\x10*2^\n\x11\x42lockStateManager\x12I\n\x10UpdateBlockState\x12\x18.UpdateBlockStateRequest\x1a\x19.UpdateBlockStateResponse\"\x00\x32\x63\n\x16\x42lockStateNotification\x12I\n\x10NotifyBlockState\x12\x18.NotifyBlockStateRequest\x1a\x19.NotifyBlockStateResponse\"\x00\x42\x08Z\x06./specb\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'block_pb2', globals()) diff --git a/backend/auto_operation/spec/block_pb2.pyi b/backend/auto_operation/spec/block_pb2.pyi index 65f0a999..a6117e3a 100644 --- a/backend/auto_operation/spec/block_pb2.pyi +++ b/backend/auto_operation/spec/block_pb2.pyi @@ -13,9 +13,9 @@ chofu_b3: BlockId chofu_b4: BlockId chofu_b5: BlockId hachioji_b1: BlockId +hachioji_b2: BlockId hashimoto_b1: BlockId hashimoto_b2: BlockId -hashioji_b2: BlockId sakurajosui_b1: BlockId sakurajosui_b2: BlockId sakurajosui_b3: BlockId diff --git a/backend/external/internal/embed/stationInit.yml b/backend/external/internal/embed/stationInit.yml index 50b47bd0..d8342727 100644 --- a/backend/external/internal/embed/stationInit.yml +++ b/backend/external/internal/embed/stationInit.yml @@ -1,86 +1,86 @@ stations: - name: motoyawata_s1 - state: ON + state: POINTSTATE_ON - name: motoyawata_s2 - state: ON + state: POINTSTATE_ON - name: iwamotocho_s1 - state: ON + state: POINTSTATE_ON - name: iwamotocho_s2 - state: ON + state: POINTSTATE_ON - name: iwamotocho_s4 - state: ON + state: POINTSTATE_ON - name: iwamotocho_b1 - state: ON + state: POINTSTATE_ON - name: iwamotocho_b4 - state: ON + state: POINTSTATE_ON - name: kudanshita_s5 - state: ON + state: POINTSTATE_ON - name: kudanshita_s6 - state: ON + state: POINTSTATE_ON - name: sasazuka_b1 - state: ON + state: POINTSTATE_ON - name: sasazuka_b2 - state: ON + state: POINTSTATE_ON - name: sasazuka_s1 - state: ON + state: POINTSTATE_ON - name: sasazuka_s2 - state: ON + state: POINTSTATE_ON - name: sasazuka_s3 - state: ON + state: POINTSTATE_ON - name: sasazuka_s4 - state: ON + state: POINTSTATE_ON - name: sasazuka_s5 - state: ON + state: POINTSTATE_ON - name: meidaimae_s1 - state: ON + state: POINTSTATE_ON - name: meidaimae_s2 - state: ON + state: POINTSTATE_ON - name: chofu_s1 - state: ON + state: POINTSTATE_ON - name: chofu_s2 - state: OFF + state: POINTSTATE_OFF - name: chofu_s3 - state: ON + state: POINTSTATE_ON - name: chofu_s4 - state: ON + state: POINTSTATE_ON - name: chofu_s5 - state: ON + state: POINTSTATE_ON - name: chofu_s6 - state: ON + state: POINTSTATE_ON - name: chofu_b1 - state: ON + state: POINTSTATE_ON - name: chofu_b2 - state: OFF + state: POINTSTATE_OFF - name: chofu_b3 - state: ON + state: POINTSTATE_ON - name: chofu_b4 - state: ON + state: POINTSTATE_ON - name: chofu_b5 - state: ON + state: POINTSTATE_ON - name: kitano_b1 - state: ON + state: POINTSTATE_ON - name: kitano_b2 - state: ON + state: POINTSTATE_ON - name: kitano_s1 - state: ON + state: POINTSTATE_ON - name: kitano_s2 - state: ON + state: POINTSTATE_ON - name: kitano_s3 - state: ON + state: POINTSTATE_ON - name: kitano_s4 - state: ON + state: POINTSTATE_ON - name: kitano_s5 - state: ON + state: POINTSTATE_ON - name: kitano_s6 - state: ON + state: POINTSTATE_ON - name: takao_s1 - state: ON + state: POINTSTATE_ON - name: takao_s2 - state: ON + state: POINTSTATE_ON diff --git a/backend/external/internal/grpc.go b/backend/external/internal/grpc.go index 9c11f740..3e329398 100644 --- a/backend/external/internal/grpc.go +++ b/backend/external/internal/grpc.go @@ -116,3 +116,42 @@ func GRPCListenAndServe(ctx context.Context, logger *zap.Logger, port uint, hand logger.Panic("failed to server", zap.Error(err)) } } + +// GrpcStateHandler is a handler for gRPC. +type GrpcStateHandlerForInternal struct { + logger *zap.Logger + env *envStore.Env + stateInput <-chan synccontroller.KV[spec.StationId, spec.PointStateEnum] +} + +// / handleInput transmits changes received in channel to ATS. +func (g GrpcStateHandlerForInternal) handleInput(ctx context.Context) { + con, err := grpc.DialContext(ctx, g.env.InternalServer.Addr.String(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + g.logger.Error("failed to connect ATS", zap.Error(err)) + } + defer con.Close() + for d := range g.stateInput { + client := spec.NewPointStateNotificationClient(con) + req := &spec.NotifyPointStateRequest{ + State: &spec.PointAndState{ + Station: &spec.Station{StationId: d.Key}, + State: d.Value, + }, + } + _, err := client.NotifyPointState(ctx, req) + if err != nil { + g.logger.Error("failed to send data to ATS", zap.Any("payload", req), zap.Error(err)) + } + } +} + +func NewGrpcHandlerForInternal(logger *zap.Logger, env *envStore.Env, stateInput <-chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) *GrpcStateHandlerForInternal { + return &GrpcStateHandlerForInternal{logger, env, stateInput} +} + +func (g GrpcStateHandlerForInternal) Run(ctx context.Context) { + g.handleInput(ctx) +} diff --git a/backend/external/internal/root.go b/backend/external/internal/root.go index 88b1755f..90d89d68 100644 --- a/backend/external/internal/root.go +++ b/backend/external/internal/root.go @@ -2,9 +2,16 @@ package internal import ( "context" + "fmt" + "net/http" + "time" + + "github.com/gorilla/mux" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/ueckoken/plarail2022/backend/external/pkg/envStore" "github.com/ueckoken/plarail2022/backend/external/pkg/httphandler" "github.com/ueckoken/plarail2022/backend/external/pkg/synccontroller" + "github.com/ueckoken/plarail2022/backend/external/pkg/websockethandler" "github.com/ueckoken/plarail2022/backend/external/spec" "go.uber.org/zap" @@ -14,17 +21,18 @@ import ( func Run(logger *zap.Logger) { ctx := context.Background() synccontrollerInput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) - synccontrollerOutput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) + synccontrollerOutput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum], 32) grpcHandlerInput := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) - main2grpcHandler := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) - httpInputKV := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) + main2autooperation := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum]) + main2internal := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum], 32) + httpInputKV := make(chan synccontroller.KV[spec.StationId, spec.PointStateEnum], 32) httpInput := make(chan *spec.PointAndState) httpOutput := make(chan *spec.PointAndState) go func() { for c := range synccontrollerOutput { select { - case main2grpcHandler <- c: + case main2autooperation <- c: default: logger.Info("buffer full", zap.String("buffer", "main2grpcHandler")) } @@ -33,36 +41,119 @@ func Run(logger *zap.Logger) { default: logger.Info("buffer full", zap.String("buffer", "httpInputKV")) } + select { + case main2internal <- c: + default: + logger.Info("buffer full", zap.String("buffer", "internal")) + } } }() + go func() { for c := range httpInputKV { - httpInput <- &spec.PointAndState{Station: &spec.Station{StationId: c.Key}, State: c.Value} + select { + case httpInput <- &spec.PointAndState{Station: &spec.Station{StationId: c.Key}, State: c.Value}: + default: + logger.Info("buffer full", zap.String("buffer", "httpInput")) + } } }() go func() { for c := range httpOutput { - synccontrollerInput <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: c.GetStation().GetStationId(), Value: c.GetState()} + select { + case synccontrollerInput <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: c.GetStation().GetStationId(), Value: c.GetState()}: + default: + logger.Info("buffer full", zap.String("buffer", "synccontrollerInput-httpoutput")) + } + } + }() + + go func() { + for c := range grpcHandlerInput { + select { + case synccontrollerInput <- c: + default: + logger.Info("buffer full", zap.String("buffer", "synccontrollerInput-grpchandler")) + } } }() envVal := envStore.GetEnv() httpServer := httphandler.NewHTTPServer( - logger.Named("sync-controller"), + logger.Named("http-state"), httpOutput, httpInput, envVal, + "httppointserver", ) + StartStationSync(logger.Named("station-sync"), synccontrollerInput, synccontrollerOutput) - grpcHandler := NewGrpcHandler(logger.Named("grpc-handler"), envVal, main2grpcHandler, grpcHandlerInput) + grpcHandler := NewGrpcHandler(logger.Named("grpc-handler"), envVal, main2autooperation, grpcHandlerInput) + internalHandler := NewGrpcHandlerForInternal(logger.Named("grpc-internal"), envVal, main2internal) + go internalHandler.Run(ctx) + + httpBlockInput := make(chan *spec.BlockAndState) + httpBlockOutput := make(chan *spec.BlockAndState) + blocksyncInput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum]) + blocksyncOutput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum]) + grpcBlockHandlerInput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum]) + grpcBlockHandlerOutput := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum]) + + httpBlockServer := httphandler.NewHTTPServer( + logger.Named("http-block"), + httpBlockOutput, + httpBlockInput, + envVal, + "httpblockserver", + ) - client2blocksync := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum]) - blocksync2client := make(chan synccontroller.KV[spec.BlockId, spec.BlockStateEnum]) - startBlockSync(logger.Named("blocksync"), client2blocksync, blocksync2client) - grpcBlockHandl := NewGrpcBlockHandler(logger.Named("grpc-block-handler"), envVal, client2blocksync, blocksync2client) + go func() { + for c := range grpcBlockHandlerOutput { + select { + case blocksyncInput <- synccontroller.KV[spec.BlockId, spec.BlockStateEnum]{Key: c.Key, Value: c.Value}: + default: + logger.Info("buffer full", zap.String("buffer", "blocksyncInput-grpchandler")) + } + } + }() + + go func() { + for c := range blocksyncOutput { + select { + case grpcBlockHandlerInput <- c: + default: + logger.Info("buffer full", zap.String("buffer", "grpcblockhandlerinput-blocksync")) + } + select { + case httpBlockInput <- &spec.BlockAndState{BlockId: c.Key, State: c.Value}: + default: + logger.Info("buffer full", zap.String("buffer", "httpblockinput-blocksync")) + } + } + }() + + startBlockSync(logger.Named("blocksync"), blocksyncInput, blocksyncOutput) + grpcBlockHandl := NewGrpcBlockHandler(logger.Named("grpc-block-handler"), envVal, grpcBlockHandlerOutput, grpcBlockHandlerInput) go GRPCListenAndServe(ctx, logger, uint(envVal.ClientSideServer.GrpcPort), grpcHandler, grpcBlockHandl) - httpServer.StartServer() + r := mux.NewRouter() + r.HandleFunc("/", websockethandler.HandleStatic) + r.Handle("/metrics", promhttp.Handler()) + httpBlockServer.RegisterServer(r, "/blockws") + httpServer.RegisterServer(r, "/pointws") + + srv := &http.Server{ + Handler: r, + Addr: fmt.Sprintf("0.0.0.0:%d", int(envVal.ClientSideServer.Port)), + ReadHeaderTimeout: 5 * time.Second, + ReadTimeout: 5 * time.Second, + WriteTimeout: 5 * time.Second, + } + + logger.Info("start listening") + if err := srv.ListenAndServe(); err != nil { + logger.Panic("failed to serve", zap.Error(err)) + } } diff --git a/backend/external/internal/stationsync.go b/backend/external/internal/stationsync.go index 44639b5f..65a6f53b 100644 --- a/backend/external/internal/stationsync.go +++ b/backend/external/internal/stationsync.go @@ -29,7 +29,11 @@ func initStationSync(logger *zap.Logger, r *InitRule, initializer chan<- synccon logger.Error("unknown state", zap.String("state", sta.State)) continue } - initializer <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: spec.StationId(id), Value: spec.PointStateEnum(state)} + select { + case initializer <- synccontroller.KV[spec.StationId, spec.PointStateEnum]{Key: spec.StationId(id), Value: spec.PointStateEnum(state)}: + default: + logger.Error("failed to initialize sync controller, buffer full") + } time.Sleep(500 * time.Millisecond) } } diff --git a/backend/external/pkg/httphandler/httphandler.go b/backend/external/pkg/httphandler/httphandler.go index 66f1571d..cd29b253 100644 --- a/backend/external/pkg/httphandler/httphandler.go +++ b/backend/external/pkg/httphandler/httphandler.go @@ -1,16 +1,12 @@ package httphandler import ( - "fmt" "github.com/ueckoken/plarail2022/backend/external/pkg/envStore" "github.com/ueckoken/plarail2022/backend/external/pkg/websockethandler" - "net/http" "sync" - "time" "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" "go.uber.org/zap" "google.golang.org/protobuf/proto" ) @@ -28,8 +24,7 @@ type HTTPServer[T proto.Message] struct { } // NewHTTPServer creates HTTP server. -func NewHTTPServer[T proto.Message](logger *zap.Logger, httpOutput chan<- T, httpInput <-chan T, env *envStore.Env) *HTTPServer[T] { - const namespace = "plarailexternal" +func NewHTTPServer[T proto.Message](logger *zap.Logger, httpOutput chan<- T, httpInput <-chan T, env *envStore.Env, namespace string) *HTTPServer[T] { clientConn := prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: namespace, @@ -76,31 +71,16 @@ type ClientsCollection[T proto.Message] struct { } // StartServer starts HTTP server and websocket server. -func (h *HTTPServer[T]) StartServer() { +func (h *HTTPServer[T]) RegisterServer(r *mux.Router, endpoint string) { clientChannelSend := make(chan websockethandler.ClientChannel[T]) handlerInput := make(chan T) go h.registerClient(clientChannelSend) go h.broadcastChanges() go h.unregisterClients() - r := mux.NewRouter() prometheus.MustRegister(h.numberOfClientConnection) prometheus.MustRegister(h.totalClientConnection) prometheus.MustRegister(h.totalCLientCommands) - r.HandleFunc("/", websockethandler.HandleStatic) - r.Handle("/ws", websockethandler.NewClientHandler(h.logger.Named("ws-handler"), handlerInput, clientChannelSend)) - r.Handle("/metrics", promhttp.Handler()) - srv := &http.Server{ - Handler: r, - Addr: fmt.Sprintf("0.0.0.0:%d", h.environment.ClientSideServer.Port), - ReadHeaderTimeout: 5 * time.Second, - ReadTimeout: 5 * time.Second, - WriteTimeout: 5 * time.Second, - } - - h.logger.Info("start listening") - if err := srv.ListenAndServe(); err != nil { - h.logger.Panic("failed to serve", zap.Error(err)) - } + r.Handle(endpoint, websockethandler.NewClientHandler(h.logger.Named("ws-handler"), handlerInput, clientChannelSend)) } // broadcastChanges receives the change from main channel and broadcast it to clients. diff --git a/backend/external/pkg/synccontroller/syncController.go b/backend/external/pkg/synccontroller/syncController.go index 3821e291..17367b48 100644 --- a/backend/external/pkg/synccontroller/syncController.go +++ b/backend/external/pkg/synccontroller/syncController.go @@ -96,7 +96,6 @@ func (s *SyncController[T, U]) periodicallySync() { } } s.kvs.mtx.Unlock() - s.logger.Info("unlocked") }() } } diff --git a/backend/external/pkg/websockethandler/embed/index.html b/backend/external/pkg/websockethandler/embed/index.html index d9b2b711..61decbc5 100644 --- a/backend/external/pkg/websockethandler/embed/index.html +++ b/backend/external/pkg/websockethandler/embed/index.html @@ -11,7 +11,7 @@ p1.innerHTML = data; }; window.onload = function () { - sock = new WebSocket("ws://" + location.host + "/ws"); + sock = new WebSocket("wss://" + location.host + "/ws"); sock.onmessage = function (event) { var data = JSON.parse(event.data); sock.send(`{"station": {"stationId":26}, "state": 1}`); diff --git a/backend/external/pkg/websockethandler/websockethandler.go b/backend/external/pkg/websockethandler/websockethandler.go index 9733f1a7..9c33cad1 100644 --- a/backend/external/pkg/websockethandler/websockethandler.go +++ b/backend/external/pkg/websockethandler/websockethandler.go @@ -60,7 +60,7 @@ func (m ClientHandler[T]) ServeHTTP(w http.ResponseWriter, r *http.Request) { return c.SetReadDeadline(time.Now().Add(20 * time.Second)) }) c.SetCloseHandler(func(code int, text string) error { - m.logger.Info("connection closed") + m.logger.Info("connection closed", zap.Int("code", code), zap.String("text", text)) cancel() return nil }) diff --git a/backend/external/spec/block.pb.go b/backend/external/spec/block.pb.go index b8ce9f16..d3ca52cb 100644 --- a/backend/external/spec/block.pb.go +++ b/backend/external/spec/block.pb.go @@ -89,7 +89,7 @@ const ( BlockId_hashimoto_b1 BlockId = 31 BlockId_hashimoto_b2 BlockId = 32 BlockId_hachioji_b1 BlockId = 41 - BlockId_hashioji_b2 BlockId = 42 + BlockId_hachioji_b2 BlockId = 42 ) // Enum value maps for BlockId. @@ -112,7 +112,7 @@ var ( 31: "hashimoto_b1", 32: "hashimoto_b2", 41: "hachioji_b1", - 42: "hashioji_b2", + 42: "hachioji_b2", } BlockId_value = map[string]int32{ "unknown": 0, @@ -132,7 +132,7 @@ var ( "hashimoto_b1": 31, "hashimoto_b2": 32, "hachioji_b1": 41, - "hashioji_b2": 42, + "hachioji_b2": 42, } ) @@ -434,7 +434,7 @@ var file_proto_block_proto_rawDesc = []byte{ 0x6d, 0x6f, 0x74, 0x6f, 0x5f, 0x62, 0x31, 0x10, 0x1f, 0x12, 0x10, 0x0a, 0x0c, 0x68, 0x61, 0x73, 0x68, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x5f, 0x62, 0x32, 0x10, 0x20, 0x12, 0x0f, 0x0a, 0x0b, 0x68, 0x61, 0x63, 0x68, 0x69, 0x6f, 0x6a, 0x69, 0x5f, 0x62, 0x31, 0x10, 0x29, 0x12, 0x0f, 0x0a, 0x0b, - 0x68, 0x61, 0x73, 0x68, 0x69, 0x6f, 0x6a, 0x69, 0x5f, 0x62, 0x32, 0x10, 0x2a, 0x32, 0x5e, 0x0a, + 0x68, 0x61, 0x63, 0x68, 0x69, 0x6f, 0x6a, 0x69, 0x5f, 0x62, 0x32, 0x10, 0x2a, 0x32, 0x5e, 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x49, 0x0a, 0x10, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x18, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x42, diff --git a/backend/proto/block.proto b/backend/proto/block.proto index ffb65a70..02369187 100644 --- a/backend/proto/block.proto +++ b/backend/proto/block.proto @@ -42,7 +42,7 @@ enum BlockId { hashimoto_b2 = 32; hachioji_b1 = 41; - hashioji_b2 = 42; + hachioji_b2 = 42; } message BlockAndState { diff --git a/debug/auto_operation_visualizer/package-lock.json b/debug/auto_operation_visualizer/package-lock.json index 91a4f4f6..2fffb59c 100644 --- a/debug/auto_operation_visualizer/package-lock.json +++ b/debug/auto_operation_visualizer/package-lock.json @@ -18,7 +18,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "socket.io-client": "^4.5.3", - "typescript": "4.9.3" + "typescript": "4.8.4" } }, "node_modules/@babel/runtime": { @@ -2882,9 +2882,9 @@ } }, "node_modules/typescript": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", - "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -4962,9 +4962,9 @@ "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==" }, "typescript": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz", - "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==" + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==" }, "unbox-primitive": { "version": "1.0.2", diff --git a/debug/auto_operation_visualizer/package.json b/debug/auto_operation_visualizer/package.json index b49dbf58..909514d6 100644 --- a/debug/auto_operation_visualizer/package.json +++ b/debug/auto_operation_visualizer/package.json @@ -19,6 +19,6 @@ "react": "18.2.0", "react-dom": "18.2.0", "socket.io-client": "^4.5.3", - "typescript": "4.9.3" + "typescript": "4.8.4" } } diff --git a/frontend/camera_sender/index.html b/frontend/camera_sender/index.html index 40b97f24..25484450 100644 --- a/frontend/camera_sender/index.html +++ b/frontend/camera_sender/index.html @@ -22,6 +22,9 @@

Room example

+ + +
diff --git a/frontend/camera_sender/index.js b/frontend/camera_sender/index.js index 7cff67e2..d00ea6e3 100644 --- a/frontend/camera_sender/index.js +++ b/frontend/camera_sender/index.js @@ -2,10 +2,27 @@ const Peer = window.Peer ; (async function main() { + var sel = document.getElementById('select'); + const devices = (await navigator.mediaDevices.enumerateDevices()) + .filter((device) => device.kind === 'videoinput') + .map((device) => { + return { + text: device.label, + value: device.deviceId, + }; + }); + for (var i = 0; i < devices.length; i++) { + var opt = document.createElement("option"); + opt.value = devices[i].value; + opt.text = devices[i].text; + sel.add(opt, null); + } + console.log(devices); const localVideo = document.getElementById("js-local-stream") const joinTrigger = document.getElementById("js-join-trigger") const leaveTrigger = document.getElementById("js-leave-trigger") const remoteVideos = document.getElementById("js-remote-streams") + const setCameraTrigger = document.getElementById("set-camera-trigger") const roomId = document.getElementById("js-room-id") const roomMode = document.getElementById("js-room-mode") const localText = document.getElementById("js-local-text") @@ -27,16 +44,34 @@ const Peer = window.Peer () => (roomMode.textContent = getRoomModeByHash()) ) - const localStream = await navigator.mediaDevices + let localStream = await navigator.mediaDevices .getUserMedia({ - video: true, + video: { + deviceId: document.getElementById('select').value + } }) - .catch(console.error) + .catch(console.error); + + setCameraTrigger.addEventListener("click", async () => { + localStream = await navigator.mediaDevices + .getUserMedia({ + video: { + deviceId: document.getElementById('select').value + } + }) + .catch(console.error) + // Render local stream + localVideo.muted = true; + localVideo.srcObject = localStream; + localVideo.playsInline = true; + await localVideo.play().catch(console.error) + }); + // Render local stream - localVideo.muted = true - localVideo.srcObject = localStream - localVideo.playsInline = true + localVideo.muted = true; + localVideo.srcObject = localStream; + localVideo.playsInline = true; await localVideo.play().catch(console.error) // eslint-disable-next-line require-atomic-updates diff --git a/frontend/site/components/RailRoadMap.tsx b/frontend/site/components/RailRoadMap.tsx index 8c5886da..a77935e2 100644 --- a/frontend/site/components/RailRoadMap.tsx +++ b/frontend/site/components/RailRoadMap.tsx @@ -4,13 +4,19 @@ import Platform from "./svgParts/Platform" import SwitchPoint from "./svgParts/SwitchPoint" import StopPoint from "./svgParts/StopPoint" import { Point, TrainData } from "../types/svgPartsTypes" -import { BunkiRailId, StationId, StopRailId } from "../types/control-messages" +import { + BlocklId, + BunkiRailId, + StationId, + StopRailId, +} from "../types/control-messages" interface Prop { datas: { stop: Record switchState: Record train1: TrainData + blockState: Record } onStopPointOrSwitchPointClick?: (stationId: StationId) => any } @@ -27,33 +33,23 @@ type MapRange = { } const STOP_PONINTS: StopPointPosition[] = [ - { position: { x: 940, y: 560 }, id: "motoyawata_s1" }, - { position: { x: 1000, y: 560 }, id: "motoyawata_s2" }, - { position: { x: 120, y: 20 }, id: "kitano_s6" }, - { position: { x: 240, y: 20 }, id: "kitano_s4" }, - { position: { x: 240, y: 60 }, id: "kitano_s3" }, - { position: { x: 240, y: 80 }, id: "kitano_s2" }, - { position: { x: 240, y: 120 }, id: "kitano_s1" }, - { position: { x: 520, y: 20 }, id: "chofu_s4" }, - { position: { x: 520, y: 60 }, id: "chofu_s3" }, - { position: { x: 520, y: 120 }, id: "chofu_s2" }, - { position: { x: 520, y: 160 }, id: "chofu_s1" }, - { position: { x: 700, y: 60 }, id: "meidaimae_s2" }, - { position: { x: 700, y: 80 }, id: "meidaimae_s1" }, - { position: { x: 800, y: 70 }, id: "sasazuka_s5" }, - { position: { x: 880, y: 20 }, id: "sasazuka_s4" }, - { position: { x: 880, y: 60 }, id: "sasazuka_s3" }, - { position: { x: 880, y: 80 }, id: "sasazuka_s2" }, - { position: { x: 880, y: 120 }, id: "sasazuka_s1" }, - { position: { x: 120, y: 140 }, id: "kitano_s5" }, - { position: { x: 180, y: 200 }, id: "takao_s1" }, - { position: { x: 120, y: 380 }, id: "takao_s2" }, - { position: { x: 320, y: 180 }, id: "chofu_s5" }, - { position: { x: 940, y: 180 }, id: "kudanshita_s5" }, - { position: { x: 1000, y: 180 }, id: "kudanshita_s6" }, - { position: { x: 880, y: 380 }, id: "iwamotocho_s1" }, - { position: { x: 940, y: 380 }, id: "iwamotocho_s2" }, - { position: { x: 1000, y: 380 }, id: "iwamotocho_s4" }, + { position: { x: 700, y: 40 }, id: "shinjuku_s1" }, + { position: { x: 700, y: 100 }, id: "shinjuku_s2" }, + { position: { x: 950, y: 250 }, id: "sakurajosui_s0" }, + { position: { x: 1000, y: 400 }, id: "sakurajosui_s1" }, + { position: { x: 950, y: 400 }, id: "sakurajosui_s2" }, + { position: { x: 900, y: 400 }, id: "sakurajosui_s3" }, + { position: { x: 850, y: 400 }, id: "sakurajosui_s4" }, + { position: { x: 900, y: 500 }, id: "sakurajosui_s5" }, + { position: { x: 350, y: 550 }, id: "chofu_s0" }, + { position: { x: 350, y: 400 }, id: "chofu_s1" }, + { position: { x: 400, y: 400 }, id: "chofu_s2" }, + { position: { x: 300, y: 400 }, id: "chofu_s4" }, + { position: { x: 240, y: 400 }, id: "chofu_s3" }, + { position: { x: 90, y: 40 }, id: "hachioji_s2" }, + { position: { x: 90, y: 100 }, id: "hachioji_s1" }, + { position: { x: 90, y: 300 }, id: "hashimoto_s1" }, + { position: { x: 90, y: 240 }, id: "hashimoto_s2" }, ] type SwitchPointPotiionAndAngle = { @@ -65,81 +61,18 @@ type SwitchPointPotiionAndAngle = { } const SWITCH_POINTS: SwitchPointPotiionAndAngle[] = [ { - position: { x: 160, y: 20 }, - fromAngle: 180, - leftOutAngle: 0, - rightOutAngle: 45, - id: "kitano_b2", - }, - { - position: { x: 320, y: 120 }, - fromAngle: 0, - leftOutAngle: 180, - rightOutAngle: 225, - id: "kitano_b1", - }, - { - position: { x: 380, y: 20 }, - fromAngle: 180, - leftOutAngle: 45, - rightOutAngle: 0, - id: "chofu_b5", - }, - { - position: { x: 440, y: 60 }, - fromAngle: 180, - leftOutAngle: -45, - rightOutAngle: 0, - id: "chofu_b4", - }, - { - position: { x: 420, y: 160 }, - fromAngle: 0, - leftOutAngle: 225, - rightOutAngle: 180, - id: "chofu_b3", - }, - { - position: { x: 480, y: 120 }, - fromAngle: 0, - leftOutAngle: 180, - rightOutAngle: 135, - id: "chofu_b2", - }, - { - position: { x: 600, y: 120 }, - fromAngle: 0, - leftOutAngle: 135, - rightOutAngle: 180, - id: "chofu_b1", - }, - { - position: { x: 800, y: 20 }, - fromAngle: 180, - leftOutAngle: 0, - rightOutAngle: 45, - id: "sasazuka_b2", - }, - { - position: { x: 840, y: 80 }, - fromAngle: 0, - leftOutAngle: 180, - rightOutAngle: 135, - id: "sasazuka_b1", - }, - { - position: { x: 1000, y: 280 }, + position: { x: 950, y: 300 }, fromAngle: 270, leftOutAngle: 90, - rightOutAngle: 135, - id: "iwamotocho_b4", + rightOutAngle: 0, + id: "sakurajosui_p1", }, { - position: { x: 940, y: 480 }, + position: { x: 350, y: 500 }, fromAngle: 90, leftOutAngle: 270, - rightOutAngle: 225, - id: "iwamotocho_b1", + rightOutAngle: 0, + id: "chofu_p1", }, ] @@ -160,111 +93,47 @@ const MAP_RANGES: MapRange[] = [ { range: { leftUp: { x: 0, y: 0 }, - rightDown: { x: 180, y: 140 }, + rightDown: { x: 360, y: 140 }, }, id: "keiohachioji", name: "京王八王子付近", }, { range: { - leftUp: { x: 120, y: 0 }, - rightDown: { x: 360, y: 140 }, + leftUp: { x: 0, y: 200 }, + rightDown: { x: 360, y: 350 }, }, id: "kitano", - name: "北野付近", + name: "橋本付近", }, { range: { - leftUp: { x: 360, y: 0 }, - rightDown: { x: 620, y: 180 }, + leftUp: { x: 200, y: 300 }, + rightDown: { x: 620, y: 600 }, }, id: "chofu", name: "調布付近", }, { range: { - leftUp: { x: 620, y: 0 }, - rightDown: { x: 800, y: 140 }, + leftUp: { x: 800, y: 200 }, + rightDown: { x: 1200, y: 540 }, }, id: "meidaimae", - name: "明大前付近", + name: "桜上水付近", }, { range: { - leftUp: { x: 780, y: 0 }, + leftUp: { x: 500, y: 0 }, rightDown: { x: 1020, y: 140 }, }, id: "sasazuka", - name: "笹塚付近", - }, - { - range: { - leftUp: { x: 780, y: 0 }, - rightDown: { x: 1020, y: 140 }, - }, - id: "shinjuku", name: "新宿付近", }, - { - range: { - leftUp: { x: 100, y: 100 }, - rightDown: { x: 200, y: 280 }, - }, - id: "takao", - name: "高尾付近", - }, - { - range: { - leftUp: { x: 100, y: 300 }, - rightDown: { x: 200, y: 440 }, - }, - id: "takaosanguchi", - name: "高尾山口付近", - }, - { - range: { - leftUp: { x: 300, y: 140 }, - rightDown: { x: 400, y: 340 }, - }, - id: "wakabadai", - name: "若葉台付近", - }, - { - range: { - leftUp: { x: 300, y: 320 }, - rightDown: { x: 400, y: 440 }, - }, - id: "hashimoto", - name: "橋本付近", - }, - { - range: { - leftUp: { x: 920, y: 140 }, - rightDown: { x: 1020, y: 260 }, - }, - id: "kudanshita", - name: "九段下付近", - }, - { - range: { - leftUp: { x: 860, y: 260 }, - rightDown: { x: 1020, y: 500 }, - }, - id: "iwamotocho", - name: "岩本町付近", - }, - { - range: { - leftUp: { x: 920, y: 500 }, - rightDown: { x: 1020, y: 620 }, - }, - id: "motoyawata", - name: "本八幡付近", - }, ] const RailroadMap: FC = ({ - datas: { stop, switchState, train1 }, + datas: { stop, switchState, train1, blockState }, onStopPointOrSwitchPointClick, }) => { const [mapRange, setMapRange] = useState(MAP_RANGES[0]) @@ -278,411 +147,220 @@ const RailroadMap: FC = ({ > - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + {STOP_PONINTS.map(({ position, id }) => ( diff --git a/frontend/site/components/VideoCast.tsx b/frontend/site/components/VideoCast.tsx index 2ee17d6d..e5596abf 100644 --- a/frontend/site/components/VideoCast.tsx +++ b/frontend/site/components/VideoCast.tsx @@ -15,45 +15,54 @@ interface Prop { roomIds: string[] styles: CSSProperties[] } -const SW_WSURL = "wss://webrtc.chofufes2022.ueckoken.club/" + const SKYWAY_APIKEY = process.env.SKYWAY_APIKEY === undefined ? "2eb379e0-0374-4e3c-9674-d7415b0b7f27" : process.env.SKYWAY_APIKEY const SKYWAY_DEBUG_LEVEL = 2 -const skyWayPeer: Peer = new Peer({ - key: SKYWAY_APIKEY, - debug: SKYWAY_DEBUG_LEVEL, -}) - const VideoCast: FC = ({ roomIds, styles }) => { const [isPeerAvailable, setIsPeerAvailable] = useState(false) + const skyWayPeer = useRef() useEffect(() => { - skyWayPeer?.on("open", (id) => { - console.log(`opened skyway peer id:${id}`) - setIsPeerAvailable(true) + skyWayPeer.current = new Peer({ + key: SKYWAY_APIKEY, + debug: SKYWAY_DEBUG_LEVEL, }) - skyWayPeer?.on("close", () => { - console.log("closed skyway peer") + function onPeerOpen(id: string) { + console.log(`opened skyway peer id: ${id}`) + setIsPeerAvailable(true) + } + function onPeerClose() { + console.log(`closed skyway peer id: ${skyWayPeer.current?.id}`) setIsPeerAvailable(false) - }) + } + skyWayPeer.current.on("open", onPeerOpen) + skyWayPeer.current.on("close", onPeerClose) return () => { - skyWayPeer?.destroy() - setIsPeerAvailable(false) + console.log("clean up skyway peer") + if (skyWayPeer.current === undefined) { + return + } + skyWayPeer.current.off("open", onPeerOpen) + skyWayPeer.current.off("close", onPeerClose) + skyWayPeer.current.destroy() + skyWayPeer.current = undefined } - }, []) + }, [setIsPeerAvailable]) return ( {roomIds.map((roomId, index) => { - if (skyWayPeer === undefined || !isPeerAvailable) { + console.log("skyway peer", skyWayPeer.current) + if (!skyWayPeer.current || !isPeerAvailable) { return

Peer not available

} return ( @@ -75,6 +84,8 @@ const RoomViewer: FC = ({ roomId, peer, style }) => { useEffect(() => { console.log("joinroom ", roomId) + console.log("peerinfo", peer) + while (!peer.open) {} const skywayRoom = peer.joinRoom(roomId, { mode: "sfu", }) diff --git a/frontend/site/components/svgParts/Rail.tsx b/frontend/site/components/svgParts/Rail.tsx index bbe624e0..ed9112e3 100644 --- a/frontend/site/components/svgParts/Rail.tsx +++ b/frontend/site/components/svgParts/Rail.tsx @@ -4,9 +4,10 @@ import { Point, TrainData } from "../../types/svgPartsTypes" interface Props { positions: [Point, Point, ...Point[]] trains: TrainData[] + isClosed: boolean } -const Rail: FC = ({ positions, trains }) => { +const Rail: FC = ({ positions, trains, isClosed }) => { const pointsText = positions .map((point: Point) => `${point.x}, ${point.y}`) .join("\n") @@ -14,7 +15,8 @@ const Rail: FC = ({ positions, trains }) => { diff --git a/frontend/site/next.config.js b/frontend/site/next.config.js index 8b61df4e..3a4b6577 100644 --- a/frontend/site/next.config.js +++ b/frontend/site/next.config.js @@ -1,4 +1,4 @@ /** @type {import('next').NextConfig} */ module.exports = { - reactStrictMode: true, + reactStrictMode: false, } diff --git a/frontend/site/package.json b/frontend/site/package.json index a6138dfb..87478299 100644 --- a/frontend/site/package.json +++ b/frontend/site/package.json @@ -26,6 +26,6 @@ "eslint-config-next": "12.3.3", "eslint-config-prettier": "8.5.0", "prettier": "2.7.1", - "typescript": "4.9.3" + "typescript": "4.8.4" } } diff --git a/frontend/site/pages/index.tsx b/frontend/site/pages/index.tsx index 1facf082..d126aefa 100644 --- a/frontend/site/pages/index.tsx +++ b/frontend/site/pages/index.tsx @@ -5,6 +5,7 @@ import RailroadMap from "../components/RailRoadMap" import VideoCast from "../components/VideoCast" import { useEffect, useRef, useState } from "react" import { + BlocklId, bunkiRailId, BunkiRailId, Message, @@ -13,120 +14,54 @@ import { StopRailId, stopRailId, } from "../types/control-messages" -import SpeedMeter from "../components/svgParts/SpeedMeter" -import { SpeedMessage, TrainId } from "../types/speed-messages" -import ReverseHandle from "../components/svgParts/ReverseHandle" // OFF: false, ON: trueと対応 type StopPointState = Record const INITIAL_STOP_POINT_STATE: StopPointState = { - motoyawata_s1: false, - motoyawata_s2: false, - iwamotocho_s1: false, - iwamotocho_s2: false, - iwamotocho_s4: false, - kudanshita_s5: false, - kudanshita_s6: false, - sasazuka_s1: false, - sasazuka_s2: false, - sasazuka_s3: false, - sasazuka_s4: false, - sasazuka_s5: false, - meidaimae_s1: false, - meidaimae_s2: false, + shinjuku_s1: false, + shinjuku_s2: false, + sakurajosui_s0: false, + sakurajosui_s1: false, + sakurajosui_s2: false, + sakurajosui_s3: false, + sakurajosui_s4: false, + sakurajosui_s5: false, + chofu_s0: false, chofu_s1: false, chofu_s2: false, chofu_s3: false, chofu_s4: false, - chofu_s5: false, - chofu_s6: false, - kitano_s1: false, - kitano_s2: false, - kitano_s3: false, - kitano_s4: false, - kitano_s5: false, - kitano_s6: false, - kitano_s7: false, - takao_s1: false, - takao_s2: false, + hachioji_s1: false, + hachioji_s2: false, + hashimoto_s1: false, + hashimoto_s2: false, } -type SwitchPointState = Record -const INITIAL_SWITCH_POINT_STATE: SwitchPointState = { - iwamotocho_b1: false, - iwamotocho_b2: false, - iwamotocho_b3: false, - iwamotocho_b4: false, - sasazuka_b1: false, - sasazuka_b2: false, +type BlockState = Record +const INITIAL_BLOCK_STATE: BlockState = { + shinjuku_b1: false, + shinjuku_b2: false, + sakurajosui_b1: false, + sakurajosui_b2: false, + sakurajosui_b3: false, + sakurajosui_b4: false, + sakurajosui_b5: false, + sakurajosui_b6: false, chofu_b1: false, chofu_b2: false, chofu_b3: false, chofu_b4: false, chofu_b5: false, - kitano_b1: false, - kitano_b2: false, - kitano_b3: false, -} - -type SpeedState = Record -const INITIAL_SPEED_STATE: SpeedState = { - TAKAO: 0, - CHICHIBU: 0, - HAKONE: 0, - OKUTAMA: 0, - NIKKO: 0, - ENOSHIMA: 0, - KAMAKURA: 0, - YOKOSUKA: 0, + hashimoto_b1: false, + hashimoto_b2: false, + hachioji_b1: false, + hachioji_b2: false, } -const INITIAL_SELECTED_TRAIN_ID: TrainId = "TAKAO" -const stationIdAndTextMap: Record = { - motoyawata_s1: "本八幡1番線", - motoyawata_s2: "本八幡2番線", - iwamotocho_s1: "岩本町1番線", - iwamotocho_s2: "岩本町2, 3番線", - iwamotocho_s4: "岩本町4番線", - kudanshita_s5: "九段下1番線", - kudanshita_s6: "九段下2番線", - sasazuka_s1: "笹塚1番線", - sasazuka_s2: "笹塚2番線", - sasazuka_s3: "笹塚3番線", - sasazuka_s4: "笹塚4番線", - sasazuka_s5: "笹塚新線", - meidaimae_s1: "明大前1番線", - meidaimae_s2: "明大前2番線", - chofu_s1: "調布1番線", - chofu_s2: "調布2番線", - chofu_s3: "調布3番線", - chofu_s4: "調布4番線", - chofu_s5: "調布-若葉台", - chofu_s6: "unknown", - kitano_s1: "北野1番線", - kitano_s2: "北野2番線", - kitano_s3: "北野3番線", - kitano_s4: "北野4番線", - kitano_s5: "北野-高尾", - kitano_s6: "北野-京王八王子", - kitano_s7: "unknown", - takao_s1: "高尾", - takao_s2: "高尾山口", - iwamotocho_b1: "岩本町1-2,3番線分岐", - iwamotocho_b2: "unknown", - iwamotocho_b3: "unknown", - iwamotocho_b4: "岩本町2,3-4番線分岐", - sasazuka_b1: "笹塚新線-明大前分岐", - sasazuka_b2: "笹塚3-4番線分岐", - chofu_b1: "調布1-2番線分岐", - chofu_b2: "調布2番線若葉台-北野分岐", - chofu_b3: "若葉台-北野分岐", - chofu_b4: "調布3-4番線分岐2", - chofu_b5: "調布3-4番線分岐1", - kitano_b1: "北野-高尾分岐", - kitano_b2: "北野3-4番線分岐", - kitano_b3: "unknown", - unknown: "unknown", +type SwitchPointState = Record +const INITIAL_SWITCH_POINT_STATE: SwitchPointState = { + chofu_p1: false, + sakurajosui_p1: false, } const Home: NextPage = () => { @@ -137,17 +72,14 @@ const Home: NextPage = () => { const [switchPointState, setSwitchPointState] = useState( INITIAL_SWITCH_POINT_STATE ) + useEffect(() => { + setSwitchPointState(INITIAL_SWITCH_POINT_STATE) + }) + const [blockState, setBlockState] = useState(INITIAL_BLOCK_STATE) const [selectedStationId, setSelectedStationId] = useState("unknown") const [trainPosition1, setTrainPosition1] = useState(0.4) - const speedWs = useRef() - const [speedState, setSpeedState] = useState(INITIAL_SPEED_STATE) - const [selectedTrainId, setSelectedTrainId] = useState( - INITIAL_SELECTED_TRAIN_ID - ) - const [isBack, setIsBack] = useState(false) - const [roomIds, setRoomIds] = useState(["chofu", "train"]) const changeStopPointOrSwtichPointState = ( @@ -173,33 +105,6 @@ const Home: NextPage = () => { changeStopPointOrSwtichPointState(stationId, nextState) } - useEffect(() => { - const ws = new WebSocket("wss://speed.chofufes2022.ueckoken.club/speed") - speedWs.current = ws - ws.addEventListener("open", (e) => { - console.log("opened") - }) - ws.addEventListener("message", (e) => { - const message: SpeedMessage = JSON.parse(e.data) - console.log(message) - setSpeedState((previousState) => ({ - ...previousState, - [message.train_name]: message.speed, - })) - }) - ws.addEventListener("error", (e) => { - console.log("error occured") - console.log(e) - }) - ws.addEventListener("close", (e) => { - console.log("closed") - console.log(e) - }) - return () => { - ws.close() - } - }, []) - useEffect(() => { const ws = new WebSocket("wss://control.chofufes2022.ueckoken.club/ws") stationWs.current = ws @@ -253,15 +158,13 @@ const Home: NextPage = () => { return (
- 工研×鉄研プラレール展示 操作ページ + 工研×鉄研プラレール展示 管理画面
-

- 工研×鉄研プラレール展示 操作ページ -

+

工研×鉄研プラレール展示 管理画面

@@ -295,49 +198,42 @@ const Home: NextPage = () => {
- -

- - - - { - setIsBack(nextIsBack) - }} - /> - - { - const a = isBack ? -1 : 1 // 前進なら1、逆進なら-1になる係数 - const message: SpeedMessage = { - train_name: selectedTrainId, - speed: a * Number.parseInt(e.target.value), - } - speedWs.current?.send(JSON.stringify(message)) - }} - /> -
@@ -418,7 +265,7 @@ const Home: NextPage = () => { target="_blank" rel="noopener noreferrer" > - ©2021 電気通信大学工学研究部 + ©2022 電気通信大学工学研究部
diff --git a/frontend/site/types/control-messages.ts b/frontend/site/types/control-messages.ts index 927c225d..66ceb798 100644 --- a/frontend/site/types/control-messages.ts +++ b/frontend/site/types/control-messages.ts @@ -2,57 +2,55 @@ import * as t from "io-ts" // https://github.com/ueckoken/plarail2021-soft/blob/a3982c4ef4b20e371052b4ad36b777a04ed67d1a/backend/proto/statesync.proto#L28-L85 // 無限 user-defined type guard イヤイヤ期なので io-ts に頼る + export const unknownId = t.literal("unknown") export const stopRailId = t.union([ - t.literal("motoyawata_s1"), - t.literal("motoyawata_s2"), - t.literal("iwamotocho_s1"), - t.literal("iwamotocho_s2"), - t.literal("iwamotocho_s4"), - t.literal("kudanshita_s5"), - t.literal("kudanshita_s6"), - t.literal("sasazuka_s1"), - t.literal("sasazuka_s2"), - t.literal("sasazuka_s3"), - t.literal("sasazuka_s4"), - t.literal("sasazuka_s5"), - t.literal("meidaimae_s1"), - t.literal("meidaimae_s2"), + t.literal("shinjuku_s1"), + t.literal("shinjuku_s2"), + t.literal("sakurajosui_s0"), + t.literal("sakurajosui_s1"), + t.literal("sakurajosui_s2"), + t.literal("sakurajosui_s3"), + t.literal("sakurajosui_s4"), + t.literal("sakurajosui_s5"), + t.literal("chofu_s0"), t.literal("chofu_s1"), t.literal("chofu_s2"), t.literal("chofu_s3"), t.literal("chofu_s4"), - t.literal("chofu_s5"), - t.literal("chofu_s6"), - t.literal("kitano_s1"), - t.literal("kitano_s2"), - t.literal("kitano_s3"), - t.literal("kitano_s4"), - t.literal("kitano_s5"), - t.literal("kitano_s6"), - t.literal("kitano_s7"), - t.literal("takao_s1"), - t.literal("takao_s2"), + t.literal("hashimoto_s1"), + t.literal("hashimoto_s2"), + t.literal("hachioji_s1"), + t.literal("hachioji_s2"), ]) export type StopRailId = t.TypeOf export const bunkiRailId = t.union([ - t.literal("iwamotocho_b1"), - t.literal("iwamotocho_b2"), - t.literal("iwamotocho_b3"), - t.literal("iwamotocho_b4"), - t.literal("sasazuka_b1"), - t.literal("sasazuka_b2"), + t.literal("sakurajosui_p1"), + t.literal("chofu_p1"), +]) +export type BunkiRailId = t.TypeOf + +export const blockId = t.union([ + t.literal("shinjuku_b1"), + t.literal("shinjuku_b2"), + t.literal("sakurajosui_b1"), + t.literal("sakurajosui_b2"), + t.literal("sakurajosui_b3"), + t.literal("sakurajosui_b4"), + t.literal("sakurajosui_b5"), + t.literal("sakurajosui_b6"), t.literal("chofu_b1"), t.literal("chofu_b2"), t.literal("chofu_b3"), t.literal("chofu_b4"), t.literal("chofu_b5"), - t.literal("kitano_b1"), - t.literal("kitano_b2"), - t.literal("kitano_b3"), + t.literal("hashimoto_b1"), + t.literal("hashimoto_b2"), + t.literal("hachioji_b1"), + t.literal("hachioji_b2"), ]) -export type BunkiRailId = t.TypeOf +export type BlocklId = t.TypeOf export const stationId = t.union([unknownId, stopRailId, bunkiRailId]) export type StationId = t.TypeOf diff --git a/frontend/site/yarn.lock b/frontend/site/yarn.lock index 4a0cc06e..8cc9f8b4 100644 --- a/frontend/site/yarn.lock +++ b/frontend/site/yarn.lock @@ -2310,10 +2310,10 @@ type-fest@^0.20.2: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ== -typescript@4.9.3: - version "4.9.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db" - integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA== +typescript@4.8.4: + version "4.8.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" + integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== unbox-primitive@^1.0.1: version "1.0.1" diff --git a/hardware/esp32_camera_mjpeg/LICENSE.txt b/hardware/esp32-cam-mjpeg/LICENSE.txt similarity index 100% rename from hardware/esp32_camera_mjpeg/LICENSE.txt rename to hardware/esp32-cam-mjpeg/LICENSE.txt diff --git a/hardware/esp32_camera_mjpeg/OV2640.cpp b/hardware/esp32-cam-mjpeg/OV2640.cpp similarity index 100% rename from hardware/esp32_camera_mjpeg/OV2640.cpp rename to hardware/esp32-cam-mjpeg/OV2640.cpp diff --git a/hardware/esp32_camera_mjpeg/OV2640.h b/hardware/esp32-cam-mjpeg/OV2640.h similarity index 100% rename from hardware/esp32_camera_mjpeg/OV2640.h rename to hardware/esp32-cam-mjpeg/OV2640.h diff --git a/hardware/esp32_camera_mjpeg/camera_pins.h b/hardware/esp32-cam-mjpeg/camera_pins.h similarity index 100% rename from hardware/esp32_camera_mjpeg/camera_pins.h rename to hardware/esp32-cam-mjpeg/camera_pins.h diff --git a/hardware/esp32_camera_mjpeg/esp32_camera_mjpeg.ino b/hardware/esp32-cam-mjpeg/esp32_camera_mjpeg.ino similarity index 86% rename from hardware/esp32_camera_mjpeg/esp32_camera_mjpeg.ino rename to hardware/esp32-cam-mjpeg/esp32_camera_mjpeg.ino index 722e57ca..4d5a86d8 100644 --- a/hardware/esp32_camera_mjpeg/esp32_camera_mjpeg.ino +++ b/hardware/esp32-cam-mjpeg/esp32_camera_mjpeg.ino @@ -17,14 +17,16 @@ #include // Select camera model -// #define CAMERA_MODEL_WROVER_KIT +//#define CAMERA_MODEL_WROVER_KIT #define CAMERA_MODEL_ESP_EYE -// #define CAMERA_MODEL_M5STACK_PSRAM -// #define CAMERA_MODEL_M5STACK_WIDE -// #define CAMERA_MODEL_AI_THINKER +//#define CAMERA_MODEL_M5STACK_PSRAM +//#define CAMERA_MODEL_M5STACK_WIDE +//#define CAMERA_MODEL_AI_THINKER #include "camera_pins.h" +// #define SSID1 "takumi-kentaro" +// #define PWD1 "k0Ken-11235" #define SSID1 "" #define PWD1 "" @@ -32,8 +34,8 @@ OV2640 cam; WebServer server(80); -const char HEADER[] = "HTTP/1.1 200 OK\r\n" - "Access-Control-Allow-Origin: *\r\n" +const char HEADER[] = "HTTP/1.1 200 OK\r\n" \ + "Access-Control-Allow-Origin: *\r\n" \ "Content-Type: multipart/x-mixed-replace; boundary=123456789000000000000987654321\r\n"; const char BOUNDARY[] = "\r\n--123456789000000000000987654321\r\n"; const char CTNTTYPE[] = "Content-Type: image/jpeg\r\nContent-Length: "; @@ -53,20 +55,19 @@ void handle_jpg_stream(void) while (true) { - if (!client.connected()) - break; + if (!client.connected()) break; cam.run(); s = cam.getSize(); client.write(CTNTTYPE, cntLen); - sprintf(buf, "%d\r\n\r\n", s); + sprintf( buf, "%d\r\n\r\n", s ); client.write(buf, strlen(buf)); client.write((char *)cam.getfb(), s); client.write(BOUNDARY, bdrLen); } } -const char JHEADER[] = "HTTP/1.1 200 OK\r\n" - "Content-disposition: inline; filename=capture.jpg\r\n" +const char JHEADER[] = "HTTP/1.1 200 OK\r\n" \ + "Content-disposition: inline; filename=capture.jpg\r\n" \ "Content-type: image/jpeg\r\n\r\n"; const int jhdLen = strlen(JHEADER); @@ -74,8 +75,7 @@ void handle_jpg(void) { WiFiClient client = server.client(); - if (!client.connected()) - return; + if (!client.connected()) return; cam.run(); client.write(JHEADER, jhdLen); client.write((char *)cam.getfb(), cam.getSize()); @@ -98,7 +98,7 @@ void setup() { Serial.begin(115200); - // while (!Serial); //wait for serial connection. + //while (!Serial); //wait for serial connection. camera_config_t config; config.ledc_channel = LEDC_CHANNEL_0; diff --git a/hardware/plarail_detection/Hallsensor.hpp b/hardware/plarail_detection/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-chofu/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-chofu/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-chofu/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-chofu/hallsensor-chofu.ino b/hardware/plarail_detection/hallsensor-chofu/hallsensor-chofu.ino new file mode 100644 index 00000000..5fb5c7d4 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-chofu/hallsensor-chofu.ino @@ -0,0 +1,89 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station chofu[5]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&chofu[0], 34, chofu_d1); + setupStation(&chofu[1], 35, chofu_d2); + setupStation(&chofu[2], 32, chofu_d3); + setupStation(&chofu[3], 33, chofu_d4); + setupStation(&chofu[4], 25, chofu_d5); +} + +void loop() { + for (int i = 0; i < 5; i++) { + detect(&chofu[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/hallsensor-hachioji/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-hachioji/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-hachioji/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-hachioji/hallsensor-hachioji.ino b/hardware/plarail_detection/hallsensor-hachioji/hallsensor-hachioji.ino new file mode 100644 index 00000000..7d51b139 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-hachioji/hallsensor-hachioji.ino @@ -0,0 +1,86 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station hachioji[2]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&hachioji[0], 34, hachioji_d1); + setupStation(&hachioji[1], 35, hachioji_d2); +} + +void loop() { + for (int i = 0; i < 2; i++) { + detect(&hachioji[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/hallsensor-hashimoto/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-hashimoto/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-hashimoto/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-hashimoto/hallsensor-hashimoto.ino b/hardware/plarail_detection/hallsensor-hashimoto/hallsensor-hashimoto.ino new file mode 100644 index 00000000..a0a6238e --- /dev/null +++ b/hardware/plarail_detection/hallsensor-hashimoto/hallsensor-hashimoto.ino @@ -0,0 +1,86 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station hashimoto[2]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&hashimoto[0], 34, hashimoto_d1); + setupStation(&hashimoto[1], 35, hashimoto_d2); +} + +void loop() { + for (int i = 0; i < 2; i++) { + detect(&hashimoto[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/hallsensor-sakurajosui/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-sakurajosui/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-sakurajosui/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-sakurajosui/hallsensor-sakurajosui.ino b/hardware/plarail_detection/hallsensor-sakurajosui/hallsensor-sakurajosui.ino new file mode 100644 index 00000000..838d7160 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-sakurajosui/hallsensor-sakurajosui.ino @@ -0,0 +1,90 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station sakurajosui[6]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&sakurajosui[0], 34, sakurajosui_d1); + setupStation(&sakurajosui[1], 35, sakurajosui_d2); + setupStation(&sakurajosui[2], 32, sakurajosui_d3); + setupStation(&sakurajosui[3], 33, sakurajosui_d4); + setupStation(&sakurajosui[4], 25, sakurajosui_d5); + setupStation(&sakurajosui[5], 26, sakurajosui_d6); +} + +void loop() { + for (int i = 0; i < 6; i++) { + detect(&sakurajosui[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/hallsensor-shinjuku/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-shinjuku/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-shinjuku/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-shinjuku/hallsensor-shinjuku.ino b/hardware/plarail_detection/hallsensor-shinjuku/hallsensor-shinjuku.ino new file mode 100644 index 00000000..b2da593c --- /dev/null +++ b/hardware/plarail_detection/hallsensor-shinjuku/hallsensor-shinjuku.ino @@ -0,0 +1,86 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station shinjuku[2]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&shinjuku[0], 34, shinjuku_d1); + setupStation(&shinjuku[1], 35, shinjuku_d2); +} + +void loop() { + for (int i = 0; i < 2; i++) { + detect(&shinjuku[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/hallsensor-testver-mul/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-testver-mul/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-testver-mul/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-testver-mul/hallsensor-testver-mul.ino b/hardware/plarail_detection/hallsensor-testver-mul/hallsensor-testver-mul.ino new file mode 100644 index 00000000..5fb5c7d4 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-testver-mul/hallsensor-testver-mul.ino @@ -0,0 +1,89 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station chofu[5]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&chofu[0], 34, chofu_d1); + setupStation(&chofu[1], 35, chofu_d2); + setupStation(&chofu[2], 32, chofu_d3); + setupStation(&chofu[3], 33, chofu_d4); + setupStation(&chofu[4], 25, chofu_d5); +} + +void loop() { + for (int i = 0; i < 5; i++) { + detect(&chofu[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/hallsensor-testver.ino b/hardware/plarail_detection/hallsensor-testver.ino deleted file mode 100755 index c7ef6633..00000000 --- a/hardware/plarail_detection/hallsensor-testver.ino +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include -#define LED_PIN 13 -#define HL_PIN 27 - -const char* ssid = ""; -const char* password = ""; - -StaticJsonDocument doc; -char json_string[255]; - -void setupjson(){ - doc["Sensor"] = 1; - - serializeJson(doc, json_string, sizeof(json_string)); -} - -HTTPClient http; - -void setup() { - Serial.begin(115200); - WiFi.begin(ssid, password); - setupjson(); - pinMode(LED_PIN, OUTPUT); - pinMode(HL_PIN, INPUT); - http.begin("http://localhost:8080/sensor"); - http.addHeader("Content-Type", "application/json"); -} - -int state = 1; -unsigned long prevtime = 0; - -void loop() { - if(digitalRead(HL_PIN) == HIGH){ - digitalWrite(LED_PIN, HIGH); - if(state == 0 && millis() - prevtime > 3000) { - int ttl = 5; - int status_code = http.POST((uint8_t *)json_string, strlen(json_string)); - while (status_code == -2 && ttl > 0){ - status_code = http.POST((uint8_t *)json_string, strlen(json_string)); - ttl--; - } - if (status_code == 200){ - prevtime = millis(); - Serial.println("[POST]Send to server"); - } - else{ - Serial.println(status_code); - Serial.println("[POST]failed to send to server"); - } - } - state = 1; - } else { - digitalWrite(LED_PIN, LOW); - if(state == 1 && millis() - prevtime > 3000) { - int ttl = 5; - int status_code = http.POST((uint8_t *)json_string, strlen(json_string)); - while (status_code == -2 && ttl > 0){ - status_code = http.POST((uint8_t *)json_string, strlen(json_string)); - ttl--; - } - if (status_code == 200){ - prevtime = millis(); - Serial.println("[POST]Send to server"); - } - else{ - Serial.println(status_code); - Serial.println("[POST]failed to send to server"); - } - } - state = 0; - } -} diff --git a/hardware/plarail_detection/hallsensor-testver/Hallsensor.hpp b/hardware/plarail_detection/hallsensor-testver/Hallsensor.hpp new file mode 100644 index 00000000..69147179 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-testver/Hallsensor.hpp @@ -0,0 +1,30 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +#endif diff --git a/hardware/plarail_detection/hallsensor-testver/hallsensor-testver.ino b/hardware/plarail_detection/hallsensor-testver/hallsensor-testver.ino new file mode 100644 index 00000000..5fb5c7d4 --- /dev/null +++ b/hardware/plarail_detection/hallsensor-testver/hallsensor-testver.ino @@ -0,0 +1,89 @@ +#include +#include +#include +#include "Hallsensor.hpp" + +struct Station { + int pin; + int state; + unsigned long prevtime; + char jsonString[255]; +}; + +struct Station chofu[5]; + +const char* ssid = ""; +const char* password = ""; + +HTTPClient http; + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} + + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); + + setupStation(&chofu[0], 34, chofu_d1); + setupStation(&chofu[1], 35, chofu_d2); + setupStation(&chofu[2], 32, chofu_d3); + setupStation(&chofu[3], 33, chofu_d4); + setupStation(&chofu[4], 25, chofu_d5); +} + +void loop() { + for (int i = 0; i < 5; i++) { + detect(&chofu[i]); + } +} + + + +StaticJsonDocument doc; + +void setupStation(struct Station *s, const int p, enum SensorName d){ + s->pin = p; + pinMode(s->pin, INPUT); + s->state = 1; + s->prevtime = 0; + doc["Sensor"] = d; + serializeJson(doc, s->jsonString, sizeof(s->jsonString)); +} + +void sendPost(struct Station *s) { + int ttl = 5; + int status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + while (status_code == -2 && ttl > 0){ + status_code = http.POST((uint8_t *)s->jsonString, strlen(s->jsonString)); + ttl--; + } + if (status_code == 200){ + s->prevtime = millis(); + Serial.println("[POST]Send to server"); + Serial.println(http.getString()); + } + else{ + Serial.println(status_code); + Serial.println("[POST]failed to send to server"); + } +} + +void detect(struct Station *s) { + if(digitalRead(s->pin) == HIGH){ + if(s->state == 0 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 1; + } else { + if(s->state == 1 && millis() - s->prevtime > 3000) { + sendPost(s); + } + s->state = 0; + } +} diff --git a/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/Hallsensor.cpp b/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/Hallsensor.cpp new file mode 100644 index 00000000..5cd85076 --- /dev/null +++ b/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/Hallsensor.cpp @@ -0,0 +1,48 @@ +#include +#include +#include "Hallsensor.hpp" + +HTTPClient http; + +Hallsensor::Hallsensor(enum SensorName s, int h) { + sen = s; + hpin = h; + pinMode(hpin, INPUT); + doc["Sensor"] = sen; + serializeJson(doc, json_string, sizeof(json_string)); + http.begin("http://:8081/sensor"); + http.addHeader("Content-Type", "application/json"); +} + +void Hallsensor::postJson() { + ttl = 5; + status_code = http.POST((uint8_t *)json_string, strlen(json_string)); + while (status_code == -2 && ttl > 0) { + status_code = http.POST((uint8_t *)json_string, strlen(json_string)); + ttl--; + } + if (status_code == 200){ + prevtime = millis(); + Serial.println("[POST]Send to server"); + } + else{ + Serial.println(status_code); + Serial.println(http.errorToString(status_code)); + Serial.println("[POST]failed to send to server"); + Serial.println(json_string); + } +} + +void Hallsensor::detect() { + if(digitalRead(hpin) == HIGH) { + if( state == 0 && millis() - prevtime > 3000 ) { + postJson(); + } + state = 1; + } else { + if(state == 1 && millis() - prevtime > 3000) { + postJson(); + } + state = 0; + } +} diff --git a/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/Hallsensor.hpp b/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/Hallsensor.hpp new file mode 100644 index 00000000..29f0feff --- /dev/null +++ b/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/Hallsensor.hpp @@ -0,0 +1,48 @@ +#ifndef Hallsensor_H +#define Hallsensor_H + + +enum SensorName { + unknown = 0, + + shinjuku_d1 = 1, + shinjuku_d2 = 2, + + sakurajosui_d1 = 11, + sakurajosui_d2 = 12, + sakurajosui_d3 = 13, + sakurajosui_d4 = 14, + sakurajosui_d5 = 15, + sakurajosui_d6 = 16, + + chofu_d1 = 21, + chofu_d2 = 22, + chofu_d3 = 23, + chofu_d4 = 24, + chofu_d5 = 25, + + hashimoto_d1 = 31, + hashimoto_d2 = 32, + + hachioji_d1 = 41, + hachioji_d2 = 42, +}; + +// クラスの定義 +class Hallsensor +{ +public: + Hallsensor(enum SensorName s, int h); + enum SensorName sen; + int hpin; + StaticJsonDocument doc; + char json_string[255]; + void detect(); + void postJson(); + int ttl; + int state = 1; + unsigned long prevtime = 0; + int status_code = 0; +}; + +#endif diff --git a/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/hallsensor-chofu.ino b/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/hallsensor-chofu.ino new file mode 100644 index 00000000..8e19c87a --- /dev/null +++ b/hardware/plarail_detection/notWorkingCode/hallsensor-chofu/hallsensor-chofu.ino @@ -0,0 +1,32 @@ +#include +#include +#include "Hallsensor.hpp" + +const char* ssid = ""; +const char* password = ""; + +WiFiServer server(80); + +void setup() { + Serial.begin(115200); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.println("connecting"); + } + if (WiFi.status() == WL_CONNECTED) { Serial.println("conected");} +} + +Hallsensor chofu_1 = Hallsensor(chofu_d1, 34); +Hallsensor chofu_2 = Hallsensor(chofu_d2, 35); +Hallsensor chofu_3 = Hallsensor(chofu_d3, 32); +Hallsensor chofu_4 = Hallsensor(chofu_d4, 33); +Hallsensor chofu_5 = Hallsensor(chofu_d5, 25); + +void loop() { + chofu_1.detect(); + chofu_2.detect(); + chofu_3.detect(); + chofu_4.detect(); + chofu_5.detect(); +} diff --git a/infra/logviewer/main.go b/infra/logviewer/main.go index df099ab7..950083ba 100644 --- a/infra/logviewer/main.go +++ b/infra/logviewer/main.go @@ -15,17 +15,8 @@ type logHandler struct { logviewer client.LogViewer } -var allowedAppName = []string{ - "soft-frontend", "soft-backend-external", -} - func isAllowed(appname string) bool { - for _, a := range allowedAppName { - if a == appname { - return true - } - } - return false + return true } func (l logHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { diff --git a/manifests/imageautomation/auto-operation/imagepolicy.yaml b/manifests/imageautomation/auto-operation/imagepolicy.yaml new file mode 100644 index 00000000..d41f8721 --- /dev/null +++ b/manifests/imageautomation/auto-operation/imagepolicy.yaml @@ -0,0 +1,14 @@ +apiVersion: image.toolkit.fluxcd.io/v1beta1 +kind: ImagePolicy +metadata: + name: auto-operation + namespace: plarail2021 +spec: + imageRepositoryRef: + name: auto-operation + filterTags: + pattern: '[a-f0-9]+-(?P[0-9]+)' + extract: '$ts' + policy: + numerical: + order: asc diff --git a/manifests/imageautomation/auto-operation/kustomization.yaml b/manifests/imageautomation/auto-operation/kustomization.yaml new file mode 100644 index 00000000..473a6b48 --- /dev/null +++ b/manifests/imageautomation/auto-operation/kustomization.yaml @@ -0,0 +1,3 @@ +resources: + - ./repository.yaml + - ./imagepolicy.yaml diff --git a/manifests/imageautomation/auto-operation/repository.yaml b/manifests/imageautomation/auto-operation/repository.yaml new file mode 100644 index 00000000..1554b014 --- /dev/null +++ b/manifests/imageautomation/auto-operation/repository.yaml @@ -0,0 +1,8 @@ +apiVersion: image.toolkit.fluxcd.io/v1beta1 +kind: ImageRepository +metadata: + name: auto-operation + namespace: plarail2021 +spec: + image: ghcr.io/ueckoken/plarail2022-auto-operation + interval: 1m0s diff --git a/manifests/imageautomation/internal/imagepolicy.yaml b/manifests/imageautomation/internal/imagepolicy.yaml new file mode 100644 index 00000000..b8ea900b --- /dev/null +++ b/manifests/imageautomation/internal/imagepolicy.yaml @@ -0,0 +1,14 @@ +apiVersion: image.toolkit.fluxcd.io/v1beta1 +kind: ImagePolicy +metadata: + name: internal + namespace: plarail2021 +spec: + imageRepositoryRef: + name: internal + filterTags: + pattern: '[a-f0-9]+-(?P[0-9]+)' + extract: '$ts' + policy: + numerical: + order: asc diff --git a/manifests/imageautomation/internal/kustomization.yaml b/manifests/imageautomation/internal/kustomization.yaml new file mode 100644 index 00000000..473a6b48 --- /dev/null +++ b/manifests/imageautomation/internal/kustomization.yaml @@ -0,0 +1,3 @@ +resources: + - ./repository.yaml + - ./imagepolicy.yaml diff --git a/manifests/imageautomation/internal/repository.yaml b/manifests/imageautomation/internal/repository.yaml new file mode 100644 index 00000000..6801b73b --- /dev/null +++ b/manifests/imageautomation/internal/repository.yaml @@ -0,0 +1,8 @@ +apiVersion: image.toolkit.fluxcd.io/v1beta1 +kind: ImageRepository +metadata: + name: internal + namespace: plarail2021 +spec: + image: ghcr.io/ueckoken/plarail2022-internal + interval: 1m0s diff --git a/manifests/imageautomation/kustomization.yaml b/manifests/imageautomation/kustomization.yaml index 77fdaee5..277b3608 100644 --- a/manifests/imageautomation/kustomization.yaml +++ b/manifests/imageautomation/kustomization.yaml @@ -2,7 +2,10 @@ resources: - ./external - ./frontend - ./frontend-python + - ./internal - ./webrtc-sender - ./receiver - ./automation.yaml - ./positioning + - ./auto-operation + - ./logviewer diff --git a/manifests/manifests/auto-operation/deployment.yaml b/manifests/manifests/auto-operation/deployment.yaml index 601cf34a..1d1c0359 100644 --- a/manifests/manifests/auto-operation/deployment.yaml +++ b/manifests/manifests/auto-operation/deployment.yaml @@ -14,7 +14,10 @@ spec: spec: containers: - name: soft-backend-auto-operation - image: ghcr.io/ueckoken/plarail2022-auto-operation:58f9e55-1667923961 + image: ghcr.io/ueckoken/plarail2022-auto-operation:df4f652-1668679369 # {"$imagepolicy": "plarail2021:auto-operation"} imagePullPolicy: Always ports: - - containerPort: 50050 + - containerPort: 50051 + envFrom: + - configMapRef: + name: auto-operation-env diff --git a/manifests/manifests/auto-operation/service.yaml b/manifests/manifests/auto-operation/service.yaml index b21d7b5e..4c0e81bb 100644 --- a/manifests/manifests/auto-operation/service.yaml +++ b/manifests/manifests/auto-operation/service.yaml @@ -10,7 +10,7 @@ spec: selector: app: auto-operation ports: - - name: web - port: 80 + - name: grpc-for-external + port: 50051 protocol: TCP - targetPort: 50050 + targetPort: 50051 diff --git a/manifests/manifests/external/deployment.yaml b/manifests/manifests/external/deployment.yaml index 29bbe5b5..e0072735 100644 --- a/manifests/manifests/external/deployment.yaml +++ b/manifests/manifests/external/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: soft-backend-external - image: ghcr.io/ueckoken/plarail2022-external:27d82b2-1668657626 # {"$imagepolicy": "plarail2021:external"} + image: ghcr.io/ueckoken/plarail2022-external:df4f652-1668679369 # {"$imagepolicy": "plarail2021:external"} imagePullPolicy: Always ports: - containerPort: 8080 diff --git a/manifests/manifests/external/env.yaml b/manifests/manifests/external/env.yaml index 13e68dbf..22e241e2 100644 --- a/manifests/manifests/external/env.yaml +++ b/manifests/manifests/external/env.yaml @@ -6,3 +6,4 @@ metadata: data: CLIENTSIDESERVER_PORT: "8080" INTERNALSERVER_ADDR: "soft-backend-internal.plarail2021.svc.cluster.local:54321" + CLIENT_SIDE_SERVER_ATS_ADDRESS: "auto-operation.plarail2021.svc.cluster.local:50051" diff --git a/manifests/manifests/frontend-camera-sender/deployment.yaml b/manifests/manifests/frontend-camera-sender/deployment.yaml index 715ed0c7..d683113a 100644 --- a/manifests/manifests/frontend-camera-sender/deployment.yaml +++ b/manifests/manifests/frontend-camera-sender/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: soft-camera-sender - image: ghcr.io/ueckoken/plarail2022-camera_sender:27d82b2-1668657626 # FIXME + image: ghcr.io/ueckoken/plarail2022-camera_sender:df4f652-1668679369 # FIXME imagePullPolicy: Always ports: - containerPort: 8080 diff --git a/manifests/manifests/frontend/deployment.yaml b/manifests/manifests/frontend/deployment.yaml index 4b4db40f..c8dc5aef 100644 --- a/manifests/manifests/frontend/deployment.yaml +++ b/manifests/manifests/frontend/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: plarail2022-soft-frontend - image: ghcr.io/ueckoken/plarail2022-frontend:27d82b2-1668657626 # {"$imagepolicy": "plarail2021:frontend"} + image: ghcr.io/ueckoken/plarail2022-frontend:df4f652-1668679369 # {"$imagepolicy": "plarail2021:frontend"} imagePullPolicy: Always ports: - containerPort: 8080 diff --git a/manifests/manifests/internal/deployment.yaml b/manifests/manifests/internal/deployment.yaml index 1f30632f..df71cc0b 100644 --- a/manifests/manifests/internal/deployment.yaml +++ b/manifests/manifests/internal/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: soft-backend-internal - image: ghcr.io/ueckoken/plarail2022-internal:0aae7ce-1668340335 + image: ghcr.io/ueckoken/plarail2022-internal:df4f652-1668679369 # {"$imagepolicy": "plarail2021:internal"} imagePullPolicy: Always ports: - containerPort: 54321 diff --git a/manifests/manifests/internal/service.yaml b/manifests/manifests/internal/service.yaml index 613b1a14..ae70f97a 100644 --- a/manifests/manifests/internal/service.yaml +++ b/manifests/manifests/internal/service.yaml @@ -6,7 +6,7 @@ metadata: labels: app: soft-backend-internal spec: - type: ClusterIP + type: NodePort selector: app: soft-backend-internal ports: diff --git a/manifests/manifests/kustomization.yaml b/manifests/manifests/kustomization.yaml index 2829926b..008e100b 100644 --- a/manifests/manifests/kustomization.yaml +++ b/manifests/manifests/kustomization.yaml @@ -8,3 +8,4 @@ resources: - ./internal # - ./positioning - ./frontend-camera-sender + - ./auto-operation diff --git a/manifests/manifests/logviewer/deployment.yaml b/manifests/manifests/logviewer/deployment.yaml index bfd7c9a5..0ed06f4e 100644 --- a/manifests/manifests/logviewer/deployment.yaml +++ b/manifests/manifests/logviewer/deployment.yaml @@ -14,7 +14,7 @@ spec: app: logviewer spec: containers: - - image: asia-northeast1-docker.pkg.dev/gotti-dev/plarail-logviewer/logviewer-401bd39657a23ac59c9a6cfad7dfbc52@sha256:1efc8ec1469c5c12902f775489546609c99e3d4f09d8abf695c799b98d861333 + - image: ghcr.io/ueckoken/plarail2022-logviewer:df4f652-1668679369 # {"$imagepolicy": "plarail2021:logviewer"} name: logviewer ports: - containerPort: 8080 @@ -28,6 +28,6 @@ spec: cpu: 5m memory: 64Mi envFrom: - - configMapRef: - name: logviewer-env + - configMapRef: + name: logviewer-env serviceAccountName: logviewer diff --git a/manifests/manifests/positioning/deployment.yaml b/manifests/manifests/positioning/deployment.yaml index 653d65b2..c2e0d4db 100644 --- a/manifests/manifests/positioning/deployment.yaml +++ b/manifests/manifests/positioning/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: positioning - image: ghcr.io/ueckoken/plarail2022-positioning:27d82b2-1668657626 # {"$imagepolicy": "plarail2021:positioning"} + image: ghcr.io/ueckoken/plarail2022-positioning:df4f652-1668679369 # {"$imagepolicy": "plarail2021:positioning"} imagePullPolicy: Always ports: - containerPort: 8080 diff --git a/manifests/manifests/python-webrtc-server/deployment.yaml b/manifests/manifests/python-webrtc-server/deployment.yaml index 16f664c9..41395188 100644 --- a/manifests/manifests/python-webrtc-server/deployment.yaml +++ b/manifests/manifests/python-webrtc-server/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: soft-python - image: ghcr.io/ueckoken/plarail2022-frontend-python:27d82b2-1668657626 # {"$imagepolicy": "plarail2021:frontend-python"} + image: ghcr.io/ueckoken/plarail2022-frontend-python:df4f652-1668679369 # {"$imagepolicy": "plarail2021:frontend-python"} imagePullPolicy: Always ports: - containerPort: 80 diff --git a/manifests/manifests/receiver-test/deployment.yaml b/manifests/manifests/receiver-test/deployment.yaml index 100fa5cd..58407d8e 100644 --- a/manifests/manifests/receiver-test/deployment.yaml +++ b/manifests/manifests/receiver-test/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: webrtc-receiver - image: ghcr.io/ueckoken/plarail2022-receiver-test:27d82b2-1668657626 # {"$imagepolicy": "plarail2021:webrtc-receiver"} + image: ghcr.io/ueckoken/plarail2022-receiver-test:df4f652-1668679369 # {"$imagepolicy": "plarail2021:webrtc-receiver"} imagePullPolicy: Always ports: - containerPort: 80 diff --git a/manifests/manifests/webrtc-sender/deployment.yaml b/manifests/manifests/webrtc-sender/deployment.yaml index f47db638..01a8e1ef 100644 --- a/manifests/manifests/webrtc-sender/deployment.yaml +++ b/manifests/manifests/webrtc-sender/deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: webrtc-sender - image: ghcr.io/ueckoken/plarail2022-webrtc-sender:27d82b2-1668657626 # {"$imagepolicy": "plarail2021:webrtc-sender"} + image: ghcr.io/ueckoken/plarail2022-webrtc-sender:df4f652-1668679369 # {"$imagepolicy": "plarail2021:webrtc-sender"} imagePullPolicy: Always ports: - containerPort: 80