forked from xuos/xiuos
optimize plc relative codes
This commit is contained in:
parent
f69edc63ba
commit
b789588fa2
|
@ -22,8 +22,6 @@
|
||||||
#include "open62541.h"
|
#include "open62541.h"
|
||||||
#include "ua_api.h"
|
#include "ua_api.h"
|
||||||
#include "sys_arch.h"
|
#include "sys_arch.h"
|
||||||
#include "plc_ch.h"
|
|
||||||
#include "plc_dev.h"
|
|
||||||
#include "plc_demo.h"
|
#include "plc_demo.h"
|
||||||
|
|
||||||
#define PLC_NS_FORMAT "n%d,%s"
|
#define PLC_NS_FORMAT "n%d,%s"
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
#ifndef __PLC_DEMO_H_
|
#ifndef __PLC_DEMO_H_
|
||||||
#define __PLC_DEMO_H_
|
#define __PLC_DEMO_H_
|
||||||
|
|
||||||
|
#include "plc_channel.h"
|
||||||
|
#include "plc_device.h"
|
||||||
|
|
||||||
#define PLC_CH_NAME "PLC"
|
#define PLC_CH_NAME "PLC"
|
||||||
#define PLC_DRV_NAME "OPCUA"
|
#define PLC_DRV_NAME "OPCUA"
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
#include "open62541.h"
|
#include "open62541.h"
|
||||||
#include "ua_api.h"
|
#include "ua_api.h"
|
||||||
#include "sys_arch.h"
|
#include "sys_arch.h"
|
||||||
#include "plc_ch.h"
|
|
||||||
#include "plc_dev.h"
|
|
||||||
#include "plc_demo.h"
|
#include "plc_demo.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
SRC_FILES := plc_dev.c plc_ch.c plc_drv.c channel.c
|
SRC_FILES := plc_device.c plc_channel.c plc_driver.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
||||||
|
|
|
@ -1,129 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 plc_ch.c
|
|
||||||
* @brief register plc channel function using channel driver framework
|
|
||||||
* @version 1.0
|
|
||||||
* @author AIIT XUOS Lab
|
|
||||||
* @date 2022-01-24
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "string.h"
|
|
||||||
#include "plc_ch.h"
|
|
||||||
#include "plc_dev.h"
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
int PlcChannelInit(struct PlcChannel* plc_ch, const char* ch_name)
|
|
||||||
{
|
|
||||||
CHECK_CH_PARAM(plc_ch);
|
|
||||||
CHECK_CH_PARAM(ch_name);
|
|
||||||
int ret = EOK;
|
|
||||||
|
|
||||||
if(CHANNEL_INSTALL != plc_ch->ch.ch_state)
|
|
||||||
{
|
|
||||||
strncpy(plc_ch->ch.ch_name, ch_name, NAME_NUM_MAX);
|
|
||||||
plc_ch->ch.ch_type = CH_PLC_TYPE;
|
|
||||||
plc_ch->ch.ch_state = CHANNEL_INSTALL;
|
|
||||||
plc_ch->ch.private_data = plc_ch->private_data;
|
|
||||||
ret = ChannelRegister(&plc_ch->ch);
|
|
||||||
|
|
||||||
if(EOK != ret)
|
|
||||||
{
|
|
||||||
KPrintf("PlcChannelInit ChannelRegister error %u\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
KPrintf("PlcChannelInit ChannelRegister channel has been register state %u\n",
|
|
||||||
plc_ch->ch.ch_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PlcDriverInit(struct PlcDriver* plc_driver, const char* driver_name)
|
|
||||||
{
|
|
||||||
CHECK_CH_PARAM(plc_driver);
|
|
||||||
CHECK_CH_PARAM(driver_name);
|
|
||||||
int ret = EOK;
|
|
||||||
|
|
||||||
if(CHDRV_INSTALL != plc_driver->driver.driver_state)
|
|
||||||
{
|
|
||||||
plc_driver->driver.driver_type = CHDRV_PLC_TYPE;
|
|
||||||
plc_driver->driver.driver_state = CHDRV_INSTALL;
|
|
||||||
strncpy(plc_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
|
|
||||||
plc_driver->driver.configure = plc_driver->configure;
|
|
||||||
ret = PlcDriverRegister(&plc_driver->driver);
|
|
||||||
|
|
||||||
if(EOK != ret)
|
|
||||||
{
|
|
||||||
KPrintf("PlcDriverInit DriverRegister error %u\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
KPrintf("PlcDriverInit Driver %s has been register state %u\n",
|
|
||||||
driver_name, plc_driver->driver.driver_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PlcReleaseChannel(struct PlcChannel* plc_ch)
|
|
||||||
{
|
|
||||||
CHECK_CH_PARAM(plc_ch);
|
|
||||||
return ChannelRelease(&plc_ch->ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
int PlcDriverAttachToChannel(const char* drv_name, const char* ch_name)
|
|
||||||
{
|
|
||||||
CHECK_CH_PARAM(drv_name);
|
|
||||||
CHECK_CH_PARAM(ch_name);
|
|
||||||
int ret = EOK;
|
|
||||||
struct Channel* ch;
|
|
||||||
struct ChDrv* driver;
|
|
||||||
ch = ChannelFind(ch_name);
|
|
||||||
|
|
||||||
if(NONE == ch)
|
|
||||||
{
|
|
||||||
KPrintf("PlcDriverAttachToChannel find plc channel error!name %s\n", ch_name);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(CH_PLC_TYPE == ch->ch_type)
|
|
||||||
{
|
|
||||||
driver = PlcDriverFind(drv_name, CHDRV_PLC_TYPE);
|
|
||||||
|
|
||||||
if(NONE == driver)
|
|
||||||
{
|
|
||||||
KPrintf("PlcDriverAttachToChannel find plc driver error!name %s\n", drv_name);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(CHDRV_PLC_TYPE == driver->driver_type)
|
|
||||||
{
|
|
||||||
ret = DriverRegisterToChannel(ch, driver);
|
|
||||||
|
|
||||||
if(EOK != ret)
|
|
||||||
{
|
|
||||||
KPrintf("PlcDriverAttachToChannel DriverRegisterToBus error %u\n", ret);
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 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 plc_ch.h
|
|
||||||
* @brief define plc bus and drv function using bus driver framework
|
|
||||||
* @version 1.0
|
|
||||||
* @author AIIT XUOS Lab
|
|
||||||
* @date 2022-01-24
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __PLC_CH_H_
|
|
||||||
#define __PLC_CH_H_
|
|
||||||
|
|
||||||
#include "channel.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct PlcDriver
|
|
||||||
{
|
|
||||||
struct ChDrv driver;
|
|
||||||
uint32 (*configure) (void *drv, struct ChConfigInfo *cfg);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlcChannel
|
|
||||||
{
|
|
||||||
struct Channel ch;
|
|
||||||
void *private_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*Register the plc bus*/
|
|
||||||
int PlcChannelInit(struct PlcChannel *plc_ch, const char *ch_name);
|
|
||||||
|
|
||||||
/*Register the plc driver*/
|
|
||||||
int PlcDriverInit(struct PlcDriver *plc_driver, const char *driver_name);
|
|
||||||
|
|
||||||
/*Release the plc device*/
|
|
||||||
int PlcReleaseChannel(struct PlcChannel *plc_ch);
|
|
||||||
|
|
||||||
/*Register the plc driver to the plc bus*/
|
|
||||||
int PlcDriverAttachToChannel(const char *drv_name, const char *ch_name);
|
|
||||||
|
|
||||||
/*Register the driver, manage with the double linklist*/
|
|
||||||
int PlcDriverRegister(struct ChDrv *driver);
|
|
||||||
|
|
||||||
/*Find the register driver*/
|
|
||||||
ChDrvType PlcDriverFind(const char *drv_name, enum ChDrvType_e drv_type);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -18,7 +18,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "channel.h"
|
#include "plc_channel.h"
|
||||||
|
#include "plc_device.h"
|
||||||
#include "transform.h"
|
#include "transform.h"
|
||||||
|
|
||||||
DoublelistType ch_linklist;
|
DoublelistType ch_linklist;
|
||||||
|
@ -431,3 +432,107 @@ uint32 ChannelDrvConfigure(struct ChDrv *drv, struct ChConfigInfo *config)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PlcChannelInit(struct PlcChannel* plc_ch, const char* ch_name)
|
||||||
|
{
|
||||||
|
CHECK_CH_PARAM(plc_ch);
|
||||||
|
CHECK_CH_PARAM(ch_name);
|
||||||
|
int ret = EOK;
|
||||||
|
|
||||||
|
if(CHANNEL_INSTALL != plc_ch->ch.ch_state)
|
||||||
|
{
|
||||||
|
strncpy(plc_ch->ch.ch_name, ch_name, NAME_NUM_MAX);
|
||||||
|
plc_ch->ch.ch_type = CH_PLC_TYPE;
|
||||||
|
plc_ch->ch.ch_state = CHANNEL_INSTALL;
|
||||||
|
plc_ch->ch.private_data = plc_ch->private_data;
|
||||||
|
ret = ChannelRegister(&plc_ch->ch);
|
||||||
|
|
||||||
|
if(EOK != ret)
|
||||||
|
{
|
||||||
|
KPrintf("PlcChannelInit ChannelRegister error %u\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KPrintf("PlcChannelInit ChannelRegister channel has been register state %u\n",
|
||||||
|
plc_ch->ch.ch_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PlcDriverInit(struct PlcDriver* plc_driver, const char* driver_name)
|
||||||
|
{
|
||||||
|
CHECK_CH_PARAM(plc_driver);
|
||||||
|
CHECK_CH_PARAM(driver_name);
|
||||||
|
int ret = EOK;
|
||||||
|
|
||||||
|
if(CHDRV_INSTALL != plc_driver->driver.driver_state)
|
||||||
|
{
|
||||||
|
plc_driver->driver.driver_type = CHDRV_PLC_TYPE;
|
||||||
|
plc_driver->driver.driver_state = CHDRV_INSTALL;
|
||||||
|
strncpy(plc_driver->driver.drv_name, driver_name, NAME_NUM_MAX);
|
||||||
|
plc_driver->driver.configure = plc_driver->configure;
|
||||||
|
ret = PlcDriverRegister(&plc_driver->driver);
|
||||||
|
|
||||||
|
if(EOK != ret)
|
||||||
|
{
|
||||||
|
KPrintf("PlcDriverInit DriverRegister error %u\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KPrintf("PlcDriverInit Driver %s has been register state %u\n",
|
||||||
|
driver_name, plc_driver->driver.driver_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PlcReleaseChannel(struct PlcChannel* plc_ch)
|
||||||
|
{
|
||||||
|
CHECK_CH_PARAM(plc_ch);
|
||||||
|
return ChannelRelease(&plc_ch->ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PlcDriverAttachToChannel(const char* drv_name, const char* ch_name)
|
||||||
|
{
|
||||||
|
CHECK_CH_PARAM(drv_name);
|
||||||
|
CHECK_CH_PARAM(ch_name);
|
||||||
|
int ret = EOK;
|
||||||
|
struct Channel* ch;
|
||||||
|
struct ChDrv* driver;
|
||||||
|
ch = ChannelFind(ch_name);
|
||||||
|
|
||||||
|
if(NONE == ch)
|
||||||
|
{
|
||||||
|
KPrintf("PlcDriverAttachToChannel find plc channel error!name %s\n", ch_name);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CH_PLC_TYPE == ch->ch_type)
|
||||||
|
{
|
||||||
|
driver = PlcDriverFind(drv_name, CHDRV_PLC_TYPE);
|
||||||
|
|
||||||
|
if(NONE == driver)
|
||||||
|
{
|
||||||
|
KPrintf("PlcDriverAttachToChannel find plc driver error!name %s\n", drv_name);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CHDRV_PLC_TYPE == driver->driver_type)
|
||||||
|
{
|
||||||
|
ret = DriverRegisterToChannel(ch, driver);
|
||||||
|
|
||||||
|
if(EOK != ret)
|
||||||
|
{
|
||||||
|
KPrintf("PlcDriverAttachToChannel DriverRegisterToBus error %u\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -11,15 +11,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file channel.h
|
* @file plc_channel.h
|
||||||
* @brief define ch driver framework function and common API
|
* @brief define ch driver framework function and common API
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @author AIIT XUOS Lab
|
* @author AIIT XUOS Lab
|
||||||
* @date 2022-03-01
|
* @date 2022-03-01
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __CHANNEL_H_
|
#ifndef __PLC_CHANNEL_H_
|
||||||
#define __CHANNEL_H_
|
#define __PLC_CHANNEL_H_
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
|
@ -240,6 +240,37 @@ uint32 ChannelDrvConfigure(struct ChDrv *drv, struct ChConfigInfo *config);
|
||||||
/*Obtain the ch using a certain dev*/
|
/*Obtain the ch using a certain dev*/
|
||||||
int DeviceObtainChannel(struct Channel *ch, struct ChDev *dev, const char *drv_name, struct ChConfigInfo *config);
|
int DeviceObtainChannel(struct Channel *ch, struct ChDev *dev, const char *drv_name, struct ChConfigInfo *config);
|
||||||
|
|
||||||
|
|
||||||
|
struct PlcDriver
|
||||||
|
{
|
||||||
|
struct ChDrv driver;
|
||||||
|
uint32 (*configure) (void *drv, struct ChConfigInfo *cfg);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PlcChannel
|
||||||
|
{
|
||||||
|
struct Channel ch;
|
||||||
|
void *private_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*Register the plc bus*/
|
||||||
|
int PlcChannelInit(struct PlcChannel *plc_ch, const char *ch_name);
|
||||||
|
|
||||||
|
/*Register the plc driver*/
|
||||||
|
int PlcDriverInit(struct PlcDriver *plc_driver, const char *driver_name);
|
||||||
|
|
||||||
|
/*Release the plc device*/
|
||||||
|
int PlcReleaseChannel(struct PlcChannel *plc_ch);
|
||||||
|
|
||||||
|
/*Register the plc driver to the plc bus*/
|
||||||
|
int PlcDriverAttachToChannel(const char *drv_name, const char *ch_name);
|
||||||
|
|
||||||
|
/*Register the driver, manage with the double linklist*/
|
||||||
|
int PlcDriverRegister(struct ChDrv *driver);
|
||||||
|
|
||||||
|
/*Find the register driver*/
|
||||||
|
ChDrvType PlcDriverFind(const char *drv_name, enum ChDrvType_e drv_type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -19,8 +19,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ua_api.h"
|
#include "ua_api.h"
|
||||||
#include "plc_ch.h"
|
#include "plc_channel.h"
|
||||||
#include "plc_dev.h"
|
#include "plc_device.h"
|
||||||
|
|
||||||
DoublelistType plcdev_list;
|
DoublelistType plcdev_list;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#define __PLC_DEV_H_
|
#define __PLC_DEV_H_
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "plc_ch.h"
|
#include "plc_channel.h"
|
||||||
|
|
||||||
#undef open
|
#undef open
|
||||||
#undef close
|
#undef close
|
|
@ -19,8 +19,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "transform.h"
|
#include "transform.h"
|
||||||
#include "plc_ch.h"
|
#include "plc_channel.h"
|
||||||
#include "plc_dev.h"
|
#include "plc_device.h"
|
||||||
|
|
||||||
static DoublelistType plcdrv_linklist;
|
static DoublelistType plcdrv_linklist;
|
||||||
|
|
Loading…
Reference in New Issue