Rev 956 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
418 | lvd | 1 | #include <stdio.h> |
2 | #include <stdlib.h> |
||
419 | lvd | 3 | #include <errno.h> |
956 | lvd | 4 | #include <unistd.h> |
418 | lvd | 5 | |
6 | #include <sys/types.h> |
||
7 | #include <sys/socket.h> |
||
8 | #include <arpa/inet.h> |
||
9 | |||
10 | #include "sndpix.h" |
||
11 | |||
12 | DPI_LINK_DECL DPI_DLLESPEC |
||
13 | int |
||
14 | sndpix( |
||
15 | int hcoord, |
||
16 | int vcoord, |
||
17 | int rrggbb, |
||
18 | int hperiod, |
||
19 | int vperiod) |
||
20 | { |
||
419 | lvd | 21 | static int hsize=0,vsize=0; |
418 | lvd | 22 | |
419 | lvd | 23 | |
418 | lvd | 24 | static int need_init = 1; |
25 | static int sock_error=0; |
||
26 | static int mysocket; |
||
27 | struct sockaddr_in addr; |
||
28 | char buf[256]; |
||
29 | |||
30 | |||
419 | lvd | 31 | char * curbuf; |
32 | int tosend; |
||
33 | int socksent; |
||
418 | lvd | 34 | |
35 | |||
36 | |||
37 | if( need_init ) |
||
38 | { |
||
39 | need_init = 0; |
||
40 | |||
41 | |||
42 | mysocket = socket(AF_INET, SOCK_STREAM, 0); |
||
43 | |||
44 | if(mysocket<0) sock_error++; |
||
45 | |||
46 | |||
47 | addr.sin_family = AF_INET; |
||
48 | addr.sin_port = htons(12345); |
||
49 | // addr.sin_addr.s_addr = htonl(0xAC100594); //172.16.5.148 |
||
50 | addr.sin_addr.s_addr = htonl(0x7F000001); //127.0.0.1 |
||
51 | |||
52 | |||
53 | |||
54 | if( !sock_error) |
||
55 | { |
||
56 | if( connect(mysocket, (struct sockaddr *)&addr, sizeof(addr) ) ) |
||
57 | { |
||
58 | sock_error++; |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | |||
64 | |||
65 | if( !sock_error ) |
||
66 | { |
||
67 | // sprintf(buf,"%08X<=%08X:%08X with %02X\n",adr,dat_hi,dat_lo,sel); |
||
68 | |||
419 | lvd | 69 | buf[0] = 0; |
418 | lvd | 70 | |
419 | lvd | 71 | if( (hperiod>0) && (vperiod>0) ) |
72 | { |
||
73 | if( (hperiod!=hsize) || (vperiod!=vsize) ) |
||
74 | { |
||
75 | hsize = hperiod; |
||
76 | vsize = vperiod; |
||
77 | |||
78 | sprintf(buf,"s%04X,%04X\n",hsize,vsize); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | if( (hsize>0) && (vsize>0) ) |
||
83 | sprintf(buf+strlen(buf),"p%04X,%04X,%02X\n",hcoord,vcoord,rrggbb); |
||
84 | |||
85 | if( strlen(buf)>0 ) |
||
86 | { |
||
87 | tosend = strlen(buf); |
||
88 | curbuf = buf; |
||
89 | |||
90 | |||
91 | |||
92 | while( tosend>0 ) |
||
93 | { |
||
94 | socksent = send(mysocket, curbuf, tosend, 0); |
||
95 | |||
96 | if( socksent<=0 ) |
||
97 | { |
||
98 | sock_error++; |
||
99 | break; |
||
100 | } |
||
101 | |||
102 | tosend -= socksent; |
||
103 | curbuf += socksent; |
||
104 | } |
||
105 | |||
106 | // if( strlen(buf)!=socksent ) |
||
107 | // { |
||
108 | // printf("send() sent %d bytes, errno=%d\n",socksent,errno); |
||
109 | // sock_error++; |
||
110 | // } |
||
111 | } |
||
418 | lvd | 112 | } |
113 | else |
||
114 | { |
||
419 | lvd | 115 | // sock_error = 0; |
116 | // need_init = 1; |
||
418 | lvd | 117 | |
118 | if( mysocket>=0 ) |
||
119 | close(mysocket); |
||
959 | lvd | 120 | |
121 | mysocket=-1; |
||
418 | lvd | 122 | } |
123 | |||
124 | |||
125 | return 0; |
||
126 | } |
||
127 |