source: tools/SendToDim/SendRPC.cc@ 9488

Last change on this file since 9488 was 223, checked in by ogrimm, 14 years ago
Added command line utilities for DIM command and RPC
File size: 1.3 KB
Line 
1//
2// Command-line utility to send a DIM RPC and print the result
3//
4//
5
6#include <stdio.h>
7#include <ctype.h>
8#include <sys/time.h>
9
10#include "dic.hxx"
11
12#define NO_LINK (char *) "__&DIM&NOLINK&__" // Data if no link available
13
14// Get configuration data
15int main(int argc, const char* argv[]) {
16
17 struct timeval Start, End;
18
19 if (argc != 3) {
20 printf("Usage: %s <RPC Name> <ASCII Data>\n", argv[0]);
21 exit(EXIT_FAILURE);
22 }
23
24 gettimeofday(&Start, NULL);
25
26 // Make RPC
27 DimRpcInfo RPC(argv[1], NO_LINK);
28 RPC.setData((char *) argv[2]);
29
30 // Check for connection to server
31 if ((RPC.getSize() == strlen(NO_LINK)+1) &&
32 (memcmp(RPC.getData(), NO_LINK, RPC.getSize()) == 0)){
33 printf("No link to server\n");
34 exit(EXIT_FAILURE);
35 }
36
37 // Calculate time to completion
38 gettimeofday(&End, NULL);
39 double Diff = (End.tv_sec-Start.tv_sec)*1e6 + End.tv_usec-Start.tv_usec;
40 printf("Time to completion %.2f ms\nASCII\n'", Diff/1000);
41
42 unsigned char *Result = (unsigned char *) RPC.getString();
43
44 // Print result as text
45 for (int i=0; i<RPC.getSize(); i++) {
46 if (isprint(Result[i])) printf("%c", Result[i]);
47 else printf(".");
48 }
49 printf("'\nHex:\n");
50
51 // Print result in hex
52 for (int i=0; i<RPC.getSize(); i++) {
53 printf("%.2x ", Result[i]);
54 if (i%4 == 3) printf(" ");
55 if (i%16 == 15) printf("\n");
56 }
57 printf("\n");
58}
Note: See TracBrowser for help on using the repository browser.