Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
HTAnticollision
Project
Project
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
马乐
HTAnticollision
Commits
f848c1da
Commit
f848c1da
authored
Mar 07, 2023
by
马乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.注册初步验证OK
2.鉴权初步验证OK 3.心跳OK
parent
02a36148
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
75 additions
and
49 deletions
+75
-49
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+3
-0
MainActivity.kt
app/src/main/java/com/waytous/anticollision/MainActivity.kt
+13
-0
MyApp.kt
app/src/main/java/com/waytous/anticollision/MyApp.kt
+9
-3
Session.kt
app/src/main/java/com/waytous/anticollision/tcp/Session.kt
+0
-0
SyncMessageListener.kt
...java/com/waytous/anticollision/tcp/SyncMessageListener.kt
+4
-3
SyncParser.kt
...src/main/java/com/waytous/anticollision/tcp/SyncParser.kt
+11
-7
TcpManager.kt
...src/main/java/com/waytous/anticollision/tcp/TcpManager.kt
+12
-11
HomeFragment.kt
...in/java/com/waytous/anticollision/ui/home/HomeFragment.kt
+20
-19
PreferenceDelegate.kt
...ava/com/waytous/anticollision/utils/PreferenceDelegate.kt
+3
-3
fragment_home.xml
app/src/main/res/layout/fragment_home.xml
+0
-3
No files found.
app/src/main/AndroidManifest.xml
View file @
f848c1da
...
...
@@ -3,7 +3,9 @@
xmlns:tools=
"http://schemas.android.com/tools"
>
<uses-permission
android:name=
"android.permission.READ_PRIVILEGED_PHONE_STATE"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
android:name=
".MyApp"
android:allowBackup=
"true"
android:dataExtractionRules=
"@xml/data_extraction_rules"
android:fullBackupContent=
"@xml/backup_rules"
...
...
@@ -11,6 +13,7 @@
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:usesCleartextTraffic=
"true"
android:theme=
"@style/Theme.HTAnticollision"
tools:targetApi=
"31"
>
<activity
...
...
app/src/main/java/com/waytous/anticollision/MainActivity.kt
View file @
f848c1da
...
...
@@ -8,7 +8,11 @@ import androidx.navigation.ui.setupWithNavController
import
com.blankj.utilcode.util.Utils
import
com.google.android.material.bottomnavigation.BottomNavigationView
import
com.gyf.immersionbar.ImmersionBar
import
com.waytous.anticollision.config.DeviceConfig
import
com.waytous.anticollision.databinding.ActivityMainBinding
import
com.waytous.anticollision.tcp.Session
import
io.github.toggery.jt808.messagebody.B8001
import
kotlin.concurrent.thread
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -25,6 +29,15 @@ class MainActivity : AppCompatActivity() {
binding
=
ActivityMainBinding
.
inflate
(
layoutInflater
)
setContentView
(
binding
.
root
)
initNavView
()
DeviceConfig
.
province
=
11
DeviceConfig
.
city
=
0
DeviceConfig
.
phoneNumber
=
"18801011111"
DeviceConfig
.
HostConfig
.
host
=
"192.168.9.48"
DeviceConfig
.
HostConfig
.
port
=
6608
val
session
=
Session
()
thread
{
session
.
login
()
}
}
private
fun
initNavView
(){
...
...
app/src/main/java/com/waytous/anticollision/MyApp.kt
View file @
f848c1da
...
...
@@ -5,10 +5,9 @@ import com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.SPStaticUtils
import
com.blankj.utilcode.util.SPUtils
import
com.blankj.utilcode.util.Utils
import
kotlin.properties.Delegates
object
MyApp
:
Application
()
{
lateinit
var
instance
:
MyApp
class
MyApp
:
Application
()
{
override
fun
onCreate
()
{
super
.
onCreate
()
...
...
@@ -17,4 +16,10 @@ object MyApp: Application() {
LogUtils
.
getConfig
().
globalTag
=
"Waytous"
SPStaticUtils
.
setDefaultSPUtils
(
SPUtils
.
getInstance
(
"settings"
))
}
companion
object
{
//情况一:声明可空的属性
private
var
instance
:
MyApp
by
Delegates
.
notNull
()
fun
instance
()
=
instance
}
}
\ No newline at end of file
app/src/main/java/com/waytous/anticollision/tcp/Session.kt
View file @
f848c1da
This diff is collapsed.
Click to expand it.
app/src/main/java/com/waytous/anticollision/tcp/SyncMessageListener.kt
View file @
f848c1da
...
...
@@ -3,17 +3,17 @@ package com.waytous.anticollision.tcp
/**
* 消息同步监听器
* */
interface
SyncMessageListener
<
T
>
{
interface
SyncMessageListener
<
in
T
>
{
/**
* 设备注册
* @param data
* */
fun
onSignUp
(
data
:
T
)
fun
onSignUp
(
payload
:
T
)
/**
* 平台通用应答
* @param data
* */
fun
onCommonResponse
(
data
:
T
)
fun
onCommonResponse
(
payload
:
T
)
}
\ No newline at end of file
app/src/main/java/com/waytous/anticollision/tcp/SyncParser.kt
View file @
f848c1da
...
...
@@ -3,7 +3,12 @@ package com.waytous.anticollision.tcp
import
com.blankj.utilcode.util.LogUtils
import
com.waytous.anticollision.BuildConfig
import
com.waytous.anticollision.utils.logd
import
io.github.toggery.jt808.codec.*
import
io.github.toggery.jt808.codec.Codec
import
io.github.toggery.jt808.codec.Message
import
io.github.toggery.jt808.codec.MessageMetadata
import
io.github.toggery.jt808.messagebody.AbstractToStringJoiner
import
io.github.toggery.jt808.messagebody.B8001
import
io.github.toggery.jt808.messagebody.B8100
import
io.netty.buffer.ByteBuf
import
io.netty.util.DefaultAttributeMap
import
io.netty.util.ReferenceCountUtil
...
...
@@ -13,7 +18,7 @@ import io.netty.util.ReferenceCountUtil
*
* @author male
* */
class
SyncParser
(
private
val
syncMessageListener
:
SyncMessageListener
<
Codec
<*>
>)
{
class
SyncParser
(
private
val
syncMessageListener
:
SyncMessageListener
<
AbstractToStringJoiner
>)
{
/**
* 解析字节流
...
...
@@ -21,13 +26,12 @@ class SyncParser(private val syncMessageListener: SyncMessageListener<Codec<*>>)
* */
fun
parse
(
buf
:
ByteBuf
){
try
{
val
message
:
Message
<
Codec
<*>
>
=
Message
.
decode
(
buf
,
MessageMetadata
.
outbounds
(),
DefaultAttributeMap
())
val
message
:
Message
<
AbstractToStringJoiner
>
=
Message
.
decode
(
buf
,
MessageMetadata
.
outbounds
(),
DefaultAttributeMap
())
logd
(
"【解析】:$message"
)
when
(
val
codec
:
Codec
<*>
=
message
.
body
){
is
B8
001Codec
->
syncMessageListener
.
onCommonResponse
(
codec
)
is
B8
100Codec
->
syncMessageListener
.
onSignUp
(
codec
)
when
(
val
payload
:
Any
=
message
.
body
){
is
B8
100
->
syncMessageListener
.
onSignUp
(
payload
)
is
B8
001
->
syncMessageListener
.
onCommonResponse
(
payload
)
}
LogUtils
.
d
(
message
.
toString
())
}
catch
(
e
:
Exception
)
{
if
(
BuildConfig
.
DEBUG
)
{
LogUtils
.
e
(
"parse received data error:${e.message}"
)
...
...
app/src/main/java/com/waytous/anticollision/tcp/TcpManager.kt
View file @
f848c1da
...
...
@@ -142,10 +142,12 @@ internal class TcpManager(
}
val
(
errCode
,
length
)
=
connection
.
receive
()
if
(
errCode
==
Error
.
NOError
)
{
if
(
length
>
0
)
{
val
buf
=
UnpooledByteBufAllocator
.
DEFAULT
.
buffer
(
length
)
buf
.
writeBytes
(
connection
.
buffer
,
0
,
length
)
connectListener
.
onDataReceived
(
buf
)
connection
.
buffer
.
fill
(
0
,
0
,
length
-
1
)
}
receiveExecutor
.
execute
{
receive
(
timeout
)
}
}
else
{
mCancel
.
set
(
true
)
...
...
@@ -212,14 +214,12 @@ internal class TcpManager(
* @param timeout
* @return Error
* */
fun
connect
(
host
:
String
,
port
:
Int
,
timeout
:
Int
,
receiveInterval
:
Int
=
2
):
Error
=
try
{
fun
connect
(
host
:
String
,
port
:
Int
,
timeout
:
Int
,
receiveInterval
:
Int
=
2
):
Error
{
try
{
receiveLock
.
lock
()
sendLock
.
lock
()
var
errorCode
:
Error
=
Error
.
NOError
if
(
socket
.
isConnected
&&
connectStatus
.
get
()
>
State
.
Disconnected
)
{
errorCode
=
Error
.
NOError
}
else
{
closeSocket
()
return
Error
.
NOError
}
connectStatus
.
set
(
State
.
Connecting
)
socket
.
soTimeout
=
receiveInterval
...
...
@@ -230,23 +230,24 @@ internal class TcpManager(
inputStream
=
socket
.
getInputStream
()
outputStream
=
socket
.
getOutputStream
()
connectStatus
.
set
(
State
.
Connected
)
errorCode
return
Error
.
NOError
}
catch
(
e
:
IOException
)
{
connectStatus
.
set
(
State
.
Disconnected
)
Error
.
IOError
return
Error
.
IOError
}
catch
(
e
:
SocketTimeoutException
)
{
connectStatus
.
set
(
State
.
Disconnected
)
Error
.
Timeout
return
Error
.
Timeout
}
catch
(
e
:
IllegalArgumentException
)
{
connectStatus
.
set
(
State
.
Disconnected
)
Error
.
InvalidParam
return
Error
.
InvalidParam
}
catch
(
e
:
Exception
)
{
connectStatus
.
set
(
State
.
Disconnected
)
Error
.
ServerUnknownError
return
Error
.
ServerUnknownError
}
finally
{
sendLock
.
unlock
()
receiveLock
.
unlock
()
}
}
/**
* 发送数据
...
...
@@ -292,7 +293,7 @@ internal class TcpManager(
Error
.
NotConnected
,
0
)
if
(
inputStream
.
available
()
<
0
)
return
ReceivedResult
(
Error
.
NOError
,
0
)
if
(
inputStream
.
available
()
<
=
0
)
return
ReceivedResult
(
Error
.
NOError
,
0
)
val
len
=
inputStream
.
read
(
buffer
)
return
if
(
len
>
0
)
{
ReceivedResult
(
Error
.
NOError
,
len
)
...
...
app/src/main/java/com/waytous/anticollision/ui/home/HomeFragment.kt
View file @
f848c1da
...
...
@@ -37,31 +37,31 @@ class HomeFragment : Fragment() {
_binding
=
FragmentHomeBinding
.
inflate
(
inflater
,
container
,
false
)
val
root
:
View
=
binding
.
root
//
val mapView: MapView = binding.mapView
val
mapView
=
MapView
(
this
.
context
!!
)
val
mapView
:
MapView
=
binding
.
mapView
//
val mapView = MapView(this.context!!)
mapView
.
getMapboxMap
().
setCamera
(
CameraOptions
.
Builder
()
.
center
(
Point
.
fromLngLat
(
LATITUDE
,
LONGITUDE
))
//
.center(
//
Point.fromLngLat(
//
LATITUDE,
//
LONGITUDE
//
))
.
zoom
(
ZOOM
).
build
()
)
mapView
.
getMapboxMap
().
loadStyle
(
style
(
Style
.
MAPBOX_STREET
S
){
mapView
.
getMapboxMap
().
loadStyle
(
style
(
Style
.
OUTDOOR
S
){
+
geoJsonSource
(
GEOJSON_SOURCE_ID
)
{
url
(
"multiple_geometry_example.geojson"
)
}
+
lineLayer
(
"linelayer"
,
GEOJSON_SOURCE_ID
)
{
lineCap
(
LineCap
.
ROUND
)
lineJoin
(
LineJoin
.
ROUND
)
lineOpacity
(
0.7
)
lineWidth
(
8.0
)
lineColor
(
"#888"
)
url
(
"asset://multiple_geometry_example.geojson"
)
}
// +lineLayer("linelayer", GEOJSON_SOURCE_ID) {
// lineCap(LineCap.ROUND)
// lineJoin(LineJoin.ROUND)
// lineOpacity(0.7)
// lineWidth(8.0)
// lineColor("#888")
// }
})
return
mapView
return
root
}
override
fun
onDestroyView
()
{
...
...
@@ -71,8 +71,8 @@ class HomeFragment : Fragment() {
companion
object
{
private
const
val
GEOJSON_SOURCE_ID
=
"geo-json"
private
const
val
LATITUDE
=
-
122.483696
private
const
val
LONGITUDE
=
3
7.83381
8
private
const
val
LATITUDE
=
-
77.0911931991577
private
const
val
LONGITUDE
=
3
8.9565388617423
8
private
const
val
ZOOM
=
14.0
}
}
\ No newline at end of file
app/src/main/java/com/waytous/anticollision/utils/PreferenceDelegate.kt
View file @
f848c1da
...
...
@@ -8,9 +8,9 @@ import kotlin.reflect.KProperty
class
PreferenceDelegate
<
T
>(
private
val
name
:
String
,
private
val
default
:
T
,
private
val
prefName
:
String
=
"settings"
)
:
ReadWriteProperty
<
Any
?,
T
>
{
private
val
prefs
:
SharedPreferences
by
lazy
{
MyApp
.
instance
.
applicationContext
.
getSharedPreferences
(
prefName
,
Context
.
MODE_PRIVATE
)
}
private
val
prefs
:
SharedPreferences
=
MyApp
.
instance
().
applicationContext
.
getSharedPreferences
(
prefName
,
Context
.
MODE_PRIVATE
)
@Synchronized
override
fun
getValue
(
thisRef
:
Any
?,
property
:
KProperty
<*>):
T
{
...
...
app/src/main/res/layout/fragment_home.xml
View file @
f848c1da
...
...
@@ -11,9 +11,6 @@
android:id=
"@+id/mapView"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
mapbox:mapbox_cameraTargetLat=
"40.7128"
mapbox:mapbox_cameraTargetLng=
"-74.0060"
mapbox:mapbox_cameraZoom=
"9.0"
mapbox:mapbox_resourcesAccessToken=
"@string/map_box_public_key"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
...
...
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