Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-charging-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 28fd649c
authored
Nov 03, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
LoginReq
1 parent
81f2091a
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
127 additions
and
168 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/ClientMain.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/Ocpp16Helper.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/ServerMain.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/base/TcpMapper.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/TcpClient.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/TcpClientHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/handler/LoginRspHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/data/LoginRspData.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/impl/LoginReq.java → platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/protocol/LoginReq.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/impl/LoginRsp.java → platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/protocol/LoginRsp.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/server/TcpServerHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/handler/LoginReqHandler.java → platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/server/handler/DefaultReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/server/handler/LoginReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/ClientMain.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.client.TcpClient
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.client.TcpClient
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.client.TcpHandlerHelper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.data.LoginReqData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.protocol.LoginReq
;
public
class
ClientMain
{
public
class
ClientMain
{
...
@@ -11,14 +12,15 @@ public class ClientMain {
...
@@ -11,14 +12,15 @@ public class ClientMain {
if
(
instance
==
null
)
{
if
(
instance
==
null
)
{
System
.
setProperty
(
"file.encoding"
,
"UTF-8"
);
System
.
setProperty
(
"file.encoding"
,
"UTF-8"
);
TcpHandlerHelper
.
scan
();
String
host
=
"localhost"
;
String
host
=
"localhost"
;
int
port
=
8888
;
int
port
=
8888
;
host
=
Ocpp16Constants
.
getTcpHost
();
host
=
Ocpp16Constants
.
getTcpHost
();
port
=
Ocpp16Constants
.
getTcpPort
();
port
=
Ocpp16Constants
.
getTcpPort
();
host
=
"121.199.192.223"
;
port
=
8768
;
TcpClient
p
=
new
TcpClient
(
host
,
port
);
TcpClient
p
=
new
TcpClient
(
host
,
port
);
p
.
start
();
p
.
start
();
...
@@ -27,7 +29,17 @@ public class ClientMain {
...
@@ -27,7 +29,17 @@ public class ClientMain {
return
instance
;
return
instance
;
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
getInstance
();
TcpClient
client
=
getInstance
();
Thread
.
sleep
(
3000
);
LoginReq
req
=
new
LoginReq
();
req
.
setData
(
new
LoginReqData
());
byte
[]
bs
=
Ocpp16Helper
.
build
(
req
);
client
.
sendSync
(
bs
);
// 定期心跳
}
}
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/Ocpp16Helper.java
View file @
28fd649
...
@@ -12,7 +12,7 @@ import com.google.common.collect.Maps;
...
@@ -12,7 +12,7 @@ import com.google.common.collect.Maps;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.data.LoginReqData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.data.LoginReqData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
imp
l.LoginReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
protoco
l.LoginReq
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.ClassUtil
;
import
cn.com.glsx.charging.util.ClassUtil
;
import
cn.com.glsx.charging.util.ClassUtils
;
import
cn.com.glsx.charging.util.ClassUtils
;
...
@@ -66,11 +66,11 @@ public class Ocpp16Helper {
...
@@ -66,11 +66,11 @@ public class Ocpp16Helper {
}
}
}
}
public
static
short
generateSeq
(
String
channelId
)
{
public
static
short
generateSeq
(
String
channelId
)
{
AtomicInteger
ai
=
seqFactorys
.
get
(
channelId
);
AtomicInteger
ai
=
seqFactorys
.
get
(
channelId
);
if
(
ai
==
null
)
{
if
(
ai
==
null
)
{
ai
=
new
AtomicInteger
();
ai
=
new
AtomicInteger
();
seqFactorys
.
put
(
channelId
,
ai
);
}
}
int
rs
=
ai
.
incrementAndGet
();
int
rs
=
ai
.
incrementAndGet
();
return
(
short
)
rs
;
// 溢出自动清零
return
(
short
)
rs
;
// 溢出自动清零
...
@@ -93,6 +93,16 @@ public class Ocpp16Helper {
...
@@ -93,6 +93,16 @@ public class Ocpp16Helper {
return
crc
==
b
.
getCrc
();
return
crc
==
b
.
getCrc
();
}
}
// TODO
public
static
String
bcdToStr
(
byte
[]
bs
)
{
return
new
String
(
bs
);
}
public
static
byte
[]
strToBcd
(
String
s
,
byte
[]
bs
)
{
// TODO 不足 位补 0
return
bs
;
}
public
static
byte
[]
build
(
Object
d
)
{
public
static
byte
[]
build
(
Object
d
)
{
// 创建一个 ByteBuf 对象
// 创建一个 ByteBuf 对象
ByteBuf
byteBuf
=
Unpooled
.
buffer
(
Ocpp16Constants
.
TCP_MAX_LENGTH
);
ByteBuf
byteBuf
=
Unpooled
.
buffer
(
Ocpp16Constants
.
TCP_MAX_LENGTH
);
...
@@ -108,19 +118,25 @@ public class Ocpp16Helper {
...
@@ -108,19 +118,25 @@ public class Ocpp16Helper {
Object
v
=
f
.
get
(
d
);
Object
v
=
f
.
get
(
d
);
if
(
v
instanceof
byte
[])
{
if
(
v
instanceof
byte
[])
{
byteBuf
.
writeBytes
((
byte
[])
v
);
byteBuf
.
writeBytes
((
byte
[])
v
);
}
else
if
(
v
instanceof
Byte
)
{
}
else
if
(
v
instanceof
Byte
)
{
byteBuf
.
writeByte
((
byte
)
v
);
byteBuf
.
writeByte
((
byte
)
v
);
}
else
if
(
v
instanceof
Short
)
{
}
else
if
(
v
instanceof
Short
)
{
byteBuf
.
writeByte
((
short
)
v
);
byteBuf
.
writeShort
((
short
)
v
);
}
else
if
(
v
instanceof
Integer
)
{
}
else
if
(
v
instanceof
Integer
)
{
byteBuf
.
writeByte
((
int
)
v
);
byteBuf
.
writeInt
((
int
)
v
);
}
else
if
(
v
instanceof
String
)
{
}
else
if
(
v
instanceof
String
)
{
// byteBuf.writeCharSequence((CharSequence) v, Charset.forName("UTF-8")); //TODO 字符串暂时按byte[]来定义,以方便确定长度
// byteBuf.writeCharSequence((CharSequence) v, Charset.forName("UTF-8")); //TODO 字符串暂时按byte[]来定义,以方便确定长度
}
else
if
(
v
instanceof
TcpData
)
{
}
else
if
(
v
instanceof
TcpData
)
{
byte
[]
bs
=
build
(
v
);
byte
[]
bs
=
build
(
v
);
byteBuf
.
writeBytes
(
bs
);
byteBuf
.
writeBytes
(
bs
);
}
}
log
.
debug
(
"build:{} field:{} value:{}"
,
d
.
getClass
().
getSimpleName
(),
f
.
getName
(),
v
);
// log.info("build:{} field:{} value:{} -- {}", d.getClass().getSimpleName(), f.getName(), v, byteBuf.readableBytes()
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -140,11 +156,23 @@ public class Ocpp16Helper {
...
@@ -140,11 +156,23 @@ public class Ocpp16Helper {
byte
type
=
ByteUtils
.
getByte
(
bs
);
byte
type
=
ByteUtils
.
getByte
(
bs
);
Pair
<
Class
<?
extends
TcpBase
>,
Class
<?
extends
TcpData
>>
pair
=
protocols
.
get
(
type
);
Pair
<
Class
<?
extends
TcpBase
>,
Class
<?
extends
TcpData
>>
pair
=
protocols
.
get
(
type
);
P
p
=
null
;
try
{
try
{
P
p
=
(
P
)
pair
.
getKey
().
newInstance
();
p
=
(
P
)
pair
.
getKey
().
newInstance
();
D
d
=
(
D
)
pair
.
getValue
().
newInstance
();
p
.
setData
(
d
);
parse
(
p
,
bs
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
p
;
}
public
static
<
D
>
Object
parse
(
Object
p
,
byte
[]
bs
)
{
try
{
int
offset
=
0
;
int
offset
=
0
;
List
<
Field
>
fields
=
ClassUtils
.
getAllFields
(
p
air
.
getKey
());
List
<
Field
>
fields
=
ClassUtils
.
getAllFields
(
p
.
getClass
());
for
(
Field
f
:
fields
)
{
for
(
Field
f
:
fields
)
{
try
{
try
{
if
(
f
.
getAnnotation
(
JsonIgnore
.
class
)
!=
null
)
{
if
(
f
.
getAnnotation
(
JsonIgnore
.
class
)
!=
null
)
{
...
@@ -153,6 +181,8 @@ public class Ocpp16Helper {
...
@@ -153,6 +181,8 @@ public class Ocpp16Helper {
f
.
setAccessible
(
true
);
f
.
setAccessible
(
true
);
Object
v
=
f
.
get
(
p
);
Object
v
=
f
.
get
(
p
);
// System.err.println(p.getClass() + " -- " + f.getName() + " -- " + v + " total:" + bs.length + " offset:" + offset);
if
(
v
instanceof
byte
[])
{
if
(
v
instanceof
byte
[])
{
byte
[]
vs
=
ByteUtils
.
getBytes
(
bs
,
offset
,
((
byte
[])
v
).
length
);
byte
[]
vs
=
ByteUtils
.
getBytes
(
bs
,
offset
,
((
byte
[])
v
).
length
);
offset
+=
vs
.
length
;
offset
+=
vs
.
length
;
...
@@ -174,9 +204,12 @@ public class Ocpp16Helper {
...
@@ -174,9 +204,12 @@ public class Ocpp16Helper {
f
.
set
(
p
,
vs
);
f
.
set
(
p
,
vs
);
}
else
if
(
v
instanceof
TcpData
)
{
}
else
if
(
v
instanceof
TcpData
)
{
byte
vs
=
ByteUtils
.
getByte
(
bs
,
offset
);
byte
[]
build
=
build
(
v
);
offset
+=
1
;
byte
[]
vs
=
ByteUtils
.
getBytes
(
bs
,
offset
,
build
.
length
);
f
.
set
(
p
,
vs
);
offset
+=
vs
.
length
;
D
d
=
(
D
)
parse
(
v
,
vs
);
f
.
set
(
p
,
d
);
}
}
log
.
debug
(
"build:{} field:{} value:{}"
,
p
.
getClass
().
getSimpleName
(),
f
.
getName
(),
v
);
log
.
debug
(
"build:{} field:{} value:{}"
,
p
.
getClass
().
getSimpleName
(),
f
.
getName
(),
v
);
...
@@ -192,29 +225,19 @@ public class Ocpp16Helper {
...
@@ -192,29 +225,19 @@ public class Ocpp16Helper {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
LoginReq
req
=
new
LoginReq
();
LoginReq
req
=
new
LoginReq
();
List
<
Field
>
fields
=
ClassUtils
.
getAllFields
(
req
.
getClass
());
for
(
Field
f
:
fields
)
{
if
(
f
.
getName
().
equals
(
"data"
))
{
try
{
f
.
setAccessible
(
true
);
Object
v
=
f
.
get
(
req
);
System
.
out
.
println
(
v
);
System
.
out
.
println
(
v
instanceof
TcpData
);
}
catch
(
IllegalArgumentException
|
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
}
req
.
setData
(
new
LoginReqData
());
req
.
setData
(
new
LoginReqData
());
fillLen
(
req
);
fillLen
(
req
);
req
.
setCrc
(
calculateCrc
(
req
));
req
.
setCrc
(
calculateCrc
(
req
));
verifyCrc
(
req
);
verifyCrc
(
req
);
System
.
out
.
println
(
req
);
System
.
out
.
println
(
req
);
System
.
out
.
println
(
build
(
req
).
length
);
System
.
out
.
println
(
build
(
req
).
length
);
scan
();
scan
();
byte
[]
bs
=
build
(
req
);
TcpBase
<
TcpData
>
base
=
parse
(
bs
);
System
.
out
.
println
(
base
);
}
}
}
}
\ No newline at end of file
\ No newline at end of file
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/ServerMain.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.client.TcpHandlerHelper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.ProxyHelper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.ProxyHelper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.TcpServer
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.TcpServer
;
...
@@ -13,8 +12,10 @@ public class ServerMain {
...
@@ -13,8 +12,10 @@ public class ServerMain {
System
.
setProperty
(
"file.encoding"
,
"UTF-8"
);
System
.
setProperty
(
"file.encoding"
,
"UTF-8"
);
if
(
server
==
null
&&
!
lock
)
{
if
(
server
==
null
&&
!
lock
)
{
TcpHandler
Helper
.
scan
();
Ocpp16
Helper
.
scan
();
// DefaultTcpNotifyHandler.startKafaka();
// DefaultTcpNotifyHandler.startKafaka();
//
ProxyHelper
.
startManager
();
ProxyHelper
.
startManager
();
synchronized
(
lock
)
{
synchronized
(
lock
)
{
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/base/TcpMapper.java
View file @
28fd649
...
@@ -5,6 +5,7 @@ import java.util.Map;
...
@@ -5,6 +5,7 @@ import java.util.Map;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.client.handler.LoginRspHandler
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -24,7 +25,7 @@ public final class TcpMapper {
...
@@ -24,7 +25,7 @@ public final class TcpMapper {
public
static
TcpMapper
CMD_BLANK
=
regist
(
0x00
,
"空白协议"
,
null
);
public
static
TcpMapper
CMD_BLANK
=
regist
(
0x00
,
"空白协议"
,
null
);
public
static
TcpMapper
CMD_REQ_LOGIN
=
regist
(
0x01
,
"充电桩登录认证"
,
null
);
public
static
TcpMapper
CMD_REQ_LOGIN
=
regist
(
0x01
,
"充电桩登录认证"
,
LoginRspHandler
.
class
);
public
static
TcpMapper
CMD_RSP_LOGIN
=
regist
(
0x02
,
"登录认证应答"
,
null
);
public
static
TcpMapper
CMD_RSP_LOGIN
=
regist
(
0x02
,
"登录认证应答"
,
null
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/TcpClient.java
View file @
28fd649
...
@@ -102,19 +102,19 @@ public class TcpClient {
...
@@ -102,19 +102,19 @@ public class TcpClient {
sendSync
(
json
);
sendSync
(
json
);
// if (!(data instanceof HeartbeatDllNotify)) {
// if (!(data instanceof HeartbeatDllNotify)) {
String
ip
=
getIp
(
future
.
channel
());
String
ip
=
getIp
(
future
.
channel
());
log
.
info
(
"【{}】send: {}"
,
ip
,
json
);
log
.
info
(
"【{}】send: {}"
,
ip
,
json
);
// }
// }
}
}
public
void
sendSync
(
String
json
)
{
public
void
sendSync
(
byte
[]
bytes
)
{
try
{
try
{
if
(
future
==
null
||
future
.
channel
()
==
null
)
{
if
(
future
==
null
||
future
.
channel
()
==
null
)
{
return
;
return
;
}
}
future
.
channel
().
writeAndFlush
(
json
);
future
.
channel
().
writeAndFlush
(
bytes
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
json
,
e
);
log
.
error
(
""
+
bytes
,
e
);
}
}
}
}
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/TcpClientHandler.java
View file @
28fd649
...
@@ -8,7 +8,7 @@ import cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler;
...
@@ -8,7 +8,7 @@ import cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpRsp
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpRsp
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
imp
l.LoginReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
protoco
l.LoginReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.TcpServer
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.TcpServer
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.handler.DefaultTcpRspHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.handler.DefaultTcpRspHandler
;
import
cn.com.glsx.charging.util.ClassUtils
;
import
cn.com.glsx.charging.util.ClassUtils
;
...
@@ -98,7 +98,6 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
...
@@ -98,7 +98,6 @@ public class TcpClientHandler extends SimpleChannelInboundHandler<String> {
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
TcpHandlerHelper
.
scan
();
int
type
=
new
LoginReq
().
getType
();
int
type
=
new
LoginReq
().
getType
();
Class
<?
extends
TcpReq
>
reqClass
=
(
Class
<?
extends
TcpReq
>)
TcpHandlerHelper
.
getTcpProtocolClass
(
type
);
Class
<?
extends
TcpReq
>
reqClass
=
(
Class
<?
extends
TcpReq
>)
TcpHandlerHelper
.
getTcpProtocolClass
(
type
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/client/handler/LoginRspHandler.java
0 → 100644
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
client
.
handler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.data.LoginRspData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.protocol.LoginRsp
;
import
io.netty.channel.Channel
;
public
class
LoginRspHandler
implements
TcpHandler
<
LoginRsp
,
LoginRsp
>
{
@Override
public
LoginRsp
handle
(
Channel
channel
,
LoginRsp
req
)
{
LoginRsp
trsp
=
new
LoginRsp
();
LoginRspData
data
=
new
LoginRspData
();
data
.
setPointId
(
null
);
data
.
setResult
((
byte
)
0
);
// SpringContextUtil.getApplicationContext().getBean(null);
log
.
info
(
"xxxx"
);
trsp
.
setData
(
data
);
return
trsp
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/data/LoginRspData.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
data
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
data
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpData
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
/**
/**
* 68(起始标志)22(数据长度)0000(序列号域)00(加密标志)01(类型)55031412782305
* 68(起始标志)0C(数据长度)0000(序列号域)00(加密标志)02(类型)55 03 14 12 78 23
* (桩编码)00(桩类型)02(充电枪数量)0F(通信协议版本:V1.5)56342E312E353000(程
* 05(桩编码)00(登陆结果:成功)DA 4C(帧校验域)
* 序版本:v4.1.50)01(网络链接类型)01010101010101010101(sim 卡)04(运营商)675A(帧
* 校验域
*
*
* @author kome
* @author kome
* @date 2023年11月1日 下午6:00:39
* @date 2023年11月1日 下午6:00:39
...
@@ -25,47 +21,8 @@ public class LoginRspData extends TcpData {
...
@@ -25,47 +21,8 @@ public class LoginRspData extends TcpData {
private
byte
[]
pointId
=
new
byte
[
7
];
private
byte
[]
pointId
=
new
byte
[
7
];
/**
/**
* 0 表示直流桩,1 表示交流桩
* 登陆结果: 0x00:登陆成功 0x01:登陆失败
*/
private
byte
pointType
;
/**
* 充电枪数量
*/
private
byte
gunCount
;
/**
* 通信协议版本 BIN 码 1 版本号乘 10,v1.0 表示 0x0A
*/
private
byte
protocolVersion
;
/**
* 程序版本 ASCII 码 8 不足 8 位补零
*/
@JsonSerialize
private
byte
[]
softVersion
=
new
byte
[
8
];
/**
* 网络链接类型
* 0x00 SIM 卡
* 0x01 LAN
* 0x02 WAN
* 0x03 其他
*/
private
byte
network
;
/**
* Sim 卡 BCD 码 10 不足 10 位补零,取不到置零
*/
private
byte
[]
sim
=
new
byte
[
10
];
/**
* 运营商 BIN 码
* 0x00 移动
* 0x02 电信
* 0x03 联通
* 0x04 其他
*/
*/
private
byte
operator
;
private
byte
result
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/
imp
l/LoginReq.java
→
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/
protoco
l/LoginReq.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
imp
l
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
protoco
l
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/
imp
l/LoginRsp.java
→
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/
protoco
l/LoginRsp.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
imp
l
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
protoco
l
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpRsp
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpRsp
;
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/server/TcpServerHandler.java
View file @
28fd649
...
@@ -3,17 +3,12 @@ package cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server;
...
@@ -3,17 +3,12 @@ package cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.channels.ClosedChannelException
;
import
java.nio.channels.ClosedChannelException
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.Ocpp16Helper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpRsp
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.handler.DefaultReqHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.client.TcpHandlerHelper
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.notify.HeartbeatTcpNotify
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.server.handler.DefaultTcpRspHandler
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSON
;
import
cn.hutool.json.JSONUtil
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
io.netty.channel.SimpleChannelInboundHandler
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -41,6 +36,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
...
@@ -41,6 +36,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
log
.
info
(
"##############################################################"
);
log
.
info
(
"##############################################################"
);
ProxyHelper
.
removeProxyInfo
(
ctx
.
channel
());
ProxyHelper
.
removeProxyInfo
(
ctx
.
channel
());
// rest sequence
}
}
...
@@ -50,24 +46,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
...
@@ -50,24 +46,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
// 收到的rsp或者notify
// 收到的rsp或者notify
try
{
try
{
JSON
parse
=
JSONUtil
.
parse
(
json
);
TcpBase
<
TcpData
>
up
=
Ocpp16Helper
.
parse
(
bytes
);
int
type
=
Integer
.
valueOf
(
ObjectUtil
.
defaultIfNull
(
parse
.
getByPath
(
"type"
),
"0"
).
toString
());
int
subtype
=
Integer
.
valueOf
(
ObjectUtil
.
defaultIfNull
(
parse
.
getByPath
(
"data.msgtype"
),
"-1"
).
toString
());
TcpBase
up
=
TcpHandlerHelper
.
parse
(
type
,
subtype
,
json
);
if
(
up
==
null
)
{
log
.
warn
(
"【{}】空Json:{}"
,
ip
,
json
);
return
;
}
if
(
up
instanceof
HeartbeatTcpNotify
)
{
log
.
debug
(
"【{}】recv: {} | {}"
,
ip
,
StrUtil
.
sub
(
json
,
0
,
600
),
up
.
getClass
().
getSimpleName
());
}
else
{
log
.
info
(
"-------------------------------------"
);
log
.
info
(
"【{}】recv: {} | {}"
,
ip
,
StrUtil
.
sub
(
json
,
0
,
600
),
up
.
getClass
().
getSimpleName
());
log
.
debug
(
"【{}】解析: {} {}:{} "
,
ip
,
StrUtil
.
sub
(
up
.
build
(),
0
,
600
),
up
.
getClass
().
getSimpleName
(),
up
.
getData
()
==
null
?
""
:
up
.
getData
().
getClass
().
getSimpleName
());
}
TcpMapper
mapper
=
TcpMapper
.
fromType
(
up
.
getType
());
TcpMapper
mapper
=
TcpMapper
.
fromType
(
up
.
getType
());
if
(
mapper
==
null
)
{
if
(
mapper
==
null
)
{
...
@@ -76,8 +55,8 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
...
@@ -76,8 +55,8 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
}
}
Class
<?
extends
TcpHandler
>
handlerClass
=
mapper
.
getHandlerClass
();
Class
<?
extends
TcpHandler
>
handlerClass
=
mapper
.
getHandlerClass
();
if
(
handlerClass
==
null
&&
up
instanceof
TcpRsp
)
{
if
(
handlerClass
==
null
)
{
handlerClass
=
Default
TcpRsp
Handler
.
class
;
handlerClass
=
Default
Req
Handler
.
class
;
}
}
if
(
handlerClass
==
null
)
{
if
(
handlerClass
==
null
)
{
log
.
info
(
"【{}】TcpMapper没有配置handler: {} - {}"
,
ip
,
mapper
.
getType
(),
mapper
.
getRemark
());
log
.
info
(
"【{}】TcpMapper没有配置handler: {} - {}"
,
ip
,
mapper
.
getType
(),
mapper
.
getRemark
());
...
@@ -88,12 +67,12 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
...
@@ -88,12 +67,12 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<byte[]> {
TcpBase
rsp
=
handler
.
handle
(
ctx
.
channel
(),
up
);
TcpBase
rsp
=
handler
.
handle
(
ctx
.
channel
(),
up
);
if
(
rsp
!=
null
)
{
if
(
rsp
!=
null
)
{
String
rspJson
=
rsp
.
build
(
);
byte
[]
rspBytes
=
Ocpp16Helper
.
build
(
rsp
);
ctx
.
channel
().
writeAndFlush
(
rsp
Json
);
ctx
.
channel
().
writeAndFlush
(
rsp
Bytes
);
log
.
info
(
"【{}】send: {}"
,
ip
,
StrUtil
.
sub
(
json
,
0
,
600
)
);
log
.
info
(
"【{}】send: {}"
,
ip
,
rsp
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"【{}】{}"
,
ip
,
json
,
e
);
log
.
error
(
"【{}】{}"
,
ip
,
e
);
}
finally
{
}
finally
{
ProxyHelper
.
addProxyInfo
(
ctx
.
channel
());
ProxyHelper
.
addProxyInfo
(
ctx
.
channel
());
}
}
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/
client/handler/Login
ReqHandler.java
→
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/
server/handler/Default
ReqHandler.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
client
.
handler
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
server
.
handler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpData
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.impl.LoginReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.protocol.LoginRsp
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.impl.LoginRsp
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.codec.Base64
;
import
io.netty.channel.Channel
;
import
io.netty.channel.Channel
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Slf4j
public
class
LoginReqHandler
implements
TcpHandler
<
LoginReq
,
LoginRsp
>
{
public
class
DefaultReqHandler
implements
TcpHandler
<
TcpBase
<
TcpData
>
,
LoginRsp
>
{
@Override
@Override
public
LoginRsp
handle
(
Channel
channel
,
LoginReq
req
)
{
public
LoginRsp
handle
(
Channel
channel
,
TcpBase
<
TcpData
>
req
)
{
LoginRsp
trsp
=
new
LoginRsp
();
LoginRsp
trsp
=
new
LoginRsp
();
// trsp.setReqKey(req.getReqKey());
// trsp.setReqKey(req.getReqKey());
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/ocpp/ocpp16/tcp/server/handler/LoginReqHandler.java
View file @
28fd649
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
server
.
handler
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
ocpp
.
ocpp16
.
tcp
.
server
.
handler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
imp
l.LoginReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
protoco
l.LoginReq
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
imp
l.LoginRsp
;
import
cn.com.glsx.charging.modules.ocpp.ocpp16.tcp.
protoco
l.LoginRsp
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.codec.Base64
;
import
io.netty.channel.Channel
;
import
io.netty.channel.Channel
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -15,46 +15,6 @@ public class LoginReqHandler implements TcpHandler<LoginReq, LoginRsp> {
...
@@ -15,46 +15,6 @@ public class LoginReqHandler implements TcpHandler<LoginReq, LoginRsp> {
LoginRsp
trsp
=
new
LoginRsp
();
LoginRsp
trsp
=
new
LoginRsp
();
// trsp.setReqKey(req.getReqKey());
// trsp.setReqKey(req.getReqKey());
// LoginQrcodeTcpData tdata = new LoginQrcodeTcpData();
// trsp.setData(tdata);
//
// try {
// DllClient client = DllFacade.openNewWxwork(req.getData().getUserId(), 0, "TcpReq");
//
// if (client == null) {
// trsp.setError(TcpErrorEnum.ERROR_OPERATION_FAILED.getError());
// return trsp;
// }
//
// SelfInfoDllData userInfo = client.getUserInfo();
// if (userInfo == null || userInfo.getUserId() == null) {
// int i = 50;
// while (client.getQrcodeData() == null && i-- > 0) {
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// LoginQrcodeDllData data = client.getQrcodeData();
// if (data == null || data.getBase64EncodePath() == null) {
// trsp.setError(TcpErrorEnum.ERROR_OPERATION_FAILED.getError());
// return trsp;
// }
// String imagePath = data.getBase64EncodePath();
// log.info("loginQrcodePath:{}", imagePath);
// byte[] bytes = FileUtil.readBytes(new File(imagePath));
// tdata.setBase64EncodeQrcode(Base64.encode(bytes));
// tdata.setLoginQrcodeKey(data.getLoginQrcodeKey());
// } else {
// BeanUtils.copyProperties(userInfo, tdata);
// }
// } catch (Exception e) {
// e.printStackTrace();
// //
// trsp.setError(TcpErrorEnum.ERROR_USERID_NOT_LOGIN.getError());
// }
return
trsp
;
return
trsp
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment