diff options
author | athulappadan | 2015-05-21 15:51:46 +0530 |
---|---|---|
committer | athulappadan | 2015-05-21 15:51:46 +0530 |
commit | b533da9ede041621be3588867dd966ee16568c28 (patch) | |
tree | b5e60b9da9e330dd9016e8900ad5908eba676bca | |
parent | 880869a2aaf695201a833d5fea65d7b9186a0950 (diff) | |
download | nghdl-b533da9ede041621be3588867dd966ee16568c28.tar.gz nghdl-b533da9ede041621be3588867dd966ee16568c28.tar.bz2 nghdl-b533da9ede041621be3588867dd966ee16568c28.zip |
changes for multiple output feature
-rw-r--r-- | src/ghdlserver/ghdlserver.c | 114 | ||||
-rw-r--r-- | src/ghdlserver/ghdlserver.h | 2 | ||||
-rwxr-xr-x | src/model_generation.py | 19 |
3 files changed, 47 insertions, 88 deletions
diff --git a/src/ghdlserver/ghdlserver.c b/src/ghdlserver/ghdlserver.c index 0e5c887..68c9941 100644 --- a/src/ghdlserver/ghdlserver.c +++ b/src/ghdlserver/ghdlserver.c @@ -19,6 +19,7 @@ //FILE *log_file = NULL; //FILE *log_sock_id = NULL; FILE *log_server = NULL; +FILE *log_server1 = NULL; #define z32__ "00000000000000000000000000000000" char* Out_Port_Array[MAX_NUMBER_PORT]; @@ -545,88 +546,36 @@ void Vhpi_Send() //snprintf(sockid,sizeof(sockid),"%d",s->val); - int i=0; - for (i=0;i<out_port_num;i++) - { - printf("The array out is %s \n",Out_Port_Array[i]); - fprintf(log_server,"The data is sending for output %s \n",Out_Port_Array[i]); - Data_Send(sockid,Out_Port_Array[i]); - } - - /* - HASH_FIND_STR(users,"o",s); - if(s) - { - printf("Server- The key is %s and value is %s \n",s->key,s->val); - printf("Server- s-val %s \n",s->val); - - //Count Digits in number - while(cpy>0) - { - rem[count_digits]=cpy%10; - count_digits++; - cpy=cpy/10; - } - - int c=0; - - //adds the difference of length as 0's - for(i=0;i<2-count_digits;i++) - new_str[c++]='0'; - - //appends rest of the string - for(i=count_digits-1;i>=0;i--) - new_str[c++]=rem[i]+48; - new_str[c++]='\0'; - - out=(char *)malloc(sizeof(char)); - snprintf(out,sizeof(out),"%s",s->val); - //HASH_DEL(users, s); - //free(s); - - while(1) - { - if(can_write_to_socket(sockid)) - break; - usleep(1000); - - } - - if ((send(sockid,out,sizeof(out),0))== -1) - { - perror("Server- Failure Sending Message\n"); - //exit(1); - } - - } - else - { - printf("Server- The key %s Not found \n",s->key); - } - - */ - - - //#ifdef DEBUG - //fprintf(log_file,"Server- Info: trying to send message %s in %d\n", send_buffer, vhpi_cycle_count); - //fflush(log_file); - //#endif + Data_Send(sockid); fflush(log_server); fclose(log_server); } -void Data_Send(int sockid,char* out_port) +void Data_Send(int sockid) { - char* out; - HASH_FIND_STR(users,out_port,s); + char* out; + out = (char *) malloc(sizeof(char)); + *out = '\0'; + char send_data_buf[BUFSIZ]; + int i; + char colon = ':'; + char semicolon = ';'; + for (i=0;i<out_port_num;i++) + { + HASH_FIND_STR(users,Out_Port_Array[i],s); if(s) { printf("Server-Sending data has key:%s and value:%s \n",s->key,s->val); - fprintf(log_server,"Sending data has key:%s and value:%s \n",s->key,s->val); - out=(char *)malloc(sizeof(char)); - snprintf(out,sizeof(out),"%s",s->val); + fprintf(log_server,"Sending data has key:%s and value:%s \n",s->key,s->val); + + strncat(out, s->key, strlen(s->key)); + strncat(out, &colon, 1); + strncat(out, s->val, strlen(s->val)); + strncat(out, &semicolon, 1); + + //HASH_DEL(users, s); //free(s); while(1) @@ -636,17 +585,22 @@ void Data_Send(int sockid,char* out_port) usleep(1000); } - if ((send(sockid,out,sizeof(out),0))== -1) - { - perror("Server- Failure Sending Message\n"); - exit(1); - } } else { - printf("Server- The output port's %s value Not found \n",out_port); - fprintf(log_server,"The %s's value not found in the table \n",out_port); - } + printf("Server- The output port's %s value Not found \n",Out_Port_Array[i]); + fprintf(log_server,"The %s's value not found in the table \n",Out_Port_Array[i]); + } + } + + strcpy(send_data_buf, out); + + if ((send(sockid, send_data_buf, sizeof(send_data_buf), 0)) == -1) + { + perror("Server- Failure Sending Message\n"); + exit(1); + } + fprintf(log_server,"Val of output buffer %s\n",send_data_buf); } void Vhpi_Close() diff --git a/src/ghdlserver/ghdlserver.h b/src/ghdlserver/ghdlserver.h index d8bc017..07cccb6 100644 --- a/src/ghdlserver/ghdlserver.h +++ b/src/ghdlserver/ghdlserver.h @@ -44,7 +44,7 @@ int receive_string(int n, char* buffer); void send_packet_and_wait_for_response(char* buffer, int send_length, char* server_host_name, int server_port_number); void set_non_blocking(int sock_id); -void Data_Send(int sockid,char* out_port); +void Data_Send(int sockid); //Vhpi Function void Vhpi_Initialize(); diff --git a/src/model_generation.py b/src/model_generation.py index 5e854a0..c5350c0 100755 --- a/src/model_generation.py +++ b/src/model_generation.py @@ -166,7 +166,8 @@ var_section=''' log_client=fopen("client.log","a"); int socket_fd, bytes_recieved; char send_data[1024]; - char recv_data[1024]; + char recv_data[1024]; + char *key_iter; struct hostent *host; struct sockaddr_in server_addr; double time_limit = PARAM(stop_time); @@ -349,7 +350,7 @@ recv_data=''' printf("Client-Either Connection Closed or Error \\n"); exit(1); } - //recv_data[bytes_recieved] = '\\0'; + recv_data[bytes_recieved] = '\\0'; printf("Client-Message Received From Server - %s\\n",recv_data); fprintf(log_client,"Message Received From Server- %s\\n",recv_data); @@ -362,14 +363,17 @@ sch_output_event=[] for item in output_port: sch_output_event.append("\t\t\t/* Scheduling event and processing them */\n\ -\t\t\tfor(Ii=0;Ii<PORT_SIZE("+item.split(':')[0]+");Ii++)\n\ +\t\t\tif((key_iter=strstr(recv_data, "+'"'+item.split(':')[0]+':"'")) != NULL)\n\ \t\t\t{\n\ -\t\t\t\tprintf(\"Client- Bit val is %c \\n\",recv_data[Ii]);\n\ -\t\t\t\tfprintf(log_client,\"Client-Bit val is %c \\n\",recv_data[Ii]);\n\ -\t\t\t\tif(recv_data[Ii]=='0')\n\t\t\t\t{\n\ +\t\t\twhile(*key_iter++ != ':');\n\ +\t\t\tfor(Ii=0;*key_iter != ';';Ii++,key_iter++)\n\ +\t\t\t{\n\ +\t\t\t\tprintf(\"Client- Bit val is %c \\n\",*key_iter);\n\ +\t\t\t\tfprintf(log_client,\"Client-Bit val is %c \\n\",*key_iter);\n\ +\t\t\t\tif(*key_iter=='0')\n\t\t\t\t{\n\ \t\t\t\t\tprintf(\"Client-Zero Received \");\n\ \t\t\t\t\t_op_"+item.split(':')[0]+"[Ii]=ZERO;\n\t\t\t\t}\n\ -\t\t\t\telse if(recv_data[Ii]=='1')\n\t\t\t\t{\n\ +\t\t\t\telse if(*key_iter=='1')\n\t\t\t\t{\n\ \t\t\t\t\tprintf(\"Client-One Received \\n\");\n\ \t\t\t\t\t_op_"+item.split(':')[0]+"[Ii]=ONE;\n\ \t\t\t\t}\n\t\t\t\telse\t\t\t\t{\n\ @@ -385,6 +389,7 @@ for item in output_port: \t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\ \t\t\t\t\t\tOUTPUT_CHANGED("+item.split(':')[0]+"[Ii]) = FALSE;\n\t\t\t\t\t}\n\ \t\t\t\t}\n\t\t\t\tOUTPUT_STRENGTH("+item.split(':')[0]+"[Ii]) = STRONG;\n\ +\t\t\t}\n\ \t\t\t}\n") |