Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
SuZhouAvp
Commits
e32fe570
Commit
e32fe570
authored
Jun 13, 2025
by
p x
Browse files
proto
parent
816a069a
Changes
13
Show whitespace changes
Inline
Side-by-side
app/build.gradle.kts
View file @
e32fe570
import
org.gradle.internal.declarativedsl.parsing.main
import
org.jetbrains.kotlin.gradle.internal.wrapPluginOptions
plugins
{
alias
(
libs
.
plugins
.
android
.
application
)
alias
(
libs
.
plugins
.
kotlin
.
android
)
id
(
"dagger.hilt.android.plugin"
)
id
(
"kotlin-kapt"
)
id
(
"com.google.protobuf"
)
}
android
{
...
...
@@ -42,6 +46,38 @@ android {
abortOnError
=
false
checkReleaseBuilds
=
false
}
sourceSets
{
//配置 protoc 编译器
}
}
protobuf
{
//配置 protoc 编译器
// protoc {
// artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
// }
plugins
{
// The codegen for lite comes as a separate artifact
// artifacts {
// "com.google.protobuf:protoc-gen-javalite:3.0.0"
// }
}
//配置生成目录,编译后会在 build 的目录下生成对应的java文件
generateProtoTasks
{
all
().
forEach
{
task-
>
task
.
builtins
{
// remove(com.google.protobuf.gradle.ProtobufPlugin.j)
// remove(java)
}
task
.
builtins
{
java
{
}
}
}
}
}
dependencies
{
...
...
@@ -55,8 +91,14 @@ dependencies {
androidTestImplementation
(
libs
.
androidx
.
junit
)
androidTestImplementation
(
libs
.
androidx
.
espresso
.
core
)
implementation
(
"com.google.protobuf:protobuf-java:3.19.2"
)
// implementation("com.google.protobuf:protobuf-lite:3.0.0")
// implementation("com.google.protobuf:protobuf-lite:3.0.0")
// implementation("com.google.protobuf:protobuf-kotlin-lite:4.31.1")
//java web socket
implementation
(
"org.java-websocket:Java-WebSocket:1.6.0"
)
//proto
// Hilt dependencies
val
hilt_version
=
"2.56.1"
implementation
(
"com.google.dagger:hilt-android:$hilt_version"
)
...
...
app/src/main/assets/PointCloud.proto
0 → 100644
View file @
e32fe570
syntax
=
"proto3"
;
package
com
.
cusc.data.clean.module
;
option
java_multiple_files
=
true
;
option
java_outer_classname
=
"Point"
;
message
PointCloud
{
repeated
Result
results
=
1
;
}
message
Result
{
double
x
=
1
;
double
y
=
2
;
double
z
=
3
;
double
angle
=
4
;
}
app/src/main/assets/comfunc.js
0 → 100644
View file @
e32fe570
import
protoRoot
from
"
@/utils/ws/base
"
;
/**
* 解码通用的protobuf数据
* 推送格式映射在response.proto里的,使用此方法 !
* SocketResponse对应解码文件base.js里面的SocketResponse
*/
export
async
function
decodeResponseProtoBuf
(
msg
)
{
const
SocketResponse
=
protoRoot
.
lookup
(
"
SocketResponse
"
);
let
blob
=
msg
.
data
;
let
arrybuff
=
await
blob
.
arrayBuffer
();
let
uinit8
=
new
Uint8Array
(
arrybuff
);
const
result
=
SocketResponse
.
decode
(
uinit8
);
return
result
;
}
app/src/main/assets/response.proto
0 → 100644
View file @
e32fe570
syntax
=
"proto3"
;
option
java_package
=
"com.cusc.imserver.protocol"
;
message
SocketResponse
{
int32
code
=
1
;
string
msg
=
2
;
int32
msgType
=
3
;
//
string
data
=
4
;
}
app/src/main/java/com/sd/cavphmi/bean/ReqBean.kt
0 → 100644
View file @
e32fe570
package
com.sd.cavphmi.bean
/***
* 向websocket 订阅数据
* **/
class
ReqBean
{
val
msgType
=
2
var
data
=
""
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/repositorys/SpaceNoRepo.kt
View file @
e32fe570
package
com.sd.cavphmi.repositorys
import
com.google.gson.Gson
import
com.sd.cavphmi.bean.SpaceNoBean
import
com.sd.cavphmi.net.MyBaseResource
import
com.sd.cavphmi.net.MyResult
import
com.sd.cavphmi.net.RequestBodyUtil
import
com.sd.cavphmi.net.httpmothod.ClientRetrofitMethod
import
com.sd.cavphmi.websockets.MyWebSocketClient
import
retrofit2.HttpException
import
javax.inject.Inject
class
SpaceNoRepo
@Inject
constructor
(
var
clientRetrofitMethod
:
ClientRetrofitMethod
)
{
var
client
:
MyWebSocketClient
?
=
null
private
var
gson
=
Gson
()
// 2.2. 联网车辆位姿数据topic
fun
subVehicle
(){
}
fun
getSendData
(){
}
suspend
fun
getSpaceData
():
MyResult
<
SpaceNoBean
>
{
var
map
=
mutableMapOf
(
"pageNo"
to
20
,
"pageSize"
to
1000
)
var
body
=
RequestBodyUtil
.
toRequestBody
(
map
)
...
...
app/src/main/java/com/sd/cavphmi/ui/MainActivity.kt
View file @
e32fe570
...
...
@@ -40,7 +40,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainVm>() {
}
override
fun
getToData
()
{
// viewModel.getSpaceData()
}
override
fun
dispatchKeyEvent
(
event
:
KeyEvent
):
Boolean
{
...
...
app/src/main/java/com/sd/cavphmi/utils/MyContants.kt
View file @
e32fe570
...
...
@@ -2,11 +2,13 @@ package com.sd.cavphmi.utils
object
MyContants
{
const
val
IS_DEBUG
=
true
var
HOST
=
if
(
IS_DEBUG
)
"https://sip-avp.isungent.cn:8443"
else
""
// var PORT = if (IS_DEBUG) "123" else "34534"
//wss://faw.cuscavp.cn:8443/socket/ws?clientSource=100 长春
var
WS_HOST
=
if
(
IS_DEBUG
)
"wss://
sip-avp.isungent
.cn:8443/socket/ws?clientSource=100"
else
""
if
(
IS_DEBUG
)
"wss://
faw.cuscavp
.cn:8443/socket/ws?clientSource=100"
else
""
...
...
app/src/main/java/com/sd/cavphmi/viewmodels/MainVm.kt
View file @
e32fe570
...
...
@@ -2,9 +2,12 @@ package com.sd.cavphmi.viewmodels
import
android.content.Context
import
androidx.lifecycle.viewModelScope
import
com.google.gson.Gson
import
com.sd.cavphmi.base.MyBaseViewModel
import
com.sd.cavphmi.bean.ReqBean
import
com.sd.cavphmi.bean.SpaceNoBean
import
com.sd.cavphmi.bean.VToXImgBean
import
com.sd.cavphmi.bean.WebSetBean
import
com.sd.cavphmi.net.MyResult
import
com.sd.cavphmi.repositorys.SpaceNoRepo
import
com.sd.cavphmi.utils.MyContants
...
...
@@ -12,10 +15,10 @@ import com.sd.cavphmi.utils.ToastHelper
import
com.sd.cavphmi.websockets.MyWebSocketClient
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
org.java_websocket.
client.WebSocketClient
import
org.java_websocket.
handshake.ServerHandshake
import
java.net.URI
import
java.nio.ByteBuffer
import
javax.inject.Inject
...
...
@@ -25,15 +28,21 @@ class MainVm @Inject constructor(
var
spaceNoRepo
:
SpaceNoRepo
)
:
MyBaseViewModel
()
{
private
var
client
:
MyWebSocketClient
?
=
null
private
var
gson
=
Gson
()
fun
startWS
()
{
val
httpHeaders
=
mutableMapOf
<
String
,
String
>()
httpHeaders
.
put
(
"Cookie"
,
"username=nemo"
)
try
{
client
=
MyWebSocketClient
(
URI
(
MyContants
.
WS_HOST
))
client
?.
onSocketCb
=
onSocketCb
client
?.
connect
()
}
catch
(
e
:
Exception
)
{
}
}
fun
closeWS
()
{
...
...
@@ -42,6 +51,42 @@ class MainVm @Inject constructor(
}
}
var
onSocketCb
=
object
:
MyWebSocketClient
.
OnSocketCb
{
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
println
(
"--------Thread.currentThread() = ${Thread.currentThread()}"
)
subVehicle
()
}
override
fun
onMessage
(
message
:
String
?)
{
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
}
override
fun
onError
(
ex
:
Exception
?)
{
}
}
/*** 2.2. 联网车辆位姿数据topic**/
fun
subVehicle
()
{
var
reqStr
=
getSendData
(
"/topic/vehicle"
)
client
?.
send
(
reqStr
)
}
fun
getSendData
(
key
:
String
):
String
{
var
data
=
WebSetBean
.
dic
.
get
(
key
)
var
req
=
ReqBean
()
req
.
data
=
data
!!
var
str
=
gson
.
toJson
(
req
)
return
str
}
fun
showVToTip
()
{
var
imgs
=
VToXImgBean
.
imgs
ToastHelper
.
showCustViewShort
(
context
,
imgs
.
get
(
"2"
)
!!
)
...
...
@@ -54,6 +99,7 @@ class MainVm @Inject constructor(
is
MyResult
.
Success
<
SpaceNoBean
>
->
{
var
a
=
0
}
else
->
{
var
b
=
0
}
...
...
app/src/main/java/com/sd/cavphmi/websockets/MyWebSocketClient.kt
View file @
e32fe570
...
...
@@ -3,7 +3,6 @@ package com.sd.cavphmi.websockets
import
org.java_websocket.client.WebSocketClient
import
org.java_websocket.drafts.Draft
import
org.java_websocket.handshake.ServerHandshake
import
java.lang.Exception
import
java.net.URI
import
java.nio.ByteBuffer
...
...
@@ -22,12 +21,15 @@ class MyWebSocketClient : WebSocketClient {
override
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
{
send
(
"Hello, it is me. Mario :)"
)
//
send("Hello, it is me. Mario :)")
System
.
out
.
println
(
TAG
+
"new connection opened"
)
onSocketCb
?.
onOpen
(
handshakedata
)
}
override
fun
onMessage
(
message
:
String
?)
{
System
.
out
.
println
(
TAG
+
"received message: "
+
message
);
onSocketCb
?.
onMessage
(
message
)
//处理各种推送消息
// let data = {};
// let result = await decodeResponseProtoBuf(msg);
...
...
@@ -46,15 +48,28 @@ class MyWebSocketClient : WebSocketClient {
}
override
fun
onMessage
(
bytes
:
ByteBuffer
?)
{
System
.
out
.
println
(
TAG
+
"received ByteBuffer"
)
System
.
out
.
println
(
TAG
+
" received ByteBuffer"
)
onSocketCb
?.
onMessage
(
bytes
)
}
override
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
{
System
.
out
.
println
(
TAG
+
"closed with exit code "
+
code
+
" additional info: "
+
reason
);
System
.
out
.
println
(
TAG
+
" closed with exit code "
+
code
+
" additional info: "
+
reason
);
onSocketCb
?.
onClose
(
code
,
reason
,
remote
)
}
override
fun
onError
(
ex
:
Exception
?)
{
System
.
err
.
println
(
TAG
+
"an error occurred:"
+
ex
);
onSocketCb
?.
onError
(
ex
)
}
var
onSocketCb
:
OnSocketCb
?
=
null
interface
OnSocketCb
{
fun
onOpen
(
handshakedata
:
ServerHandshake
?)
fun
onMessage
(
message
:
String
?)
fun
onMessage
(
bytes
:
ByteBuffer
?)
fun
onClose
(
code
:
Int
,
reason
:
String
?,
remote
:
Boolean
)
fun
onError
(
ex
:
Exception
?)
}
...
...
app/src/main/proto/response.proto
0 → 100644
View file @
e32fe570
syntax
=
"proto3"
;
package
com
.
sd.cavphmi
;
message
SocketResponse
{
int32
code
=
1
;
string
msg
=
2
;
int32
msgType
=
3
;
//
string
data
=
4
;
}
build.gradle.kts
View file @
e32fe570
...
...
@@ -2,6 +2,7 @@
buildscript
{
dependencies
{
classpath
(
libs
.
hilt
.
android
.
gradle
.
plugin
)
classpath
(
"com.google.protobuf:protobuf-gradle-plugin:0.8.19"
)
}
}
plugins
{
...
...
gradle/libs.versions.toml
View file @
e32fe570
...
...
@@ -11,6 +11,7 @@ material = "1.12.0"
activity
=
"1.10.1"
constraintlayout
=
"2.2.1"
[libraries]
androidx-core-ktx
=
{
group
=
"androidx.core"
,
name
=
"core-ktx"
,
version.ref
=
"coreKtx"
}
hilt-android-gradle-plugin
=
{
module
=
"com.google.dagger:hilt-android-gradle-plugin"
,
version.ref
=
"hiltAndroidGradlePlugin"
}
...
...
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