Go to the documentation of this file.00001
00060 #include <utility>
00061 #include <iostream>
00062 #include <iomanip>
00063 #include "ipa_canopen_core/canopen.h"
00064 #include <sstream>
00065
00066 #include <gtest/gtest.h>
00067
00068
00069 TEST(IPAcanopen, communicationTest)
00070 {
00071
00072 bool call_success = true;
00073
00074
00075 canopen::NMTmsg.ID = 0;
00076 canopen::NMTmsg.MSGTYPE = 0x00;
00077 canopen::NMTmsg.LEN = 2;
00078
00079 canopen::syncMsg.ID = 0x80;
00080 canopen::syncMsg.MSGTYPE = 0x00;
00081
00082 canopen::syncMsg.LEN = 0x00;
00083
00084 std::string deviceFile = "/dev/pcan32";
00085 canopen::baudRate = "500K";
00086
00087 if (!canopen::openConnection(deviceFile, canopen::baudRate)){
00088 std::cout << "Cannot open CAN device; aborting." << std::endl;
00089 call_success = false;
00090
00091 }
00092 else{
00093 std::cout << "Connection to CAN bus established" << std::endl;
00094 }
00095
00096 EXPECT_TRUE(call_success);
00097
00098 uint16_t CANid = 1;
00099
00100 canopen::devices[ CANid ] = canopen::Device(CANid);
00101 std::this_thread::sleep_for(std::chrono::milliseconds(10));
00102 canopen::sendNMT(CANid, canopen::NMT_START_REMOTE_NODE);
00103 std::this_thread::sleep_for(std::chrono::milliseconds(10));
00104
00105 std::this_thread::sleep_for(std::chrono::milliseconds(10));
00106
00107
00108 std::shared_ptr<TPCANRdMsg> m;
00109
00110
00111 canopen::readErrorsRegister(CANid, m);
00112
00113
00114
00115
00116 canopen::readManErrReg(CANid, m);
00117
00118
00119
00120
00121
00122 std::vector<uint16_t> vendor_id = canopen::obtainVendorID(CANid, m);
00123 uint16_t rev_number = canopen::obtainRevNr(CANid, m);
00124 std::vector<uint16_t> product_code = canopen::obtainProdCode(CANid, m);
00125 std::vector<char> manufacturer_device_name = canopen::obtainManDevName(CANid,m);
00126 std::vector<char> manufacturer_hw_version = canopen::obtainManHWVersion(CANid, m);
00127 std::vector<char> manufacturer_sw_version = canopen::obtainManSWVersion(CANid, m);
00128
00129
00130
00131
00132
00133 std::cout << "vendor_id=0x";
00134
00135 for (auto it : vendor_id)
00136 {
00137 std::cout << std::hex << it;
00138 }
00139
00140 std::cout << std::endl;
00141
00142 std::cout << "revision_number: "<< std::hex << int(rev_number) << std::dec << std::endl;
00143 std::cout << "device_name:";
00144
00145 for (auto it : manufacturer_device_name)
00146 {
00147 std::cout << it;
00148 }
00149
00150 std::cout << std::endl;
00151
00152 std::cout << "hardware_version:";
00153
00154 for (auto it : manufacturer_hw_version)
00155 {
00156 std::cout << it;
00157 }
00158
00159 std::cout << std::endl;
00160
00161 std::cout << "software_version:";
00162
00163 for (auto it : manufacturer_sw_version)
00164 {
00165 std::cout << it;
00166 }
00167
00168 std::cout << std::endl;
00169 }
00170
00171 int main(int argc, char *argv[])
00172 {
00173 testing::InitGoogleTest(&argc, argv);
00174
00175 return RUN_ALL_TESTS();
00176
00177 }
00178