Commit 61cfbded authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

o Use block_alloc() function to make sure the struct is zeroed.

o Fix disable
o Enable/disable pdo buttons should use the 'ethercat' block, not 'ec'
parent 55cf9cbc
......@@ -238,8 +238,8 @@ var trace_url = "trace.cgi";
var shell_url = "shell.cgi";
var weather_url = "status.cgi";
var ethercat_enable_param = 'controller \'params { { "ec", "pdo_enabled", (int)1 } } \' ';
var ethercat_disable_param = 'controller \'params { { "ec", "pdo_enabled", (int)0 } } \' ';
var ethercat_enable_param = 'controller \'params { { "ethercat", "pdo_enabled", (int)1 } } \' ';
var ethercat_disable_param = 'controller \'params { { "ethercat", "pdo_enabled", (int)0 } } \' ';
var azimuth_enable_param = 'controller \'params { { "azimuth_servo_state", "override", (int)0 } { "azimuth_servo_state", "enabled", (int)1 } { "elevation_safety", "recover", (int)0 } } \' ';
var azimuth_disable_param = 'controller \'params { { "azimuth_servo_state", "override", (int)0 } { "azimuth_servo_state", "enabled", (int)0 } { "elevation_safety", "recover", (int)0 } } \' ';
......
......@@ -69,6 +69,9 @@ static void calculate_tx(struct controller_block *tx)
esc_al_state_set(&stbr->addr, ESC_AL_STATE_OPERATIONAL, &timeout);
enabled = true;
}
if (!enable && enabled) {
enabled = false;
}
stbr->tx.A180 = enabled;
stbr->tx.F210 = (*private->input_ba1 << 0) | (*private->input_ba2 << 1);
......@@ -215,52 +218,32 @@ struct controller_block *block_stoeber_create(char *name, va_list ap)
int i;
int serial_number;
double max_torque, brake_resistor, brake_power;
char trx_name[strlen(name)+strlen("_Xx0")];
ec_pos = va_arg(ap, int);
serial_number = va_arg(ap, int);
max_torque = va_arg(ap, double);
brake_resistor = va_arg(ap, double);
brake_power = va_arg(ap, double);
stoeber = malloc(sizeof(struct controller_block));
stoeber = controller_block_alloc("stoeber", name,
sizeof(struct controller_block_private));
if (!stoeber)
goto err_malloc;
stoeber_tx = malloc(sizeof(struct controller_block));
if (!stoeber_tx)
sprintf(trx_name, "%s_tx", name);
stoeber_tx = controller_block_alloc("stoeber_tx", name, 0);
goto err_malloc_tx;
stoeber_rx = malloc(sizeof(struct controller_block));
stoeber_tx->private = stoeber->private;
sprintf(trx_name, "%s_rx", name);
stoeber_rx = controller_block_alloc("stoeber_rx", name, 0);
if (!stoeber_rx)
goto err_malloc_rx;
stoeber->type = "stoeber";
stoeber_tx->type = "stoeber_tx";
stoeber_rx->type = "stoeber_rx";
stoeber->name = strdup(name);
if (!stoeber->name)
goto err_name;
stoeber_rx->name = malloc(strlen(name)+4);
if (!stoeber_rx->name)
goto err_stoeber_rx_name;
sprintf(stoeber_rx->name, "%s_rx", name);
stoeber_tx->name = malloc(strlen(name)+4);
if (!stoeber_tx->name)
goto err_stoeber_tx_name;
sprintf(stoeber_tx->name, "%s_tx", name);
stoeber_rx->private = stoeber->private;
private = calloc(1, sizeof(struct controller_block_private));
if (!private)
goto err_private;
stoeber->private = private;
stoeber_rx->private = private;
stoeber_tx->private = private;
memset(&private->stbr, 0, sizeof(private->stbr));
ec_addr_set_auto_inc_nr(&private->stbr.addr, ec_pos);
private->stbr.max_speed = RPM2RADS(3000);
......@@ -352,9 +335,6 @@ struct controller_block *block_stoeber_create(char *name, va_list ap)
stoeber->outputs = stoeber_rx->outputs;
stoeber->output = stoeber_rx->output;
stoeber_tx->outputs = 0;
stoeber_tx->output = NULL;
stoeber_tx->inputs = 5;
stoeber_tx->input = calloc(stoeber_tx->inputs, sizeof(struct controller_block_interm));
if (!stoeber_tx->input)
......@@ -392,10 +372,9 @@ struct controller_block *block_stoeber_create(char *name, va_list ap)
stoeber->input[i].ghostof = &stoeber_tx->input[i];
}
stoeber->calculate = NULL;
stoeber_tx->calculate = calculate_tx;
stoeber_rx->calculate = calculate_rx;
controller_block_add(stoeber_tx);
controller_block_add(stoeber_rx);
controller_block_add(stoeber);
......@@ -409,18 +388,14 @@ err_tx_input:
err_rx_output:
/* no way to un-init the device? */
err_stoeber_init:
free(private);
err_private:
free(stoeber_tx->name);
err_stoeber_tx_name:
free(stoeber_rx->name);
err_stoeber_rx_name:
free(stoeber->name);
err_name:
free(stoeber_rx);
err_malloc_rx:
free(stoeber_tx->name);
free(stoeber_tx);
err_malloc_tx:
free(stoeber->private);
free(stoeber->name);
free(stoeber);
err_malloc:
return NULL;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment