From 9dd32799d1edec1e3eed7e041cde18cec644964c Mon Sep 17 00:00:00 2001 From: aespinro Date: Mon, 19 Aug 2024 16:22:35 +0200 Subject: [PATCH] wip --- go.mod | 21 +- go.sum | 38 +--- internal/app/app.go | 78 +------ internal/server/server.go | 66 +++++- internal/service/service.go | 64 +----- internal/types/print_data.go | 46 ++++ pkg/api/api.pb.go | 418 ----------------------------------- pkg/api/api.proto | 33 --- pkg/api/api_grpc.pb.go | 109 --------- pkg/api/generate.go | 3 - 10 files changed, 119 insertions(+), 757 deletions(-) create mode 100644 internal/types/print_data.go delete mode 100644 pkg/api/api.pb.go delete mode 100644 pkg/api/api.proto delete mode 100644 pkg/api/api_grpc.pb.go delete mode 100644 pkg/api/generate.go diff --git a/go.mod b/go.mod index 557b451..ca9fc95 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,11 @@ module git.espin.casa/albert/cml04-printer-robot -go 1.21.6 +go 1.22.1 + +require git.espin.casa/albert/logger v0.0.0-20240312060442-59b35e5c6996 require ( - git.espin.casa/albert/logger v0.0.0-20240130174416-19d12b345cdc - google.golang.org/grpc v1.61.0 - google.golang.org/protobuf v1.32.0 -) - -require github.com/gorilla/websocket v1.5.0 // indirect - -require ( - github.com/eclipse/paho.mqtt.golang v1.4.3 - github.com/golang/protobuf v1.5.3 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - golang.org/x/net v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.14.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect + golang.org/x/sync v0.8.0 + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect ) diff --git a/go.sum b/go.sum index 31d54ba..775f0db 100644 --- a/go.sum +++ b/go.sum @@ -1,43 +1,15 @@ -git.espin.casa/albert/logger v0.0.0-20240130174416-19d12b345cdc h1:8xlNjgJX7XQ7nxFki/e/Lga1mGuvr0A2lezdT2zmzl8= -git.espin.casa/albert/logger v0.0.0-20240130174416-19d12b345cdc/go.mod h1:dacFMi82f5ysDOaJQm0QmQaJZ7mwGFiayJ2iS+JKAfQ= +git.espin.casa/albert/logger v0.0.0-20240312060442-59b35e5c6996 h1:gOY7u2z9gMOdp0Q1Rod9XvoM0gL84SBXR7n/VxrgvtE= +git.espin.casa/albert/logger v0.0.0-20240312060442-59b35e5c6996/go.mod h1:dacFMi82f5ysDOaJQm0QmQaJZ7mwGFiayJ2iS+JKAfQ= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= -github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA= -google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0= -google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/app/app.go b/internal/app/app.go index 55a23a5..b9e5065 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -2,105 +2,39 @@ package app import ( "flag" - "net" "os" "os/signal" "syscall" "git.espin.casa/albert/cml04-printer-robot/internal/logging" - "git.espin.casa/albert/cml04-printer-robot/internal/server" "git.espin.casa/albert/cml04-printer-robot/internal/service" - "git.espin.casa/albert/cml04-printer-robot/internal/vnode" - "git.espin.casa/albert/cml04-printer-robot/pkg/api" "git.espin.casa/albert/logger" - - "google.golang.org/grpc" - "google.golang.org/grpc/reflection" ) func Run() error { // flags - apiAddr := flag.String("api", "localhost:3333", "API server address") + bindAddr := flag.String("addr", "localhost:3333", "API server address") logLevel := flag.String("level", "debug", "log level") - mqttAddr := flag.String("mqtt_addr", "tcp://10.1.152.13:1883", "MQTT address") - mqttTopic := flag.String("mqtt_topic", "vnode/ata12/robot", "MQTT topic") // parse flags flag.Parse() // setup logger log := logger.New(os.Stdout, *logLevel) // create log fields logFields := logger.LogFields{ - "app_name": "cml04-printer-robot", - "debug_legel": *logLevel, - "mqtt_address": *mqttAddr, - "api_bind_address": *apiAddr, + "app_name": "cml04-printer-robot", + "debug_legel": *logLevel, + "l2_bind_address": *bindAddr, } - // create broker - broker, err := vnode.NewBroker(*mqttAddr, log) - if err != nil { - log.Error("create new broker failed", err, logFields) - return err - } - // start broker - if err := broker.Connect(); err != nil { - log.Error("start broker failed", err, logFields) - return err - } - defer broker.Close() // create main service svc := service.NewService(broker) // add logging capabilities to main service svc = logging.NewLoggingService(svc, log) - // create data channel - dataChannel := make(chan []byte) - // create error channel - errorCallback := make(chan error) - // create done channel - done := make(chan struct{}) - // subscribe robot data topic - go broker.SubscribeToMQTTTopic(*mqttTopic, dataChannel, errorCallback, done) - // get data from channel - go func() { - for { - select { - case data := <-dataChannel: - if err := svc.RobotEventDataHandler(data); err != nil { - log.Error("error robot event handler", err, logFields) - } - case err := <-errorCallback: - log.Error("error callback", err, logFields) - case <-done: - log.Info("done callback", logFields) - } - } - }() - // create grpc server - s := grpc.NewServer() - // create api server transport - server := server.NewAPIServer(svc) - // register service - api.RegisterRobotServiceServer(s, server) - // Reflection grpc server - reflection.Register(s) - // create grpc server - lis, err := net.Listen("tcp", *apiAddr) - if err != nil { - log.Error("failed to listen", err, logFields) - return err - } - // start service server - go func() { - if err := s.Serve(lis); err != nil { - log.Error("failed to serve gRPC", err, logFields) - return - } - }() + // start banner log.Info("cml04 printer robot service started", logFields) // wait signal to finish signal := WaitSignal() - // end subscriber - close(done) + log.Info("signal received", logger.LogFields{ "signal": signal, }) diff --git a/internal/server/server.go b/internal/server/server.go index b7ea007..58b9a45 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -1,24 +1,70 @@ package server import ( - "context" + "fmt" + "net" + "sync" "git.espin.casa/albert/cml04-printer-robot/internal/service" - "git.espin.casa/albert/cml04-printer-robot/pkg/api" + "git.espin.casa/albert/logger" ) type server struct { - api.UnimplementedRobotServiceServer - svc service.IService + listener net.Listener + mux sync.RWMutex + log logger.LoggerAdapter + cons []net.Conn } -func (s server) PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) { - return s.svc.PrintPackage(ctx, req) +func (s *server) Stop() { + s.mux.Lock() + defer s.mux.Unlock() + for _, conn := range s.cons { + conn.Close() + } + s.mux.Unlock() + s.listener.Close() } -func NewAPIServer(svc service.IService) *server { - return &server{ - UnimplementedRobotServiceServer: api.UnimplementedRobotServiceServer{}, - svc: svc, +func (s *server) HandleConn(conn net.Conn) error { + buff := make([]byte, 4096) + + n, err := conn.Read(buff) + if err != nil { + + } + if n < 24 { + return fmt.Errorf("received telegram is too short") } } + +func (s *server) Start() { + for { + // Aceptar una conexión entrante + conn, err := s.listener.Accept() + if err != nil { + s.log.Error("listener failed", err, logger.LogFields{}) + continue + } + s.mux.Lock() + s.cons = append(s.cons, conn) + s.mux.Unlock() + + go s.HandleConn(conn) + } +} + +func NewServer(svc service.IService, address string, log logger.LoggerAdapter) (*server, error) { + listener, err := net.Listen("tcp", address) + if err != nil { + return nil, err + } + defer listener.Close() + + return &server{ + listener: listener, + mux: sync.RWMutex{}, + log: log, + cons: []net.Conn{}, + }, err +} diff --git a/internal/service/service.go b/internal/service/service.go index cd74bb2..125c3e6 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -3,15 +3,11 @@ package service import ( "bytes" "container/list" - "context" "encoding/json" "errors" "fmt" "strings" "time" - - "git.espin.casa/albert/cml04-printer-robot/internal/vnode" - "git.espin.casa/albert/cml04-printer-robot/pkg/api" ) var ( @@ -48,60 +44,11 @@ const ( CardColorNone ) -type Tag struct { - Topic string `json:"t"` - Value any `json:"v"` -} - -var ( - CardColorMap = map[CardColor]*Tag{ - CardColorBlueYellow: { - Topic: "/robot12/write/blue_yellow_card", - Value: false, - }, - CardColorRed: { - Topic: "/robot12/write/red_card", - Value: false, - }, - CardColorYellow: { - Topic: "/robot12/write/yellow_card", - Value: false, - }, - CardColorGreen: { - Topic: "/robot12/write/green_card", - Value: false, - }, - CardColorWhite: { - Topic: "/robot12/write/white_card", - Value: false, - }, - CardColorBlue: { - Topic: "/robot12/write/blue_card", - Value: false, - }, - CardColorOrange: { - Topic: "/robot12/write/orange_card", - Value: false, - }, - CardColorBlack: { - Topic: "/robot12/write/black_card", - Value: false, - }, - CardColorNone: { - Topic: "/robot12/write/none_card", - Value: false, - }, - } -) - type IService interface { - PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) - RobotEventDataHandler(data []byte) error } type service struct { - broker *vnode.Broker - queue *list.List + queue *list.List } func (s *service) HeartBeatHandler() error { @@ -225,15 +172,6 @@ func (s *service) QueueLen() int { return s.queue.Len() } -// PrintPackage implements IService. -func (s *service) PrintPackage(ctx context.Context, req *api.PrintPackageReq) (res *api.PrintPackageRes, err error) { - s.Enqueue(req.PackageData) - return &api.PrintPackageRes{ - Msg: "print package success", - TimeStamp: time.Now().UTC().Format(time.RFC3339), - }, nil -} - func (s *service) PrintHandler(lp LabelPrinter) error { fmt.Println(LabelPrinter(lp)) return nil diff --git a/internal/types/print_data.go b/internal/types/print_data.go new file mode 100644 index 0000000..5a3c909 --- /dev/null +++ b/internal/types/print_data.go @@ -0,0 +1,46 @@ +package types + +import ( + "bytes" + "encoding/binary" +) + +type TelegramHeader struct { + MessageLength int16 + TelegramID int16 + SequenceCounter int16 + Flags int16 + TimeStamp [8]int16 +} + +type PrintData struct { + Header *TelegramHeader + DateTime [23]byte + L2PackageId int32 + L3PackageId [6]byte + ProductionOrderNo int32 + CustomerOrderNo int32 + CustomerName [30]byte + LogoCode [3]byte + SteelGrade [15]byte + MaterialCode [18]byte + HeatId [10]byte + SectionType [20]byte + PackageDimensions [3]float32 + PackageWeight float32 + SectionDimensions [3]float32 + NumberSections int32 + NumberLayers int32 + NumberSectionsInLayer int32 + FreeTxtLp [180]byte +} + +func (p *PrintData) FromBytes(byteData []byte) error { + // create reader + reader := bytes.NewReader(byteData) + // convert reader binary data + if err := binary.Read(reader, binary.LittleEndian, p); err != nil { + return err + } + return nil +} diff --git a/pkg/api/api.pb.go b/pkg/api/api.pb.go deleted file mode 100644 index ac4666a..0000000 --- a/pkg/api/api.pb.go +++ /dev/null @@ -1,418 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.32.0 -// protoc v4.25.2 -// source: api.proto - -package api - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type PackageData struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Producto string `protobuf:"bytes,1,opt,name=producto,proto3" json:"producto,omitempty"` - Colada string `protobuf:"bytes,2,opt,name=colada,proto3" json:"colada,omitempty"` - Matnr string `protobuf:"bytes,3,opt,name=matnr,proto3" json:"matnr,omitempty"` - Barras int32 `protobuf:"varint,4,opt,name=barras,proto3" json:"barras,omitempty"` - Longitud float64 `protobuf:"fixed64,5,opt,name=longitud,proto3" json:"longitud,omitempty"` - Fecha string `protobuf:"bytes,6,opt,name=fecha,proto3" json:"fecha,omitempty"` - NormaPoducto string `protobuf:"bytes,7,opt,name=norma_poducto,json=normaPoducto,proto3" json:"norma_poducto,omitempty"` - NormaCalidad string `protobuf:"bytes,8,opt,name=norma_calidad,json=normaCalidad,proto3" json:"norma_calidad,omitempty"` - NormaTolerancia string `protobuf:"bytes,9,opt,name=norma_tolerancia,json=normaTolerancia,proto3" json:"norma_tolerancia,omitempty"` - OrdenProduccion int64 `protobuf:"varint,10,opt,name=orden_produccion,json=ordenProduccion,proto3" json:"orden_produccion,omitempty"` - OrdenCliente int64 `protobuf:"varint,11,opt,name=orden_cliente,json=ordenCliente,proto3" json:"orden_cliente,omitempty"` - NroMatricula string `protobuf:"bytes,100,opt,name=nro_matricula,json=nroMatricula,proto3" json:"nro_matricula,omitempty"` -} - -func (x *PackageData) Reset() { - *x = PackageData{} - if protoimpl.UnsafeEnabled { - mi := &file_api_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *PackageData) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*PackageData) ProtoMessage() {} - -func (x *PackageData) ProtoReflect() protoreflect.Message { - mi := &file_api_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use PackageData.ProtoReflect.Descriptor instead. -func (*PackageData) Descriptor() ([]byte, []int) { - return file_api_proto_rawDescGZIP(), []int{0} -} - -func (x *PackageData) GetProducto() string { - if x != nil { - return x.Producto - } - return "" -} - -func (x *PackageData) GetColada() string { - if x != nil { - return x.Colada - } - return "" -} - -func (x *PackageData) GetMatnr() string { - if x != nil { - return x.Matnr - } - return "" -} - -func (x *PackageData) GetBarras() int32 { - if x != nil { - return x.Barras - } - return 0 -} - -func (x *PackageData) GetLongitud() float64 { - if x != nil { - return x.Longitud - } - return 0 -} - -func (x *PackageData) GetFecha() string { - if x != nil { - return x.Fecha - } - return "" -} - -func (x *PackageData) GetNormaPoducto() string { - if x != nil { - return x.NormaPoducto - } - return "" -} - -func (x *PackageData) GetNormaCalidad() string { - if x != nil { - return x.NormaCalidad - } - return "" -} - -func (x *PackageData) GetNormaTolerancia() string { - if x != nil { - return x.NormaTolerancia - } - return "" -} - -func (x *PackageData) GetOrdenProduccion() int64 { - if x != nil { - return x.OrdenProduccion - } - return 0 -} - -func (x *PackageData) GetOrdenCliente() int64 { - if x != nil { - return x.OrdenCliente - } - return 0 -} - -func (x *PackageData) GetNroMatricula() string { - if x != nil { - return x.NroMatricula - } - return "" -} - -type PrintPackageReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` - PackageData *PackageData `protobuf:"bytes,2,opt,name=package_data,json=packageData,proto3" json:"package_data,omitempty"` - TimeStamp string `protobuf:"bytes,100,opt,name=time_stamp,json=timeStamp,proto3" json:"time_stamp,omitempty"` -} - -func (x *PrintPackageReq) Reset() { - *x = PrintPackageReq{} - if protoimpl.UnsafeEnabled { - mi := &file_api_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *PrintPackageReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*PrintPackageReq) ProtoMessage() {} - -func (x *PrintPackageReq) ProtoReflect() protoreflect.Message { - mi := &file_api_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use PrintPackageReq.ProtoReflect.Descriptor instead. -func (*PrintPackageReq) Descriptor() ([]byte, []int) { - return file_api_proto_rawDescGZIP(), []int{1} -} - -func (x *PrintPackageReq) GetSender() string { - if x != nil { - return x.Sender - } - return "" -} - -func (x *PrintPackageReq) GetPackageData() *PackageData { - if x != nil { - return x.PackageData - } - return nil -} - -func (x *PrintPackageReq) GetTimeStamp() string { - if x != nil { - return x.TimeStamp - } - return "" -} - -type PrintPackageRes struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` - TimeStamp string `protobuf:"bytes,100,opt,name=time_stamp,json=timeStamp,proto3" json:"time_stamp,omitempty"` -} - -func (x *PrintPackageRes) Reset() { - *x = PrintPackageRes{} - if protoimpl.UnsafeEnabled { - mi := &file_api_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *PrintPackageRes) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*PrintPackageRes) ProtoMessage() {} - -func (x *PrintPackageRes) ProtoReflect() protoreflect.Message { - mi := &file_api_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use PrintPackageRes.ProtoReflect.Descriptor instead. -func (*PrintPackageRes) Descriptor() ([]byte, []int) { - return file_api_proto_rawDescGZIP(), []int{2} -} - -func (x *PrintPackageRes) GetMsg() string { - if x != nil { - return x.Msg - } - return "" -} - -func (x *PrintPackageRes) GetTimeStamp() string { - if x != nil { - return x.TimeStamp - } - return "" -} - -var File_api_proto protoreflect.FileDescriptor - -var file_api_proto_rawDesc = []byte{ - 0x0a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, - 0x22, 0x8b, 0x03, 0x0a, 0x0b, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, - 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x6f, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x6f, 0x12, 0x16, 0x0a, 0x06, - 0x63, 0x6f, 0x6c, 0x61, 0x64, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, - 0x6c, 0x61, 0x64, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x61, 0x74, 0x6e, 0x72, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x61, 0x74, 0x6e, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, - 0x72, 0x72, 0x61, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x61, 0x72, 0x72, - 0x61, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x12, 0x14, - 0x0a, 0x05, 0x66, 0x65, 0x63, 0x68, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x66, - 0x65, 0x63, 0x68, 0x61, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x5f, 0x70, 0x6f, - 0x64, 0x75, 0x63, 0x74, 0x6f, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x72, - 0x6d, 0x61, 0x50, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x6f, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x6f, 0x72, - 0x6d, 0x61, 0x5f, 0x63, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0c, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x43, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x64, 0x12, 0x29, - 0x0a, 0x10, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x5f, 0x74, 0x6f, 0x6c, 0x65, 0x72, 0x61, 0x6e, 0x63, - 0x69, 0x61, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x54, - 0x6f, 0x6c, 0x65, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x61, 0x12, 0x29, 0x0a, 0x10, 0x6f, 0x72, 0x64, - 0x65, 0x6e, 0x5f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x63, 0x69, 0x6f, 0x6e, 0x18, 0x0a, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x0f, 0x6f, 0x72, 0x64, 0x65, 0x6e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, - 0x63, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x6f, 0x72, 0x64, 0x65, 0x6e, 0x5f, 0x63, 0x6c, - 0x69, 0x65, 0x6e, 0x74, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x6f, 0x72, 0x64, - 0x65, 0x6e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6e, 0x72, 0x6f, - 0x5f, 0x6d, 0x61, 0x74, 0x72, 0x69, 0x63, 0x75, 0x6c, 0x61, 0x18, 0x64, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0c, 0x6e, 0x72, 0x6f, 0x4d, 0x61, 0x74, 0x72, 0x69, 0x63, 0x75, 0x6c, 0x61, 0x22, 0x7d, - 0x0a, 0x0f, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, - 0x71, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x33, 0x0a, 0x0c, 0x70, 0x61, 0x63, - 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x10, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, - 0x61, 0x52, 0x0b, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1d, - 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x64, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x42, 0x0a, - 0x0f, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, - 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, - 0x73, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x18, 0x64, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x6d, - 0x70, 0x32, 0x4a, 0x0a, 0x0c, 0x52, 0x6f, 0x62, 0x6f, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x3a, 0x0a, 0x0c, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, - 0x65, 0x12, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, - 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x50, 0x72, - 0x69, 0x6e, 0x74, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x42, 0x37, 0x5a, - 0x35, 0x67, 0x69, 0x74, 0x2e, 0x65, 0x73, 0x70, 0x69, 0x6e, 0x2e, 0x63, 0x61, 0x73, 0x61, 0x2f, - 0x61, 0x6c, 0x62, 0x65, 0x72, 0x74, 0x2f, 0x63, 0x6d, 0x6c, 0x30, 0x34, 0x2d, 0x70, 0x72, 0x69, - 0x6e, 0x74, 0x65, 0x72, 0x2d, 0x72, 0x6f, 0x62, 0x6f, 0x74, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, - 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_api_proto_rawDescOnce sync.Once - file_api_proto_rawDescData = file_api_proto_rawDesc -) - -func file_api_proto_rawDescGZIP() []byte { - file_api_proto_rawDescOnce.Do(func() { - file_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_proto_rawDescData) - }) - return file_api_proto_rawDescData -} - -var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_api_proto_goTypes = []interface{}{ - (*PackageData)(nil), // 0: api.PackageData - (*PrintPackageReq)(nil), // 1: api.PrintPackageReq - (*PrintPackageRes)(nil), // 2: api.PrintPackageRes -} -var file_api_proto_depIdxs = []int32{ - 0, // 0: api.PrintPackageReq.package_data:type_name -> api.PackageData - 1, // 1: api.RobotService.PrintPackage:input_type -> api.PrintPackageReq - 2, // 2: api.RobotService.PrintPackage:output_type -> api.PrintPackageRes - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name -} - -func init() { file_api_proto_init() } -func file_api_proto_init() { - if File_api_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PackageData); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PrintPackageReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_api_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PrintPackageRes); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_api_proto_rawDesc, - NumEnums: 0, - NumMessages: 3, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_api_proto_goTypes, - DependencyIndexes: file_api_proto_depIdxs, - MessageInfos: file_api_proto_msgTypes, - }.Build() - File_api_proto = out.File - file_api_proto_rawDesc = nil - file_api_proto_goTypes = nil - file_api_proto_depIdxs = nil -} diff --git a/pkg/api/api.proto b/pkg/api/api.proto deleted file mode 100644 index e4ad009..0000000 --- a/pkg/api/api.proto +++ /dev/null @@ -1,33 +0,0 @@ -syntax = "proto3"; -package api; -option go_package = "git.espin.casa/albert/cml04-printer-robot/pkg/api;api"; - -service RobotService { - rpc PrintPackage (PrintPackageReq) returns (PrintPackageRes); -} - -message PackageData{ - string producto = 1; - string colada = 2; - string matnr = 3; - int32 barras = 4; - double longitud = 5; - string fecha = 6; - string norma_poducto = 7; - string norma_calidad = 8; - string norma_tolerancia = 9; - int64 orden_produccion = 10; - int64 orden_cliente = 11; - string nro_matricula = 100; -} - -message PrintPackageReq{ - string sender = 1; - PackageData package_data = 2; - string time_stamp = 100; -} - -message PrintPackageRes{ - string msg = 1; - string time_stamp = 100; -} \ No newline at end of file diff --git a/pkg/api/api_grpc.pb.go b/pkg/api/api_grpc.pb.go deleted file mode 100644 index caa1804..0000000 --- a/pkg/api/api_grpc.pb.go +++ /dev/null @@ -1,109 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.2 -// source: api.proto - -package api - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -const ( - RobotService_PrintPackage_FullMethodName = "/api.RobotService/PrintPackage" -) - -// RobotServiceClient is the client API for RobotService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type RobotServiceClient interface { - PrintPackage(ctx context.Context, in *PrintPackageReq, opts ...grpc.CallOption) (*PrintPackageRes, error) -} - -type robotServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewRobotServiceClient(cc grpc.ClientConnInterface) RobotServiceClient { - return &robotServiceClient{cc} -} - -func (c *robotServiceClient) PrintPackage(ctx context.Context, in *PrintPackageReq, opts ...grpc.CallOption) (*PrintPackageRes, error) { - out := new(PrintPackageRes) - err := c.cc.Invoke(ctx, RobotService_PrintPackage_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// RobotServiceServer is the server API for RobotService service. -// All implementations must embed UnimplementedRobotServiceServer -// for forward compatibility -type RobotServiceServer interface { - PrintPackage(context.Context, *PrintPackageReq) (*PrintPackageRes, error) - mustEmbedUnimplementedRobotServiceServer() -} - -// UnimplementedRobotServiceServer must be embedded to have forward compatible implementations. -type UnimplementedRobotServiceServer struct { -} - -func (UnimplementedRobotServiceServer) PrintPackage(context.Context, *PrintPackageReq) (*PrintPackageRes, error) { - return nil, status.Errorf(codes.Unimplemented, "method PrintPackage not implemented") -} -func (UnimplementedRobotServiceServer) mustEmbedUnimplementedRobotServiceServer() {} - -// UnsafeRobotServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to RobotServiceServer will -// result in compilation errors. -type UnsafeRobotServiceServer interface { - mustEmbedUnimplementedRobotServiceServer() -} - -func RegisterRobotServiceServer(s grpc.ServiceRegistrar, srv RobotServiceServer) { - s.RegisterService(&RobotService_ServiceDesc, srv) -} - -func _RobotService_PrintPackage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(PrintPackageReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RobotServiceServer).PrintPackage(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: RobotService_PrintPackage_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RobotServiceServer).PrintPackage(ctx, req.(*PrintPackageReq)) - } - return interceptor(ctx, in, info, handler) -} - -// RobotService_ServiceDesc is the grpc.ServiceDesc for RobotService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var RobotService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "api.RobotService", - HandlerType: (*RobotServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "PrintPackage", - Handler: _RobotService_PrintPackage_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "api.proto", -} diff --git a/pkg/api/generate.go b/pkg/api/generate.go deleted file mode 100644 index 113f504..0000000 --- a/pkg/api/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package api - -//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api.proto