This commit is contained in:
邹宗楠
2022-07-27 17:46:26 +08:00
parent de5bff6892
commit 9d0d0f5e21
2 changed files with 28 additions and 36 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"git.rosy.net.cn/baseapi/utils" "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/business/model/dao"
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
"io" "io"
@@ -23,7 +22,6 @@ func ListenTcp() {
return return
} }
globals.SugarLogger.Debugf("begin listenTcp port 8000......") globals.SugarLogger.Debugf("begin listenTcp port 8000......")
globals.SugarLogger.Debugf("begin listenTcp port 8000......刘磊")
for { for {
c, err := l.Accept() c, err := l.Accept()
if err != nil { if err != nil {
@@ -35,7 +33,6 @@ func ListenTcp() {
} }
func (t *TcpClient) handleConn(c net.Conn) { func (t *TcpClient) handleConn(c net.Conn) {
globals.SugarLogger.Debugf("begin listenTcp port 8000......刘磊2")
if c == nil { if c == nil {
globals.SugarLogger.Debugf("conn is nil") globals.SugarLogger.Debugf("conn is nil")
return return
@@ -67,7 +64,6 @@ func (t *TcpClient) handleConn(c net.Conn) {
//} //}
//看是心跳还是打印回调 //看是心跳还是打印回调
data := hex.EncodeToString(buffer[:n]) data := hex.EncodeToString(buffer[:n])
globals.SugarLogger.Debugf("handleConn msg ....................liulei: %v", data)
//证明是心跳 //证明是心跳
if strings.Contains(data, heartText) { if strings.Contains(data, heartText) {
globals.SugarLogger.Debugf("handleConn heart: %v", data) globals.SugarLogger.Debugf("handleConn heart: %v", data)
@@ -225,8 +221,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
//只有在线才打印内容 //只有在线才打印内容
case printerStatusOnline: case printerStatusOnline:
if c = t.getPrintConn(printMsg.PrintNo); c != nil { if c = t.getPrintConn(printMsg.PrintNo); c != nil {
//data, err = buildMsg(printMsg) data, err = buildMsg(printMsg)
data = jxutils.Hextob("1e00140200ff50bc147df3d71b401B59415515" + "ff")
} }
case printerStatusOffline: case printerStatusOffline:
err = fmt.Errorf("打印机离线!") err = fmt.Errorf("打印机离线!")

View File

@@ -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)) lenData := int64(len(str) + len(const1) + len(orderNoHexH) + len(orderNoHexL) + len(printInit) + 2 + 4 + len(printData))
x1, x2 := int2h8l8(lenData / 2) x1, x2 := int2h8l8(lenData / 2)
dataStr := str + x1 + x2 + const1 + orderNoHexH + orderNoHexL + printInit + printData dataStr := str + x1 + x2 + const1 + orderNoHexH + orderNoHexL + printInit + printData
dataStr = `1e00140200ff50bc147df3d71b401B59415515` check := getCheckSum(dataStr)
//check := getCheckSum(dataStr) return jxutils.Hextob(dataStr + check), err
//return jxutils.Hextob(dataStr + check), err
return jxutils.Hextob(dataStr + "ff"), err
} }
//替换特殊字符上面那个hextob转不了先替换一下 //替换特殊字符上面那个hextob转不了先替换一下
@@ -491,36 +489,35 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
int16Sound := strconv.FormatInt(intSound, 16) int16Sound := strconv.FormatInt(intSound, 16)
voice += int16Sound voice += int16Sound
} }
globals.SugarLogger.Debug("voice==================", voice)
result = strings.ReplaceAll(result, sound, "") 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 strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
// if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 { if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {
// sound := sounds[1] sound := sounds[1]
// if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil { if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil {
// //先把结束标签消了 //先把结束标签消了
// result = strings.ReplaceAll(result, byteSignSoundE, "") result = strings.ReplaceAll(result, byteSignSoundE, "")
// soundPrefix := "" soundPrefix := ""
// if printer.Sound != "" { if printer.Sound != "" {
// soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound
// } else { } else {
// soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]"
// } }
// hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix)) hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
// hexPrefixStr := hex.EncodeToString(hexPrefix) hexPrefixStr := hex.EncodeToString(hexPrefix)
// realSound := hexPrefixStr + sound realSound := hexPrefixStr + sound
// allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2) allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
// if len(allLen) < 2 { if len(allLen) < 2 {
// allLen = "0" + allLen allLen = "0" + allLen
// } }
// soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2)) soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2))
// result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr) result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr)
// } }
// } }
//} }
return result return result
} }