s19-from-mpar
parent
ac7580e620
commit
8e5c077b9f
@ -0,0 +1,74 @@
|
|||||||
|
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
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func ParseStringHexAddress(hexAddress string) (res uint64, err error) {
|
||||||
|
parsedValue, err := strconv.ParseUint(hexAddress[2:], 16, 32)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return parsedValue, nil
|
||||||
|
}
|
Loading…
Reference in New Issue