1
0
Fork 0

Reduce variable scope

This commit is contained in:
Julien PEYREGNE 2021-03-19 09:44:29 +01:00
parent 9554c2c8df
commit 877edc50a8
5 changed files with 6 additions and 12 deletions

View file

@ -145,7 +145,6 @@ OD_entry_t *OD_find(OD_t *od, uint16_t index) {
return NULL;
}
uint16_t cur;
uint16_t min = 0;
uint16_t max = od->size - 1;
@ -154,7 +153,7 @@ OD_entry_t *OD_find(OD_t *od, uint16_t index) {
* max number of loop passes is log2(N) */
while (min < max) {
/* get entry between min and max */
cur = (min + max) >> 1;
uint16_t cur = (min + max) >> 1;
OD_entry_t* entry = &od->list[cur];
if (index == entry->index) {

View file

@ -443,9 +443,8 @@ void CO_SDOserver_initCallbackPre(CO_SDOserver_t *SDO,
static inline void reverseBytes(void *start, OD_size_t size) {
uint8_t *lo = (uint8_t *)start;
uint8_t *hi = (uint8_t *)start + size - 1;
uint8_t swap;
while (lo < hi) {
swap = *lo;
uint8_t swap = *lo;
*lo++ = *hi;
*hi-- = swap;
}

View file

@ -50,7 +50,6 @@ int main (void){
uint32_t heapMemoryUsed;
void *CANmoduleAddress = NULL; /* CAN module address */
uint8_t pendingNodeId = 10; /* read from dip switches or nonvolatile memory, configurable by LSS slave */
uint8_t activeNodeId = 10; /* Copied from CO_pendingNodeId in the communication reset section */
uint16_t pendingBitRate = 125; /* read from dip switches or nonvolatile memory, configurable by LSS slave */
/* Configure microcontroller. */
@ -94,7 +93,7 @@ int main (void){
log_printf("Error: LSS slave initialization failed: %d\n", err);
return 0;
}
activeNodeId = pendingNodeId;
uint8_t activeNodeId = pendingNodeId;
err = CO_CANopenInit(activeNodeId);
if(err != CO_ERROR_NO && err != CO_ERROR_NODE_ID_UNCONFIGURED_LSS) {
log_printf("Error: CANopen initialization failed: %d\n", err);

View file

@ -104,14 +104,13 @@ static uint32_t CO_CANgetIndexFromIdent(
/** Disable socketCAN rx ******************************************************/
static CO_ReturnError_t disableRx(CO_CANmodule_t *CANmodule)
{
int ret;
uint32_t i;
CO_ReturnError_t retval;
/* insert a filter that doesn't match any messages */
retval = CO_ERROR_NO;
for (i = 0; i < CANmodule->CANinterfaceCount; i ++) {
ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER,
int ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER,
NULL, 0);
if(ret < 0){
log_printf(LOG_ERR, CAN_FILTER_FAILED,
@ -128,7 +127,6 @@ static CO_ReturnError_t disableRx(CO_CANmodule_t *CANmodule)
/** Set up or update socketCAN rx filters *************************************/
static CO_ReturnError_t setRxFilters(CO_CANmodule_t *CANmodule)
{
int ret;
size_t i;
int count;
CO_ReturnError_t retval;
@ -155,7 +153,7 @@ static CO_ReturnError_t setRxFilters(CO_CANmodule_t *CANmodule)
retval = CO_ERROR_NO;
for (i = 0; i < CANmodule->CANinterfaceCount; i ++) {
ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER,
int ret = setsockopt(CANmodule->CANinterfaces[i].fd, SOL_CAN_RAW, CAN_RAW_FILTER,
rxFiltersCpy, sizeof(struct can_filter) * count);
if(ret < 0){
log_printf(LOG_ERR, CAN_FILTER_FAILED,

View file

@ -42,8 +42,6 @@ static CO_CANinterfaceState_t CO_CANerrorSetListenOnly(
CO_CANinterfaceErrorhandler_t *CANerrorhandler,
bool_t resetIf)
{
char command[100];
log_printf(LOG_DEBUG, DBG_CAN_SET_LISTEN_ONLY, CANerrorhandler->ifName);
clock_gettime(CLOCK_MONOTONIC, &CANerrorhandler->timestamp);
@ -51,6 +49,7 @@ static CO_CANinterfaceState_t CO_CANerrorSetListenOnly(
if (resetIf) {
int ret;
char command[100];
snprintf(command, sizeof(command), "ip link set %s down && "
"ip link set %s up "
"&",