#include "realvalue.h"
#include "yt_unit_shm.h"

#include <stdio.h>

extern YT_UNIT_SHM *ytShm;

void set_realtime_io_value(quint8 commid, quint8 busadd, quint8 value, uint timestamp)
{

}

void set_realtime_real_value(quint8 commid, quint8 busadd, float value, uint timestamp)
{
    ytShm->spStatusList.spStatus[commid][busadd].REALTIME_VALUE = value*1.0;
    ytShm->spStatusList.spStatus[commid][busadd].REALTIME_TIMESTAMP = timestamp;
}


void set_realtime_value(quint8 commid, quint8 busadd, float value, uint timestamp)
{
//    printf("%d) %d %f\n",commid,busadd,value);
    if(commid<4)
    {
        if(ytShm->commList.comm[commid].ENABLED==0x01)
        {
            if(ytShm->sPointList.sPoint[commid][busadd].ENABLED==0x01)
            {
//                printf("pno_type:%d\n",ytShm->sPointList.sPoint[commid][busadd].PNO_TYPE);
                switch(ytShm->sPointList.sPoint[commid][busadd].PNO_TYPE)
                {
                case 0x01://开关量输入
                    set_realtime_io_value(commid, busadd, (value==0)?0x00:0x01, timestamp);
                    break;
                case 0x02://模拟量输入
                    set_realtime_real_value(commid, busadd, value, timestamp);
                    break;
                default:
                    break;
                }
            }
        }
    }
}
