diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3d746a8d..e106ad89 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -75,9 +75,10 @@ Including the files in this order helps avoid dependencies being brought in indi An example: +shapes/circle.cpp ```C++ /** - * @file shapes/circle.cpp + * @file */ // The corresponding header file that this source file implements diff --git a/Common/app/PeripheralInstances.cpp b/Common/app/PeripheralInstances.cpp index cc1e760d..af1aef7a 100644 --- a/Common/app/PeripheralInstances.cpp +++ b/Common/app/PeripheralInstances.cpp @@ -12,12 +12,13 @@ /********************************* Includes **********************************/ + #include "PeripheralInstances.h" -#include "HalUartInterface.h" #include "GpioInterfaceImpl.h" #include "OsInterfaceImpl.h" #include "SystemConf.h" +#include "UartInterfaceImpl.h" #include "usart.h" #include "gpio.h" @@ -26,7 +27,7 @@ using dynamixel::Motor; using dynamixel::DaisyChain; using dynamixel::DaisyChainParams; -using hal::HalUartInterface; +using hal::UartInterfaceImpl; using cmsis::OsInterfaceImpl; using hal::GpioInterfaceImpl; @@ -37,7 +38,7 @@ using hal::GpioInterfaceImpl; namespace periph{ // Variables // ---------------------------------------------------------------------------- -HalUartInterface uart_if; +UartInterfaceImpl uart_if; OsInterfaceImpl os_if; GpioInterfaceImpl gpio_if; diff --git a/Common/app/freertos.cpp b/Common/app/freertos.cpp index 8618c76d..f90cc9ca 100644 --- a/Common/app/freertos.cpp +++ b/Common/app/freertos.cpp @@ -53,7 +53,7 @@ /* USER CODE BEGIN Includes */ /** - * @file freertos.c + * @file * @brief Code for freertos application * @author Gokul * @author Tyler @@ -76,9 +76,9 @@ #include "rx_helper.h" #include "tx_helper.h" #include "UartDriver/UartDriver.h" -#include "HalUartInterface.h" #include "OsInterfaceImpl.h" #include "CircularDmaBuffer/CircularDmaBuffer.h" +#include "UartInterfaceImpl.h" /* USER CODE END Includes */ /* Variables -----------------------------------------------------------------*/ @@ -151,7 +151,7 @@ namespace{ buffer::BufferMaster buffer_master; cmsis::OsInterfaceImpl os_if_impl; -hal::HalUartInterface uart_if; +hal::UartInterfaceImpl uart_if; uart::UartDriver pc_uart_driver(&os_if_impl, &uart_if, UART_HANDLE_PC); bool setup_is_done = false; @@ -406,7 +406,7 @@ void StartCommandTask(void const * argument) pMotor->setComplianceMargin(1); } } - + // The only other communication with the motors will occur in the UART // threads, so we can use DMA now. periph::initMotorIOType(IO_Type::DMA); diff --git a/Common/app/imu_helper.cpp b/Common/app/imu_helper.cpp index 1fccdf5f..63affc7d 100644 --- a/Common/app/imu_helper.cpp +++ b/Common/app/imu_helper.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file imu_helper.cpp + * @file * @author Tyler Gamvrelis * * @addtogroup IMU_Helper IMU Helper diff --git a/Common/app/imu_helper.h b/Common/app/imu_helper.h index 10e782c1..d2c93b13 100644 --- a/Common/app/imu_helper.h +++ b/Common/app/imu_helper.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file imu_helper.h + * @file * @author Tyler Gamvrelis * @brief Helper file for the IMU thread in the main program flow * diff --git a/Common/app/rx_helper.h b/Common/app/rx_helper.h index e22bda5f..c51b035b 100644 --- a/Common/app/rx_helper.h +++ b/Common/app/rx_helper.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file rx_helper.h + * @file * @author Hannah * @brief Header for the helper file used to aid StartRXTask() in freertos.cpp ***************************************************************************** diff --git a/Common/app/tx_helper.cpp b/Common/app/tx_helper.cpp index 1e43bc61..0cb1acdf 100644 --- a/Common/app/tx_helper.cpp +++ b/Common/app/tx_helper.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file tx_helper.c + * @file * @author Hannah * @brief Helper file for the function StartTXTask() in freertos.cpp ***************************************************************************** diff --git a/Common/app/tx_helper.h b/Common/app/tx_helper.h index ec604371..db2dcaa3 100644 --- a/Common/app/tx_helper.h +++ b/Common/app/tx_helper.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file tx_helper.h + * @file * @author Hannah * @brief Header for the helper file used to aid StartTxTask() in freertos.cpp ***************************************************************************** diff --git a/Common/component/UartDriver/UartDriver.cpp b/Common/component/UartDriver/UartDriver.cpp index fc957db7..55c39c6e 100644 --- a/Common/component/UartDriver/UartDriver.cpp +++ b/Common/component/UartDriver/UartDriver.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file UartDriver.cpp + * @file * @author Tyler Gamvrelis * * @defgroup UartDriver diff --git a/Common/component/UartDriver/UartDriver.h b/Common/component/UartDriver/UartDriver.h index c660e3dc..abd1e7eb 100644 --- a/Common/component/UartDriver/UartDriver.h +++ b/Common/component/UartDriver/UartDriver.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file UartDriver.h + * @file * @author Tyler Gamvrelis * @author Robert Fairley * diff --git a/Common/component/UdpDriver/UdpDriver.cpp b/Common/component/UdpDriver/UdpDriver.cpp index fa9943d5..fd31b2d8 100644 --- a/Common/component/UdpDriver/UdpDriver.cpp +++ b/Common/component/UdpDriver/UdpDriver.cpp @@ -3,7 +3,7 @@ * @file * @author Robert Fairley * - * @defgroup udp_driver + * @defgroup udp * @brief Implementation of UdpDriver. * @{ ***************************************************************************** @@ -17,7 +17,6 @@ /********************************* Includes **********************************/ #include "UdpDriver.h" - using lwip::UdpRawInterface; using cmsis::OsInterface; using udp::UdpDriver; @@ -28,34 +27,43 @@ namespace { // Functions // ---------------------------------------------------------------------------- - static void defaultRecvCallback(void *arg, struct udp_pcb *pcb, - struct pbuf *pPbuf, - const ip_addr_t *addr, + struct pbuf *p_pbuf, + const ip_addr_t *ip_addr, u16_t port) { - UdpDriver *caller = (UdpDriver*) arg; - caller->setRecvPbuf(pPbuf); - caller->signalReceiveCplt(); + UdpDriver *self = static_cast(arg); + self->setRecvPbuf(p_pbuf); + self->signalReceiveCplt(); } -static bool transmitImpl(UdpDriver* caller, struct pbuf * pPbuf) { - const ip_addr_t addr = caller->getIpaddrPc(); +static bool transmitImpl(UdpDriver* self, struct pbuf * p_pbuf) { + const ip_addr_t addr = self->getIpAddrDest(); bool success = false; - if (caller->getUdpInterface()->udpConnect(const_cast(caller->getPcb()), - &addr, caller->getPortPc()) != ERR_OK) { + if (self->getUdpIf()->udpConnect( + const_cast(self->getPcb()), + &addr, + self->getPortDest() + ) != ERR_OK) + { goto out; } - if (caller->getUdpInterface()->udpSend(const_cast(caller->getPcb()), pPbuf) != ERR_OK) { + if (self->getUdpIf()->udpSend( + const_cast(self->getPcb()), + p_pbuf + ) != ERR_OK) + { goto disconnect; } success = true; disconnect: - caller->getUdpInterface()->udpDisconnect(const_cast(caller->getPcb())); + self->getUdpIf()->udpDisconnect( + const_cast(self->getPcb()) + ); out: return success; @@ -65,31 +73,33 @@ static bool transmitImpl(UdpDriver* caller, struct pbuf * pPbuf) { namespace udp { -/************************** UdpDriver ***************************/ // Public // ---------------------------------------------------------------------------- +UdpDriver::UdpDriver() +{ -UdpDriver::UdpDriver() { } -UdpDriver::UdpDriver(const ip_addr_t ipaddrIn, - const ip_addr_t ipaddrPcIn, - const u16_t portIn, - const u16_t portPcIn, - const UdpRawInterface *udpInterfaceIn, - const OsInterface *osInterfaceIn - ) : - ipaddr(ipaddrIn), - ipaddrPc(ipaddrPcIn), - port(portIn), - portPc(portPcIn), - udpInterface(udpInterfaceIn), - osInterface(osInterfaceIn) +UdpDriver::UdpDriver( + const ip_addr_t m_ip_addr_src, + const ip_addr_t m_ip_addr_dest, + const u16_t m_port_src, + const u16_t m_port_dest, + const UdpRawInterface *m_udp_if, + const OsInterface *m_os_if +) : + m_ip_addr_src(m_ip_addr_src), + m_ip_addr_dest(m_ip_addr_dest), + m_port_src(m_port_src), + m_port_dest(m_port_dest), + m_udp_if(m_udp_if), + m_os_if(m_os_if) { } -UdpDriver::~UdpDriver() { +UdpDriver::~UdpDriver() +{ } @@ -97,18 +107,27 @@ UdpDriver::~UdpDriver() { * @brief initialize UdpDriver and do critical checks. * @return false if a check fails, true if initialization completes successfully. */ -bool UdpDriver::initialize() { - if (!getUdpInterface() || !getOsInterface()) { +bool UdpDriver::initialize() +{ + if (!getUdpIf() || !getOsIf()) + { return false; } - osSemaphoreStaticDef(UdpDriverRecv, &recvSemaphoreControlBlock); - if ((recvSemaphore = getOsInterface()->OS_osSemaphoreCreate(osSemaphore(UdpDriverRecv), 1)) == NULL) { + osSemaphoreStaticDef(UdpDriverRecv, &m_recv_semaphore_control_block); + if ((m_recv_semaphore = getOsIf()->OS_osSemaphoreCreate( + osSemaphore(UdpDriverRecv), + 1 + )) == NULL) + { return false; } - osMutexStaticDef(UdpDriverRecvPbuf, &recvPbufMutexControlBlock); - if ((recvPbufMutex = getOsInterface()->OS_osMutexCreate(osMutex(UdpDriverRecvPbuf))) == NULL) { + osMutexStaticDef(UdpDriverRecvPbuf, &m_recv_pbuf_mutex_control_block); + if ((m_recv_pbuf_mutex = getOsIf()->OS_osMutexCreate( + osMutex(UdpDriverRecvPbuf) + )) == NULL) + { return false; } @@ -116,25 +135,39 @@ bool UdpDriver::initialize() { } /** - * @brief set up UdpDriver to receive UdpPackets, calling recvCallback when a packet is received. - * @param recvCallback callback function to call when lwIP detects a packet has been received. + * @brief set up UdpDriver to receive UDP packets, calling recvCallback when a packet is received. + * @param recv_callback callback function to call when lwIP detects a packet has been received. * @return true if setup completed successfully, false otherwise. */ -bool UdpDriver::setupReceive(udp_recv_fn recvCallback) { +bool UdpDriver::setupReceive(udp_recv_fn recv_callback) +{ bool success = false; - pcb = getUdpInterface()->udpNew(); + m_pcb = getUdpIf()->udpNew(); - if (!getPcb()) { + if (!getPcb()) + { return false; } - success = (getUdpInterface()->udpBind(const_cast(getPcb()), &ipaddr, port) == ERR_OK); - - if (success) { - udp_recv_fn callback = (recvCallback == nullptr) ? defaultRecvCallback : recvCallback; - getUdpInterface()->udpRecv(const_cast(getPcb()), callback, this); - } else { + success = (getUdpIf()->udpBind( + const_cast(getPcb()), + &m_ip_addr_src, + getPortSrc() + ) == ERR_OK); + + if (success) + { + udp_recv_fn callback = (recv_callback == nullptr) + ? defaultRecvCallback : recv_callback; + getUdpIf()->udpRecv( + const_cast(getPcb()), + callback, + this + ); + } + else + { forgetPcb(); } @@ -143,19 +176,21 @@ bool UdpDriver::setupReceive(udp_recv_fn recvCallback) { /** * @brief Wait for a packet to be available to read, and read the packet into rxArrayOut. Cleans up the packet read from lwIP. - * @param rxArrayOut array to read packet data payload into. - * @param numBytes the maximum number of bytes to read from the packet (should not be greater than the length of rxArrayout). + * @param rx_array_out array to read packet data payload into. + * @param num_bytes the maximum number of bytes to read from the packet (should not be greater than the length of rxArrayout). * @return true if read packet successfully, false if failed to read the packet into rxArrayOut. */ -bool UdpDriver::receive(uint8_t *rxArrayOut, const size_t numBytes) { +bool UdpDriver::receive(uint8_t *rx_array_out, const size_t num_bytes) +{ bool success = false; - struct pbuf *recvPbuf = nullptr; + struct pbuf *recv_pbuf = nullptr; waitReceiveCplt(); - recvPbuf = getRecvPbuf(); + recv_pbuf = getRecvPbuf(); - if (packetToBytes(rxArrayOut, numBytes, recvPbuf) <= (u16_t) 0) { + if (packetToBytes(rx_array_out, num_bytes, recv_pbuf) <= (u16_t) 0) + { goto out; } @@ -163,7 +198,8 @@ bool UdpDriver::receive(uint8_t *rxArrayOut, const size_t numBytes) { out: - if (recvPbuf) { + if (recv_pbuf) + { forgetRecvPbuf(); } @@ -171,35 +207,45 @@ bool UdpDriver::receive(uint8_t *rxArrayOut, const size_t numBytes) { } /** - * @brief transmit data from txArrayIn through UDP. Allocates and cleans up a new packet internally. - * @param txArrayIn array holding data to transmit. - * @param number of bytes to transmit. + * @brief transmit data from txArrayIn through UDP. Allocates and cleans up a new temporary packet internally. + * @param tx_array_in array holding data to transmit. + * @param num_bytes number of bytes to transmit. * @return true if the data was transmitted successfully, false otherwise. */ -bool UdpDriver::transmit(const uint8_t *txArrayIn, const size_t numBytes) { +bool UdpDriver::transmit(const uint8_t *tx_array_in, const size_t num_bytes) +{ bool success = false; /* TODO: see if this can be allocated once at setup, if numBytes is known and unchanging. */ - struct pbuf *allocPbuf = getUdpInterface()->pbufAlloc(PBUF_TRANSPORT, numBytes, PBUF_RAM); - if (!allocPbuf) { + struct pbuf *temp_pbuf = getUdpIf()->pbufAlloc( + PBUF_TRANSPORT, + num_bytes, + PBUF_RAM + ); + if (!temp_pbuf) + { goto out; } - if (!bytesToPacket(txArrayIn, numBytes, allocPbuf)) { + if (!bytesToPacket(tx_array_in, num_bytes, temp_pbuf)) + { goto out; } - if (!transmitImpl(this, allocPbuf)) { + if (!transmitImpl(this, temp_pbuf)) + { goto out; } success = true; out: - if (allocPbuf) { + if (temp_pbuf) + { /* Error if zero pbufs freed for the one just allocated for Tx. */ - if ((success = getUdpInterface()->pbufFree(allocPbuf) > (u8_t) 0)) { - allocPbuf = nullptr; + if ((success = getUdpIf()->pbufFree(temp_pbuf) > (u8_t) 0)) + { + temp_pbuf = nullptr; } } @@ -208,106 +254,152 @@ bool UdpDriver::transmit(const uint8_t *txArrayIn, const size_t numBytes) { /** * @brief Copy the received packet to byteArrayOut, to a maximum of numBytes. - * @param byteArrayOut the array to copy the bytes from the packet to. - * @param numBytes the maximum number of bytes to copy (should not be greater than the size of byteArrayOut). - * @param pPbuf pointer to the packet (pbuf) to copy the bytes from. - * @return the number of bytes copied to byteArrayOut. + * @param byte_array_out the array to copy the bytes from the packet to. + * @param num_bytes the maximum number of bytes to copy (should not be greater than the size of byteArrayOut). + * @param p_pbuf pointer to the packet (pbuf) to copy the bytes from. + * @return the number of bytes copied to byte_array_out. */ -u16_t UdpDriver::packetToBytes(uint8_t *byteArrayOut, const size_t numBytes, struct pbuf *pPbuf) const { - if (!byteArrayOut || !pPbuf) { +u16_t UdpDriver::packetToBytes( + uint8_t *byte_array_out, + const size_t num_bytes, + struct pbuf *p_pbuf + ) const +{ + if (!byte_array_out || !p_pbuf) + { return (u16_t) 0; } - return getUdpInterface()->pbufCopyPartial(pPbuf, byteArrayOut, numBytes, 0); + return getUdpIf()->pbufCopyPartial( + p_pbuf, + byte_array_out, + num_bytes, + 0 + ); } /** - * @brief Copy numBytes from byteArrayIn to a packet. - * @param byteArrayOut the array to copy the bytes to the packet from. - * @param numBytes the number of bytes to copy from byteArrayIn. - * @param pPbuf pointer to the packet (pbuf) to copy the bytes to. + * @brief Copy num_bytes from byte_array_in to a packet. + * @param byte_array_in the array to copy the bytes to the packet from. + * @param num_bytes the number of bytes to copy from byte_array_in. + * @param p_pbuf pointer to the packet (pbuf) to copy the bytes to. * @return true if copied numBytes succesfully, false otherwise. */ -bool UdpDriver::bytesToPacket(const uint8_t *byteArrayIn, const size_t numBytes, struct pbuf *pPbuf) const { - if (!byteArrayIn || !pPbuf) { +bool UdpDriver::bytesToPacket( + const uint8_t *byte_array_in, + const size_t num_bytes, + struct pbuf *p_pbuf) const +{ + if (!byte_array_in || !p_pbuf) + { return false; } - return (getUdpInterface()->pbufTake(pPbuf, byteArrayIn, numBytes) == ERR_OK); + return (getUdpIf()->pbufTake(p_pbuf, byte_array_in, num_bytes) + == ERR_OK); } -void UdpDriver::signalReceiveCplt() { - getOsInterface()->OS_osSemaphoreRelease(recvSemaphore); +void UdpDriver::signalReceiveCplt() +{ + getOsIf()->OS_osSemaphoreRelease(m_recv_semaphore); } -void UdpDriver::waitReceiveCplt() { - while (getOsInterface()->OS_osSemaphoreWait(recvSemaphore, SEMAPHORE_WAIT_NUM_MS) != osOK) { +void UdpDriver::waitReceiveCplt() +{ + while (getOsIf()->OS_osSemaphoreWait( + m_recv_semaphore, + SEMAPHORE_WAIT_NUM_MS + ) != osOK) + { ; } } -void UdpDriver::setRecvPbuf(struct pbuf *pPbuf) { - while (getOsInterface()->OS_osMutexWait(recvPbufMutex, SEMAPHORE_WAIT_NUM_MS) != osOK) { +void UdpDriver::setRecvPbuf(struct pbuf *p_pbuf) +{ + while (getOsIf()->OS_osMutexWait( + m_recv_pbuf_mutex, + SEMAPHORE_WAIT_NUM_MS + ) != osOK) + { ; } - recvPbuf = pPbuf; - getOsInterface()->OS_osMutexRelease(recvPbufMutex); + m_recv_pbuf = p_pbuf; + getOsIf()->OS_osMutexRelease(m_recv_pbuf_mutex); } -const ip_addr_t UdpDriver::getIpaddr() const { - return ipaddr; +const ip_addr_t UdpDriver::getIpAddrSrc() const +{ + return m_ip_addr_src; } -const ip_addr_t UdpDriver::getIpaddrPc() const { - return ipaddrPc; +const ip_addr_t UdpDriver::getIpAddrDest() const +{ + return m_ip_addr_dest; } -const u16_t UdpDriver::getPort() const { - return port; +const u16_t UdpDriver::getPortSrc() const +{ + return m_port_src; } -const u16_t UdpDriver::getPortPc() const { - return portPc; +const u16_t UdpDriver::getPortDest() const +{ + return m_port_dest; } -const UdpRawInterface* UdpDriver::getUdpInterface() const { - return udpInterface; +const UdpRawInterface* UdpDriver::getUdpIf() const +{ + return m_udp_if; } -const OsInterface* UdpDriver::getOsInterface() const { - return osInterface; +const OsInterface* UdpDriver::getOsIf() const +{ + return m_os_if; } -struct udp_pcb* UdpDriver::getPcb() const { - return pcb; +struct udp_pcb* UdpDriver::getPcb() const +{ + return m_pcb; } -struct pbuf* UdpDriver::getRecvPbuf() const { - while (getOsInterface()->OS_osMutexWait(recvPbufMutex, SEMAPHORE_WAIT_NUM_MS) != osOK) { +struct pbuf* UdpDriver::getRecvPbuf() const +{ + while (getOsIf()->OS_osMutexWait( + m_recv_pbuf_mutex, + SEMAPHORE_WAIT_NUM_MS + ) != osOK) + { ; } - struct pbuf *pPbuf = recvPbuf; - getOsInterface()->OS_osMutexRelease(recvPbufMutex); - return pPbuf; + struct pbuf *p_pbuf = m_recv_pbuf; + getOsIf()->OS_osMutexRelease(m_recv_pbuf_mutex); + return p_pbuf; } -void UdpDriver::forgetRecvPbuf() { - while (getOsInterface()->OS_osMutexWait(recvPbufMutex, SEMAPHORE_WAIT_NUM_MS) != osOK) { +void UdpDriver::forgetRecvPbuf() +{ + while (getOsIf()->OS_osMutexWait( + m_recv_pbuf_mutex, + SEMAPHORE_WAIT_NUM_MS + ) != osOK) + { ; } - getUdpInterface()->pbufFree(recvPbuf); + getUdpIf()->pbufFree(m_recv_pbuf); setRecvPbuf(nullptr); - getOsInterface()->OS_osMutexRelease(recvPbufMutex); + getOsIf()->OS_osMutexRelease(m_recv_pbuf_mutex); } -void UdpDriver::forgetPcb() { - getUdpInterface()->udpRemove(const_cast(getPcb())); - pcb = nullptr; +void UdpDriver::forgetPcb() +{ + getUdpIf()->udpRemove(const_cast(getPcb())); + m_pcb = nullptr; } -} // end namespace udp_driver +} // end namespace udp /** * @} */ -/* end - udp_driver */ +/* end - udp */ diff --git a/Common/component/UdpDriver/UdpDriver.h b/Common/component/UdpDriver/UdpDriver.h index 9180ab9d..1a296251 100644 --- a/Common/component/UdpDriver/UdpDriver.h +++ b/Common/component/UdpDriver/UdpDriver.h @@ -4,7 +4,7 @@ * @author Robert Fairley * @brief Abstraction over UDP library providing common driver functions. * - * @defgroup Header + * @defgroup HeaderUdpDriver * @ingroup lwip * @{ ***************************************************************************** @@ -26,8 +26,6 @@ using cmsis::OsInterface; using lwip::UdpRawInterface; - -/************************** udp_driver **************************/ namespace udp { // Constants @@ -40,69 +38,75 @@ constexpr TickType_t SEMAPHORE_WAIT_NUM_TICKS = pdMS_TO_TICKS(SEMAPHORE_WAIT_NUM class UdpDriver { public: UdpDriver(); - UdpDriver(const ip_addr_t ipaddrIn, - const ip_addr_t ipaddrPcIn, - const u16_t portIn, - const u16_t portPcIn, - const UdpRawInterface *udpInterfaceIn, - const OsInterface *osInterfaceIn); + UdpDriver(const ip_addr_t m_ip_addr_src, + const ip_addr_t m_ip_addr_dest, + const u16_t m_port_src, + const u16_t m_port_dest, + const UdpRawInterface *m_udp_if, + const OsInterface *m_os_if); ~UdpDriver(); /* User-facing - typically call directly. */ bool initialize(); - bool setupReceive(udp_recv_fn recvCallback); - bool receive(uint8_t *rxArrayOut, const size_t numBytes); - bool transmit(const uint8_t *txArrayIn, const size_t numBytes); + bool setupReceive(udp_recv_fn recv_callback); + bool receive(uint8_t *rx_array_out, const size_t num_bytes); + bool transmit(const uint8_t *tx_array_in, const size_t num_bytes); /* Utility - public but typically no need to call directly. */ - bool bytesToPacket(const uint8_t *byteArrayIn, const size_t numBytes, struct pbuf *pPbuf) const; - u16_t packetToBytes(uint8_t *byteArrayOut, const size_t numBytes, struct pbuf *pPbuf) const; + bool bytesToPacket( + const uint8_t *byte_array_in, + const size_t num_bytes, + struct pbuf *p_pbuf + ) const; + u16_t packetToBytes( + uint8_t *byte_array_out, + const size_t num_bytes, + struct pbuf *p_pbuf + ) const; void signalReceiveCplt(); void waitReceiveCplt(); - - /* Accessors - public but typically no need to call directly. */ - void setRecvPbuf(struct pbuf *pPbuf); - - const ip_addr_t getIpaddr() const; - const ip_addr_t getIpaddrPc() const; - const u16_t getPort() const; - const u16_t getPortPc() const; - const UdpRawInterface* getUdpInterface() const; - const OsInterface* getOsInterface() const; - struct udp_pcb* getPcb() const; - struct pbuf* getRecvPbuf() const; - void forgetPcb(); void forgetRecvPbuf(); + /* Accessors - public but typically no need to call directly. */ + void setRecvPbuf(struct pbuf *p_pbuf); + const ip_addr_t getIpAddrSrc() const; + const ip_addr_t getIpAddrDest() const; + const u16_t getPortSrc() const; + const u16_t getPortDest() const; + const UdpRawInterface* getUdpIf() const; + const OsInterface* getOsIf() const; + struct udp_pcb* getPcb() const; + struct pbuf* getRecvPbuf() const; + private: /* UdpDriver configuration. */ - const ip_addr_t ipaddr = {0x0}; - const ip_addr_t ipaddrPc = {0x0}; - const u16_t port = 0; - const u16_t portPc = 0; + const ip_addr_t m_ip_addr_src = {0x0}; + const ip_addr_t m_ip_addr_dest = {0x0}; + const u16_t m_port_src = 0; + const u16_t m_port_dest = 0; /* External interfaces. */ - const UdpRawInterface *udpInterface = nullptr; - const OsInterface *osInterface = nullptr; + const UdpRawInterface *m_udp_if = nullptr; + const OsInterface *m_os_if = nullptr; /* Data modified internally by the Raw API. */ /* TODO: decide whether NULL or nullptr, since lwIP API will use NULL when setting these. */ - struct udp_pcb *pcb = nullptr; - struct pbuf *recvPbuf = nullptr; + struct udp_pcb *m_pcb = nullptr; + struct pbuf *m_recv_pbuf = nullptr; /* Synchronization. */ - mutable osSemaphoreId recvSemaphore; /* TODO: replace with binary semaphore-style task notification. */ - mutable osStaticSemaphoreDef_t recvSemaphoreControlBlock; - mutable osMutexId recvPbufMutex; - mutable osStaticMutexDef_t recvPbufMutexControlBlock; + mutable osSemaphoreId m_recv_semaphore; /* TODO: replace with binary semaphore-style task notification. */ + mutable osStaticSemaphoreDef_t m_recv_semaphore_control_block; + mutable osMutexId m_recv_pbuf_mutex; + mutable osStaticMutexDef_t m_recv_pbuf_mutex_control_block; }; -} // end namespace udp_driver +} // end namespace lwip /** * @} */ -/* end - Header */ +/* end - HeaderUdpDriver */ #endif /* UDP_DRIVER_H */ diff --git a/Common/hardware/GpioInterfaceImpl.cpp b/Common/hardware/GpioInterfaceImpl.cpp index ea436048..7bb2e720 100644 --- a/Common/hardware/GpioInterfaceImpl.cpp +++ b/Common/hardware/GpioInterfaceImpl.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file GpioInterfaceImpl.cpp + * @file * @author Tyler Gamvrelis * * @defgroup Implementation diff --git a/Common/hardware/GpioInterfaceImpl.h b/Common/hardware/GpioInterfaceImpl.h index 783fe7dd..fdb998ca 100644 --- a/Common/hardware/GpioInterfaceImpl.h +++ b/Common/hardware/GpioInterfaceImpl.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file GpioInterfaceImpl.h + * @file * @author Tyler Gamvrelis * * @defgroup Header diff --git a/Common/hardware/HalI2cInterface.cpp b/Common/hardware/I2CInterfaceImpl.cpp similarity index 77% rename from Common/hardware/HalI2cInterface.cpp rename to Common/hardware/I2CInterfaceImpl.cpp index 70b828de..5737f761 100644 --- a/Common/hardware/HalI2cInterface.cpp +++ b/Common/hardware/I2CInterfaceImpl.cpp @@ -1,10 +1,10 @@ /** ***************************************************************************** - * @file HalI2CInterface.cpp + * @file * @author Hannah * @brief Performs HAL related functions for I2C Interface * - * @defgroup HalI2CInterface + * @defgroup I2CInterfaceImpl * @ingroup I2C * @brief HAL related functions for I2C Interface * @{ @@ -12,16 +12,16 @@ */ /********************************* Includes **********************************/ -#include "HalI2CInterface.h" +#include "I2CInterfaceImpl.h" namespace hal{ /**************************** HAL I2C Interface ******************************/ // Public -HALI2CInterface::HALI2CInterface() {} -HALI2CInterface::~HALI2CInterface() {} +I2CInterfaceImpl::I2CInterfaceImpl() {} +I2CInterfaceImpl::~I2CInterfaceImpl() {} -HAL_StatusTypeDef HALI2CInterface::memWrite(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, +HAL_StatusTypeDef I2CInterfaceImpl::memWrite(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout) const { //HAL_I2C_Mem_Write @@ -29,21 +29,21 @@ HAL_StatusTypeDef HALI2CInterface::memWrite(I2C_HandleTypeDef *i2cHandlePtr, uin pData, Size, Timeout); } -HAL_StatusTypeDef HALI2CInterface::memRead(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, +HAL_StatusTypeDef I2CInterfaceImpl::memRead(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout) const { //HAL_I2C_Mem_Read return HAL_I2C_Mem_Read(i2cHandlePtr, DevAddress, MemAddress, MemAddSize, pData, Size, Timeout); } -HAL_StatusTypeDef HALI2CInterface::memWriteIT(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, +HAL_StatusTypeDef I2CInterfaceImpl::memWriteIT(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size) const { //HAL_I2C_Mem_Write_IT return HAL_I2C_Mem_Write_IT(i2cHandlePtr, DevAddress, MemAddress, MemAddSize, pData, Size); } -HAL_StatusTypeDef HALI2CInterface::memReadIT(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, +HAL_StatusTypeDef I2CInterfaceImpl::memReadIT(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size) const { //HAL_I2C_Mem_Read_IT return HAL_I2C_Mem_Read_IT(i2cHandlePtr, DevAddress, MemAddress, MemAddSize, @@ -56,5 +56,5 @@ HAL_StatusTypeDef HALI2CInterface::memReadIT(I2C_HandleTypeDef *i2cHandlePtr, ui /** * @} */ -/* end - HalI2CInterface */ +/* end - I2CInterfaceImpl */ diff --git a/Common/hardware/HalI2CInterface.h b/Common/hardware/I2CInterfaceImpl.h similarity index 81% rename from Common/hardware/HalI2CInterface.h rename to Common/hardware/I2CInterfaceImpl.h index d807aa3a..dda87cb4 100644 --- a/Common/hardware/HalI2CInterface.h +++ b/Common/hardware/I2CInterfaceImpl.h @@ -1,17 +1,17 @@ /** ***************************************************************************** - * @file HalI2CInterface.h + * @file * @author Hannah L - * @brief Defines the HALI2CInterface class, which calls HAL functions related to I2C + * @brief Defines the I2CInterfaceImpl class, which calls HAL functions related to I2C * - * @defgroup HalI2CInterface + * @defgroup I2CInterfaceImpl * @ingroup I2C * @{ ***************************************************************************** */ -#ifndef COMMON_HALI2CINTERFACE_H_ -#define COMMON_HALI2CINTERFACE_H_ +#ifndef COMMON_I2CINTERFACEIMPL_H_ +#define COMMON_I2CINTERFACEIMPL_H_ /********************************* Includes **********************************/ @@ -24,10 +24,10 @@ namespace hal{ * @class Concrete HAL implementation of the abstract I2CInterface class, to be * used in production builds */ -class HALI2CInterface: public I2CInterface { +class I2CInterfaceImpl: public I2CInterface { public: - HALI2CInterface(); - ~HALI2CInterface(); + I2CInterfaceImpl(); + ~I2CInterfaceImpl(); HAL_StatusTypeDef memWrite(I2C_HandleTypeDef *i2cHandlePtr, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout) const; //HAL_I2C_Mem_Write @@ -47,4 +47,4 @@ class HALI2CInterface: public I2CInterface { */ /* end - Header */ -#endif /* COMMON_HALI2CINTERFACE_H_ */ +#endif /* COMMON_I2CINTERFACEIMPL_H_ */ diff --git a/Common/hardware/OsInterfaceImpl.cpp b/Common/hardware/OsInterfaceImpl.cpp index 64caed6a..5a7d9c09 100644 --- a/Common/hardware/OsInterfaceImpl.cpp +++ b/Common/hardware/OsInterfaceImpl.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file OsInterfaceImpl.cpp + * @file * @author Izaak Niksan * @brief Implements the FreeRTOS wrapper class, which makes direct calls * to the true functions defined in the FreeRTOS library diff --git a/Common/hardware/OsInterfaceImpl.h b/Common/hardware/OsInterfaceImpl.h index d1efcf74..c51512d6 100644 --- a/Common/hardware/OsInterfaceImpl.h +++ b/Common/hardware/OsInterfaceImpl.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file OsInterfaceImpl.h + * @file * @author Izaak Niksan * @brief An interface to various production FreeRTOS functions, which serves * as a wrapper to the true functionality of the OS. @@ -76,7 +76,7 @@ class OsInterfaceImpl : public OsInterface{ osMutexId OS_osMutexCreate ( const osMutexDef_t *mutex_def ) const override final; - + osSemaphoreId OS_osSemaphoreCreate ( const osSemaphoreDef_t *semaphore_def, int32_t count diff --git a/Common/hardware/HalUartInterface.cpp b/Common/hardware/UartInterfaceImpl.cpp similarity index 89% rename from Common/hardware/HalUartInterface.cpp rename to Common/hardware/UartInterfaceImpl.cpp index 93e06b65..958123c1 100644 --- a/Common/hardware/HalUartInterface.cpp +++ b/Common/hardware/UartInterfaceImpl.cpp @@ -1,9 +1,9 @@ /** ***************************************************************************** - * @file HalUartInterface.cpp + * @file * @author Tyler Gamvrelis * - * @defgroup HalUartInterface + * @defgroup UartInterfaceImpl * @brief Implements UartInterface using HAL functions * @{ ***************************************************************************** @@ -13,7 +13,7 @@ /********************************* Includes **********************************/ -#include "HalUartInterface.h" +#include "UartInterfaceImpl.h" @@ -112,14 +112,14 @@ HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart) namespace hal{ -/***************************** HalUartInterface ******************************/ +/***************************** UartInterfaceImpl ******************************/ // Public // ---------------------------------------------------------------------------- -HalUartInterface::HalUartInterface(){;} +UartInterfaceImpl::UartInterfaceImpl(){;} -HalUartInterface::~HalUartInterface(){;} +UartInterfaceImpl::~UartInterfaceImpl(){;} -HAL_StatusTypeDef HalUartInterface::transmitPoll( +HAL_StatusTypeDef UartInterfaceImpl::transmitPoll( const UART_HandleTypeDef* uartHandlePtr, uint8_t* arrTransmit, size_t numBytes, @@ -136,7 +136,7 @@ HAL_StatusTypeDef HalUartInterface::transmitPoll( return status; } -HAL_StatusTypeDef HalUartInterface::receivePoll( +HAL_StatusTypeDef UartInterfaceImpl::receivePoll( const UART_HandleTypeDef* uartHandlePtr, uint8_t* arrReceive, size_t numBytes, @@ -154,7 +154,7 @@ HAL_StatusTypeDef HalUartInterface::receivePoll( } #if defined(THREADED) -HAL_StatusTypeDef HalUartInterface::transmitIT( +HAL_StatusTypeDef UartInterfaceImpl::transmitIT( const UART_HandleTypeDef* uartHandlePtr, uint8_t* arrTransmit, size_t numBytes @@ -169,7 +169,7 @@ HAL_StatusTypeDef HalUartInterface::transmitIT( return status; } -HAL_StatusTypeDef HalUartInterface::receiveIT( +HAL_StatusTypeDef UartInterfaceImpl::receiveIT( const UART_HandleTypeDef* uartHandlePtr, uint8_t* arrReceive, size_t numBytes @@ -184,7 +184,7 @@ HAL_StatusTypeDef HalUartInterface::receiveIT( return status; } -HAL_StatusTypeDef HalUartInterface::transmitDMA( +HAL_StatusTypeDef UartInterfaceImpl::transmitDMA( const UART_HandleTypeDef* uartHandlePtr, uint8_t* arrTransmit, size_t numBytes @@ -199,7 +199,7 @@ HAL_StatusTypeDef HalUartInterface::transmitDMA( return status; } -HAL_StatusTypeDef HalUartInterface::receiveDMA( +HAL_StatusTypeDef UartInterfaceImpl::receiveDMA( const UART_HandleTypeDef* uartHandlePtr, uint8_t* arrReceive, size_t numBytes @@ -214,7 +214,7 @@ HAL_StatusTypeDef HalUartInterface::receiveDMA( return status; } -__IO uint32_t HalUartInterface::getDmaRxInstanceNDTR( +__IO uint32_t UartInterfaceImpl::getDmaRxInstanceNDTR( const UART_HandleTypeDef* uartHandlePtr ) const { @@ -223,7 +223,7 @@ __IO uint32_t HalUartInterface::getDmaRxInstanceNDTR( #endif -void HalUartInterface::abortTransmit( +void UartInterfaceImpl::abortTransmit( const UART_HandleTypeDef* uartHandlePtr ) const { @@ -232,7 +232,7 @@ void HalUartInterface::abortTransmit( ); } -void HalUartInterface::abortReceive( +void UartInterfaceImpl::abortReceive( const UART_HandleTypeDef* uartHandlePtr ) const { @@ -241,7 +241,7 @@ void HalUartInterface::abortReceive( ); } -__IO uint32_t HalUartInterface::getErrorCode( +__IO uint32_t UartInterfaceImpl::getErrorCode( const UART_HandleTypeDef* uartHandlePtr ) const { @@ -253,4 +253,4 @@ __IO uint32_t HalUartInterface::getErrorCode( /** * @} */ -/* end - HalUartInterface */ +/* end - UartInterfaceImpl */ diff --git a/Common/hardware/HalUartInterface.h b/Common/hardware/UartInterfaceImpl.h similarity index 88% rename from Common/hardware/HalUartInterface.h rename to Common/hardware/UartInterfaceImpl.h index 822b9143..f70c3c0d 100644 --- a/Common/hardware/HalUartInterface.h +++ b/Common/hardware/UartInterfaceImpl.h @@ -1,9 +1,9 @@ /** ***************************************************************************** - * @file HalUartInterface.h + * @file * @author Tyler Gamvrelis * - * @defgroup HalUartInterface + * @defgroup UartInterfaceImpl * @addtogroup UART * @{ ***************************************************************************** @@ -12,8 +12,8 @@ -#ifndef HAL_UART_INTERFACE_H -#define HAL_UART_INTERFACE_H +#ifndef UART_INTERFACE_IMPL_H +#define UART_INTERFACE_IMPL_H @@ -24,7 +24,7 @@ -/****************************** HalUartInterface *****************************/ +/****************************** UartInterfaceImpl *****************************/ namespace hal{ // Classes and structs // ---------------------------------------------------------------------------- @@ -32,10 +32,10 @@ namespace hal{ * @class Concrete implementation of the abstract UartInterface class, to be * used in production builds */ -class HalUartInterface : public UartInterface{ +class UartInterfaceImpl : public UartInterface{ public: - HalUartInterface(); - ~HalUartInterface(); + UartInterfaceImpl(); + ~UartInterfaceImpl(); HAL_StatusTypeDef transmitPoll( const UART_HandleTypeDef* uartHandlePtr, diff --git a/Common/hardware/UdpRawInterfaceImpl.cpp b/Common/hardware/UdpRawInterfaceImpl.cpp index 157b82d7..13d965a2 100644 --- a/Common/hardware/UdpRawInterfaceImpl.cpp +++ b/Common/hardware/UdpRawInterfaceImpl.cpp @@ -11,52 +11,88 @@ #include "UdpRawInterfaceImpl.h" -namespace lwip { +namespace lwip +{ -struct udp_pcb* UdpRawInterfaceImpl::udpNew() const { +struct udp_pcb* UdpRawInterfaceImpl::udpNew() const +{ return udp_new(); } -err_t UdpRawInterfaceImpl::udpBind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, - u16_t port) const { +err_t UdpRawInterfaceImpl::udpBind( + struct udp_pcb *pcb, + const ip_addr_t *ipaddr, + u16_t port +) const +{ return udp_bind(pcb, ipaddr, port); } -void UdpRawInterfaceImpl::udpRecv(struct udp_pcb *pcb, udp_recv_fn recv, - void *recv_arg) const { +void UdpRawInterfaceImpl::udpRecv( + struct udp_pcb *pcb, + udp_recv_fn recv, + void *recv_arg +) const +{ udp_recv(pcb, recv, recv_arg); } -void UdpRawInterfaceImpl::udpRemove(struct udp_pcb *pcb) const { +void UdpRawInterfaceImpl::udpRemove(struct udp_pcb *pcb) const +{ udp_remove(pcb); } -err_t UdpRawInterfaceImpl::udpConnect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, - u16_t port) const { +err_t UdpRawInterfaceImpl::udpConnect( + struct udp_pcb *pcb, + const ip_addr_t *ipaddr, + u16_t port +) const +{ return udp_connect(pcb, ipaddr, port); } -err_t UdpRawInterfaceImpl::udpSend(struct udp_pcb *pcb, struct pbuf *p) const { +err_t UdpRawInterfaceImpl::udpSend( + struct udp_pcb *pcb, + struct pbuf *p +) const +{ return udp_send(pcb, p); } -void UdpRawInterfaceImpl::udpDisconnect(struct udp_pcb *pcb) const { +void UdpRawInterfaceImpl::udpDisconnect(struct udp_pcb *pcb) const +{ udp_disconnect(pcb); } -u8_t UdpRawInterfaceImpl::pbufFree(struct pbuf *p) const { +u8_t UdpRawInterfaceImpl::pbufFree(struct pbuf *p) const +{ return pbuf_free(p); } -struct pbuf* UdpRawInterfaceImpl::pbufAlloc(pbuf_layer layer, u16_t length, pbuf_type type) const { +struct pbuf* UdpRawInterfaceImpl::pbufAlloc( + pbuf_layer layer, + u16_t length, + pbuf_type type +) const +{ return pbuf_alloc(layer, length, type); } -u16_t UdpRawInterfaceImpl::pbufCopyPartial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset) const { +u16_t UdpRawInterfaceImpl::pbufCopyPartial( + const struct pbuf *buf, + void *dataptr, u16_t len, + u16_t offset +) const +{ return pbuf_copy_partial(buf, dataptr, len, offset); } -err_t UdpRawInterfaceImpl::pbufTake(struct pbuf *buf, const void *dataptr, u16_t len) const { +err_t UdpRawInterfaceImpl::pbufTake( + struct pbuf *buf, + const void *dataptr, + u16_t len +) const +{ return pbuf_take(buf, dataptr, len); } diff --git a/Common/interface/GpioInterface.h b/Common/interface/GpioInterface.h index 163f95c7..9aaa2edf 100644 --- a/Common/interface/GpioInterface.h +++ b/Common/interface/GpioInterface.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file GpioInterface.h + * @file * @author Tyler Gamvrelis * @brief Abstract interface for GPIO functions * diff --git a/Common/interface/I2CInterface.h b/Common/interface/I2CInterface.h index ac51e1a7..32a1c663 100644 --- a/Common/interface/I2CInterface.h +++ b/Common/interface/I2CInterface.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file I2CInterface.h + * @file * @author Hannah L * * @defgroup I2CInterface @@ -9,8 +9,8 @@ ***************************************************************************** */ -#ifndef COMMON_INCLUDE_I2CINTERFACE_H_ -#define COMMON_INCLUDE_I2CINTERFACE_H_ +#ifndef COMMON_INCLUDE_I2CINTERFACE_H +#define COMMON_INCLUDE_I2CINTERFACE_H /********************************* Includes **********************************/ #include @@ -101,4 +101,4 @@ class I2CInterface { // ---------------------------------------------------------------------------- }// end namespace hal -#endif /* COMMON_INCLUDE_I2CINTERFACE_H_ */ +#endif /* COMMON_INCLUDE_I2CINTERFACE_H */ diff --git a/Common/interface/OsInterface.h b/Common/interface/OsInterface.h index cceb1df0..4a090b56 100644 --- a/Common/interface/OsInterface.h +++ b/Common/interface/OsInterface.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file OsInterface.h + * @file * @author Izaak Niksan * @brief Defines an abstract interface of FreeRTOS functions. * diff --git a/Common/interface/UartInterface.h b/Common/interface/UartInterface.h index f939cd09..ecd24062 100644 --- a/Common/interface/UartInterface.h +++ b/Common/interface/UartInterface.h @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file UartInterface.h + * @file * @author Tyler Gamvrelis * * @defgroup UartInterface diff --git a/Common/interface/UdpRawInterface.h b/Common/interface/UdpRawInterface.h index 7fd08d44..e65c7b28 100644 --- a/Common/interface/UdpRawInterface.h +++ b/Common/interface/UdpRawInterface.h @@ -4,29 +4,26 @@ * @author Robert Fairley * @brief Wrapper interface for UDP function calls from the lwIP Raw API. * - * @defgroup Header + * @defgroup HeaderUdpRawInterface * @defgroup lwip * @{ ***************************************************************************** */ -/* NB: defgroup used above since there is no .cpp file associated with this class. */ - #ifndef UDP_RAW_INTERFACE_H #define UDP_RAW_INTERFACE_H #include -#include -#include -#include +#include "lwip/netif.h" +#include "lwip/udp.h" +#include "lwip/arch.h" namespace lwip { class UdpRawInterface { public: - virtual ~UdpRawInterface() { - } + virtual ~UdpRawInterface() {} virtual struct udp_pcb *udpNew() const = 0; virtual err_t udpBind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) const = 0; @@ -48,6 +45,6 @@ class UdpRawInterface { /** * @} */ -/* end - Header */ +/* end - HeaderUdpRawInterface */ #endif /* UDP_INTERFACE_H */ diff --git a/Common/mock/MockGpioInterface.h b/Common/mock/GpioInterfaceMock.h similarity index 82% rename from Common/mock/MockGpioInterface.h rename to Common/mock/GpioInterfaceMock.h index 8f5878aa..f5285611 100644 --- a/Common/mock/MockGpioInterface.h +++ b/Common/mock/GpioInterfaceMock.h @@ -1,10 +1,10 @@ /** ***************************************************************************** - * @file MockGpioInterface.h + * @file * @author Tyler Gamvrelis * @brief Mocks GPIO functions * - * @defgroup MockGpioInterface + * @defgroup GpioInterfaceMock * @ingroup Mocks * @{ ***************************************************************************** @@ -13,8 +13,8 @@ -#ifndef MOCK_GPIO_INTERFACE_H -#define MOCK_GPIO_INTERFACE_H +#ifndef GPIO_INTERFACE_MOCK_H +#define GPIO_INTERFACE_MOCK_H @@ -34,7 +34,7 @@ namespace hal { namespace gmock { // Classes and structs // ---------------------------------------------------------------------------- -class MockGpioInterface : public GpioInterface{ +class GpioInterfaceMock : public GpioInterface{ public: MOCK_CONST_METHOD2( readPin, @@ -71,6 +71,6 @@ class MockGpioInterface : public GpioInterface{ /** * @} */ -/* end - MockGpioInterface */ +/* end - GpioInterfaceMock */ -#endif /* MOCK_GPIO_INTERFACE_H */ +#endif /* GPIO_INTERFACE_MOCK_H */ diff --git a/Common/mock/MockI2CInterface.h b/Common/mock/I2CInterfaceMock.h similarity index 84% rename from Common/mock/MockI2CInterface.h rename to Common/mock/I2CInterfaceMock.h index b3839c5e..47174bc8 100644 --- a/Common/mock/MockI2CInterface.h +++ b/Common/mock/I2CInterfaceMock.h @@ -1,17 +1,17 @@ /** ***************************************************************************** - * @file MockI2CInterface.h + * @file * @author Hannah L * @brief Defines the MockI2CInterface class using gmock * - * @defgroup MockI2CInterface + * @defgroup I2CInterfaceMock * @ingroup I2C * @{ ***************************************************************************** */ -#ifndef COMMON_INCLUDE_MOCKI2CINTERFACE_H_ -#define COMMON_INCLUDE_MOCKI2CINTERFACE_H_ +#ifndef COMMON_INCLUDE_I2CINTERFACEMOCK_H_ +#define COMMON_INCLUDE_I2CINTERFACEMOCK_H_ /********************************* Includes **********************************/ #include "I2CInterface.h" @@ -27,7 +27,7 @@ namespace gmock { /** * @class MockI2CInterface Emulates I2CInterface for unit testing purposes */ -class MockI2CInterface: public I2CInterface{ +class I2CInterfaceMock: public I2CInterface{ public: MOCK_CONST_METHOD1(assignHandle, void(I2C_HandleTypeDef *hi2c)); MOCK_CONST_METHOD6(memWrite , HAL_StatusTypeDef(uint16_t DevAddress, uint16_t MemAddress, @@ -45,4 +45,9 @@ class MockI2CInterface: public I2CInterface{ } // end namespace gmock } // end namespace hal -#endif /* COMMON_INCLUDE_MOCKI2CINTERFACE_H_ */ +/** + * @} + */ +/* end I2CInterfaceMock */ + +#endif /* COMMON_INCLUDE_I2CINTERFACEMOCK_H_ */ diff --git a/Common/mock/MockMotor.h b/Common/mock/MotorMock.h similarity index 82% rename from Common/mock/MockMotor.h rename to Common/mock/MotorMock.h index 0860fc0f..e88cf3b0 100644 --- a/Common/mock/MockMotor.h +++ b/Common/mock/MotorMock.h @@ -1,11 +1,11 @@ /** ***************************************************************************** - * @file MockMotor.h + * @file * @author Tyler Gamvrelis * @brief Since this is an abstract class, it needs to be mocked to test the * concrete methods * - * @defgroup MockMotor + * @defgroup MotorMock * @ingroup Mocks * @{ ***************************************************************************** @@ -14,8 +14,8 @@ -#ifndef MOCK_MOTOR_H -#define MOCK_MOTOR_H +#ifndef MOTOR_MOCK_H +#define MOTOR_MOCK_H @@ -32,18 +32,18 @@ using dynamixel::ResolutionDivider; -/****************************** MockMotorInterface ******************************/ +/****************************** MotorMockInterface ******************************/ namespace dynamixel { namespace gmock { // Classes and structs // ---------------------------------------------------------------------------- /** - * @class MockMotor Mocks the abstract methods of Motor so that it can be + * @class MotorMock Mocks the abstract methods of Motor so that it can be * unit tested */ -class MockMotor : public Motor { +class MotorMock : public Motor { public: - MockMotor( + MotorMock( uint8_t id, DaisyChain* daisyChain, ResolutionDivider divider @@ -84,6 +84,6 @@ class MockMotor : public Motor { /** * @} */ -/* end MockMotor */ +/* end MotorMock */ #endif /* MOCK_MOTOR_H */ diff --git a/Common/mock/MockOsInterface.h b/Common/mock/OsInterfaceMock.h similarity index 88% rename from Common/mock/MockOsInterface.h rename to Common/mock/OsInterfaceMock.h index 0e7ebf73..72fb8ec1 100644 --- a/Common/mock/MockOsInterface.h +++ b/Common/mock/OsInterfaceMock.h @@ -1,10 +1,10 @@ /** ***************************************************************************** - * @file MockOsInterface.h + * @file * @author Izaak Niksan * @author Tyler Gamvrelis * - * @defgroup MockOsInterface + * @defgroup OsInterfaceMock * @ingroup Mocks * @{ ***************************************************************************** @@ -13,8 +13,8 @@ -#ifndef MOCK_OS_INTERFACE_H -#define MOCK_OS_INTERFACE_H +#ifndef OS_INTERFACE_MOCK_H +#define OS_INTERFACE_MOCK_H @@ -29,16 +29,16 @@ using cmsis::OsInterface; -/****************************** MockOsInterface ******************************/ +/****************************** OsInterfaceMock ******************************/ namespace cmsis { namespace gmock { // Classes and structs // ---------------------------------------------------------------------------- /** - * @class MockOsInterface Implements OsInterface for unit testing + * @class OsInterfaceMock Implements OsInterface for unit testing * purposes */ -class MockOsInterface : public OsInterface { +class OsInterfaceMock : public OsInterface { public: MOCK_CONST_METHOD4( OS_xTaskNotifyWait, @@ -153,6 +153,6 @@ class MockOsInterface : public OsInterface { /** * @} */ -/* end - MockOsInterface */ +/* end - OsInterfaceMock */ -#endif /* MOCK_OS_INTERFACE_H */ +#endif /* OS_INTERFACE_MOCK_H */ diff --git a/Common/mock/MockUartInterface.h b/Common/mock/UartInterfaceMock.h similarity index 87% rename from Common/mock/MockUartInterface.h rename to Common/mock/UartInterfaceMock.h index 0049d10b..ed68bf9d 100644 --- a/Common/mock/MockUartInterface.h +++ b/Common/mock/UartInterfaceMock.h @@ -1,9 +1,9 @@ /** ***************************************************************************** - * @file MockUartInterface.h + * @file * @author Tyler Gamvrelis * - * @defgroup MockUartInterface + * @defgroup UartInterfaceMock * @ingroup Mocks * @{ ***************************************************************************** @@ -28,15 +28,15 @@ using hal::UartInterface; -/***************************** MockUartInterface *****************************/ +/***************************** UartInterfaceMock *****************************/ namespace hal { namespace gmock { // Classes and structs // ---------------------------------------------------------------------------- /** - * @class MockUartInterface Implements UartInterface for unit testing purposes + * @class UartInterfaceMock Implements UartInterface for unit testing purposes */ -class MockUartInterface : public UartInterface{ +class UartInterfaceMock : public UartInterface{ public: MOCK_CONST_METHOD4( transmitPoll, @@ -94,6 +94,6 @@ class MockUartInterface : public UartInterface{ /** * @} */ -/* end - MockUartInterface */ +/* end - UartInterfaceMock */ #endif /* MOCK_UART_INTERFACE_H */ diff --git a/Common/test/AX12A_test.cpp b/Common/test/AX12ATest.cpp similarity index 92% rename from Common/test/AX12A_test.cpp rename to Common/test/AX12ATest.cpp index fc517fbc..622fda94 100644 --- a/Common/test/AX12A_test.cpp +++ b/Common/test/AX12ATest.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file AX12A_test.cpp + * @file * @author Tyler Gamvrelis * * @defgroup AX12A_Test @@ -16,19 +16,19 @@ /********************************* Includes **********************************/ #include "Dynamixel/AX12A.h" -#include "MockUartInterface.h" -#include "MockOsInterface.h" -#include "MockGpioInterface.h" -#include "UartDriver/UartDriver.h" - #include #include +#include "GpioInterfaceMock.h" +#include "OsInterfaceMock.h" +#include "UartDriver/UartDriver.h" +#include "UartInterfaceMock.h" + using ::testing::_; -using cmsis::gmock::MockOsInterface; -using hal::gmock::MockUartInterface; -using hal::gmock::MockGpioInterface; +using cmsis::gmock::OsInterfaceMock; +using hal::gmock::UartInterfaceMock; +using hal::gmock::GpioInterfaceMock; using dynamixel::DaisyChainParams; using dynamixel::DaisyChain; @@ -66,9 +66,9 @@ class AX12ATest : public ::testing::Test { } UartDriver *UARTxDriver = nullptr; - MockUartInterface uart; - MockOsInterface os; - MockGpioInterface gpio; + UartInterfaceMock uart; + OsInterfaceMock os; + GpioInterfaceMock gpio; DaisyChainParams p; }; diff --git a/Common/test/Buffer_test.cpp b/Common/test/BufferTest.cpp similarity index 97% rename from Common/test/Buffer_test.cpp rename to Common/test/BufferTest.cpp index cfd5b430..30065dd1 100644 --- a/Common/test/Buffer_test.cpp +++ b/Common/test/BufferTest.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file Buffer_test.cpp + * @file * @author Gokul Dharan * * @defgroup Buffer_test @@ -16,11 +16,11 @@ /********************************* Includes **********************************/ #include "uart_handler.h" #include "PeripheralInstances.h" -#include "MockOsInterface.h" #include "BufferBase.h" #include #include +#include "OsInterfaceMock.h" using ::testing::DoAll; @@ -28,7 +28,7 @@ using ::testing::SetArgPointee; using ::testing::Return; using ::testing::_; -using cmsis::gmock::MockOsInterface; +using cmsis::gmock::OsInterfaceMock; using namespace buffer; @@ -43,7 +43,7 @@ osMutexId mutex = nullptr; // ---------------------------------------------------------------------------- class BufferTest : public ::testing::Test { protected: - MockOsInterface os; + OsInterfaceMock os; }; // Functions diff --git a/Common/test/CircularDmaBuffer_test.cpp b/Common/test/CircularDmaBufferTest.cpp similarity index 98% rename from Common/test/CircularDmaBuffer_test.cpp rename to Common/test/CircularDmaBufferTest.cpp index 0298f469..fa5c1d9a 100644 --- a/Common/test/CircularDmaBuffer_test.cpp +++ b/Common/test/CircularDmaBufferTest.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file CircularDmaBuffer_test.cpp + * @file * @author Robert * * @defgroup circular_dma_buffer_test @@ -13,13 +13,12 @@ /********************************* Includes **********************************/ #include "CircularDmaBuffer/CircularDmaBuffer.h" -#include "MockUartInterface.h" - #include #include +#include "UartInterfaceMock.h" using uart::CircularDmaBuffer; -using hal::gmock::MockUartInterface; +using hal::gmock::UartInterfaceMock; using ::testing::Return; using ::testing::_; @@ -58,7 +57,7 @@ class CircularDmaBufferTest : public ::testing::Test { /* buff_ is an automatically initialized CircularDmaBuffer object, to avoid * repeating code where only some default initialization is needed. */ CircularDmaBuffer* buff_ = nullptr; - MockUartInterface uart_if; + UartInterfaceMock uart_if; }; // Functions diff --git a/Common/test/DaisyChain_test.cpp b/Common/test/DaisyChainTest.cpp similarity index 90% rename from Common/test/DaisyChain_test.cpp rename to Common/test/DaisyChainTest.cpp index 8f41ada9..1601403c 100644 --- a/Common/test/DaisyChain_test.cpp +++ b/Common/test/DaisyChainTest.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file DaisyChain_test.cpp + * @file * @author Tyler Gamvrelis * * @defgroup DaisyChain_Test @@ -16,14 +16,12 @@ /********************************* Includes **********************************/ #include "DaisyChain/DaisyChain.h" -#include "DaisyChain/DaisyChain.h" -#include "MockUartInterface.h" -#include "MockOsInterface.h" -#include "MockGpioInterface.h" - #include #include +#include "GpioInterfaceMock.h" +#include "OsInterfaceMock.h" +#include "UartInterfaceMock.h" using ::testing::DoAll; using ::testing::Return; @@ -31,9 +29,9 @@ using ::testing::_; using uart::UartDriver; using hal::IO_Type; -using cmsis::gmock::MockOsInterface; -using hal::gmock::MockUartInterface; -using hal::gmock::MockGpioInterface; +using cmsis::gmock::OsInterfaceMock; +using hal::gmock::UartInterfaceMock; +using hal::gmock::GpioInterfaceMock; using dynamixel::DaisyChainParams; using dynamixel::DaisyChain; @@ -69,9 +67,9 @@ class DaisyChainShould : public ::testing::Test { } UartDriver *UARTxDriver = nullptr; - MockUartInterface uart; - MockOsInterface os; - MockGpioInterface gpio; + UartInterfaceMock uart; + OsInterfaceMock os; + GpioInterfaceMock gpio; DaisyChainParams p; }; diff --git a/Common/test/MX28_test.cpp b/Common/test/MX28Test.cpp similarity index 90% rename from Common/test/MX28_test.cpp rename to Common/test/MX28Test.cpp index 36fa3e9e..9b93f96f 100644 --- a/Common/test/MX28_test.cpp +++ b/Common/test/MX28Test.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file MX28_test.cpp + * @file * @author Tyler Gamvrelis * * @defgroup MX28_Test @@ -16,22 +16,22 @@ /********************************* Includes **********************************/ #include "Dynamixel/MX28.h" -#include "MockUartInterface.h" -#include "MockOsInterface.h" -#include "MockGpioInterface.h" #include "UartDriver/UartDriver.h" - #include #include +#include "GpioInterfaceMock.h" +#include "OsInterfaceMock.h" +#include "UartInterfaceMock.h" + using ::testing::_; using uart::UartDriver; -using cmsis::gmock::MockOsInterface; -using hal::gmock::MockUartInterface; -using hal::gmock::MockGpioInterface; +using cmsis::gmock::OsInterfaceMock; +using hal::gmock::UartInterfaceMock; +using hal::gmock::GpioInterfaceMock; using dynamixel::DaisyChainParams; using dynamixel::DaisyChain; @@ -69,9 +69,9 @@ class MX28Test : public ::testing::Test { } UartDriver *UARTxDriver = nullptr; - MockUartInterface uart; - MockOsInterface os; - MockGpioInterface gpio; + UartInterfaceMock uart; + OsInterfaceMock os; + GpioInterfaceMock gpio; DaisyChainParams p; }; diff --git a/Common/test/Motor_test.cpp b/Common/test/MotorTest.cpp similarity index 77% rename from Common/test/Motor_test.cpp rename to Common/test/MotorTest.cpp index 1d9a57d4..714cbc8e 100644 --- a/Common/test/Motor_test.cpp +++ b/Common/test/MotorTest.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file Motor_test.cpp + * @file * @author Tyler Gamvrelis * * @defgroup Motor_Test @@ -14,15 +14,14 @@ /********************************* Includes **********************************/ -#include "MockMotor.h" - -#include "MockUartInterface.h" -#include "MockOsInterface.h" -#include "MockGpioInterface.h" - #include #include +#include "GpioInterfaceMock.h" +#include "MotorMock.h" +#include "OsInterfaceMock.h" +#include "UartInterfaceMock.h" + using ::testing::_; using ::testing::Args; using ::testing::ElementsAreArray; @@ -31,10 +30,10 @@ using ::testing::Return; using uart::UartDriver; -using dynamixel::gmock::MockMotor; -using cmsis::gmock::MockOsInterface; -using hal::gmock::MockUartInterface; -using hal::gmock::MockGpioInterface; +using dynamixel::gmock::MotorMock; +using cmsis::gmock::OsInterfaceMock; +using hal::gmock::UartInterfaceMock; +using hal::gmock::GpioInterfaceMock; using dynamixel::Motor; using dynamixel::DaisyChainParams; @@ -76,9 +75,9 @@ class MotorTest : public ::testing::Test { } UartDriver *UARTxDriver = nullptr; - MockUartInterface uart; - MockOsInterface os; - MockGpioInterface gpio; + UartInterfaceMock uart; + OsInterfaceMock os; + GpioInterfaceMock gpio; DaisyChainParams p; }; @@ -89,13 +88,13 @@ class MotorTest : public ::testing::Test { // ---------------------------------------------------------------------------- TEST_F(MotorTest, CanBeCreated){ DaisyChain chain(p); - MockMotor m1(1, &chain, ResolutionDivider::AX12A); - MockMotor m2(1, &chain, ResolutionDivider::MX28); + MotorMock m1(1, &chain, ResolutionDivider::AX12A); + MotorMock m2(1, &chain, ResolutionDivider::MX28); } TEST_F(MotorTest, CanResetMotor){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.reset(); } @@ -103,22 +102,22 @@ TEST_F(MotorTest, CanResetMotor){ TEST_F(MotorTest, IdReturnsIdSetAtInitialization){ DaisyChain chain(p); - MockMotor m0(1, &chain, ResolutionDivider::AX12A); + MotorMock m0(1, &chain, ResolutionDivider::AX12A); ASSERT_EQ(m0.id(), 1); - MockMotor m1(2, &chain, ResolutionDivider::AX12A); + MotorMock m1(2, &chain, ResolutionDivider::AX12A); ASSERT_EQ(m1.id(), 2); - MockMotor m2(18, &chain, ResolutionDivider::AX12A); + MotorMock m2(18, &chain, ResolutionDivider::AX12A); ASSERT_EQ(m2.id(), 18); - MockMotor m3(42, &chain, ResolutionDivider::AX12A); + MotorMock m3(42, &chain, ResolutionDivider::AX12A); ASSERT_NE(m3.id(), 0); } TEST_F(MotorTest, setIdBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setId(10); @@ -128,7 +127,7 @@ TEST_F(MotorTest, setIdBoundsCheckPasses){ TEST_F(MotorTest, setReturnDelayTimeBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setReturnDelayTime(150); @@ -138,7 +137,7 @@ TEST_F(MotorTest, setReturnDelayTimeBoundsCheckPasses){ TEST_F(MotorTest, setCWAngleLimitBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setCwAngleLimit(dynamixel::MIN_ANGLE); @@ -148,7 +147,7 @@ TEST_F(MotorTest, setCWAngleLimitBoundsCheckPasses){ TEST_F(MotorTest, setCCWAngleLimitBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setCcwAngleLimit(dynamixel::MAX_ANGLE); @@ -158,7 +157,7 @@ TEST_F(MotorTest, setCCWAngleLimitBoundsCheckPasses){ TEST_F(MotorTest, setVoltageLimitsBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setVoltageLimit(VoltageLimit::HIGHEST, dynamixel::MAX_VOLTAGE); m.setVoltageLimit(VoltageLimit::LOWEST, dynamixel::MIN_VOLTAGE); @@ -174,7 +173,7 @@ TEST_F(MotorTest, setVoltageLimitsBoundsCheckPasses){ TEST_F(MotorTest, setMaxTorqueBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setMaxTorque(100.0); @@ -184,7 +183,7 @@ TEST_F(MotorTest, setMaxTorqueBoundsCheckPasses){ TEST_F(MotorTest, setStatusReturnLevelBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setStatusReturnLevel(StatusReturnLevel::PING_ONLY); m.setStatusReturnLevel(StatusReturnLevel::READS_ONLY); @@ -195,7 +194,7 @@ TEST_F(MotorTest, setStatusReturnLevelBoundsCheckPasses){ TEST_F(MotorTest, setAlarmBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setAlarm(AlarmType::LED, AlarmCondition::INPUT_VOLTAGE_ERR); m.setAlarm(AlarmType::SHUTDOWN, AlarmCondition::OVERHEATING_ERR); @@ -209,7 +208,7 @@ TEST_F(MotorTest, setAlarmBoundsCheckPasses){ TEST_F(MotorTest, CanEnableTorque){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.enableTorque(true); m.enableTorque(false); @@ -217,7 +216,7 @@ TEST_F(MotorTest, CanEnableTorque){ TEST_F(MotorTest, CanEnableLed){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.enableLed(true); m.enableLed(false); @@ -225,7 +224,7 @@ TEST_F(MotorTest, CanEnableLed){ TEST_F(MotorTest, setGoalPositionBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setGoalPosition(150.0); @@ -235,7 +234,7 @@ TEST_F(MotorTest, setGoalPositionBoundsCheckPasses){ TEST_F(MotorTest, setGoalTorqueBoundsCheckPasses){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setGoalTorque(100.0); @@ -245,14 +244,14 @@ TEST_F(MotorTest, setGoalTorqueBoundsCheckPasses){ TEST_F(MotorTest, CanLockEEPROM){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.lockEEPROM(); } TEST_F(MotorTest, CanSetPunch){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.setPunch(10.0); @@ -262,7 +261,7 @@ TEST_F(MotorTest, CanSetPunch){ TEST_F(MotorTest, CanGetGoalPosition){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); float angle = 0; m.getPosition(angle); @@ -270,7 +269,7 @@ TEST_F(MotorTest, CanGetGoalPosition){ TEST_F(MotorTest, CanGetLoad){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); float load = 0; m.getLoad(load); @@ -278,7 +277,7 @@ TEST_F(MotorTest, CanGetLoad){ TEST_F(MotorTest, CanGetVoltage){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); float voltage = 0; m.getVoltage(voltage); @@ -286,7 +285,7 @@ TEST_F(MotorTest, CanGetVoltage){ TEST_F(MotorTest, CanGetTemperature){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); uint8_t temp = 0; m.getTemperature(temp); @@ -294,7 +293,7 @@ TEST_F(MotorTest, CanGetTemperature){ TEST_F(MotorTest, CanCheckIfIsJointMode){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); bool isJointMode = false; m.isJointMode(isJointMode); @@ -302,7 +301,7 @@ TEST_F(MotorTest, CanCheckIfIsJointMode){ TEST_F(MotorTest, CanPing){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); uint8_t retrievedId; m.ping(retrievedId); @@ -310,7 +309,7 @@ TEST_F(MotorTest, CanPing){ TEST_F(MotorTest, CanCheckIfIsMoving){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); bool isMoving = false; m.isMoving(isMoving); @@ -318,21 +317,21 @@ TEST_F(MotorTest, CanCheckIfIsMoving){ TEST_F(MotorTest, CanEnterWheelMode){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.enterWheelMode(); } TEST_F(MotorTest, CanEnterJointMode){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); m.enterJointMode(); } TEST_F(MotorTest, ParsesReadDataExampleProperly){ DaisyChain chain(p); - MockMotor m(1, &chain, ResolutionDivider::AX12A); + MotorMock m(1, &chain, ResolutionDivider::AX12A); // AX12A datasheet page 20, section 4-2 uint8_t expectedTxArray[] = {0xFF, 0xFF, 0x01, 0x04, 0x02, 0x2B, 0x01, 0xCC}; diff --git a/Common/test/UartDriver_test.cpp b/Common/test/UartDriverTest.cpp similarity index 90% rename from Common/test/UartDriver_test.cpp rename to Common/test/UartDriverTest.cpp index 7da21a7d..4deebdd5 100644 --- a/Common/test/UartDriver_test.cpp +++ b/Common/test/UartDriverTest.cpp @@ -1,6 +1,6 @@ /** ***************************************************************************** - * @file UartDriver_test.cpp + * @file * @author Tyler Gamvrelis * * @defgroup UartDriver_Test @@ -18,12 +18,12 @@ #include "UartDriver/UartDriver.h" #include "Notification.h" -#include "MockUartInterface.h" -#include "MockOsInterface.h" - #include #include +#include "OsInterfaceMock.h" +#include "UartInterfaceMock.h" + using ::testing::DoAll; using ::testing::SetArgPointee; @@ -32,8 +32,8 @@ using ::testing::_; using uart::UartDriver; -using cmsis::gmock::MockOsInterface; -using hal::gmock::MockUartInterface; +using cmsis::gmock::OsInterfaceMock; +using hal::gmock::UartInterfaceMock; using hal::IO_Type; @@ -81,7 +81,7 @@ TEST(UartDriver, ShouldFailReceiveWithNullInitializers){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailTransmitWithNullUartInterface){ - MockOsInterface os; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; @@ -96,7 +96,7 @@ TEST(UartDriver, ShouldFailTransmitWithNullUartInterface){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailReceiveWithNullUartInterface){ - MockOsInterface os; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; @@ -111,8 +111,8 @@ TEST(UartDriver, ShouldFailReceiveWithNullUartInterface){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailTransmitWithNullUartHandle){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UartDriver UARTxDriver(&os, &uart, nullptr); @@ -125,8 +125,8 @@ TEST(UartDriver, ShouldFailTransmitWithNullUartHandle){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailReceiveWithNullUartHandle){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UartDriver UARTxDriver(&os, &uart, nullptr); @@ -139,7 +139,7 @@ TEST(UartDriver, ShouldFailReceiveWithNullUartHandle){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailTransmitITWithNullOSInterface){ - MockUartInterface uart; + UartInterfaceMock uart; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -154,7 +154,7 @@ TEST(UartDriver, ShouldFailTransmitITWithNullOSInterface){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailTransmitDMAWithNullOSInterface){ - MockUartInterface uart; + UartInterfaceMock uart; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -169,7 +169,7 @@ TEST(UartDriver, ShouldFailTransmitDMAWithNullOSInterface){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailReceiveITWithNullOSInterface){ - MockUartInterface uart; + UartInterfaceMock uart; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -184,7 +184,7 @@ TEST(UartDriver, ShouldFailReceiveITWithNullOSInterface){ // This is needed so that the driver won't work unless it's initialized // properly TEST(UartDriver, ShouldFailReceiveDMAWithNullOSInterface){ - MockUartInterface uart; + UartInterfaceMock uart; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -197,7 +197,7 @@ TEST(UartDriver, ShouldFailReceiveDMAWithNullOSInterface){ } TEST(UartDriver, ShouldCallTransmitPollForPollIOType){ - MockUartInterface uart; + UartInterfaceMock uart; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -212,8 +212,8 @@ TEST(UartDriver, ShouldCallTransmitPollForPollIOType){ } TEST(UartDriver, ShouldCallTransmitITPollForITIOType){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -228,8 +228,8 @@ TEST(UartDriver, ShouldCallTransmitITPollForITIOType){ } TEST(UartDriver, ShouldCallTransmitDMAForDMAIOType){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -244,8 +244,8 @@ TEST(UartDriver, ShouldCallTransmitDMAForDMAIOType){ } TEST(UartDriver, ShouldFailAndAbortTransmitPollWhenHardwareCallFails){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -263,8 +263,8 @@ TEST(UartDriver, ShouldFailAndAbortTransmitPollWhenHardwareCallFails){ } TEST(UartDriver, ShouldFailAndAbortTransmitITWhenHardwareCallFails){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -282,8 +282,8 @@ TEST(UartDriver, ShouldFailAndAbortTransmitITWhenHardwareCallFails){ } TEST(UartDriver, ShouldFailAndAbortTransmitDMAWhenHardwareCallFails){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -301,8 +301,8 @@ TEST(UartDriver, ShouldFailAndAbortTransmitDMAWhenHardwareCallFails){ } TEST(UartDriver, ShouldFailAndAbortTransmitITWhenOSBlockTimesOut){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -322,8 +322,8 @@ TEST(UartDriver, ShouldFailAndAbortTransmitITWhenOSBlockTimesOut){ } TEST(UartDriver, ShouldFailAndAbortTransmitDMAWhenOSBlockTimesOut){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -343,8 +343,8 @@ TEST(UartDriver, ShouldFailAndAbortTransmitDMAWhenOSBlockTimesOut){ } TEST(UartDriver, PollTransmitCanSucceed){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -360,8 +360,8 @@ TEST(UartDriver, PollTransmitCanSucceed){ } TEST(UartDriver, ITTransmitCanSucceed){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -379,8 +379,8 @@ TEST(UartDriver, ITTransmitCanSucceed){ } TEST(UartDriver, DMATransmitCanSucceed){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -398,8 +398,8 @@ TEST(UartDriver, DMATransmitCanSucceed){ } TEST(UartDriver, ShouldCallReceivePollForPollIOType){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -414,8 +414,8 @@ TEST(UartDriver, ShouldCallReceivePollForPollIOType){ } TEST(UartDriver, ShouldCallReceiveITForITIOType){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -430,8 +430,8 @@ TEST(UartDriver, ShouldCallReceiveITForITIOType){ } TEST(UartDriver, ShouldCallReceiveDMAForDMAIOType){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -446,8 +446,8 @@ TEST(UartDriver, ShouldCallReceiveDMAForDMAIOType){ } TEST(UartDriver, ShouldFailAndAbortReceivePollWhenHardwareCallFails){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -465,8 +465,8 @@ TEST(UartDriver, ShouldFailAndAbortReceivePollWhenHardwareCallFails){ } TEST(UartDriver, ShouldFailAndAbortReceiveITWhenHardwareCallFails){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -484,8 +484,8 @@ TEST(UartDriver, ShouldFailAndAbortReceiveITWhenHardwareCallFails){ } TEST(UartDriver, ShouldFailAndAbortReceiveDMAWhenHardwareCallFails){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -503,8 +503,8 @@ TEST(UartDriver, ShouldFailAndAbortReceiveDMAWhenHardwareCallFails){ } TEST(UartDriver, ShouldFailAndAbortReceiveITWhenOSBlockTimesOut){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -524,8 +524,8 @@ TEST(UartDriver, ShouldFailAndAbortReceiveITWhenOSBlockTimesOut){ } TEST(UartDriver, ShouldFailAndAbortReceiveDMAWhenOSBlockTimesOut){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -545,8 +545,8 @@ TEST(UartDriver, ShouldFailAndAbortReceiveDMAWhenOSBlockTimesOut){ } TEST(UartDriver, PollReceiveCanSucceed){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(nullptr, &uart, &UARTx); @@ -562,8 +562,8 @@ TEST(UartDriver, PollReceiveCanSucceed){ } TEST(UartDriver, ITReceiveCanSucceed){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); @@ -581,8 +581,8 @@ TEST(UartDriver, ITReceiveCanSucceed){ } TEST(UartDriver, DMAReceiveCanSucceed){ - MockUartInterface uart; - MockOsInterface os; + UartInterfaceMock uart; + OsInterfaceMock os; UART_HandleTypeDef UARTx = {0}; UartDriver UARTxDriver(&os, &uart, &UARTx); diff --git a/Common/test/UdpDriver_test.cpp b/Common/test/UdpDriverTest.cpp similarity index 92% rename from Common/test/UdpDriver_test.cpp rename to Common/test/UdpDriverTest.cpp index 375128fb..7c74561c 100644 --- a/Common/test/UdpDriver_test.cpp +++ b/Common/test/UdpDriverTest.cpp @@ -1,10 +1,10 @@ /** ***************************************************************************** - * @file UdpDriver_test.cpp + * @file * @author Robert Fairley * - * @defgroup udp_driver_test - * @ingroup udp_driver + * @defgroup UdpDriver_Test + * @ingroup UDP * @brief Unit tests for the UdpDriver class. * @{ ***************************************************************************** @@ -15,19 +15,16 @@ /********************************* Includes **********************************/ -#include -#include - #include #include -#include "UdpRawInterfaceMock.h" - - +#include "OsInterfaceMock.h" +#include "UdpRawInterfaceMock.h" +#include "UdpDriver/UdpDriver.h" using udp::UdpDriver; using lwip::gmock::UdpRawInterfaceMock; -using cmsis::gmock::MockOsInterface; +using cmsis::gmock::OsInterfaceMock; using ::testing::Return; using ::testing::_; @@ -56,10 +53,10 @@ const ip_addr_t ZERO_IP_ADDR_T = {0x0}; class UdpDriverTest : public ::testing::Test { protected: UdpRawInterfaceMock udp_if; - MockOsInterface os_if; + OsInterfaceMock os_if; }; -} +} // end anonymous namespace @@ -67,12 +64,12 @@ class UdpDriverTest : public ::testing::Test { TEST_F(UdpDriverTest, DefaultInitializeMembersToZero) { UdpDriver udpDriverUnderTest; - EXPECT_EQ(udpDriverUnderTest.getIpaddr(), ZERO_IP_ADDR_T); - EXPECT_EQ(udpDriverUnderTest.getIpaddrPc(), ZERO_IP_ADDR_T); - EXPECT_EQ(udpDriverUnderTest.getPort(), (u16_t) 0); - EXPECT_EQ(udpDriverUnderTest.getPortPc(), (u16_t) 0); - EXPECT_EQ(udpDriverUnderTest.getUdpInterface(), nullptr); - EXPECT_EQ(udpDriverUnderTest.getOsInterface(), nullptr); + EXPECT_EQ(udpDriverUnderTest.getIpAddrSrc(), ZERO_IP_ADDR_T); + EXPECT_EQ(udpDriverUnderTest.getIpAddrDest(), ZERO_IP_ADDR_T); + EXPECT_EQ(udpDriverUnderTest.getPortSrc(), (u16_t) 0); + EXPECT_EQ(udpDriverUnderTest.getPortDest(), (u16_t) 0); + EXPECT_EQ(udpDriverUnderTest.getUdpIf(), nullptr); + EXPECT_EQ(udpDriverUnderTest.getOsIf(), nullptr); } TEST_F(UdpDriverTest, InitializeMembersWithParameterizedConstructor) { @@ -82,12 +79,12 @@ TEST_F(UdpDriverTest, InitializeMembersWithParameterizedConstructor) { UdpDriver udpDriverUnderTest(TEST_IP_ADDR, TEST_IP_ADDR_PC, (u16_t) 7, (u16_t) 6340, &udp_if, &os_if); - EXPECT_EQ(TEST_IP_ADDR, udpDriverUnderTest.getIpaddr()); - EXPECT_EQ(TEST_IP_ADDR_PC, udpDriverUnderTest.getIpaddrPc()); - EXPECT_EQ((u16_t) 7, udpDriverUnderTest.getPort()); - EXPECT_EQ((u16_t) 6340, udpDriverUnderTest.getPortPc()); - EXPECT_EQ(&udp_if, udpDriverUnderTest.getUdpInterface()); - EXPECT_EQ(&os_if, udpDriverUnderTest.getOsInterface()); + EXPECT_EQ(TEST_IP_ADDR, udpDriverUnderTest.getIpAddrSrc()); + EXPECT_EQ(TEST_IP_ADDR_PC, udpDriverUnderTest.getIpAddrDest()); + EXPECT_EQ((u16_t) 7, udpDriverUnderTest.getPortSrc()); + EXPECT_EQ((u16_t) 6340, udpDriverUnderTest.getPortDest()); + EXPECT_EQ(&udp_if, udpDriverUnderTest.getUdpIf()); + EXPECT_EQ(&os_if, udpDriverUnderTest.getOsIf()); } TEST_F(UdpDriverTest, SucceedInitialize) { @@ -347,3 +344,8 @@ TEST_F(UdpDriverTest, FailTransmitWhenUdpSendUnsuccessful) { ASSERT_FALSE(udpDriverUnderTest.transmit(txBuff, sizeof(txBuff))); } + +/** + * @} + */ +/* end - UdpDriver_Test */ diff --git a/Robot/.cproject b/Robot/.cproject index d7c26387..46787dd6 100644 --- a/Robot/.cproject +++ b/Robot/.cproject @@ -135,12 +135,22 @@