commit
e1b353f06c
8 changed files with 22 additions and 25 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -679,6 +678,10 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
uint32_t timeDifference_us,
|
||||
uint32_t *timerNext_us)
|
||||
{
|
||||
if (SDO == NULL) {
|
||||
return CO_SDO_RT_wrongArguments;
|
||||
}
|
||||
|
||||
(void)timerNext_us; /* may be unused */
|
||||
|
||||
CO_SDO_return_t ret = CO_SDO_RT_waitingResponse;
|
||||
|
|
@ -686,10 +689,7 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
bool_t isNew = CO_FLAG_READ(SDO->CANrxNew);
|
||||
|
||||
|
||||
if (SDO == NULL) {
|
||||
ret = CO_SDO_RT_wrongArguments;
|
||||
}
|
||||
else if (SDO->valid && SDO->state == CO_SDO_ST_IDLE && !isNew) {
|
||||
if (SDO->valid && SDO->state == CO_SDO_ST_IDLE && !isNew) {
|
||||
/* Idle and nothing new */
|
||||
ret = CO_SDO_RT_ok_communicationEnd;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,8 +201,8 @@ bool_t CO_TIME_process(CO_TIME_t *TIME,
|
|||
ms = us / 1000;
|
||||
TIME->residual_us = us % 1000;
|
||||
TIME->ms += ms;
|
||||
if (TIME->ms >= (1000*60*60*24)) {
|
||||
TIME->ms -= (1000*60*60*24);
|
||||
if (TIME->ms >= ((uint32_t)1000*60*60*24)) {
|
||||
TIME->ms -= ((uint32_t)1000*60*60*24);
|
||||
TIME->days += 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -631,7 +631,7 @@ size_t CO_fifo_readR322a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
|
||||
if (fifo != NULL && count >= 20 && CO_fifo_getOccupied(fifo) == sizeof(n)) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%g", CO_SWAP_32(n));
|
||||
return sprintf(buf, "%g", (double)CO_SWAP_32(n));
|
||||
}
|
||||
else {
|
||||
return CO_fifo_readHex2a(fifo, buf, count, end);
|
||||
|
|
@ -643,7 +643,7 @@ size_t CO_fifo_readR642a(CO_fifo_t *fifo, char *buf, size_t count, bool_t end) {
|
|||
|
||||
if (fifo != NULL && count >= 30 && CO_fifo_getOccupied(fifo) == sizeof(n)) {
|
||||
CO_fifo_read(fifo, (uint8_t *)&n, sizeof(n), NULL);
|
||||
return sprintf(buf, "%g", CO_SWAP_64(n));
|
||||
return sprintf(buf, "%g", (double)CO_SWAP_64(n));
|
||||
}
|
||||
else {
|
||||
return CO_fifo_readHex2a(fifo, buf, count, end);
|
||||
|
|
|
|||
|
|
@ -1213,8 +1213,11 @@ CO_ReturnError_t CO_CANopenInitPDO(CO_t *co,
|
|||
uint8_t nodeId,
|
||||
uint32_t *errInfo)
|
||||
{
|
||||
if (co == NULL || nodeId < 1 || nodeId > 127 || co->nodeIdUnconfigured) {
|
||||
return (co != NULL || co->nodeIdUnconfigured)
|
||||
if (co == NULL) {
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
if (nodeId < 1 || nodeId > 127 || co->nodeIdUnconfigured) {
|
||||
return (co->nodeIdUnconfigured)
|
||||
? CO_ERROR_NODE_ID_UNCONFIGURED_LSS : CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
@ -63,7 +62,7 @@ int main (void){
|
|||
return 0;
|
||||
}
|
||||
else {
|
||||
log_printf("Allocated %d bytes for CANopen objects\n", heapMemoryUsed);
|
||||
log_printf("Allocated %u bytes for CANopen objects\n", heapMemoryUsed);
|
||||
}
|
||||
|
||||
/* initialize EEPROM */
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -182,9 +180,8 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule)
|
|||
{
|
||||
CO_ReturnError_t ret;
|
||||
|
||||
CANmodule->CANnormal = false;
|
||||
|
||||
if(CANmodule != NULL) {
|
||||
CANmodule->CANnormal = false;
|
||||
ret = setRxFilters(CANmodule);
|
||||
if (ret == CO_ERROR_NO) {
|
||||
/* Put CAN module in normal mode */
|
||||
|
|
|
|||
|
|
@ -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 "
|
||||
"&",
|
||||
|
|
|
|||
Loading…
Reference in a new issue