Beispiel #1
0
int main() {
    struct sOneWireDevice *devices, *device;
    pthread_t poll_thread;
    struct timeval tick;
    unsigned long last_tick;

#ifdef DEBUG
    fprintf(stderr, "Debug mode\r\n");
#endif

    log_entry("Starting up", LOG_NO_EXIT);
    KEEP_RUNNING = 1;
    zExitCode = 0;

    signal(SIGINT, intHandler);
    initDB();
    initGPIO();

    if (pthread_create(&poll_thread, NULL, cPoll, NULL)) {
        log_entry("Error creating thread", EXIT_FAILURE);
    }

    gettimeofday(&tick, NULL);
    last_tick = tick.tv_sec;

    devices = list_devices();

    while (KEEP_RUNNING == 1) {
        gettimeofday(&tick, NULL);
        if ((tick.tv_sec - last_tick) >= LOG_INTERVAL) {
            last_tick = tick.tv_sec;

            device = devices;
            while (device != NULL) {
                if (updateValue(device) != NULL)
                    log_device(device);
                device = device->next;
            }

            power = 0;
            elapsedTicks = 0;
        }
        sleep(1);
    }

    if (pthread_join(poll_thread, NULL)) {
        log_entry("Error joining thread\n", EXIT_FAILURE);
    }


    device = devices;
    while (device != NULL) {
        devices = device->next;
        free(device);
        device = devices;
    }
    restoreGPIO();
    log_entry("Cleanup finished, exiting", LOG_NO_EXIT);
    return (0);
}
int parse_data(char *buf)
{
        int i,data,rtn,found,act;
        char address[20];
        char port_num[5];
        char port_data[5];
        char response[40];
        time_t tt,tloc;
        sscanf(buf,"%s\t%s\t%s",address,port_num,port_data);
        if (!Daemon) printf("parse_data: looking for device %s\t%s\t%s\n\r",address,port_num,port_data);
	found = 0;
        for (i=0;i<NUM_DEVICES;i++)
        {
                if (T->device[i].type[0] == 'R')        //raspberry device
                {
                        if (T->device[i].offset[0] == 'i')      //R device of type in
                        {
                                rtn = strcmp(T->device[i].ip_address,address);  //check ip_address
                                if (rtn == 0)
                                {
                                        //if (!Daemon) printf ("Found  match %s at %d\n",T->device[i].name,i);
                                        if (T->device[i].addr[0] == port_num[0])        //ports numbers match
                                        {
						found = 1;
                                                if (!Daemon) printf("parse_data: found a match %s updating with act = %c\n",T->device[i].name,port_data[0]);
                                                if (port_data[0] == '0') act = 0;
                                                if (port_data[0] == '1') act = 1;
                                                rtn = log_device(i,act);
                                        }
                                }
                        }
                }
        }
	if (!Daemon) 
	{
		if (found == 0)
		{
			printf ("parse_data: counld not match %s with stored data\n",buf);
		}
	}
        return(0);
}
Beispiel #3
0
int main()
{
	rcp_device *devs;
	int num;

	tlog_init(TLOG_MODE_STDERR, TLOG_DEBUG, NULL);

	autodetect(&devs, &num);

	TL_INFO("%d device%s detected", num, num>1?"s":"");
	for (int i=0; i<num; i++)
	{
		log_device(TLOG_INFO, &devs[i]);
		TL_INFO("------------------------");
	}

	free(devs);


	return 0;
}
Beispiel #4
0
int cubeb_enumerate_devices(cubeb * context,
                            cubeb_device_type devtype,
                            cubeb_device_collection * collection)
{
  int rv;
  if ((devtype & (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT)) == 0)
    return CUBEB_ERROR_INVALID_PARAMETER;
  if (collection == NULL)
    return CUBEB_ERROR_INVALID_PARAMETER;
  if (!context->ops->enumerate_devices)
    return CUBEB_ERROR_NOT_SUPPORTED;

  rv = context->ops->enumerate_devices(context, devtype, collection);

  if (g_cubeb_log_callback) {
    for (size_t i = 0; i < collection->count; i++) {
      log_device(&collection->device[i]);
    }
  }

  return rv;
}