diff --git a/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c b/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c index cec5d53e1..d8f480d59 100755 --- a/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c +++ b/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c @@ -22,8 +22,6 @@ #include "open62541.h" #include "ua_api.h" #include "sys_arch.h" -#include "plc_ch.h" -#include "plc_dev.h" #include "plc_demo.h" #define PLC_NS_FORMAT "n%d,%s" diff --git a/APP_Framework/Applications/control_app/plc_demo/plc_demo.h b/APP_Framework/Applications/control_app/plc_demo/plc_demo.h index 45df0f4fa..12096936e 100755 --- a/APP_Framework/Applications/control_app/plc_demo/plc_demo.h +++ b/APP_Framework/Applications/control_app/plc_demo/plc_demo.h @@ -21,6 +21,9 @@ #ifndef __PLC_DEMO_H_ #define __PLC_DEMO_H_ +#include "plc_channel.h" +#include "plc_device.h" + #define PLC_CH_NAME "PLC" #define PLC_DRV_NAME "OPCUA" diff --git a/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c b/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c index 87864b3b8..c4cd7a9c2 100755 --- a/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c +++ b/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c @@ -24,8 +24,6 @@ #include "open62541.h" #include "ua_api.h" #include "sys_arch.h" -#include "plc_ch.h" -#include "plc_dev.h" #include "plc_demo.h" diff --git a/APP_Framework/Framework/control/plc/shared/Makefile b/APP_Framework/Framework/control/plc/shared/Makefile index e72134886..1a56440e3 100755 --- a/APP_Framework/Framework/control/plc/shared/Makefile +++ b/APP_Framework/Framework/control/plc/shared/Makefile @@ -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 diff --git a/APP_Framework/Framework/control/plc/shared/plc_ch.c b/APP_Framework/Framework/control/plc/shared/plc_ch.c deleted file mode 100755 index f2b83abd5..000000000 --- a/APP_Framework/Framework/control/plc/shared/plc_ch.c +++ /dev/null @@ -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; -} diff --git a/APP_Framework/Framework/control/plc/shared/plc_ch.h b/APP_Framework/Framework/control/plc/shared/plc_ch.h deleted file mode 100755 index f32817138..000000000 --- a/APP_Framework/Framework/control/plc/shared/plc_ch.h +++ /dev/null @@ -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 diff --git a/APP_Framework/Framework/control/plc/shared/channel.c b/APP_Framework/Framework/control/plc/shared/plc_channel.c similarity index 78% rename from APP_Framework/Framework/control/plc/shared/channel.c rename to APP_Framework/Framework/control/plc/shared/plc_channel.c index 22b76fbfb..3fe084514 100755 --- a/APP_Framework/Framework/control/plc/shared/channel.c +++ b/APP_Framework/Framework/control/plc/shared/plc_channel.c @@ -18,7 +18,8 @@ */ #include "string.h" -#include "channel.h" +#include "plc_channel.h" +#include "plc_device.h" #include "transform.h" DoublelistType ch_linklist; @@ -431,3 +432,107 @@ uint32 ChannelDrvConfigure(struct ChDrv *drv, struct ChConfigInfo *config) 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; +} diff --git a/APP_Framework/Framework/control/plc/shared/channel.h b/APP_Framework/Framework/control/plc/shared/plc_channel.h similarity index 86% rename from APP_Framework/Framework/control/plc/shared/channel.h rename to APP_Framework/Framework/control/plc/shared/plc_channel.h index c87134d03..a00262bf1 100755 --- a/APP_Framework/Framework/control/plc/shared/channel.h +++ b/APP_Framework/Framework/control/plc/shared/plc_channel.h @@ -11,15 +11,15 @@ */ /** -* @file channel.h +* @file plc_channel.h * @brief define ch driver framework function and common API * @version 1.0 * @author AIIT XUOS Lab * @date 2022-03-01 */ -#ifndef __CHANNEL_H_ -#define __CHANNEL_H_ +#ifndef __PLC_CHANNEL_H_ +#define __PLC_CHANNEL_H_ #include "list.h" @@ -240,6 +240,37 @@ uint32 ChannelDrvConfigure(struct ChDrv *drv, struct ChConfigInfo *config); /*Obtain the ch using a certain dev*/ 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 } #endif diff --git a/APP_Framework/Framework/control/plc/shared/plc_dev.c b/APP_Framework/Framework/control/plc/shared/plc_device.c similarity index 98% rename from APP_Framework/Framework/control/plc/shared/plc_dev.c rename to APP_Framework/Framework/control/plc/shared/plc_device.c index ed44b5b7b..670452e2a 100755 --- a/APP_Framework/Framework/control/plc/shared/plc_dev.c +++ b/APP_Framework/Framework/control/plc/shared/plc_device.c @@ -19,8 +19,8 @@ */ #include "ua_api.h" -#include "plc_ch.h" -#include "plc_dev.h" +#include "plc_channel.h" +#include "plc_device.h" DoublelistType plcdev_list; diff --git a/APP_Framework/Framework/control/plc/shared/plc_dev.h b/APP_Framework/Framework/control/plc/shared/plc_device.h similarity index 99% rename from APP_Framework/Framework/control/plc/shared/plc_dev.h rename to APP_Framework/Framework/control/plc/shared/plc_device.h index f17b78f3b..6744a1474 100755 --- a/APP_Framework/Framework/control/plc/shared/plc_dev.h +++ b/APP_Framework/Framework/control/plc/shared/plc_device.h @@ -22,7 +22,7 @@ #define __PLC_DEV_H_ #include "list.h" -#include "plc_ch.h" +#include "plc_channel.h" #undef open #undef close diff --git a/APP_Framework/Framework/control/plc/shared/plc_drv.c b/APP_Framework/Framework/control/plc/shared/plc_driver.c similarity index 97% rename from APP_Framework/Framework/control/plc/shared/plc_drv.c rename to APP_Framework/Framework/control/plc/shared/plc_driver.c index f58d3afb5..358856b8b 100755 --- a/APP_Framework/Framework/control/plc/shared/plc_drv.c +++ b/APP_Framework/Framework/control/plc/shared/plc_driver.c @@ -19,8 +19,8 @@ */ #include "transform.h" -#include "plc_ch.h" -#include "plc_dev.h" +#include "plc_channel.h" +#include "plc_device.h" static DoublelistType plcdrv_linklist;