support plc demo

This commit is contained in:
wlyu
2022-02-15 14:24:46 +08:00
parent 3bc3577d35
commit 338f4ad41a
21 changed files with 188 additions and 88 deletions

View File

@@ -25,13 +25,6 @@
#include "plc_bus.h"
#include "plc_dev.h"
#define PLC_BUS_NAME "plc bus"
#define PLC_DRV_NAME "plc driver"
struct PlcDevice plc_device;
struct PlcBus plc_bus;
struct PlcDriver plc_drv;
static DoubleLinklistType plcdev_list;
@@ -52,7 +45,7 @@ static int PlcDeviceOpen(void *dev)
if(plc_dev->net == PLC_IND_ENET_OPCUA)
{
return ua_open(dev);
return ua_open(plc_dev->priv_data);
}
return EOK;
@@ -66,21 +59,21 @@ static void PlcDeviceClose(void *dev)
if(plc_dev->net == PLC_IND_ENET_OPCUA)
{
ua_close(dev);
ua_close(plc_dev->priv_data);
}
}
static int PlcDeviceWrite(void *dev, const void *buf, size_t len)
{
NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(write_param);
NULL_PARAM_CHECK(buf);
int ret;
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
if(plc_dev->net == PLC_IND_ENET_OPCUA)
{
ret = ua_write(dev, buf, len);
ret = ua_write(plc_dev->priv_data, buf, len);
}
return ret;
@@ -89,20 +82,20 @@ static int PlcDeviceWrite(void *dev, const void *buf, size_t len)
static int PlcDeviceRead(void *dev, void *buf, size_t len)
{
NULL_PARAM_CHECK(dev);
NULL_PARAM_CHECK(read_param);
NULL_PARAM_CHECK(buf);
int ret;
struct PlcDevice *plc_dev = (struct PlcDevice *)dev;
if(plc_dev->net == PLC_IND_ENET_OPCUA)
{
ret = ua_read(dev, buf, len);
ret = ua_read(plc_dev->priv_data, buf, len);
}
return ret;
}
static const struct PlcOps plc_done =
static struct PlcOps plc_done =
{
.open = PlcDeviceOpen,
.close = PlcDeviceClose,
@@ -145,6 +138,7 @@ int PlcDevRegister(struct PlcDevice *plc_device, void *plc_param, const char *de
if (DEV_INSTALL != plc_device->state) {
strncpy(plc_device->name, device_name, strlen(device_name));
plc_device->ops = &plc_done;
DoubleLinkListInsertNodeAfter(&plcdev_list, &(plc_device->link));
plc_device->state = DEV_INSTALL;
} else {
@@ -189,17 +183,3 @@ int PlcDeviceAttachToBus(const char *dev_name, const char *bus_name)
return EOK;
}
void PlcTestInit(void)
{
PlcBusInit(&plc_bus, PLC_BUS_NAME);
PlcDriverInit(&plc_drv, PLC_DRV_NAME);
}
void test_plc_bus(int argc, char *argv[])
{
PlcTestInit();
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
plc, test_plc_bus, test PLC);

View File

@@ -58,6 +58,11 @@ union PlcCfg {
struct PlcDevice;
#undef open
#undef close
#undef read
#undef write
// operation API
struct PlcOps {
int (*open)(void *dev); // open and connect PLC device
@@ -123,9 +128,13 @@ struct PlcDevice {
struct PlcInfo info;/* Plc info, such as vendor name and model name */
union PlcCfg cfg;
struct PlcOps ops; /* filesystem-like APIs for data transferring */
struct PlcOps *ops; /* filesystem-like APIs for data transferring */
struct PlcInterface interface; /* protocols used for transferring data from program to plc */
void *priv_data;
DoubleLinklistType link;/* link list node */
};
int PlcDevRegister(struct PlcDevice *plc_device, void *plc_param, const char *device_name);
#endif

View File

@@ -231,7 +231,6 @@ int PlcHardwareDevConfigureCs(struct HardwareDev *dev, uint8 plc_chip_select, ui
msg->plc_chip_select = plc_chip_select;
msg->plc_cs_release = plc_cs_release;
ret = plc_dev->plc_dev_done->dev_write(plc_dev, msg);
x_free(msg);