void *canbus_awsiotlogger_thread(void *ptr) {

  syslog(LOG_DEBUG, "canbus_awsiotlogger_thread: running");

  canbus_logger *pLogger = (canbus_logger *)ptr;

  int can_frame_len = sizeof(struct can_frame);
  struct can_frame frame;
  memset(&frame, 0, can_frame_len);

  int data_len = can_frame_len + 25;
  char data[data_len];
  memset(data, 0, data_len);

  while(canbus_isconnected(pLogger->canbus) && canbus_read(pLogger->canbus, &frame) > 0 && pLogger->isrunning) {

    memset(data, 0, data_len);
    canbus_framecpy(&frame, data);

    if(frame.can_id & CAN_ERR_FLAG) {
      syslog(LOG_ERR, "canbus_awsiotlogger_thread: CAN ERROR: %s", data);
      continue;
    }

    awsiot_client_publish(iotlogger, awsiotlogger_topic, data);
  }

  syslog(LOG_DEBUG, "canbus_awsiotlogger_thread: stopping");
  pLogger->canbus_thread_state = CANBUS_LOGTHREAD_STOPPED;
  canbus_iotlogger_close();

  return NULL;
}
Exemple #2
0
static int
canbus_probe(device_t dev)
{
	u_int8_t flag;

	set_ioresource(dev);
	if(alloc_ioresource(dev))
		return (ENXIO);
	flag = canbus_read(dev, NULL, CANBE_SOUND_INTR_ADDR);
	release_ioresource(dev);

	if (bootverbose)
		device_printf(dev, "probe flag = 0x%x\n", flag);

	if (flag != CANBE_SOUND_INTR_VAL0 && flag != CANBE_SOUND_INTR_VAL1 &&
	    flag != CANBE_SOUND_INTR_VAL2 && flag != CANBE_SOUND_INTR_VAL3) {
		device_printf(dev, "Device Not Found\n");
		return (ENXIO);
	}
	device_set_desc(dev, "CanBe I/O Bus");

	return (0);	
}