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

📄 calc_rt.c

📁 Source code for an Numeric Cmputer
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Classic Ladder Project *//* Copyright (C) 2001 Marc Le Douarain *//* mavati@club-internet.fr *//* http://www.multimania.com/mavati/classicladder *//* February 2001 *//* Last update : 19 Ocotober 2002 *//* -------------- *//* Refresh a rung *//* -------------- *//* This library is free software; you can redistribute it and/or *//* modify it under the terms of the GNU Lesser General Public *//* License as published by the Free Software Foundation; either *//* version 2.1 of the License, or (at your option) any later version. *//* This library is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *//* Lesser General Public License for more details. *//* You should have received a copy of the GNU Lesser General Public *//* License along with this library; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "rtapi.h"#include "arithm_eval.h"#include "classicladder.h"#include "global.h"#include "vars_access.h"#include "manager.h"#ifdef SEQUENTIAL_SUPPORT#include "calc_sequential_rt.h"#endif#include "calc_rt.h"static char StateOnLeft(int x,int y,StrRung * TheRung){    char State = 0;    int PosY;    char StillConnected;    if (x==0)        return 1;    /* Direct on left */    if (TheRung->Element[x-1][y].DynamicOutput)        State = 1;    /* Up */    PosY = y;    StillConnected = TheRung->Element[x][PosY].ConnectedWithTop;    while( (PosY>0) && StillConnected)    {        PosY--;        if (TheRung->Element[x-1][PosY].DynamicOutput)            State = 1;        if ( !(TheRung->Element[x][PosY].ConnectedWithTop) )            StillConnected = FALSE;    }    /* Down */    if (y<RUNG_HEIGHT-1)    {        PosY = y+1;        StillConnected = TheRung->Element[x][PosY].ConnectedWithTop;        while( (PosY<RUNG_HEIGHT) && StillConnected)        {            if (TheRung->Element[x-1][PosY].DynamicOutput)                State = 1;            PosY++;            if (PosY<RUNG_HEIGHT)            {                if ( !(TheRung->Element[x][PosY].ConnectedWithTop) )                    StillConnected = FALSE;            }        }    }    return State;}/* Elements : -| |- and -|/|- */static char CalcTypeInput(int x,int y,StrRung * UpdateRung,char IsNot,char OnlyFronts){    char State;    char StateElement;    char StateVar;    StateElement = ReadVar(UpdateRung->Element[x][y].VarType,UpdateRung->Element[x][y].VarNum);    if (IsNot)        StateElement = !StateElement;    StateVar = StateElement;    if (OnlyFronts)    {        if (StateElement && UpdateRung->Element[x][y].DynamicVarBak)            StateElement = 0;    }    UpdateRung->Element[x][y].DynamicState = StateElement;    if (x==0)    {        State = StateElement;    }    else    {        UpdateRung->Element[x][y].DynamicInput = StateOnLeft(x,y,UpdateRung);        State = StateElement && UpdateRung->Element[x][y].DynamicInput;    }    UpdateRung->Element[x][y].DynamicOutput = State;    UpdateRung->Element[x][y].DynamicVarBak = StateVar;    return State;}/* Element : --- */static char CalcTypeConnection(int x,int y,StrRung * UpdateRung){    char State;    char StateElement;    StateElement = 1;    if (x==0)    {        State = StateElement;    }    else    {        UpdateRung->Element[x][y].DynamicInput = StateOnLeft(x,y,UpdateRung);        State = StateElement && UpdateRung->Element[x][y].DynamicInput;    }    UpdateRung->Element[x][y].DynamicState = State;    UpdateRung->Element[x][y].DynamicOutput = State;    return State;}/* Elements : -( )- and -(/)- */static char CalcTypeOutput(int x,int y,StrRung * UpdateRung,char IsNot){    char State;    State = StateOnLeft(x,y,UpdateRung);    UpdateRung->Element[x][y].DynamicInput = State;    UpdateRung->Element[x][y].DynamicState = State;    if (IsNot)        State = !State;    WriteVar(UpdateRung->Element[x][y].VarType,UpdateRung->Element[x][y].VarNum,State);    return State;}/* Elements : -(S)- and -(R)- */static char CalcTypeOutputSetReset(int x,int y,StrRung * UpdateRung,char IsReset){    char State;    UpdateRung->Element[x][y].DynamicInput = StateOnLeft(x,y,UpdateRung);    State = UpdateRung->Element[x][y].DynamicInput;    UpdateRung->Element[x][y].DynamicState = State;    if (State)    {        if (IsReset)            State = 0;  /* reset */        else            State = 1;  /* set */        WriteVar(UpdateRung->Element[x][y].VarType,UpdateRung->Element[x][y].VarNum,State);    }    return State;}/* Element : -(J)- */static int CalcTypeOutputJump(int x,int y,StrRung * UpdateRung){    char State;    int Goto = -1;    State = StateOnLeft(x,y,UpdateRung);    if (State)        Goto = UpdateRung->Element[x][y].VarNum;    UpdateRung->Element[x][y].DynamicInput = State;    UpdateRung->Element[x][y].DynamicState = State;    return Goto;}/* Element : -(C)- */static int CalcTypeOutputCall(int x,int y,StrRung * UpdateRung){    char State;    int CallSrSection = -1;    State = StateOnLeft(x,y,UpdateRung);    if (State)        CallSrSection = SearchSubRoutineWithItsNumber( UpdateRung->Element[x][y].VarNum );    UpdateRung->Element[x][y].DynamicInput = State;    UpdateRung->Element[x][y].DynamicState = State;    return CallSrSection;}/* Element : Timer (2x2 Blocks) */static void CalcTypeTimer(int x,int y,StrRung * UpdateRung){    StrTimer * Timer;    Timer = &TimerArray[UpdateRung->Element[x][y].VarNum];    if (x==0)    {        Timer->InputEnable = 1;    }    else    {        Timer->InputEnable = StateOnLeft(x-1,y,UpdateRung);    }    if (!Timer->InputEnable)    {        Timer->OutputRunning = 0;        Timer->OutputDone = 0;        Timer->Value = Timer->Preset;    }    else    {        if (Timer->Value>0)        {            Timer->Value -= InfosGene->TimeSinceLastScan;            Timer->OutputRunning = 1;            Timer->OutputDone = 0;        }        else        {            Timer->OutputRunning = 0;            Timer->OutputDone = 1;        }    }    UpdateRung->Element[x][y].DynamicOutput = Timer->OutputDone;    UpdateRung->Element[x][y+1].DynamicOutput = Timer->OutputRunning;}/* Element : Monostable (2x2 Blocks) */static void CalcTypeMonostable(int x,int y,StrRung * UpdateRung){    StrMonostable * Monostable;    Monostable = &MonostableArray[UpdateRung->Element[x][y].VarNum];    if (x==0)    {        Monostable->Input = 1;    }    else    {        Monostable->Input = StateOnLeft(x-1,y,UpdateRung);    }    /* detecting impulse on input, the monostable is not retriggerable */    if (Monostable->Input && !Monostable->InputBak && (Monostable->Value==0) )    {        Monostable->OutputRunning = 1;        Monostable->Value = Monostable->Preset;    }    if (Monostable->Value>0)        Monostable->Value -= InfosGene->TimeSinceLastScan;    else        Monostable->OutputRunning = 0;    Monostable->InputBak = Monostable->Input;    UpdateRung->Element[x][y].DynamicOutput = Monostable->OutputRunning;}/* Element : Compar (3 Horizontal Blocks) */static char CalcTypeCompar(int x,int y,StrRung * UpdateRung){    char State;    char StateElement;    StateElement = EvalCompare(ArithmExpr[UpdateRung->Element[x][y].VarNum].Expr);    UpdateRung->Element[x][y].DynamicState = StateElement;    if (x==2)    {

⌨️ 快捷键说明

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