full version of beta including resources and binary
This commit is contained in:
76
include/mightywatt.h
Normal file
76
include/mightywatt.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef MIGHTYWATT_H
|
||||
#define MIGHTYWATT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MW_FW_VERSION_MAX 31
|
||||
#define MW_BOARD_REV_MAX 31
|
||||
|
||||
typedef struct mw_device mw_device;
|
||||
|
||||
typedef enum {
|
||||
MW_MODE_CURRENT = 0,
|
||||
MW_MODE_VOLTAGE = 1,
|
||||
MW_MODE_POWER = 2,
|
||||
MW_MODE_RESISTANCE = 3,
|
||||
MW_MODE_VOLTAGE_INVERTED = 4,
|
||||
} mw_mode;
|
||||
|
||||
enum {
|
||||
MW_STATUS_READY = 0,
|
||||
MW_STATUS_CURRENT_OVERLOAD = 1 << 0,
|
||||
MW_STATUS_VOLTAGE_OVERLOAD = 1 << 1,
|
||||
MW_STATUS_POWER_OVERLOAD = 1 << 2,
|
||||
MW_STATUS_OVERHEAT = 1 << 3,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char firmware_version[MW_FW_VERSION_MAX + 1];
|
||||
char board_revision[MW_BOARD_REV_MAX + 1];
|
||||
uint32_t max_current_dac_ma;
|
||||
uint32_t max_current_adc_ma;
|
||||
uint32_t max_voltage_dac_mv;
|
||||
uint32_t max_voltage_adc_mv;
|
||||
uint32_t max_power_mw;
|
||||
uint32_t dvm_input_resistance_ohm;
|
||||
uint32_t temperature_threshold_c;
|
||||
} mw_capabilities;
|
||||
|
||||
typedef struct {
|
||||
uint16_t current_ma;
|
||||
uint16_t voltage_mv;
|
||||
uint8_t temperature_c;
|
||||
bool remote;
|
||||
uint8_t status;
|
||||
} mw_report;
|
||||
|
||||
const char *mw_last_error(const mw_device *dev);
|
||||
int mw_open(mw_device **out_dev, const char *port_path, int settle_ms);
|
||||
void mw_close(mw_device *dev);
|
||||
|
||||
int mw_identify(mw_device *dev);
|
||||
int mw_query_capabilities(mw_device *dev, mw_capabilities *caps);
|
||||
int mw_get_report(mw_device *dev, mw_report *report);
|
||||
int mw_set(mw_device *dev, mw_mode mode, uint32_t milli_units, mw_report *report);
|
||||
int mw_set_remote(mw_device *dev, bool enable, mw_report *report);
|
||||
int mw_set_series_resistance(mw_device *dev, uint16_t milliohm, mw_report *report);
|
||||
int mw_get_series_resistance(mw_device *dev, uint16_t *milliohm);
|
||||
|
||||
size_t mw_status_string(uint8_t status, char *buffer, size_t buffer_size);
|
||||
const char *mw_mode_name(mw_mode mode);
|
||||
uint32_t mw_report_power_mw(const mw_report *report);
|
||||
uint32_t mw_capability_limit_for_mode(const mw_capabilities *caps, mw_mode mode);
|
||||
int mw_validate_target(const mw_capabilities *caps, mw_mode mode, uint32_t milli_units,
|
||||
char *buffer, size_t buffer_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
45
include/mightywatt_app.h
Normal file
45
include/mightywatt_app.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef MIGHTYWATT_APP_H
|
||||
#define MIGHTYWATT_APP_H
|
||||
|
||||
#include "mightywatt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct mw_app mw_app;
|
||||
|
||||
typedef struct {
|
||||
bool capabilities_valid;
|
||||
mw_capabilities capabilities;
|
||||
bool report_valid;
|
||||
mw_report last_report;
|
||||
bool target_valid;
|
||||
mw_mode target_mode;
|
||||
uint32_t target_milli_units;
|
||||
bool restore_target_valid;
|
||||
mw_mode restore_target_mode;
|
||||
uint32_t restore_target_milli_units;
|
||||
} mw_app_state;
|
||||
|
||||
int mw_app_open(mw_app **out_app, const char *port_path, int settle_ms);
|
||||
void mw_app_close(mw_app *app);
|
||||
const char *mw_app_last_error(const mw_app *app);
|
||||
|
||||
int mw_app_refresh_capabilities(mw_app *app, mw_capabilities *out_caps);
|
||||
int mw_app_get_report(mw_app *app, mw_report *out_report);
|
||||
int mw_app_set_target(mw_app *app, mw_mode mode, uint32_t milli_units, mw_report *out_report);
|
||||
int mw_app_load_off(mw_app *app, mw_report *out_report);
|
||||
int mw_app_load_on(mw_app *app, mw_mode mode, uint32_t milli_units, mw_report *out_report);
|
||||
int mw_app_restore_target(mw_app *app, mw_report *out_report);
|
||||
int mw_app_safe(mw_app *app, mw_report *out_report);
|
||||
int mw_app_set_remote(mw_app *app, bool enable, mw_report *out_report);
|
||||
int mw_app_get_series_resistance(mw_app *app, uint16_t *milliohm);
|
||||
int mw_app_set_series_resistance(mw_app *app, uint16_t milliohm, mw_report *out_report);
|
||||
int mw_app_get_state(const mw_app *app, mw_app_state *out_state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
113
include/mightywatt_controller.h
Normal file
113
include/mightywatt_controller.h
Normal file
@ -0,0 +1,113 @@
|
||||
#ifndef MIGHTYWATT_CONTROLLER_H
|
||||
#define MIGHTYWATT_CONTROLLER_H
|
||||
|
||||
#include "mightywatt_app.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MW_CONTROLLER_PORT_PATH_MAX 255
|
||||
#define MW_CONTROLLER_ERROR_MAX 255
|
||||
|
||||
typedef struct mw_controller mw_controller;
|
||||
|
||||
typedef enum {
|
||||
MW_CONTROLLER_STOPPED = 0,
|
||||
MW_CONTROLLER_CONNECTING = 1,
|
||||
MW_CONTROLLER_CONNECTED = 2,
|
||||
MW_CONTROLLER_RECONNECT_WAIT = 3,
|
||||
} mw_controller_connection_state;
|
||||
|
||||
typedef enum {
|
||||
MW_CTRL_CMD_NONE = 0,
|
||||
MW_CTRL_CMD_SET_TARGET,
|
||||
MW_CTRL_CMD_LOAD_ON,
|
||||
MW_CTRL_CMD_LOAD_OFF,
|
||||
MW_CTRL_CMD_RESTORE_TARGET,
|
||||
MW_CTRL_CMD_SAFE,
|
||||
MW_CTRL_CMD_SET_REMOTE,
|
||||
MW_CTRL_CMD_SET_SERIES_RESISTANCE,
|
||||
MW_CTRL_CMD_REFRESH_CAPABILITIES,
|
||||
MW_CTRL_CMD_GET_SERIES_RESISTANCE,
|
||||
} mw_controller_command_kind;
|
||||
|
||||
typedef struct {
|
||||
const char *port_path;
|
||||
int settle_ms;
|
||||
int poll_interval_ms;
|
||||
int reconnect_ms;
|
||||
size_t queue_capacity;
|
||||
bool safe_on_shutdown;
|
||||
} mw_controller_config;
|
||||
|
||||
typedef struct {
|
||||
bool running;
|
||||
bool connected;
|
||||
mw_controller_connection_state connection_state;
|
||||
uint64_t snapshot_seq;
|
||||
uint64_t connect_attempts;
|
||||
uint64_t reconnect_count;
|
||||
uint64_t poll_success_count;
|
||||
uint64_t poll_error_count;
|
||||
uint64_t command_success_count;
|
||||
uint64_t command_error_count;
|
||||
uint64_t last_queued_command_id;
|
||||
uint64_t last_completed_command_id;
|
||||
int last_completed_result;
|
||||
mw_controller_command_kind last_completed_kind;
|
||||
size_t pending_commands;
|
||||
char port_path[MW_CONTROLLER_PORT_PATH_MAX + 1];
|
||||
char last_error[MW_CONTROLLER_ERROR_MAX + 1];
|
||||
char last_completed_error[MW_CONTROLLER_ERROR_MAX + 1];
|
||||
bool app_state_valid;
|
||||
mw_app_state app_state;
|
||||
bool series_resistance_valid;
|
||||
uint16_t series_resistance_milliohm;
|
||||
} mw_controller_snapshot;
|
||||
|
||||
void mw_controller_config_init(mw_controller_config *config);
|
||||
|
||||
int mw_controller_start(mw_controller **out_controller, const mw_controller_config *config);
|
||||
void mw_controller_stop(mw_controller *controller);
|
||||
|
||||
int mw_controller_get_snapshot(mw_controller *controller, mw_controller_snapshot *out_snapshot);
|
||||
int mw_controller_wait_for_update(mw_controller *controller,
|
||||
uint64_t last_seen_snapshot_seq,
|
||||
int timeout_ms,
|
||||
uint64_t *out_snapshot_seq);
|
||||
|
||||
int mw_controller_queue_set_target(mw_controller *controller,
|
||||
mw_mode mode,
|
||||
uint32_t milli_units,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_load_on(mw_controller *controller,
|
||||
mw_mode mode,
|
||||
uint32_t milli_units,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_load_off(mw_controller *controller, uint64_t *out_command_id);
|
||||
int mw_controller_queue_restore_target(mw_controller *controller, uint64_t *out_command_id);
|
||||
int mw_controller_queue_safe(mw_controller *controller, uint64_t *out_command_id);
|
||||
int mw_controller_queue_set_remote(mw_controller *controller,
|
||||
bool enable,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_set_series_resistance(mw_controller *controller,
|
||||
uint16_t milliohm,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_refresh_capabilities(mw_controller *controller,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_get_series_resistance(mw_controller *controller,
|
||||
uint64_t *out_command_id);
|
||||
|
||||
const char *mw_controller_connection_state_name(mw_controller_connection_state state);
|
||||
const char *mw_controller_command_kind_name(mw_controller_command_kind kind);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
30
include/mightywatt_log.h
Normal file
30
include/mightywatt_log.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef MIGHTYWATT_LOG_H
|
||||
#define MIGHTYWATT_LOG_H
|
||||
|
||||
#include "mightywatt.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct mw_csv_logger mw_csv_logger;
|
||||
|
||||
typedef enum {
|
||||
MW_CSV_UNITS_ENGINEERING = 0,
|
||||
MW_CSV_UNITS_RAW = 1
|
||||
} mw_csv_units_mode;
|
||||
|
||||
int mw_csv_logger_open(mw_csv_logger **out_logger, const char *path, mw_csv_units_mode units_mode);
|
||||
void mw_csv_logger_close(mw_csv_logger *logger);
|
||||
int mw_csv_logger_write(mw_csv_logger *logger,
|
||||
const char *context,
|
||||
long step_index,
|
||||
const mw_report *report);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
46
include/mightywatt_sequence.h
Normal file
46
include/mightywatt_sequence.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef MIGHTYWATT_SEQUENCE_H
|
||||
#define MIGHTYWATT_SEQUENCE_H
|
||||
|
||||
#include "mightywatt_app.h"
|
||||
#include "mightywatt_log.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const char *csv_path;
|
||||
int sample_period_ms_override;
|
||||
bool safe_on_abort;
|
||||
mw_csv_units_mode csv_units_mode;
|
||||
} mw_sequence_run_options;
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
int sample_period_ms;
|
||||
size_t steps_total;
|
||||
size_t steps_completed;
|
||||
size_t samples_written;
|
||||
bool aborted;
|
||||
bool abort_sequence_ran;
|
||||
size_t abort_steps_completed;
|
||||
bool last_report_valid;
|
||||
mw_report last_report;
|
||||
} mw_sequence_result;
|
||||
|
||||
int mw_sequence_run_file(mw_app *app,
|
||||
const char *json_path,
|
||||
const mw_sequence_run_options *options,
|
||||
mw_sequence_result *out_result,
|
||||
char *error_text,
|
||||
size_t error_text_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user