[OSADL-svn-commits] r52 - in fddi-20070618-1-trunk: include/osadl src tests
OSADL repository commits
osadl-svn-commits at lists.osadl.org
Tue Oct 2 11:44:41 CEST 2007
Author: robert
Date: Wed Jul 11 21:01:13 2007
New Revision: 52
Log:
more modbus stuff
Modified:
fddi-20070618-1-trunk/include/osadl/fddi.h
fddi-20070618-1-trunk/src/libfddi.c
fddi-20070618-1-trunk/src/libfddi_libmodbus.c
fddi-20070618-1-trunk/tests/test_fddi_libmodbus1.c
Modified: fddi-20070618-1-trunk/include/osadl/fddi.h
==============================================================================
--- fddi-20070618-1-trunk/include/osadl/fddi.h (original)
+++ fddi-20070618-1-trunk/include/osadl/fddi.h Wed Jul 11 21:01:13 2007
@@ -22,6 +22,8 @@
#ifndef OSADL_FDDI_H
#define OSADL_FDDI_H
+#include <stdint.h>
+
typedef enum {
STATE_UNCONFIGURED, /* the device is not configured */
@@ -103,32 +105,57 @@
};
+typedef enum {
+
+ IN,
+ OUT,
+ INOUT,
+
+} fddi_tpu_direction_enum_t;
+
struct fddi_tpu {
- char *name;
- int id;
- unsigned long flags;
+
+ /* FIXME: maybe put into generic list implementation */
struct fddi_tpu *next;
struct fddi_tpu *previous;
+
+ char *id_prefix;
+ int id_index;
+ char *id_postfix;
+ char *id;
+
+ uint64_t cycletime; /* ns */
+ fddi_tpu_direction_enum_t direction;
fddi_pv_t *pv_list_head;
+ unsigned long flags;
char *payload;
};
struct fddi_iface_backend_ops {
+
int (*configure) (fddi_iface_t *iface, const char *configfile, void *data);
int (*setstate) (fddi_iface_t *iface, fddi_state_enum_t state);
int (*cmd) (fddi_iface_t *iface, fddi_cmd_enum_t cmd);
+
};
struct fddi_iface {
char *name;
fddi_state_enum_t state;
+
fddi_device_t *devlist_head;
+ unsigned int nodev;
+
fddi_tpu_t *tpulist_head;
+ unsigned int notpus;
+ unsigned int nopvs;
void *backend_lib;
fddi_iface_backend_ops_t backend;
+ /* FIXME: add private data for derived backends */
+
};
/* fddi_iface_attr_t */
@@ -151,6 +178,11 @@
extern int fddi_iface_gettpulist(fddi_iface_t *iface, fddi_tpu_t **tpu);
extern int fddi_iface_getversionstr(fddi_iface_t *iface, const char **version);
extern int fddi_iface_getversion(fddi_iface_t *iface, int *version);
+/*
+ * TODO: split public/private
+ * TODO: add_tpu(), with counts
+ * TODO: add_pv(), with counts
+ */
/* fddi_device_t */
extern int fddi_dev_getnext(fddi_device_t **dev);
Modified: fddi-20070618-1-trunk/src/libfddi.c
==============================================================================
--- fddi-20070618-1-trunk/src/libfddi.c (original)
+++ fddi-20070618-1-trunk/src/libfddi.c Wed Jul 11 21:01:13 2007
@@ -409,22 +409,24 @@
return 0;
}
+/* FIXME: change into ID scheme */
int fddi_tpu_getname(fddi_tpu_t *tpu, char **name)
{
if ((!tpu) || (!name))
return EINVAL;
- *name = tpu->name;
+ *name = tpu->id;
return 0;
}
+/* FIXME: change into ID scheme */
int fddi_tpu_getid(fddi_tpu_t *tpu, int *id)
{
if ((!tpu) || (!id))
return EINVAL;
- *id = tpu->id;
- return 0;
+// *id = tpu->id;
+ return EINVAL;
}
int fddi_tpu_gettimestamp(fddi_tpu_t *tpu, int *timestamp) /* FIXME tv */
Modified: fddi-20070618-1-trunk/src/libfddi_libmodbus.c
==============================================================================
--- fddi-20070618-1-trunk/src/libfddi_libmodbus.c (original)
+++ fddi-20070618-1-trunk/src/libfddi_libmodbus.c Wed Jul 11 21:01:13 2007
@@ -7,83 +7,75 @@
#include <stdlib.h>
#include <osadl/fddi.h>
+static fddi_tpu_t tpu = {
+ .id_prefix = "dout",
+ .id_index = -1,
+ .id_postfix = "",
+ .id = "dout",
+ .direction = IN,
+ .cycletime = (10*1000*1000),
+};
+
+static fddi_pv_t pv1 = {
+ .id_prefix = "signal_red",
+ .id_index = -1,
+ .id_postfix = "",
+ .id = "signal_red",
+ .param_list_head = NULL,
+ .name = NULL,
+ .type = BOOL,
+ .offset = 0,
+ .bit = 0,
+};
+
+static fddi_pv_t pv2 = {
+ .id_prefix = "signal_yellow",
+ .id_index = -1,
+ .id_postfix = "",
+ .id = "signal_yellow",
+ .param_list_head = NULL,
+ .name = NULL,
+ .type = BOOL,
+ .offset = 0,
+ .bit = 1,
+};
+
+static fddi_pv_t pv3 = {
+ .id_prefix = "signal_green",
+ .id_index = -1,
+ .id_postfix = "",
+ .id = "signal_green",
+ .param_list_head = NULL,
+ .name = NULL,
+ .type = BOOL,
+ .offset = 0,
+ .bit = 1,
+};
+
+int fddi_backend_configure(fddi_iface_t *iface, const char *configfile, void *data);
+int fddi_backend_setstate(fddi_iface_t *iface, fddi_state_enum_t state);
+int fddi_backend_cmd(fddi_iface_t *iface, fddi_cmd_enum_t cmd);
+
int fddi_backend_configure(fddi_iface_t *iface, const char *configfile, void *data)
{
- fddi_tpu_t *tpu;
- fddi_pv_t *pv1, *pv2, *pv3;
-
printf("parsing configfile: %s\n", configfile);
printf("for interface: %s\n", iface->name);
- /*
- * FIXME: add xml parser here, we configure this hard
- * for a first test
- */
-
- tpu = calloc(1, sizeof(fddi_tpu_t));
- if (!tpu)
- goto out;
-
- pv1 = calloc(1, sizeof(fddi_pv_t));
- if (!tpu)
- goto pv1;
-
- pv2 = calloc(1, sizeof(fddi_pv_t));
- if (!tpu)
- goto pv2;
-
- pv3 = calloc(1, sizeof(fddi_pv_t));
- if (!tpu)
- goto pv3;
-
- iface->tpulist_head = tpu;
- tpu->pv_list_head = pv1;
-
- // pv1->id_prefix =
- // pv1->id_index =
- // pv1->id_postfix =
- // pv1->id =
- // pv1->param_list_head = NULL;
- // pv1->name =
- pv1->type = BOOL;
- pv1->offset = 0;
- pv1->bit = 0;
- pv1->previous = NULL;
- pv1->next = pv2;
-
- // pv2->id_prefix =
- // pv2->id_index =
- // pv2->id_postfix =
- // pv2->id =
- // pv2->param_list_head = NULL;
- // pv2->name =
- pv2->type = BOOL;
- pv2->offset = 0;
- pv2->bit = 1;
- pv2->previous = pv1;
- pv2->next = pv3;
-
- // pv3->id_prefix =
- // pv3->id_index =
- // pv3->id_postfix =
- // pv3->id =
- // pv3->param_list_head = NULL;
- // pv3->name =
- pv3->type = BOOL;
- pv3->offset = 0;
- pv3->bit = 2;
- pv3->previous = pv2;
- pv3->next = NULL;
+ /* FIXME: everything's hardcoded for now, we add an xml parser later */
+
+ iface->tpulist_head = &tpu;
+ tpu.pv_list_head = &pv1;
+
+ pv1.next = &pv2;
+ pv2.previous = &pv1;
+ pv2.next = &pv3;
+ pv3.previous = &pv2;
+
+ /* FIXME: setup thread here which handles the cycle */
+
+ fddi_backend_setstate(iface, STATE_PREOPERATIONAL);
return 0;
-pv3:
- free(pv2);
-pv2:
- free(pv1);
-pv1:
- free(tpu);
-out:
- return ENOMEM;
}
int fddi_backend_setstate(fddi_iface_t *iface, fddi_state_enum_t state)
@@ -97,6 +89,7 @@
case STATE_PREOPERATIONAL:
case STATE_OPERATIONAL:
case STATE_OPERATION_ERROR:
+ iface->state = state;
retval = 0;
break;
default:
Modified: fddi-20070618-1-trunk/tests/test_fddi_libmodbus1.c
==============================================================================
--- fddi-20070618-1-trunk/tests/test_fddi_libmodbus1.c (original)
+++ fddi-20070618-1-trunk/tests/test_fddi_libmodbus1.c Wed Jul 11 21:01:13 2007
@@ -3,6 +3,9 @@
#include <osadl/fddi.h>
+static int endme;
+static int countdown = 500;
+
int main(void)
{
fddi_iface_attr_t modbus0_attr;
@@ -10,6 +13,8 @@
int ret;
+ /* FIXME: we have to agree on a bus start workflow! */
+
/* instanciate io_interface */
fddi_iface_attr_init(&modbus0_attr);
fddi_iface_attr_setclass(&modbus0_attr, "libfddi_libmodbus.so");
@@ -21,12 +26,27 @@
return ret;
}
- ret = fddi_iface_configure(&modbus0_iface,"test_fddi_libmodbus1.xml", NULL);
+ ret = fddi_iface_configure(&modbus0_iface, "test_fddi_libmodbus1.xml", NULL);
if (ret) {
fprintf(stderr, "fddi_iface_configure() failed\n");
return ret;
}
+ /* TODO: attach callbacks to TPUs here */
+
+ /* everything is configured, now we can start */
+ ret = fddi_iface_cmd(&modbus0_iface, CMD_START);
+ if (ret) {
+ fprintf(stderr, "fddi_iface_cmd() failed\n");
+ return ret;
+ }
+
+ while (!endme) {
+ countdown--;
+ if (countdown == 0)
+ endme = 1;
+ }
+
/* destruct io_interface */
fddi_iface_destroy(&modbus0_iface);
More information about the OSADL-svn-commits
mailing list