canoe循环切换会话 脚本怎么写

canoe中循环切换会话的脚本,例如10 01 切换到10 02,10 01切换至10 03,10 02切换此10 03,10 02 再切换10 01 以此类推的覆盖全部切换方式的脚本怎么写


includes
{
  
}
/*
*Purpose:session switch
*Realize ideas: 发送10 01 正响应回复50 01 ,负响应7F 01 xx (根据xx,NRC的值来确认具体的问题)
*回复50 01,接着发送10 02 ,正响应50 02,负响应7F 02 xx (根据xx,NRC的值来确认具体的问题),
*回复50 02,接着发送10 03 ,正响应50 03,负响应7F 03 xx  (根据xx,NRC的值来确认具体的问题),
以此类推,会话相互切换,覆盖全部的切换方式。
*/
variables
{
  message * TestMsg;
  _align(1) struct SessionSwitch_t
  {
    byte u8Did[2];
  };
  struct SessionSwitch_t tDidCfgMap[9] = {
    {{0x10, 0x01}},
    {{0x10, 0x02}},
    {{0x10, 0x01}},
    {{0x10, 0x03}},
    {{0x10, 0x02}},
    {{0x10, 0x01}},
    {{0x10, 0x02}},
    {{0x10, 0x03}},
    {{0x10, 0x01}}
  };
  msTimer SessionSwitchTime;
  byte CnDidTestCurIdx;// elCount(tDidCfgMap)
  byte CnDidTestIdxMax;
  byte CnDidCurMsgSendCnt = 0;
  byte CnDidSwitchFlag = 0;
  message 0x77e DiagReq = {
    dlc=8
  };
}

on start
{
  write("on start");
  CnDidTestIdxMax = elCount(tDidCfgMap);
}

on timer SessionSwitchTime 
{
  byte BufTemp[8];
  TestMsg.id = 0x77E;
  TestMsg.dlc = 8;
  output(TestMsg);
  
  
}

on key 't'
{
  write("on key 't'");
  SendDiagReqCheckDidState();
  setTimer(SessionSwitchTime,150);
}

on message 0x7BE
{
  message 0x77E msg1;
  byte RxDidLength;
  byte BufTemp[8];
  if((this.byte(0) == 0x06 && 0x03)
    &&(this.byte(1) == 0x50 && 0x7F)
    &&(this.byte(2) == tDidCfgMap[CnDidTestCurIdx].u8Did[1])
    )
  {
    msg1.dlc = 8;
    CnDidTestCurIdx++;
    msg1.byte(0) = 0x02;
    msg1.byte(1) = tDidCfgMap[CnDidTestCurIdx].u8Did[0];
    msg1.byte(2) = tDidCfgMap[CnDidTestCurIdx].u8Did[1];
    output(msg1);
  }
  if(CnDidTestCurIdx == 1)
  {
    for(CnDidTestCurIdx = 1; CnDidTestCurIdx <= 9; CnDidTestCurIdx++)
    {
      if(RxDidLength == 6)
      {
        msg1.byte(0) = 0x02;
        msg1.byte(1) = tDidCfgMap[CnDidTestCurIdx].u8Did[0];
        msg1.byte(2) = tDidCfgMap[CnDidTestCurIdx].u8Did[1];
        output(msg1);
        setTimer(SessionSwitchTime,150);
       
      }
    }
    
  }
 /* else if(CnDidTestCurIdx == 3)
  {
    for(CnDidTestCurIdx = 3; CnDidTestCurIdx >= 0; CnDidTestCurIdx--)
    {
      if(RxDidLength == 6)
      {
        msg1.byte(0) = 0x02;
        msg1.byte(1) = tDidCfgMap[CnDidTestCurIdx].u8Did[0];
        msg1.byte(2) = tDidCfgMap[CnDidTestCurIdx].u8Did[1];
      }
      else
      {
        break;
      }
    }
  }*/
   
}

void SendDiagReq(byte Buff[], byte Length)
{
  byte CnDidIdx = 0;
  DiagReq.byte(0) = 0x00 + Length;

  for (CnDidIdx=0;CnDidIdx < Length;CnDidIdx ++)
  {
    DiagReq.byte(1+CnDidIdx) = Buff[CnDidIdx];
  }
  output(DiagReq);
}

 
void SendDiagReqCheckDidState()
{ 
  byte BufTemp[8];
  BufTemp[0] = tDidCfgMap[CnDidTestCurIdx].u8Did[0];
  BufTemp[1] = tDidCfgMap[CnDidTestCurIdx].u8Did[1];
  SendDiagReq(BufTemp, 2);
}