You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package commands
|
|
|
|
import (
|
|
"os"
|
|
|
|
"git.cheetah.cat/cheetah/moto-flash-data/common"
|
|
"git.cheetah.cat/cheetah/moto-flash-data/s19"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type S19FromMparCommand struct {
|
|
FileName string `long:"file" short:"f" required:"true" description:"input-file, format: mpar"`
|
|
StartAddress string `long:"start-address" required:"true" short:"a" description:"start address"`
|
|
|
|
OutputFileName string `long:"out" short:"o" required:"true" description:"output-file, format: s19"`
|
|
}
|
|
|
|
func (command *S19FromMparCommand) Execute(args []string) error {
|
|
baseAddr, err := common.ParseStringHexAddress(command.StartAddress)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Info().Str("input", command.FileName).Msg("S19-FromMpar")
|
|
|
|
inputFile, err := os.Open(command.FileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer inputFile.Close()
|
|
|
|
s19File, err := s19.NewS19Writer(command.OutputFileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer s19File.Close()
|
|
log.Info().Str("output", command.OutputFileName).Msg("Writing file...")
|
|
|
|
records, err := s19File.CreateRecordsFromBinary(inputFile, uint32(baseAddr), 32)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// S0 14 5E73 3D466C617368205265706F72745E6F3D30 19
|
|
// S0 14 5E73 3D466C617368205265706F72745E6F3D30 <Checksum>
|
|
header := []s19.SRecord{
|
|
{
|
|
Type: "S0",
|
|
Count: 0x14,
|
|
Address: 0x5E73,
|
|
Data: []byte("=Flash Report^o=0"), // 3D466C617368205265706F72745E6F3D30
|
|
},
|
|
}
|
|
footer := []s19.SRecord{ // S701FE
|
|
{
|
|
Type: "S7",
|
|
Count: 0,
|
|
Address: 0x01FE,
|
|
Data: []byte{},
|
|
},
|
|
}
|
|
err = s19File.WriteRecords(header)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = s19File.WriteRecords(records)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = s19File.WriteRecords(footer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|