Commit 5e0f41a8 by 周田

feat:添加设备通信参数

parent 571c5161
# Generated by Django 3.2.19 on 2023-08-23 06:34
# Generated by Django 3.2.19 on 2023-08-24 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',
},
),
]
# 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',
),
]
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 = 'SimulateDeviceCommunicationParameter'
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 = 'DeviceCommunicationParameter'
......@@ -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
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",
communitate_mode=communication.communitate_mode,
comunitate_mode=communication.communicate_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
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment