Re: [Canfestival-devel] Help me to run my own can virtual driver
> > Hi My problem is solved it was because of not handling receive request before send I added my edited codes (candev.cpp and candev.h ) > #ifndef CANDEV_H #define CANDEV_H #include #include #include #include #include #include #include "canBus.h" #include "definition.h" using namespace std; class canBus; class canDev { public: canDev(const int ); virtual ~canDev(); UNS8 canReceive_driver(Message_ *m); UNS8 canSend_driver(const Message_ *m); int TranslateBaudRate(char* optarg); UNS8 canChangeBaudRate_driver(CAN_HANDLE fd0, char *baud); CAN_HANDLE canOpen_driver(s_BOARD_ *board); int canClose_driver(CAN_HANDLE fd0); void canSetBus(canBus *Bus); int getNodeID()const; void setMsgBuffer(Message_ *m); void AddNewBus(char *baudrate, canBus* cBus); bool IsBusPresent(char *baudrate); canBus * GetBusAddress(char *baudrate); static map BusesMap; static int ID; pthread_mutex_t mutex; pthread_cond_t cond; protected: private: canBus *Bus; int nodeID; s_BOARD_ *board; queuebuffer; }; #endif // CANDEV_H #include "candev.h" std::map canDev::BusesMap; int canDev::ID = 0; canDev::canDev(const int ) { this->nodeID = ID; pthread_cond_init(, NULL); pthread_mutex_init(, NULL); ID++; //ctor } canDev::~canDev() { pthread_cond_destroy(); pthread_mutex_destroy(); //dtor } void canDev::canSetBus(canBus *Bus) { if(this->Bus != Bus && this->Bus != NULL) { this->Bus->removeDev(this); } this->Bus = Bus; this->Bus->registerDev(this); this->board->busname = this->Bus->GetBusName(); this->board->baudrate = this->Bus->GetBuadRate(); } UNS8 canDev::canReceive_driver(Message_ *m) { pthread_mutex_lock(); if (buffer.empty()) { pthread_cond_wait(, ); pthread_mutex_unlock(); } Message_ * temp = buffer.front(); m->cob_id = (temp)->cob_id; memcpy(m->data, (temp)->data,8); m->len = (temp)->len; m->rtr = (temp)->rtr; buffer.pop(); delete temp; return 0; } UNS8 canDev::canSend_driver(const Message_ *m) { this->Bus->sendMessage(this, m); return 0; } int canDev::TranslateBaudRate(char *optarg) { if (!strcmp(optarg, "1M")) return (int)1000; if (!strcmp(optarg, "500K")) return (int)500; if (!strcmp(optarg, "250K")) return (int)250; if (!strcmp(optarg, "125K")) return (int)125; if (!strcmp(optarg, "100K")) return (int)100; if (!strcmp(optarg, "50K")) return (int)50; if (!strcmp(optarg, "20K")) return (int)20; if (!strcmp(optarg, "10K")) return (int)10; if (!strcmp(optarg, "5K")) return (int)5; if (!strcmp(optarg, "none")) return 0; return 0x; } UNS8 canDev::canChangeBaudRate_driver( CAN_HANDLE fd0, char *baud) { printf("Faked changing to baud rate %s[%d]\n", baud, TranslateBaudRate(baud)); return 0; } CAN_HANDLE canDev::canOpen_driver(s_BOARD_ *board) { Bus = new canBus(); Bus = NULL; this->board = new s_BOARD_; this->board->baudrate = board->baudrate; this->board->busname = board->busname; return NULL; } int canDev::canClose_driver(CAN_HANDLE fd0) { this->Bus->removeDev(this); return 0; } int canDev::getNodeID()const { return nodeID; } void canDev::setMsgBuffer(Message_ *m) { Message_ * temp = new Message_; temp->cob_id = m->cob_id; memcpy(temp->data, m->data, 8); temp->len = m->len; temp->rtr = m->rtr; buffer.push(temp); pthread_cond_signal(); } void canDev::AddNewBus(char * baudrate, canBus * cBus) { BusesMap[baudrate] = cBus; } bool canDev::IsBusPresent(char * baudrate) { if (BusesMap.empty()) return false; map::iterator it; it = BusesMap.find(baudrate); if (it == BusesMap.end()) { return false; } return true; } canBus * canDev::GetBusAddress(char *baudrate) { map::iterator it; it = BusesMap.find(baudrate); return (*it).second; }-- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Canfestival-devel mailing list Canfestival-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/canfestival-devel
Re: [Canfestival-devel] Help me to run my own can virtual driver
> > Hi Lars Many thanks for your answer. Interestingly sygwin didn't show me any error and warning. I solved that error but my code have previous problem yet, I added my edited can-New.cpp Looking for you Many thanks // can_new_win32.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" /* This file is part of CanFestival, a library implementing CanOpen Stack. Copyright (C): Edouard TISSERANT See COPYING file for copyrights details. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "candev.h" #include using namespace std; extern "C" { #include "can_driver.h" // UNS8 LIBAPI canReceive_driver(CAN_HANDLE fd0, Message *m) { Message_ * m1 = new Message_; cout << "in recv "; char s[1024]; int res = reinterpret_cast(fd0)->canReceive_driver(m1); if (res == 1) return 1; m->cob_id = m1->cob_id; m->rtr = m1->rtr; m->len = m1->len; m->data[0] = m1->data[0]; m->data[1] = m1->data[1]; m->data[2] = m1->data[2]; m->data[3] = m1->data[3]; m->data[4] = m1->data[4]; m->data[5] = m1->data[5]; m->data[6] = m1->data[6]; m->data[7] = m1->data[7]; printf("{0x%3.3x,%1d,%1d,{0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x}}", m->cob_id, m->rtr, m->len, m->data[0], m->data[1], m->data[2], m->data[3], m->data[4], m->data[5], m->data[6], m->data[7] ); delete m1; cout << "error test4" << endl; #if defined DEBUG_MSG_CONSOLE_ON printf("in : "); print_message(m); #endif return 0; } UNS8 LIBAPI canSend_driver(CAN_HANDLE fd0, Message const *m) { cout << "in send "; char s[1024]; printf("{0x%3.3x,%1d,%1d,{0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x,0x%2.2x}}", m->cob_id, m->rtr, m->len, m->data[0], m->data[1], m->data[2], m->data[3], m->data[4], m->data[5], m->data[6], m->data[7] ); Message_ * m1 = new Message_; m1->cob_id = m->cob_id; m1->rtr = m->rtr; m1->len = m->len; m1->data[0] = m->data[0]; m1->data[1] = m->data[1]; m1->data[2] = m->data[2]; m1->data[3] = m->data[3]; m1->data[4] = m->data[4]; m1->data[5] = m->data[5]; m1->data[6] = m->data[6]; m1->data[7] = m->data[7]; reinterpret_cast (fd0)->canSend_driver(m1); #if defined DEBUG_MSG_CONSOLE_ON printf("out : "); print_message(m); #endif return 0; } CAN_HANDLE LIBAPI canOpen_driver(s_BOARD *board) { try { cout << "Open \n"; s_BOARD_ temp1; temp1.baudrate = board->baudrate; temp1.busname = board->busname; CAN_HANDLE res = (CAN_HANDLE) new canDev(0); canBus * temp = new canBus(); if (!reinterpret_cast (res)->IsBusPresent(board->baudrate)) { temp = new canBus(board->busname, board->baudrate); reinterpret_cast (res)->AddNewBus(board->baudrate, temp); } else temp = reinterpret_cast (res)->GetBusAddress(board->baudrate); reinterpret_cast (res)->canOpen_driver(); reinterpret_cast (res)->canSetBus(temp); temp->ConnectedDevID(); return res; } catch (...) { cerr << "can_new: couldn't open" << endl; return NULL; } } int LIBAPI canClose_driver(CAN_HANDLE inst) { delete reinterpret_cast (inst); return 1; } UNS8 LIBAPI canChangeBaudRate_driver(CAN_HANDLE fd, char* baud) { cerr << "canChangeBaudRate not yet supported by this driver\n"; return 0; } } -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Canfestival-devel mailing list Canfestival-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/canfestival-devel
Re: [Canfestival-devel] Help me to run my own can virtual driver
Hi, I do not have cygwin installed so i am using visual studio, it gave a error while compiling 'uninitialized local variable 'm1' used' That should be fixed. If you did not get a segfault, it is pure luck :) UNS8 LIBAPI canReceive_driver(CAN_HANDLE fd0, Message *m) { Message_ * m1; int res = reinterpret_cast(fd0)->canReceive_driver(m1); You might want to turn on a loot of the compiler warnings as it will help finding bugs. As soon as you have fixed the bug i can take a new look. Happy coding! Best Regards Lars On Tue, Apr 17, 2018 at 2:32 PM, wrote: > hi all > I need your help. > I added my source for my_virtual_can driver. > I want to run TestMasterSlave with that. > Its dll is built okay, but when I run it the nodes go to initial state and > then pre operational, > Then the master node goes to post_sync and stuck on that. > please look in my codes and guide me why my program doesn't go to slave boot > up state and other states, > I'll be grateful for any help > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Canfestival-devel mailing list > Canfestival-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/canfestival-devel > -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Canfestival-devel mailing list Canfestival-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/canfestival-devel