/**
 * @fn uint8_t SensorWirelessOperation(s_AppRadio * pRadio, unsigned int * pBuffer)
 *
 * @brief This function initiates a data exchange, qualifies any received data as 
 *        being from a network member, and if so copies data to Nodes[].InData[]
 *        and returns the node IDindex that it came from
 *
 * @param pRadio an s_AppRadio structure pointer
 * @param pBuffer an unsigned integer pointer
 *
 * @return an unsigned int, IDindex; >0 is valid, =0 is invalid/no data
 */
uint8_t SensorWirelessOperation(s_AppRadio * pRadio, unsigned int * pBuffer)
{
  uint8_t IDindex;
  uint8_t ByteCount = sizeof(PayloadFrame);
  //If there is a need to do additional stuff prior to send, do it here!
  
  if (DataExchange(pRadio, (uint8_t *)(SensorPayload(pBuffer)), &ByteCount)) {  // Prepare the sensor/actuator payload and initiate data exchange
    //We should perhaps check here if we got a full payload?
    IDindex = NetworkValidation(&Payloads[0]);                                  // Data from the radio is available, check if its from a member, if so copy the data and return the node index it came from.
    if (IDindex){
      //If there is a need, do something with the data here. Populate the user's buffer with the data
      
      if(Payloads[INCOMING_FRAME].Data[2] & 0x0004){                            // If there is new data(for PWM) from the remote module's GUI
        Nodes[0].Data[3] = Payloads[INCOMING_FRAME].Data[2] & 0xFFF0;           // Mask of the bit for new data, because it is not needed any more.
      }                                                                         // Else use old data
      pBuffer[3] = Nodes[0].Data[3];                                            

      if(Payloads[INCOMING_FRAME].Data[2] & 0x0002){                            // If there is new data(for green LED) from the remote module's GUI
        Nodes[0].Data[1] = Payloads[INCOMING_FRAME].Data[2] & 0x0001;           // Mask of the bit for new data, because it is not needed any more.
      }                                                                         // Else use old data
      pBuffer[1] = Nodes[0].Data[1];                                          
      Payloads[INCOMING_FRAME].Data[2] = 0x0000;                                // Clear the field as the same buffer is used for the incoming frame.
      
      if(Nodes[0].CurrentCycleTime != Payloads[0].CycleTime){
        SetCycleTime(pRadio, 0, Payloads[0].CycleTime);
      }
      return IDindex;                                                           // Allow main() to be notified of the newly arrived data, which is now in Nodes[].InData[]
    }
  }
  return 0;                                                                     // There is no data or it was not from a network member
}
Beispiel #2
0
// Initializations needed by options
void LoadOptions()
{
	LoadOpts(pageControls, SIZEOF(pageControls), MODULE_NAME);

	// This is created here to assert that this key always exists
	opts.refresh_status_message_timer = db_get_w(NULL, "MyDetails", "RefreshStatusMessageTimer", 12);
	db_set_w(NULL, "MyDetails", "RefreshStatusMessageTimer", opts.refresh_status_message_timer);

	SetCycleTime();
	RefreshFrameAndCalcRects();
}
Beispiel #3
0
BOOL CReceiver::Init( CWSASocket * pBindSocket, CPeerMap * pPeerMap, CSender * pSender, CReliableSender * pReliableSender, CLurkerTimer * pTimeStamp, CUDPServer * pServer, CUDPClient * pClient, DWORD dwCycleTimeMs )
{
	if( NULL == pBindSocket || NULL == pPeerMap || NULL == pTimeStamp )	return FALSE;
	if( NULL == pServer && NULL == pClient ) return FALSE;
	if( NULL != pServer && NULL != pClient ) return FALSE;

	m_pServer = pServer;
	m_pClient = pClient;
	m_pTimeStamp = pTimeStamp;

	if(m_pServer)
	{
		m_pSysBuffer = m_pServer->GetSysBuffer();
	}
	else if(m_pClient)
	{
		m_pSysBuffer = m_pClient->GetSysBuffer();
	}

	SetCycleTime(dwCycleTimeMs);

	m_pRecvBuffer = new CListBuffer();

	m_pPeerMap = pPeerMap;

	m_pSocket = pBindSocket;
	m_bEndThread = FALSE;

	m_pSender = pSender;
	m_pReliableSender = pReliableSender;

//	m_UDPPacketCoder.InitializeInstance();
//	m_UDPPacketCoder.SetDecrypt();
	m_usLatestDPMPacketID = 0;

	m_hSocketEvent = ::WSACreateEvent();
	::WSAResetEvent(m_hSocketEvent);
	::WSAEventSelect(m_pSocket->GetHandle(), m_hSocketEvent, FD_READ | FD_CLOSE);

	DWORD dwOutThreadID = 0;

	m_iPreProcessPacket = 0;
	if( TRUE == CreateThread( NULL, 0, 0, &dwOutThreadID) )
	{
		return TRUE;
	}

	return FALSE;
}
Beispiel #4
0
TMasterLogic::TMasterLogic()
{
  SetCycleTime(100);

  mMasterForm = NULL;
  // значения по-умолчанию для параметров командной строки
  std::string sLocalHost;
  TResolverSelf_IP_v4 resolver;
  resolver.Get(sLocalHost, 0);

  TInputCmdDevTool::TInput input;
  input.ip_dst   = boost::asio::ip::address_v4::from_string(sLocalHost).to_ulong();
  input.port_self = MASTER_PORT;
  input.port_dst  = SUPER_SERVER_PORT;

  mInputCmd.SetDefParam(input);
}