| 1 | // This file is part of pluggable-monitor-protocol-handler. |
| 2 | // |
| 3 | // SPDX-FileCopyrightText: Arduino s.r.l. and/or its affiliated companies |
| 4 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 5 | |
| 6 | package monitor |
| 7 | |
| 8 | type message struct { |
| 9 | EventType string `json:"eventType"` |
| 10 | Message string `json:"message,omitempty"` |
| 11 | Error bool `json:"error,omitempty"` |
| 12 | ProtocolVersion int `json:"protocolVersion,omitempty"` |
| 13 | PortDescription *PortDescriptor `json:"port_description,omitempty"` |
| 14 | } |
| 15 | |
| 16 | // PortDescriptor is a struct to describe the characteristic of a port |
| 17 | type PortDescriptor struct { |
| 18 | Protocol string `json:"protocol,omitempty"` |
| 19 | ConfigurationParameter map[string]*PortParameterDescriptor `json:"configuration_parameters,omitempty"` |
| 20 | } |
| 21 | |
| 22 | // PortParameterDescriptor contains characteristics for every parameter |
| 23 | type PortParameterDescriptor struct { |
| 24 | Label string `json:"label,omitempty"` |
| 25 | Type string `json:"type,omitempty"` |
| 26 | Values []string `json:"value,omitempty"` |
| 27 | Selected string `json:"selected,omitempty"` |
| 28 | } |
| 29 | |
| 30 | func messageOk(event string) *message { |
| 31 | return &message{ |
| 32 | EventType: event, |
| 33 | Message: "OK", |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func messageError(event, msg string) *message { |
| 38 | return &message{ |
| 39 | EventType: event, |
| 40 | Error: true, |
| 41 | Message: msg, |
| 42 | } |
| 43 | } |