Example #1
0
void go_alpm_log_cb(alpm_loglevel_t level, const char *fmt, va_list arg) {
  char *s = malloc(128);
  if (s == NULL) return;
  int16_t length = vsnprintf(s, 128, fmt, arg);
  if (length > 128) {
    length = (length + 16) & ~0xf;
    s = realloc(s, length);
  }
  if (s != NULL) {
		logCallback(level, s);
		free(s);
  }
}
Example #2
0
/**
* Connect to the given device. Return error code if fails
**/
JNIEXPORT jint JNICALL Java_eu_tevs_openbm_GatewayNative_connect(JNIEnv* env, jobject obj, jstring _device, jint _cts)
{
    int loglevel = 0;
 
    // set log level and file
    if (loglevel < 0) loglevel = 0;
    if (loglevel > 4) loglevel = 4;
    Logger::instance()->setLevel((Logger::Level)loglevel);
    Logger::instance()->setCallback(logCallback);
    
    LOG_DEBUG("Connect to IBus...");
    
    // get arguments
    std::string device = env->GetStringUTFChars(_device, 0);
    int cts = static_cast<int>(_cts);
 
 #if 1 
     int fd, serial;
    fd = open("/dev/ttyS2", O_RDWR | O_NONBLOCK | O_NOCTTY);
  termios ios;
  errno = 0;
  tcgetattr(fd, &ios);
    ios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK
        | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
    ios.c_oflag &= ~OPOST;
    ios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    ios.c_cflag &= ~(CSIZE | PARENB);
    ios.c_cflag |= CS8;
    ios.c_iflag |= IGNPAR;
    ios.c_cflag |= CREAD | CLOCAL;
    errno = 0;
    tcsetattr(fd, TCSANOW, &ios);
    
    ioctl(fd, TIOCMGET, &serial);
    if (serial & TIOCM_CTS)
        logCallback("TIOCM_CTS is not set");
    else
        logCallback("TIOCM_CTS is set");
    close(fd);      
#endif
    
    // try to connect 
    try
    {
        if (Application::g_app)
        {
            Application::g_app->disconnectIBus();
            delete Application::g_app;
            Application::g_app = NULL;
        }
        
        Application::g_app = new Application(openbm::Address, openbm::Port, 0, openbm::ClientAliveTimeout);
        
        IBus::CTSType ccc = IBus::NO;
        if (cts < 0) ccc = IBus::NO;
        if (cts == 0) ccc = IBus::HARDWARE;
        if (cts > 0) ccc = IBus::GPIO;
        
        if (!Application::g_app->connectIBus(device, ccc)) return jint(-1);
        
    }catch(...)
    {
        return jint(-1);    
    }
    
    Application::g_app->setUseWebserver(false);
 
    LOG_DEBUG("Connected...");
    
    return jint(0);
}
 void onExit_STATE_6(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_6, EXIT);
 }
 void onEntry_STATE_6(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_6, ENTRY);
 }
 void onPostDo_STATE_6(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_6, POSTDO);
 }
 void onDo_STATE_5(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_5, DO);
 }
 void onExit_STATE_5(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_5, EXIT);
   m_fsm.goTo(STATE_6);
 }
 void onPreDo_STATE_4(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_4, PREDO);
 }
 void onEntry_STATE_4(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_4, ENTRY);
   m_fsm.goTo(STATE_5);
 }
 void onPostDo_STATE_3(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_3, POSTDO);
   m_fsm.goTo(STATE_4);
 }
 void onDo_STATE_2(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_2, DO);
   m_fsm.goTo(STATE_3);
 }
 void onPreDo_STATE_1(const RTC_Utils::StateHolder<int>& states)
 {
   logCallback(STATE_1, PREDO);
   m_fsm.goTo(STATE_2);
 }