| 1 |
|
| #include "libiis.h" |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| |
| 5 |
|
| /*************************************************************** |
| 6 |
|
| |
| 7 |
|
| pdliisdisplay.c |
| 8 |
|
| |
| 9 |
|
| ****************************************************************/ |
| 10 |
|
| |
| 11 |
|
| /* Redefine iis_error to use Perl's croak() */ |
| 12 |
|
| |
| 13 |
0 |
| void iis_error( char* error1, char*error2 ) { |
| 14 |
0 |
| croak (error1,error2); |
| 15 |
|
| } |
| 16 |
|
| |
| 17 |
|
| |
| 18 |
|
| /*****************************************************/ |
| 19 |
|
| |
| 20 |
|
| |
| 21 |
|
| /* Rest of the subroutines are identical to libiis.c v1.0 */ |
| 22 |
|
| |
| 23 |
|
| |
| 24 |
|
| /******************* iis_cur ************************/ |
| 25 |
|
| |
| 26 |
|
| /* Return cursor position and character typed */ |
| 27 |
|
| |
| 28 |
0 |
| void iis_cur(float*x, float*y, char* ch) { |
| 29 |
|
| |
| 30 |
|
| unsigned short hdr[8]; |
| 31 |
|
| short buf[SZ_WCSTEXT]; |
| 32 |
|
| int nbytes,wcs; |
| 33 |
|
| |
| 34 |
|
| /* Send read request */ |
| 35 |
|
| |
| 36 |
0 |
| hdr[TRANSFER_ID] = PDL_IIS_IREAD; |
| 37 |
0 |
| hdr[THING_COUNT] = 0; |
| 38 |
0 |
| hdr[SUB_UNIT] = IMCURSOR; |
| 39 |
0 |
| hdr[CHECK_SUM] = 0; |
| 40 |
0 |
| hdr[X_REGISTER] = 0; |
| 41 |
0 |
| hdr[Y_REGISTER] = 0; |
| 42 |
0 |
| hdr[Z_REGISTER] = 0; |
| 43 |
0 |
| hdr[T_REGISTER] = 0; |
| 44 |
0 |
| iis_checksum(hdr); |
| 45 |
0 |
| iis_write((char*)hdr, 8*sizeof(short)); |
| 46 |
|
| |
| 47 |
|
| /* Read however many bytes it send in this case */ |
| 48 |
|
| |
| 49 |
0 |
▶ | if ((nbytes = read (iispipe_i, buf, SZ_WCSTEXT)) <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((nbytes = read (iispipe_i, buf, SZ_WCSTEXT)) <= 0) |
0 |
0 |
0 |
|
| 50 |
0 |
| iis_error ("iis_cur: cannot read IIS pipe\n",""); |
| 51 |
|
| |
| 52 |
0 |
▶ | if (sscanf ((char*)buf, "%f %f %d %c", x, y, &wcs, ch) != 4) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sscanf ((char*)buf, "%f %f %d %c", x, y, &wcs, ch) != 4) |
0 |
0 |
0 |
|
| 53 |
0 |
| iis_error ("iis_cur: can't parse '%s'\n", (char*)buf); |
| 54 |
0 |
| } |
| 55 |
|
| |
| 56 |
|
| |
| 57 |
|
| /******************* iis_drawcirc *******************/ |
| 58 |
|
| |
| 59 |
|
| /* Draw a circle on the image display at a given position */ |
| 60 |
|
| |
| 61 |
0 |
| void iis_drawcirc(float xcen, float ycen, float radius, int colour, int frame) { |
| 62 |
|
| |
| 63 |
|
| unsigned short hdr[8]; |
| 64 |
|
| unsigned char *data; |
| 65 |
|
| int i,j,y; |
| 66 |
|
| int ymin,ymax,ntrans,nlines,nbytes; |
| 67 |
|
| float xcen2,ycen2,dd; |
| 68 |
|
| char wcsbuf[SZ_WCSTEXT]; |
| 69 |
|
| float xx, yx, xy, yy, xo, yo; /* wcs matrix values */ |
| 70 |
|
| float xx2, yx2, xy2, yy2, xo2, yo2; /* wcs inverse matrix values */ |
| 71 |
|
| char label[1024]; /* wcs file title */ |
| 72 |
|
| int w_type; /* wcs scaling code */ |
| 73 |
|
| float low, high; /* wcs scaling limits */ |
| 74 |
|
| int chan; |
| 75 |
|
| float rr; |
| 76 |
|
| |
| 77 |
0 |
| chan = iis_chan(frame); |
| 78 |
|
| |
| 79 |
|
| |
| 80 |
|
| /* Send WCS read request */ |
| 81 |
|
| |
| 82 |
0 |
| hdr[TRANSFER_ID] = -PDL_IIS_IREAD; |
| 83 |
0 |
| hdr[THING_COUNT] = 0; |
| 84 |
0 |
| hdr[SUB_UNIT] = WCS; |
| 85 |
0 |
| hdr[CHECK_SUM] = 0; |
| 86 |
0 |
| hdr[X_REGISTER] = 0; |
| 87 |
0 |
| hdr[Y_REGISTER] = 0; |
| 88 |
0 |
| hdr[Z_REGISTER] = chan; |
| 89 |
0 |
| hdr[T_REGISTER] = 0; |
| 90 |
0 |
| iis_checksum(hdr); |
| 91 |
0 |
| iis_write((char*)hdr, 8*sizeof(short)); |
| 92 |
|
| |
| 93 |
0 |
| iis_read ((char*)wcsbuf, SZ_WCSTEXT); /* Get WCS data */ |
| 94 |
|
| |
| 95 |
0 |
| sscanf(wcsbuf, "%[^\n]\n%f%f%f%f%f%f%f%f%d", label, |
| 96 |
|
| &xx, &yx, &xy, &yy, &xo, &yo, &low, &high, &w_type); |
| 97 |
|
| |
| 98 |
|
| /* Invert transform (I don't care about non-square coord systems! */ |
| 99 |
|
| |
| 100 |
0 |
| xcen2 = (xcen-xo)/xx; |
| 101 |
0 |
| ycen2 = frameY - (ycen-yo)/yy - 1; |
| 102 |
|
| |
| 103 |
|
| /* Correct scale factor - OK for square images don't want to |
| 104 |
|
| draw ellipses for non-square ones so take geometric mean */ |
| 105 |
|
| |
| 106 |
0 |
| rr = radius / sqrt(iis_abs(xx*yy)); |
| 107 |
|
| |
| 108 |
|
| /* Transfer limits (with buffer to allow for edge effects) */ |
| 109 |
|
| |
| 110 |
0 |
| ymin = ycen2-rr-2; |
| 111 |
0 |
▶ | if (ymin<0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ymin<0) |
0 |
0 |
0 |
|
| 112 |
0 |
| ymin=0; |
| 113 |
0 |
| ymax = ycen2+rr+2; |
| 114 |
0 |
▶ | if (ymax>=frameY) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ymax>=frameY) |
0 |
0 |
0 |
|
| 115 |
0 |
| ymax=frameY-1; |
| 116 |
|
| |
| 117 |
|
| /* Work out how many lines to transfer at a go */ |
| 118 |
|
| |
| 119 |
0 |
| ntrans = RBUFFSZ/frameX; |
| 120 |
0 |
▶ | if (ntrans<1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ntrans<1) |
0 |
0 |
0 |
|
| 121 |
0 |
| ntrans = 1; |
| 122 |
|
| |
| 123 |
|
| /* Allocate buffer for data transfers */ |
| 124 |
|
| |
| 125 |
0 |
| data = (unsigned char*) calloc(ntrans*frameX, sizeof(unsigned char)); |
| 126 |
0 |
▶ | if (data==NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (data==NULL) |
0 |
0 |
0 |
|
| 127 |
0 |
| iis_error("iis_drawcirc: out of memory for buffer",""); |
| 128 |
|
| |
| 129 |
|
| /* Loop over blocks */ |
| 130 |
|
| |
| 131 |
0 |
▶ | for (y = ymin; y < ymax; y+=ntrans) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (y = ymin; y < ymax; y+=ntrans) { |
0 |
0 |
0 |
|
| 132 |
|
| |
| 133 |
0 |
| nlines = ntrans; /* Number of lines to transfer */ |
| 134 |
0 |
▶ | if (y+ntrans>ymax) |
Branch: 1 branch
| Branch | True | False | Total |
| if (y+ntrans>ymax) |
0 |
0 |
0 |
|
| 135 |
0 |
| nlines = ymax - y; |
| 136 |
|
| |
| 137 |
|
| /* Read data */ |
| 138 |
|
| |
| 139 |
0 |
| hdr[TRANSFER_ID] = -PDL_IIS_IREAD | PACKED | BLOCKXFER; |
| 140 |
0 |
| hdr[THING_COUNT] = -nlines*frameX; |
| 141 |
0 |
| hdr[SUB_UNIT] = REFRESH; |
| 142 |
0 |
| hdr[CHECK_SUM] = 0; |
| 143 |
0 |
| hdr[X_REGISTER] = ADVXONTC; |
| 144 |
0 |
| hdr[Y_REGISTER] = ADVYONXOV+frameY-y-nlines; |
| 145 |
0 |
| hdr[Z_REGISTER] = chan; |
| 146 |
0 |
| hdr[T_REGISTER] = ALLBITPL; |
| 147 |
0 |
| iis_checksum(hdr); |
| 148 |
0 |
| iis_write((char*)hdr, 8*sizeof(short)); |
| 149 |
0 |
| iis_read((char*)data, nlines*frameX*sizeof(char)); |
| 150 |
|
| |
| 151 |
|
| /* Write data */ |
| 152 |
|
| |
| 153 |
0 |
| hdr[TRANSFER_ID] = PDL_IIS_IWRITE | PACKED | BLOCKXFER; |
| 154 |
0 |
| hdr[THING_COUNT] = -nlines*frameX; |
| 155 |
0 |
| hdr[SUB_UNIT] = REFRESH; |
| 156 |
0 |
| hdr[CHECK_SUM] = 0; |
| 157 |
0 |
| hdr[X_REGISTER] = ADVXONTC; |
| 158 |
0 |
| hdr[Y_REGISTER] = ADVYONXOV+frameY-y-nlines; |
| 159 |
0 |
| hdr[Z_REGISTER] = chan; |
| 160 |
0 |
| hdr[T_REGISTER] = ALLBITPL; |
| 161 |
0 |
| iis_checksum(hdr); |
| 162 |
0 |
| iis_write((char*)hdr, 8*sizeof(short)); |
| 163 |
|
| |
| 164 |
|
| /* Change Data - draw in i and j to fill circle gaps via symmetry */ |
| 165 |
|
| |
| 166 |
0 |
▶ | for (j=0; j<nlines; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<nlines; j++) { |
0 |
0 |
0 |
|
| 167 |
0 |
| dd = rr*rr - (y+j-ycen2)*(y+j-ycen2); |
| 168 |
0 |
▶ | if (dd>=0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (dd>=0) { |
0 |
0 |
0 |
|
| 169 |
0 |
| dd = sqrt(dd); |
| 170 |
0 |
| i = iis_round( (float)xcen2 - dd ); |
| 171 |
0 |
▶ | if (i>=0 && i<frameX) |
Branch: 2 branches
| Branch | True | False | Total |
| if (i>=0 && i<frameX) |
0 |
0 |
0 |
| if (i>=0 && i<frameX) |
0 |
0 |
0 |
|
| 172 |
0 |
| data[ (nlines-j-1)*frameX + i ] = colour; |
| 173 |
0 |
| i = iis_round( (float)xcen2 + dd ); |
| 174 |
0 |
▶ | if (i>=0 && i<frameX) |
Branch: 2 branches
| Branch | True | False | Total |
| if (i>=0 && i<frameX) |
0 |
0 |
0 |
| if (i>=0 && i<frameX) |
0 |
0 |
0 |
|
| 175 |
0 |
| data[ (nlines-j-1)*frameX + i ] = colour; |
| 176 |
|
| } |
| 177 |
|
| } |
| 178 |
|
| |
| 179 |
0 |
▶ | for (i=0; i<frameX; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i<frameX; i++) { |
0 |
0 |
0 |
|
| 180 |
0 |
| dd = rr*rr - (i-xcen2)*(i-xcen2); |
| 181 |
0 |
▶ | if (dd>=0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (dd>=0) { |
0 |
0 |
0 |
|
| 182 |
0 |
| dd = sqrt(dd); |
| 183 |
0 |
| j = iis_round( (float)ycen2 - (float)y - dd ); |
| 184 |
0 |
▶ | if (j>=0 && j<nlines) |
Branch: 2 branches
| Branch | True | False | Total |
| if (j>=0 && j<nlines) |
0 |
0 |
0 |
| if (j>=0 && j<nlines) |
0 |
0 |
0 |
|
| 185 |
0 |
| data[ (nlines-j-1)*frameX + i ] = colour; |
| 186 |
0 |
| j = iis_round( (float)ycen2 - (float)y + dd ); |
| 187 |
0 |
▶ | if (j>=0 && j<nlines) |
Branch: 2 branches
| Branch | True | False | Total |
| if (j>=0 && j<nlines) |
0 |
0 |
0 |
| if (j>=0 && j<nlines) |
0 |
0 |
0 |
|
| 188 |
0 |
| data[ (nlines-j-1)*frameX + i ] = colour; |
| 189 |
|
| } |
| 190 |
|
| } |
| 191 |
|
| |
| 192 |
0 |
| iis_write((char*)data, nlines*frameX*sizeof(char)); |
| 193 |
|
| |
| 194 |
|
| } |
| 195 |
0 |
| free(data); |
| 196 |
0 |
| } |
| 197 |
|
| |
| 198 |
|
| |
| 199 |
|
| /******************* iis_open ****************/ |
| 200 |
|
| |
| 201 |
|
| /* |
| 202 |
|
| Open IIS connection - if inpipe or outpipe are "" default |
| 203 |
|
| pipes are searched for in the environment variable $IMTDEV, |
| 204 |
|
| then in the directories (with the usual filenames) $HOME/iraf/dev, |
| 205 |
|
| $HOME/dev, and finally /dev. |
| 206 |
|
| |
| 207 |
|
| Note the frame buffer configuration number and dimensions |
| 208 |
|
| must be suppled by hand - life is too short to write |
| 209 |
|
| imtoolrc parsing code in C! If these don't match those in the |
| 210 |
|
| appropriate imtoolrc file problems will occur. |
| 211 |
|
| |
| 212 |
|
| */ |
| 213 |
|
| |
| 214 |
0 |
| void iis_open(char* inpipe, char* outpipe, int fb, int fbx, int fby) { |
| 215 |
|
| |
| 216 |
|
| FILE *syspipe; |
| 217 |
0 |
| char *home, *imtdev, *tok=NULL; |
| 218 |
|
| char iname[STRSIZE],oname[STRSIZE]; |
| 219 |
|
| int i,j; |
| 220 |
|
| |
| 221 |
0 |
| home = getenv("HOME"); |
| 222 |
|
| |
| 223 |
0 |
| imtdev = getenv("IMTDEV"); |
| 224 |
0 |
▶ | if (imtdev != NULL) /* Start parsing IMTDEV environment variable */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (imtdev != NULL) /* Start parsing IMTDEV environment variable */ |
0 |
0 |
0 |
|
| 225 |
0 |
| tok = strtok(imtdev,":"); |
| 226 |
0 |
▶ | if (tok!=NULL && strcmp(tok,"fifo")!=0) /* Ignore if not fifo */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (tok!=NULL && strcmp(tok,"fifo")!=0) /* Ignore if not fifo */ |
0 |
0 |
0 |
| if (tok!=NULL && strcmp(tok,"fifo")!=0) /* Ignore if not fifo */ |
0 |
0 |
0 |
|
| 227 |
0 |
| tok = NULL; |
| 228 |
|
| |
| 229 |
|
| /* Get input fifo name */ |
| 230 |
|
| |
| 231 |
0 |
▶ | if (strcmp(inpipe,"")==0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(inpipe,"")==0) { |
0 |
0 |
0 |
|
| 232 |
|
| |
| 233 |
0 |
▶ | if (tok!=NULL) { /* Check next bit of IMTDEV */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (tok!=NULL) { /* Check next bit of IMTDEV */ |
0 |
0 |
0 |
|
| 234 |
0 |
| tok = strtok(NULL,":"); |
| 235 |
0 |
▶ | if (tok != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tok != NULL) { |
0 |
0 |
0 |
|
| 236 |
0 |
| strncpy(iname,tok,STRSIZE); |
| 237 |
0 |
| goto gotin; |
| 238 |
|
| } |
| 239 |
|
| } |
| 240 |
|
| |
| 241 |
|
| /* Else look in standard places */ |
| 242 |
|
| |
| 243 |
0 |
| strncpy(iname,home,STRSIZE); strncat(iname,"/iraf/dev/imt1i",STRSIZE - strlen(iname) - 1); |
| 244 |
0 |
▶ | if (!access(iname,F_OK)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!access(iname,F_OK)) |
0 |
0 |
0 |
|
| 245 |
0 |
| goto gotin; |
| 246 |
0 |
| strncpy(iname,home,STRSIZE); strncat(iname,"/dev/imt1i",STRSIZE - strlen(iname) - 1); |
| 247 |
0 |
▶ | if (!access(iname,F_OK)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!access(iname,F_OK)) |
0 |
0 |
0 |
|
| 248 |
0 |
| goto gotin; |
| 249 |
0 |
| strncpy(iname,"/dev/imt1i",STRSIZE); |
| 250 |
0 |
▶ | if (!access(iname,F_OK)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!access(iname,F_OK)) |
0 |
0 |
0 |
|
| 251 |
0 |
| goto gotin; |
| 252 |
|
| } |
| 253 |
|
| else { |
| 254 |
0 |
| strncpy(iname,inpipe,STRSIZE); /* Use supplied arg */ |
| 255 |
0 |
| goto gotin; |
| 256 |
|
| } |
| 257 |
0 |
| iis_error("Unable to locate input FIFO in any of $HOME/dev/imt1i or %s", |
| 258 |
|
| "$HOME/dev/imt1i or /dev/imt1i\n"); |
| 259 |
|
| |
| 260 |
0 |
| gotin: |
| 261 |
|
| |
| 262 |
0 |
▶ | if (strcmp(outpipe,"")==0) { /* Get output fifo name */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (strcmp(outpipe,"")==0) { /* Get output fifo name */ |
0 |
0 |
0 |
|
| 263 |
|
| |
| 264 |
0 |
▶ | if (tok!=NULL) { /* Check next bit of IMTDEV */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (tok!=NULL) { /* Check next bit of IMTDEV */ |
0 |
0 |
0 |
|
| 265 |
0 |
| tok = strtok(NULL,":"); |
| 266 |
0 |
▶ | if (tok != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tok != NULL) { |
0 |
0 |
0 |
|
| 267 |
0 |
| strncpy(oname,tok,STRSIZE); |
| 268 |
0 |
| goto gotout; |
| 269 |
|
| } |
| 270 |
|
| } |
| 271 |
|
| /* Else look in standard places */ |
| 272 |
|
| |
| 273 |
0 |
| strncpy(oname,home,STRSIZE); strncat(oname,"/iraf/dev/imt1o",STRSIZE - strlen(oname) - 1); |
| 274 |
0 |
▶ | if (!access(oname,F_OK)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!access(oname,F_OK)) |
0 |
0 |
0 |
|
| 275 |
0 |
| goto gotout; |
| 276 |
0 |
| strncpy(oname,home,STRSIZE); strncat(oname,"/dev/imt1o",STRSIZE - strlen(oname) - 1); |
| 277 |
0 |
▶ | if (!access(oname,F_OK)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!access(oname,F_OK)) |
0 |
0 |
0 |
|
| 278 |
0 |
| goto gotout; |
| 279 |
0 |
| strncpy(oname,"/dev/imt1o",STRSIZE); |
| 280 |
0 |
▶ | if (!access(oname,F_OK)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!access(oname,F_OK)) |
0 |
0 |
0 |
|
| 281 |
0 |
| goto gotout; |
| 282 |
|
| } |
| 283 |
|
| else { |
| 284 |
0 |
| strncpy(oname,outpipe,STRSIZE); /* Use supplied arg */ |
| 285 |
0 |
| goto gotout; |
| 286 |
|
| } |
| 287 |
|
| |
| 288 |
0 |
| iis_error("Unable to locate output FIFO in any of $HOME/iraf/dev/imt1o or %s", |
| 289 |
|
| "$HOME/dev/imt1o or /dev/imt1o\n"); |
| 290 |
|
| |
| 291 |
0 |
| gotout: |
| 292 |
|
| |
| 293 |
|
| /* |
| 294 |
|
| Open the output fifo. We have to open it ourselves first as a client to |
| 295 |
|
| get around the fifo open-no-client error. |
| 296 |
|
| */ |
| 297 |
|
| |
| 298 |
|
| |
| 299 |
0 |
▶ | if ((iispipe_i = open (oname, O_RDONLY | O_NONBLOCK)) != -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((iispipe_i = open (oname, O_RDONLY | O_NONBLOCK)) != -1) { |
0 |
0 |
0 |
|
| 300 |
0 |
▶ | if ((iispipe_o = open (oname, O_WRONLY | O_NONBLOCK)) != -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((iispipe_o = open (oname, O_WRONLY | O_NONBLOCK)) != -1) { |
0 |
0 |
0 |
|
| 301 |
0 |
| fcntl (iispipe_o, F_SETFL, O_WRONLY); |
| 302 |
|
| } else |
| 303 |
0 |
| iis_error("iis_open: cannot open IIS output pipe %s\n",oname); |
| 304 |
0 |
| close (iispipe_i); |
| 305 |
|
| } else |
| 306 |
0 |
| iis_error("iis_open: cannot open IIS output pipe %s\n",oname); |
| 307 |
|
| |
| 308 |
|
| /* Open the input fifo */ |
| 309 |
|
| |
| 310 |
0 |
▶ | if ((iispipe_i = open (iname, O_RDONLY | O_NONBLOCK)) != -1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((iispipe_i = open (iname, O_RDONLY | O_NONBLOCK)) != -1) { |
0 |
0 |
0 |
|
| 311 |
|
| |
| 312 |
|
| /* Clear input for reading. */ |
| 313 |
0 |
| fcntl (iispipe_i, F_SETFL, O_RDONLY); |
| 314 |
|
| } else |
| 315 |
0 |
| iis_error("iis_open: cannot open IIS input pipe %s\n",iname); |
| 316 |
|
| |
| 317 |
0 |
| fbconfig = fb; frameX = fbx; frameY = fby; /* Frame buffer globals */ |
| 318 |
0 |
| } |
| 319 |
|
| |
| 320 |
|
| /******************* iis_close ****************/ |
| 321 |
|
| |
| 322 |
|
| /* Close the IIS connection */ |
| 323 |
|
| |
| 324 |
0 |
| void iis_close() { |
| 325 |
0 |
| close(iispipe_o); |
| 326 |
0 |
| close(iispipe_i); |
| 327 |
0 |
| } |
| 328 |
|
| |
| 329 |
|
| /******************* Private routines ****************/ |
| 330 |
|
| |
| 331 |
|
| /* write to pipe */ |
| 332 |
|
| |
| 333 |
0 |
| void iis_write (char* buf, int size) { |
| 334 |
0 |
| int n = 0; |
| 335 |
0 |
| int total = 0; |
| 336 |
|
| |
| 337 |
0 |
▶ | while (total < size) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (total < size) { |
0 |
0 |
0 |
|
| 338 |
0 |
| n = write (iispipe_o, buf, size - total); |
| 339 |
0 |
▶ | if (n <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n <= 0) |
0 |
0 |
0 |
|
| 340 |
0 |
| iis_error ("iis_write: can't write to pipe\n",""); |
| 341 |
0 |
| total += n; |
| 342 |
|
| } |
| 343 |
0 |
| } |
| 344 |
|
| |
| 345 |
|
| /* read from pipe */ |
| 346 |
|
| |
| 347 |
0 |
| void iis_read (char* buf, int size) { |
| 348 |
0 |
| int n = 0; |
| 349 |
0 |
| int total = 0; |
| 350 |
|
| |
| 351 |
0 |
▶ | while (total < size) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (total < size) { |
0 |
0 |
0 |
|
| 352 |
0 |
| n = read (iispipe_i, buf, size - total); |
| 353 |
0 |
▶ | if (n <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n <= 0) |
0 |
0 |
0 |
|
| 354 |
0 |
| iis_error ("iis_read: can't read from pipe\n",""); |
| 355 |
0 |
| total += n; |
| 356 |
|
| } |
| 357 |
0 |
| } |
| 358 |
|
| |
| 359 |
0 |
| void iis_checksum ( unsigned short *hdr ) { |
| 360 |
|
| int indx; |
| 361 |
0 |
| int checksum = 0; |
| 362 |
0 |
▶ | for (indx = 0; indx < 8; indx++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (indx = 0; indx < 8; indx++) { |
0 |
0 |
0 |
|
| 363 |
0 |
| checksum += hdr[indx]; |
| 364 |
|
| } |
| 365 |
0 |
| hdr[CHECK_SUM] = CHECKSUMVAL - (unsigned short) checksum; |
| 366 |
0 |
| } |
| 367 |
|
| |
| 368 |
|
| /* Return the channel number associated with a display frame */ |
| 369 |
|
| |
| 370 |
0 |
| int iis_chan(int frame) { |
| 371 |
|
| int chan[5]; |
| 372 |
|
| |
| 373 |
0 |
| chan[1]=CHAN1; chan[2]=CHAN2; chan[3]=CHAN3; chan[4]=CHAN4; |
| 374 |
0 |
▶ | if (frame>0 && frame<5) |
Branch: 2 branches
| Branch | True | False | Total |
| if (frame>0 && frame<5) |
0 |
0 |
0 |
| if (frame>0 && frame<5) |
0 |
0 |
0 |
|
| 375 |
0 |
| return chan[frame]; |
| 376 |
|
| else { |
| 377 |
0 |
| iis_error("iis_display: invalid frame number, must be 1-4\n",""); |
| 378 |
0 |
| return -1; |
| 379 |
|
| } |
| 380 |
|
| } |
| 381 |
|
| |
| 382 |
|
| /* Round to nearest int symmetrically about zero */ |
| 383 |
|
| |
| 384 |
0 |
| int iis_round ( float i ) { |
| 385 |
0 |
▶ | if (i>=0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i>=0) |
0 |
0 |
0 |
|
| 386 |
0 |
| return (int) (i+0.5); |
| 387 |
|
| else |
| 388 |
0 |
| return -( (int)(0.5-i) ); |
| 389 |
|
| } |
| 390 |
|
| |
| 391 |
0 |
| float iis_abs(float x) { |
| 392 |
0 |
▶ | if (x<0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (x<0) |
0 |
0 |
0 |
|
| 393 |
0 |
| return (-x); |
| 394 |
|
| else |
| 395 |
0 |
| return x; |
| 396 |
|
| } |