wg_util.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
36 
37 namespace ethercat_hardware
38 {
39 
40 
41 unsigned int wg_util::rotateRight8(unsigned in)
42 {
43  in &= 0xff;
44  in = (in >> 1) | (in << 7);
45  in &= 0xff;
46  return in;
47 }
48 
49 unsigned wg_util::computeChecksum(void const *data, unsigned length)
50 {
51  const unsigned char *d = (const unsigned char *)data;
52  unsigned int checksum = 0x42;
53  for (unsigned int i = 0; i < length; ++i)
54  {
55  checksum = rotateRight8(checksum);
56  checksum ^= d[i];
57  checksum &= 0xff;
58  }
59  return checksum;
60 }
61 
62 
63 
64 unsigned SyncMan::baseAddress(unsigned num)
65 {
66  assert(num < 8);
67  return BASE_ADDR + 8 * num;
68 }
69 
70 
80 bool SyncMan::readData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num)
81 {
82  return ( EthercatDevice::readData(com, sh, baseAddress(num), this, sizeof(*this), addrMode) == 0);
83 }
84 
85 
86 unsigned SyncManActivate::baseAddress(unsigned num)
87 {
88  assert(num < 8);
89  return BASE_ADDR + 8 * num;
90 }
91 
101 bool SyncManActivate::writeData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num) const
102 {
103  return ( EthercatDevice::writeData(com, sh, baseAddress(num), this, sizeof(*this), addrMode) == 0);
104 }
105 
106 
107 }; //end namespace ethercat_hardware
d
uint16_t length
Definition: wg_util.h:119
static unsigned baseAddress(unsigned num)
Definition: wg_util.cpp:64
bool writeData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num) const
Write data to Sync Manager Activation register.
Definition: wg_util.cpp:101
unsigned computeChecksum(void const *data, unsigned length)
Definition: wg_util.cpp:49
static const unsigned BASE_ADDR
Definition: wg_util.h:129
static int writeData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EC_UINT address, void const *buffer, EC_UINT length, AddrMode addrMode)
Write data to device ESC.
unsigned int rotateRight8(unsigned in)
Definition: wg_util.cpp:41
static unsigned baseAddress(unsigned num)
Definition: wg_util.cpp:86
bool readData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num)
Read data from Sync Manager.
Definition: wg_util.cpp:80
static int readData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EC_UINT address, void *buffer, EC_UINT length, AddrMode addrMode)
Read data from device ESC.


ethercat_hardware
Author(s): Rob Wheeler , Derek King
autogenerated on Thu Mar 4 2021 03:10:21