Example #1
0
File: cm10a.c Project: mbkali/heyu
/*----------------------------------------------------------------------------+
 | Ask the CM10A to identify itself.                                          |
 +----------------------------------------------------------------------------*/
int c_cm10a_ident ( int argc, char *argv[] )	
{
    unsigned char buf[50];
    unsigned char *bp;
    int      j, count, nread, left;
    extern void millisleep();
    
    if ( (toggle_rts()) != 0 ) {
       fprintf(stderr, "Unable to toggle RTS line.\n");
       return 1;
    }

    bp = buf;
    nread = 0; left = 30;
    for ( j = 0; j < 3; j++ ) {
       count = exread(sptty, bp, left, 1);
       nread += count;
       if ( nread == 29 ) {
          if ( memcmp(buf, cm10a_standard_response, 29) == 0 ) {
             printf("CM10 is connected.\n");
	     check4poll(0,1);
             return 0;
          }
          else {
             fprintf(stderr, "Non-standard CM10A response.\n");
	     check4poll(0,1);
             return 1;
          }
       }
       bp += count;
       left -= count;
       millisleep(10);
   }
 
   if ( nread == 0 ) {    
     fprintf(stderr, "No response from CM10A\n");
   }
   else {
     fprintf(stderr, "Invalid response, %d bytes returned.\n", nread);
   }

   return 1;
}
Example #2
0
void exsock_event_hdlr( int fd, int event ) {
    int newfd;

    switch ( event ) {
    case ZS_EVT_ACCEPT_READY:
        newfd = zs_accept( fd );
        if ( newfd == -1 ) {
            perror( "New Connection Failed" );
            //zs_close( fd );
            break;
        }
        assert( !connections[ newfd ] );
        //msg_open( inconnfd, n );
        //msg_set_read( inconnfd, n );
        // pass the connection information along...
        connections[ newfd ] = (conn_data_t*) malloc( sizeof( conn_data_t ) );
        connections[ newfd ]->exlisnfd = fd;
        connections[ newfd ]->addr = *zs_get_addr( newfd );
        connections[ newfd ]->website_sockfd = -1;
        connections[ newfd ]->request_type = 0;
        connections[ newfd ]->postlen = 0;
        connections[ newfd ]->msgid = 0;
        connections[ newfd ]->is_https = zs_is_ssl( connections[ newfd ]->exlisnfd );
        connections[ newfd ]->buffer = NULL;
        connections[ newfd ]->bufferlen = 0;

        zs_set_read( newfd );
        //msg_start( inconnfd, event.data.conn.fd );
        break;
    case ZS_EVT_READ_READY:
        zs_clr_read( fd );
        exread( fd );
        break;
    case ZS_EVT_WRITE_READY:
        zs_clr_write( fd );
        msg_set_read( connections[ fd ]->website_sockfd, connections[ fd ]->msgid );
        break;
    }
}
Example #3
0
File: cm10a.c Project: mbkali/heyu
/*----------------------------------------------------------------------------+
 |  Initialize CM10A interface by uploading a dummy macro block.              |
 +----------------------------------------------------------------------------*/
int c_cm10a_init ( int argc, char *argv[] )
{
    unsigned char macrodata[50];
    unsigned char buf[3];
    unsigned int j, n, code;
    unsigned char cksum;
    extern int usage(), xwrite(), xread(), exread(), check4poll();

    int ignoret;

    if ( !(configp->device_type & DEV_CM10A) && i_am_relay != 1 ) {
       fprintf(stderr,
	 "Heyu not configured for CM10A - see man page heyu(1)\n");
       return 1;
    }

    if( argc > 2  )
       usage(E_2MANY);

#if 0  
    if ( cm10a_cable_check() == 1 ) {
       if ( i_am_relay != 1 ) 
          fprintf(stderr, "CM10A is not connected.\n");
       return 1;
    }
#endif

    macrodata[0] = 0xfb;          /* CM10A init code */
    for ( j = 1; j < 43; j++ ) {
       macrodata[j] = 0;
    }

    example[0] = example[0];  /* Keep compiler happy */

    /* For testing, use example CM10 macro data from protocol */
#if 0
    memcpy(macrodata, example, sizeof(example));
#endif


    cksum = checksum(macrodata + 1, 42);
    
    code = 0;

#if 0
    xwrite(tty, (char *) macrodata, 43);
    if ( i_am_relay )
       n = xread(tty, buf, 1, 1);
    else
       n = exread(sptty, buf, 1, 1);

    if ( n != 1 )
       code |= 0x10;
    else if ( buf[0] != cksum )
       code |= 0x01;
    
    xwrite(tty, "\0", 1);   /* WRMI */
    if ( i_am_relay ) 
       n = xread(tty, buf, 1, 1);
    else
       n = exread(sptty, buf, 1, 1);
#endif

    if ( i_am_relay ) {
       ignoret = write(tty, (char *) macrodata, 43);
       n = xread(tty, buf, 1, 2);
    }
    else {
       xwrite(tty, (char *) macrodata, 43);
       n = exread(sptty, buf, 1, 1);
    }

    if ( n != 1 )
       code |= 0x10;
    else if ( buf[0] != cksum )
       code |= 0x01;
    
    if ( i_am_relay ) {
       ignoret = write(tty, "\0", 1);   /* WRMI */
       n = xread(tty, buf, 1, 2);
    }
    else {
       xwrite(tty, "\0", 1);   /* WRMI */
       n = exread(sptty, buf, 1, 1);
    }

    if ( n != 1 )
       code |= 0x20;
    else if ( buf[0] != 0x55 )
       code |= 0x02;

    if ( argc == 2 )    
       check4poll(0,1);		/* zero means to discard data */

    if ( i_am_relay != 1 )
       (void) printf("CM10A initialized.\n");

    if ( i_am_relay )
       return code;

    return 0;
}