//***************************************************************************** // Executes commands within a adress range //***************************************************************************** void ExecuteFromStack(void) { uart_cmd_t *cmd = GetCmdPointer(); stack_info_t *stack = GetStackPointer(); timing_info_t *timing = GetTimerPointer(); bool loop = stack->contExecution; int j = stack->stopIdx; // // assign code entry point in stack // NB!: entry point is always valid // handled by cmdqueue commands // stack->currIdx = stack->startIdx; // // Execute code from stack, if user cancels execution // finish executing current function, before returning // cancel is handled from uart interrupt service routine // while (stack->currIdx != j && stack->execFromStack) { // calculate usage if running a script CalculateUsage(timing); timing->cmdStart = SysTickValueGet(); // check if current stack i properly populated, skip overwise if (uartCmdStack[stack->currIdx].commandFound) { // copy command from stack to cmd GetFromStack(stack->currIdx); ExecuteCommand(cmd); stack->currIdx++; } else { // increment stack counter if command is not valid stack->currIdx++; } // loop forever if requested if (loop && stack->currIdx >= j) { stack->currIdx = stack->startIdx; } // Get stop value for timing timing->cmdStop = SysTickValueGet(); } // reset stack control strucutre after // execution has been completed or // canceled StackResetCtrlStructure(stack); }
// Calculate the number of bytes available for use DWORD CConnection::TCPBandwidthMeter::CalculateLimit(DWORD tNow, bool bOut, bool bMaxMode ) const { DWORD tCutoff = tNow - METER_SECOND; // Time period for bytes if ( bMaxMode ) tCutoff += METER_MINIMUM; // Adjust time period for Max mode DWORD nData = CalculateUsage( tCutoff, true ); // #bytes in the time period // nLimit is the speed limit (bytes/second) DWORD nLimit = *pLimit; // Get the speed limit if ( bOut && Settings.Live.BandwidthScaleOut < 100 ) nLimit = nLimit * Settings.Live.BandwidthScaleOut / 100; // Adjust limit based on the scale percentage else if ( ! bOut && Settings.Live.BandwidthScaleIn < 100 ) // The scale is turned down and we should use it nLimit = nLimit * Settings.Live.BandwidthScaleIn / 100; // Adjust limit based on the scale percentage // nLimit - nData is the number of bytes still available for this time period // Set nData to this, or 0 if we're over the limit nData >= nLimit ? nData = 0 : nData = nLimit - nData; // Is this running in max mode if ( bMaxMode ) { // Adjust limit for the time elapsed since last time nLimit = nLimit * ( tNow - tLastLimit ) / 1000; // nData = speed limit in bytes per second - bytes we read in the last second // nLimit = speed limit in bytes per second * elapsed time // Return the smaller of the two nLimit = min( nLimit, nData ); } else { // Set limit to the number of bytes still available for this time period nLimit = nData; } tLastLimit = tNow; // The time of this limit calculation return nLimit; // Return the new limit }
//***************************************************************************** // This is the main routine of the command line processor, this routine should // ideally run in the while loop in the main(), but it also can be run in // a task/thread on a RTOS // // This function checks if enter key has been detected by the interrupt // service routine and if it's true, the processing of the buffer and // execution of the command will take place // //***************************************************************************** void CMDLineScheduler (void) { uart_info_t *packet = GetUartPointer(); uart_cmd_t *cmd = GetCmdPointer(); timing_info_t *timing = GetTimerPointer(); stack_info_t *stack = GetStackPointer(); if(packet->enterFlag) { CalculateUsage(timing); timing->cmdStart = SysTickValueGet(); cmd->currentCmd = UARTEncodeCommand(packet); UARTGetArguments(packet, cmd); if (!FindCommand(cmd)) { if (packet->rxCount >= MIN_CMD_LENGTH) { UARTprintf(CMD_NOT_FOUND); } } else { ExecuteCommand(cmd); SaveToStack(cmd); if (stack->execFromStack) { ExecuteFromStack(); } } CMDResetCtrlStructure(cmd); UARTResetCtrlStructure(packet); timing->cmdStop = SysTickValueGet(); // display different input prompts based on mode // during scripting, show current stack position if (stack->saveCommands) { UARTprintf(STACK_PROMPT, stack->stackIdx); } else { UARTprintf(INPUT_PROMPT); } } }