Exemplo n.º 1
0
// read from CAN forever - until manual break
int read_loop(bool display_on)
{
	// read in endless loop until Ctrl-C
	while (1) {
		TPCANRdMsg m;
		__u32 status;

		if (LINUX_CAN_Read(h, &m)) {
			perror("receivetest: LINUX_CAN_Read()");
			return errno;
		}

		if (display_on)
			print_message_ex(&m);

		// check if a CAN status is pending
		if (m.Msg.MSGTYPE & MSGTYPE_STATUS) {
			status = CAN_Status(h);
			if ((int)status < 0) {
				errno = nGetLastError();
				perror("receivetest: CAN_Status()");
				return errno;
			}

			printf("receivetest: pending CAN status 0x%04x read.\n",
				(__u16)status);
		}
	}

	return 0;
}
void test(void * arg)
{
	
	int i=0;
	for (i = 0; i < 5; i++)
	{
		LINUX_CAN_Read(can_handle, &can_msg[i]);
	}
}
Exemplo n.º 3
0
  void defaultListener() {
    while (true) {
      TPCANRdMsg m;
      if ((errno = LINUX_CAN_Read(h, &m))) {
	perror("LINUX_CAN_Read() error");
      }

      if (m.Msg.ID >= 0x180 && m.Msg.ID <= 0x4ff) { // incoming PDO 
	if (incomingPDOHandlers.find(m.Msg.ID) != incomingPDOHandlers.end())
	  incomingPDOHandlers[m.Msg.ID](m);
      }
      else if (m.Msg.ID >= 0x580 && m.Msg.ID <= 0x5ff) { // incoming SDO 
	SDOkey sdoKey(m);
	if (incomingDataHandlers.find(sdoKey) != incomingDataHandlers.end())
	  incomingDataHandlers[sdoKey](m.Msg.ID - 0x580, m.Msg.DATA);
      } else if (m.Msg.ID >= 0x700 && m.Msg.ID <= 0x7FF) 
	incomingNodeguardHandler(m.Msg.ID - 0x700, m.Msg.DATA);
    }
  }