github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/internal/serial/protocol.go (about)

     1  // This file is part of arduino-cloud-cli.
     2  //
     3  // Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/)
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published
     7  // by the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    17  
    18  package serial
    19  
    20  var (
    21  	// msgStart is the initial byte sequence of every packet.
    22  	msgStart = [2]byte{0x55, 0xAA}
    23  	// msgEnd is the final byte sequence of every packet.
    24  	msgEnd = [2]byte{0xAA, 0x55}
    25  )
    26  
    27  const (
    28  	// payloadField indicates the position of payload field.
    29  	payloadField = 5
    30  	// payloadLenField indicates the position of payload length field.
    31  	payloadLenField = 3
    32  	// payloadLenFieldLen indicatest the length of payload length field.
    33  	payloadLenFieldLen = 2
    34  	// crcFieldLen indicates the length of the signature field.
    35  	crcFieldLen = 2
    36  )
    37  
    38  // MsgType indicates the type of the packet.
    39  type MsgType byte
    40  
    41  const (
    42  	None MsgType = iota
    43  	Cmd
    44  	Data
    45  	Response
    46  )
    47  
    48  // Command indicates the command that should be
    49  // executed on the board to be provisioned.
    50  type Command byte
    51  
    52  const (
    53  	SketchInfo Command = iota + 1
    54  	CSR
    55  	Locked
    56  	GetLocked
    57  	WriteCrypto
    58  	BeginStorage
    59  	SetDeviceID
    60  	SetYear
    61  	SetMonth
    62  	SetDay
    63  	SetHour
    64  	SetValidity
    65  	SetCertSerial
    66  	SetAuthKey
    67  	SetSignature
    68  	EndStorage
    69  	ReconstructCert
    70  )