Exemplo n.º 1
0
void handleEvent(THREAD_ARG *arg)
{
    BYTE i=0;

    struct event_base* base = event_base_new();
    if (!base)
    {
        fprintf(stderr, "Could not initialize libevent!\n");
        exit(1);
    }
    eventarg.base = base;
    eventarg.UART0_fd = openUart("uart0");
    eventarg.CAN0_fd  = openCAN("can0");
    eventarg.output_socket = NULL;
    eventarg.GUIPipe_fd  = arg->GUIPipe_fd;
    eventarg.CTRLPipe_fd  = arg->CTRLPipe_fd;
    eventarg.UARTPipe_fd = arg->UARTPipe_fd;
    eventarg.lock = arg->lock;
    eventarg.cond = arg->cond;
    setEvent(base);
    for(i=0; i<MAX_CHANNEL; i++)
    {
        eventarg.timer_arg[i].channel = i+1;
        eventarg.timer_arg[i].channelTimer = event_new(base, -1, EV_TIMEOUT,
                                             cbChannelTimer, (void*)(&eventarg.timer_arg[i]));
    }
    event_base_dispatch(base);
}
Exemplo n.º 2
0
/*********************************************************************
 * @fn      Process_Command
 *
 * @brief   Process the network incoming command message.
 *
 * @param   msgBuf, len
 *
 * @return  none
 */
void Process_Command(cmd_msg_t* command/*uint8 *msgBuf*/, uint16 len) 
{
  //  uint32 cmdData;
  uint16 option = (command->option[0])<<8 + command->option[1];
  uint8  baudrate = 0x02;
  uint8 result = 0;
  unsigned char buf[1];
  
  if(len < 7) // error
  {
    return;
  }
  
  if (option==0xE101) //open Uart 0
  {
    baudrate = command->controlmsg[0];
    result = openUart(0, baudrate); // open uart 0
    buf[0] = result; // send result to BS
    App_SendSample(buf, 1, option);
  }
  else if (option==0xE102)
  {
    baudrate = command->controlmsg[0];
    result = openUart(1, baudrate); // open uart 1
    buf[0] = result;
    App_SendSample(buf, 1, option);
  }
  
  else if (option==0xE201)
  {    
    writeUart(0, command);    
  }
  else if (option==0xE202)
  {
    writeUart(1, command);
  } 
  else if (option>=0xC000 && option <=0xC0FF) // set IO
  {
    Set_IO(command);
  }
  
}
Exemplo n.º 3
0
JNIEXPORT jint JNICALL
Java_firich_com_firichsdk_SerialPort_openSerialPortSmartCard(JNIEnv *env, jobject instance, jstring path_,
                                                             jint baudrate) {
    const char *path = (*env)->GetStringUTFChars(env, path_, 0); //Android Java String convert to C char*

    struct termios tio;
    memset(&tio,0,sizeof(tio));

    int uart_file = -1;
    fd_set set;

    char lrc;
    char buffer[50];
    int recv_lenth;

    //return 0;

    uart_file = openUart(path);

    if (!setUart(uart_file,3))
    {
        closeUart(uart_file);
        return -1;
    }


    msleep(1000);

    //system ("stty -F /dev/ttyUSB2 cs8 crtscts parenb -parodd -cstopb");
    //system ("stty -F /dev/ttyUSB2 speed 9600 > /dev/null");

    //uart_file = openUart();

    FD_ZERO(&set); /* clear the set */ //Initializes the file descriptor set fdset to have zero bits for all file descriptors.
    FD_SET(uart_file, &set); /* add our file descriptor to the set */
    return uart_file;
}
Exemplo n.º 4
0
JNIEXPORT jint JNICALL
Java_firich_com_firichsdk_SerialPort_openSerialPortSmartCardTest(JNIEnv *env, jobject instance, jstring path_,
                                                    jint baudrate) {
    const char *path = (*env)->GetStringUTFChars(env, path_, 0); //Android Java String convert to C char*

    struct termios tio;
    memset(&tio,0,sizeof(tio));

    /*
     *
     *
     */
    int uart_file = -1;
    fd_set set;
    char version_msg[5] = {0x02,0x01,0x00,0x00,0x03};
    char activation_msg[5] = {0x02,0x10,0x00,0x00,0x12};
    char deactivation_msg[5] = {0x02,0x20,0x00,0x00,0x22};
    char lrc;
    char buffer[50];
    int recv_lenth;

    //return 0;

    uart_file = openUart(path);

    if (!setUart(uart_file,3))
    {
        closeUart(uart_file);
        return -1;
    }


    //closeUart(uart_file);
    msleep(1000);

    //system ("stty -F /dev/ttyUSB2 cs8 crtscts parenb -parodd -cstopb");
    //system ("stty -F /dev/ttyUSB2 speed 9600 > /dev/null");

    //uart_file = openUart();

    FD_ZERO(&set); /* clear the set */ //Initializes the file descriptor set fdset to have zero bits for all file descriptors.
    FD_SET(uart_file, &set); /* add our file descriptor to the set */

    //recv_lenth = sendAndRecvMesgUart(uart_file,version_msg, sizeof(version_msg),buffer,sizeof(buffer));

    //memcpy((void*)data,buffer,recv_lenth);

    //closeUart(uart_file); //debug
    return  uart_file; //debug

    lrc = calulateLRC(&buffer[0], recv_lenth-1);
    printf("LRC of Version = 0x%x\n", lrc);


    closeUart(uart_file);
/*
    if(0 != memcmp(&lrc, &buffer[rec_lenth-1],1))
    {
        printf("Get Version LRC error\n");
        return 0;
    }
    else
    {
        return (int)recv_lenth;
    }
*/
    //return lrc; //  C char convert to Android Java String
/*
 *
 * uart_file = openUart();

    setUart(uart_file,3);	//3 for 9600

    closeUart(uart_file);
    msleep(1000);
 */



}