📄 eibdrv_admin.c
字号:
/* --------------------------------------------------------------------------- eibdrv_admin.c --------------------------------------------------------------------------- eibdrv_admin Version 0.2.1 Copyright (C) 2002, Wolfgang Tumfart Donaustrasse 104/9 A-2344 Maria Enzersdorf Austria (Europe) tumfart@auto.tuwien.ac.at 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 of the License, 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. --------------------------------------------------------------------------- *//* --------------------------------------------------------------------------- This program servers for output and change of internal parameter of the eibdrv driver like - mode, baudrate and serial port used, - size of buffers and their occupation and for visualization of internal statistical information about read and write actions delivered by the driver. Start: eibdrv_admin /dev/eibdrv (Example) --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- FormsLibrary is copyrighted by T.C. Zhao and Mark Overmars. It is not public domain, but may be used for running publically available free software. --------------------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <termios.h>#include <fcntl.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/time.h>#include "forms.h"#include "eibdrv.h"#include "eibdrv_fl.h"/* Name of Panelfile for eibdrv_admin and number of message panels included. */ #define EIBDRV_ADMIN_PANELFILE "/sbin/eibdrv_admin.panel"#define EIBDRV_ADMIN_PANELFILESIZE 13#define EIBDRV_ADMIN_STATUS_NOTSET 0 // No status request sent yet#define EIBDRV_ADMIN_STATUS_RESPONDED 1 // Status request msg acknowledged by BCU2#define EIBDRV_ADMIN_STATUS_FAILED 2 // Status request msg ignored by BCU2/* Various color defines */#define EIBDRV_ADMIN_COUNT_COL FL_PALEGREEN // Size/Occupancy bar for values < 100%#define EIBDRV_ADMIN_COUNT100_COL FL_TOMATO // Size/Occupancy bar for value = 100%#define EIBDRV_ADMIN_W1_COL FL_PALEGREEN // Bar for 1-Writes and 0-Reads#define EIBDRV_ADMIN_W2_COL FL_DARKCYAN // Bar for 2-Writes and 1-Reads#define EIBDRV_ADMIN_W3_COL FL_ORCHID // Bar for 3-Writes and 2-Reads#define EIBDRV_ADMIN_WFAILED_COL FL_TOMATO // Bar for failed-Writes#define EIBDRV_ADMIN_STATUS_RESPONDED_COL FL_PALEGREEN // Box for Status msg acknowledged#define EIBDRV_ADMIN_STATUS_FAILED_COL FL_TOMATO // Box for Status msg ignored/* Main Form */typedef struct { FL_FORM *VisForm; void *vdata; char *cdata; long ldata; FL_OBJECT *DeviceText; FL_OBJECT *ModeText; FL_OBJECT *BaudrateText; FL_OBJECT *PortText; FL_OBJECT *WProcSizeText; FL_OBJECT *RProcSizeText; FL_OBJECT *WProcOccText; FL_OBJECT *RProcOccText; FL_OBJECT *WProcOccBox; FL_OBJECT *WProcOccGroundBox; FL_OBJECT *RProcOccBox; FL_OBJECT *RProcOccGroundBox; FL_OBJECT *WMsgSizeText; FL_OBJECT *RMsgSizeText; FL_OBJECT *WMsgOccText; FL_OBJECT *WMsgOccBox; FL_OBJECT *WMsgOccGroundBox; FL_OBJECT *StatusBox; FL_OBJECT *TimeResetText; FL_OBJECT *TimeActualizeText; FL_OBJECT *TimeNextText; FL_OBJECT *ActIntervalCounter; FL_OBJECT *ActwoResetCheckbtn; FL_OBJECT *ActwResetCheckbtn; FL_OBJECT *WGroundBox; FL_OBJECT *WBox[4]; FL_OBJECT *TotWText; FL_OBJECT *SecWText; FL_OBJECT *AvgWText; FL_OBJECT *RGroundBox; FL_OBJECT *RBox[3]; FL_OBJECT *TotRText; FL_OBJECT *SecRText; FL_OBJECT *ResetStatBtn; FL_OBJECT *ActStatBtn; FL_OBJECT *ResizeBtn; FL_OBJECT *ResetProtBtn; FL_OBJECT *StatusBtn; FL_OBJECT *ExitBtn; FL_OBJECT *TimesTimer; } FD_VisForm;/* Form for resizing process and message buffers */typedef struct { FL_FORM *VisForm; void *vdata; char *cdata; long ldata; FL_OBJECT *WProcBufSizeEditfield; FL_OBJECT *RProcBufSizeEditfield; FL_OBJECT *WMsgBufSizeEditfield; FL_OBJECT *RMsgBufSizeEditfield; FL_OBJECT *OkBtn; FL_OBJECT *CancelBtn; } FD_ResizeBufferForm;typedef struct { int mode; // Standard/Server mode of driver int symb_baudrate; // symbolic constant of baudrate char *port; // serial port unsigned long outbuf_size; // outgoing messages (writes) unsigned long wpbuf_size; // writing processes unsigned long rpbuf_size; // reading processes unsigned long rpbuf_msgbuf_size; // incoming messages (reads) } Eib_settings; typedef struct { FD_VisForm *MainForm; // Main Form FD_ResizeBufferForm *ResizeBufferForm; // Resize buffers form int resbufform_visible; // Resize buffers form shown/hidden PanelContent *Panels; // all error and message panels int eib_fd; // file descriptor of eibdrv device int cleanup_code; // entry point in cleanup function Eib_settings *ftstation_settings; // settings of device Eib_statistics *ftstation_stat; // internal statistics of device time_t stat_reset_time; // time since last statistics reset time_t stat_get_time; // time since last statistics actualization time_t stat_plan_time; // time of next statistics actualization time_t act_interval; // statistics actualization interval } Eib_bcu2_admin;int baudrates[18][2]={ {B50,50}, // Table of symbolic baudrates and their integer {B75,75}, // value {B110,110}, {B134,134}, {B150,150}, {B200,200}, {B300,300}, {B600,600}, {B1200,1200}, {B1800,1800}, {B2400,2400}, {B4800,4800}, {B9600,9600}, {B19200,19200}, {B38400,38400}, {B57600,57600}, {B115200,115200}, {B230400,230400}};/* --------------------------------------------------------------------------- Various function prototypes. ---------------------------------------------------------------------------*/FD_VisForm *create_form_MainForm(void);FD_ResizeBufferForm *create_form_ResizeBufferForm(void);void cleanup(void *arg,int btn);/* --------------------------------------------------------------------------- Allocation and deallocation of central struct of administrator. --------------------------------------------------------------------------- */ Eib_bcu2_admin *getEib_bcu2_admin(){ Eib_bcu2_admin *help=(Eib_bcu2_admin *)fl_calloc(1,sizeof(Eib_bcu2_admin)); help->resbufform_visible=FL_EXT_INVISIBLE; help->Panels=NULL; help->cleanup_code=0; help->ftstation_settings=(Eib_settings *)fl_calloc(1,sizeof(Eib_settings)); help->ftstation_settings->port=NULL; help->ftstation_stat=(Eib_statistics *)fl_calloc(1,sizeof(Eib_statistics)); return help;}void returnEib_bcu2_admin(Eib_bcu2_admin *admin){ free(admin->MainForm); free(admin->ResizeBufferForm); returnPanelContentA(admin->Panels,EIBDRV_ADMIN_PANELFILESIZE); if (admin->ftstation_settings->port!=NULL) free(admin->ftstation_settings->port); free(admin->ftstation_settings); free(admin->ftstation_stat); free(admin);} /* --------------------------------------------------------------------------- Creation of all forms and callbacks of all visual elements. --------------------------------------------------------------------------- */void actualize_MainForm_BufSiz(Eib_bcu2_admin *admin){ char *helpstring=(char *)malloc(50*sizeof(char)); if (admin->ftstation_settings->mode==FT_SERVERMODE) { sprintf(helpstring,"%li",admin->ftstation_settings->wpbuf_size); fl_set_object_label(admin->MainForm->WProcSizeText,helpstring); sprintf(helpstring,"%li",admin->ftstation_settings->rpbuf_size); fl_set_object_label(admin->MainForm->RProcSizeText,helpstring); sprintf(helpstring,"%li",admin->ftstation_settings->outbuf_size); fl_set_object_label(admin->MainForm->WMsgSizeText,helpstring); sprintf(helpstring,"%li",admin->ftstation_settings->rpbuf_msgbuf_size); fl_set_object_label(admin->MainForm->RMsgSizeText,helpstring); } free(helpstring);}void actualize_MainForm_Stat(Eib_bcu2_admin *admin){ char *helpstring=(char *)malloc(50*sizeof(char)); Eib_settings *settings=admin->ftstation_settings; Eib_statistics *stat=admin->ftstation_stat; FD_VisForm *form=admin->MainForm; double diff_time; unsigned long rw_ges; double rw_pt; int lowerbound; int i; int avg_w1time; if (admin->ftstation_settings->mode==FT_SERVERMODE) { sprintf(helpstring,"%li",stat->wpbuf_count); fl_set_object_label(form->WProcOccText,helpstring); sprintf(helpstring,"%li",stat->rpbuf_count); fl_set_object_label(form->RProcOccText,helpstring);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -