-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreader.go
50 lines (47 loc) · 1.14 KB
/
reader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"io"
"strings"
)
var check_return bool = false
var collect_reply bool = false
var incoming_sms chan string = make(chan string, 1)
var proceed chan string = make(chan string, 1)
var collect chan []string = make(chan []string, 1)
func reader(reader io.Reader) {
//buffered := bufio.NewReader(reader)
var buf []byte
var collect_buf []string
for true {
var input []byte = make([]byte, 1)
reader.Read(input)
buf = append(buf, input[0])
casted := string(buf)
if strings.HasSuffix(casted, "\r\n") {
casted = casted[:len(casted)-2]
//fmt.Println(casted)
if collect_reply {
collect_buf = append(collect_buf, casted)
if casted == "OK" {
//this was the last line to collect.
collect <- collect_buf
collect_buf = nil
collect_reply = false
}
}
if check_return && casted == "OK" {
proceed <- casted
}
if check_return && casted == "ERROR" {
proceed <- casted
}
if strings.HasPrefix(casted, "+CMTI: \"SM\",") {
//let's get the index of the string.
components := strings.Split(casted, ",")
idx := components[1]
incoming_sms <- idx
}
buf = nil
}
}
}