Commit 1f134bf3 authored by Claes Sjofors's avatar Claes Sjofors

Profinet viewer, configured devices displayed

parent 116e419a
......@@ -4,7 +4,8 @@ link_rule_mk := 1
link = $(ldxx) -L$(pwr_elib) $(elinkflags) $(domap) -o $(pwr_exe)/profinet_viewer_gtk \
$(bld_dir)/profinet_viewer_gtk.o \
$(bld_dir)/pn_viewer_gtk.o $(bld_dir)/pn_viewernav_gtk.o \
$(bld_dir)/pn_viewer.o $(bld_dir)/pn_viewernav.o $(bld_dir)/pn_viewer_pnac.o\
$(bld_dir)/pn_viewer.o $(bld_dir)/pn_viewernav.o \
$(bld_dir)/pn_viewer_pnac.o\
$(wb_msg_eobjs) $(rt_msg_eobjs) \
$(pwr_eobj)/rt_io_user.o \
$(pwre_conf_libdir) $(pwre_conf_libpwrxttgtk) $(pwre_conf_libpwrxtt) $(pwre_conf_libgtk) \
......
......@@ -108,6 +108,9 @@ PnViewerGtk::PnViewerGtk (
GtkWidget *functions_update = gtk_menu_item_new_with_mnemonic("_Update");
g_signal_connect(functions_update, "activate", G_CALLBACK(activate_update), this);
GtkWidget *functions_filter = gtk_menu_item_new_with_mnemonic("_Filter");
g_signal_connect(functions_filter, "activate", G_CALLBACK(activate_filter), this);
GtkWidget *functions_setdevice = gtk_menu_item_new_with_mnemonic("_Set Device Properties");
g_signal_connect(functions_setdevice, "activate", G_CALLBACK(activate_setdevice), this);
......@@ -118,6 +121,7 @@ PnViewerGtk::PnViewerGtk (
GtkMenu *functions_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_update);
gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_filter);
gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_setdevice);
gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_changevalue);
......@@ -181,12 +185,31 @@ PnViewerGtk::PnViewerGtk (
gtk_widget_show_all( statusbar);
// Create viewernav
viewernav = new PnViewerNavGtk( this, form, &nav_widget);
GtkWidget *nav_paned = gtk_hpaned_new();
GtkWidget *nav_left = gtk_vbox_new( FALSE, 0);
GtkWidget *nav_right = gtk_vbox_new( FALSE, 0);
GtkWidget *header_left = gtk_label_new( "Devices on Network");
GtkWidget *header_right = gtk_label_new( "Devices from Configuration");
viewernav = new PnViewerNavGtk( this, nav_right, viewer_eType_Network, &nav_widget);
viewernav->change_value_cb = &change_value;
viewernav->message_cb = &message_cb;
viewernavconf = new PnViewerNavGtk( this, nav_left, viewer_eType_Configuration, &navconf_widget);
viewernavconf->change_value_cb = &change_value;
viewernavconf->message_cb = &message_cb;
gtk_box_pack_start( GTK_BOX(nav_left), header_left, FALSE, FALSE, 5);
gtk_box_pack_start( GTK_BOX(nav_left), nav_widget, TRUE, TRUE, 5);
gtk_box_pack_start( GTK_BOX(nav_right), header_right, FALSE, FALSE, 5);
gtk_box_pack_start( GTK_BOX(nav_right), navconf_widget, TRUE, TRUE, 5);
gtk_paned_pack1( GTK_PANED(nav_paned), nav_left, TRUE, TRUE);
gtk_paned_pack2( GTK_PANED(nav_paned), nav_right, FALSE, TRUE);
gtk_box_pack_start( GTK_BOX(form), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
gtk_box_pack_start( GTK_BOX(form), GTK_WIDGET(nav_widget), TRUE, TRUE, 0);
gtk_box_pack_start( GTK_BOX(form), GTK_WIDGET(nav_paned), TRUE, TRUE, 0);
gtk_box_pack_start( GTK_BOX(form), GTK_WIDGET(statusbar), FALSE, FALSE, 3);
gtk_container_add( GTK_CONTAINER(toplevel), form);
......@@ -311,6 +334,13 @@ void PnViewerGtk::activate_update( GtkWidget *w, gpointer data)
viewer->activate_update();
}
void PnViewerGtk::activate_filter( GtkWidget *w, gpointer data)
{
PnViewer *viewer = (PnViewer *)data;
viewer->activate_filter( viewer_eFilterType_NotMatching);
}
void PnViewerGtk::activate_setdevice( GtkWidget *w, gpointer data)
{
PnViewer *viewer = (PnViewer *)data;
......
......@@ -63,6 +63,7 @@ class PnViewerGtk : public PnViewer {
GtkWidget *toplevel;
GtkWidget *form;
GtkWidget *nav_widget;
GtkWidget *navconf_widget;
GtkWidget *msg_label;
GtkWidget *cmd_prompt;
GtkWidget *cmd_input;
......@@ -79,6 +80,7 @@ class PnViewerGtk : public PnViewer {
static void valchanged_cmd_input( GtkWidget *w, gpointer data);
static void activate_exit( GtkWidget *w, gpointer data);
static void activate_update( GtkWidget *w, gpointer data);
static void activate_filter( GtkWidget *w, gpointer data);
static void activate_setdevice( GtkWidget *w, gpointer data);
static void activate_changevalue( GtkWidget *w, gpointer data);
static void activate_zoom_in( GtkWidget *w, gpointer data);
......
......@@ -58,8 +58,9 @@ extern "C" {
PnViewerNavGtk::PnViewerNavGtk (
void *l_parent_ctx,
GtkWidget *l_parent_wid,
viewer_eType l_type,
GtkWidget **w) :
PnViewerNav( l_parent_ctx), parent_wid(l_parent_wid)
PnViewerNav( l_parent_ctx, l_type), parent_wid(l_parent_wid)
{
form_widget = scrolledbrowwidgetgtk_new(
PnViewerNav::init_brow_cb, this, &brow_widget);
......
......@@ -46,8 +46,9 @@
class PnViewerNavGtk : public PnViewerNav {
public:
PnViewerNavGtk(
void *ev_parent_ctx,
GtkWidget *ev_parent_wid,
void *v_parent_ctx,
GtkWidget *v_parent_wid,
viewer_eType v_type,
GtkWidget **w);
~PnViewerNavGtk();
......
......@@ -54,16 +54,19 @@
#include "pn_viewer.h"
static int test = 0;
PnViewer::PnViewer(
void *v_parent_ctx,
const char *v_name,
const char *v_device,
pwr_tStatus *status) :
parent_ctx(v_parent_ctx), viewernav(NULL), wow(0), input_open(0), pnet(0), close_cb(0)
parent_ctx(v_parent_ctx), viewernav(NULL), viewernavconf(NULL), wow(0), input_open(0), pnet(0), close_cb(0)
{
strcpy( name, v_name);
strcpy( device, v_device);
if ( !test)
pnet = new PnViewerPNAC( status, device);
}
......@@ -74,10 +77,135 @@ PnViewer::~PnViewer()
void PnViewer::update_devices()
{
int sts;
if ( !test) {
dev_vect.clear();
pnet->fetch_devices( dev_vect);
conf_vect.clear();
sts = fetch_config( dev_vect);
if ( EVEN(sts)) printf( "Error reading configuration file\n");
viewernav->set( dev_vect);
viewernavconf->set( conf_vect);
}
else {
dev_vect.clear();
sts = fetch_config( dev_vect);
if ( EVEN(sts)) printf( "Error reading configuration file\n");
viewernav->set( dev_vect);
strcpy( device, "test"); // Test
conf_vect.clear();
sts = fetch_config( conf_vect);
if ( EVEN(sts)) printf( "Error reading configuration file\n");
viewernavconf->set( conf_vect);
}
}
void PnViewer::filter( viewer_eFilterType filtertype)
{
switch ( filtertype) {
case viewer_eFilterType_No:
for ( unsigned int i = 0; i < dev_vect.size(); i++)
dev_vect[i].hide = false;
for ( unsigned int i = 0; i < conf_vect.size(); i++)
conf_vect[i].hide = false;
break;
case viewer_eFilterType_NotMatching:
// Compare dev_vect and conf_vect and display device that doesn't match
// Set all
for ( unsigned int i = 0; i < dev_vect.size(); i++)
dev_vect[i].hide = false;
for ( unsigned int i = 0; i < conf_vect.size(); i++)
conf_vect[i].hide = false;
for ( unsigned int i = 0; i < dev_vect.size(); i++) {
for ( unsigned int j = 0; j < conf_vect.size(); j++) {
if ( strcmp( dev_vect[i].devname, conf_vect[j].devname) == 0 &&
dev_vect[i].vendorid == conf_vect[j].vendorid &&
dev_vect[i].deviceid == conf_vect[j].deviceid &&
dev_vect[i].ipaddress[0] == conf_vect[j].ipaddress[0] &&
dev_vect[i].ipaddress[1] == conf_vect[j].ipaddress[1] &&
dev_vect[i].ipaddress[2] == conf_vect[j].ipaddress[2] &&
dev_vect[i].ipaddress[3] == conf_vect[j].ipaddress[3]) {
dev_vect[i].hide = true;
conf_vect[j].hide = true;
break;
}
}
}
break;
}
viewernav->set( dev_vect);
viewernavconf->set( conf_vect);
}
int PnViewer::fetch_config( vector<PnDevice>& vect)
{
PnDevice pndevice;
pwr_tFileName fname;
char edev[20];
FILE *fp;
char line[500];
char elemv[7][100];
int nr;
int sts;
cdh_ToLower( edev, device);
sprintf( fname, "$pwrp_load/pwr_pnviewer_%s.dat", edev);
dcli_translate_filename( fname, fname);
fp = fopen( fname, "r");
if ( !fp)
return 0;
while ( dcli_read_line( line, sizeof( line), fp)) {
nr = dcli_parse( line, " ", "", (char *)elemv, sizeof( elemv) / sizeof( elemv[0]),
sizeof( elemv[0]), 0);
if ( nr != 6)
continue;
strncpy( pndevice.devname, elemv[1], sizeof(pndevice.devname));
sts = sscanf( elemv[2], "%hhu.%hhu.%hhu.%hhu",
&pndevice.ipaddress[0], &pndevice.ipaddress[1],
&pndevice.ipaddress[2], &pndevice.ipaddress[3]);
if ( sts != 4) {
printf( "Not a valid IP address: %s\n", elemv[2]);
pndevice.ipaddress[0] = 0;
pndevice.ipaddress[1] = 0;
pndevice.ipaddress[2] = 0;
pndevice.ipaddress[3] = 0;
}
sts = sscanf( elemv[3], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
&pndevice.macaddress[0], &pndevice.macaddress[1],
&pndevice.macaddress[2], &pndevice.macaddress[3],
&pndevice.macaddress[4], &pndevice.macaddress[5]);
if ( sts != 6) {
printf( "Not a valid MAC address: %s\n", elemv[3]);
pndevice.macaddress[0] = 0;
pndevice.macaddress[1] = 0;
pndevice.macaddress[2] = 0;
pndevice.macaddress[3] = 0;
pndevice.macaddress[4] = 0;
pndevice.macaddress[5] = 0;
}
sts = sscanf( elemv[4], "%u", &pndevice.vendorid);
if ( sts != 1)
return 0;
sts = sscanf( elemv[5], "%u", &pndevice.deviceid);
if ( sts != 1)
return 0;
vect.push_back(pndevice);
}
fclose( fp);
return 1;
}
void PnViewer::set_device_properties( unsigned char *macaddress, unsigned char *ipaddress,
......@@ -110,6 +238,11 @@ void PnViewer::activate_update()
}
}
void PnViewer::activate_filter( viewer_eFilterType filtertype)
{
filter( filtertype);
}
void PnViewer::activate_setdevice()
{
pwr_tStatus sts;
......
......@@ -69,7 +69,10 @@ class PnViewer {
void update_devices();
void set_device_properties( unsigned char *macaddress, unsigned char *ipaddress,
char *devname);
int fetch_config( vector<PnDevice>& vect);
void filter( viewer_eFilterType filtertype);
void activate_update();
void activate_filter( viewer_eFilterType filtertype);
void activate_setdevice();
void activate_changevalue();
void activate_close();
......@@ -82,9 +85,11 @@ class PnViewer {
char name[80];
char device[20];
PnViewerNav *viewernav;
PnViewerNav *viewernavconf;
CoWow *wow;
int input_open;
vector<PnDevice> dev_vect;
vector<PnDevice> conf_vect;
PnViewerPNAC *pnet;
void (*close_cb)( void *);
......
......@@ -344,8 +344,8 @@ int PnViewerNav::init_brow_cb( FlowCtx *fctx, void *client_data)
return 1;
}
PnViewerNav::PnViewerNav( void *l_parent_ctx) :
parent_ctx(l_parent_ctx), change_value_cb(0)
PnViewerNav::PnViewerNav( void *l_parent_ctx, viewer_eType l_type) :
type(l_type), parent_ctx(l_parent_ctx), change_value_cb(0)
{
}
......@@ -562,6 +562,8 @@ int PnViewerNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
double ll_x, ll_y, ur_x, ur_y;
int sts;
viewernav->set_input_focus();
switch ( event->object.object_type)
{
case flow_eObjectType_Node:
......@@ -612,6 +614,13 @@ int PnViewerNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
break;
}
case flow_eEvent_MB1DoubleClick:
brow_GetUserData( event->object.object, (void **)&item);
switch( item->type) {
case viewitem_eItemType_Device:
sts = item->open_children( viewernav);
break;
default: ;
}
break;
default:
;
......@@ -706,8 +715,9 @@ int PnViewerNav::check_attr_value()
switch( base_item->type) {
case viewitem_eItemType_DeviceAttr:
if (( strcmp( base_item->name, "DeviceName") == 0) ||
( strcmp( base_item->name, "IP Address") == 0))
if ( type == viewer_eType_Network &&
( strcmp( base_item->name, "DeviceName") == 0 ||
strcmp( base_item->name, "IP Address") == 0))
return 1;
else
return PB__ATTRNOEDIT;
......@@ -724,6 +734,7 @@ void PnViewerNav::set( vector<PnDevice>& dev_vect)
brow_DeleteAll( brow->ctx);
for ( unsigned int i = 0; i < dev_vect.size(); i++) {
if ( !dev_vect[i].hide)
new ItemDevice( this, "", dev_vect[i].ipaddress, dev_vect[i].macaddress,
dev_vect[i].devname, dev_vect[i].vendorid, dev_vect[i].deviceid,
0, flow_eDest_IntoLast);
......@@ -927,8 +938,9 @@ ItemDeviceAttr::ItemDeviceAttr( PnViewerNav *viewernav, const char *item_name, p
brow_SetAnnotation( node, 1, value, strlen(value));
brow_SetAnnotPixmap( node, 0, viewernav->brow->pixmap_attr);
if ( strcmp( item_name, "DeviceName") == 0 ||
strcmp( item_name, "IP Address") == 0)
if ( viewernav->type == viewer_eType_Network &&
( strcmp( item_name, "DeviceName") == 0 ||
strcmp( item_name, "IP Address") == 0))
brow_SetAnnotPixmap( node, 1, viewernav->brow->pixmap_edit);
}
......
......@@ -40,6 +40,7 @@
/* pn_viewernav.h -- Profinet viewer */
#include <vector>
#include <string.h>
#ifndef pwr_h
# include "pwr.h"
......@@ -63,16 +64,32 @@
class PnDevice {
public:
PnDevice() {}
PnDevice() : vendorid(0), deviceid(0), hide(false)
{
strcpy( devname, "");
memset( &ipaddress, 0, sizeof(ipaddress));
memset( &macaddress, 0, sizeof(macaddress));
}
unsigned char ipaddress[4];
unsigned char macaddress[6];
char devname[80];
int vendorid;
int deviceid;
bool hide;
};
class ItemDevice;
typedef enum {
viewer_eType_Network,
viewer_eType_Configuration
} viewer_eType;
typedef enum {
viewer_eFilterType_No,
viewer_eFilterType_NotMatching
} viewer_eFilterType;
typedef enum {
viewitem_eItemType_Device,
viewitem_eItemType_DeviceAttr
......@@ -100,9 +117,10 @@ class PnViewerNavBrow {
class PnViewerNav {
public:
PnViewerNav( void *v_parent_ctx);
PnViewerNav( void *l_parent_ctx, viewer_eType l_type);
virtual ~PnViewerNav();
viewer_eType type;
void *parent_ctx;
PnViewerNavBrow *brow;
void (*change_value_cb)( void *);
......@@ -115,7 +133,7 @@ class PnViewerNav {
void unzoom();
void set( vector<PnDevice>& dev_vect);
int set_attr_value( char *value_str);
int check_attr_value();
virtual int check_attr_value();
int get_selected_device( ItemDevice **device);
void vendorid_to_str( unsigned int vendorid, char *vendorid_str, int size);
void get_device_info( unsigned int vendorid, unsigned int deviceid,
......
......@@ -73,6 +73,8 @@
using namespace std;
static pwr_tStatus generate_viewer_data(device_sCtx *ctx);
class ChanItem {
public:
ChanItem() : subslot_number(0), representation(0), number(0), use_as_bit(0), cid(0) {}
......@@ -416,6 +418,11 @@ int pndevice_save_cb( void *sctx)
}
}
}
// Write data of all devices for profinet viewer
// Data is device name, IP and MAC address
sts = generate_viewer_data( ctx);
sts = rsts;
return_now:
......@@ -423,6 +430,101 @@ int pndevice_save_cb( void *sctx)
return sts;
}
static pwr_tStatus generate_viewer_data(device_sCtx *ctx)
{
pwr_tOid controller;
pwr_tCid ccid;
FILE *fp;
FILE *ofp;
pwr_tFileName fname;
char line[500];
char elemv[3][200];
int nr;
char device_text[200];
char device_name[80];
char ip_address[80];
char mac_address[80];
unsigned int vendor_id = 0;
unsigned int device_id = 0;
char *s;
pwr_tStatus sts;
pwr_tOid oid;
char *ethernet_device;
int size;
sts = ldh_GetParent( ctx->ldhses, ctx->aref.Objid, &controller);
if ( EVEN(sts)) return sts;
sts = ldh_GetObjectClass( ctx->ldhses, controller, &ccid);
if ( ODD(sts) && ccid == pwr_cClass_PnControllerSoftingPNAK) {
sts = ldh_GetObjectPar( ctx->ldhses, controller, "RtBody",
"EthernetDevice", (char **)&ethernet_device, &size);
if ( EVEN(sts)) return sts;
dcli_trim( ethernet_device, ethernet_device);
cdh_ToLower( ethernet_device, ethernet_device);
sprintf( fname, "$pwrp_load/pwr_pnviewer_%s.dat", ethernet_device);
free( ethernet_device);
dcli_translate_filename( fname, fname);
ofp = fopen( fname, "w");
if ( !ofp)
return 0;
for ( sts = ldh_GetChild( ctx->ldhses, controller, &oid);
ODD(sts);
sts = ldh_GetNextSibling( ctx->ldhses, oid, &oid)) {
sprintf( fname, "$pwrp_load/pwr_pn_%s.xml", cdh_ObjidToFnString( 0, oid));
dcli_translate_filename( fname, fname);
fp = fopen( fname, "r");
if ( !fp)
return 0;
while ( dcli_read_line( line, sizeof( line), fp)) {
dcli_trim( line, line);
nr = dcli_parse( line, "=", "", (char *)elemv, sizeof( elemv) / sizeof( elemv[0]),
sizeof( elemv[0]), 0);
if ( nr != 2)
continue;
if ( strcmp( elemv[0], "DeviceText") == 0) {
strncpy( device_text, elemv[1], sizeof(device_text));
}
else if ( strcmp( elemv[0], "VendorId") == 0) {
sscanf( elemv[1], "%d", &vendor_id);
}
else if ( strcmp( elemv[0], "DeviceId") == 0) {
sscanf( elemv[1], "%d", &device_id);
}
else if ( strcmp( elemv[0], "DeviceName") == 0) {
strncpy( device_name, elemv[1], sizeof(device_name));
}
else if ( strcmp( elemv[0], "IP_Address") == 0) {
strncpy( ip_address, elemv[1], sizeof(ip_address));
}
else if ( strcmp( elemv[0], "MAC_Address") == 0) {
strncpy( mac_address, elemv[1], sizeof(mac_address));
if ( (s = strchr( mac_address, '/')))
*s = 0;
dcli_trim( mac_address, mac_address);
break;
}
}
fclose(fp);
fprintf( ofp, "\"%s\" \"%s\" \"%s\" \"%s\" %d %d\n", device_text, device_name, ip_address, mac_address,
vendor_id, device_id);
}
fclose(ofp);
}
return 1;
}
static int pndevice_check_io( device_sCtx *ctx, gsdml_VirtualSubmoduleList *vsl,
vector<ChanItem>& input_vect, vector<ChanItem>& output_vect)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment