github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/internal/ota/version.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 ota 19 20 const compressionEnabledMagicNumber = 0x40 21 22 // Version contains all the OTA header information 23 // Check out https://arduino.atlassian.net/wiki/spaces/RFC/pages/1616871540/OTA+header+structure for more 24 // information on the OTA header specs. 25 type Version struct { 26 HeaderVersion uint8 27 Compression bool 28 Signature bool 29 Spare uint8 30 PayloadTarget uint8 31 PayloadMayor uint8 32 PayloadMinor uint8 33 PayloadPatch uint8 34 PayloadBuildNum uint32 35 } 36 37 // Bytes builds a 8 byte length representation of the Version Struct for the OTA update. 38 func (v *Version) Bytes() []byte { 39 version := []byte{0, 0, 0, 0, 0, 0, 0, 0} 40 41 // Set compression 42 if v.Compression { 43 version[7] = 0x40 44 } 45 46 // Other field are currently not implemented ¯\_(ツ)_/¯ 47 48 return version 49 } 50 51 // Bytes builds a 8 byte length representation of the Version Struct for the OTA update. 52 func decodeVersion(version []byte) Version { 53 54 compressed := (version[7] == compressionEnabledMagicNumber) 55 56 // Other field are currently not implemented ¯\_(ツ)_/¯ 57 58 return Version{ 59 Compression: compressed, 60 } 61 }