[Armadeus-commitlog] armadeus branch, master, updated. armadeus-4.0-2428-gef7bb80
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-07-28 15:57:07
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via ef7bb8030f0429ad1a26c8bbfb03d67781207958 (commit)
via 399dcdcb7df7446b78648c0ed0971f32123a5c85 (commit)
from 20825e320da906c7d5c3fadfdb0b0e4a0234d803 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ef7bb8030f0429ad1a26c8bbfb03d67781207958
Author: Kevin JOLY <jol...@gm...>
Date: Thu Jul 28 17:51:47 2011 +0200
[BUILDROOT]Add package anybus-tools
Signed-off-by: Kevin JOLY <jol...@gm...>
commit 399dcdcb7df7446b78648c0ed0971f32123a5c85
Author: Kevin JOLY <jol...@gm...>
Date: Thu Jul 28 17:51:46 2011 +0200
[BUILDROOT]Remove package anybusd
Signed-off-by: Kevin JOLY <jol...@gm...>
-----------------------------------------------------------------------
Summary of changes:
buildroot/package/armadeus/Config.in | 2 +-
buildroot/package/armadeus/anybus-tools/Config.in | 9 +
.../package/armadeus/anybus-tools/anybus-tools.mk | 21 ++
buildroot/package/armadeus/anybusd/Config.in | 4 -
buildroot/package/armadeus/anybusd/anybusd.mk | 21 --
target/packages/anybus-tools/Makefile | 53 +++
target/packages/anybus-tools/README | 9 +
target/packages/anybus-tools/about_help.c | 130 ++++++++
target/packages/anybus-tools/about_help.h | 12 +
target/packages/anybus-tools/anybus-tools.c | 250 ++++++++++++++
target/packages/anybus-tools/edit_input.c | 104 ++++++
target/packages/anybus-tools/edit_input.h | 15 +
target/packages/anybus-tools/mailbox.c | 349 ++++++++++++++++++++
target/packages/anybus-tools/mailbox.h | 17 +
target/packages/anybus-tools/map_output.c | 105 ++++++
target/packages/anybus-tools/map_output.h | 15 +
target/packages/anybus-tools/read_reg.c | 74 ++++
target/packages/anybus-tools/read_reg.h | 13 +
target/packages/anybus-tools/sel_iface.c | 137 ++++++++
target/packages/anybus-tools/sel_iface.h | 15 +
target/packages/anybus-tools/win.c | 158 +++++++++
target/packages/anybus-tools/win.h | 15 +
target/packages/anybusd/Makefile | 32 --
target/packages/anybusd/S60anybusd | 41 ---
target/packages/anybusd/anybusd.c | 201 -----------
25 files changed, 1502 insertions(+), 300 deletions(-)
create mode 100644 buildroot/package/armadeus/anybus-tools/Config.in
create mode 100644 buildroot/package/armadeus/anybus-tools/anybus-tools.mk
delete mode 100644 buildroot/package/armadeus/anybusd/Config.in
delete mode 100644 buildroot/package/armadeus/anybusd/anybusd.mk
create mode 100644 target/packages/anybus-tools/Makefile
create mode 100644 target/packages/anybus-tools/README
create mode 100644 target/packages/anybus-tools/about_help.c
create mode 100644 target/packages/anybus-tools/about_help.h
create mode 100644 target/packages/anybus-tools/anybus-tools.c
create mode 100644 target/packages/anybus-tools/edit_input.c
create mode 100644 target/packages/anybus-tools/edit_input.h
create mode 100644 target/packages/anybus-tools/mailbox.c
create mode 100644 target/packages/anybus-tools/mailbox.h
create mode 100644 target/packages/anybus-tools/map_output.c
create mode 100644 target/packages/anybus-tools/map_output.h
create mode 100644 target/packages/anybus-tools/read_reg.c
create mode 100644 target/packages/anybus-tools/read_reg.h
create mode 100644 target/packages/anybus-tools/sel_iface.c
create mode 100644 target/packages/anybus-tools/sel_iface.h
create mode 100644 target/packages/anybus-tools/win.c
create mode 100644 target/packages/anybus-tools/win.h
delete mode 100644 target/packages/anybusd/Makefile
delete mode 100755 target/packages/anybusd/S60anybusd
delete mode 100644 target/packages/anybusd/anybusd.c
diff --git a/buildroot/package/armadeus/Config.in b/buildroot/package/armadeus/Config.in
index 33c7659..e77a511 100644
--- a/buildroot/package/armadeus/Config.in
+++ b/buildroot/package/armadeus/Config.in
@@ -1,6 +1,6 @@
menu "Armadeus specific tools/utilities"
-source package/armadeus/anybusd/Config.in
+source package/armadeus/anybus-tools/Config.in
source package/armadeus/as_devices/Config.in
source package/armadeus/demos/Config.in
source package/armadeus/fpgaregs/Config.in
diff --git a/buildroot/package/armadeus/anybus-tools/Config.in b/buildroot/package/armadeus/anybus-tools/Config.in
new file mode 100644
index 0000000..c91a828
--- /dev/null
+++ b/buildroot/package/armadeus/anybus-tools/Config.in
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_ANYBUS_TOOLS
+ bool "anybus-tools"
+ depends on BR2_PACKAGE_NCURSES
+ help
+ Tools for HMS module anybus.
+
+comment "anybus-tools requires package ncurses"
+ depends on !BR2_PACKAGE_NCURSES
+
diff --git a/buildroot/package/armadeus/anybus-tools/anybus-tools.mk b/buildroot/package/armadeus/anybus-tools/anybus-tools.mk
new file mode 100644
index 0000000..301fe6f
--- /dev/null
+++ b/buildroot/package/armadeus/anybus-tools/anybus-tools.mk
@@ -0,0 +1,21 @@
+#############################################################
+#
+# anybus-tools
+#
+#############################################################
+ANYBUS_TOOLS_VERSION = 0.1
+ANYBUS_TOOLS_BIN_NAME = anybus-tools
+ANYBUS_TOOLS_SITE=$(TOPDIR)/../target/packages/anybus-tools/
+ANYBUS_TOOLS_SITE_METHOD=copy
+LINUX_DIR=$(BUILD_DIR)/linux-$(KERNEL_VERSION)/
+
+define ANYBUS_TOOLS_BUILD_CMDS
+ ln -sf "$(LINUX_DIR)/include/net/anybus_interface.h" "$(STAGING_DIR)/usr/include/net/anybus_interface.h"
+ $(MAKE) CC="$(TARGET_CC)" -C $(@D) all
+endef
+
+define ANYBUS_TOOLS_INSTALL_TARGET_CMDS
+ $(INSTALL) -m 0755 $(ANYBUS_TOOLS_DIR)/$(ANYBUS_TOOLS_BIN_NAME) $(TARGET_DIR)/usr/bin/$(ANYBUS_TOOLS_BIN_NAME)
+endef
+
+$(eval $(call GENTARGETS,package,anybus-tools))
diff --git a/buildroot/package/armadeus/anybusd/Config.in b/buildroot/package/armadeus/anybusd/Config.in
deleted file mode 100644
index e822ab1..0000000
--- a/buildroot/package/armadeus/anybusd/Config.in
+++ /dev/null
@@ -1,4 +0,0 @@
-config BR2_PACKAGE_ANYBUSD
- bool "anybusd"
- help
- Socket daemon for anybus module
diff --git a/buildroot/package/armadeus/anybusd/anybusd.mk b/buildroot/package/armadeus/anybusd/anybusd.mk
deleted file mode 100644
index f5fbe28..0000000
--- a/buildroot/package/armadeus/anybusd/anybusd.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-#############################################################
-#
-# anybusd
-#
-#############################################################
-ANYBUSD_VERSION = 0.1
-ANYBUSD_BIN_NAME = anybusd
-ANYBUSD_INIT_SCRIPT_NAME = S60anybusd
-ANYBUSD_SITE=$(TOPDIR)/../target/packages/anybusd/
-ANYBUSD_SITE_METHOD=copy
-
-define ANYBUSD_BUILD_CMDS
- $(MAKE) CC="$(TARGET_CC)" -C $(@D) all
-endef
-
-define ANYBUSD_INSTALL_TARGET_CMDS
- $(INSTALL) -m 0755 $(ANYBUSD_DIR)/$(ANYBUSD_BIN_NAME) $(TARGET_DIR)/usr/bin/$(ANYBUSD_BIN_NAME)
- $(INSTALL) -m 0755 $(ANYBUSD_DIR)/$(ANYBUSD_INIT_SCRIPT_NAME) $(TARGET_DIR)/etc/init.d/$(ANYBUSD_INIT_SCRIPT_NAME)
-endef
-
-$(eval $(call GENTARGETS,package,anybusd))
diff --git a/target/packages/anybus-tools/Makefile b/target/packages/anybus-tools/Makefile
new file mode 100644
index 0000000..3a5cfb4
--- /dev/null
+++ b/target/packages/anybus-tools/Makefile
@@ -0,0 +1,53 @@
+# Default values for local compiling:
+ARMADEUS_BASE_DIR=../../..
+-include $(ARMADEUS_BASE_DIR)/Makefile.in
+
+STAGING_DIR:=$(ARMADEUS_BUILD_DIR)/staging_dir/
+INSTALL_DIR:=$(ARMADEUS_ROOTFS_DIR)/usr/bin/
+INITD_DIR:=$(ARMADEUS_ROOTFS_DIR)/etc/init.d/
+CC:=$(ARMADEUS_TOOLCHAIN_PATH)/arm-linux-gcc
+STRIP:=$(ARMADEUS_TOOLCHAIN_PATH)arm-linux-sstrip
+
+DEFINES=TARGET
+CFLAGS= -W -Wall -g
+LIB= -lncurses
+
+EXEC=anybus-tools
+
+default: $(EXEC)
+
+all: $(EXEC)
+
+read_reg.o: read_reg.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+about_help.o: about_help.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+mailbox.o: mailbox.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+edit_input.o: edit_input.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+map_output.o: map_output.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+sel_iface.o: sel_iface.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+win.o: win.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+anybus-tools.o: anybus-tools.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+$(EXEC): read_reg.o about_help.o mailbox.o edit_input.o map_output.o sel_iface.o win.o anybus-tools.o
+ $(CC) $(LDFLAGS) -o $@ $^ $(LIB)
+
+clean:
+ rm -rf anybus-tools
+ rm -rf *.o
+
+.PHONY: clean install uninstall
+
diff --git a/target/packages/anybus-tools/README b/target/packages/anybus-tools/README
new file mode 100644
index 0000000..306c3ad
--- /dev/null
+++ b/target/packages/anybus-tools/README
@@ -0,0 +1,9 @@
+Tools used with anybus_interface driver and HMS Anybus module.
+
+If you run it on an Armadeus board APF51-Dev, you can generate the design and
+copy the driver automatically with the script :
+your_armadeus_dir/firmware/pod_scripts/apf51_anybus_interface.pod
+A pre-designed FPGA design is also available in this directory.
+
+Have a look to this wiki page for further informations:
+http://www.armadeus.com/wiki/index.php?title=HMS_anybus_Linux
diff --git a/target/packages/anybus-tools/about_help.c b/target/packages/anybus-tools/about_help.c
new file mode 100644
index 0000000..b34996f
--- /dev/null
+++ b/target/packages/anybus-tools/about_help.c
@@ -0,0 +1,130 @@
+/*
+ * Display help and about windows in anybus-tools application.
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "about_help.h"
+
+void about()
+{
+ int height = 13;
+ int width = 45;
+ int starty = 2;
+ int startx = (COLS -width) / 2;
+ int i;
+ WINDOW* win;
+
+ win = newwin(height, width, starty, startx);
+ box(win, 0, 0);
+
+ wattron(win, A_STANDOUT);
+ for (i = 1 ; i < width - 1; i++)
+ mvwprintw(win, 0, i, " ");
+
+ mvwprintw(win, 0, (width - strlen("About...")) / 2, "About...");
+ wattroff(win, A_STANDOUT);
+
+ mvwprintw(win, 2, 2, "Anybus tools is a set of tools used");
+ mvwprintw(win, 3, 2, "to communicate with the HMS Anybus module.");
+ mvwprintw(win, 5, 2, "(C) Copyright 2011 - Armadeus Systems");
+ mvwprintw(win, 6, 2, "<su...@ar...>");
+ mvwprintw(win, 7, 2, "Author: Kevin JOLY jol...@gm...");
+ mvwprintw(win, 9, 2, "HMS website : http://www.hms.se/");
+ wattroff(win, A_STANDOUT);
+
+ wattron(win, A_STANDOUT);
+ mvwprintw(win, height - 2, (width - strlen("< Ok >")) / 2, "< Ok >");
+ wattroff(win, A_STANDOUT);
+
+ wmove(win, height - 2, (width - strlen("< Ok >")) / 2);
+ wrefresh(win);
+ getch();
+ endwin();
+}
+
+void help()
+{
+ int height = 24;
+ int width = 78;
+ int starty = 0;
+ int startx = (COLS -width) / 2;
+ int i;
+ WINDOW* win;
+
+ win = newwin(height, width, starty, startx);
+ box(win, 0, 0);
+
+ wattron(win, A_STANDOUT);
+ for (i = 1 ; i < width - 1; i++)
+ mvwprintw(win, 0, i, " ");
+
+ mvwprintw(win, 0, (width - strlen("Help")) / 2, "Help");
+ wattroff(win, A_STANDOUT);
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 1, 2, "Edit input area");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 2, 2, "Send datas to the fieldbus through the HMS Anybus module.");
+ mvwprintw(win, 3, 2, "You can move the cursor in the Anybus's internal memory using arrow key.");
+ mvwprintw(win, 4, 2, "Use < Enter > to edit the selected field.");
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 5, 2, "Map output area");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 6, 2, "View datas on the fieldbus through the HMS Anybus module.");
+ mvwprintw(win, 7, 2, "You can move the cursor in the Anybus's internal memory using arrow key.");
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 8, 2, "Mailbox message");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 9, 2, "Send and receive Anybus mailbox messages.");
+ mvwprintw(win, 10, 2, "You can move the cursor on the differents fields using arrow key.");
+ mvwprintw(win, 11, 2, "Use < Enter > to edit the selected field. You can edit the mailbox datas");
+ mvwprintw(win, 12, 2, "as the Edit input area menu. Then, move to < Send > to send the mailbox.");
+ mvwprintw(win, 13, 2, "When a response occurs, the right window is automatically refreshed.");
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 14, 2, "Read register");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 15, 2, "Read an anybus register. Hit < Enter > to edit the address.");
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 16, 2, "change interface");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 17, 2, "Change the Anybus interface corresponding to the module.");
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 18, 2, "About...");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 19, 2, "Display the \"About\" message.");
+
+ wattron(win, A_BOLD);
+ mvwprintw(win, 20, 2, "Help");
+ wattroff(win, A_BOLD);
+ mvwprintw(win, 21, 2, "Display this help.");
+
+ wattron(win, A_STANDOUT);
+ mvwprintw(win, height - 2, (width - strlen("< Ok >")) / 2, "< Ok >");
+ wattroff(win, A_STANDOUT);
+
+ wmove(win, height - 2, (width - strlen("< Ok >")) / 2);
+ wrefresh(win);
+ getch();
+ endwin();
+}
diff --git a/target/packages/anybus-tools/about_help.h b/target/packages/anybus-tools/about_help.h
new file mode 100644
index 0000000..976d996
--- /dev/null
+++ b/target/packages/anybus-tools/about_help.h
@@ -0,0 +1,12 @@
+#ifndef ABOUT_HELP_HEADER
+#define ABOUT_HELP_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ncurses.h>
+
+void about();
+void help();
+
+#endif
diff --git a/target/packages/anybus-tools/anybus-tools.c b/target/packages/anybus-tools/anybus-tools.c
new file mode 100644
index 0000000..58e1772
--- /dev/null
+++ b/target/packages/anybus-tools/anybus-tools.c
@@ -0,0 +1,250 @@
+/*
+ * anybus-tools is an application communicating with an HMS anybus module
+ * through the driver anybus_interface.
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ncurses.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/if_packet.h>
+#include <net/if.h>
+#include <netinet/in.h>
+
+#include "edit_input.h"
+#include "map_output.h"
+#include "sel_iface.h"
+#include "win.h"
+#include "mailbox.h"
+#include "read_reg.h"
+#include "about_help.h"
+
+void exit_curses()
+{
+ erase();
+ refresh();
+ curs_set(1);
+ endwin();
+ echo();
+}
+
+int init_file_ioctl(char *anybus_interface)
+{
+ char file_dev[256];
+
+ snprintf(file_dev, sizeof(file_dev), "/dev/%s_device", anybus_interface);
+
+ return open(file_dev, O_RDONLY);
+}
+
+int init_sock(char *anybus_interface)
+{
+ struct ifreq ifr;
+ struct sockaddr_ll addr;
+ int sk = 0;
+
+ addr.sll_family = AF_PACKET;
+ addr.sll_protocol = IPPROTO_UDP;
+ addr.sll_pkttype = PACKET_BROADCAST;
+
+ strncpy(ifr.ifr_name, anybus_interface, strlen(anybus_interface));
+
+ if ((sk = socket(PF_PACKET , SOCK_RAW, AF_PACKET)) < 0 ) {
+ exit_curses();
+ perror("socket");
+ return sk;
+ }
+
+ ioctl(sk, SIOCGIFINDEX, &ifr);
+ addr.sll_ifindex = ifr.ifr_ifindex;
+
+ if(bind(sk, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ exit_curses();
+ perror("bind");
+ return EXIT_FAILURE;
+ }
+
+return sk;
+}
+
+int print_menu(char *anybus_interface)
+{
+ char *choices[] = { "Edit input area", "Map output area", "Mailbox message", "Read register", "Change interface","About...", "Help" };
+ int startx, starty, width, height;
+ int ch = 0, selection = 0;
+ WINDOW *win_menu;
+
+ height = 12;
+ width = 40;
+ starty = 3;
+ startx = (COLS - width) / 2;
+
+ win_menu = create_new_win(height, width, starty, startx, "Anybus-tools");
+
+ mvwprintw(win_menu, height - 2, width - 11, "'q' : quit");
+ mvwprintw(win_menu, height - 2, 2, "interface: %s", anybus_interface);
+ refresh_menu(win_menu, selection, width, choices, 7);
+ wrefresh(win_menu);
+
+ while((ch != 'q') && (ch != 'Q') && (ch != 10))
+ {
+ ch = wgetch(win_menu);
+ switch(ch)
+ {
+ case 65:
+ if (selection > 0)
+ selection--;
+ break;
+ case 66:
+ if (selection < 6)
+ selection++;
+ break;
+ }
+
+ refresh_menu(win_menu, selection, width, choices, 7);
+ wrefresh(win_menu);
+ }
+
+ if ((ch == 'q') || (ch == 'Q'))
+ selection = -1;
+ endwin();
+
+ return selection;
+}
+
+void signal_handler(int sig)
+{
+ switch(sig) {
+ case SIGTERM:
+ exit_curses();
+ exit(0);
+ break;
+ default:
+ break;
+ }
+}
+
+int main()
+{
+ int ret = 0;
+ char anybus_interface[IFACE_NAME_LEN];
+ char *anybus_interface_ptr;
+ int sock, fd_device;
+
+ signal(SIGTERM, signal_handler);
+ initscr();
+ raw();
+ noecho();
+ curs_set(0);
+
+ if ((anybus_interface_ptr = sel_iface()) == NULL) {
+ exit_curses();
+ return EXIT_FAILURE;
+ }
+
+ strncpy(anybus_interface, anybus_interface_ptr, IFACE_NAME_LEN);
+
+ free(anybus_interface_ptr);
+
+ if ((sock = init_sock(anybus_interface)) < 0)
+ return EXIT_FAILURE;
+
+ if((fd_device = init_file_ioctl(anybus_interface)) < 0) {
+ close(sock);
+ exit_curses();
+ printf("Unable to find the device file of the anybus module\n");
+ return fd_device;
+ }
+
+ while (ret >= 0) {
+
+ erase();
+ refresh();
+
+ ret = print_menu(anybus_interface);
+
+ erase();
+ refresh();
+
+ switch(ret) {
+ case 0:
+ if (edit_input(sock, fd_device) < 0) {
+ exit_curses();
+ perror("edit_input");
+ close(fd_device);
+ close(sock);
+ return EXIT_FAILURE;
+ }
+ break;
+ case 1:
+ if (map_output(sock, fd_device) < 0) {
+ exit_curses();
+ perror("map_output");
+ close(fd_device);
+ close(sock);
+ return EXIT_FAILURE;
+ }
+ break;
+ case 2:
+ if (mailbox(fd_device) < 0) {
+ exit_curses();
+ perror("mailbox");
+ close(fd_device);
+ close(sock);
+ return EXIT_FAILURE;
+ }
+ break;
+ case 3:
+ if (read_register(fd_device) < 0) {
+ exit_curses();
+ perror("read_register");
+ close(fd_device);
+ close(sock);
+ return EXIT_FAILURE;
+ }
+ break;
+ case 4:
+ if ((anybus_interface_ptr = sel_iface()) != NULL) {
+ strcpy(anybus_interface, anybus_interface_ptr);
+ free(anybus_interface_ptr);
+ }
+ break;
+ case 5:
+ about();
+ break;
+ case 6:
+ help();
+ break;
+ }
+ }
+
+ close(fd_device);
+ close(sock);
+ exit_curses();
+ return EXIT_SUCCESS;
+}
diff --git a/target/packages/anybus-tools/edit_input.c b/target/packages/anybus-tools/edit_input.c
new file mode 100644
index 0000000..ba78bc2
--- /dev/null
+++ b/target/packages/anybus-tools/edit_input.c
@@ -0,0 +1,104 @@
+/*
+ * Edit the input data area of an HMS Anybus module to send data on fieldbus.
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "edit_input.h"
+
+int edit_input(int sock, int fd_device)
+{
+ int i, line_offset, selection_line = 0, selection_col = 0, ret;
+ char ch = 0;
+ int value;
+ struct anybus_frame frame;
+
+ memset(frame.data, 0, sizeof(frame.data));
+
+ if ((ret = ioctl(fd_device, ANYBUS_MAP_INPUT, frame.data)) < 0)
+ return ret;
+
+ while ((ch != 'q') && (ch != 'Q'))
+ {
+
+ line_offset = 0;
+
+ for (i = 0 ; i < 0x100 ; i++) {
+
+ if ((i % 16 == 0) && (i != 0))
+ line_offset++;
+
+ mvprintw(line_offset, (i % 16) * 5 + 4, " ");
+
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attron(A_STANDOUT);
+ mvprintw(line_offset, (i % 16) * 5, "%04X", frame.data[i]);
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attroff(A_STANDOUT);
+ }
+
+ attron(A_STANDOUT);
+ for (i = 0 ; i < 80 ; i++) {
+ mvprintw(23, i, " ");
+ }
+ mvprintw(23, 1, "Anybus address: 0x%03X", (32 * selection_line + selection_col * 2));
+ mvprintw(23, 30, "Fieldbus address: 0x%02X", (16 * selection_line + selection_col));
+ mvprintw(23, 60, "q : quit this tool");
+ attroff(A_STANDOUT);
+
+ refresh();
+
+ move(selection_line, selection_col*5);
+
+ ch = getch();
+ switch(ch)
+ {
+ case 65: /* Up */
+ if (selection_line > 0)
+ selection_line--;
+ break;
+ case 66: /* Down */
+ if (selection_line < 15)
+ selection_line++;
+ break;
+ case 68: /* Left */
+ if (selection_col > 0)
+ selection_col--;
+ break;
+ case 67: /* Right */
+ if (selection_col < 15)
+ selection_col++;
+ break;
+ case 10: /* Validate */
+ mvprintw(selection_line, selection_col * 5, " ");
+ echo();
+ mvscanw(selection_line, selection_col * 5, "%4X", &value);
+ noecho();
+ frame.data[16 * selection_line + selection_col] = value;
+ frame.reg = 0;
+
+ frame.len = 256;
+ if ((ret = send(sock, (void *)&frame, sizeof(frame), 0)) < 0)
+ return ret;
+
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/target/packages/anybus-tools/edit_input.h b/target/packages/anybus-tools/edit_input.h
new file mode 100644
index 0000000..6332b67
--- /dev/null
+++ b/target/packages/anybus-tools/edit_input.h
@@ -0,0 +1,15 @@
+#ifndef EDIT_INPUT_HEADER
+#define EDIT_INPUT_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ncurses.h>
+#include <string.h>
+#include <net/anybus_interface.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+int edit_input(int sock, int fd_device);
+
+#endif
diff --git a/target/packages/anybus-tools/mailbox.c b/target/packages/anybus-tools/mailbox.c
new file mode 100644
index 0000000..0b2e566
--- /dev/null
+++ b/target/packages/anybus-tools/mailbox.c
@@ -0,0 +1,349 @@
+/*
+ * Send and receive mailbox message from the HMS Anybus module
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "mailbox.h"
+
+int mailbox(int fd_device)
+{
+ int startx, starty, width, height, ycurpos, xcurpos;
+ WINDOW *win_send_mb, *win_recv_mb;
+ char focus = 0, ch;
+ int selection = 0, i, ret = 0;
+ struct mailbox_msg mail_to_send, received_mail;
+ unsigned short value;
+ fd_set fdlist;
+
+ memset(&mail_to_send, 0, sizeof(mail_to_send));
+ memset(&received_mail, 0, sizeof(received_mail));
+
+ height = 19;
+ width = 38;
+ starty = 1;
+ startx = 1;
+init_windows:
+ win_send_mb = create_new_win(height, width, starty, startx, "Mail to send");
+ win_recv_mb = create_new_win(height, width, starty, startx + 39, "Response mail");
+
+ attron(A_STANDOUT);
+ for (i = 0 ; i < 80 ; i++) {
+ mvprintw(23, i, " ");
+ }
+
+ mvprintw(23, 2, "<- or -> : switch window");
+ mvprintw(23, 60, "q : quit this tool");
+ attroff(A_STANDOUT);
+
+ refresh_form_mail_to_send(win_send_mb, selection, width, mail_to_send, focus ^ 1);
+ wrefresh(win_send_mb);
+ refresh_form_received_mail(win_recv_mb, selection, width, received_mail, focus);
+ wrefresh(win_recv_mb);
+ refresh();
+
+
+ while((ch != 'q') && (ch != 'Q')) {
+
+ FD_ZERO(&fdlist);
+ FD_SET(fd_device, &fdlist);
+ FD_SET(0, &fdlist);
+
+ if (selection == 13)
+ ycurpos = starty + selection + 3;
+ else
+ ycurpos = starty + selection + 2;
+
+ if (focus == 0) {
+ if (selection == 12)
+ xcurpos = startx + width - 7;
+ else if (selection == 13)
+ xcurpos = startx + width - 21;
+ else
+ xcurpos = startx + width - 5;
+ } else {
+ if (selection == 12)
+ xcurpos = startx + 39 + width - 7;
+ else
+ xcurpos = startx + 39 + width - 5;
+ }
+
+ move(ycurpos, xcurpos);
+ refresh();
+
+ if (select(fd_device + 1, &fdlist, NULL, NULL, NULL) < 0)
+ mvprintw(0, 0, "Error");
+
+ if (FD_ISSET(0, &fdlist)) {
+ ch = getch();
+ switch(ch) {
+ case 65: /* Up */
+ if (selection > 0)
+ selection--;
+ break;
+ case 66: /* Down */
+ if (((selection < 13) && (focus == 0)) || (selection < 12))
+ selection++;
+ break;
+ case 68: /* Left */
+ focus = 0;
+ selection = 0;
+ break;
+ case 67: /* Right */
+ focus = 1;
+ selection = 0;
+ break;
+ case 10:
+ if (focus == 0) {
+ if (selection < 12) {
+ mvwprintw(win_send_mb, selection + 2, width - 5, " ");
+ echo();
+ mvwscanw(win_send_mb, selection + 2, width - 5, "%4X", &value);
+ noecho();
+ }
+ switch (selection) {
+ case 0:
+ mail_to_send.id = value;
+ break;
+ case 1:
+ mail_to_send.msg_information = value;
+ break;
+ case 2:
+ mail_to_send.command_number = value;
+ break;
+ case 3:
+ if (value > ANYBUS_MAILBOX_DATA_LEN)
+ value = ANYBUS_MAILBOX_DATA_LEN;
+ mail_to_send.data_size = value;
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ mail_to_send.extended_word[selection - 4] = value;
+ break;
+ case 12:
+ endwin();
+ edit_data_mailbox(mail_to_send.data, mail_to_send.data_size / 2);
+ goto init_windows;
+ break;
+ case 13:
+ if ((ret = ioctl(fd_device, ANYBUS_MB_WRITE, &mail_to_send)) < 0)
+ return ret;
+ break;
+ }
+ } else {
+ endwin();
+ if ((ch == 10) && (selection == 12))
+ map_data_mailbox(received_mail.data, received_mail.data_size / 2);
+ goto init_windows;
+ }
+ break;
+ }
+ }
+ if (FD_ISSET(fd_device, &fdlist)) {
+ if((ret = ioctl(fd_device, ANYBUS_MB_READ, &received_mail)) < 0)
+ return ret;
+ }
+
+ refresh_form_mail_to_send(win_send_mb, selection, width, mail_to_send, focus ^ 1);
+ wrefresh(win_send_mb);
+ refresh_form_received_mail(win_recv_mb, selection, width, received_mail, focus);
+ wrefresh(win_recv_mb);
+ }
+
+ endwin();
+
+ return 0;
+}
+
+int edit_data_mailbox(unsigned short data[ANYBUS_DATA_LEN], int data_len)
+{
+ int i, line_offset, selection_line = 0, selection_col = 0;
+ char ch = 0;
+ int value;
+
+ erase();
+ refresh();
+
+ if (data_len == 0) {
+ mvprintw(2, 2, "/!\\ No datas available in this mailbox message.");
+ mvprintw(3, 2, " Press any key to continue.");
+ getch();
+ erase();
+ refresh();
+ return -1;
+ }
+
+ while ((ch != 'q') && (ch != 'Q'))
+ {
+
+ line_offset = 0;
+
+ for (i = 0 ; i < data_len ; i++) {
+
+ if ((i % 16 == 0) && (i != 0))
+ line_offset++;
+
+ mvprintw(line_offset, (i % 16) * 5 + 4, " ");
+
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attron(A_STANDOUT);
+
+ mvprintw(line_offset, (i % 16) * 5, "%04X", data[i]);
+
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attroff(A_STANDOUT);
+ }
+
+ attron(A_STANDOUT);
+ for (i = 0 ; i < 80 ; i++) {
+ mvprintw(23, i, " ");
+ }
+
+ mvprintw(23, 1, "Address: 0x%03X", (32 * selection_line + selection_col * 2));
+ mvprintw(23, 60, "q : quit this tool");
+ attroff(A_STANDOUT);
+
+ refresh();
+
+ move(selection_line, selection_col*5);
+
+ ch = getch();
+ switch(ch)
+ {
+ case 65: /* Up */
+ if (selection_line > 0)
+ selection_line--;
+ break;
+ case 66: /* Down */
+ if (selection_line < ((data_len - 1)/ 16)) {
+ selection_line++;
+ if ((selection_line == ((data_len - 1)/ 16)) && (selection_col > (data_len - 1) % 16))
+ selection_col = (data_len - 1) % 16;
+ }
+ break;
+ case 68: /* Left */
+ if (selection_col > 0)
+ selection_col--;
+ break;
+ case 67: /* Right */
+ if (((selection_line != ((data_len - 1)/ 16)) && selection_col < 15) || (selection_col < ((data_len - 1) % 16)))
+ selection_col++;
+ break;
+ case 10: /* Validate */
+ mvprintw(selection_line, selection_col * 5, " ");
+ echo();
+ mvscanw(selection_line, selection_col * 5, "%4X", &value);
+ noecho();
+ data[16 * selection_line + selection_col] = value;
+ break;
+ }
+ }
+
+ erase();
+ refresh();
+
+ return 0;
+}
+
+int map_data_mailbox(unsigned short data[ANYBUS_DATA_LEN], int data_len)
+{
+ int i, line_offset, selection_line = 0, selection_col = 0;
+ char ch = 0;
+
+ erase();
+ refresh();
+
+ if (data_len == 0) {
+ mvprintw(2, 2, "/!\\ No datas available in this mailbox message.");
+ mvprintw(3, 2, " Press any key to continue.");
+ getch();
+ erase();
+ refresh();
+ return -1;
+ }
+
+ while ((ch != 'q') && (ch != 'Q'))
+ {
+
+ line_offset = 0;
+
+ for (i = 0 ; i < data_len ; i++) {
+
+ if ((i % 16 == 0) && (i != 0))
+ line_offset++;
+
+ mvprintw(line_offset, (i % 16) * 5 + 4, " ");
+
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attron(A_STANDOUT);
+
+ mvprintw(line_offset, (i % 16) * 5, "%04X", data[i]);
+
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attroff(A_STANDOUT);
+ }
+
+ attron(A_STANDOUT);
+ for (i = 0 ; i < 80 ; i++) {
+ mvprintw(23, i, " ");
+ }
+
+ mvprintw(23, 1, "Address: 0x%03X", (32 * selection_line + selection_col * 2));
+ mvprintw(23, 60, "q : quit this tool");
+ attroff(A_STANDOUT);
+
+ refresh();
+
+ move(selection_line, selection_col*5);
+
+ ch = getch();
+ switch(ch)
+ {
+ case 65: /* Up */
+ if (selection_line > 0)
+ selection_line--;
+ break;
+ case 66: /* Down */
+ if (selection_line < ((data_len - 1)/ 16)) {
+ selection_line++;
+ if ((selection_line == ((data_len - 1)/ 16)) && (selection_col > (data_len - 1) % 16))
+ selection_col = (data_len - 1) % 16;
+ }
+ break;
+ case 68: /* Left */
+ if (selection_col > 0)
+ selection_col--;
+ break;
+ case 67: /* Right */
+ if (((selection_line != ((data_len - 1)/ 16)) && selection_col < 15) || (selection_col < ((data_len - 1) % 16)))
+ selection_col++;
+ break;
+ }
+ }
+
+ erase();
+ refresh();
+
+ return 0;
+}
diff --git a/target/packages/anybus-tools/mailbox.h b/target/packages/anybus-tools/mailbox.h
new file mode 100644
index 0000000..f2b7cf1
--- /dev/null
+++ b/target/packages/anybus-tools/mailbox.h
@@ -0,0 +1,17 @@
+#ifndef MAILBOX_HEADER
+#define MAILBOX_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ncurses.h>
+#include <net/anybus_interface.h>
+#include <sys/ioctl.h>
+
+#include "win.h"
+
+int mailbox(int fd_device);
+int edit_data_mailbox(unsigned short data[ANYBUS_DATA_LEN], int data_len);
+int map_data_mailbox(unsigned short data[ANYBUS_DATA_LEN], int data_len);
+
+#endif
diff --git a/target/packages/anybus-tools/map_output.c b/target/packages/anybus-tools/map_output.c
new file mode 100644
index 0000000..4658c85
--- /dev/null
+++ b/target/packages/anybus-tools/map_output.c
@@ -0,0 +1,105 @@
+/*
+ * Watch HMS Anybus output data area memory
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "map_output.h"
+
+int map_output(int sock, int fd_device)
+{
+ int i, line_offset, selection_line = 0, selection_col = 0, ret;
+ char ch = 0;
+ struct anybus_frame frame;
+ fd_set readfs_list;
+
+ memset (frame.data, 0, sizeof(frame.data));
+
+ if ((ret = ioctl(fd_device, ANYBUS_MAP_OUTPUT, frame.data)) < 0) {
+ return ret;
+ }
+
+ while ((ch != 'q') && (ch != 'Q')) {
+
+ FD_ZERO(&readfs_list);
+ FD_SET(0, &readfs_list);
+ FD_SET(sock, &readfs_list);
+
+ line_offset = 0;
+
+ for (i = 0 ; i < 0x100 ; i++) {
+
+ if ((i % 16 == 0) && (i != 0))
+ line_offset++;
+
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attron(A_STANDOUT);
+
+ mvprintw(line_offset, (i % 16) * 5, "%04X", frame.data[i]);
+ if ((selection_col == i % 16) && (selection_line == line_offset))
+ attroff(A_STANDOUT);
+ }
+
+ attron(A_STANDOUT);
+ for (i = 0 ; i < 80 ; i++) {
+ mvprintw(23, i, " ");
+ }
+ mvprintw(23, 1, "Anybus address: 0x%03X", (32 * selection_line + selection_col * 2));
+ mvprintw(23, 30, "Fieldbus address: 0x%02X", (16 * selection_line + selection_col));
+ mvprintw(23, 60, "q : quit this tool");
+ attroff(A_STANDOUT);
+
+ move(selection_line, selection_col*5);
+ refresh();
+
+ if((ret = select(sock + 1, &readfs_list, NULL, NULL, NULL)) < 0)
+ {
+ return ret;
+ }
+
+ if(FD_ISSET(sock, &readfs_list)) {
+ if((ret = recv(sock, (void *)&frame, sizeof(frame), 0)) < 0)
+ return ret;
+ }
+
+ if(FD_ISSET(0, &readfs_list)) {
+ ch = getch();
+ switch(ch) {
+ case 65: /* Up */
+ if (selection_line > 0)
+ selection_line--;
+ break;
+ case 66: /* Down */
+ if (selection_line < 15)
+ selection_line++;
+ break;
+ case 68: /* Left */
+ if (selection_col > 0)
+ selection_col--;
+ break;
+ case 67: /* Right */
+ if (selection_col < 15)
+ selection_col++;
+ break;
+ }
+ }
+
+ }
+
+ return 0;
+}
diff --git a/target/packages/anybus-tools/map_output.h b/target/packages/anybus-tools/map_output.h
new file mode 100644
index 0000000..a84ffec
--- /dev/null
+++ b/target/packages/anybus-tools/map_output.h
@@ -0,0 +1,15 @@
+#ifndef MAP_OUTPUT_HEADER
+#define MAP_OUTPUT_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ncurses.h>
+#include <net/anybus_interface.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+int map_output(int sock, int fd_device);
+
+#endif
diff --git a/target/packages/anybus-tools/read_reg.c b/target/packages/anybus-tools/read_reg.c
new file mode 100644
index 0000000..a7e7565
--- /dev/null
+++ b/target/packages/anybus-tools/read_reg.c
@@ -0,0 +1,74 @@
+/*
+ * Read a specific in the HMS Anybus module.
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "read_reg.h"
+
+int read_register(int fd_device)
+{
+ WINDOW *win;
+ struct anybus_register anybus_reg = {.address = 0, .value = 0 };
+ int i, ret = 0;
+ char ch;
+ int height = 8;
+ int width = 22;
+ int starty = 2;
+ int startx = (COLS -width) / 2;
+ unsigned short value;
+
+ win = newwin(height, width, starty, startx);
+ box(win, 0, 0);
+
+ wattron(win, A_STANDOUT);
+ for (i = 1 ; i < width - 1; i++)
+ mvwprintw(win, 0, i, " ");
+
+ mvwprintw(win, 0, (width - strlen("Read register")) / 2, "Read register");
+ wattroff(win, A_STANDOUT);
+
+ mvwprintw(win, 2, 2, "Address :");
+ mvwprintw(win, 3, 2, "Value :");
+ mvwprintw(win, height - 2, 1, "q : quit this tool");
+
+ while ((ch != 'q') && (ch != 'Q')) {
+ wattron(win, A_STANDOUT);
+ mvwprintw(win, 2, width - 4, "%03X", anybus_reg.address);
+ wattroff(win, A_STANDOUT);
+ mvwprintw(win, 3, width - 3, "%02X", anybus_reg.value);
+
+ wmove(win, 2, width-4);
+ wrefresh(win);
+ ch = getch();
+
+ if (ch == 10) {
+ mvwprintw(win, 2, width - 4, " ");
+ echo();
+ mvwscanw(win, 2, width - 4, "%3X", &value);
+ noecho();
+ anybus_reg.address = value;
+ if ((ret = ioctl(fd_device, ANYBUS_READ_REG, &anybus_reg)) < 0) {
+ return ret;
+ }
+ }
+ }
+
+ endwin();
+ return 0;
+}
diff --git a/target/packages/anybus-tools/read_reg.h b/target/packages/anybus-tools/read_reg.h
new file mode 100644
index 0000000..7c1c6e8
--- /dev/null
+++ b/target/packages/anybus-tools/read_reg.h
@@ -0,0 +1,13 @@
+#ifndef READ_REG_HEADER
+#define READ_REG_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ncurses.h>
+#include <string.h>
+#include <net/anybus_interface.h>
+#include <sys/ioctl.h>
+
+int read_register(int fd_device);
+
+#endif
diff --git a/target/packages/anybus-tools/sel_iface.c b/target/packages/anybus-tools/sel_iface.c
new file mode 100644
index 0000000..afc9891
--- /dev/null
+++ b/target/packages/anybus-tools/sel_iface.c
@@ -0,0 +1,137 @@
+/*
+ * Select the anybus interface used for communicate with the HMS Anybus module
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "sel_iface.h"
+
+int is_anybus(char *iface_name)
+{
+ char buffer[IFACE_NAME_LEN];
+
+ strncpy(buffer, iface_name, strlen(iface_name) - 1);
+
+ if(strcmp(buffer, "anybus")) /* False */
+ return 0;
+ else
+ return 1;
+}
+
+int print_menu_iface(char **ifaces_names,int n_ifaces)
+{
+ int startx, starty, width, height;
+ int ch = 0, selection = 0;
+ WINDOW *win_menu_iface;
+
+ if (n_ifaces < 1) {
+ mvprintw(2, 2, "/!\\ No anybus interface found.");
+ refresh();
+ return -1;
+ }
+
+ height = 12;
+ width = 40;
+ starty = 3;
+ startx = (COLS - width) / 2;
+
+ win_menu_iface = create_new_win(height, width, starty, startx, "Select anybus interface");
+
+ mvwprintw(win_menu_iface, height - 2, 2, "'q' : quit");
+ refresh_menu(win_menu_iface, selection, width, ifaces_names, n_ifaces);
+ wrefresh(win_menu_iface);
+
+ while((ch != 'q') && (ch != 'Q') && (ch != 10)) {
+ ch = wgetch(win_menu_iface);
+ switch(ch)
+ {
+ case 65:
+ if (selection > 0)
+ selection--;
+ break;
+ case 66:
+ if (selection < n_ifaces -1)
+ selection++;
+ break;
+ }
+
+ refresh_menu(win_menu_iface, selection, width, ifaces_names, n_ifaces);
+ wrefresh(win_menu_iface);
+ }
+
+ if ((ch == 'q') || (ch == 'Q'))
+ selection = -1;
+ endwin();
+
+ return selection;
+}
+
+char* sel_iface()
+{
+ FILE *f_net_dev;
+ char *ifaces_names[IFACE_NAME_LEN];
+ char buffer[IFACE_NAME_LEN];
+ int n_ifaces = 0;
+ int iface_char = 0;
+ char read_char = 0;
+ int i, selection;
+
+ f_net_dev = fopen("/proc/net/dev", "r");
+
+ if (f_net_dev == NULL) {
+ printf("Unable to open /proc/net/dev\n");
+ return NULL;
+ }
+
+ while(!feof(f_net_dev)) {
+ read_char = getc(f_net_dev);
+
+ if (read_char == '\n') {
+ iface_char = 0; /* Reset the interface name cursor */
+ } else if ((iface_char < IFACE_NAME_LEN)) { /* Prevent from buffer overflow */
+ if (read_char == ':') /* End of interface name */
+ read_char = '\0';
+ if (read_char != ' ') { /* Do not copy whitespace */
+ buffer[iface_char] = read_char;
+ iface_char++; /* Increment the interface name cursor */
+ }
+ if (read_char == '\0') {
+ if (is_anybus(buffer)) {
+ ifaces_names[n_ifaces] = (char*)malloc(IFACE_NAME_LEN);
+ strcpy(ifaces_names[n_ifaces], buffer);
+ n_ifaces++; /* Increment the interface cursor */
+ }
+ }
+ }
+ }
+
+ fclose(f_net_dev);
+
+ selection = print_menu_iface(ifaces_names, n_ifaces);
+
+ /* Free useless ifaces_names */
+ for(i = 0; i < n_ifaces; i++) {
+ if (i != selection)
+ free(ifaces_names[i]);
+ }
+
+ if (selection < 0)
+ return NULL;
+
+ return ifaces_names[selection];
+}
diff --git a/target/packages/anybus-tools/sel_iface.h b/target/packages/anybus-tools/sel_iface.h
new file mode 100644
index 0000000..220684e
--- /dev/null
+++ b/target/packages/anybus-tools/sel_iface.h
@@ -0,0 +1,15 @@
+#ifndef SEL_IFACE_HEADER
+#define SEL_IFACE_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ncurses.h>
+
+#include "win.h"
+
+#define IFACE_NAME_LEN 10
+
+char* sel_iface();
+
+#endif
diff --git a/target/packages/anybus-tools/win.c b/target/packages/anybus-tools/win.c
new file mode 100644
index 0000000..b2f50ce
--- /dev/null
+++ b/target/packages/anybus-tools/win.c
@@ -0,0 +1,158 @@
+/*
+ * Some basics menu operations with ncurses...
+ *
+ * Copyright (C) 2011 Armadeus Systems
+ * Kevin JOLY <jol...@gm...>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include "win.h"
+
+WINDOW *create_new_win(int height, int width, int starty, int startx, const char *title)
+{
+ WINDOW *win;
+ int i;
+
+ win = newwin(height, width, starty, startx);
+ box(win, 0, 0);
+
+ wattron(win, A_STANDOUT);
+
+ for (i = 1 ; i < width - 1; i++)
+ mvwprintw(win, 0, i, " ");
+
+ mvwprintw(win, 0, (width - strlen(title)) / 2, title);
+
+ wattroff(win, A_STANDOUT);
+
+ wrefresh(win);
+
+ return win;
+}
+
+void refresh_menu(WINDOW *win, int selection, int width, char **choices, int n_choices)
+{
+ int i;
+
+ for (i = 0; i < n_choices ; i++) {
+ if ( i == selection)
+ wattron(win, A_BOLD);
+ mvwprintw(win, 2 + i, ((width - strlen(choices[i])) / 2) - 2, " ");
+ mvwprintw(win, 2 + i, (width - strlen(choices[i])) / 2, choices[i]);
+ if ( i == selection)
+ wattroff(win, A_BOLD);
+ }
+
+ mvwprintw(win, 2 + selection, (width - strlen(choices[selection])) / 2 - 2, "*");
+ wmove(win, 2 + selection, ((width - strlen(choices[selection])) / 2) - 2);
+}
+
+void refresh_form_mail_to_send(WINDOW *win, int selection, int width, struct mailbox_msg mail, char focused)
+{
+ int i;
+ char *choices[] = { "Message ID", "Message information", "Command Number", "Data size","Extended Word 1", "Extended Word 2",
+ "Extended Word 3", "Extended Word 4", "Extended Word 5", "Extended Word 6", "Extended Word 7", "Extended Word 8", "Data"};
+
+ for (i = 0; i < 14 ; i++) {
+
+ if ( i < 13)
+ mvwprintw(win, 2 + i, 2, choices[i]);
+
+ if ((i == selection) && (focused == 1))
+ wattron(win, A_STANDOUT);
+
+ switch(i) {
+ case 0:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.id);
+ break;
+ case 1:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.msg_information);
+ break;
+ case 2:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.command_number);
+ break;
+ case 3:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.data_size);
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.extended_word[i - 4]);
+ break;
+ case 12:
+ mvwprintw(win, 2 + i, width - 9, "< EDIT >");
+ break;
+ case 13:
+ mvwprintw(win, 3 + i, (width - strlen("< SEND >")) / 2, "< SEND >");
+ break;
+ }
+
+ if ((i == selection) && (focused == 1))
+ wattroff(win, A_STANDOUT);
+ }
+
+}
+
+void refresh_form_received_mail(WINDOW *win, int selection, int width, struct mailbox_msg mail, char focused)
+{
+ int i;
+ char *choices[] = { "Message ID", "Messages informations", "Command Number", "Data size","Extended Word 1", "Extended Word 2",
+ "Extended Word 3", "Extended Word 4", "Extended Word 5", "Extended Word 6", "Extended Word 7", "Extended Word 8", "Data"};
+
+ for (i = 0; i < 13 ; i++) {
+
+ mvwprintw(win, 2 + i, 2, choices[i]);
+
+ if ((i == selection) && (focused == 1))
+ wattron(win, A_STANDOUT);
+
+ switch(i) {
+ case 0:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.id);
+ break;
+ case 1:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.msg_information);
+ break;
+ case 2:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.command_number);
+ break;
+ case 3:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.data_size);
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ mvwprintw(win, 2 + i, width - 5, "%04X", mail.extended_word[i - 4]);
+ break;
+ case 12:
+ mvwprintw(win, 2 + i, width - 9, "< VIEW >");
+ }
+
+ if ((i == selection) && (focused == 1))
+ wattroff(win, A_STANDOUT);
+ }
+
+}
diff --git a/target/packages/anybus-tools/win.h b/target/packages/anybus-tools/win.h
new file mode 100644
index 0000000..5cdeb56
--- /dev/null
+++ b/target/packages/anybus-tools/win.h
@@ -0,0 +1,15 @@
+#ifndef WIN_HEADER
+#define WIN_HEADER
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ncurses.h>
+#include <net/anybus_interface.h>
+
+WINDOW *create_new_win(int height, int width, int starty, int startx, const char *title);
+void refresh_menu(WINDOW *win, int selection, int width, char **choices, int n_choices);
+void refresh_form_mail_to_send(WINDOW *win, int selection, int width, struct mailbox_msg mail, char focused);
+void refresh_form_received_mail(WINDOW *win, int selection, int width, struct mailbox_msg mail, char focused);
+
+#endif
diff --git a/target/packages/anybusd/Makefile b/target/packages/anybusd/Makefile
deleted file mode 100644
index 1b7e984..0000000
--- a/target/packages/anybusd/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-# Default values for local compiling:
-ARMADEUS_BASE_DIR=../../..
--include $(ARMADEUS_BASE_DIR)/Makefile.in
-
-STAGING_DIR:=$(ARMADEUS_BUILD_DIR)/staging_dir/
-INSTALL_DIR:=$(ARMADEUS_ROOTFS_DIR)/usr/bin/
-INITD_DIR:=$(ARMADEUS_ROOTFS_DIR)/etc/init.d/
-CC:=$(ARMADEUS_TOOLCHAIN_PATH)/arm-linux-gcc
-STRIP:=$(ARMADEUS_TOOLCHAIN_PATH)arm-linux-sstrip
-
-DEFINES=TARGET
-CFLAGS= -Wall
-
-EXEC=anybusd
-INIT_SCRIPT=S60anybusd
-
-default: $(EXEC)
-
-all: $(EXEC)
-
-anybusd.o: anybusd.c
- $(CC) $(CFLAGS) -c -o $@ $^
-
-$(EXEC): anybusd.o
- $(CC) $(LDFLAGS) -o $@ $^
-
-clean:
- rm -rf anybusd
- rm -rf *.o
-
-.PHONY: clean install uninstall
-
diff --git a/target/packages/anybusd/S60anybusd b/target/packages/anybusd/S60anybusd
deleted file mode 100755
index 9a169fd..0000000
--- a/target/packages/anybusd/S60anybusd
+++ /dev/null
@@ -1,41 +0,0 @@
-#! /bin/sh
-
-start() {
- modprobe anybus_interface_platform
- modprobe anybus_interface
- echo -n "Starting Anybusd: "
- anybusd
- echo "done"
-}
-
-stop() {
- rmmod anybus_interface
- rmmod anybus_interface_platform
- echo -n "Stopping Anybusd: "
- killall anybusd
- echo "done"
-}
-
-restart() {
- stop
- start
-}
-
-# See how we were called.
-case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart|reload)
- restart
- ;;
- *)
- echo "Usage: $0 {start|stop|reload|restart}"
- exit 1
-esac
-
-exit $?
-
diff --git a/target/packages/anybusd/anybusd.c b/target/packages/anybusd/anybusd.c
deleted file mode 100644
index 6ec51cb..0000000
--- a/target/packages/anybusd/anybusd.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Daemon for interface with HMS Anybus module through FPGA.
- * (Driver anybus_interface is required)
- *
- * Copyright (C) 2011 <jol...@gm...>
- * Armadeus Systems
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <signal.h>
-#include <arpa/inet.h>
-#include <errno.h>
-
-#define DAEMON_NAME "anybusd"
-#define PID_FILE "/var/run/anybusd.pid"
-
-/* ctrl_register on Wishbone bus */
-#define ANYBUS_TRANSMIT 0x0002
-#define ANYBUS_RECEIVE 0x0004
-#define ANYBUS_4_CLOCK_CYCLES 0x0020
-#define ANYBUS_TRANSMISSION_ERROR 0x0001
-
-/* FPGA registers*/
-#define CTRL_REG 0x0002
-#define ADDRESS_REG 0x0004
-#define DATA_REG 0x0006
-
-#define ACTION 0x10
-
-/* Indication register on AnyBus module */
-#define ANYBUS_SEND 0x80
-#define ANYBUS_ACK 0x40
-
-#define PORT 4037
-
-void signal_handler(int sig)
-{
- switch(sig) {
- case SIGTERM:
- exit(0);
- break;
- default:
- break;
- }
-}
-
-void write_fpga(unsigned short address, unsigned short value, void* fpga_mem)
-{
- *(unsigned short*)(fpga_mem+(address)) = value;
-}
-
-unsigned short read_fpga(unsigned short address, void* fpga_mem)
-{
- return *(unsigned short*)(fpga_mem+(address));
-}
-
-int write_anybus(unsigned short address, unsigned short value, void* fpga_mem)
-{
- int n;
- write_fpga(ADDRESS_REG, address, fpga_mem);
- write_fpga(DATA_REG, value, fpga_mem);
- write_fpga(CTRL_REG, ANYBUS_4_CLOCK_CYCLES | ANYBUS_TRANSMIT, fpga_mem);
-
- if ((n = read_fpga(CTRL_REG, fpga_mem)) & ANYBUS_TRANSMISSION_ERROR) {
- return -1;
- }
- return 0;
-}
-
-int read_anybus(unsigned short address, void* fpga_mem)
-{
- int n;
- write_fpga(ADDRESS_REG, address, fpga_mem);
- write_fpga(CTRL_REG, ANYBUS_4_CLOCK_CYCLES | ANYBUS_RECEIVE, fpga_mem);
-
- if ((n = read_fpga(CTRL_REG, fpga_mem)) & ANYBUS_TRANSMISSION_ERROR) {
- return -1;
- }
- return read_fpga(DATA_REG, fpga_mem);
-}
-
-int main(int argc, char *argv[])
-{
- int file_mem;
- socklen_t sinsize;
- int listen...
[truncated message content] |