Example #1
0
int RobbyUp(void)
{
  Output &= ~O_DOWN; // if UP then !DOWN 
  Output |= O_UP;
  
  while(1)
  {
     if( WriteSerial(Output) == -1)
      {
	return (-1);
      }
     usleep(PAUSE);
     if( ReadSerial(&Input) == -1)
      {
	return (-1);
      }
     if((~Input & I_UP) == I_UP)
       {
	 Output &= ~O_UP;
	 if( WriteSerial(Output) == -1)
	   {
	     return (-1);
	   }
	 break;
       }
     else
       {
	 usleep(50);
       }
  }
  return (0);
}
Example #2
0
int RobbyRight(void)
{
  Output &= ~O_LEFT;
  Output |= O_RIGHT;

  while(1)
  {
     if( WriteSerial(Output) == -1)
       {
	return (-1);
       }
     usleep(PAUSE);       
     if( ReadSerial(&Input) == -1)
      {
	return (-1);
      }
     if((~Input & I_RIGHT) == I_RIGHT)
       {
	 usleep(140000);		// permet de continuer le mouvement pour atteindre la butée mécanique
	 Output &= ~O_RIGHT;
	 if( WriteSerial(Output) == -1)
	   {
	     return (-1);
	   }
	 break;
       }
     else
       {
	 usleep(50);
       }
  }
  return (0);
}
Example #3
0
void PrintIRBuffer(const rom char *title)
{
    WORD t;
    BYTE hilo;
    WORD byteOrWord; // 0:未設定
    WORD pos;
    char separator[2] = {'\0','\0'};

    PutsString("");  // なぜかこの出力がないと1発目が化ける

    PutsString(title);

    hilo = 1;
    pos = 0;
    byteOrWord = 0;
    while (1) {
        if (!WaitToReadySerial()) return;
        t = ReadBuffer(&pos,&byteOrWord);
        if (t==BUFF_EOF)
            break;
        sprintf(uartOutBuffer, (far rom char*)"%s%c%u",
                separator,
                hilo ? 'H' : 'L',
                t);
        WriteSerial(uartOutBuffer);
        hilo=!hilo;
        separator[0] = ',';
    }
    if (!WaitToReadySerial()) return;
    sprintf(uartOutBuffer, (far rom char*)"\r\n");
    WriteSerial(uartOutBuffer);
    if (!WaitToReadySerial()) return;
}
Example #4
0
int InitRobby(void)
{

  Input = 0;
  Output = 0;

  if(OpenSerial (PORT_NAME) == -1)
    {
      return (-1);
    }

  if( WriteSerial(Output) == -1)	// tous les relais à zéro
    {
      return (-1);
    }

  /* hack pour ne pas rester bloqué en mode démon */
  /* si la carte n'est pas reliée au port série */
  usleep(500);
  
  if( ReadSerialNonBlock(&Input) == -1)		// on initialise avec l'état réel des entrées
    {
      return (-1);
    }

  return (0);
}
Example #5
0
void PutsString(const rom char *str)
{
    if (!WaitToReadySerial()) return;
    strcpypgm2ram(uartOutBuffer, (const far rom char*)str);
    WriteSerial(uartOutBuffer);
    if (!WaitToReadySerial()) return;
}
Example #6
0
void CDataParser::ProcessInfraredRequest( QByteArray& byStream )
{
    //²éѯȡ¿¨°´Å¥×´Ì¬	AA	03 00	51 43	xx	ÎÞ	xx	55

    QByteArray byBody = GetBody( byStream );
    if ( 1 > byBody.length( ) ) {
        return;
    }
    quint8 nAddress = byBody.at( 0 );

    char cCmd [ ] = { 0xAA, 0x03, 0x00, 0x51, 0x43, nAddress + 1, 0x00, 0x55 };

    WriteSerial( pSerialPort, cCmd, sizeof ( cCmd ) );
}
Example #7
0
void CDataParser::ProcessBallotSenseRequest( QByteArray& byStream )
{
    //²éѯƱÏäµØ¸Ð״̬	AA	03 00	51 42	xx	ÎÞ 	xx	55

    QByteArray byBody = GetBody( byStream );
    if ( 1 > byBody.length( ) ) {
        return;
    }
    quint8 nAddress = byBody.at( 0 );

    char cCmd [ ] = { 0xAA, 0x03, 0x00, 0x51, 0x42, nAddress + 1, 0x00, 0x55 };

    WriteSerial( pSerialPort, cCmd, sizeof ( cCmd ) );
}
Example #8
0
int RobbyClose(void)
{
  Output &= ~O_CLOSE;
  
  if( WriteSerial(Output) == -1)
    {
	return (-1);
    }
usleep(PAUSE);    
  if( ReadSerial(&Input) == -1)
    {
	return (-1);
    }
  return (0);
}
Example #9
0
int RobbyOpen(void)
{
  Output |= O_OPEN;
  
  if( WriteSerial(Output) == -1)
    {
	return (-1);
    }
  usleep(PAUSE);    
  if( ReadSerial(&Input) == -1)
    {
	return (-1);
    }
  return (0);
}
Example #10
0
void CDataParser::ProcessGateRequest( QByteArray& byStream )
{
    QByteArray byBody = GetBody( byStream );
    if ( 2 > byBody.length( ) ) {
        return;
    }
    quint8 nAddress = ( quint8 ) byBody.at( 0 );
    quint8 nOperation = ( quint8 ) byBody.at( 1 );

    bool bOpen = ( 0 == nOperation );
    char cCan = nAddress + 1;
    char cCmd [ ] = { 0xAA, 0x03, 0x00, bOpen ? 0x4F : 0x43, 0x00, cCan, 0x00, 0x55 };
    //OpenGate=AA 03 00 4F 00 %1
    //CloseGate=AA 03 00 43 00 %1

    WriteSerial( pSerialPort, cCmd, sizeof ( cCmd ) );
}
Example #11
0
void CDataParser::ProcessLedRequest( QByteArray& byStream )
{
    QByteArray byBody = GetBody( byStream );
    if ( 1 > byBody.length( ) ) {
        return;
    }
    quint8 nAddress = ( quint8 ) byBody.at( 0 );
    QByteArray byData = byBody.right( byBody.length( ) - 1 );
    QString strContent( byData );

    //F5 C2 FF 01 0B 08 FF FF 26 4E 30 34 26 48 30 34 24 31
    QByteArray byTmp;
    char cCmd [ ] = { 0xF5, 0xC2, 0xFF, 0x01, 0x0B, 0x08, 0xFF, 0xFF, 0x26,
                                 0x4E, 0x30, 0x34, 0x26, 0x48, 0x30, 0x34, 0x24, 0x31 };
    byTmp.append( cCmd, sizeof ( cCmd ) );
    byTmp.append( CCommonFunction::GetTextCodec( )->fromUnicode( strContent ) );
    byTmp.append( char ( 0x1A ) );

    WriteSerial( pWineSerialPort, byTmp.data( ), byTmp.length( ) );
}
Example #12
0
void CDataParser::ProcessTrafficLightsRequest( QByteArray& byStream )
{
    QByteArray byBody = GetBody( byStream );
    if ( 2 > byBody.length( ) ) {
        return;
    }
    quint8 nAddress = ( quint8 ) byBody.at( 0 );
    quint8 nOperation = ( quint8 ) byBody.at( 1 );
    quint8 nTail;

    //µØÖ·Âë01
    //µÆ¹Ø±Õ£ºFA 2C 01 00 27
    //ºìµÆÁÁ£ºFA 2C 01 01 28
    //Â̵ÆÁÁ£ºFA 2C 01 02 29
    //==================================
    //µØÖ·Âë02
    //µÆ¹Ø±Õ£ºFA 2C 02 00 28
    //ºìµÆÁÁ£ºFA 2C 02 01 29
    //Â̵ÆÁÁ£ºFA 2C 02 02 2A

    switch ( nOperation  ) {
    case 0 :
        nOperation = 0x01;
        nTail = 0x28;
        break;
    case 1 :
        nOperation = 0x02;
        nTail = 0x29;
        break;

    case 2 :
        nOperation = 0x00;
        nTail = 0x27;
        break;
    }

    char cCmd [ ] = { 0xFA, 0x2C, nAddress + 1, nOperation, nAddress ?  nTail + 1 : nTail };

    WriteSerial( pWineSerialPort, cCmd, sizeof ( cCmd ) ); // pWineSerialPort
}
Example #13
0
void CDataParser::TimerActiveSend( quint16 nAddress )
{
    char cCmd [ ] = { 0xAA, 0x03, 0x00, 0x51, 0x41, nAddress, 0x00, 0x55 };
    WriteSerial( pSerialPort, cCmd, sizeof ( cCmd ) );
}
static int SerialWrite(DriverCall *dc) {
  int nwritten = 0;
  te_status testatus = TS_IN_PKT;

  if (dc->dc_context == NULL) {
    Angel_TxEngineInit(&config, &(dc->dc_packet), &(wstate.txstate));
    wstate.wbindex = 0;
    dc->dc_context = &wstate;
  }

  while ((testatus == TS_IN_PKT) && (wstate.wbindex < MAXWRITESIZE))
  {
    /* send the raw data through the tx engine to escape and encapsulate */
    testatus = Angel_TxEngine(&(dc->dc_packet), &(wstate.txstate),
                              &(wstate.writebuf)[wstate.wbindex]);
    if (testatus != TS_IDLE) wstate.wbindex++;
  }

  if (testatus == TS_IDLE) {
#ifdef DEBUG
    printf("SerialWrite: testatus is TS_IDLE during preprocessing\n");
#endif
  }

#ifdef DO_TRACE
  { 
    int i = 0;

    while (i<wstate.wbindex)
    {
        printf(">%02X ",wstate.writebuf[i]);

        if (!(++i % 16))
            printf("\n");
    }
    if (i % 16)
        printf("\n");
  }
#endif

#ifdef COMPILING_ON_WINDOWS
  if (WriteSerial(wstate.writebuf, wstate.wbindex) == COM_OK)
  {
    nwritten = wstate.wbindex;
    if (pfnProgressCallback != NULL)
    {
      progressInfo.nWritten += nwritten;
      (*pfnProgressCallback)(&progressInfo);
    }
  }
  else
  {
      MessageBox(GetFocus(), "Write error\n", "Angel", MB_OK | MB_ICONSTOP);
      return -1;   /* SJ - This really needs to return a value, which is picked up in */
                   /*      DevSW_Read as meaning stop debugger but don't kill. */
  }
#else
  nwritten = Unix_WriteSerial(wstate.writebuf, wstate.wbindex);

  if (nwritten < 0) {
    nwritten=0;
  }
#endif

#ifdef DEBUG
  if (nwritten > 0)
    printf("Wrote %#04x bytes\n", nwritten);
#endif

  if ((unsigned) nwritten == wstate.wbindex && 
      (testatus == TS_DONE_PKT || testatus == TS_IDLE)) {

    /* finished sending the packet */

#ifdef DEBUG
    printf("SerialWrite: calling Angel_TxEngineInit after sending packet (len=%i)\n",wstate.wbindex);
#endif
    testatus = TS_IN_PKT;
    wstate.wbindex = 0;
    return 1;
  }
  else {
#ifdef DEBUG
    printf("SerialWrite: Wrote part of packet wbindex=%i, nwritten=%i\n",
           wstate.wbindex, nwritten);
#endif
   
    /*
     *  still some data left to send shuffle whats left down and reset
     * the ptr
     */
    memmove((char *) wstate.writebuf, (char *) (wstate.writebuf+nwritten),
            wstate.wbindex-nwritten);
    wstate.wbindex -= nwritten;
    return 0;
  }
  return -1;
}
Example #15
0
void PutsStringCPtr(char *str)
{
    if (!WaitToReadySerial()) return;
    WriteSerial(str);
    if (!WaitToReadySerial()) return;
}
Example #16
0
void SerialWrite(u32 data)
{
	WriteSerial((u8)data);
	//putc(data,stdout);
}