Exemplo n.º 1
0
static void FlushRecordData(RecordWriter* writer, FILE* stream, const void* extra, size_t extraSize)
{
	if(writer->bufIndex == 0 && extraSize == 0)
	{
		return; //no data to flush
	}

	IOSeekEnd(stream);
	objsize_t recordStart = IOGetFilePos(stream);

	//write record
	IOWriteWordBE(stream, writer->bufIndex + extraSize);	//size
	IOWriteObjSizeBE(stream, OBJ_RECORD_ILLEGAL_OFFSET);	//next (uninitialized)
	if(writer->bufIndex > 0)
	{
		IOWrite(stream, writer->buf, writer->bufIndex);	//data
	}
	if(extraSize > 0)
	{
		IOWrite(stream, extra, extraSize);				//data (extra)
	}

	//update previous next-field
	objsize_t head = IOGetFilePos(stream);
	IOSetFilePos(stream, writer->prevNextOffset);
	IOWriteObjSizeBE(stream, recordStart);
	IOSetFilePos(stream, head); //TODO remove, not needed (it's not..?)

	//reset writer
	writer->bufIndex = 0;
	writer->prevNextOffset = recordStart + OBJ_RECORD_NEXT_OFFSET;
}
Exemplo n.º 2
0
bool Wiimote::Write()
{
	if (!m_write_reports.Empty())
	{
		Report const& rpt = m_write_reports.Front();

		bool const is_speaker_data = rpt[1] == WM_WRITE_SPEAKER_DATA;

		if (!is_speaker_data || m_last_audio_report.GetTimeDifference() > 5)
		{
			if (SConfig::GetInstance().iBBDumpPort > 0 && m_index == WIIMOTE_BALANCE_BOARD)
			{
				static sf::UdpSocket Socket;
				Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost, SConfig::GetInstance().iBBDumpPort);
			}
			IOWrite(rpt.data(), rpt.size());

			if (is_speaker_data)
			{
				m_last_audio_report.Update();
			}

			m_write_reports.Pop();
			return true;
		}
	}

	return false;
}
Exemplo n.º 3
0
bool Wiimote::Write()
{
	if (!m_write_reports.Empty())
	{
		Report const& rpt = m_write_reports.Front();

		bool const is_speaker_data = rpt[1] == WM_WRITE_SPEAKER_DATA;

		if (!is_speaker_data || m_last_audio_report.GetTimeDifference() > 5)
		{
			if (Core::g_CoreStartupParameter.iBBDumpPort > 0 && index == WIIMOTE_BALANCE_BOARD)
			{
				static sf::SocketUDP Socket;
				Socket.Send((char*)rpt.data(), rpt.size(), sf::IPAddress::LocalHost, Core::g_CoreStartupParameter.iBBDumpPort);
			}
			IOWrite(rpt.data(), rpt.size());

			if (is_speaker_data)
			{
				m_last_audio_report.Update();
			}

			m_write_reports.Pop();
			return true;
		}
	}

	return false;
}
Exemplo n.º 4
0
// Send a packet to the wiimote.
// report_type should be one of WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc.
bool Wiimote::SendRequest(unsigned char report_type, unsigned char* data, int length)
{
	unsigned char buffer[32] = {WM_SET_REPORT | WM_BT_OUTPUT, report_type};

	memcpy(buffer + 2, data, length);

	return (IOWrite(buffer, length + 2) != 0);
}
Exemplo n.º 5
0
Arquivo: mux.c Projeto: tguillem/vlc
int IOWriteTyped(void *opaque, uint8_t *buf, int buf_size,
                              enum AVIODataMarkerType type, int64_t time)
{
    VLC_UNUSED(time);

    sout_mux_t *p_mux = opaque;
    sout_mux_sys_t *p_sys = p_mux->p_sys;
    if ( !p_sys->b_header_done && type != AVIO_DATA_MARKER_HEADER )
        p_sys->b_header_done = true;
    return IOWrite(opaque, buf, buf_size);
}
Exemplo n.º 6
0
bool Wiimote::PrepareOnThread()
{
	// core buttons, no continuous reporting
	u8 static const mode_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_REPORT_MODE, 0, WM_REPORT_CORE};

	// Set the active LEDs and turn on rumble.
	u8 static const led_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_LEDS, u8(WIIMOTE_LED_1 << (m_index%WIIMOTE_BALANCE_BOARD) | 0x1)};

	// Turn off rumble
	u8 static const rumble_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_RUMBLE, 0};

	// Request status report
	u8 static const req_status_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_REQUEST_STATUS, 0};
	// TODO: check for sane response?

	return (IOWrite(mode_report, sizeof(mode_report)) &&
	        IOWrite(led_report, sizeof(led_report)) &&
	        (SLEEP(200), IOWrite(rumble_report, sizeof(rumble_report))) &&
	        IOWrite(req_status_report, sizeof(req_status_report)));
}
Exemplo n.º 7
0
bool Wiimote::Write()
{
	Report rpt;
	bool audio_written = false;
	
	if (m_audio_reports.Pop(rpt))
	{
		IOWrite(rpt.first, rpt.second);
		delete[] rpt.first;
		audio_written = true;
	}

	if (m_write_reports.Pop(rpt))
	{
		IOWrite(rpt.first, rpt.second);
		delete[] rpt.first;
		return true;
	}	

	return audio_written;
}
Exemplo n.º 8
0
void systemBeep(bool onoff)
{
#if !defined(BEEPER)
    UNUSED(onoff);
#elif defined(BEEPER_PWM)
    TIM_CtrlPWMOutputs(BEEPER_PWM_TIMER, onoff ? ENABLE : DISABLE);
    beeperState = onoff;
#else
    IOWrite(beeperIO, beeperInverted ? onoff : !onoff);
    beeperState = onoff;
#endif
}
Exemplo n.º 9
0
void systemBeep(bool onoff)
{
#ifdef BEEPER
    if (beeperFrequency == 0) {
        IOWrite(beeperIO, beeperInverted ? onoff : !onoff);
    } else {
        pwmWriteBeeper(onoff);
    }
#else
    UNUSED(onoff);
#endif
}
Exemplo n.º 10
0
static int WriteToHandle(HANDLE& dev_handle, WinWriteMethod& method, const u8* buf, size_t size)
{
  OVERLAPPED hid_overlap_write = OVERLAPPED();
  hid_overlap_write.hEvent = CreateEvent(nullptr, true, false, nullptr);

  DWORD written = 0;
  IOWrite(dev_handle, hid_overlap_write, method, buf, size, &written);

  CloseHandle(hid_overlap_write.hEvent);

  return written;
}
Exemplo n.º 11
0
void InnerNet::WriteData(SESSION* pSession)
{
	uint32_t uOutPackets = 0;
	uint32_t uTotalWrited = 0;
	int nRet = IOWrite(pSession->nSock, &pSession->oPacketList, INNERNET_MAX_RW_PEREVENT, &uOutPackets, &uTotalWrited);
	if (nRet == -1)
	{
		CloseSession(pSession->nSessionID);
		return;
	}
	pSession->uBlockDataSize -= uTotalWrited;
	pSession->uOutPacketCount += uOutPackets;
	uint32_t &uTotalOutPackets = GetOutPackets();
	uTotalOutPackets += uOutPackets;
}
Exemplo n.º 12
0
void Wiimote::Write()
{
  if (m_write_reports.Empty())
    return;

  Report const& rpt = m_write_reports.Front();

  if (SConfig::GetInstance().iBBDumpPort > 0 && m_index == WIIMOTE_BALANCE_BOARD)
  {
    static sf::UdpSocket Socket;
    Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost,
                SConfig::GetInstance().iBBDumpPort);
  }
  IOWrite(rpt.data(), rpt.size());

  m_write_reports.Pop();

  if (!m_write_reports.Empty())
    IOWakeup();
}
Exemplo n.º 13
0
trap_retval ReqFile_write( void )
{
    int          retval;
    file_write_req      *acc;
    file_write_ret      *ret;

    acc = GetInPtr( 0 );
    ret = GetOutPtr( 0 );

    retval = IOWrite( acc->handle, GetInPtr( sizeof(*acc) ),
                      ( GetTotalSize() - sizeof( *acc ) ) );
    if( retval < 0 ) {
        ret->err = retval;
        ret->len = 0;
    } else {
        ret->err = 0;
        ret->len = retval;
    }
    return( sizeof( *ret ) );
}
Exemplo n.º 14
0
//加载模块信息
void implementsetting::LoadModuleState(const string&host)
{
    unsigned char txBuf[12]= {0},rxBuf[12]= {0};
    unsigned char checkValue = 0;
    unsigned short *gpioBak = NULL;
    int len = 0;

    gpioBak = __ipGpioBak[host];

    txBuf[0] = 'R';

    for(int i =1; i<11; i++)
    {
        checkValue^=txBuf[i];
    }

    txBuf[11] = checkValue;

    IOWrite(host, (char*)txBuf, (int)sizeof(txBuf));
    len = (int)sizeof(txBuf);
    IORead(host, (char*)rxBuf, &len);

    if(rxBuf[0] != 'R')return;

    checkValue = 0;

    for(int i =1; i<11; i++)
    {
        checkValue^=rxBuf[i];
    }

    //if(checkValue != rxBuf[11])return;//此处不要检验

    for(int i =1,j=0; i<11; j++)
    {
        gpioBak[j] = rxBuf[i];
        i++;
        gpioBak[j] += rxBuf[i]*256;
        i++;
    }
}
Exemplo n.º 15
0
void targetPreInit(void)
{
    switch (hardwareRevision) {
    case BJF4_REV3:
    case BJF4_MINI_REV3A:
    case BJF4_REV4:
        break;
    default:
        return;
    }

    IO_t inverter = IOGetByTag(IO_TAG(UART1_INVERTER));
    IOInit(inverter, OWNER_INVERTER, 1);
    IOConfigGPIO(inverter, IOCFG_OUT_PP);

    bool high = false;
    serialPortConfig_t *portConfig = serialFindPortConfiguration(SERIAL_PORT_USART1);
    if (portConfig) {
        bool smartportEnabled = (portConfig->functionMask & FUNCTION_TELEMETRY_SMARTPORT);
        if (smartportEnabled && (telemetryConfig()->telemetry_inversion) && (feature(FEATURE_TELEMETRY))) {
            high = true;
        }
    }
    /* reverse this for rev4, as it does not use the XOR gate */
    if (hardwareRevision == BJF4_REV4) {
        high = !high;
    }
    IOWrite(inverter, high);

    /* ensure the CS pin for the flash is pulled hi so any SD card initialisation does not impact the chip */
    if (hardwareRevision == BJF4_REV3) {
        IO_t flashIo = IOGetByTag(IO_TAG(M25P16_CS_PIN));
        IOConfigGPIO(flashIo, IOCFG_OUT_PP);
        IOHi(flashIo);

        IO_t sdcardIo = IOGetByTag(IO_TAG(SDCARD_SPI_CS_PIN));
        IOConfigGPIO(sdcardIo, IOCFG_OUT_PP);
        IOHi(sdcardIo);
    }
}
Exemplo n.º 16
0
static void inverterSet(IO_t pin, bool on)
{
    IOWrite(pin, on);
}
Exemplo n.º 17
0
void ledSet(int led, bool on)
{
    const bool inverted = (1 << (led)) & ledPolarity;
    IOWrite(leds[led], on ? inverted : !inverted);
}
Exemplo n.º 18
0
//执行命令
bool implementsetting::ExcuteCmd(const string&ip,const string&sw,int chan)
{
    string str = __ioInfoMap[sw][chan-1];
    //mingw编译不通过,改为拷贝赋值
    vector<string> gpioValueStr = split(str,",");
    unsigned short *gpioBak = __ipGpioBak[ip];

    for(int i =0; i<5; i++)
    {
        gpioBak[i]|=atol(gpioValueStr[i].c_str());
    }

    __actionList[ip] = gpioBak;

    unsigned char txBuf[12] = {0};
    unsigned char checkValue = 0;

    txBuf[0]='W';

    for(int i =1,j=0; i<11; j++)
    {
        txBuf[i] = gpioBak[j]%256;
        checkValue^=txBuf[i];
        i++;
        txBuf[i] = gpioBak[j]/256;
        checkValue^=txBuf[i];
        i++;
    }

    txBuf[11] = checkValue;

#ifdef __DEBUG_PRINT
    cout<<sw<<"<"<<ip<<">"<<str<<endl;
    unsigned short tmpItems;
    for( int i=0; i<5; i++ )
    {
        tmpItems = *(unsigned short*)&txBuf[i*2+1];
        bitset<16> bs(tmpItems);
        cout<<hex<<tmpItems<<"-"<<bs<<" ";
        if(i%4==0)cout<<endl;
    }
    //cout<<endl<<endl;
    for(int i=0; i<12; i++)
    {
        cout<<hex<<static_cast<int>(txBuf[i])<<" ";
    }
    cout<<endl;
#endif

    bool funcResult = true;
    bool wrResult=false;
    int len = 12;
    unsigned char rxBuf[12] = {0};

    for(int i=0; i<3; i++)
    {
        wrResult = IOWrite(ip,(char*)txBuf,sizeof(txBuf));
        if(wrResult == false)
        {
            funcResult = false;
            break;
        }

        IORead(ip,(char*)rxBuf,&len);

        if(len == sizeof(txBuf))
        {
            for(int j=0; j<sizeof(txBuf); j++)
                if(rxBuf[j] != txBuf[j])
                    wrResult = false;
        }
        else
            wrResult = false;

        if(wrResult == true)
            break;
        else
            funcResult =false;

        //Delay(100);
    }

    return funcResult;
}
Exemplo n.º 19
0
void ledSet(int led, bool on)
{
    bool inverted = (1 << (led + ledOffset)) & ledPolarity;
    IOWrite(leds[led + ledOffset], on ? inverted : !inverted);
}
Exemplo n.º 20
0
//执行动作
bool implementsetting::Excute(void)
{
    if (!bLoadMap)
    {
        Message("SWITCH::Excute failed::load map failed!");
        return false;
    }

    bool funcResult = true;
    unsigned char txBuf[12] = { 0 }, rxBuf[12] = {0};
    unsigned char checkValue = 0;
    unsigned short *gpioBak = NULL;
    string ip;
    int replyCnt = 0; //尝试次数
    map<string, bool>hostIPEnableList;
    vector<string> actionQueue;

    txBuf[0]='W';

    //读入主机使能队列
    /*		for (map<string, stHostControl>::iterator itr = __hostCtrl.begin();
    			itr != __hostCtrl.end();
    			itr++)
    		{
    			hostIPEnableList[itr->second.ip] = itr->second.enable;
    		}*/

    for (map<string, string>::iterator itr = __ipmap.begin();
            itr != __ipmap.end();
            itr++)
    {
        hostIPEnableList[itr->second] = true;
    }

    for (map<string, unsigned short*>::iterator actionIter = __actionList.begin();
            actionIter != __actionList.end();
            actionIter++)
    {
        if (!hostIPEnableList[actionIter->first])continue;
        actionQueue.push_back(actionIter->first);
    }

    replyCnt = 0;

    while (true)
    {
        //下发开关指令队列
        for (map<string, unsigned short*>::iterator actionIter = __actionList.begin();
                actionIter != __actionList.end();
                actionIter++)
        {
            ip = actionIter->first;
            gpioBak = actionIter->second;

            if (!hostIPEnableList[ip])continue;

            checkValue = 0;
            for (int i = 1, j = 0; i < 11; j++)
            {
                txBuf[i] = gpioBak[j] % 256;
                checkValue ^= txBuf[i];
                i++;
                txBuf[i] = gpioBak[j] / 256;
                checkValue ^= txBuf[i];
                i++;
            }

            txBuf[11] = checkValue;

#ifdef __DEBUG_PRINT
            cout<<"<"<<ip<<">";
            for(int i=0; i<12; i++)
            {
                cout<<uppercase<<hex<<static_cast<int>(txBuf[i])<<" ";
            }
            cout<<endl;
#endif

            bool wrResult = false;
            int len = 12;

            for (int i = 0; i < 1; i++)
            {
                funcResult = wrResult = IOWrite(ip, (char*)txBuf, sizeof(txBuf));

                if (wrResult == false)continue;

                funcResult = wrResult = IORead(ip, (char*)rxBuf, &len);

                if (wrResult == false)continue;

                for (int j = 0; j < sizeof(txBuf); j++)
                {
                    if (rxBuf[j] != txBuf[j])
                    {
                        wrResult = false;
                        break;
                    }
                }

                funcResult = wrResult;
                if (wrResult == true)break;
            }

            if (!funcResult)break;
        }

        //break;
        if (replyCnt > 1 || funcResult)break;

        replyCnt++;

        //断开连接
        for (vector<string>::iterator itr = actionQueue.begin();
                itr != actionQueue.end();
                itr++)
        {
            IODisConnect(*itr);
        }

        //复位
        funcResult = IOResetWithList(actionQueue);

        //重连
        for (vector<string>::iterator itr = actionQueue.begin();
                itr != actionQueue.end();
                itr++)
        {
            IOConnectBegin(*itr);
        }

        bool wait = true;
        funcResult = true;
        vector<string> errHost;

        for (vector<string>::iterator itr = actionQueue.begin();
                itr != actionQueue.end();
                itr++)
        {
            if (!IOConnectEnd(*itr, wait ? 1000 : 100))
            {
                errHost.push_back(*itr);
                funcResult = false;
                break;
            }
            wait = false;
            //if (!funcResult)break;
            //LoadModuleState(*itr);
        }

        if (!funcResult)
        {
            string info("<MatrixSwitch>:[");

            for (vector<string>::iterator itr = errHost.begin();
                    itr != errHost.end();
                    itr++)
            {
                for (map<string,string>::iterator mtr = __ipmap.begin();
                        mtr != __ipmap.end();
                        mtr++)
                {
                    if (mtr->second == *itr)info.append(mtr->first + '@');
                }

                info.append(*itr+'/');
            }

            info.append("]:<Failed>");

            Message(info);

            break;
        }

        Delay(500);
    }

    return funcResult;
}