예제 #1
0
파일: lss.c 프로젝트: githubhjz/CanFestival
/*!                                                                                                
**                                                                                                 
**                                                                                                 
** @param d                                                                                        
** @param cob_id                                                                                   
**                                                                                                 
** @return                                                                                         
**/  
UNS8 sendSlaveLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
{
	Message m;
	UNS8 i;

	if (!d->CurrentCommunicationState.csLSS)
	{
		MSG_WAR(0x2D17, "unable to send the LSS message, not in the proper state =>", d->nodeState);
		return 0xFF;
	}

	for (i = 1; i < 8; i++)
	{
		m.data[i] = 0;
	}

	m.len = 8;
	m.rtr = NOT_A_REQUEST;
	m.data[0]=command;
	m.cob_id=UNS16_LE(SLSS_ADRESS);

	/* Tha data sent with the msg depends on the command */
	switch(command)
	{
		case LSS_INQ_NODE_ID: /* Inquire Node-ID */
		{
			m.data[1]=*(UNS8 *)dat1;
		} break;
		case LSS_CONF_NODE_ID: /* Configure Node-ID */
		case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
		case LSS_CONF_STORE: /* Store Configured Parameters */
		{
			m.data[1]=*(UNS8 *)dat1;
			m.data[2]=*(UNS8 *)dat2;
		} break;
		case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
		case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
		case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
		case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
		{
			m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
			m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
			m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
			m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
		} break;
		case LSS_SM_SELECTIVE_RESP: /* Switch Mode Selective response*/
		case LSS_IDENT_SLAVE: /* LSS Identify Slave */
		case LSS_IDENT_NON_CONF_SLAVE: /* LSS identify non-configured remote slave */
		{
		} break;
		default:
		{
			MSG_ERR(0x1D18, "send Slave LSS command not implemented", command);
			return 0xFF;
		}
	}

	return canSend(d->canHandle,&m);
}
예제 #2
0
파일: sync.c 프로젝트: AubrCool/canfestival
/*!                                                                                                
**                                                                                                 
**                                                                                                 
** @param d                                                                                        
** @param cob_id                                                                                   
**                                                                                                 
** @return                                                                                         
**/  
UNS8 sendSYNCMessage(CO_Data* d)
{
  Message m;
  
  MSG_WAR(0x3001, "sendSYNC ", 0);
  
  m.cob_id = (UNS16)UNS16_LE(*d->COB_ID_Sync);
  m.rtr = NOT_A_REQUEST;
  m.len = 0;
  
  return canSend(d->canHandle,&m);
}
예제 #3
0
/*!
**
**
** @param d
** @param nodeId
**
** @return
**/
UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId)
{
    Message m;

    /* message configuration */
    UNS16 tmp = nodeId | (NODE_GUARD << 7);
    m.cob_id = UNS16_LE(tmp);
    m.rtr = REQUEST;
    m.len = 0;

    MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);

    return canSend(d->canHandle,&m);
}
예제 #4
0
/*!
**
**
** @param d
** @param m
**/
void canDispatch(CO_Data* d, Message *m)
{
	UNS16 cob_id = UNS16_LE(m->cob_id);
	switch (cob_id >> 7) {
	case SYNC:		/* can be a SYNC or a EMCY message */
		if (cob_id == 0x080) {	/* SYNC */
			if (d->CurrentCommunicationState.csSYNC)
				proceedSYNC(d);
		} else 		/* EMCY */
			if (d->CurrentCommunicationState.csEmergency)
				proceedEMCY(d, m);
		break;
	/* case TIME_STAMP: */
	case PDO1tx:
	case PDO1rx:
	case PDO2tx:
	case PDO2rx:
	case PDO3tx:
	case PDO3rx:
	case PDO4tx:
	case PDO4rx:
		if (d->CurrentCommunicationState.csPDO)
			proceedPDO(d, m);
		break;
	case SDOtx:
	case SDOrx:
		if (d->CurrentCommunicationState.csSDO)
			proceedSDO(d, m);
		break;
	case NODE_GUARD:
		if (d->CurrentCommunicationState.csHeartbeat)
			proceedNODE_GUARD(d, m);
		break;
	case NMT:
		if (*(d->iam_a_slave)) {
			proceedNMTstateChange(d, m);
		}
#ifdef CO_ENABLE_LSS
	case LSS:
		if (!d->CurrentCommunicationState.csLSS)break;
		if ((*(d->iam_a_slave)) && cob_id == MLSS_ADRESS) {
			proceedLSS_Slave(d, m);
		} else if (!(*(d->iam_a_slave)) && cob_id == SLSS_ADRESS) {
			proceedLSS_Master(d, m);
		}
		break;
#endif
	}
}
예제 #5
0
파일: lss.c 프로젝트: githubhjz/CanFestival
/*!                                                                                                
**                                                                                                 
**                                                                                                 
** @param d                                                                                        
** @param cob_id                                                                                   
**                                                                                                 
** @return                                                                                         
**/  
UNS8 sendMasterLSSMessage(CO_Data* d, UNS8 command,void *dat1,void *dat2)
{
	Message m;
	UNS8 i;
	UNS8 res;
	UNS8 hasResponse=0;

	for (i = 1; i < 8; i++)
	{
		m.data[i]=0;
	}

	m.len = 8;
	m.rtr = NOT_A_REQUEST;
	m.data[0]=command;
	m.cob_id=UNS16_LE(MLSS_ADRESS);

	/* Tha data sent with the msg depends on the command */
	switch(command)
	{
		case LSS_CONF_NODE_ID: /* Configure Node-ID */
		{
			hasResponse=1;
		}
		case LSS_SM_GLOBAL: /* Switch Mode Global */
		{
			m.data[1]=*(UNS8 *)dat1;
		} break;
		case LSS_CONF_BIT_TIMING: /* Configure Bit Timing Parameters */
		{
			m.data[1]=*(UNS8 *)dat1;
			d->lss_transfer.baudRate=*(char **)dat2;

			if ((m.data[2]=CO_TranslateBaudRate(d->lss_transfer.baudRate))!=0xFF)
			{
				hasResponse=1;
				break;
			}

			MSG_ERR(0x1D19, "Master-> Baud rate not supported",0);
			d->lss_transfer.dat1=0xFF;

			/* if bit timing is not supported comment the previous code and uncomment the following one*/
			/*{
			MSG_ERR(0x1D1A, "Master-> Bit timing not supported",0);
			d->lss_transfer.dat1=0x01;
			}*/

			d->lss_transfer.dat2=0;
			/* If there is a callback, it is responsible of the error */
			if (d->lss_transfer.Callback)
			{
				(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
			}

			return 0xFF;
			//break;
		}
		case LSS_CONF_ACT_BIT_TIMING: /* Activate Bit Timing Parameters */
		{
			m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
			m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);

			if(d->lss_transfer.baudRate != "none")
			{
				d->lss_transfer.switchDelay=(UNS16)(*(UNS32*)dat1 & 0xFFFF);
				d->lss_transfer.switchDelayState=SDELAY_FIRST;
				d->lss_transfer.canHandle_t=d->canHandle;

				res=canSend(d->canHandle,&m);
				if (res==0)
				{
					StartLSS_SDELAY_TIMER();
					d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
				}
				return res;
			} else
			{
				MSG_ERR(0x1D1B, "Master-> Baud rate not specified",0);
				d->lss_transfer.dat1=1;

				/* If there is a callback, it is responsible of the error */
				if (d->lss_transfer.Callback)
				{
					(*d->lss_transfer.Callback)(d,d->lss_transfer.command);
				}
				return 0xFF;
			}
			//break;
		}
		case LSS_SM_SELECTIVE_SERIAL:
		case LSS_IDENT_REMOTE_SERIAL_HIGH:
		{
			hasResponse=1;
		}
		case LSS_SM_SELECTIVE_VENDOR: /* Switch Mode Selective */
		case LSS_SM_SELECTIVE_PRODUCT:
		case LSS_SM_SELECTIVE_REVISION:
		case LSS_IDENT_REMOTE_VENDOR: /* LSS Identify Remote Slaves */
		case LSS_IDENT_REMOTE_PRODUCT:
		case LSS_IDENT_REMOTE_REV_LOW:
		case LSS_IDENT_REMOTE_REV_HIGH:
		case LSS_IDENT_REMOTE_SERIAL_LOW:
		{
			m.data[1]=(UNS8)(*(UNS32*)dat1 & 0xFF);
			m.data[2]=(UNS8)(*(UNS32*)dat1>>8 & 0xFF);
			m.data[3]=(UNS8)(*(UNS32*)dat1>>16 & 0xFF);
			m.data[4]=(UNS8)(*(UNS32*)dat1>>24 & 0xFF);
		} break;

		case LSS_CONF_STORE: /* Store Configured Parameters */
		case LSS_IDENT_REMOTE_NON_CONF: /* LSS identify non-configured remote slave */
		case LSS_INQ_VENDOR_ID: /* Inquire Identity Vendor-ID */
		case LSS_INQ_PRODUCT_CODE: /* Inquire Identity Product-Code */
		case LSS_INQ_REV_NUMBER: /* Inquire Identity Revision-Number */
		case LSS_INQ_SERIAL_NUMBER: /* Inquire Identity Serial-Number */
		case LSS_INQ_NODE_ID: /* Inquire Node-ID */
		{
			hasResponse=1;
		} break;
#ifdef CO_ENABLE_LSS_FS
		case LSS_IDENT_FASTSCAN:
		{
			if (d->lss_transfer.FastScan_SM==LSS_FS_RESET)
			{
				UNS8 i;
				/* Initialize the lss_fs_transfer FastScan parameters */
				for(i = 0; i < 4; i++)
				{
					d->lss_transfer.lss_fs_transfer.FS_LSS_ID[i]=(*(lss_fs_transfer_t*)dat1).FS_LSS_ID[i];
					d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]=(*(lss_fs_transfer_t*)dat1).FS_BitChecked[i];
					/* Adjust BitChecked from 32-1 to 31-0 */
					if (d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]>0)
					{
						d->lss_transfer.lss_fs_transfer.FS_BitChecked[i]--;
					}
				}

				d->lss_transfer.IDNumber=0;
				d->lss_transfer.BitChecked=128;
				d->lss_transfer.LSSSub=0;
				d->lss_transfer.LSSNext=0;

				/* it will generate a response only if it is the start of the FastScan protocol*/
				hasResponse=1;
			}

			m.data[1]=(UNS8)(d->lss_transfer.IDNumber & 0xFF);
			m.data[2]=(UNS8)(d->lss_transfer.IDNumber>>8 & 0xFF);
			m.data[3]=(UNS8)(d->lss_transfer.IDNumber>>16 & 0xFF);
			m.data[4]=(UNS8)(d->lss_transfer.IDNumber>>24 & 0xFF);
			m.data[5]=d->lss_transfer.BitChecked;
			m.data[6]=d->lss_transfer.LSSSub;
			m.data[7]=d->lss_transfer.LSSNext;
		} break;
#endif
		default:
		{
			MSG_ERR(0x1D1C, "send Master LSS command not implemented", command);
			return 0xFF;
		}
	}
	
	res=canSend(d->canHandle,&m);
	if (res==0 && hasResponse==1){
		StartLSS_MSG_TIMER();
		d->lss_transfer.state=LSS_TRANS_IN_PROGRESS;
	}

	return res;
}