Esempio n. 1
0
////////////////////////////////////////////////////////////////////////////
// demoSetOutput
// toggle NORMAL/SILENT mode of a CAN channel
//
////////////////////////////////////////////////////////////////////////////
XLstatus demoSetOutput(int outputMode, XLaccess xlChanMaskTx)
{
   XLstatus xlStatus;
   char *sMode = "NORMAL";
  
   switch (outputMode)
   {
      case XL_OUTPUT_MODE_NORMAL:
         sMode = "NORMAL";
      break;

      case XL_OUTPUT_MODE_SILENT:
         sMode = "SILENT";
      break;

      case XL_OUTPUT_MODE_TX_OFF:
         sMode = "SILENT-TXOFF";
      break;
   }

   // to get an effect we deactivate the channel first.
   xlStatus = xlDeactivateChannel(g_xlPortHandle, g_xlChannelMask);

   xlStatus = xlCanSetChannelOutput(g_xlPortHandle, xlChanMaskTx, outputMode);
   printf("- SetChannelOutput: CM(0x%I64x), %s, %s, %d\n", xlChanMaskTx, sMode, xlGetErrorString(xlStatus), outputMode);
 
   // and activate the channel again.
   xlStatus = xlActivateChannel(g_xlPortHandle, g_xlChannelMask, XL_BUS_TYPE_CAN, XL_ACTIVATE_RESET_CLOCK);
  
   return xlStatus;
}
Esempio n. 2
0
HRESULT CDIL_LIN_VectorXL::StartHardware(void)
{
    // ------------------------------------
    // go with all selected channels on bus
    // ------------------------------------
    XLstatus xlStatus = XL_ERROR;
    HRESULT nReturn = S_FALSE;

    xlStatus = xlActivateChannel(g_xlPortHandle[0], g_xlChannelMask, XL_BUS_TYPE_LIN, XL_ACTIVATE_RESET_CLOCK);

    if(xlStatus == XL_SUCCESS)
    {
        nReturn = defERR_OK;
        //nSetApplyConfiguration();
    }
    return nReturn;
}
Esempio n. 3
0
////////////////////////////////////////////////////////////////////////////
// demoStartStop
// toggle the channel activate/deactivate
//
////////////////////////////////////////////////////////////////////////////
XLstatus demoStartStop(int activated)
{
   XLstatus xlStatus;

   if (activated)
   {
      xlStatus = xlActivateChannel(g_xlPortHandle, g_xlChannelMask, XL_BUS_TYPE_CAN, XL_ACTIVATE_RESET_CLOCK);
      printf("- ActivateChannel : CM(0x%I64x), %s\n", g_xlChannelMask, xlGetErrorString(xlStatus));
   }
   else
   {
      xlStatus = xlDeactivateChannel(g_xlPortHandle, g_xlChannelMask);
      printf("- DeactivateChannel: CM(0x%I64x), %s\n", g_xlChannelMask, xlGetErrorString(xlStatus));
   }

   return XL_SUCCESS;
}
Esempio n. 4
0
HRESULT CDIL_LIN_VectorXL::StartHardware(void)
{
    // ------------------------------------
    // go with all selected channels on bus
    // ------------------------------------
    xlFlushReceiveQueue(g_xlPortHandle[0]);

    XLstatus xlStatus = XL_ERROR;
    HRESULT nReturn = S_FALSE;

    xlStatus = xlActivateChannel(g_xlPortHandle[0], g_xlChannelMask, XL_BUS_TYPE_LIN, XL_ACTIVATE_RESET_CLOCK);

    if(xlStatus == XL_SUCCESS)
    {
        sg_bCurrState = STATE_CONNECTED;
        nReturn = S_OK;
        //nSetApplyConfiguration();
    }
    return nReturn;
}
Esempio n. 5
0
////////////////////////////////////////////////////////////////////////////
// main
// 
//
////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
   XLstatus      xlStatus;
   XLaccess      xlChanMaskTx = 0;

   int           stop = 0;
   int           activated = 0;
   int           c;
   unsigned char xlChanIndex = 0;
   unsigned int  txID = 0x01;
   int           outputMode = XL_OUTPUT_MODE_NORMAL;


   printf("----------------------------------------------------------\n");
   printf("- J1939_stack_test - Test Application for J1939 stack    -\n");
   printf("-             using XL Family Driver API                 -\n");
   printf("-             Timespace Technology,  " __DATE__"         -\n");
#ifdef WIN64
   printf("-             - 64bit Version -                          -\n");
#endif
   printf("----------------------------------------------------------\n");

   // ------------------------------------
   // commandline may specify application 
   // name and baudrate
   // ------------------------------------
   if (argc > 1)
   {
      g_BaudRate = atoi(argv[1]);

      if (g_BaudRate)
      {
         printf("Baudrate = %u\n", g_BaudRate);
         argc--;
         argv++;
      } 
   }

   if (argc > 1)
   {
      strncpy(g_AppName, argv[1], XL_MAX_APPNAME);
      g_AppName[XL_MAX_APPNAME] = 0;
      printf("AppName = %s\n", g_AppName);
      argc--;
      argv++;
   }

   if (argc > 1)
   {
      sscanf (argv[1], "%lx", &txID ) ;

      if (txID)
      {
         printf("TX ID = %lx\n", txID);
      }
   }

   // ------------------------------------
   // initialize the driver structures 
   // for the application
   // ------------------------------------
   xlStatus = demoInitDriver(&xlChanMaskTx, &xlChanIndex);
   printf("- Init             : %s\n", xlGetErrorString(xlStatus));
  
#if 0
   if (XL_SUCCESS == xlStatus)
   {
      // ------------------------------------
      // create the RX thread to read the
      // messages
      // ------------------------------------
      xlStatus = demoCreateRxThread();
      printf("- Create RX thread : %s\n",  xlGetErrorString(xlStatus));
   }
#endif

   if (XL_SUCCESS == xlStatus)
   {
      // ------------------------------------
      // go with all selected channels on bus
      // ------------------------------------
      xlStatus = xlActivateChannel(g_xlPortHandle, g_xlChannelMask, XL_BUS_TYPE_CAN, XL_ACTIVATE_RESET_CLOCK);
      printf("- ActivateChannel  : CM=0x%I64x, %s\n", g_xlChannelMask, xlGetErrorString(xlStatus));
      if (xlStatus == XL_SUCCESS)
      {
         activated = 1;
      }
   }

   printf("\n: Press <h> for help - actual channel Ch=%d, CM=0x%02I64x\n", xlChanIndex, xlChanMaskTx);

   // initialise the J1939 stack
   J1939_stk_init();

   // ------------------------------------
   // parse the key - commands
   // ------------------------------------
   while (stop == 0)
   {
      unsigned long n;
      INPUT_RECORD ir;

      // run the J1939 stack
      J1939_stk_periodic();

      ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &ir, 1, &n);

      if ((n == 1) && (ir.EventType == KEY_EVENT))
      {
         if (ir.Event.KeyEvent.bKeyDown)
         {
            c = ir.Event.KeyEvent.uChar.AsciiChar;

            switch (c)
            {
               case 'v':
                  if (g_silent)
                  {
                     g_silent = 0;
                     printf("- screen on\n");
                  }
                  else
                  {
                     g_silent = 1;
                     printf("- screen off\n");
                  }
               break;

               case 't': // transmit a message
                  demoTransmit(txID, xlChanMaskTx);
               break;

               case 'b':  // transmit message burst 
                  demoTransmitBurst(txID);
               break; 

               case 'm': // transmit a remote message
                  demoTransmitRemote(txID, xlChanMaskTx);
               break;

               case '-': // channel selection
                  if (xlChanIndex == 0)
                  {
                     xlChanIndex = g_xlDrvConfig.channelCount;
                  }
                  xlChanIndex--;
            
				  xlChanMaskTx = g_xlDrvConfig.channel[xlChanIndex].channelMask;
                  printf("- TX Channel set to channel: %02d, %s CM(0x%I64x)\n", 
                     g_xlDrvConfig.channel[xlChanIndex].channelIndex, g_xlDrvConfig.channel[xlChanIndex].name, xlChanMaskTx);
               break;
            
               case '+': // channel selection   
                  xlChanIndex++;
                  if (xlChanIndex >= g_xlDrvConfig.channelCount)
                  {
                     xlChanIndex = 0;
                  }

                  xlChanMaskTx = g_xlDrvConfig.channel[xlChanIndex].channelMask;
                  printf("- TX Channel set to channel: %02d, %s CM(0x%I64x)\n", 
                  g_xlDrvConfig.channel[xlChanIndex].channelIndex, g_xlDrvConfig.channel[xlChanIndex].name, xlChanMaskTx);
               break;

               case 'x':
                  txID ^= XL_CAN_EXT_MSG_ID; // toggle ext/std
                  printf("- Id set to 0x%08X\n", txID);
               break;

               case 'I': // id selection
                  if (txID & XL_CAN_EXT_MSG_ID)
                  {
                     txID = (txID-1) | XL_CAN_EXT_MSG_ID;
                  }
                  else if (txID == 0)
                  {
                     txID = 0x7FF;
                  }
                  else
                  {
                     txID--;
                  }
                  printf("- Id set to 0x%08X\n", txID);
               break;

               case 'i':
                  if (txID & XL_CAN_EXT_MSG_ID)
                  {
                     txID = (txID+1) | XL_CAN_EXT_MSG_ID;
                  }
                  else if (txID == 0x7FF)
                  {
                     txID = 0;
                  }
                  else
                  {
                     txID++;
                  }
                  printf("- Id set to 0x%08X\n", txID);
               break;

               case 'g':
                  xlStatus = xlCanRequestChipState(g_xlPortHandle, g_xlChannelMask);
                  printf("- RequestChipState : CM(0x%I64x), %s\n", g_xlChannelMask, xlGetErrorString(xlStatus));
               break;

               case 'a':
                  if (g_TimerRate)
                  {
                     g_TimerRate = 0; 
                  }
                  else
                  {
                     g_TimerRate = 20000;
                  }
                  xlStatus = xlSetTimerRate(g_xlPortHandle, g_TimerRate);
                  printf("- SetTimerRate     : %d, %s\n", g_TimerRate, xlGetErrorString(xlStatus));
               break;

               case 'o':
                  switch(outputMode)
                  {
                     case XL_OUTPUT_MODE_NORMAL:
                        outputMode = XL_OUTPUT_MODE_SILENT;
                     break;

                     case XL_OUTPUT_MODE_SILENT:
                        outputMode = XL_OUTPUT_MODE_TX_OFF;
                     break;

                     case XL_OUTPUT_MODE_TX_OFF:
                     default:
                        outputMode = XL_OUTPUT_MODE_NORMAL;
                     break;
                  }
            
                  demoSetOutput(outputMode, xlChanMaskTx);
               break;

               case 'r':
                  xlStatus = xlResetClock(g_xlPortHandle);
                  printf("- ResetClock       : %s\n", xlGetErrorString(xlStatus));
               break;

               case 's':
                  if (activated)
                  {
                     activated = 0;
                  }
                  else
                  {
                     activated = 1;
                  }
                  demoStartStop(activated);
               break;

               case 'p':
                  demoPrintConfig();
               break;

               case 27: // end application
                  stop = 1;
               break;

               case 'h':
                  demoHelp();
               break;

               default:
               break;
               // end switch
            }
         }
      }
   } // end while
  

   if ((XL_SUCCESS != xlStatus) && activated)
   { 
      xlStatus = xlDeactivateChannel(g_xlPortHandle, g_xlChannelMask);
      printf("- DeactivateChannel: CM(0x%I64x), %s\n", g_xlChannelMask, xlGetErrorString(xlStatus));
   } 
   demoCleanUp();

   return(0);
} // end main()