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