00001 /******************************************************************************* 00002 * Copyright 2017 ROBOTIS CO., LTD. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 *******************************************************************************/ 00016 00021 00022 #ifndef DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_SDK_MAC_PORTHANDLERMAC_H_ 00023 #define DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_SDK_MAC_PORTHANDLERMAC_H_ 00024 00025 00026 #include "port_handler.h" 00027 00028 namespace dynamixel 00029 { 00030 00034 class PortHandlerMac : public PortHandler 00035 { 00036 private: 00037 int socket_fd_; 00038 int baudrate_; 00039 char port_name_[100]; 00040 00041 double packet_start_time_; 00042 double packet_timeout_; 00043 double tx_time_per_byte; 00044 00045 bool setupPort(const int cflag_baud); 00046 bool setCustomBaudrate(int speed); 00047 int getCFlagBaud(const int baudrate); 00048 00049 double getCurrentTime(); 00050 double getTimeSinceStart(); 00051 00052 public: 00057 PortHandlerMac(const char *port_name); 00058 00063 virtual ~PortHandlerMac() { closePort(); } 00064 00070 bool openPort(); 00071 00076 void closePort(); 00077 00082 void clearPort(); 00083 00089 void setPortName(const char *port_name); 00090 00096 char *getPortName(); 00097 00106 bool setBaudRate(const int baudrate); 00107 00114 int getBaudRate(); 00115 00122 int getBytesAvailable(); 00123 00134 int readPort(uint8_t *packet, int length); 00135 00146 int writePort(uint8_t *packet, int length); 00147 00153 void setPacketTimeout(uint16_t packet_length); 00154 00160 void setPacketTimeout(double msec); 00161 00166 bool isPacketTimeout(); 00167 }; 00168 00169 } 00170 00171 00172 #endif /* DYNAMIXEL_SDK_INCLUDE_DYNAMIXEL_SDK_MAC_PORTHANDLERMAC_H_ */