예제 #1
0
IDL_VPTR IDL_CDECL idl_bam_cxc_get_data(int argc, IDL_VPTR argv[]) {
	QSharedMemory shared_memory("photo");

	//QTextStream(stdout) << shared_memory.nativeKey() << endl;

	if (!shared_memory.attach(QSharedMemory::ReadOnly)) {
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Could not attach to shared memory block photo");
	}

	shared_memory.lock();
	int size = shared_memory.size();
	if (size != sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS) {
		shared_memory.unlock();
		shared_memory.detach();
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Unexpected size for shared memory block photo");
	
	}
	const unsigned int *data = (const unsigned int *) shared_memory.data();
	unsigned int *data_copy = (unsigned int *) malloc(sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS);
	memcpy(data_copy, data, sizeof(unsigned int) * NPIXELX * NPIXELY * NCHANNELS);

	shared_memory.unlock();
	shared_memory.detach();

	int n_dim = 3;
	IDL_MEMINT dim[3] = {NCHANNELS, NPIXELY, NPIXELX};
	IDL_VPTR rv = IDL_ImportArray(n_dim, dim, IDL_TYP_ULONG, (UCHAR *) data_copy, (IDL_ARRAY_FREE_CB) free, 0);

	return rv;
}
예제 #2
0
static unsigned long int* get_shared_memory(const char* key) {
	QSharedMemory shared_memory(key);

	//QTextStream(stdout) << shared_memory.nativeKey() << endl;

	if (!shared_memory.attach(QSharedMemory::ReadOnly)) {
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Could not attach to shared memory block %s", key);
	}

	shared_memory.lock();
	int size = shared_memory.size();
	if (size != sizeof(unsigned long int) * NPIXELX * NPIXELY) {
		shared_memory.unlock();
		shared_memory.detach();
		IDL_MessageFromBlock(bam_cxc_msg_block, BAM_CXC_ERROR, IDL_MSG_LONGJMP, "Unexpected size for shared memory block %s", key);
	
	}
	const unsigned long int *data = (const unsigned long int *) shared_memory.data();
	unsigned long int *data_copy = (unsigned long int *) malloc(sizeof(unsigned long int) * NPIXELX * NPIXELY);
	memcpy(data_copy, data, sizeof(unsigned long int) * NPIXELX * NPIXELY);

	shared_memory.unlock();
	shared_memory.detach();

	return data_copy;
}
예제 #3
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_GetCameraFromIndex
//
IDL_VPTR IDL_CDECL idlpgr_GetCameraFromIndex(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  int camera;
  fc2PGRGuid guid;
  IDL_VPTR idl_guid;
  IDL_ULONG *pd;
  IDL_MEMINT dim = 4;
  int i;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  camera = (argc == 2) ? (int) IDL_LongScalar(argv[1]) : 0;

  error = fc2GetCameraFromIndex(context, camera, &guid);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not acquire specified camera",
			 error);

  // transfer camera guid to IDL as a vector of ULONG values
  pd = (IDL_ULONG *) 
    IDL_MakeTempVector(IDL_TYP_ULONG, dim, IDL_ARR_INI_NOP, &idl_guid);
  for (i = 0; i < 4; i++)
    pd[i] = guid.value[i];
  
  return idl_guid;
}
예제 #4
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_GetImage
//
// Transfer image data to preallocated IDL buffer
//
void IDL_CDECL idlpgr_GetImage(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Image *image;
  IDL_MEMINT ndims, dim[IDL_MAX_ARRAY_DIM];
  IDL_VPTR idl_image;
  UCHAR *pd;

  image = (fc2Image *) IDL_ULong64Scalar(argv[0]);
  
  if (image->cols == image->stride) {
    ndims = 2;
    dim[0] = image->cols;
    dim[1] = image->rows;
  } else {
    ndims = 3;
    dim[0] = 3;
    dim[1] = image->cols;
    dim[2] = image->rows;
  }

  idl_image = argv[1];
  IDL_ENSURE_ARRAY(idl_image);
  if (idl_image->value.arr->arr_len == image->stride*image->rows){
    pd = idl_image->value.arr->data;
  } else {
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "IDL buffer is not the same size as the image.",
			 error);
  }
  memcpy(pd, image->pData, image->rows*image->stride);
}
예제 #5
0
int IDL_Load ( void )
{
  if ( ! ( msg_block = IDL_MessageDefineBlock ( "IDLtoC", ARRLEN ( msg_arr ),msg_arr ) ) )
    return IDL_FALSE;
  if ( !IDL_ShadowStartup() )
    IDL_MessageFromBlock ( msg_block, IDL_SHADOW_ERROR, IDL_MSG_RET, "Unable to initialize Shadow" );

  return IDL_TRUE;
}
예제 #6
0
int IDL_Load(void) {
  if (!(readwu_msg_block=IDL_MessageDefineBlock("readwu", ARRLEN(msg_arr),msg_arr))) {
    return NULL;
  }
  if (!readwu_startup()) {
    IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"can't load readwu");
  }
  return IDL_TRUE;
}
예제 #7
0
static IDL_VPTR IDL_CDECL IDL_mg_heapid(int argc, IDL_VPTR *argv) {
  IDL_ENSURE_SCALAR(argv[0]);

  if (argv[0]->type != IDL_TYP_PTR && argv[0]->type != IDL_TYP_OBJREF) {
    IDL_MessageFromBlock(msg_block, M_MG_WRONG_TYPE, IDL_MSG_RET);
  }

  return IDL_GettmpULong(argv[0]->value.hvid);
}
예제 #8
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_DestroyContext
//
void IDL_CDECL idlpgr_DestroyContext(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  error = fc2DestroyContext(context);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not destroy specified context",
			 error);
}
예제 #9
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_CreateContext
//
IDL_VPTR IDL_CDECL idlpgr_CreateContext(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;

  error = fc2CreateContext(&context);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP, 
			 "Could not create context",
			 error);

  return IDL_GettmpULong64((IDL_ULONG64) context);
}
예제 #10
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_StopCapture
//
void IDL_CDECL idlpgr_StopCapture(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  
  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  
  error = fc2StopCapture(context);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not stop capture",
			 error);
}
예제 #11
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_DestroyImage
//
void IDL_CDECL idlpgr_DestroyImage(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Image *image;

  image = (fc2Image *) IDL_ULong64Scalar(argv[0]);
  error = fc2DestroyImage(image);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not destroy image",
			 error);
  IDL_MemFree(image, NULL, 0);
}
예제 #12
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_GetCameraInfo
//
// Returns a subset of the fc2CameraInfo structure
//
IDL_VPTR IDL_CDECL idlpgr_GetCameraInfo(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2CameraInfo camerainfo;
  IDL_StructDefPtr sdef;
  char *pd;
  IDL_MEMINT one = 1;
  IDL_VPTR idl_camerainfo;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  error = fc2GetCameraInfo(context, &camerainfo);
  if (error) 
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not read camera info",
			 error);

  static IDL_STRUCT_TAG_DEF tags[] = {
    { "SERIALNUMBER",     0, (void *) IDL_TYP_ULONG },
    { "ISCOLORCAMERA",    0, (void *) IDL_TYP_LONG },
    { "MODELNAME",        0, (void *) IDL_TYP_STRING },
    { "VENDORNAME",       0, (void *) IDL_TYP_STRING },
    { "SENSORINFO",       0, (void *) IDL_TYP_STRING },
    { "SENSORRESOLUTION", 0, (void *) IDL_TYP_STRING },
    { "DRIVERNAME",       0, (void *) IDL_TYP_STRING },
    { "FIRMWAREVERSION",  0, (void *) IDL_TYP_STRING },
    { 0 }
  };
  sdef = IDL_MakeStruct("fc2CameraInfo", tags);
  pd = IDL_MakeTempStruct(sdef, 1, &one, &idl_camerainfo, TRUE);
  *(IDL_ULONG *) pd      = camerainfo.serialNumber;
  pd += sizeof(IDL_ULONG);
  *(IDL_LONG *) pd = camerainfo.isColorCamera;
  pd += sizeof(IDL_LONG);
  IDL_StrStore((IDL_STRING *) pd, camerainfo.modelName);
  pd += sizeof(IDL_STRING);
  IDL_StrStore((IDL_STRING *) pd, camerainfo.vendorName);
  pd += sizeof(IDL_STRING);
  IDL_StrStore((IDL_STRING *) pd, camerainfo.sensorInfo);
  pd += sizeof(IDL_STRING);
  IDL_StrStore((IDL_STRING *) pd, camerainfo.sensorResolution);
  pd += sizeof(IDL_STRING);
  IDL_StrStore((IDL_STRING *) pd, camerainfo.driverName);
  pd += sizeof(IDL_STRING);
  IDL_StrStore((IDL_STRING *) pd, camerainfo.firmwareVersion);
  
  return idl_camerainfo;
}
예제 #13
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_SetProperty
//
// Write property values to camera
//
// Reference: FlyCapture2Defs_C.h
//
void IDL_CDECL idlpgr_SetProperty(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2Property property;
  char *sname;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  IDL_ENSURE_STRUCTURE(argv[1]);
  IDL_StructTagNameByIndex(argv[1]->value.s.sdef, 0, IDL_MSG_LONGJMP, &sname);
  if (strcmp(sname, "fc2Property"))
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERROR, IDL_MSG_LONGJMP,
			 "Argument is not of type fc2Property.");

  memcpy((char *) &property, (char *) argv[1]->value.s.arr->data, 
	 sizeof(fc2Property));

  error = fc2SetProperty(context, &property);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not set requested property",
			 error);
}
예제 #14
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_Connect
//
void IDL_CDECL idlpgr_Connect(int argc, IDL_VPTR argv[])
 {
  fc2Error error;
  fc2Context context;
  fc2PGRGuid guid;
  IDL_MEMINT n;
  IDL_ULONG *pd;
  int i;
  
  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  IDL_ENSURE_ARRAY(argv[1]);
  if (argv[1]->value.arr->n_elts != 4)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERROR, IDL_MSG_LONGJMP,
			 "Provided variable is not a camera GUID.");
  pd = (IDL_ULONG *) argv[1]->value.arr->data;
  for (i = 0; i < 4; i++)
    guid.value[i] = pd[i];
  error = fc2Connect(context, &guid);
  if (error) 
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not connect camera to context",
			 error);
}
예제 #15
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_RetrieveBuffer
//
// Transfer image to Point Grey image buffer.
//
void IDL_CDECL idlpgr_RetrieveBuffer(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2Image *image;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  image = (fc2Image *) IDL_ULong64Scalar(argv[1]);

  error = fc2RetrieveBuffer(context, image);
  if (error) 
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not retrieve image buffer",
			 error);
}
예제 #16
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_WriteRegister
//
// Write unsigned integer to specified register
//
void IDL_CDECL idlpgr_WriteRegister(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  unsigned int address, value;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  address = (unsigned int) IDL_ULongScalar(argv[1]);
  value =   (unsigned int) IDL_ULongScalar(argv[2]);

  error = fc2WriteRegister(context, address, value);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not write value to specified register",
			 error);
}
예제 #17
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_CreateImage
//
IDL_VPTR IDL_CDECL idlpgr_CreateImage(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Image *image;
  IDL_MEMINT dim;

  dim = (IDL_MEMINT) sizeof(fc2Image);
  image = (fc2Image *) IDL_MemAlloc(dim, NULL, 0);
  error = fc2CreateImage(image);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could create image",
			 error);

  return IDL_GettmpULong64((IDL_ULONG64) image);
}
예제 #18
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_GetNumOfCameras
//
IDL_VPTR IDL_CDECL idlpgr_GetNumOfCameras(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  unsigned int ncameras = 0;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);

  error = fc2GetNumOfCameras(context, &ncameras);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not count cameras",
			 error);
  
  return IDL_GettmpLong(ncameras);
}
예제 #19
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_ReadRegister
//
// Read contents of specified register
//
IDL_VPTR IDL_CDECL idlpgr_ReadRegister(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  unsigned int address, value;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  address = (unsigned int) IDL_ULongScalar(argv[1]);
  
  error = fc2ReadRegister(context, address, &value);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not read from specified register",
			 error);
  
  return IDL_GettmpULong((IDL_ULONG) value);
}
예제 #20
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_GetPropertyInfo
//
// Get information about property
//
// Reference: FlyCapture2Defs_C.h
//
IDL_VPTR IDL_CDECL idlpgr_GetPropertyInfo(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2PropertyInfo info;
  static IDL_MEMINT one = 1;
  static IDL_MEMINT r[] = {1, 8};
  static IDL_MEMINT s[] = {1, MAX_STRING_LENGTH};
  IDL_VPTR idl_info;
  IDL_StructDefPtr sdef;
  char *pd;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  info.type = (fc2PropertyType) IDL_LongScalar(argv[1]);

  error = fc2GetPropertyInfo(context, &info);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not get requested property information",
			 error);

  static IDL_STRUCT_TAG_DEF tags[] = {
    { "TYPE",             0, (void *) IDL_TYP_LONG },
    { "PRESENT",          0, (void *) IDL_TYP_LONG },
    { "AUTOSUPPORTED",    0, (void *) IDL_TYP_LONG },
    { "MANUALSUPPORTED",  0, (void *) IDL_TYP_LONG },
    { "ONOFFSUPPORTED",   0, (void *) IDL_TYP_LONG },
    { "ONEPUSHSUPPORTED", 0, (void *) IDL_TYP_LONG },
    { "ABSVALSUPPORTED",  0, (void *) IDL_TYP_LONG },
    { "READOUTSUPPORTED", 0, (void *) IDL_TYP_LONG },
    { "MIN",              0, (void *) IDL_TYP_ULONG },
    { "MAX",              0, (void *) IDL_TYP_ULONG },
    { "ABSMIN",           0, (void *) IDL_TYP_FLOAT },
    { "ABSMAX",           0, (void *) IDL_TYP_FLOAT },
    { "PUNITS",           s, (void *) IDL_TYP_BYTE },
    { "PUNITABBR",        s, (void *) IDL_TYP_BYTE },
    { "RESERVED",         r, (void *) IDL_TYP_ULONG },
    { 0 }
  };

  sdef = IDL_MakeStruct("fc2PropertyInfo", tags);
  pd = IDL_MakeTempStruct(sdef, 1, &one, &idl_info, TRUE);
  memcpy(pd, (char *) &info, sizeof(fc2PropertyInfo));

  return idl_info;
}
예제 #21
0
파일: idlpgr.c 프로젝트: davidgrier/idlpgr
//
// idlpgr_GetProperty
//
// Read property values from camera
//
// Reference: FlyCapture2Defs_C.h
//
IDL_VPTR IDL_CDECL idlpgr_GetProperty(int argc, IDL_VPTR argv[])
{
  fc2Error error;
  fc2Context context;
  fc2Property property;
  static IDL_MEMINT r[] = {1, 8};
  static IDL_MEMINT one = 1;
  IDL_VPTR idl_property;
  IDL_StructDefPtr sdef;
  char *pd;

  context = (fc2Context) IDL_ULong64Scalar(argv[0]);
  property.type = (fc2PropertyType) IDL_LongScalar(argv[1]);

  error = fc2GetProperty(context, &property);
  if (error)
    IDL_MessageFromBlock(msgs, M_IDLPGR_ERRORCODE, IDL_MSG_LONGJMP,
			 "Could not get requested property",
			 error);
  
  static IDL_STRUCT_TAG_DEF tags[] = {
    { "TYPE",           0, (void *) IDL_TYP_LONG },
    { "PRESENT",        0, (void *) IDL_TYP_LONG },
    { "ABSCONTROL",     0, (void *) IDL_TYP_LONG },
    { "ONEPUSH",        0, (void *) IDL_TYP_LONG },
    { "ONOFF",          0, (void *) IDL_TYP_LONG },
    { "AUTOMANUALMODE", 0, (void *) IDL_TYP_LONG },
    { "VALUEA",         0, (void *) IDL_TYP_ULONG },
    { "VALUEB",         0, (void *) IDL_TYP_ULONG },
    { "ABSVALUE",       0, (void *) IDL_TYP_FLOAT },
    { "RESERVED",       r, (void *) IDL_TYP_ULONG },
    { 0 }
  };
  sdef = IDL_MakeStruct("fc2Property", tags);
  pd = IDL_MakeTempStruct(sdef, 1, &one, &idl_property, TRUE);
  memcpy(pd, (char *) &property, sizeof(fc2Property));

  return idl_property;
}
예제 #22
0
파일: mg_net.c 프로젝트: jiezhou87/mglib
/*
  err = MG_NET_SENDVAR(socket, variable [, host] [, port])

  Sends a complete IDL variable to a socket for reading by MG_NET_RECVVAR. The
  variable must be one of the basic types, but strings and arrays are sent
  with array dimensions and lengths intact.

	When sending data from a UDP socket, you must specify the remote host and
	port arguments where host is the value returned from the MG_NET_NAME2HOST
	function.

  Note: This is the easiest way to send a complete variable from one IDL to
  another. The receiver will byteswap the data if necessary. One should be
  careful not to mix calls to MG_NET_SEND/RECV and MG_NET_SENDVAR/RECVVAR as
  the latter send formatted information. You can use the two calls on the same
  socket as long as they are paired.
*/
static IDL_VPTR IDL_CDECL mg_net_sendvar(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i;
  i_var	var;
  int host, addr_len;
  short	port;
  IDL_LONG iRet;
  IDL_VPTR vpTmp;
  char *pbuffer;
  struct sockaddr_in sin;

  i = IDL_LongScalar(argv[0]);
  if ((i < 0) || (i >= MAX_SOCKETS)) return (IDL_GettmpLong(-1));
  if (net_list[i].iState != NET_IO) return (IDL_GettmpLong(-1));
  IDL_ENSURE_SIMPLE(argv[1]);
  vpTmp = argv[1];

  if (net_list[i].iType == NET_UDP) {
    if (argc == 4) {
      host = IDL_ULongScalar(argv[2]);
      port = (short) IDL_LongScalar(argv[3]);
    } else {
      IDL_MessageFromBlock(msg_block,
			   MG_NET_ERROR,
			   IDL_MSG_RET,
			   "This UDP socket requires the destination HOST and PORT arguments.");
    }
  }

  var.token = TOKEN;
  var.type = vpTmp->type;
  if ((var.type == IDL_TYP_STRUCT) ||
      (var.type == IDL_TYP_PTR) ||
      (var.type == IDL_TYP_OBJREF) ||
      (var.type == IDL_TYP_UNDEF)) {
    IDL_MessageFromBlock(msg_block,
			 MG_NET_BADTYPE,
			 IDL_MSG_LONGJMP,
			 IDL_TypeNameFunc(var.type));
  }

  if (vpTmp->type == IDL_TYP_STRING) {
    if (vpTmp->flags & IDL_V_ARR) return (IDL_GettmpLong(-1));
    pbuffer = IDL_STRING_STR(&(vpTmp->value.str));
    var.ndims = 0;
    var.len = vpTmp->value.str.slen + 1;
    var.nelts = var.len;
  } else if (vpTmp->flags & IDL_V_ARR) {
    pbuffer = vpTmp->value.arr->data;
    var.ndims = vpTmp->value.arr->n_dim;
    var.len = vpTmp->value.arr->arr_len;
    var.nelts = vpTmp->value.arr->n_elts;
    memcpy(var.dims, vpTmp->value.arr->dim, IDL_MAX_ARRAY_DIM * sizeof(IDL_LONG));
  } else {
    pbuffer = &(vpTmp->value.c);
    var.ndims = 0;
    var.len = IDL_TypeSizeFunc(var.type);
    var.nelts = 1;
  }

  /* send native, recvvar swaps if needed */
  if (net_list[i].iType == NET_UDP) {
    sin.sin_addr.s_addr = host;
    sin.sin_family = AF_INET;
    sin.sin_port = htons(port);
    addr_len = sizeof(struct sockaddr_in);

    iRet = sendto(net_list[i].socket, (char *) &var, sizeof(i_var), 0,
		  (struct sockaddr *) &sin, addr_len);
    if (iRet == -1) return(IDL_GettmpLong(iRet));

    iRet = sendto(net_list[i].socket, pbuffer, var.len, 0,
		  (struct sockaddr *) &sin, addr_len);
  } else {
    iRet = send(net_list[i].socket,(char *) &var, sizeof(i_var), 0);
    if (iRet == -1) return (IDL_GettmpLong(iRet));
    
    iRet = send(net_list[i].socket, pbuffer, var.len, 0);
  }

  return(IDL_GettmpLong(1));
}
예제 #23
0
IDL_VPTR readwu(int argc, IDL_VPTR argv[], char *argk) {
  IDL_VPTR filename=NULL;
  static IDL_VARIABLE rv;
  rv.type=IDL_TYP_INT;
  rv.flags=IDL_V_CONST|IDL_V_NULL;
  rv.value.i=-1;

  char *outfile=NULL, buf[256];
  struct stat statbuf;
  int nbytes,nread,nsamples;
  std::string tmpbuf("");
  int i=0,j;

  if (argc != 1) {
    fprintf(stderr,"argc=%d\n",argc);
    fprintf(stderr,"array=readwu(wufile_name)\n");
    return &rv;
  }
  IDL_STRING *infile=NULL;
  if (argv[0]->type != IDL_TYP_STRING) {
    IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"Parameter 1 must be type STRING");
  } else {
    infile=(IDL_STRING *)(&argv[0]->value.s);
  }
  FILE *in=fopen(infile->s,"r");
  if (!in) {
    IDL_MessageFromBlock(readwu_msg_block,0,IDL_MSG_RET,"File not found");
    return &rv;
  } 
  stat(infile->s,&statbuf);
  nbytes=statbuf.st_size;
  fseek(in,0,SEEK_SET);
  tmpbuf.reserve(nbytes);
  // read entire file into a buffer.
  while ((nread=(int)fread(buf,1,sizeof(buf),in))) {
    tmpbuf+=std::string(&(buf[0]),nread);
  }
  // parse the header
  header.parse_xml(tmpbuf);
  // decode the data
  std::vector<unsigned char> datav(
    xml_decode_field<unsigned char>(tmpbuf,"data") 
  );
  tmpbuf.clear();
  nsamples=header.group_info->data_desc.nsamples;
  nbytes=nsamples*header.group_info->recorder_cfg->bits_per_sample/8;
  if (datav.size() < nbytes) {
    fprintf(stderr,"Data size does not match number of samples\n");
    return &rv;
  }
  // convert the data to floating point
  sah_complex *fpdata=(sah_complex *)IDL_MemAlloc(nsamples*sizeof(sah_complex),0,IDL_MSG_RET);
  if (!fpdata) {
    fprintf(stderr,"Unable to allocate memory!\r\n");
    return &rv;
  } 
  bits_to_floats(&(datav[0]),fpdata,nsamples);
  datav.clear();
  IDL_MEMINT dims[]={nsamples};
  return IDL_ImportArray(1,dims,IDL_TYP_COMPLEX,(UCHAR *)fpdata,NULL,NULL);
}