Ejemplo n.º 1
0
FIO_status currentState_save(void){
	FIL fff; // File handler
	FIO_status res = FIO_OK;
	if (SDFS_open(&fff, "0:/" SETTING_NAME, F_WR_CLEAR) != SDFS_OK){
		return FIO_FILE_CREATE_ERROR;
	}
	json_write_string(0,"{",&fff);
	json_write_value(1, ATTR_SET_CALIBR,Current_state.calibration_name,1,&fff);
	json_write_value(1, ATTR_SET_PRESET,Current_state.preset_name,0,&fff);
	json_write_string(0,"}",&fff);
	if (SDFS_close(&fff)!= SDFS_OK)
		return FIO_FILE_CLOSE_ERROR;
	return res;
}
Ejemplo n.º 2
0
void message_bus_write_json(yajl_gen g, void *context) {
    state *state = context;

    yajl_val output_values = state_get_json(state, STATE_OUTPUT_VALUES);

    assert(YAJL_IS_ARRAY(output_values));

    yajl_gen_map_open(g);

    int len = YAJL_GET_ARRAY(output_values)->len;
    for (int i = 0; i < len; i++) {
        char *k = YAJL_GET_STRING(YAJL_GET_ARRAY(output_values)->values[i]);

        state_value_type type = state_get_value_type(state, k);

        yajl_gen_string(g, (unsigned char *)k, strlen(k));

        float float_value;
        int int_value;
        yajl_val json_value;
        switch (type) {
            case state_value_type_float:
                float_value = state_get_float(state, k);
                yajl_gen_double(g, (double)float_value);
                break;
            case state_value_type_int:
                int_value = state_get_int(state, k);
                yajl_gen_integer(g, int_value);
                break;
            case state_value_type_json:
                json_value = state_get_json(state, k);
                json_write_value(g, json_value);
                break;
            default:
                assert(0);
                break;
        }
    }

    yajl_gen_map_close(g);
}