Пример #1
0
static char cRead( char cBus, char cAddress, char *pcData, char cBytes )
{
    vStart( cBus );

    /* Check if SCL is not held down */
    if( !cGetSCL( cBus ) )
    {
        return wireSTATUS_HELD_LOW;
    }

    /* Send Address */
    cSendByte( cBus, cAddress | 0x01 );
    if( !cGetAck( cBus ) )
    {
        vStop( cBus );
        return wireSTATUS_NACK;
    }

    /* Read Data */
    while( cBytes-- )
    {
        *pcData = cGetByte( cBus );
        pcData++;

        if( cBytes > 0 )
        {
            vSendAck( cBus );
        }
    }

    vSendNack(cBus);
    vStop( cBus );
    
    return wireSTATUS_SUCCESS;
}
Пример #2
0
static char cWrite( char cBus, char cAddress, char *pcData, char cBytes )
{
    vStart( cBus );

    /* Check if SCL is not held down */
    if( !cGetSCL( cBus ) )
    {
        return wireSTATUS_HELD_LOW;
    }

    /* Send Address */
    cSendByte( cBus, cAddress & 0xFE );
    if( !cGetAck( cBus ) )
    {
        vStop( cBus );
        return wireSTATUS_FAIL;
    }

    /* Send Data */
    while( cBytes-- )
    {
        cSendByte( cBus, *pcData );
        if( !cGetAck( cBus ) )
        {
            vStop( cBus );
            return wireSTATUS_NACK;
        }
        ++pcData;
    }

    vStop( cBus );
    return wireSTATUS_SUCCESS;
}
Пример #3
0
static int iRun()
{
	int fd=0,i=0,j,ret=0,try;

	fd=open(_acDevice,O_RDWR);
	if(fd<=0)
	{
		perror("open");
		return 0;
	}
	vInitCom(fd);
	pvPrint1("Test du port comm\n");
	if(iTestCx(fd))
	{
		printf("Ecowatt not found\n");
		vStop(fd);
		ret=-1;
	}
	else
	{
		if(_iFunction==-1)
		{

			pvPrint1("Ecowatt ready\n");
			if(iGetDate(fd))
			{
				printf("Ecowatt Date not found\n");
				ret=-1;
			}
			for(i=0;i<NB_JOUR;i++)
			{
				printf("%d pct\n\r",(i*100)/255);
				for(try=0;try<NB_TRY;try++)
				{
					if(iGetDay(fd,i))
					{
						printf("Recuperation jour %d  => ko\n",i);
					}
					else
					{
						pvPrint1("Recuperation jour %d  => ok\n",i);
						break;
					}
				}
				if(try==NB_TRY)
				{
					return -1;
				}
			}

			if(_bEmon)
				vSendDataEmoncs3();

			if(_bSql)
				vSendDataMysql();

			vSaveData();
		}
		else
		{
			for(i=0;i<255;i++)
			{
				iFonction(fd,_iFunction,i);
			}
		}

		vStop(fd);
	}