Sonntag, 19. Februar 2017

CAN Code Part I

Lets look into some parts of the code. I dont know how many parts this will be :-) Lets do it pragmatically so not a lot of CAN background before. The function is about detecting if a certain node on the CAN bus is a UVR 1611 controller. Three parameters are downloaded from a potential 1611 controller. Vendor, product and version. If those three match than the function returns 1611 (int). If any of the three mycanopen_sdo_upload_exp functions fail, the last comparison fails as well.

Note that the verbindungsAufbau and verbindungsAbbau is crucial. The verbindungsAufbau function uses the CAN node id you configured your controller. The function returns a temporary node ID this controller is listening to. The cob_id is a temporary alias for this controller which is required to access its object dictionary. The object dictionary is accessed using the mycanopen_sdo_upload_exp function. After accessing the object dictionary this alias is released.



//public
int Uvr_Can::isUVR_c(int to_node_id) { 

    boost::mutex::scoped_lock lock(can_if_mtx_);

    uint32_t vendor = 0, product = 0, version = 0, identifier = 0;
    int ret = 0, cob_id = 0;

    //cob_id = verbindungsAufbau(sock_, self_node_id_, to_node_id);
    cob_id = this->verbindungsAufbau_c(to_node_id);

    mycanopen_sdo_upload_exp(sock_, cob_id, 0x1018, 0x01, &vendor);
    mycanopen_sdo_upload_exp(sock_, cob_id, 0x1018, 0x02, &product);
    mycanopen_sdo_upload_exp(sock_, cob_id, 0x1018, 0x03, &version);

    mycanopen_sdo_upload_exp(sock_, cob_id, 0x23e2, 0x01, &identifier);

    verbindungsAbbau(sock_, self_node_id_, to_node_id);

    if(vendor == 0x000000CB && product == 0x0000100B && identifier == 128) ret = 1611;

    return ret;
}

Keine Kommentare:

Kommentar veröffentlichen