check telegram string

This commit is contained in:
w1ndyb0y
2020-12-21 16:18:08 +08:00
parent 8a116818cf
commit 481870cea9
2 changed files with 43 additions and 3 deletions
+3 -1
View File
@@ -55,7 +55,6 @@ func init() {
// startCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func start(cmd *cobra.Command, args []string) {
// Go signal notification works by sending `os.Signal`
// values on a channel. We'll create a channel to
@@ -95,8 +94,11 @@ func start(cmd *cobra.Command, args []string){
}
buffer, count := utils.ReadPort()
if count > 0 {
if lograw {
log.Print(string(buffer))
}
utils.Append(buffer)
}
}
<-done
fmt.Println("exiting")
+38
View File
@@ -0,0 +1,38 @@
package utils
import (
"log"
"regexp"
"strings"
)
const (
StartTag = "ZCZC"
EndTag = "NNNN"
Expression = "(?s)ZCZC.*NNNN"
)
var buffer []byte
func Append(data []byte) {
buffer = append(buffer, data...)
if buffer[len(buffer)-1] == '\r' {
buffer = append(buffer, '\n')
}
check()
}
func check() {
teleString := string(buffer)
if strings.Index(teleString, EndTag) > 0 {
exp, _ := regexp.Compile(Expression)
telegram := exp.FindString(string(buffer))
if len(telegram) > 0 {
log.Println("telegram : ", telegram)
buffer = nil
//TODO save telegram
}
}
}