示例#1
0
文件: cs2eth.c 项目: GBert/railroad
static void ProcessSystemData(Cs2ethStruct *Data, MrIpcCmdType *CmdFrame)
{  char UdpFrame[MR_CS2_UDP_LENGTH];
   MrCs2CanDataType CanMsg;
   int i;
   ClientInfo *OneClient;

   if (MrIpcGetCommand(CmdFrame) != MrIpcCmdNull)
   {
      switch (MrIpcGetCommand(CmdFrame))
      {
         case MrIpcCmdRequestLocName:
         case MrIpcCmdRequestLocInfo:
            break;
         default:
            MrIpcDecodeToCan(CmdFrame, &CanMsg);
            if (Cs2ethGetVerbose(Data))
            {
#ifdef TRACE
               if (Cs2ethGetTrace(Data))
                  MrCs2Trace(&CanMsg);
#endif
               printf("send can data 0x%lx %d to UDP client\n    ",
                      MrCs2GetId(&CanMsg), MrCs2GetDlc(&CanMsg));
               for (i = 0; i < 8; i++)
                  printf("0x%02x ", CanMsg.Data[i]);
               printf("\n    hash 0x%x resp 0x%x cmd 0x%x prio 0x%x\n",
                      MrCs2GetHash(&CanMsg), MrCs2GetResponse(&CanMsg),
                      MrCs2GetCommand(&CanMsg), MrCs2GetPrio(&CanMsg));
            }
            MrEthCs2Encode(UdpFrame, &CanMsg);
            if (Cs2ethGetUdpConnected(Data))
            {
               if ((MrIpcGetReceiverSocket(CmdFrame) == MR_IPC_SOCKET_ALL) ||
                   (MrIpcGetReceiverSocket(CmdFrame) == Cs2ethGetOutsideUdpSock(Data)))
               {
                  if (Cs2ethGetVerbose(Data))
                     puts("send as udp");
                  MrEthCs2SendTo(Cs2ethGetOutsideUdpSock(Data),
                                 (struct sockaddr_in *)&(Cs2ethGetClientAddr(Data)),
                                 UdpFrame);
               }
            }
            MengeInitIterator(Cs2ethGetClientIter(Data),
                              Cs2ethGetClients(Data));
            OneClient = (ClientInfo *)MengeFirst(Cs2ethGetClientIter(Data));
            while (OneClient != (ClientInfo *)NULL)
            {
               if ((MrIpcGetReceiverSocket(CmdFrame) == MR_IPC_SOCKET_ALL) ||
                   (MrIpcGetReceiverSocket(CmdFrame) == OneClient->ClientSock))
               {
                 if (Cs2ethGetVerbose(Data))
                     printf("send to tcp socket %d\n", OneClient->ClientSock);
                  MrEthCs2Send(OneClient->ClientSock, UdpFrame);
               }
               OneClient = (ClientInfo *)MengeNext(Cs2ethGetClientIter(Data));
            }
            break;
      }
   }
}
示例#2
0
文件: cs2eth.c 项目: GBert/railroad
static void ProcessOutsideData(Cs2ethStruct *Data, MrCs2CanDataType *CanMsg,
                               int SenderSocket)
{  MrIpcCmdType Cmd;
#ifdef TRACE
   unsigned long Uid;
   int SoftwareVersion, DeviceId;
#endif
   int i;

   if (Cs2ethGetVerbose(Data))
   {
      printf("can data 0x%lx %d\n    ",
             MrCs2GetId(CanMsg), MrCs2GetDlc(CanMsg));
      for (i = 0; i < 8; i++)
         printf("0x%02x ", CanMsg->Data[i]);
      printf("\n    hash 0x%x resp 0x%x cmd 0x%x prio 0x%x\n",
             MrCs2GetHash(CanMsg), MrCs2GetResponse(CanMsg),
             MrCs2GetCommand(CanMsg), MrCs2GetPrio(CanMsg));
#ifdef TRACE
      switch (MrMs2GetCommand(CanMsg))
      {
         case MR_MS2_CMD_PING:
            switch (MrCs2GetNumParamBytes(CanMsg))
            {
               case 0:
                  MrCs2DecPing0(CanMsg);
                  if (Cs2ethGetVerbose(Data))
                     puts("Softwarestand Anfrage/Teilnehmer Ping");
                  break;
               case 8:
                  MrCs2DecPing8(CanMsg, &Uid, &SoftwareVersion, &DeviceId);
                  if (Cs2ethGetVerbose(Data))
                     printf("Softwarestand Anfrage/Teilnehmer Ping (Uid = 0x%lx, SwVersion = 0x%x, DeviceId = 0x%x)\n",
                            Uid, SoftwareVersion, DeviceId);
                  break;
               default:
                  if (Cs2ethGetVerbose(Data))
                     puts("Softwarestand Anfrage/Teilnehmer Ping (unknown parameter)");
                  break;
            }
            break;
         default:
            break;
      }
      if (Cs2ethGetTrace(Data))
         MrCs2Trace(CanMsg);
#endif
   }
   MrIpcInit(&Cmd);
   MrIpcEncodeFromCan(&Cmd, CanMsg);
   MrIpcSetSenderSocket(&Cmd, SenderSocket);
   MrIpcSetReceiverSocket(&Cmd, MR_IPC_SOCKET_ALL);
   if (MrIpcGetCanHash(&Cmd) == 0)
      MrIpcSetCanHash(&Cmd, MrCs2CalcHash(MrIpcGetCanHash(&Cmd)));
   MrIpcSend(Cs2ethGetClientSock(Data), &Cmd);
   MrIpcExit(&Cmd);
}
示例#3
0
void MrCs2Decode(MrCs2CanDataType *CanMsg, CanFrameStruct *CanFrame)
{  unsigned CanHash, Response, Command, Prio, i;

   MrCs2SetId(CanMsg, CanFrame->CanId);
   MrCs2SetDlc(CanMsg, CanFrame->CanDlc);
   for (i = 0; i < 8; i++)
      CanMsg->Data[i] = CanFrame->CanData[i];
   MrCs2DecodeId(MrCs2GetId(CanMsg), &CanHash, &Response, &Command, &Prio);
   MrCs2SetHash(CanMsg, CanHash & ~MR_CS2_MASK_HASH_MAGIC);
   MrCs2SetResponse(CanMsg, Response);
   MrCs2SetCommand(CanMsg, Command);
   MrCs2SetPrio(CanMsg, Prio);
   MrCs2SetIsCs2(CanMsg, MrCs2IsCs2Msg(CanHash, MrCs2GetCommand(CanMsg)));
}