Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into mqtt

This commit is contained in:
wgzAIIT
2023-07-20 16:30:51 +08:00
42 changed files with 4893 additions and 2 deletions

View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file modbus_rtu_app.c
* @brief support get data from and send data to Modbus rtu server
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.12.12
*/
#include <stdio.h>
#include <string.h>
#include <transform.h>
#include <adapter.h>
#define ADAPTER_RTU_DATA_LENGTH 112
#define ADAPTER_RTU_TRANSFER_DATA_LENGTH ADAPTER_RTU_DATA_LENGTH + 16
uint8_t client_join_data[ADAPTER_RTU_TRANSFER_DATA_LENGTH];
/* ----------------------- Modbus includes ----------------------------------*/
#include "mb.h"
#include "mbport.h"
/* ----------------------- Defines ------------------------------------------*/
#define REG_INPUT_START 1000
#define REG_INPUT_NREGS 4
/* ----------------------- Static variables ---------------------------------*/
static USHORT usRegInputStart = REG_INPUT_START;
static USHORT usRegInputBuf[REG_INPUT_NREGS];
/* ----------------------- Start implementation -----------------------------*/
eMBErrorCode
eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
{
eMBErrorCode eStatus = MB_ENOERR;
int iRegIndex;
if( ( usAddress >= REG_INPUT_START )
&& ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
{
iRegIndex = ( int )( usAddress - usRegInputStart );
while( usNRegs > 0 )
{
*pucRegBuffer++ =
( unsigned char )( usRegInputBuf[iRegIndex] >> 8 );
*pucRegBuffer++ =
( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
iRegIndex++;
usNRegs--;
}
}
else
{
eStatus = MB_ENOREG;
}
return eStatus;
}
eMBErrorCode
eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs,
eMBRegisterMode eMode )
{
return MB_ENOREG;
}
eMBErrorCode
eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils,
eMBRegisterMode eMode )
{
return MB_ENOREG;
}
eMBErrorCode
eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
{
return MB_ENOREG;
}
/******************Modbus RTU TEST*********************/
int AdapterModbusRtuTest(void)
{
const char *send_msg = "Adapter_Modbus_Rtu Test";
char recv_msg[256] = {0};
int baud_rate = BAUD_RATE_115200;
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_MODBUS_RTU_NAME);
struct AdapterData priv_rtu_net;
priv_rtu_net.len = ADAPTER_RTU_TRANSFER_DATA_LENGTH;
priv_rtu_net.buffer = client_join_data;
AdapterDeviceOpen(adapter);
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
AdapterDeviceJoin(adapter,(uint8_t *)&priv_rtu_net);
eMBErrorCode eStatus;
eStatus = eMBInit( MB_RTU, 0x0A, 0, 38400, MB_PAR_EVEN );
/* Enable the Modbus Protocol Stack. */
eStatus = eMBEnable( );
for( ;; )
{
( void )eMBPoll( );//判断事件的发生,并执行对应的回调函数
/* Here we simply count the number of poll cycles. */
usRegInputBuf[0]++;
}
// while (1) {
// AdapterDeviceSend(adapter, send_msg, strlen(send_msg));
// AdapterDeviceRecv(adapter, recv_msg, 256);
// printf("4G recv msg %s\n", recv_msg);
// memset(recv_msg, 0, 256);
// }
return 0;
}
PRIV_SHELL_CMD_FUNCTION(AdapterModbusRtuTest, a Modbus Rtu adpter sample, PRIV_SHELL_CMD_FUNC_ATTR);

View File

@@ -1,3 +1,3 @@
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence
include $(KERNEL_ROOT)/compiler.mk

View File

@@ -1,3 +1,3 @@
SRC_FILES := inovance_am401_cpu1608tn_ethernet.c
SRC_FILES := inovance_am401_cpu1608tn_ethernet.c inovance_am401_cpu1608tn_uart.c
include $(KERNEL_ROOT)/compiler.mk

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file inovance_am401_cpu1608tn_ethernet.c
* @brief PLC inovance am401 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.5.15
*/
#include <control.h>
extern int Adapter4GActive(void);
void ControlInovanceam401UartTest(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
#ifdef CONNECTION_ADAPTER_4G
Adapter4GActive();
#endif
ControlProtocolType modbus_rtu_protocol = ControlProtocolFind();
if (NULL == modbus_rtu_protocol) {
printf("%s get modbus rtu protocol %p failed\n", __func__, modbus_rtu_protocol);
return;
}
printf("%s get modbus rtu protocol %p successfull\n", __func__, modbus_rtu_protocol);
if (CONTROL_REGISTERED == modbus_rtu_protocol->protocol_status) {
ControlProtocolOpen(modbus_rtu_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_rtu_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus rtu data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_rtu_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlInovanceam401UartTest, inovance am401 uart Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@@ -0,0 +1,80 @@
{
"device_id": 1,
"device_name": "INOVANCE_am401_RTU",
"communication_type": 1,
"serial_config": {
"station": 1,
"baud_rate": 9600,
"data_bits": 8,
"stop_bits": 1,
"check_mode":3
},
"protocol_type": 3,
"read_period": 2000,
"read_item_list": [
{
"value_name": "q00",
"value_type": 1,
"function_code": 1,
"start_address": 0,
"quantity": 1
},
{
"value_name": "q01",
"value_type": 1,
"function_code": 1,
"start_address":1,
"quantity": 1
},
{
"value_name": "q10",
"value_type": 1,
"function_code": 1,
"start_address": 8,
"quantity": 1
},
{
"value_name": "mw100",
"value_type": 3,
"function_code": 3,
"start_address": 100,
"quantity": 1
},
{
"value_name": "mw101",
"value_type": 3,
"function_code": 3,
"start_address": 101,
"quantity": 1
},
{
"value_name": "md200",
"value_type": 4,
"function_code": 3,
"start_address": 400,
"quantity": 2
},
{
"value_name": "md201",
"value_type": 4,
"function_code": 3,
"start_address": 402,
"quantity": 2
},
{
"value_name": "md300",
"value_type": 9,
"function_code": 3,
"start_address": 600,
"quantity": 2
},
{
"value_name": "md301",
"value_type": 9,
"function_code": 3,
"start_address": 602,
"quantity": 2
}
]
}

View File

@@ -0,0 +1,3 @@
SRC_FILES := kv_8000.c
include $(KERNEL_ROOT)/compiler.mk

View File

@@ -0,0 +1,22 @@
# KEYENCE 通信测试
[TOC]
## 通信接线及参数设置
* 网口
*Mosbus TCP协议IP192.168.250.40Port502
## 存储区
- 存储区ZF区。
## 通信测试
1共测试INT16类型数据。
2测试ZF区数据。
3D区数据测试用功能码03和06以字为单位读写。如读写ZF1则配方文件中起始地址则直接写1即可。

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file kv_8000.c
* @brief PLC KEYENCE KV-8000 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.4.12
*/
#include <control.h>
void ControlKV8000Test(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
if (NULL == modbus_tcp_protocol) {
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
return;
}
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
ControlProtocolOpen(modbus_tcp_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_tcp_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlKV8000Test, KEYENCE Plc KV_8000 Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@@ -0,0 +1,37 @@
{
"device_id": 1,
"device_name": "GJ2",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.40",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.255.0",
"port": 502
},
"protocol_type": 2,
"read_period": 100,
"read_item_list": [
{
"value_name": "ZF0",
"value_type": 3,
"function_code": 3,
"start_address": 0,
"quantity": 1
},
{
"value_name": "ZF1",
"value_type": 3,
"function_code": 3,
"start_address": 1,
"quantity": 1
},
{
"value_name": "ZF2",
"value_type": 3,
"function_code": 3,
"start_address": 2,
"quantity": 1
}
]
}

View File

@@ -0,0 +1,21 @@
# SCHNEIDER M241通信测试
[TOC]
## 通信接线及参数设置
* 串口
* M241支持2路485串口本次采用的是serial2。波特率9600数据位8位停止位1位校验偶校验
## 存储区
- 存储区MW区。
## 通信测试
1共测试INT16共1种类型数据。
2测试MW区数据。
3MW区数据测试用功能码03以字为单位读取。如读MW100则配方文件中起始地址则直接写100即可。

View File

@@ -0,0 +1,23 @@
# XINJIE 通信测试
[TOC]
## 通信接线及参数设置
* 网口
*Mosbus TCP协议IP192.168.250.32Port502
## 存储区
- 存储区M、D区。
## 通信测试
1共测试BOOLINT16共2种类型数据。
2测试M区及D区数据。
3D区数据测试用功能码03和06以字为单位读写。如读写D500则配方文件中起始地址则直接写500即可。
4M区数据测试用功能码01和05以位为单位读写。如读写M19则配方文件中起始地址则直接写19即可。