Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue_django_test
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
周田
vue_django_test
Commits
5e0f41a8
Commit
5e0f41a8
authored
Aug 24, 2023
by
周田
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:添加设备通信参数
parent
571c5161
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
58 deletions
+113
-58
0001_initial.py
device_communication/migrations/0001_initial.py
+25
-13
0002_auto_20230823_1435.py
device_communication/migrations/0002_auto_20230823_1435.py
+0
-21
models.py
device_communication/models.py
+67
-16
urls.py
device_communication/urls.py
+4
-0
views.py
device_communication/views.py
+17
-8
xdc.sqlite
xdc.sqlite
+0
-0
No files found.
device_communication/migrations/0001_initial.py
View file @
5e0f41a8
# Generated by Django 3.2.19 on 2023-08-2
3 06:34
# Generated by Django 3.2.19 on 2023-08-2
4 03:03
from
django.db
import
migrations
,
models
...
...
@@ -15,32 +15,44 @@ class Migration(migrations.Migration):
name
=
'DeviceCommunicationParameter'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
)),
(
'station_id'
,
models
.
CharField
(
max_length
=
10
)),
(
'device_id'
,
models
.
IntegerField
(
default
=
0
)),
(
'device_name'
,
models
.
CharField
(
max_length
=
100
)),
(
'device_name_chn'
,
models
.
CharField
(
max_length
=
100
)),
(
'protocol_name'
,
models
.
CharField
(
max_length
=
100
)),
(
'communicate_mode'
,
models
.
CharField
(
max_length
=
100
)),
(
'tcp_ip'
,
models
.
CharField
(
max_length
=
40
)),
(
'tcp_port'
,
models
.
IntegerField
()),
(
'udp_ip_src'
,
models
.
CharField
(
max_length
=
40
)),
(
'udp_port_src'
,
models
.
IntegerField
()),
(
'udp_ip_dst'
,
models
.
CharField
(
max_length
=
40
)),
(
'udp_port_dst'
,
models
.
IntegerField
()),
(
'tcp_ip'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
40
)),
(
'tcp_port'
,
models
.
IntegerField
(
default
=
0
)),
(
'udp_ip_src'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
40
)),
(
'udp_port_src'
,
models
.
IntegerField
(
default
=
0
)),
(
'udp_ip_dst'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
40
)),
(
'udp_port_dst'
,
models
.
IntegerField
(
default
=
0
)),
(
'performance_fields'
,
models
.
TextField
()),
],
options
=
{
'db_table'
:
'DeviceCommunicationParameter'
,
},
),
migrations
.
CreateModel
(
name
=
'SimulateDeviceCommunicationParameter'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
)),
(
'station_id'
,
models
.
CharField
(
max_length
=
10
)),
(
'device_id'
,
models
.
IntegerField
(
default
=
0
)),
(
'device_name'
,
models
.
CharField
(
max_length
=
100
)),
(
'device_name_chn'
,
models
.
CharField
(
max_length
=
100
)),
(
'protocol_name'
,
models
.
CharField
(
max_length
=
100
)),
(
'communicate_mode'
,
models
.
CharField
(
max_length
=
100
)),
(
'tcp_ip'
,
models
.
CharField
(
max_length
=
40
)),
(
'tcp_port'
,
models
.
IntegerField
()),
(
'udp_ip_src'
,
models
.
CharField
(
max_length
=
40
)),
(
'udp_port_src'
,
models
.
IntegerField
()),
(
'udp_ip_dst'
,
models
.
CharField
(
max_length
=
40
)),
(
'udp_port_dst'
,
models
.
IntegerField
()),
(
'tcp_ip'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
40
)),
(
'tcp_port'
,
models
.
IntegerField
(
default
=
0
)),
(
'udp_ip_src'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
40
)),
(
'udp_port_src'
,
models
.
IntegerField
(
default
=
0
)),
(
'udp_ip_dst'
,
models
.
CharField
(
blank
=
True
,
default
=
''
,
max_length
=
40
)),
(
'udp_port_dst'
,
models
.
IntegerField
(
default
=
0
)),
(
'performance_fields'
,
models
.
TextField
()),
],
options
=
{
'db_table'
:
'SimulateDeviceCommunicationParameter'
,
},
),
]
device_communication/migrations/0002_auto_20230823_1435.py
deleted
100644 → 0
View file @
571c5161
# Generated by Django 3.2.19 on 2023-08-23 06:35
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'device_communication'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterModelTable
(
name
=
'devicecommunicationparameter'
,
table
=
'Device_Communication_Parameter'
,
),
migrations
.
AlterModelTable
(
name
=
'simulatedevicecommunicationparameter'
,
table
=
'Simulate_Device_Communication_Parameter'
,
),
]
device_communication/models.py
View file @
5e0f41a8
from
django.db
import
models
def
allow_none
(
value
):
"""
当传过来的值为 none 时,则在数据库里存一个空值
:param value: 通过基本校验之后的值
"""
if
value
==
"none"
:
return
""
return
value
# Create your models here.
class
SimulateDeviceCommunicationParameter
(
models
.
Model
):
"""
...
...
@@ -7,41 +19,80 @@ class SimulateDeviceCommunicationParameter(models.Model):
"""
id
=
models
.
AutoField
(
primary_key
=
True
)
station_id
=
models
.
CharField
(
max_length
=
10
)
device_id
=
models
.
IntegerField
()
device_id
=
models
.
IntegerField
(
default
=
0
)
device_name
=
models
.
CharField
(
max_length
=
100
)
device_name_chn
=
models
.
CharField
(
max_length
=
100
)
protocol_name
=
models
.
CharField
(
max_length
=
100
)
communicate_mode
=
models
.
CharField
(
max_length
=
100
)
tcp_ip
=
models
.
CharField
(
max_length
=
40
)
tcp_port
=
models
.
IntegerField
()
udp_ip_src
=
models
.
CharField
(
max_length
=
40
)
udp_port_src
=
models
.
IntegerField
()
udp_ip_dst
=
models
.
CharField
(
max_length
=
40
)
udp_port_dst
=
models
.
IntegerField
()
tcp_ip
=
models
.
CharField
(
max_length
=
40
,
default
=
""
,
blank
=
True
)
tcp_port
=
models
.
IntegerField
(
default
=
0
)
udp_ip_src
=
models
.
CharField
(
max_length
=
40
,
default
=
""
,
blank
=
True
)
udp_port_src
=
models
.
IntegerField
(
default
=
0
)
udp_ip_dst
=
models
.
CharField
(
max_length
=
40
,
default
=
""
,
blank
=
True
)
udp_port_dst
=
models
.
IntegerField
(
default
=
0
)
performance_fields
=
models
.
TextField
()
def
validate
(
self
,
attrs
:
dict
):
"""
校验字段,在进行基础校验之后,如果字段名称为下面的字段,
且当传过来的值为 none 时,存一个空值
:param attrs: 通过基本校验之后的值
"""
for
field_name
,
value
in
attrs
.
items
():
if
field_name
in
([
'tcp_ip'
,
'tcp_port'
,
'udp_ip_src'
,
'udp_port_src'
,
'udp_ip_dst'
,
'udp_port_dst'
]):
attrs
[
field_name
]
=
allow_none
(
value
)
return
attrs
class
Meta
:
db_table
=
'Simulate
_Device_Communication_
Parameter'
db_table
=
'Simulate
DeviceCommunication
Parameter'
class
DeviceCommunicationParameter
(
models
.
Model
):
"""
设备通信参数
{
"station_id": "XX1",
"device_id": 1,
"device_name": "XXXX",
"device_name_chn": "XXXX",
"protocol_name": "HY_VirtualDevice_PROTOCOL",
"communicate_mode": "TCP_CLIENT",
"tcp_ip": "127.0.0.1",
"tcp_port": 8888,
"performance_fields": ["info", "END", "CMDS"]
}
"""
id
=
models
.
AutoField
(
primary_key
=
True
)
station_id
=
models
.
CharField
(
max_length
=
10
)
device_id
=
models
.
IntegerField
()
device_id
=
models
.
IntegerField
(
default
=
0
)
device_name
=
models
.
CharField
(
max_length
=
100
)
device_name_chn
=
models
.
CharField
(
max_length
=
100
)
protocol_name
=
models
.
CharField
(
max_length
=
100
)
communicate_mode
=
models
.
CharField
(
max_length
=
100
)
tcp_ip
=
models
.
CharField
(
max_length
=
40
)
tcp_port
=
models
.
IntegerField
()
udp_ip_src
=
models
.
CharField
(
max_length
=
40
)
udp_port_src
=
models
.
IntegerField
()
udp_ip_dst
=
models
.
CharField
(
max_length
=
40
)
udp_port_dst
=
models
.
IntegerField
()
tcp_ip
=
models
.
CharField
(
max_length
=
40
,
default
=
""
,
blank
=
True
)
tcp_port
=
models
.
IntegerField
(
default
=
0
)
udp_ip_src
=
models
.
CharField
(
max_length
=
40
,
default
=
""
,
blank
=
True
)
udp_port_src
=
models
.
IntegerField
(
default
=
0
)
udp_ip_dst
=
models
.
CharField
(
max_length
=
40
,
default
=
""
,
blank
=
True
)
udp_port_dst
=
models
.
IntegerField
(
default
=
0
)
performance_fields
=
models
.
TextField
()
def
validate
(
self
,
attrs
:
dict
):
"""
校验字段,在进行基础校验之后,如果字段名称为下面的字段,
且当传过来的值为 none 时,存一个空值
:param attrs: 通过基本校验之后的值
"""
for
field_name
,
value
in
attrs
.
items
():
if
field_name
in
([
'tcp_ip'
,
'tcp_port'
,
'udp_ip_src'
,
'udp_port_src'
,
'udp_ip_dst'
,
'udp_port_dst'
]):
attrs
[
field_name
]
=
allow_none
(
value
)
return
attrs
class
Meta
:
db_table
=
'Device
_Communication_
Parameter'
db_table
=
'Device
Communication
Parameter'
device_communication/urls.py
View file @
5e0f41a8
...
...
@@ -4,4 +4,7 @@ from . import views
urlpatterns
=
[
re_path
(
r'^device_communication/$'
,
views
.
get_protocol_names
),
re_path
(
r'^device_communication/protocol_performance/$'
,
views
.
get_protocol_field_names
),
re_path
(
r'^device_communication/set_communication_to_devinfo_table/$'
,
views
.
set_communication_to_devinfo_table
),
re_path
(
r'^device_communication/communicate/$'
,
views
.
DeviceCommunicationParameterViewSet
.
as_view
({
'post'
:
'create'
})),
]
\ No newline at end of file
device_communication/views.py
View file @
5e0f41a8
from
rest_framework.decorators
import
api_view
from
rest_framework.response
import
Response
from
rest_framework
import
status
from
rest_framework
import
status
,
mixins
from
rest_framework.viewsets
import
GenericViewSet
from
.models
import
(
SimulateDeviceCommunicationParameter
,
DeviceCommunicationParameter
)
from
.models
import
(
SimulateDeviceCommunicationParameter
,
DeviceCommunicationParameter
)
from
protocol_version_manage.models
import
(
AllProtocolVersion
,
AllProtocolDefinAndVersion
,
AllDevCmdDefineAndVersion
)
from
device_data_op.models
import
TableXproAllDevinfo
from
.serializers
import
(
SimulateDeviceCommunicationParameterSerializer
,
DeviceCommunicationParameterSerializer
)
@api_view
([
'GET'
])
...
...
@@ -66,19 +68,26 @@ def set_communication_to_devinfo_table(request):
dev_name_chn
=
communication
.
device_name_chn
,
protocol_name
=
communication
.
protocol_name
,
cmd_excel_path
=
"null"
,
com
munitate_mode
=
communication
.
communit
ate_mode
,
com
unitate_mode
=
communication
.
communic
ate_mode
,
tcp_ip
=
communication
.
tcp_ip
,
tcp_port
=
communication
.
tcp_port
,
udp_ip_src
=
communication
.
udp_ip_src
,
udp_port_src
=
communication
.
udp_port_src
,
udp_ip_dst
=
communication
.
udp_ip_dst
,
udp_port_dst
=
communication
.
udp_port_dst
,
udpmc_ip
=
"
null
"
,
udpmc_ip_tx
=
"
null
"
,
udpmc_ip
=
""
,
udpmc_ip_tx
=
""
,
udpmc_port_tx
=
0
,
udpmc_ip_rx
=
"
null
"
,
udpmc_ip_rx
=
""
,
udpmc_port_rx
=
0
,
remarks
=
"
null
"
)
remarks
=
""
)
for
communication
in
communications
])
return
Response
(
status
=
status
.
HTTP_200_OK
)
class
DeviceCommunicationParameterViewSet
(
mixins
.
CreateModelMixin
,
GenericViewSet
):
queryset
=
DeviceCommunicationParameter
.
objects
.
all
()
serializer_class
=
DeviceCommunicationParameterSerializer
xdc.sqlite
View file @
5e0f41a8
No preview for this file type
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