Commit ccc6bf40 by 이병복

테스트 프로그램수정

parent 49b573dd
package main package main
import ( import (
"encoding/binary"
"fmt" "fmt"
"net" "net"
"time" "time"
"golang.org/x/text/encoding/korean"
) )
var testData = [][]byte{
{64, 1, 24, 7, 11, 13, 49, 17, 0, 0, 1, 1, 0, 0, 1, 2, 50, 195, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 161, 186, 241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{64, 0, 24, 7, 11, 13, 49, 18, 0, 0, 1, 1, 0, 0, 1, 2, 50, 195, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 161, 186, 241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{64, 1, 24, 7, 11, 13, 49, 19, 0, 0, 1, 1, 0, 0, 1, 2, 50, 195, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 161, 186, 241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{64, 0, 24, 7, 11, 13, 49, 20, 0, 0, 1, 1, 0, 0, 1, 2, 50, 195, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 161, 186, 241, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
func main() { func main() {
listener, err := net.Listen("tcp", ":12345") listener, err := net.Listen("tcp", ":12345")
if err != nil { if err != nil {
...@@ -31,52 +35,17 @@ func main() { ...@@ -31,52 +35,17 @@ func main() {
func handleConnection(conn net.Conn) { func handleConnection(conn net.Conn) {
defer conn.Close() defer conn.Close()
for { fmt.Println("New client connected")
// 테스트 데이터 생성
testData := createTestData()
_, err := conn.Write(testData) for {
for _, data := range testData {
_, err := conn.Write(data)
if err != nil { if err != nil {
fmt.Println("Error sending data:", err) fmt.Println("Error sending data:", err)
return return
} }
fmt.Printf("Sent data: %v\n", data)
time.Sleep(10 * time.Second) // 10초마다 데이터 전송 time.Sleep(5 * time.Second) // 5초 간격으로 데이터 전송
}
} }
}
func createTestData() []byte {
data := make([]byte, 64)
// Log_size
data[0] = 64
// Log_type
data[1] = 1
// Log_datetime (2024-07-01 15:30:00)
binary.LittleEndian.PutUint16(data[2:4], 2024)
data[4] = 7 // month
data[5] = 1 // day
data[6] = 15 // hour
data[7] = 30 // minute
data[8] = 0 // second
// Log_On
data[9] = 1
// Log_Address
copy(data[10:17], []byte("A1B2C3D"))
// Log_Area (EUC-KR 인코딩)
area := "소방서 1"
areaEncoded, _ := korean.EUCKR.NewEncoder().Bytes([]byte(area))
copy(data[17:41], areaEncoded)
// Log_Device (EUC-KR 인코딩)
device := "연기감지기"
deviceEncoded, _ := korean.EUCKR.NewEncoder().Bytes([]byte(device))
copy(data[41:], deviceEncoded)
return data
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment