Exemplo n.º 1
0
int setPower(bus_t bus, int state, char *msg)
{
    gettimeofday(&buses[bus].power_change_time, NULL);
    buses[bus].power_state = (state == -1) ? 0 : state;
    /* buses[bus].power_state = state; */
    strcpy(buses[bus].power_msg, msg);
    buses[bus].power_changed = (state == -1) ? 0 : 1;
    /* buses[bus].power_changed = 1; */
    /* Resume thread to transmit power change */
    resume_bus_thread(bus);
    return SRCP_OK;
}
Exemplo n.º 2
0
/* Uebernehme die neuen Angaben fuer die Weiche, einige wenige Pruefungen */
int enqueueGA(bus_t busnumber, int addr, int port, int action,
              long int activetime)
{
    int result;
    struct timeval akt_time;
    int number_ga = get_number_ga(busnumber);

    if ((addr > 0) && (addr <= number_ga)) {
        if (queue_isfull(busnumber)) {
            syslog_bus(busnumber, DBG_WARN, "GA Command Queue full");
            return SRCP_TEMPORARILYPROHIBITED;
        }

        result = pthread_mutex_lock(&queue_mutex[busnumber]);
        if (result != 0) {
            syslog_bus(busnumber, DBG_ERROR,
                       "pthread_mutex_lock() failed: %s (errno = %d).",
                       strerror(result), result);
        }

        queue[busnumber][in[busnumber]].protocol =
                ga[busnumber].gastate[addr].protocol;
        queue[busnumber][in[busnumber]].type =
                ga[busnumber].gastate[addr].type;
        queue[busnumber][in[busnumber]].action = action;
        queue[busnumber][in[busnumber]].port = port;
        queue[busnumber][in[busnumber]].activetime = activetime;
        gettimeofday(&akt_time, NULL);
        queue[busnumber][in[busnumber]].tv[port] = akt_time;
        queue[busnumber][in[busnumber]].id = addr;

        in[busnumber]++;
        if (in[busnumber] == QUEUELEN)
            in[busnumber] = 0;

        result = pthread_mutex_unlock(&queue_mutex[busnumber]);
        if (result != 0) {
            syslog_bus(busnumber, DBG_ERROR,
                       "pthread_mutex_unlock() failed: %s (errno = %d).",
                       strerror(result), result);
        }
        /* Restart thread to send GL command */
        resume_bus_thread(busnumber);
    }
    else {
        return SRCP_WRONGVALUE;
    }
    return SRCP_OK;
}