📄 sdoc.c
字号:
/***************************************************************************
sdoc.c - description
-------------------
begin : Fri May 17 2002
copyright : (C) 2002 by Raphael Zulliger
email : zulli@hsr.ch
***************************************************************************/
/***************************************************************************
* *
* This library is Copyright (c) Raphael Zulliger <zulli@gmx.net>. *
* It is licensed under the GNU Library General Public License (LGPL). *
* *
***************************************************************************/
#include <def.h>
#include <canop.h>
void saveOD( BYTE bSubindex )
{
}
void loadOD( BYTE bSubindex )
{
}
void processReceivedSDO( s_rx_buffer_message* canopenMessage )
{
// readRxBuffer( ); // read a maximum of all CANMessages into the
// //buffer (if more than RX_CAN_BUFFER_SIZE has arrived, the old one will be deleted!)
//
// // go through every possibly received CAN/CANopen-message
// for( i=0; i<RX_CAN_BUFFER_SIZE; i++ )
// {
// // check wheter the message's cob-id is between 0x700 and 0x700 + 128(decimal). if this
// // is not the case, it can't be a lifeguard-message
// if( ( (WORD)canMessageRxBuffer[i].m.cob_id.w >= (WORD)0x700 ) && ( (WORD)canMessageRxBuffer[i].m.cob_id.w <= (WORD)0x780 ) )
// { // so we've found a lifeguard-message... lets have a look if he have to care about this message
// for( j=0; j<COUNT_OF_HEARTBEAT_CONSUMER; j++ )
// { // for every possibly configured heartbeat prodcuer, check wheter we are a consumer
// if( heartBeatTable[j].id == (WORD)canMessageRxBuffer[i].m.cob_id.w )
// {// the acutally checked message we received was configured in the object dictionary... so check wheter
// // the heartbeat message was sent within the correct time
// // so lets reset the time!
// heartBeatTable[j].time = 0;
// }
// }
// }
// }
}
/*************************************************************************
* Functions which are responsible for SDO handling... (SDO-Server)
*
* THEORIE:
* -general:
* an SDO-Client is the CANope device which wants to modify/read
* the object dictionary of an other CANopen device. So a
* device which wants to provide the service to modify the
* entries of its object dictionary, must have an SDO-Server
* implemented.
* An write-access is often called as "Download", a read-access
* is called "Upload".
* -transfer:
* the SDO-Client sends a messge to the SDO-Server with the CAN-
* ID 1536+Node-id (0x600+node-id of the Server). the SDO-Server
* responds with a message CAN-ID: 1408+Node-id (of the server).
* This two ID's are the "default"-SDOs. A CANopen-device can
* provide up to 127 SDOs... if this is the case, it is
* important to set the IDs to non-used IDs! (this is usually
* done by a SDO-Manager)
*
*************************************************************************/
//Array of transfers
//static s_transfer transfers[MAX_CAN_BUS_ID][SDO_MAX_NODE_ID] = {[0 ... MAX_CAN_BUS_ID-1] = {[0 ... SDO_MAX_NODE_ID-1] = S_TRANSFER_INITIALIZER}};
//
//
//int Flux_MGR(int bus_id, int ID) //Flux Manager
//{
// int i, res;
// char t, n, c, e, s;
// s_SDO sdo;
//
// MSG("Flux_MGR\n");
//
// res = -1;
//
// sdo.ID = ID;
//
// if(TS_HAVE_TO_DO(transfers[bus_id][ID].state)){
// switch(TS_ACTIVITY(transfers[bus_id][ID].state)){
// case TS_ACTIVATED: // Initiate a Domain (up/down)load
// sdo.body.data.init.index = transfers[bus_id][ID].index;
// sdo.body.data.init.subindex = transfers[bus_id][ID].subindex;
// if(TS_IS_DOWNLOAD(transfers[bus_id][ID].state)){
// // Number of bytes < 5 -> expedited tranfer
// if(transfers[bus_id][ID].count < 5){
// n = 4 - transfers[bus_id][ID].count;
// e = 1;
// s = 1;
// sdo.len = 8 - n;
// for(i=0; i<4-n; i++){
// sdo.body.data.init.data[i] = transfers[bus_id][ID].data[i];
// }
// transfers[bus_id][ID].offset = transfers[bus_id][ID].count; // Next call will finish.
// } else { // Normal transfer
// n = 0;
// e = 0;
// s = 1;
// sdo.len = 8;
// for(i=0; i<4-n; i++){ // re-idianees
// sdo.body.data.init.data[i] = (transfers[bus_id][ID].count & (0xff << (i*8))) >> (i*8);
// }
// transfers[bus_id][ID].offset = 0;
// }
// sdo.body.SCS = IDD_client(n,e,s);
// } else {
// sdo.len = 4;
// sdo.body.SCS = IDU_client;
// transfers[bus_id][ID].offset = 0;
// }
// res = Send_SDO(bus_id, sdo, Rx);
// TS_SET_ACTIVITY(transfers[bus_id][ID].state, TS_WORKING | TS_WAIT_SERVER);
// break;
// case TS_WORKING: // Follow Domain (up/down)load
// if(TS_IS_DOWNLOAD(transfers[bus_id][ID].state)){
// i = transfers[bus_id][ID].count - transfers[bus_id][ID].offset;
// if(i <= 0){ // Download Finished
// res = 0;
// transfers[bus_id][ID].state = TS_FREE;
// break;
// } else { // Follow segmented transfer
// if(i>7){
// n = 0; // There is no unused byte
// c = 0; // It is not the last message
// } else {
// n = 7 - i; // There could have unused bytes
// c = 1; // This is the last message
// }
// sdo.len = 8 - n;
// for(i=0; i<7-n; i++){
// sdo.body.data.segment.data[i] = transfers[bus_id][ID].data[(int)transfers[bus_id][(int)sdo.ID].offset++];
// }
// t = (transfers[bus_id][ID].state & TS_TOGGLE) >> 4; // take the toggle bit
// sdo.body.SCS = DDS_client(t,n,c);
// transfers[bus_id][ID].state ^= TS_TOGGLE; // toggle afterward
// }
// } else { // Upload
// sdo.len = 1;
// t = (transfers[bus_id][ID].state & TS_TOGGLE) >> 4; // take the toggle bit
// sdo.body.SCS = UDS_client(t);
// transfers[bus_id][ID].state ^= TS_TOGGLE; // toggle afterward
// }
// res = Send_SDO(bus_id, sdo, Rx);
// TS_SET_ACTIVITY(transfers[bus_id][ID].state, TS_WORKING | TS_WAIT_SERVER);
// break;
// default: // Transfer not in use or transfer error. Blub blub...
// break;
// }
// }
// return res;
//}
//
//int ProceedSDO(int bus_id, Message *m,const proceed_info *p_i, int follow)
//{
// int i;
// char t, n, c, e, s;
// s_SDO sdo;
//
// MSG("ProceedSDO\n");
//
// sdo.ID = GET_NODE_ID((*m));
// sdo.len = (*m).len;
// memcpy(&sdo.body, &m->data, sdo.len);
//
// // If there really is a running transfer
// // And we are waiting for a message
// // And the message is not Abort
// if(TS_ACTIVITY(transfers[bus_id][(int)sdo.ID].state) == TS_WORKING &&
// !TS_HAVE_TO_DO(transfers[bus_id][(int)sdo.ID].state) &&
// !(sdo.body.SCS & ADT_server)){
// if(IS_DOWNLOAD_RESPONSE(sdo.body.SCS)){
// // FIXME : Should warn for strange & unexpected paquets...
// if(transfers[bus_id][(int)sdo.ID].count <= transfers[bus_id][(int)sdo.ID].offset){
// transfers[bus_id][(int)sdo.ID].state = TS_FREE;
// }
// } else { // Upload
// if(IS_SEGMENTED_RESPONSE(sdo.body.SCS)){ //segment containing data to store.
// UDS_server_params(sdo.body.SCS,t,n,c);
// // FIXME : should warn for bad toggle bit
// for(i=0; i<7-n; i++){ //FIXME : should take care of data overrun
// transfers[bus_id][(int)sdo.ID].data[transfers[bus_id][(int)sdo.ID].offset++] = sdo.body.data.segment.data[i];
// }
// if(c) // If last segment get in finished state.
// transfers[bus_id][(int)sdo.ID].state = TS_FINISHED;
// transfers[bus_id][(int)sdo.ID].count = transfers[bus_id][(int)sdo.ID].offset;
// } else { //Initial Upload Upload Response
// IDU_server_params(sdo.body.SCS,n,e,s);
// // FIXME : should warn for crazy dictionary (sub)index
// if(e){ //expedited transfer
// if(!s) n = 0; // "data bytes contain data to be downloaded"
// for(i=0; i<4-n; i++){
// transfers[bus_id][(int)sdo.ID].data[i] = sdo.body.data.init.data[i];
// }
// transfers[bus_id][(int)sdo.ID].count = 4-n;
// transfers[bus_id][(int)sdo.ID].state = TS_FINISHED;
// } else { //normal transfer
// if(s){
// for(i=0; i<4-n; i++){
// transfers[bus_id][(int)sdo.ID].count |= sdo.body.data.init.data[i] << (i*8);
// }
// transfers[bus_id][(int)sdo.ID].offset = 0;
// }else{ //FIXME : e=0 et s=0 Standard ?
// transfers[bus_id][(int)sdo.ID].offset = 0;
// for(i=0; i<4; i++){
// transfers[bus_id][(int)sdo.ID].data[(int)transfers[bus_id][(int)sdo.ID].offset++] = sdo.body.data.init.data[i];
// }
// }
// }
// }
// }
// // Stop waiting for this node after each received message.
// transfers[bus_id][(int)sdo.ID].state &= ~TS_WAIT_SERVER;
// if(follow) Flux_MGR(bus_id,sdo.ID);
// } else {//FIXME : should warn for unexpected message
// transfers[bus_id][(int)sdo.ID].state = TS_ERROR;
// }
// return 0;
//}
//
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -