Skip to content
Snippets Groups Projects
Select Git revision
  • 4d7717b1f474080eae8f9798e4ff329ef3576f15
  • master default protected
  • Stormwind
  • patch-1
  • schneider/bsec
  • dx/meh-bdf-to-stm
  • dx/somewhat-more-dynamic-config
  • rahix/proper-sleep
  • dx/flatten-config-module
  • genofire/ble-follow-py
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

build_image

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    config.c 12.75 KiB
    #include "modules/log.h"
    #include "modules/config.h"
    #include "modules/filesystem.h"
    #include "epicardium.h"
    
    #include <assert.h>
    #include <stdbool.h>
    #include <ctype.h>
    #include <string.h>
    #include <strings.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <stddef.h>
    #include <stdio.h>
    
    #define MAX_LINE_LENGTH 80
    #define KEYS_PER_BLOCK 16
    #define KEY_LENGTH 16
    #define NOT_INT_MAGIC ((int)0x80000000)
    
    // one key-value pair representing a line in the config
    typedef struct {
    	char key[KEY_LENGTH];
    
    	// the value in the config file, if it's an integer.
    	// for strings it's set to NOT_INT_MAGIC
    	int value;
    
    	// the byte offset in the config file to read the value string
    	size_t value_offset;
    } config_slot;
    
    // a block of 16 config slots
    // if more are needed, this becomes a linked list
    typedef struct {
    	config_slot slots[KEYS_PER_BLOCK];
    	void *next;
    } config_block;
    
    static config_block *config_data = NULL;
    
    // returns the config slot for a key name
    static config_slot *find_config_slot(const char *key)
    {
    	config_block *current = config_data;
    
    	while (current) {
    		for (int i = 0; i < KEYS_PER_BLOCK; i++) {
    			config_slot *k = &current->slots[i];
    
    			if (strcmp(k->key, key) == 0) {
    				// found what we're looking for
    				return k;
    
    			} else if (*k->key == '\0') {
    				// found the first empty key
    				return NULL;
    			}
    		}
    		current = current->next;
    	}
    
    	return NULL;
    }
    
    // returns the next available config slot, or allocates a new block if needed
    static config_slot *allocate_config_slot()
    {
    	config_block *current;