BxCmdLock.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. type CmdLock struct {
  7. baseBxCmd
  8. StoreMode byte
  9. LockFlag byte
  10. ProgramFileName string
  11. }
  12. // NewCmdLock 锁定状态:0x00——解锁状态,0x01——锁定状态
  13. func NewCmdLock(flag byte, name string) CmdLock {
  14. return CmdLock{
  15. baseBxCmd: newBaseCmd(CMD_LOCK_UNLOCK.group, CMD_LOCK_UNLOCK.code),
  16. LockFlag: flag,
  17. ProgramFileName: name,
  18. }
  19. }
  20. // SetStoreMode 锁定状态保存方式:0x00——掉电不保存,0x01——掉电保存
  21. func (cmd *CmdLock) SetStoreMode(storeMode byte) {
  22. cmd.StoreMode = storeMode
  23. }
  24. func (cmd *CmdLock) Build() []byte {
  25. w := bytes.NewBuffer(make([]byte, 0, 32))
  26. binary.Write(w, binary.LittleEndian, cmd.Group())
  27. binary.Write(w, binary.LittleEndian, cmd.Cmd())
  28. binary.Write(w, binary.LittleEndian, byte(0x01))
  29. binary.Write(w, binary.LittleEndian, []byte{0x00, 0x00})
  30. binary.Write(w, binary.LittleEndian, cmd.StoreMode)
  31. binary.Write(w, binary.LittleEndian, cmd.LockFlag)
  32. binary.Write(w, binary.BigEndian, []byte(cmd.ProgramFileName))
  33. return w.Bytes()
  34. }