Esempio n. 1
0
void
eeprom_init (void)
{
  uip_ipaddr_t ip;
  (void) ip;			/* Keep GCC quiet. */

#ifdef ETHERNET_SUPPORT
  eeprom_save_P (mac, PSTR (CONF_ETHERSEX_MAC), 6);
#endif

#if (defined(IPV4_SUPPORT) && !defined(BOOTP_SUPPORT) && !defined(DHCP_SUPPORT)) || defined(IPV6_STATIC_SUPPORT)
  set_CONF_ETHERSEX_IP (&ip);
  eeprom_save (ip, &ip, IPADDR_LEN);
#ifdef ETHERNET_SUPPORT
  set_CONF_ETHERSEX_GATEWAY (&ip);
  eeprom_save (gateway, &ip, IPADDR_LEN);
#endif

#ifdef IPV4_SUPPORT
  set_CONF_ETHERSEX_IP4_NETMASK (&ip);
  eeprom_save (netmask, &ip, IPADDR_LEN);
#endif
#endif

#ifdef DNS_SUPPORT
  set_CONF_DNS_SERVER (&ip);
  eeprom_save (dns_server, &ip, IPADDR_LEN);
#endif

#ifdef PAM_SINGLE_USER_EEPROM_SUPPORT
  /* Copy the httpd's password. */
  eeprom_save_P (pam_username, PSTR (PAM_SINGLE_USERNAME), 16);
  eeprom_save_P (pam_password, PSTR (PAM_SINGLE_PASSWORD), 16);
#endif

#ifdef ADC_VOLTAGE_SUPPORT
  eeprom_save_int (adc_vref, ADC_REF_VOLTAGE);
#endif

#ifdef KTY_SUPPORT
  eeprom_save_char (kty_calibration, 0);
#endif

#ifdef MQ2_SUPPORT
  eeprom_save_long (mq2_calibration, 0);
#endif

#ifdef MQ135_SUPPORT
  eeprom_save_long (mq135_calibration, 0);
#endif

#ifdef STELLA_EEPROM
  uint8_t stella_temp[10] = { 0 };
  eeprom_save (stella_channel_values, stella_temp, 10);
#endif

#ifdef DMX_FXSLOT_SUPPORT
  struct fxslot_struct_stripped fxslots_temp[DMX_FXSLOT_AMOUNT] = { {0,0,0,0,0,0,0} };
  eeprom_save (dmx_fxslots, fxslots_temp, DMX_FXSLOT_AMOUNT*sizeof(struct fxslot_struct_stripped));
#endif

#ifdef ONEWIRE_NAMING_SUPPORT
  ow_name_t temp_name;
  memset(&temp_name, 0, sizeof(ow_name_t));
  for (int8_t i = 0; i < OW_SENSORS_COUNT; i++)
  {
    eeprom_save(ow_names[i], &temp_name, sizeof(ow_name_t));
  }
#endif

#ifdef SMS77_EEPROM_SUPPORT
  eeprom_save_P (sms77_username, PSTR (CONF_SMS77_USER), SMS77_VALUESIZE);
  eeprom_save_P (sms77_password, PSTR (CONF_SMS77_PASS), SMS77_VALUESIZE);
  eeprom_save_P (sms77_receiver, PSTR (CONF_SMS77_TO), SMS77_VALUESIZE);
  eeprom_save_P (sms77_type, PSTR (CONF_SMS77_TYPE), SMS77_VALUESIZE);
#endif

#ifdef JABBER_EEPROM_SUPPORT
  eeprom_save_P (jabber_username, PSTR (CONF_JABBER_USERNAME),
		 JABBER_VALUESIZE);
  eeprom_save_P (jabber_password, PSTR (CONF_JABBER_PASSWORD),
		 JABBER_VALUESIZE);
  eeprom_save_P (jabber_resource, PSTR (CONF_JABBER_RESOURCE),
		 JABBER_VALUESIZE);
  eeprom_save_P (jabber_hostname, PSTR (CONF_JABBER_HOSTNAME),
		 JABBER_VALUESIZE);
#endif

#ifdef MOTD_SUPPORT
  eeprom_save_P (motd_text, PSTR (CONF_MOTD_DEFAULT), MOTD_VALUESIZE);
#endif

#ifdef CRON_EEPROM_SUPPORT
  uint8_t count = 0;
  eeprom_save_offset(crontab, 0, &count, sizeof(count));
#endif

#ifdef TANKLEVEL_SUPPORT
  tanklevel_params_t tanklevel_temp = {
    .sensor_offset = TANKLEVEL_SENSOR_OFFSET,
    .med_density = TANKLEVEL_MED_DENSITY,
    .ltr_per_m = TANKLEVEL_LTR_PER_M,
    .ltr_full = TANKLEVEL_LTR_FULL,
    .raise_time = TANKLEVEL_RAISE_TIME,
    .hold_time = TANKLEVEL_HOLD_TIME
  };
  eeprom_save (tanklevel_params, &tanklevel_temp, sizeof(tanklevel_params_t));
#endif
  eeprom_update_chksum ();
}
Esempio n. 2
0
int16_t
cron_save()
{
#ifdef CRON_VFS_SUPPORT
  struct vfs_file_handle_t *file;
  vfs_size_t filesize;
  vfs_size_t tempsize;
#else
  uint16_t filesize;
  uint16_t tempsize;
#endif
  uint8_t count = 0;
  uint8_t saved_count = 0;

#ifdef DEBUG_CRON
  debug_printf("cron: saving jobs\n");
#endif

#ifdef CRON_VFS_SUPPORT
  file = vfs_create(CRON_FILENAME);

  if (file == NULL)
  {
#ifdef DEBUG_CRON
    debug_printf("cron: can't create file\n");
#endif
    return -1;
  }
#endif

  // placeholder
  filesize = sizeof(count);
  struct cron_event_linkedlist *job = head;
  while (job)
  {
    if (job->event.persistent)
    {
      count++;
      filesize += sizeof(struct cron_event) + job->event.extrasize;
    }
    job = job->next;
  }

#ifdef CRON_VFS_SUPPORT
  if (vfs_write(file, &count, sizeof(count)) != sizeof(count))
    return cron_write_error(file);
#else
  if (filesize >= CRON_EEPROM_SIZE)
    return -1;
  eeprom_save_offset(crontab, 0, &count, sizeof(uint8_t));
#endif

  filesize = sizeof(count);
  job = head;
  while (job)
  {
    if (job->event.persistent)
    {
#ifdef DEBUG_CRON
      debug_printf("cron: writing job %i\n", count);
#endif

      tempsize = sizeof(struct cron_event) + job->event.extrasize;
#ifdef DEBUG_CRON
      debug_printf
        ("cron: try to allocate size of %i consist of struct %i and extrasize %i!\n",
         tempsize, sizeof(struct cron_event), job->event.extrasize);
#endif

#ifdef CRON_VFS_SUPPORT
      if (vfs_write(file, &job->event, tempsize) != tempsize)
        return cron_write_error(file);
#else
      eeprom_save_offset(crontab, filesize, &job->event, tempsize);
#endif
      filesize += tempsize;
      saved_count++;
    }
    job = job->next;
    // reset watchdog only if it seems that everything is going right
    if (saved_count <= count)
    {
      wdt_kick();
    }
  }
#ifdef DEBUG_CRON
  debug_printf("cron: all jobs written with total size of %i\n", filesize);
#endif

#ifdef CRON_VFS_SUPPORT
  vfs_truncate(file, filesize);
  vfs_close(file);
#else
  eeprom_update_chksum();
#endif
  return saved_count;
}