Commit 63366439 by 周田

feat:将参数添加的 devinfo 表上,供 device 子模块使用

parent 4d7c889b
...@@ -6,7 +6,10 @@ class SimulateDeviceCommunicationParameter(models.Model): ...@@ -6,7 +6,10 @@ class SimulateDeviceCommunicationParameter(models.Model):
模拟设备通信参数 模拟设备通信参数
""" """
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
station_id = models.CharField(max_length=10)
device_id = models.IntegerField()
device_name = models.CharField(max_length=100) device_name = models.CharField(max_length=100)
device_name_chn = models.CharField(max_length=100)
protocol_name = models.CharField(max_length=100) protocol_name = models.CharField(max_length=100)
communicate_mode = models.CharField(max_length=100) communicate_mode = models.CharField(max_length=100)
tcp_ip = models.CharField(max_length=40) tcp_ip = models.CharField(max_length=40)
...@@ -26,7 +29,10 @@ class DeviceCommunicationParameter(models.Model): ...@@ -26,7 +29,10 @@ class DeviceCommunicationParameter(models.Model):
设备通信参数 设备通信参数
""" """
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
station_id = models.CharField(max_length=10)
device_id = models.IntegerField()
device_name = models.CharField(max_length=100) device_name = models.CharField(max_length=100)
device_name_chn = models.CharField(max_length=100)
protocol_name = models.CharField(max_length=100) protocol_name = models.CharField(max_length=100)
communicate_mode = models.CharField(max_length=100) communicate_mode = models.CharField(max_length=100)
tcp_ip = models.CharField(max_length=40) tcp_ip = models.CharField(max_length=40)
......
...@@ -2,8 +2,12 @@ from rest_framework.decorators import api_view ...@@ -2,8 +2,12 @@ from rest_framework.decorators import api_view
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from .models import (
SimulateDeviceCommunicationParameter, DeviceCommunicationParameter)
from protocol_version_manage.models import (AllProtocolVersion, AllProtocolDefinAndVersion, from protocol_version_manage.models import (AllProtocolVersion, AllProtocolDefinAndVersion,
AllDevCmdDefineAndVersion) AllDevCmdDefineAndVersion)
from device_data_op.models import TableXproAllDevinfo
@api_view(['GET']) @api_view(['GET'])
def get_protocol_names(request): def get_protocol_names(request):
...@@ -36,3 +40,45 @@ def get_protocol_field_names(request): ...@@ -36,3 +40,45 @@ def get_protocol_field_names(request):
res_data = ([field_name for field_name in field_name_set]) res_data = ([field_name for field_name in field_name_set])
return Response(data=res_data, status=status.HTTP_200_OK) return Response(data=res_data, status=status.HTTP_200_OK)
@api_view(['POST'])
def set_communication_to_devinfo_table(request):
"""
将设备通信参数或模拟设备通信参数设置到设备信息表
"""
type = request.data.get('type')
if type is None or type == '':
return Response(status=status.HTTP_400_BAD_REQUEST)
if type == 'simulate':
communications = SimulateDeviceCommunicationParameter.objects.all()
else:
communications = DeviceCommunicationParameter.objects.all()
# 清空设备信息表
# TableXproAllDevinfo.objects.all().delete()
TableXproAllDevinfo.objects.bulk_create(
[TableXproAllDevinfo(sta_id=communication.station_id,
dev_id=communication.device_id,
dev_name=communication.device_name,
dev_name_chn=communication.device_name_chn,
protocol_name=communication.protocol_name,
cmd_excel_path="null",
communitate_mode=communication.communitate_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_port_tx=0,
udpmc_ip_rx="null",
udpmc_port_rx=0,
remarks="null")
for communication in communications])
return Response(status=status.HTTP_200_OK)
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