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"
"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("打印机离线!")

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))
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
}