|
@@ -12,15 +12,11 @@ import (
|
|
|
|
|
|
type Screener interface {
|
|
|
Display()
|
|
|
+ CorrectTime(time.Time)
|
|
|
}
|
|
|
|
|
|
type Screen struct {
|
|
|
- Id byte
|
|
|
- Sn string
|
|
|
Name string
|
|
|
- Type byte
|
|
|
- FileNum byte
|
|
|
- Files []string
|
|
|
Conn net.Conn
|
|
|
IsLive bool
|
|
|
StateInfo *bx.StateInfo
|
|
@@ -48,29 +44,23 @@ func (s *Screen) Display() {
|
|
|
|
|
|
func (s *Screen) send(data []byte) {
|
|
|
if !s.IsLive {
|
|
|
- fmt.Println("连接已断开!")
|
|
|
return
|
|
|
}
|
|
|
_, err := s.Conn.Write(data)
|
|
|
if err != nil {
|
|
|
- logrus.Error("tcp write error:", err)
|
|
|
+ logrus.WithFields(map[string]interface{}{"设备名": s.Name}).Error("tcp write error:", err)
|
|
|
s.IsLive = false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-func (s *Screen) CorrectTime() (ok bool) {
|
|
|
+func (s *Screen) CorrectTime(now time.Time) {
|
|
|
if !s.IsLive {
|
|
|
- return false
|
|
|
+ return
|
|
|
}
|
|
|
- cmd := bx.NewBxCmdSystemClockCorrect(time.Now())
|
|
|
+ cmd := bx.NewBxCmdSystemClockCorrect(now)
|
|
|
data := bx.NewBxDataPackCmd(cmd)
|
|
|
- _, err := s.Conn.Write(data.Pack())
|
|
|
- if err != nil {
|
|
|
- logrus.WithFields(map[string]interface{}{"Id": s.Id, "Name": s.Name}).Errorf("Conn写数据失败:%v", err)
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
+ s.send(data.Pack())
|
|
|
}
|
|
|
|
|
|
type Color byte
|
|
@@ -87,14 +77,14 @@ const (
|
|
|
None
|
|
|
)
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-func (s *Screen) TextRam(str string, color Color, playMode byte) {
|
|
|
+func (s *Screen) TextRam(ft FlashFile) {
|
|
|
if !s.IsLive {
|
|
|
return
|
|
|
}
|
|
@@ -103,19 +93,17 @@ func (s *Screen) TextRam(str string, color Color, playMode byte) {
|
|
|
|
|
|
|
|
|
encoder := simplifiedchinese.GB18030.NewEncoder()
|
|
|
- bytes, err := encoder.Bytes([]byte("\\C" + strconv.Itoa(int(color)) + str))
|
|
|
+ bytes, err := encoder.Bytes([]byte("\\C" + strconv.Itoa(int(ft.color)) + ft.msg))
|
|
|
if err != nil {
|
|
|
logrus.Error("编码转换失败:", err)
|
|
|
return
|
|
|
}
|
|
|
- x := 0x8000
|
|
|
- w := 0x8040
|
|
|
- area := bx.NewBxAreaDynamic(s.StateInfo.DynaAreaNum, playMode, int16(x), 0, int16(w), 16, bytes, false)
|
|
|
+ area := bx.NewBxAreaDynamic(s.StateInfo.DynaAreaNum, 0, byte(ft.dispMode), ft.originX, ft.originY, ft.width, ft.height, bytes, false)
|
|
|
areas = append(areas, area)
|
|
|
|
|
|
cmd := bx.NewBxCmdSendDynamicArea(areas)
|
|
|
pack := bx.NewBxDataPackCmd(cmd)
|
|
|
- pack.SetDispType(2)
|
|
|
+ pack.SetDispType(1)
|
|
|
d := pack.Pack()
|
|
|
s.send(d)
|
|
|
s.ReadResp()
|
|
@@ -138,30 +126,90 @@ func (s *Screen) DelRamText(numbers ...byte) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (s *Screen) TextFlash(msg string, color Color) {
|
|
|
+type RunMode byte
|
|
|
+
|
|
|
+const (
|
|
|
+ Loop RunMode = iota
|
|
|
+ LoopAndStayAtEnd
|
|
|
+ LoopAndTimeoutOff
|
|
|
+ LoopAndStayAtLogo
|
|
|
+ LoopAndOff
|
|
|
+ LoopAndCountOff
|
|
|
+ DefaultRunMode RunMode = Loop
|
|
|
+)
|
|
|
+
|
|
|
+type DispMode byte
|
|
|
+
|
|
|
+const (
|
|
|
+ _ DispMode = iota
|
|
|
+ Static
|
|
|
+ QuickPunch
|
|
|
+ MoveLeft
|
|
|
+ MoveRight
|
|
|
+ MoveUp
|
|
|
+ MoveDown
|
|
|
+ DefaultDispMode DispMode = Static
|
|
|
+)
|
|
|
+
|
|
|
+type FlashFile struct {
|
|
|
+ msg string
|
|
|
+ color Color
|
|
|
+ runMode RunMode
|
|
|
+ dispMode DispMode
|
|
|
+ originX uint16
|
|
|
+ originY uint16
|
|
|
+ width uint16
|
|
|
+ height uint16
|
|
|
+}
|
|
|
+
|
|
|
+func (ft *FlashFile) SetMsg(msg string, color Color) {
|
|
|
+ ft.msg = msg
|
|
|
+ ft.color = color
|
|
|
+}
|
|
|
+func (ft *FlashFile) SetMode(runMode RunMode, dispMode DispMode) {
|
|
|
+ ft.runMode = runMode
|
|
|
+ ft.dispMode = dispMode
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ft *FlashFile) SetOrigin(x uint16, xIsPixel bool, y uint16) {
|
|
|
+ ft.originY = y
|
|
|
+ if xIsPixel {
|
|
|
+ ft.originX = 0x8000 | x
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ft.originX = x
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (ft *FlashFile) SetArea(w uint16, yIsPixel bool, h uint16) {
|
|
|
+ ft.height = h
|
|
|
+ if yIsPixel {
|
|
|
+ ft.width = 0x8000 | w
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ft.width = w
|
|
|
+}
|
|
|
+
|
|
|
+func (s *Screen) TextFlash(ft FlashFile) {
|
|
|
if !s.IsLive {
|
|
|
return
|
|
|
}
|
|
|
encoder := simplifiedchinese.GB18030.NewEncoder()
|
|
|
var bytes []byte
|
|
|
|
|
|
- if color == None {
|
|
|
- bytes = []byte(msg)
|
|
|
+ if ft.color == None {
|
|
|
+ bytes = []byte(ft.msg)
|
|
|
} else {
|
|
|
- bytes, _ = encoder.Bytes([]byte("\\C" + strconv.Itoa(int(color)) + msg))
|
|
|
+ bytes, _ = encoder.Bytes([]byte("\\C" + strconv.Itoa(int(ft.color)) + ft.msg))
|
|
|
}
|
|
|
- x := 0x8000
|
|
|
- w := 0x8040
|
|
|
- area := bx.NewBxAreaDynamic(0xff, 2, int16(x), 0, int16(w), 16, bytes, false)
|
|
|
+ area := bx.NewBxAreaDynamic(0xff, byte(ft.runMode), byte(ft.dispMode), ft.originX, ft.originY, ft.width, ft.height, bytes, false)
|
|
|
|
|
|
name := fmt.Sprintf("P%03d", s.StateInfo.ProgramNum)
|
|
|
- fmt.Println("文件名:", name)
|
|
|
file := bx.NewBxFile(name, "", []bx.BxArea{area})
|
|
|
cmd := file.NewCmdWriteFile()
|
|
|
pack := bx.NewBxDataPackCmd(cmd)
|
|
|
data := pack.Pack()
|
|
|
- fmt.Println("数据长度:", len(data))
|
|
|
- fmt.Printf("数据:% 02x\n", data)
|
|
|
s.send(data)
|
|
|
resp := s.ReadResp()
|
|
|
if !resp.IsAck() {
|
|
@@ -170,9 +218,7 @@ func (s *Screen) TextFlash(msg string, color Color) {
|
|
|
}
|
|
|
pack1 := bx.NewBxDataPackCmd(cmd)
|
|
|
data1 := pack1.Pack()
|
|
|
- fmt.Println("数据长度:", len(data))
|
|
|
s.send(data1)
|
|
|
- fmt.Printf("数据1:% 02x\n", data1)
|
|
|
resp1 := s.ReadResp()
|
|
|
if resp1.NoError() {
|
|
|
s.StateInfo.ProgramNum++
|