Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed Nov 11, 2024
1 parent 0ba7692 commit 0805fd7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
20 changes: 10 additions & 10 deletions differential_pressure_sensor/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static void handleFastLoop(State* const state, const CanardMicrosecond monotonic
uavcan_si_unit_pressure_Scalar_1_0 msg = {0};
msg._pascal = (float) rand() * 0.1F; // TODO: sample data from the real sensor.
// Serialize and publish the message:
uint8_t serialized[uavcan_si_unit_pressure_Scalar_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_si_unit_pressure_Scalar_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = uavcan_si_unit_pressure_Scalar_1_0_serialize_(&msg, &serialized[0], &serialized_size);
assert(err >= 0);
Expand Down Expand Up @@ -226,8 +226,8 @@ static void handle1HzLoop(State* const state, const CanardMicrosecond monotonic_
heartbeat.health.value = uavcan_node_Health_1_0_NOMINAL;
}

uint8_t serialized[uavcan_node_Heartbeat_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
size_t serialized_size = sizeof(serialized);
uint8_t serialized[uavcan_node_Heartbeat_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = uavcan_node_Heartbeat_1_0_serialize_(&heartbeat, &serialized[0], &serialized_size);
assert(err >= 0);
if (err >= 0)
Expand Down Expand Up @@ -259,7 +259,7 @@ static void handle1HzLoop(State* const state, const CanardMicrosecond monotonic_
uavcan_pnp_NodeIDAllocationData_2_0 msg = {0};
msg.node_id.value = UINT16_MAX;
getUniqueID(msg.unique_id);
uint8_t serialized[uavcan_pnp_NodeIDAllocationData_2_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_pnp_NodeIDAllocationData_2_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = uavcan_pnp_NodeIDAllocationData_2_0_serialize_(&msg, &serialized[0], &serialized_size);
assert(err >= 0);
Expand Down Expand Up @@ -287,7 +287,7 @@ static void handle1HzLoop(State* const state, const CanardMicrosecond monotonic_
uavcan_si_unit_temperature_Scalar_1_0 msg = {0};
msg.kelvin = (float) rand() * 0.01F; // TODO: sample data from the real sensor.
// Serialize and publish the message:
uint8_t serialized[uavcan_si_unit_temperature_Scalar_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_si_unit_temperature_Scalar_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = uavcan_si_unit_temperature_Scalar_1_0_serialize_(&msg, &serialized[0], &serialized_size);
assert(err >= 0);
Expand Down Expand Up @@ -365,7 +365,7 @@ static void handle01HzLoop(State* const state, const CanardMicrosecond monotonic
fillServers(state->canard.rx_subscriptions[CanardTransferKindRequest], &m.servers);
fillServers(state->canard.rx_subscriptions[CanardTransferKindResponse], &m.clients); // For regularity.

// Serialize and publish the message.
// Serialize and publish the message. Use a smaller buffer if you know that message is always small.
uint8_t serialized[uavcan_node_port_List_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = uavcan_node_port_List_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_;
if (uavcan_node_port_List_0_1_serialize_(&m, &serialized[0], &serialized_size) >= 0)
Expand Down Expand Up @@ -544,7 +544,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
{
// The request object is empty so we don't bother deserializing it. Just send the response.
const uavcan_node_GetInfo_Response_1_0 resp = processRequestNodeGetInfo();
uint8_t serialized[uavcan_node_GetInfo_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_node_GetInfo_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t res = uavcan_node_GetInfo_Response_1_0_serialize_(&resp, &serialized[0], &serialized_size);
if (res >= 0)
Expand All @@ -567,7 +567,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
if (uavcan_register_Access_Request_1_0_deserialize_(&req, transfer->payload, &size) >= 0)
{
const uavcan_register_Access_Response_1_0 resp = processRequestRegisterAccess(&req);
uint8_t serialized[uavcan_register_Access_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_register_Access_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
if (uavcan_register_Access_Response_1_0_serialize_(&resp, &serialized[0], &serialized_size) >= 0)
{
Expand All @@ -586,7 +586,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
if (uavcan_register_List_Request_1_0_deserialize_(&req, transfer->payload, &size) >= 0)
{
const uavcan_register_List_Response_1_0 resp = {.name = registerGetNameByIndex(req.index)};
uint8_t serialized[uavcan_register_List_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_register_List_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
if (uavcan_register_List_Response_1_0_serialize_(&resp, &serialized[0], &serialized_size) >= 0)
{
Expand All @@ -605,7 +605,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
if (uavcan_node_ExecuteCommand_Request_1_1_deserialize_(&req, transfer->payload, &size) >= 0)
{
const uavcan_node_ExecuteCommand_Response_1_1 resp = processRequestExecuteCommand(&req);
uint8_t serialized[uavcan_node_ExecuteCommand_Response_1_1_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_node_ExecuteCommand_Response_1_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
if (uavcan_node_ExecuteCommand_Response_1_1_serialize_(&resp, &serialized[0], &serialized_size) >= 0)
{
Expand Down
6 changes: 3 additions & 3 deletions libudpard_demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ static void cbOnNodeIDAllocationData(struct Subscriber* const self, struct Udpar
(void) fprintf(stderr, "RPC dispatcher start failed: %i\n", rpc_start_res);
}
} // Otherwise, it's a response destined to another node, or it's a malformed message.
} // Otherwise, the message is malformed.
} // Otherwise, it's a request from another allocation client node, or we already have a node-ID.
} // Otherwise, the message is malformed.
} // Otherwise, it's a request from another allocation client node, or we already have a node-ID.
}

static void cbOnMyData(struct Subscriber* const self, struct UdpardRxTransfer* const transfer)
Expand Down Expand Up @@ -1254,7 +1254,7 @@ static void* regStore(struct Register* const self, void* const context)
assert((self != NULL) && (context != NULL));
if (self->persistent && self->remote_mutable)
{
byte_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_] = {0};
byte_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_];
size_t sr_size = uavcan_register_Value_1_0_EXTENT_BYTES_;
const bool ok = (uavcan_register_Value_1_0_serialize_(&self->value, serialized, &sr_size) >= 0) &&
storagePut(self->name, sr_size, &serialized[0]);
Expand Down
8 changes: 4 additions & 4 deletions shared/register/register.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void registerRead(const char* const register_name, uavcan_register_Value_1_0* co
FILE* const fp = registerOpen(&register_name[0], false);
if (fp != NULL)
{
uint8_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_] = {0};
uint8_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_];
size_t sr_size = fread(&serialized[0], 1U, uavcan_register_Value_1_0_EXTENT_BYTES_, fp);
(void) fclose(fp);
uavcan_register_Value_1_0 out = {0};
Expand All @@ -54,9 +54,9 @@ void registerRead(const char* const register_name, uavcan_register_Value_1_0* co

void registerWrite(const char* const register_name, const uavcan_register_Value_1_0* const value)
{
uint8_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_] = {0};
size_t sr_size = uavcan_register_Value_1_0_EXTENT_BYTES_;
const int8_t err = uavcan_register_Value_1_0_serialize_(value, serialized, &sr_size);
uint8_t serialized[uavcan_register_Value_1_0_EXTENT_BYTES_];
size_t sr_size = uavcan_register_Value_1_0_EXTENT_BYTES_;
const int8_t err = uavcan_register_Value_1_0_serialize_(value, serialized, &sr_size);
if (err >= 0)
{
FILE* const fp = registerOpen(&register_name[0], true);
Expand Down
28 changes: 14 additions & 14 deletions udral_servo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static void handleFastLoop(State* const state, const CanardMicrosecond monotonic
// If there are any hardware or configuration issues, report them here:
msg.heartbeat.health.value = uavcan_node_Health_1_0_NOMINAL;
// Serialize and publish the message:
uint8_t serialized[reg_udral_service_actuator_common_Feedback_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[reg_udral_service_actuator_common_Feedback_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err =
reg_udral_service_actuator_common_Feedback_0_1_serialize_(&msg, &serialized[0], &serialized_size);
Expand Down Expand Up @@ -275,8 +275,8 @@ static void handleFastLoop(State* const state, const CanardMicrosecond monotonic
msg.value.kinematics.acceleration.meter_per_second_per_second = state->servo.acceleration;
msg.value.force.newton = state->servo.force;
// Serialize and publish the message:
uint8_t serialized[reg_udral_physics_dynamics_translation_LinearTs_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
size_t serialized_size = sizeof(serialized);
uint8_t serialized[reg_udral_physics_dynamics_translation_LinearTs_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err =
reg_udral_physics_dynamics_translation_LinearTs_0_1_serialize_(&msg, &serialized[0], &serialized_size);
assert(err >= 0);
Expand All @@ -303,8 +303,8 @@ static void handleFastLoop(State* const state, const CanardMicrosecond monotonic
msg.value.current.ampere = 20.315F;
msg.value.voltage.volt = 51.3F;
// Serialize and publish the message:
uint8_t serialized[reg_udral_physics_dynamics_translation_LinearTs_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
size_t serialized_size = sizeof(serialized);
uint8_t serialized[reg_udral_physics_dynamics_translation_LinearTs_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = reg_udral_physics_electricity_PowerTs_0_1_serialize_(&msg, &serialized[0], &serialized_size);
assert(err >= 0);
if (err >= 0)
Expand Down Expand Up @@ -341,8 +341,8 @@ static void handle1HzLoop(State* const state, const CanardMicrosecond monotonic_
heartbeat.health.value = uavcan_node_Health_1_0_NOMINAL;
}

uint8_t serialized[uavcan_node_Heartbeat_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
size_t serialized_size = sizeof(serialized);
uint8_t serialized[uavcan_node_Heartbeat_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = uavcan_node_Heartbeat_1_0_serialize_(&heartbeat, &serialized[0], &serialized_size);
assert(err >= 0);
if (err >= 0)
Expand Down Expand Up @@ -374,7 +374,7 @@ static void handle1HzLoop(State* const state, const CanardMicrosecond monotonic_
uavcan_pnp_NodeIDAllocationData_2_0 msg = {0};
msg.node_id.value = UINT16_MAX;
getUniqueID(msg.unique_id);
uint8_t serialized[uavcan_pnp_NodeIDAllocationData_2_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_pnp_NodeIDAllocationData_2_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err = uavcan_pnp_NodeIDAllocationData_2_0_serialize_(&msg, &serialized[0], &serialized_size);
assert(err >= 0);
Expand Down Expand Up @@ -403,7 +403,7 @@ static void handle1HzLoop(State* const state, const CanardMicrosecond monotonic_
// Publish the servo status -- this is a low-rate message with low-severity diagnostics.
reg_udral_service_actuator_common_Status_0_1 msg = {0};
// TODO: POPULATE THE MESSAGE: temperature, errors, etc.
uint8_t serialized[reg_udral_service_actuator_common_Status_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[reg_udral_service_actuator_common_Status_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t err =
reg_udral_service_actuator_common_Status_0_1_serialize_(&msg, &serialized[0], &serialized_size);
Expand Down Expand Up @@ -500,7 +500,7 @@ static void handle01HzLoop(State* const state, const CanardMicrosecond monotonic
fillServers(state->canard.rx_subscriptions[CanardTransferKindRequest], &m.servers);
fillServers(state->canard.rx_subscriptions[CanardTransferKindResponse], &m.clients); // For regularity.

// Serialize and publish the message.
// Serialize and publish the message. Use a smaller buffer if you know that message is always small.
uint8_t serialized[uavcan_node_port_List_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = uavcan_node_port_List_0_1_SERIALIZATION_BUFFER_SIZE_BYTES_;
if (uavcan_node_port_List_0_1_serialize_(&m, &serialized[0], &serialized_size) >= 0)
Expand Down Expand Up @@ -721,7 +721,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
{
// The request object is empty so we don't bother deserializing it. Just send the response.
const uavcan_node_GetInfo_Response_1_0 resp = processRequestNodeGetInfo();
uint8_t serialized[uavcan_node_GetInfo_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_node_GetInfo_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
const int8_t res = uavcan_node_GetInfo_Response_1_0_serialize_(&resp, &serialized[0], &serialized_size);
if (res >= 0)
Expand All @@ -740,7 +740,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
if (uavcan_register_Access_Request_1_0_deserialize_(&req, transfer->payload, &size) >= 0)
{
const uavcan_register_Access_Response_1_0 resp = processRequestRegisterAccess(&req);
uint8_t serialized[uavcan_register_Access_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_register_Access_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
if (uavcan_register_Access_Response_1_0_serialize_(&resp, &serialized[0], &serialized_size) >= 0)
{
Expand All @@ -755,7 +755,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
if (uavcan_register_List_Request_1_0_deserialize_(&req, transfer->payload, &size) >= 0)
{
const uavcan_register_List_Response_1_0 resp = {.name = registerGetNameByIndex(req.index)};
uint8_t serialized[uavcan_register_List_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_register_List_Response_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
if (uavcan_register_List_Response_1_0_serialize_(&resp, &serialized[0], &serialized_size) >= 0)
{
Expand All @@ -770,7 +770,7 @@ static void processReceivedTransfer(State* const state, const CanardRxTransfer*
if (uavcan_node_ExecuteCommand_Request_1_1_deserialize_(&req, transfer->payload, &size) >= 0)
{
const uavcan_node_ExecuteCommand_Response_1_1 resp = processRequestExecuteCommand(&req);
uint8_t serialized[uavcan_node_ExecuteCommand_Response_1_1_SERIALIZATION_BUFFER_SIZE_BYTES_] = {0};
uint8_t serialized[uavcan_node_ExecuteCommand_Response_1_1_SERIALIZATION_BUFFER_SIZE_BYTES_];
size_t serialized_size = sizeof(serialized);
if (uavcan_node_ExecuteCommand_Response_1_1_serialize_(&resp, &serialized[0], &serialized_size) >= 0)
{
Expand Down

0 comments on commit 0805fd7

Please sign in to comment.