Пример #1
0
int16_t
parse_cmd_onewire_list(char *cmd, char *output, uint16_t len)
{

  uint8_t firstonbus = 0;
  int16_t ret;

  if (ow_global.lock == 0)
  {
    firstonbus = 1;
#if ONEWIRE_BUSCOUNT > 1
    ow_global.bus = 0;
#endif
    OW_DEBUG_LIST("called onewire list for the first time\n");

#ifdef ONEWIRE_DS2502_SUPPORT
    /* parse optional parameters */
    while (*cmd == ' ')
      cmd++;
    switch (*cmd)
    {
      case 't':
        ow_global.list_type = OW_LIST_TYPE_TEMP_SENSOR;
        break;
      case 'e':
        ow_global.list_type = OW_LIST_TYPE_EEPROM;
        break;
      case '\0':
        ow_global.list_type = OW_LIST_TYPE_ALL;
        break;
      default:
        return ECMD_ERR_PARSE_ERROR;
    }
#endif
  }
  else
  {
    OW_DEBUG_LIST("called onewire list again\n");
    firstonbus = 0;
  }

#if defined ONEWIRE_DS2502_SUPPORT || ONEWIRE_BUSCOUNT > 1
list_next:;
#endif

#if ONEWIRE_BUSCOUNT > 1
  ret =
    ow_search_rom((uint8_t) (1 << (ow_global.bus + ONEWIRE_STARTPIN)),
                  firstonbus);
#else
  ret = ow_search_rom(ONEWIRE_BUSMASK, firstonbus);
#endif

  /* make sure only one conversion happens at a time */
  ow_global.lock = 1;

  if (ret == 1)
  {
#ifdef ONEWIRE_DS2502_SUPPORT
    if (ow_global.list_type == OW_LIST_TYPE_ALL ||
        (ow_global.list_type == OW_LIST_TYPE_TEMP_SENSOR &&
         ow_temp_sensor(&ow_global.current_rom)) ||
        (ow_global.list_type == OW_LIST_TYPE_EEPROM &&
         ow_eeprom(&ow_global.current_rom)))
    {
      /* only print device rom address if it matches the selected list type */
#endif

      OW_DEBUG_LIST("discovered device "
#if ONEWIRE_BUSCOUNT > 1
                    "%02x %02x %02x %02x %02x %02x %02x %02x on bus %d\n",
#else
                    "%02x %02x %02x %02x %02x %02x %02x %02x\n",
#endif
                    ow_global.current_rom.bytewise[0],
                    ow_global.current_rom.bytewise[1],
                    ow_global.current_rom.bytewise[2],
                    ow_global.current_rom.bytewise[3],
                    ow_global.current_rom.bytewise[4],
                    ow_global.current_rom.bytewise[5],
                    ow_global.current_rom.bytewise[6],
                    ow_global.current_rom.bytewise[7]
#if ONEWIRE_BUSCOUNT > 1
                    , ow_global.bus);
#else
        );
#endif
#ifdef ONEWIRE_NAMING_SUPPORT
      char *name = "";
      ow_sensor_t *sensor = ow_find_sensor(&ow_global.current_rom);
      if (sensor != NULL && sensor->named)
      {
        name = sensor->name;
      }
#endif
      ret = snprintf_P(output, len, PSTR("%02x%02x%02x%02x%02x%02x%02x%02x"
#ifdef ONEWIRE_NAMING_SUPPORT
                                         "\t%s"
#endif
                       ),
                       ow_global.current_rom.bytewise[0],
                       ow_global.current_rom.bytewise[1],
                       ow_global.current_rom.bytewise[2],
                       ow_global.current_rom.bytewise[3],
                       ow_global.current_rom.bytewise[4],
                       ow_global.current_rom.bytewise[5],
                       ow_global.current_rom.bytewise[6],
                       ow_global.current_rom.bytewise[7]
#ifdef ONEWIRE_NAMING_SUPPORT
                       , name
#endif
        );

      OW_DEBUG_LIST("generated %d bytes\n", ret);

      /* set return value that the parser has to be called again */
      if (ret > 0)
        ret = ECMD_AGAIN(ret);

      OW_DEBUG_LIST("returning %d\n", ret);
      return ECMD_FINAL(ret);

#ifdef ONEWIRE_DS2502_SUPPORT
    }
Пример #2
0
int16_t
parse_cmd_onewire_list(char *cmd, char *output, uint16_t len)
{
#ifdef ONEWIRE_DS2502_SUPPORT
  int8_t list_type;
  while (*cmd == ' ')
    cmd++;
  switch (*cmd)
  {
    case 't':
      list_type = OW_LIST_TYPE_TEMP_SENSOR;
      break;
    case 'e':
      list_type = OW_LIST_TYPE_EEPROM;
      break;
    case '\0':
      list_type = OW_LIST_TYPE_ALL;
      break;
    default:
      return ECMD_ERR_PARSE_ERROR;
  }
  cmd++;                        /* for static bytes */
#endif
  /* trick: use bytes on cmd as "connection specific static variables" */
  if (cmd[0] != ECMD_STATE_MAGIC)       /* indicator flag: real invocation:  0 */
  {
    cmd[0] = ECMD_STATE_MAGIC;  /* continuing call: 23 */
    cmd[1] = 0;                 /* counter for sensors in list */
  }
  uint8_t i = cmd[1];
  /* This is a special case: the while loop below printed a sensor which was
   * last in the list, so we still need to send an 'OK' after the sensor id */
  if (i >= OW_SENSORS_COUNT)
    return ECMD_FINAL_OK;

  int16_t ret = 0;
  do
  {
    if (ow_sensors[i].ow_rom_code.raw != 0)
    {
#ifdef ONEWIRE_DS2502_SUPPORT
      if (list_type == OW_LIST_TYPE_ALL ||
          (list_type == OW_LIST_TYPE_TEMP_SENSOR &&
           ow_temp_sensor(&ow_sensors[i].ow_rom_code)) ||
          (list_type == OW_LIST_TYPE_EEPROM &&
           ow_eeprom(&ow_sensors[i].ow_rom_code)))
      {
#endif
#ifdef ONEWIRE_NAMING_SUPPORT
        const char *name = "";
        if (ow_sensors[i].named)
          name = ow_sensors[i].name;

#endif
#ifdef ONEWIRE_ECMD_LIST_VALUES_SUPPORT
        char temperature[7];
        itoa_fixedpoint(ow_sensors[i].temp.val,
                        ow_sensors[i].temp.twodigits + 1, temperature,
                        sizeof(temperature));
#endif
        ret = snprintf_P(output, len, PSTR("%02x%02x%02x%02x%02x%02x%02x%02x"
#ifdef ONEWIRE_NAMING_SUPPORT
                                           "\t%s"
#endif
#ifdef ONEWIRE_ECMD_LIST_VALUES_SUPPORT
                                           "\t%s"
#endif
#ifdef ONEWIRE_ECMD_LIST_POWER_SUPPORT
                                           "\t%d"
#endif
                         ), ow_sensors[i].ow_rom_code.bytewise[0],
                         ow_sensors[i].ow_rom_code.bytewise[1],
                         ow_sensors[i].ow_rom_code.bytewise[2],
                         ow_sensors[i].ow_rom_code.bytewise[3],
                         ow_sensors[i].ow_rom_code.bytewise[4],
                         ow_sensors[i].ow_rom_code.bytewise[5],
                         ow_sensors[i].ow_rom_code.bytewise[6],
                         ow_sensors[i].ow_rom_code.bytewise[7]
#ifdef ONEWIRE_NAMING_SUPPORT
                         , name
#endif
#ifdef ONEWIRE_ECMD_LIST_VALUES_SUPPORT
                         , temperature
#endif
#ifdef ONEWIRE_ECMD_LIST_POWER_SUPPORT
                         , ow_sensors[i].power
#endif
          );
#ifdef ONEWIRE_DS2502_SUPPORT
      }
#endif
    }
    i++;
  }
  while (ret == 0 && i < OW_SENSORS_COUNT);
  /* The while loop exited either because a sensor has been found or because
   * there is no sensor left, let's check for that */
  if (ret == 0)
  {
    /* => i has reached OW_SENSORS_COUNT */
    return ECMD_FINAL_OK;
  }
  /* else, ret is != 0 which means a sensor has been found and this functions
   * has to be called again to prevent a buffer overflow. save i to cmd[1] */
  cmd[1] = i;

  return ECMD_AGAIN(ret);
}
Пример #3
0
int16_t parse_cmd_onewire_list(char *cmd, char *output, uint16_t len)
{
    int8_t list_type;
    while (*cmd == ' ')
        cmd++;
    switch (*cmd) {
    case 't':
        list_type = OW_LIST_TYPE_TEMP_SENSOR;
        break;
    case 'e':
        list_type = OW_LIST_TYPE_EEPROM;
        break;
    case '\0':
        list_type = OW_LIST_TYPE_ALL;
        break;
    default:
        return ECMD_ERR_PARSE_ERROR;
    }
    static uint8_t i=0;
    if(i>=OW_SENSORS_COUNT)
    {
        i=0;
        return  ECMD_FINAL_OK;
    }
    int16_t ret=0;
    do
    {
        if(ow_sensors[i].ow_rom_code.raw != 0)
        {
            if ((list_type == OW_LIST_TYPE_ALL) || (list_type == OW_LIST_TYPE_TEMP_SENSOR && ow_temp_sensor(&ow_sensors[i].ow_rom_code)) || (list_type == OW_LIST_TYPE_EEPROM && ow_eeprom(&ow_sensors[i].ow_rom_code))) {
                ret = snprintf_P(output, len,
                                 PSTR("%02x%02x%02x%02x%02x%02x%02x%02x"),
                                 ow_sensors[i].ow_rom_code.bytewise[0],
                                 ow_sensors[i].ow_rom_code.bytewise[1],
                                 ow_sensors[i].ow_rom_code.bytewise[2],
                                 ow_sensors[i].ow_rom_code.bytewise[3],
                                 ow_sensors[i].ow_rom_code.bytewise[4],
                                 ow_sensors[i].ow_rom_code.bytewise[5],
                                 ow_sensors[i].ow_rom_code.bytewise[6],
                                 ow_sensors[i].ow_rom_code.bytewise[7]
                                );
            }
        }
        i++;
    } while(ret == 0 && i<OW_SENSORS_COUNT);
    return	ECMD_AGAIN(ret);
}