⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csr.c

📁 GSM手机设计软件代码
💻 C
📖 第 1 页 / 共 2 页
字号:
          theCallReference[0] =
            receivedSignal.sig.csrPosnDataReq.callReference;
          theBcdNum[0] =
            receivedSignal.sig.csrPosnDataReq.calledBcdNumber;

          if (receivedSignal.sig.csrPosnDataReq.csrOnlyCall) {
            requireTa[0] = FALSE;
            ctState = CT_STATE_WANT_DATA;
          }
          else {
            requireTa[0] = TRUE;
            ctState = CT_STATE_WANT_TA;
          }

          sendRrCsrMeasReq(&signalToSend);

          if (TimerRunning (&ctDataTimer)) {
            /* Timer is running and it shouldn't be so stop it. */
            StopTimer (&ctDataTimer);
          }
          
          StartTimer (&ctDataTimer);
        }
        else {
          /* What should we do if already want data?  Need to
             extract CallReference and CalledPartyBcdNum and also
             check what type of call it is. If it is not an
             csrOnlyCall and the previous ones have been then we
             are currently only waiting for data and should change
             to waiting for TA */
          if (nCalls < MAX_CALLS)
          {
            ++nCalls;
            theCallReference[nCalls-1] =
              receivedSignal.sig.csrPosnDataReq.callReference;
            theBcdNum[nCalls-1] =
              receivedSignal.sig.csrPosnDataReq.calledBcdNumber;

            if (receivedSignal.sig.csrPosnDataReq.csrOnlyCall)
            {
              requireTa[nCalls-1] = FALSE;
            }
            else {
              requireTa[nCalls-1] = TRUE;
              /* we now require TA, if didn't before we ought
                 to give phone more time to get it. */
              if (ctState == CT_STATE_WANT_DATA)
              {
                ctState = CT_STATE_WANT_TA;
                /* Need to give phone a little more time in
                   order to get the timing advance therefore
                   stop timer and restart it */
                if (TimerRunning (&ctDataTimer))
                {
                  StopTimer (&ctDataTimer);
                }
                
                StartTimer (&ctDataTimer);
              }
            }

          } /* end of if(nCalls < MAX_CALLS) */
        } /* end of if (not in IDLE state) */

          /* need to send CsrProceedingInd signal */
        sendCsrProceedingInd(&signalToSend,&(theCallReference[nCalls-1]));
        break;

      case (SIG_TIMER_EXPIRY):
        if((ctState != CT_STATE_IDLE))
        {
          readyToSend = TRUE;
          ctState = CT_STATE_IDLE;
        }
        break;

      case (SIG_CSR_ABORT_REQ):
        if (ctState != CT_STATE_IDLE)
        {
          /* Need to check that at least one of the calls being
             setup has the correct call reference */
          for (looper = 0; looper < nCalls; looper++)
          {
            if(((receivedSignal.sig).csrAbortReq).callReference ==
               theCallReference[looper])
            {
              /* Send confimation of the abort message back to AL. */
              sendCsrAbortCnf(&signalToSend,&(theCallReference[looper]));
              if (nCalls == 1)
              {
                /* This is the only call therefore stop timer */
                /* we expect the timer to be still running
                   at this point, so stop it. */
                if (TimerRunning (&ctDataTimer))
                {
                  StopTimer (&ctDataTimer);
                }
                ctState = CT_STATE_IDLE;
                nCalls = 0;
              }
              else {
                /* This is not the only call. Therefore only remove
                   this one from the loop. Shift all those further
                   along in list back one, then decrement nCalls*/
                for (looper2 = looper; looper2 < (nCalls - 1); ++looper2)
                {
                  theCallReference[looper2] = 
                    theCallReference[looper2+1];
                  theBcdNum[looper2] = theBcdNum[looper2+1];
                  requireTa[looper2] = requireTa[looper2+1];
                }
                --nCalls;

                /* If that was the only call that wanted TA then we
                   move to state CT_STATE_WANT_DATA otherwise stay in
                   CT_STATE_WANT_TA. */
                ctState = CT_STATE_WANT_DATA;
                for (looper2 = 0; looper2 < nCalls; ++looper2)
                {
                  if (requireTa[looper2]) {
                    ctState = CT_STATE_WANT_TA;
                  }
                }
              } /* end of if nCalls=1 */
              break; /* Break from loop not case. */
            } /* end of if call reference correct */
          } /* end of loop */
        }
        break;

      case (SIG_RR_CSR_TIMINGADV_IND):
        /* Extract timing advance info and timetag it. */
        GetRelativeTime(&currentTime);
        taBuffer.timeTag = currentTime;
        taBuffer.taData = (receivedSignal.sig).rrCsrTimingAdvInd;
        taBuffer.taValid = TRUE;
        /* if waiting for timing advance: you've got it now so go
           ahead and send message. */
        if (ctState == CT_STATE_WANT_TA)
        {
          /* we expect the timer to be still running at this
             point, so stop it. */
          if (TimerRunning (&ctDataTimer))
          {
            StopTimer (&ctDataTimer);
          }
          readyToSend = TRUE;
          ctState = CT_STATE_IDLE;
        }
        break;

      default:
        break;
    } /* end of message switch */

      /* Now we have handled the event as appropriate, see if we
         can send some data
      */
    if (readyToSend)
    {
      /* get CurrentTime. */
      GetRelativeTime (&currentTime);

      /* check that dataset haven't been outdated ie. were received
         within MAX_DATA_TIME.  If not then invalidate that dataset.
         Doing the comparision like this enables overflowing of
         currentTime from 2^31-1 to 0 to be allowed relies on the fact
         that FrameTicks is an unsigned 32 bit integer */
      if ((UInt32)(currentTime - dataBuffer.timeTag) > MAX_DATA_TIME) {
        dataBuffer.dataValid = FALSE;
        validData = FALSE;
      }
      else {
        validData = TRUE;
      }
    
      if ((UInt32)(currentTime - taBuffer.timeTag) > MAX_DATA_TIME) {
        taBuffer.taValid = FALSE;
      }

      /* loop through all the position requests that have been
         setup and send back the data */
      for ( ; nCalls > 0; --nCalls)
      {
        sendCsrPosnDataCnf(&taBuffer,
                           &signalToSend,
                           &(theCallReference[nCalls-1]),
                           &(theBcdNum[nCalls-1]),
                           validData);
      }
    } /* end of if (readyToSend) */
  } /* end of while (true) */

  /* will never get here. */
}

void sendRrCsrMeasReq(SignalBuffer * const signalOut)
{
  signalOut->type = SIG_RR_CSR_MEAS_REQ;
  SendSignal(RR_TASK_ID,signalOut);
}

void sendCsrProceedingInd(      SignalBuffer  * const signalOut,
                                const CallReference * const callRef)
{
  signalOut->type = SIG_CSR_PROCEEDING_IND;
  signalOut->sig.csrProceedingInd.callReference = *callRef;

  SendSignal(AL_TASK_ID,signalOut);
}

void sendCsrAbortCnf(      SignalBuffer  * const signalOut,
                           const CallReference * const callRef)
{
  signalOut->type = SIG_CSR_ABORT_CNF;
  signalOut->sig.csrAbortCnf.callReference =  *callRef;

  SendSignal(AL_TASK_ID,signalOut);
}


/*
 * May need to add the DataBuffer and oldest buffer arguments, but
 * don't need them for this example.
 */
void sendCsrPosnDataCnf(const TaBuffer          * const taBuffer,
                              SignalBuffer      * const signalOut,
                        const CallReference     * const callRef,
                        const CalledPartyBcdNum * const bcdNum,
                        const Boolean                   gotData)
{
  /* temporary pointer to CsrPosnDataCnf signal */
  CsrPosnDataCnf * signalData;
  TimingData data;

  signalOut->type = SIG_CSR_POSN_DATA_CNF;

  signalData = &(signalOut->sig.csrPosnDataCnf);
  signalData->callReference = *callRef;

  if (!gotData)
  {
    signalData->cursorDataValid = FALSE;
  } 
  else 
  {
    signalData->cursorDataValid = TRUE;
    getTimingData(taBuffer, &data);
    /* For an SMS message we need call createSMS at the some point. */
    createSMS(bcdNum, 0, &(signalData->cursorData[0]), &data);
  }

  SendSignal(AL_TASK_ID,signalOut);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -