cli implemented supporting set_outpu_voltage and help only yet
This commit is contained in:
@@ -36,6 +36,40 @@ ESeriesMaxValue get_E_MAX(ESeries E_series) {
|
||||
return output;
|
||||
}
|
||||
|
||||
ESeries get_E_Series(int number) {
|
||||
|
||||
ESeries output;
|
||||
|
||||
switch (number) {
|
||||
case 3:
|
||||
output = E3;
|
||||
break;
|
||||
case 6:
|
||||
output = E6;
|
||||
break;
|
||||
case 12:
|
||||
output = E12;
|
||||
break;
|
||||
case 24:
|
||||
output = E24;
|
||||
break;
|
||||
case 48:
|
||||
output = E48;
|
||||
break;
|
||||
case 96:
|
||||
output = E96;
|
||||
break;
|
||||
case 192:
|
||||
output = E192;
|
||||
break;
|
||||
default:
|
||||
output = E0;
|
||||
break;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
double round_to_E_series (double continuous_value, ESeries E_series) {
|
||||
|
||||
/*
|
||||
|
||||
@@ -22,11 +22,13 @@ double E192_values[192] = { 1.00, 1.01, 1.02, 1.04, 1.05, 1.06, 1.07, 1.09, 1.10
|
||||
|
||||
double *E_values[7] = {E3_values, E6_values, E12_values, E24_values, E48_values, E96_values, E192_values};
|
||||
|
||||
typedef enum {E3, E6, E12, E24, E48, E96, E192} ESeries;
|
||||
typedef enum { E0, E3, E6, E12, E24, E48, E96, E192} ESeries;
|
||||
typedef enum {E_NIL=0, E3_MAX=2, E6_MAX=5, E12_MAX=11, E24_MAX=23, E48_MAX=47, E96_MAX=95, E192_MAX=191} ESeriesMaxValue;
|
||||
|
||||
extern ESeriesMaxValue get_E_MAX(ESeries E_series);
|
||||
|
||||
extern ESeries get_E_Series(int number);
|
||||
|
||||
extern double round_to_E_series (double continuous_value, ESeries E_series);
|
||||
|
||||
#endif /*ESERIES_H*/
|
||||
|
||||
103
main.c
103
main.c
@@ -1,6 +1,7 @@
|
||||
/*main.c*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib/max_functions.h"
|
||||
|
||||
@@ -10,6 +11,106 @@ static int state=0;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
printf("\n");
|
||||
printf("max668_calc: Usage: max668_calc set_output_voltage -E [E series] -V [voltage]\n");
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-h") == 0) {
|
||||
printf("max668_calc: Usage: max668_calc set_output_voltage -E [E series] -V [voltage]\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int command = 0;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "set_output_voltage") == 0) {
|
||||
|
||||
command = 1;
|
||||
}
|
||||
else if ((strchr(argv[i], '-') == NULL) && (strchr(argv[i-1], '-') == NULL)) {
|
||||
|
||||
printf("max668_calc: Usage: max668_calc set_output_voltage -E [E series] -V [voltage]\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
double voltage = 0.0;
|
||||
ESeries e_series;
|
||||
char input[10];
|
||||
int read_number;
|
||||
int temp_result;
|
||||
|
||||
switch (command) {
|
||||
|
||||
case 1:
|
||||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
|
||||
if (argv[i][0] == '-') {
|
||||
|
||||
if (strcmp(argv[i], "-V") == 0) {
|
||||
|
||||
if(strlen(argv[i+1]) > 9) {
|
||||
|
||||
printf("max668_calc: Malformed voltage format.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
strncpy(argv[i+1], input, strlen(argv[i+1]));
|
||||
input[strlen(argv[i+1])+1] = '\0';
|
||||
|
||||
if (input[strlen(input)] == 'V') {
|
||||
|
||||
input[strlen(input)] = '\0';
|
||||
}
|
||||
|
||||
temp_result = sscanf(input, "%lf", &voltage);
|
||||
|
||||
if (temp_result == 0) {
|
||||
printf("max668_calc: Malformed voltage format.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(argv[i], "-E") == 0) {
|
||||
|
||||
if(strlen(argv[i+1]) > 9) {
|
||||
|
||||
printf("max668_calc: Malformed E series format.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
strncpy(argv[i+1], input, strlen(argv[i+1]));
|
||||
input[strlen(argv[i+1])+1] = '\0';
|
||||
|
||||
if (input[0] == 'E') {
|
||||
|
||||
strcpy(input, &input[1]);
|
||||
}
|
||||
|
||||
temp_result = sscanf(input, "%i", &read_number);
|
||||
|
||||
if (temp_result == 0) {
|
||||
printf("max668_calc: Malformed E-Series format.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
e_series = get_E_Series(read_number);
|
||||
}
|
||||
|
||||
else {
|
||||
printf("max668_calc: Unknown option. Use max668_calc -h\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
set_output_voltage(voltage, e_series);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("max668_calc: Command not found. Use max668_calc -h\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user