|
@@ -12,15 +12,11 @@ import (
|
|
|
|
|
|
type Screener interface {
|
|
type Screener interface {
|
|
Display()
|
|
Display()
|
|
|
|
+ CorrectTime(time.Time)
|
|
}
|
|
}
|
|
|
|
|
|
type Screen struct {
|
|
type Screen struct {
|
|
- Id byte
|
|
|
|
- Sn string //B006K12311020021
|
|
|
|
Name string
|
|
Name string
|
|
- Type byte
|
|
|
|
- FileNum byte
|
|
|
|
- Files []string
|
|
|
|
Conn net.Conn
|
|
Conn net.Conn
|
|
IsLive bool
|
|
IsLive bool
|
|
StateInfo *bx.StateInfo //状态信息
|
|
StateInfo *bx.StateInfo //状态信息
|
|
@@ -48,29 +44,23 @@ func (s *Screen) Display() {
|
|
|
|
|
|
func (s *Screen) send(data []byte) {
|
|
func (s *Screen) send(data []byte) {
|
|
if !s.IsLive {
|
|
if !s.IsLive {
|
|
- fmt.Println("连接已断开!")
|
|
|
|
return
|
|
return
|
|
}
|
|
}
|
|
_, err := s.Conn.Write(data)
|
|
_, err := s.Conn.Write(data)
|
|
if err != nil {
|
|
if err != nil {
|
|
- logrus.Error("tcp write error:", err)
|
|
|
|
|
|
+ logrus.WithFields(map[string]interface{}{"设备名": s.Name}).Error("tcp write error:", err)
|
|
s.IsLive = false
|
|
s.IsLive = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// CorrectTime 校正时间
|
|
// CorrectTime 校正时间
|
|
-func (s *Screen) CorrectTime() (ok bool) {
|
|
|
|
|
|
+func (s *Screen) CorrectTime(now time.Time) {
|
|
if !s.IsLive {
|
|
if !s.IsLive {
|
|
- return false
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- cmd := bx.NewBxCmdSystemClockCorrect(time.Now())
|
|
|
|
|
|
+ cmd := bx.NewBxCmdSystemClockCorrect(now)
|
|
data := bx.NewBxDataPackCmd(cmd)
|
|
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
|
|
type Color byte
|
|
@@ -87,14 +77,14 @@ const (
|
|
None
|
|
None
|
|
)
|
|
)
|
|
|
|
|
|
-// TextRam
|
|
|
|
|
|
+// TextRam dispMode显示方式
|
|
// 0x01——静止显示
|
|
// 0x01——静止显示
|
|
// 0x02——快速打出
|
|
// 0x02——快速打出
|
|
// 0x03——向左移动
|
|
// 0x03——向左移动
|
|
// 0x04——向右移动
|
|
// 0x04——向右移动
|
|
// 0x05——向上移动
|
|
// 0x05——向上移动
|
|
// 0x06——向下移动
|
|
// 0x06——向下移动
|
|
-func (s *Screen) TextRam(str string, color Color, playMode byte) {
|
|
|
|
|
|
+func (s *Screen) TextRam(ft FlashFile) {
|
|
if !s.IsLive {
|
|
if !s.IsLive {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -103,19 +93,17 @@ func (s *Screen) TextRam(str string, color Color, playMode byte) {
|
|
//var x, y int16
|
|
//var x, y int16
|
|
//var w, h int16 = 64, 16
|
|
//var w, h int16 = 64, 16
|
|
encoder := simplifiedchinese.GB18030.NewEncoder()
|
|
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 {
|
|
if err != nil {
|
|
logrus.Error("编码转换失败:", err)
|
|
logrus.Error("编码转换失败:", err)
|
|
return
|
|
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)
|
|
areas = append(areas, area)
|
|
//
|
|
//
|
|
cmd := bx.NewBxCmdSendDynamicArea(areas)
|
|
cmd := bx.NewBxCmdSendDynamicArea(areas)
|
|
pack := bx.NewBxDataPackCmd(cmd)
|
|
pack := bx.NewBxDataPackCmd(cmd)
|
|
- pack.SetDispType(2) //动态显示模式
|
|
|
|
|
|
+ pack.SetDispType(1) //动态显示模式
|
|
d := pack.Pack()
|
|
d := pack.Pack()
|
|
s.send(d)
|
|
s.send(d)
|
|
s.ReadResp()
|
|
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 //循环完后,停留显示LOGO
|
|
|
|
+ LoopAndOff //循环完后不在显示
|
|
|
|
+ LoopAndCountOff //循环设定次数后不在显示
|
|
|
|
+ DefaultRunMode RunMode = Loop //默认
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type DispMode byte
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ _ DispMode = iota
|
|
|
|
+ Static //0x01——静止显示
|
|
|
|
+ QuickPunch //0x02——快速打出
|
|
|
|
+ MoveLeft //0x03——向左移动
|
|
|
|
+ MoveRight //0x04——向右移动
|
|
|
|
+ MoveUp //0x05——向上移动
|
|
|
|
+ MoveDown //0x06——向下移动
|
|
|
|
+ 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
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetOrigin xIsPixel=true表示x坐标为像素单位, =false表示以字节(8像素)为单位;y只有像素单位
|
|
|
|
+func (ft *FlashFile) SetOrigin(x uint16, xIsPixel bool, y uint16) {
|
|
|
|
+ ft.originY = y
|
|
|
|
+ if xIsPixel {
|
|
|
|
+ ft.originX = 0x8000 | x
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ ft.originX = x
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SetArea isPixel=true表示像素单位, =false表示以字节(8像素)为单位
|
|
|
|
+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 {
|
|
if !s.IsLive {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
encoder := simplifiedchinese.GB18030.NewEncoder()
|
|
encoder := simplifiedchinese.GB18030.NewEncoder()
|
|
var bytes []byte
|
|
var bytes []byte
|
|
//
|
|
//
|
|
- if color == None {
|
|
|
|
- bytes = []byte(msg)
|
|
|
|
|
|
+ if ft.color == None {
|
|
|
|
+ bytes = []byte(ft.msg)
|
|
} else {
|
|
} 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)
|
|
//if s.FileNum
|
|
//if s.FileNum
|
|
name := fmt.Sprintf("P%03d", s.StateInfo.ProgramNum)
|
|
name := fmt.Sprintf("P%03d", s.StateInfo.ProgramNum)
|
|
- fmt.Println("文件名:", name)
|
|
|
|
file := bx.NewBxFile(name, "", []bx.BxArea{area})
|
|
file := bx.NewBxFile(name, "", []bx.BxArea{area})
|
|
cmd := file.NewCmdWriteFile()
|
|
cmd := file.NewCmdWriteFile()
|
|
pack := bx.NewBxDataPackCmd(cmd)
|
|
pack := bx.NewBxDataPackCmd(cmd)
|
|
data := pack.Pack()
|
|
data := pack.Pack()
|
|
- fmt.Println("数据长度:", len(data))
|
|
|
|
- fmt.Printf("数据:% 02x\n", data)
|
|
|
|
s.send(data)
|
|
s.send(data)
|
|
resp := s.ReadResp()
|
|
resp := s.ReadResp()
|
|
if !resp.IsAck() {
|
|
if !resp.IsAck() {
|
|
@@ -170,9 +218,7 @@ func (s *Screen) TextFlash(msg string, color Color) {
|
|
}
|
|
}
|
|
pack1 := bx.NewBxDataPackCmd(cmd)
|
|
pack1 := bx.NewBxDataPackCmd(cmd)
|
|
data1 := pack1.Pack()
|
|
data1 := pack1.Pack()
|
|
- fmt.Println("数据长度:", len(data))
|
|
|
|
s.send(data1)
|
|
s.send(data1)
|
|
- fmt.Printf("数据1:% 02x\n", data1)
|
|
|
|
resp1 := s.ReadResp()
|
|
resp1 := s.ReadResp()
|
|
if resp1.NoError() {
|
|
if resp1.NoError() {
|
|
s.StateInfo.ProgramNum++
|
|
s.StateInfo.ProgramNum++
|