source: trunk/FACT++/dim/src/util/dim_send_command.c@ 16336

Last change on this file since 16336 was 15282, checked in by tbretz, 12 years ago
Updated to v20r7.
File size: 2.2 KB
Line 
1#include <ctype.h>
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5#include <dic.h>
6
7int received = 0;
8char str[132] = {'\0'};
9
10void rout(tag, code)
11int *tag;
12int *code;
13{
14 int silent;
15
16 silent = *tag;
17 if(!silent)
18 dim_print_date_time();
19 if(*code)
20 {
21 if(!silent)
22 printf(" Command %s Successfully Sent\n", str);
23 }
24 else
25 {
26 if(!silent)
27 printf(" Command %s Unsuccessfull\n", str);
28 }
29 received = 1;
30#ifdef WIN32
31 wake_up();
32#endif
33}
34/*
35main(argc,argv)
36int argc;
37char **argv;
38{
39 char data[1024] = {'\0'};
40 int silent = 0;
41
42 if(argc < 2)
43 {
44 printf("Command Name > ");
45 fflush(stdout);
46 scanf("%s", str);
47 printf("Command String > ");
48 fflush(stdout);
49 scanf("%s", data);
50 }
51 else
52 {
53 sprintf(str,argv[1]);
54 if(argc < 3)
55 data[0] = '\0';
56 else
57 {
58 sprintf(data,argv[2]);
59 if(argc > 3)
60 silent = 1;
61 }
62 }
63 dic_cmnd_callback(str,data,(int)strlen(data)+1, rout, silent);
64 while(!received)
65 dim_wait();
66 sleep(1);
67}
68*/
69int main(argc,argv)
70int argc;
71char **argv;
72{
73int i;
74int silent = 0;
75char data[1024] = {'\0'};
76int data_int, data_int_flag = 0;
77char dns_node[128], *ptr;
78int dns_port = 0;
79
80 dns_node[0] = '\0';
81 for(i = 1; i < argc; i++)
82 {
83 if(!strcmp(argv[i],"-dns"))
84 {
85 strcpy(dns_node,argv[i+1]);
86 if((ptr = strchr(dns_node,':')))
87 {
88 *ptr = '\0';
89 ptr++;
90 sscanf(ptr,"%d",&dns_port);
91 }
92 i++;
93 }
94 else if(!strcmp(argv[i],"-s"))
95 {
96 silent = 1;
97 }
98 else if(!strcmp(argv[i],"-i"))
99 {
100 data_int_flag = 1;
101 }
102 else
103 {
104 if(!str[0])
105 {
106 strcpy(str, argv[i]);
107 }
108 else if(!data[0])
109 {
110 strcpy(data,argv[i]);
111 }
112 }
113 }
114 if(dns_node[0])
115 {
116 dic_set_dns_node(dns_node);
117 }
118 if(dns_port)
119 {
120 dic_set_dns_port(dns_port);
121 }
122 if(!str[0])
123 {
124 printf("dim_send_command: Insufficient parameters\n");
125 printf("usage: dim_send_command <cmnd_name> [<data>] [-dns <dns_node>] [-s] [-i]\n");
126 exit(0);
127 }
128 if(!data[0])
129 data[0] = '\0';
130 if(data_int_flag)
131 {
132 sscanf(data,"%d",&data_int);
133 dic_cmnd_callback(str,&data_int,sizeof(int), rout, silent);
134 }
135 else
136 {
137 dic_cmnd_callback(str,data,(int)strlen(data)+1, rout, silent);
138 }
139 while(!received)
140 dim_wait();
141 sleep(1);
142 return(1);
143}
Note: See TracBrowser for help on using the repository browser.