check telegram string
This commit is contained in:
+3
-1
@@ -55,7 +55,6 @@ func init() {
|
|||||||
// startCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
// startCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func start(cmd *cobra.Command, args []string) {
|
func start(cmd *cobra.Command, args []string) {
|
||||||
// Go signal notification works by sending `os.Signal`
|
// Go signal notification works by sending `os.Signal`
|
||||||
// values on a channel. We'll create a channel to
|
// 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()
|
buffer, count := utils.ReadPort()
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
|
if lograw {
|
||||||
log.Print(string(buffer))
|
log.Print(string(buffer))
|
||||||
}
|
}
|
||||||
|
utils.Append(buffer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
<-done
|
<-done
|
||||||
fmt.Println("exiting")
|
fmt.Println("exiting")
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user