Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
2401-0022-lte-fire-alarm
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
이병복
2401-0022-lte-fire-alarm
Commits
7d9b616e
Commit
7d9b616e
authored
Jul 15, 2024
by
이병복
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
최신커밋
parent
ccc6bf40
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
8 deletions
+115
-8
main.go
cmd/app-hangul-test/main.go
+70
-0
main.go
cmd/app-lte-alarm/main.go
+45
-8
No files found.
cmd/app-hangul-test/main.go
0 → 100644
View file @
7d9b616e
package
main
import
(
"encoding/hex"
"fmt"
"io"
"strings"
"golang.org/x/text/encoding/korean"
"golang.org/x/text/transform"
)
// UTF-8 문자열을 hex로 변환
func
utf8ToHex
(
s
string
)
string
{
return
hex
.
EncodeToString
([]
byte
(
s
))
}
// UTF-8 문자열을 EUC-KR hex로 변환
func
utf8ToEUCKRHex
(
s
string
)
(
string
,
error
)
{
encoder
:=
korean
.
EUCKR
.
NewEncoder
()
eucKRBytes
,
_
,
err
:=
transform
.
Bytes
(
encoder
,
[]
byte
(
s
))
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"EUC-KR encoding error: %v"
,
err
)
}
return
hex
.
EncodeToString
(
eucKRBytes
),
nil
}
// EUC-KR hex를 한글(UTF-8)로 변환
func
eucKRHexToUTF8
(
hexString
string
)
(
string
,
error
)
{
bytes
,
err
:=
hex
.
DecodeString
(
hexString
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"hex decoding error: %v"
,
err
)
}
decoder
:=
korean
.
EUCKR
.
NewDecoder
()
reader
:=
transform
.
NewReader
(
strings
.
NewReader
(
string
(
bytes
)),
decoder
)
result
,
err
:=
io
.
ReadAll
(
reader
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"EUC-KR decoding error: %v"
,
err
)
}
return
string
(
result
),
nil
}
func
main
()
{
// 사용자로부터 UTF-8 한글 입력 받기
var
koreanInput
string
fmt
.
Print
(
"한글을 입력하세요 (UTF-8): "
)
fmt
.
Scanln
(
&
koreanInput
)
// 1. UTF-8 한글을 hex로 변환
utf8Hex
:=
utf8ToHex
(
koreanInput
)
fmt
.
Printf
(
"1. UTF-8 Hex: %s
\n
"
,
utf8Hex
)
// 2. UTF-8 한글을 EUC-KR hex로 변환
eucKRHex
,
err
:=
utf8ToEUCKRHex
(
koreanInput
)
if
err
!=
nil
{
fmt
.
Printf
(
"Error converting to EUC-KR hex: %v
\n
"
,
err
)
return
}
fmt
.
Printf
(
"2. EUC-KR Hex: %s
\n
"
,
eucKRHex
)
// 3. EUC-KR hex를 다시 한글(UTF-8)로 변환
koreanOutput
,
err
:=
eucKRHexToUTF8
(
eucKRHex
)
if
err
!=
nil
{
fmt
.
Printf
(
"Error converting back to Korean: %v
\n
"
,
err
)
return
}
fmt
.
Printf
(
"3. Decoded Korean (UTF-8): %s
\n
"
,
koreanOutput
)
}
cmd/app-lte-alarm/main.go
View file @
7d9b616e
...
...
@@ -38,14 +38,22 @@ type LogEntry struct {
// JSONLogEntry 구조체 정의 (이전과 동일)
type
JSONLogEntry
struct
{
CallNo
string
`json:"callNo"`
Type
uint8
`json:"type"`
DateTime
string
`json:"dateTime"`
On
uint8
`json:"on
"`
Address
string
`json:"addr
ess
"`
Area
string
`json:"
area
"`
Device
string
`json:"device"`
Status
string
`json:"status
"`
Address
string
`json:"addr"`
Area
string
`json:"
zoneNm
"`
Device
string
`json:"device
Nm
"`
}
// callNo string
// type int
// status string
// zoneNm string
// deviceNm string
// addr string
var
config
Config
func
loadConfig
()
error
{
...
...
@@ -164,6 +172,15 @@ func Deserialize(data []byte) (*LogEntry, error) {
return
nil
,
fmt
.
Errorf
(
"invalid data length: expected , got %d"
,
le
.
Size
)
}
// 수신기에서 넘어오는 타입 값
// 1: 화재
// 2: 고장
// 3: 설비
// 4: 출력
// 5: 운영
// 6: 축적
// 7: 아나로그감지기 예비경보
// 8: 화재복구
le
.
Type
=
data
[
1
]
le
.
DateTime
=
fmt
.
Sprintf
(
"%02d-%02d-%02d %02d:%02d:%02d"
,
(
int
(
data
[
2
])
+
2000
),
data
[
3
],
data
[
4
],
data
[
5
],
data
[
6
],
data
[
7
])
le
.
On
=
data
[
8
]
...
...
@@ -202,13 +219,33 @@ func convertToJSON(le *LogEntry) ([]byte, error) {
return
nil
,
err
}
// 로그 타입 변경
switch
le
.
Type
{
case
1
:
le
.
Type
=
6
// 화재
case
2
:
le
.
Type
=
2
// 고장
case
3
:
le
.
Type
=
3
// 설비
case
4
:
le
.
Type
=
4
// 출력
}
jsonLE
:=
JSONLogEntry
{
CallNo
:
"010-0000-0000"
,
Type
:
le
.
Type
,
DateTime
:
le
.
DateTime
,
On
:
le
.
On
,
Address
:
fmt
.
Sprintf
(
"%d%d-%d-%d%d%d-%d"
,
le
.
Address
[
0
],
le
.
Address
[
1
],
le
.
Address
[
2
],
le
.
Address
[
3
],
le
.
Address
[
4
],
le
.
Address
[
5
],
le
.
Address
[
6
]),
Area
:
area
,
Device
:
device
,
Status
:
func
()
string
{
if
le
.
On
==
1
{
return
"동작"
}
return
"해제"
}(),
Address
:
fmt
.
Sprintf
(
"%d%d-%d-%d%d%d-%d"
,
le
.
Address
[
0
],
le
.
Address
[
1
],
le
.
Address
[
2
],
le
.
Address
[
3
],
le
.
Address
[
4
],
le
.
Address
[
5
],
le
.
Address
[
6
]),
Area
:
area
,
Device
:
device
,
}
return
json
.
Marshal
(
jsonLE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment