From 9d0d0f5e2145735381b00b6459864a3d40e6a87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Wed, 27 Jul 2022 17:46:26 +0800 Subject: [PATCH] 1 --- business/jxstore/event/event_tcp.go | 7 +-- business/jxstore/event/event_tcp_utils.go | 57 +++++++++++------------ 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index 7fe6e3f3b..dbda527d5 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "fmt" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/globals" "io" @@ -23,7 +22,6 @@ func ListenTcp() { return } globals.SugarLogger.Debugf("begin listenTcp port 8000......") - globals.SugarLogger.Debugf("begin listenTcp port 8000......刘磊") for { c, err := l.Accept() if err != nil { @@ -35,7 +33,6 @@ func ListenTcp() { } func (t *TcpClient) handleConn(c net.Conn) { - globals.SugarLogger.Debugf("begin listenTcp port 8000......刘磊2") if c == nil { globals.SugarLogger.Debugf("conn is nil") return @@ -67,7 +64,6 @@ func (t *TcpClient) handleConn(c net.Conn) { //} //看是心跳还是打印回调 data := hex.EncodeToString(buffer[:n]) - globals.SugarLogger.Debugf("handleConn msg ....................liulei: %v", data) //证明是心跳 if strings.Contains(data, heartText) { globals.SugarLogger.Debugf("handleConn heart: %v", data) @@ -225,8 +221,7 @@ func (t *TcpClient) doPrint(key string) (err error) { //只有在线才打印内容 case printerStatusOnline: if c = t.getPrintConn(printMsg.PrintNo); c != nil { - //data, err = buildMsg(printMsg) - data = jxutils.Hextob("1e00140200ff50bc147df3d71b401B59415515" + "ff") + data, err = buildMsg(printMsg) } case printerStatusOffline: err = fmt.Errorf("打印机离线!") diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 6ac593217..198e8b296 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -377,10 +377,8 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) { lenData := int64(len(str) + len(const1) + len(orderNoHexH) + len(orderNoHexL) + len(printInit) + 2 + 4 + len(printData)) x1, x2 := int2h8l8(lenData / 2) dataStr := str + x1 + x2 + const1 + orderNoHexH + orderNoHexL + printInit + printData - dataStr = `1e00140200ff50bc147df3d71b401B59415515` - //check := getCheckSum(dataStr) - //return jxutils.Hextob(dataStr + check), err - return jxutils.Hextob(dataStr + "ff"), err + check := getCheckSum(dataStr) + return jxutils.Hextob(dataStr + check), err } //替换特殊字符,上面那个hextob转不了,先替换一下 @@ -491,36 +489,35 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { int16Sound := strconv.FormatInt(intSound, 16) voice += int16Sound } - globals.SugarLogger.Debug("voice==================", voice) result = strings.ReplaceAll(result, sound, "") - result = strings.ReplaceAll(result, byteSignSound, "1B59415502") + result = strings.ReplaceAll(result, byteSignSound, hexSignSoundSolidification+voice) } } // 自动合成语音功能 - //if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { - // if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 { - // sound := sounds[1] - // if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil { - // //先把结束标签消了 - // result = strings.ReplaceAll(result, byteSignSoundE, "") - // soundPrefix := "" - // if printer.Sound != "" { - // soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound - // } else { - // soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" - // } - // hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix)) - // hexPrefixStr := hex.EncodeToString(hexPrefix) - // realSound := hexPrefixStr + sound - // allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2) - // if len(allLen) < 2 { - // allLen = "0" + allLen - // } - // soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2)) - // result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr) - // } - // } - //} + if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { + if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 { + sound := sounds[1] + if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil { + //先把结束标签消了 + result = strings.ReplaceAll(result, byteSignSoundE, "") + soundPrefix := "" + if printer.Sound != "" { + soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound + } else { + soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + } + hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix)) + hexPrefixStr := hex.EncodeToString(hexPrefix) + realSound := hexPrefixStr + sound + allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2) + if len(allLen) < 2 { + allLen = "0" + allLen + } + soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2)) + result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr) + } + } + } return result }