diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ghdlserver/ghdlserver.c | 97 | ||||
-rw-r--r-- | src/model_generation.py | 5 | ||||
-rw-r--r-- | src/outitf.c | 148 |
3 files changed, 66 insertions, 184 deletions
diff --git a/src/ghdlserver/ghdlserver.c b/src/ghdlserver/ghdlserver.c index 60e1a20..d324e7b 100644 --- a/src/ghdlserver/ghdlserver.c +++ b/src/ghdlserver/ghdlserver.c @@ -89,89 +89,6 @@ struct my_struct { static struct my_struct *s, *users, *tmp = NULL; -/* 17.Mar.2017 - RM - Get the process id of ngspice program.*/ -static int get_ngspice_pid(void) -{ - DIR* dirp; - FILE* fp = NULL; - struct dirent* dir_entry; - char path[1024], rd_buff[1024]; - pid_t pid = -1; - - if ((dirp = opendir("/proc/")) == NULL) - { - perror("get_ngspice_pid() - opendir /proc failed "); - exit(-1); - } - - while ((dir_entry = readdir(dirp)) != NULL) - { - char* nptr; - int valid_num = 0; - - int tmp = strtol(dir_entry->d_name, &nptr, 10); - if ((errno == ERANGE) && (tmp == LONG_MAX || tmp == LONG_MIN)) - { - perror("get_ngspice_pid() - strtol"); // Number out of range. - return(-1); - } - if (dir_entry->d_name == nptr) - { - continue; // No digits found. - } - if (tmp) - { - sprintf(path, "/proc/%s/comm", dir_entry->d_name); - if ((fp = fopen(path, "r")) != NULL) - { - fscanf(fp, "%s", rd_buff); - if (strcmp(rd_buff, NGSPICE) == 0) - { - pid = (pid_t)tmp; // 5.July.2019 - RP - Kludge - } - } - } - } - - if (fp) fclose(fp); - - return(pid); -} - - -/* 23.Mar.2017 - RM - Pass the sock_port argument. We need this if a netlist - * uses more than one instance of the same test bench, so that we can uniquely - * identify the PID files. - */ -/* 10.Mar.2017 - RM - Create PID file for the test bench in /tmp. */ -static void create_pid_file(int sock_port) -{ - pid_t my_pid = getpid(); - pid_t ngspice_pid = get_ngspice_pid(); - - if (ngspice_pid == -1) - { - fprintf(stderr, "create_pid_file() Failed to get ngspice PID"); - syslog(LOG_ERR, "create_pid_file() Failed to get ngspice PID"); - exit(1); - } - - sprintf(pid_filename, "/tmp/NGHDL_%d_%s_%d", ngspice_pid, __progname, sock_port); - pid_file = fopen(pid_filename, "a"); // 26.Sept.2019 - RP - Open file in append mode - - if (pid_file) - { - pid_file_created = 1; - fprintf(pid_file,"%d\n", my_pid); - fclose(pid_file); - } else { - perror("create_pid_file() - cannot open PID file "); - syslog(LOG_ERR, "create_pid_file(): Unable to open PID file in /tmp"); - exit(1); - } -} - - #ifdef DEBUG static char* curtim(void) { @@ -316,16 +233,23 @@ static int connect_to_client(int server_fd) //Receive string from socket and put it inside buffer. static void receive_string(int sock_id, char* buffer) -{ +{ int nbytes = 0; /* 08.Nov.2019 - RP - Blocking Socket - Receive */ nbytes = recv(sock_id, buffer, MAX_BUF_SIZE, 0); if (nbytes <= 0) { - perror("receive_string() - READ FAILURE "); + perror("receive_string() - READ FAILURE "); exit(1); } + + //28.May.2020 - BM - Added method to close server by NGSPICE after simulation + char *exitstr = "CLOSE_FROM_NGSPICE"; + if (strcmp(buffer, exitstr)==0) + { + Vhpi_Exit(0); + } } @@ -447,7 +371,6 @@ void Vhpi_Initialize(int sock_port, char sock_ip[]) nanosleep(&ts, NULL); // 10.Mar.2017 - RM - Create PID file for the test bench. - create_pid_file(sock_port); } @@ -510,4 +433,4 @@ void Vhpi_Exit(int sig) close(server_socket_id); syslog(LOG_INFO, "*** Closed VHPI link. Exiting... ***"); exit(0); -}
\ No newline at end of file +} diff --git a/src/model_generation.py b/src/model_generation.py index da8e272..dcb0788 100644 --- a/src/model_generation.py +++ b/src/model_generation.py @@ -268,7 +268,8 @@ class ModelGeneration: if (fptr) { char line[20]; - while(fscanf(fptr, "%s", line) == 1) { + int line_port; + while(fscanf(fptr, "%s %d\\n", line, &line_port) == 2) { ip_count++; } @@ -284,7 +285,7 @@ class ModelGeneration: fptr = fopen(ip_filename, "a"); if (fptr) { - fprintf(fptr, "%s\\n", my_ip); + fprintf(fptr, "%s %d\\n", my_ip, sock_port); fclose(fptr); } else { perror("Client - cannot open Common_IP file "); diff --git a/src/outitf.c b/src/outitf.c index fba5224..c015c04 100644 --- a/src/outitf.c +++ b/src/outitf.c @@ -49,6 +49,12 @@ Modified: 2000 AlansFixes, 2013/2015 patch by Krzysztof Blaszkowski #include <stdlib.h> #include <string.h> #include <errno.h> +// 27.May.2020 - BM - Added the following #include +#include <stdio.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <unistd.h> +#include <string.h> extern char *spice_analysis_get_name(int index); extern char *spice_analysis_get_description(int index); @@ -112,102 +118,46 @@ static double *valueold, *valuenew; static bool savenone = FALSE; #endif -/* 10.Mar.2017 - RM - Added nghdl_tb_SIGUSR1().*/ -static void nghdl_tb_SIGUSR1(char* pid_file) -{ - int ret; - char line[80]; - char* nptr; - pid_t pid[256], tmp; - int count=0, i; - - FILE* fp = fopen(pid_file, "r"); - - if (fp) - { - /* 22.Oct.2019 - RP - Scan and store all the PIDs in this file */ - while (fscanf(fp, "%s", line) == 1) - { - // PID is converted to a decimal value. - tmp = (pid_t) strtol(line, &nptr, 10); - if ((errno != ERANGE) && (errno!= EINVAL)) - { - pid[count++] = tmp; - } - } - - fclose(fp); - } - - /* 22.Oct.2019 - RP - Kill all the active PIDs */ - for(i=0; i<count; i++) - { - if (pid[i]) - { - // Check if a process with this pid really exists. - ret = kill(pid[i], 0); - if (ret == 0) - { - kill(pid[i], SIGUSR1); - } - } - } - // 22.Oct.2019 - RP - remove(pid_file); +//28.May.2020 - BM - Closing the GHDL server after simulation is over + +static void close_server(void) +{ + FILE *fptr; + char ip_filename[48]; + sprintf(ip_filename, "/tmp/NGHDL_COMMON_IP_%d.txt", getpid()); + fptr = fopen(ip_filename, "r"); + if (fptr) + { + char IPaddr_file[20]; + int PORT_file; + while(fscanf(fptr, "%s %d\n", IPaddr_file, &PORT_file) == 2) + { printf("\nIPaddr - %s portno - %d", IPaddr_file, PORT_file); + int sock = 0; + struct sockaddr_in serv_addr; + char *message = "CLOSE_FROM_NGSPICE"; + if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + printf("\n Socket creation error \n"); + } + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(PORT_file); + serv_addr.sin_addr.s_addr = inet_addr(IPaddr_file); + + if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + printf("\nConnection Failed\n"); + } + send(sock , message , strlen(message) , 0 ); + close(sock); + } + } + remove(ip_filename); } -/* 10.Mar.2017 - RM - Added nghdl_orphan_tb().*/ -static void nghdl_orphan_tb(void) -{ - struct dirent* dirp; - DIR* dirfd; - char* dir = "/tmp"; - char filename_tmp[1024]; - char pid_file_prefix[256]; - - sprintf(pid_file_prefix, "NGHDL_%d", getpid()); - - if ((dirfd = opendir(dir)) == NULL) - { - fprintf(stderr, "nghdl_orphan_tb(): Cannot open /tmp\n"); - return; - } - /* Loop through /tmp directories looking for "NGHDL_<my pid>*" files.*/ - while ((dirp = readdir(dirfd)) != NULL) - { - struct stat stbuf; - sprintf(filename_tmp, "/tmp/%s", dirp->d_name); - if (strstr(filename_tmp, pid_file_prefix)) - { - if (stat(filename_tmp, &stbuf) == -1) - { - fprintf(stderr, - "nghdl_orphan_tb: stat() failed; ERRNO=%d on file:%s\n", - errno, filename_tmp); - continue; - } - - if ((stbuf.st_mode & S_IFMT) == S_IFDIR) - { - continue; - } - else - { - nghdl_tb_SIGUSR1(filename_tmp); - } - } - } - - // 22.Oct.2019 - RP - char ip_filename[40]; - sprintf(ip_filename, "/tmp/NGHDL_COMMON_IP_%d.txt", getpid()); - remove(ip_filename); -} -/* End 10.Mar.2017 - RM */ - -/* The two "begin plot" routines share all their internals... */ +// The two "begin plot" routines share all their internals... int OUTpBeginPlot(CKTcircuit *circuitPtr, JOB *analysisPtr, @@ -1136,10 +1086,13 @@ fileEnd(runDesc *run) /* 10.Mar.2017 - RM - Check if any orphan test benches are running. If any are * found, force them to exit. */ - nghdl_orphan_tb(); - + //nghdl_orphan_tb(); /* End 10.Mar.2017 */ + /* 28.MaY.2020 - BM */ + close_server; + /* End 28.MaY.2020 */ + if (run->fp != stdout) { long place = ftell(run->fp); @@ -1294,9 +1247,14 @@ static void plotEnd(runDesc *run) { /* 10.Mar.2017 - RM */ - nghdl_orphan_tb(); + //nghdl_orphan_tb(); /* End 10.Mar.2017 */ + /* 28.MaY.2020 - BM */ + close_server; + /* End 28.MaY.2020 */ + + fprintf(stdout, "\nNo. of Data Rows : %d\n", run->pointCount); } |