Пример #1
0
void HeartbeatArrival(uint16_t sourceId, const std::uint8_t *data, std::uint8_t len)
{
	if (len<5)
		return;
	CANExtended::DeviceState state = static_cast<CANExtended::DeviceState>(data[0]);
	if (state != CANExtended::Operational)
		return;
	auto unit = unitManager->FindUnit(sourceId&0x7f);
	bool updated = (unit!=nullptr) && (unit->UpdateStatus()==StorageUnit::Updated);
	
	if (unit == nullptr || updated)
	{
		StorageBasic basic(CanEx);
		basic.DeviceId = sourceId;
		basic.SensorNum = data[2];
		basic.Version = (data[3]<<8)|data[4];
		switch (data[1])
		{
			case UNIT_TYPE_INDEPENDENT:
				unit.reset(new IndependentUnit(basic));
				break;
			case UNIT_TYPE_UNITY:
				unit.reset(new UnityUnit(basic));
				break;
			case UNIT_TYPE_UNITY_RFID:
				unit.reset(new RfidUnit(basic));
				break;
			default:
				CanEx->Sync(sourceId, DeviceSync::SyncLive,  CANExtended::Trigger);
				return;
		}
		unit->ReadCommandResponse.bind(ethEngine.get(), &NetworkEngine::DeviceReadResponse);
		unit->WriteCommandResponse.bind(ethEngine.get(), &NetworkEngine::DeviceWriteResponse);
		CanEx->RegisterDevice(unit);
		if (updated)
		{	
			unitManager->Recover(sourceId&0x7f, unit);
#ifdef DEBUG_PRINT
			cout<<"#Recovered Device 0x"<<std::hex<<sourceId<<std::dec<<endl;
#endif
		}
		else
		{
			unitManager->Add(sourceId&0x7f, unit);
#ifdef DEBUG_PRINT
			cout<<"#Added Device 0x"<<std::hex<<sourceId<<std::dec<<endl;
#endif
		}
	}
	//CanEx->Sync(sourceId, DeviceSync::SyncLive, CANExtended::AutoSync); //Confirm & Start AutoSync
	CanEx->Sync(sourceId, DeviceSync::SyncLive, CANExtended::Trigger);
	if (updated)
		unitManager->SyncUpdate();
}
void InputEventsWestonTest::WaitForSynchronize()
{
  synchronized = false;
  syncCallback.reset(new xw::Callback(clientLibrary,
                                      display->Sync(),
                                      boost::bind(&InputEventsWestonTest::Synchronize,
                                                  this)));
  
  while (!synchronized)
    loop->Dispatch();
}