comparison DDS_Fox.c @ 13:e45d6e9544f5

Log file name and line number on error
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 16 Jul 2012 13:04:01 +0200
parents adc9e2a67547
children b47b97cfd050
comparison
equal deleted inserted replaced
12:e8cca9555280 13:e45d6e9544f5
1 #include <userint.h>
2 #include <tcpsupp.h> 1 #include <tcpsupp.h>
3 #include <ansi_c.h> 2 #include <ansi_c.h>
4 #include "DDS_Fox.h" 3 #include "DDS_Fox.h"
5 4
6 //#define DDS_IP "192.168.0.3" 5 //#define DDS_IP "192.168.0.3"
40 GetCtrlVal (panel, CONTROL_DDS_RATE, &(Parameter->SweepRate)) ; 39 GetCtrlVal (panel, CONTROL_DDS_RATE, &(Parameter->SweepRate)) ;
41 GetCtrlVal (panel, CONTROL_DDS_DELTA_T, &(Parameter->Delta_T)) ; 40 GetCtrlVal (panel, CONTROL_DDS_DELTA_T, &(Parameter->Delta_T)) ;
42 return(Parameter); 41 return(Parameter);
43 }*/ 42 }*/
44 43
44
45 #define error(...) _error(__FILE__, __LINE__, __func__, __VA_ARGS__)
46
47 void _error(const char *file, int line, const char *func, const char *frmt, ...)
48 {
49 va_list args;
50 va_start(args, line);
51 fprintf(stderr, "ERROR: %s:%d:%s: ", file, line, func);
52 vfprintf(stderr, frmt, args);
53 fprintf(stderr, "\n");
54 va_end(args);
55 }
45 56
46 57
47 void DDS_Initialize (DDSParameter *Param) { 58 void DDS_Initialize (DDSParameter *Param) {
48 char Request[255]; 59 char Request[255];
49 //send NOP command 60 //send NOP command
292 int SendCmd(char *Buffer, DDSParameter *Param) { 303 int SendCmd(char *Buffer, DDSParameter *Param) {
293 unsigned int hConv=0; 304 unsigned int hConv=0;
294 char Response[255]; 305 char Response[255];
295 char parsebuf[255]; 306 char parsebuf[255];
296 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) { 307 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) {
297 printf("Connect failed\n"); 308 error("Connect failed");
298 return -1; 309 return -1;
299 } 310 }
300 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) { 311 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) {
301 printf("Write failed\n"); 312 error("Write failed");
302 return -1; 313 return -1;
303 } 314 }
304 sprintf(Response," "); 315 sprintf(Response," ");
305 if (ClientTCPRead (hConv, Response, 255, 0) < 0) { 316 if (ClientTCPRead (hConv, Response, 255, 0) < 0) {
306 printf("Read failed\n"); 317 error("Read failed");
307 return -1; 318 return -1;
308 } 319 }
309 if (strncmp("OK",Response,2)) { 320 if (strncmp("OK",Response,2)) {
310 printf("Response failed %s %s\n", Buffer, Response); 321 error("Response failed %s %s", Buffer, Response);
311 return -1; 322 return -1;
312 } 323 }
313 return 0; 324 return 0;
314 } 325 }
315 326
317 int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) { 328 int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) {
318 unsigned int hConv=0; 329 unsigned int hConv=0;
319 char parsebuf[255]; 330 char parsebuf[255];
320 char Response[255]; 331 char Response[255];
321 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) { 332 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) {
322 printf("Connect failed\n"); 333 error("Connect failed");
323 return -1; 334 return -1;
324 } 335 }
325 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) { 336 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) {
326 printf("Write failed\n"); 337 error("Write failed");
327 return -1; 338 return -1;
328 } 339 }
329 sprintf(Response," "); 340 sprintf(Response," ");
330 if (ClientTCPRead (hConv, Response, 255, 0) < 0) { 341 if (ClientTCPRead (hConv, Response, 255, 0) < 0) {
331 printf("Read failed\n"); 342 error("Read failed");
332 return -1; 343 return -1;
333 } 344 }
334 345
335 if (strncmp(Buffer,Response,strlen(Buffer))) { 346 if (strncmp(Buffer,Response,strlen(Buffer))) {
336 printf("Response failed %s %s\n", Buffer, Response); 347 error("Response failed %s %s", Buffer, Response);
337 return -1; 348 return -1;
338 } 349 }
339 350
340 sprintf(parsebuf,"%s",Response) ; 351 sprintf(parsebuf,"%s",Response) ;
341 parse_command(Rd, parsebuf) ; 352 parse_command(Rd, parsebuf) ;