Ejemplo n.º 1
0
static void
__BarjutReader(
	void *threadinst )
{
	iOThread        th = ( iOThread ) threadinst;
	iOBarjut        pBarjut = ( iOBarjut ) ThreadOp.getParm( th );
	iOBarjutData    data = Data( pBarjut );
	int             time = 0;

	while( data->run )
	{
		if( !data->initOK )
		{
			__getVersion( data );
			data->initOK = __initBarjut( data );
			if( !data->initOK )
			{
				ThreadOp.sleep( 1000 );
				continue;
			}
		}

		if( time >= ( data->timeout * 1000 ) )
		{
			__getBarjutData( data, True );
			time = 0;
		}
		else
		{
			time += 20;
			ThreadOp.sleep( 20 );
			__getBarjutData( data, False );
		}
	};
	data->runFinished = True;

	TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999,
					 "BarJuT ended. <%s>", data->iid );
}
Ejemplo n.º 2
0
static void __HSI88feedbackReader( void* threadinst ) {
  iOThread th = (iOThread)threadinst;
  iOHSI88 pHSI88 = (iOHSI88)ThreadOp.getParm( th );
  iOHSI88Data o = Data(pHSI88);
  unsigned char* fb = allocMem(256);
  char out[6];
  char buffer [512];
  int k = 0;
  Boolean crDetected = False;
  int waitcounter = 0;
  Boolean ok;
  int avail = 0;
  Boolean l_dummy = True;
  int l_iLoop = 0;

  memset(fb,0,256);

  ThreadOp.sleep(1000);
  TraceOp.trc( name, TRCLEVEL_INFO, __LINE__, 9999, "HSI88 Reader started");
  if( !o->usb ) {
    __preinitHSI88(pHSI88);
    ThreadOp.sleep(100);
  }

  while( o->run ) {

    if( !o->dummyio && !o->initOK ) {
      __flushHSI88(pHSI88, True);
      __getVersion(pHSI88);
      o->initOK = __initHSI88(pHSI88);
      if( !o->initOK ) {
        ThreadOp.sleep( 1000 );
        continue;
      }
    }

    ThreadOp.sleep(10);


    if( o->dummyio ) {
      l_iLoop++;
      if( l_iLoop > 200 ) {
        iONode nodeC = NodeOp.inst( wFeedback.name(), NULL, ELEMENT_NODE );
        int addr = 4;
        wFeedback.setaddr( nodeC, addr );
        wFeedback.setstate( nodeC, l_dummy );
        if( o->iid != NULL )
          wFeedback.setiid( nodeC, o->iid );
        TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sensor %d %s",addr, wFeedback.isstate( nodeC )?"high":"low" );
        __fbstatetrigger( pHSI88, nodeC );
        l_dummy = !l_dummy;
        l_iLoop = 0;
      }
      continue;
    }

    avail = __availBytes(o);

    if( avail > 0 )
      ok = __readBytes( o, buffer, 1 );
    else
      continue;

    if( ok )
      TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Byte available: 0x%02X", buffer[0]);
    else
      continue;

    if( ok && buffer[0] == 'i' ) {
      int modcnt = 0;
      int i = 0;
      int j = 0;
      TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Info received, waiting for module count...");
      ok = __readBytes( o, (char*)buffer, 1 );
      buffer[1] = '\0';
      modcnt = buffer[0];
      TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "%d modules",modcnt);
      for( i = 0; i < modcnt; i++ ) {
        int modnr = 0;
        unsigned char highbyte = 0;
        unsigned char lowbyte = 0;
        TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "reading module data %d...", i);
        ok = __readBytes( o, (char*)buffer, 3 );
        TraceOp.trc( name, TRCLEVEL_BYTE, __LINE__, 9999, "module data %d=0x%02X 0x%02X 0x%02X", i,
                     buffer[0], buffer[1], buffer[2] );
        modnr    = buffer[0];
        highbyte = buffer[1];
        lowbyte  = buffer[2];
        for (j = 0; j< 8; j++)
        {
          if ( ( highbyte & (0x01 << j)) != (fb[modnr*2]&(0x01 << j)))
          {
            iONode nodeC = NodeOp.inst( wFeedback.name(), NULL, ELEMENT_NODE );
            int addr = (modnr-1) * 16 + j+9;
            wFeedback.setaddr( nodeC, addr );
            wFeedback.setstate( nodeC, ( highbyte & (0x01 << j))?True:False );
            if( o->iid != NULL )
              wFeedback.setiid( nodeC, o->iid );

            TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sensor %d %s",addr, wFeedback.isstate( nodeC )?"high":"low" );
            __fbstatetrigger( pHSI88, nodeC );
          }
          if ( ( lowbyte & (0x01 << j)) != (fb[modnr*2 +1]&(0x01 << j)))
          {
            iONode nodeC = NodeOp.inst( wFeedback.name(), NULL, ELEMENT_NODE );
            int addr = (modnr-1) * 16 + j+1;
            wFeedback.setaddr( nodeC, addr );
            wFeedback.setstate( nodeC,  (lowbyte & (0x01 << j))?True:False );
            if( o->iid != NULL )
              wFeedback.setiid( nodeC, o->iid );

            TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "sensor %d %s",addr, wFeedback.isstate( nodeC )?"high":"low" );
            __fbstatetrigger( pHSI88, nodeC );
          }

        }
        fb[modnr*2] = highbyte;
        fb[modnr*2+1] = lowbyte;

      }

      TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "Waiting for CR response...");
      ok = __readBytes( o, (char*)buffer, 1 );
      if (buffer[0] != '\r')
      {
        TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "Protocol Error: expected 0x13 got 0x%02x",(unsigned char)buffer[0]);
      }

      continue;
    }


    /* unmatched response. read until cr */
    TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "reading unmatched response %d...", k);
    k=0;
    crDetected = False;
    while (ok && !crDetected)
    {
      ok = __readBytes( o, (char*)&buffer[k], 1 );
      TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "Unmatched response %d=0x%02X", k, buffer[k]);
      if(buffer[k] == '\r')
        crDetected = True;
      k++;
    };

  };

  TraceOp.trc( name, TRCLEVEL_MONITOR, __LINE__, 9999, "FeedbackReader ended. <%s>", o->iid );
}