Exemple #1
0
bool CNetMgr::GetPacket(uint8 nTravelDir, CPacket_Read *pPacket, CBaseConn **pSender)
{
	// Check the drivers.
	for (uint32 i=0; i < m_Drivers; i++)
	{
		CBaseDriver *pDriver = m_Drivers[i];

		CPacket_Read cCurPacket;
		CBaseConn *pCurSender;

		while (pDriver->GetPacket(&cCurPacket, &pCurSender))
		{
			IncRecvCounter(pCurSender, cCurPacket.Size());

			ParseMsg(cCurPacket, g_CV_ParseNet_Incoming | g_CV_ParseNet, nTravelDir, pCurSender);

			if (HandleReceivedPacket(cCurPacket, pCurSender, true))
			{
				*pPacket = cCurPacket;
				*pSender = pCurSender;
				return true;
			}
		}
	}

	return false;
}
void
NetLobbyClient::DoServerMods(NetPeer* peer, Text msg)
{
    mods_req_time = NetLayer::GetUTC() + 3600;

    List<NetLobbyParam> params;
    ParseMsg(msg, params);
    server_mods.destroy();

    Text  name;
    Text  version;
    Text  url;

    for (int i = 0; i < params.size(); i++) {
        NetLobbyParam* p = params[i];

        if (p->name == "mod") {
            name = p->value;
        }

        else if (p->name == "url") {
            url = p->value;
        }

        else if (p->name == "ver") {
            version = p->value;

            ModInfo* info = new(__FILE__,__LINE__) ModInfo(name, version, url);
            server_mods.append(info);
        }
    }

    params.destroy();
}
Exemple #3
0
void CHtvDesign::SynHtDistQueRams(CHtvIdent *pHier)
{
    string inputFileName = g_htvArgs.GetInputFileName();

    CHtvIdentTblIter identIter(pHier->GetFlatIdentTbl());
    for (identIter.Begin(); !identIter.End(); identIter++) {
        if (!identIter->IsVariable() || !identIter->IsHtDistQue())
            continue;

        CHtvIdent *pQueueRam = identIter();
        m_bIsHtQueueRamsPresent = true;

        // Block Ram
        int addrWidth = pQueueRam->GetType()->GetHtMemoryAddrWidth1();
        addrWidth += pQueueRam->GetType()->GetHtMemoryAddrWidth2();

        string cQueName = pQueueRam->GetName();
        if (cQueName.substr(0,2) == "r_" || cQueName.substr(0,2) == "m_")
            cQueName.replace(0, 2, "c_");
        else
            cQueName.insert(0, "c_");

        string rQueName = pQueueRam->GetName();
        if (rQueName.substr(0,2) == "m_")
            rQueName.replace(0, 2, "r_");

        vector<int> refList(pQueueRam->GetDimenCnt(), 0);

        char buf[128];
        do {
            string refDimStr;
            string modDimStr;

            for (size_t i = 0; i < refList.size(); i += 1) {
                sprintf(buf, "$%d", refList[i]);
                refDimStr += buf;

                sprintf(buf, "$%d", refList[i]);
                modDimStr += buf;
            }

            m_vFile.Print("\n%s_HtQueueRam #( .DATA_WIDTH(%d), .ADDR_WIDTH(%d) ) %s%s ( ",
                          inputFileName.c_str(), pQueueRam->GetWidth(), addrWidth, pQueueRam->GetName().c_str(), modDimStr.c_str());

            bool bMultiple;
            CHtvIdent * pMethod = FindUniqueAccessMethod(&pQueueRam->GetHierIdent()->GetWriterList(), bMultiple);

            if (bMultiple)
                ParseMsg(PARSE_FATAL, pQueueRam->GetLineInfo(), "ht_queue push by muliple methods");

            m_vFile.Print(".clk( %s ), ", pMethod->GetClockIdent()->GetName().c_str());
            m_vFile.Print(".we( %s_WrEn%s ), ", cQueName.c_str(), refDimStr.c_str());
            m_vFile.Print(".wa( %s_WrAddr%s[%d:0] ), ", rQueName.c_str(), refDimStr.c_str(), addrWidth-1);
            m_vFile.Print(".din( %s_WrData%s ), ", cQueName.c_str(), refDimStr.c_str());
            m_vFile.Print(".ra( %s_RdAddr%s[%d:0] ), ", rQueName.c_str(), refDimStr.c_str(), addrWidth-1);
            m_vFile.Print(".dout( %s_RdData%s ) );\n", cQueName.c_str(), refDimStr.c_str());

        } while (!pQueueRam->DimenIter(refList));
    }
}
void
NetLobbyClient::DoAuthUser(NetPeer* peer, Text msg)
{
    List<NetLobbyParam> params;
    ParseMsg(msg, params);

    int  level = NetAuth::NET_AUTH_STANDARD;
    Text salt;

    for (int i = 0; i < params.size(); i++) {
        NetLobbyParam* p = params[i];

        int num = 0;
        sscanf_s(p->value, "%d", &num);

        if (p->name == "level") {
            level = num;
        }

        else if (p->name == "salt") {
            salt = p->value;
        }
    }

    Text response = NetAuth::CreateAuthResponse(level, salt);
    if (response.length() > 0)
    SendData(NET_LOBBY_USER_AUTH, response);
}
Exemple #5
0
bool CNetMgr::SendPacket(const CPacket_Read &cPacket, CBaseConn *idSendTo, uint32 packetFlags)
{
	if(!idSendTo)
		return false;

	ParseMsg(cPacket, g_CV_ParseNet_Outgoing | g_CV_ParseNet, NETMGR_TRAVELDIR_UNKNOWN, idSendTo);

	return LagOrSend(CPacket_Read(cPacket), idSendTo, packetFlags);
}
Exemple #6
0
void CDsnInfo::InitAndValidateModOhm()
{
	// Internal ram checks
	for (size_t modIdx = 0; modIdx < m_modList.size(); modIdx += 1) {
		CModule &mod = *m_modList[modIdx];

		if (!mod.m_bIsUsed || !mod.m_ohm.m_bOutHostMsg) continue;

		if (mod.m_modInstList.size() > 1)
			ParseMsg(Error, mod.m_ohm.m_lineInfo, "Outbound host message from replicated/multi-instance module not currently supported");
	}
}
Exemple #7
0
void CDsnInfo::InitAndValidateModOhm()
{
	// Internal ram checks
	for (size_t modIdx = 0; modIdx < m_modList.size(); modIdx += 1) {
		CModule * pMod = m_modList[modIdx];

		if (!pMod->m_bIsUsed || !pMod->m_ohm.m_bOutHostMsg) continue;

		if (pMod->m_instSet.GetTotalCnt() > 1)
			ParseMsg(Error, pMod->m_ohm.m_lineInfo, "Outbound host message from replicated/multi-instance module not supported");
	}
}
void
NetLobbyClient::DoMissionList(NetPeer* peer, Text msg)
{
    List<NetLobbyParam> params;
    ParseMsg(msg, params);

    if (params.size() > 2) {
        campaigns.destroy();

        NetCampaignInfo*  c = 0;
        MissionInfo*      m = 0;

        for (int i = 0; i < params.size(); i++) {
            NetLobbyParam* p = params[i];

            if (p->name == "c_id") {
                c = new(__FILE__,__LINE__) NetCampaignInfo;
                sscanf_s(p->value, "0x%x", &c->id);
                campaigns.append(c);

                m = 0;
            }

            else if (c && p->name == "c_name") {
                c->name = p->value;
            }

            else if (p->name == "m_id") {
                int id = 0;
                sscanf_s(p->value, "0x%x", &id);

                int m_id = id &  NET_MISSION_MASK;
                int c_id = id >> NET_CAMPAIGN_SHIFT;

                for (int i = 0; i < campaigns.size(); i++) {
                    NetCampaignInfo* c = campaigns[i];
                    if (c->id == c_id) {
                        m = new(__FILE__,__LINE__) MissionInfo;
                        m->id = m_id;
                        c->missions.append(m);
                        missions.append(m);  // for later garbage collection
                        break;
                    }
                }
            }

            else if (m && p->name == "m_name") {
Exemple #9
0
/**
**  ParseBuffer: Handler client/server interaction.
**
**  @param session  Current session.
*/
static void ParseBuffer(Session *session)
{
	char *buf;

	if (!session || session->Buffer[0] == '\0') {
		return;
	}

	buf = session->Buffer;

	if (!session->UserData.LoggedIn) {
		if (!strncmp(buf, "USER ", 5)) {
			ParseUser(session, buf + 5);
		} else if (!strncmp(buf, "REGISTER ", 9)) {
			ParseRegister(session, buf + 9);
		} else {
			fprintf(stderr, "Unknown command: %s\n", session->Buffer);
			Send(session, "ERR_BADCOMMAND\n");
		}
	} else {
		if (!strncmp(buf, "USER ", 5) || !strncmp(buf, "REGISTER ", 9)) {
			Send(session, "ERR_ALREADYLOGGEDIN\n");
		} else if (!strncmp(buf, "CREATEGAME ", 11)) {
			ParseCreateGame(session, buf + 11);
		} else if (!strcmp(buf, "CANCELGAME") || !strncmp(buf, "CANCELGAME ", 11)) {
			ParseCancelGame(session, buf + 10);
		} else if (!strcmp(buf, "STARTGAME") || !strncmp(buf, "STARTGAME ", 10)) {
			ParseStartGame(session, buf + 9);
		} else if (!strcmp(buf, "LISTGAMES") || !strncmp(buf, "LISTGAMES ", 10)) {
			ParseListGames(session, buf + 9);
		} else if (!strncmp(buf, "JOINGAME ", 9)) {
			ParseJoinGame(session, buf + 9);
		} else if (!strcmp(buf, "PARTGAME") || !strncmp(buf, "PARTGAME ", 9)) {
			ParsePartGame(session, buf + 8);
		} else if (!strncmp(buf, "ENDGAME ", 8)) {
			ParseEndGame(session, buf + 8);
		} else if (!strncmp(buf, "MSG ", 4)) {
			ParseMsg(session, buf + 4);
		} else {
			fprintf(stderr, "Unknown command: %s\n", session->Buffer);
			Send(session, "ERR_BADCOMMAND\n");
		}
	}
}
Exemple #10
0
int OneStepFromFile(FILE *file, char *msg)
{
  MsgData data;
  
  if (!file)
    return (0);
  
  *msg = '\0';

  do {
    if (ReadNlFromFile(file, msg) == EOF) {
      SetNextStep();
      return (0);
    }
    data = ParseMsg(msg);
  } while (data->type == TYPE_NULL);

  return(1);
}
void
NetLobbyClient::DoServerInfo(NetPeer* peer, Text msg)
{
    List<NetLobbyParam> params;
    ParseMsg(msg, params);

    for (int i = 0; i < params.size(); i++) {
        NetLobbyParam* p = params[i];

        int num = 0;
        sscanf_s(p->value, "%d", &num);

        if (p->name == "info") {
            server_info.machine_info = p->value;
        }

        else if (p->name == "version") {
            server_info.version = p->value;
        }

        else if (p->name == "mode") {
            server_info.status = num;
        }

        else if (p->name == "users") {
            server_info.nplayers = num;
        }

        else if (p->name == "host") {
            server_info.hosted = (p->value == "true");
        }

        else if (p->name == "port") {
            server_info.gameport = (WORD) num;
        }
    }

    params.destroy();
}
Exemple #12
0
CMifWr * CDsnInfo::AddWriteMem(CModule * pModule, string queueW, string rspGrpId, string rspGrpW, string rspCntW,
	bool maxBw, bool bPause, bool bPoll, bool bReqPause, bool bMultiWr)
{
	CMif & mif = pModule->m_mif;

	// check if mif write interface was already added for 'mifId'
	if (mif.m_bMifWr) {
		ParseMsg(Error, "AddWriteMem already specified for module");
		return &mif.m_mifWr;
	}

	mif.m_bMif = true;
	mif.m_bMifWr = true;

	mif.m_mifWr.m_queueW = queueW;
	mif.m_mifWr.m_rspGrpId = rspGrpId;
	mif.m_mifWr.m_rspGrpW = rspGrpW;
	mif.m_mifWr.m_rspCntW = rspCntW;
	mif.m_mifWr.m_bMaxBw = maxBw;
	mif.m_mifWr.m_bPause = bPause;
	mif.m_mifWr.m_bPoll = bPoll;
	mif.m_mifWr.m_bReqPause = bReqPause;
	mif.m_mifWr.m_bMultiQwWrReq = bMultiWr;

	mif.m_mifWr.m_lineInfo = CPreProcess::m_lineInfo;

	if (pModule->m_memPortList.size() < 1) {
		pModule->m_memPortList.resize(1);
		pModule->m_memPortList[0] = new CModMemPort;
	}

	CModMemPort & modMemPort = *pModule->m_memPortList[0];

	modMemPort.m_bIsMem = true;
	modMemPort.m_bWrite = true;

	return &mif.m_mifWr;
}
void
NetLobbyClient::DoChat(NetPeer* peer, Text msg)
{
    List<NetLobbyParam> params;
    ParseMsg(msg, params);

    int  id = 0;
    Text user_name;
    Text chat_msg;

    for (int i = 0; i < params.size(); i++) {
        NetLobbyParam* p = params[i];

        int num = 0;
        sscanf_s(p->value, "%d", &num);

        if (p->name == "id")
        id = num;

        else if (p->name == "user")
        user_name = p->value;

        else if (p->name == "msg")
        chat_msg = p->value;
    }

    params.destroy();

    // receive chat from server:
    if (id && chat_msg.length()) {
        NetChatEntry* entry = new(__FILE__,__LINE__) NetChatEntry(id, user_name, chat_msg);

        if (!chat_log.contains(entry))
        chat_log.insertSort(entry);
        else
        delete entry; // received duplicate
    }
}
Exemple #14
0
static void *NeovimServer(void *arg)
{
    unsigned short bindportn = 10100;
    ssize_t nread;
    int bsize = 5012;
    char buf[bsize];
    int result;

    struct addrinfo hints;
    struct addrinfo *rp;
    struct addrinfo *res;
    struct sockaddr_storage peer_addr;
    int Sfd = -1;
    char bindport[16];
    socklen_t peer_addr_len = sizeof(struct sockaddr_storage);

    // block SIGINT
    {
        sigset_t set;
        sigemptyset(&set);
        sigaddset(&set, SIGINT);
        sigprocmask(SIG_BLOCK, &set, NULL);
    }

    memset(&hints, 0, sizeof(struct addrinfo));
    hints.ai_family = AF_INET;    /* Allow IPv4 or IPv6 */
    hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
    hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
    hints.ai_protocol = 0;          /* Any protocol */
    hints.ai_canonname = NULL;
    hints.ai_addr = NULL;
    hints.ai_next = NULL;
    rp = NULL;
    result = 1;
    while(rp == NULL && bindportn < 10149){
        bindportn++;
        sprintf(bindport, "%d", bindportn);
        if(getenv("R_IP_ADDRESS"))
            result = getaddrinfo(NULL, bindport, &hints, &res);
        else
            result = getaddrinfo("127.0.0.1", bindport, &hints, &res);
        if(result != 0){
            fprintf(stderr, "Error at getaddrinfo (%s)\n", gai_strerror(result));
            fflush(stderr);
            return NULL;
        }

        for (rp = res; rp != NULL; rp = rp->ai_next) {
            Sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
            if (Sfd == -1)
                continue;
            if (bind(Sfd, rp->ai_addr, rp->ai_addrlen) == 0)
                break;       /* Success */
            close(Sfd);
        }
        freeaddrinfo(res);   /* No longer needed */
    }

    if (rp == NULL) {        /* No address succeeded */
        fprintf(stderr, "Could not bind\n");
        fflush(stderr);
        return NULL;
    }

    RegisterPort(bindportn);

    snprintf(myport, 127, "%d", bindportn);
    char endmsg[128];
    snprintf(endmsg, 127, "%scall >>> STOP Now <<< !!!", getenv("NVIMR_SECRET"));

    /* Read datagrams and reply to sender */
    for (;;) {
        memset(buf, 0, bsize);

        nread = recvfrom(Sfd, buf, bsize, 0,
                (struct sockaddr *) &peer_addr, &peer_addr_len);
        if (nread == -1){
            fprintf(stderr, "recvfrom failed [port %d]\n", bindportn);
            fflush(stderr);
            continue;     /* Ignore failed request */
        }
        if(strncmp(endmsg, buf, 28) == 0)
            break;

        ParseMsg(buf);
    }
    if(df){
        fclose(df);
        df = NULL;
    }
    return NULL;
}
Exemple #15
0
static void NeovimServer(void *arg)
{
    unsigned short bindportn = 10100;
    ssize_t nread;
    int bsize = 5012;
    char buf[bsize];
    int result;

    WSADATA wsaData;
    SOCKADDR_IN RecvAddr;
    SOCKADDR_IN peer_addr;
    SOCKET Sfd;
    int peer_addr_len = sizeof (peer_addr);
    int nattp = 0;
    int nfail = 0;

    result = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (result != NO_ERROR) {
        fprintf(stderr, "WSAStartup failed with error %d.\n", result);
        fflush(stderr);
        return;
    }

    while(bindportn < 10149){
        bindportn++;
        Sfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if (Sfd == INVALID_SOCKET) {
            fprintf(stderr, "socket failed with error %d\n", WSAGetLastError());
            fflush(stderr);
            return;
        }

        RecvAddr.sin_family = AF_INET;
        RecvAddr.sin_port = htons(bindportn);
        RecvAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

        nattp++;
        if(bind(Sfd, (SOCKADDR *) & RecvAddr, sizeof (RecvAddr)) == 0)
            break;
        nfail++;
    }
    if(nattp == nfail){
        fprintf(stderr, "Could not bind\n");
        fflush(stderr);
        return;
    }

    RegisterPort(bindportn);

    /* Read datagrams and reply to sender */
    for (;;) {
        memset(buf, 0, bsize);

        nread = recvfrom(Sfd, buf, bsize, 0,
                (SOCKADDR *) &peer_addr, &peer_addr_len);
        if (nread == SOCKET_ERROR) {
            fprintf(stderr, "recvfrom failed with error %d [port %d]\n",
                    bindportn, WSAGetLastError());
            fflush(stderr);
            return;
        }
        if(strstr(buf, "QUIT_NVINSERVER_NOW"))
            break;

        ParseMsg(buf);
    }
    if(df){
        fprintf(df, "Neovim server: Finished receiving. Closing socket.\n");
        fflush(df);
    }
    result = closesocket(Sfd);
    if (result == SOCKET_ERROR) {
        fprintf(stderr, "closesocket failed with error %d\n", WSAGetLastError());
        fflush(stderr);
        return;
    }
    WSACleanup();
    if(df){
        fclose(df);
        df = NULL;
    }
    return;
}
Exemple #16
0
int CV_OneStepFromFile(FILE *file, char *msg, MsgData *msgData, 
		      Tcl_Interp *interp)
{
  int count = 0;
  int invalid_line;

  *msg = '\0';
  
  /* we loop until a valid message has been read from the log file. if the end
     of the file is reached then the function returns 0. */

  do {

//	if (ReadNlFromFile(file, msg) == EOF) 
//		return (0);
// @@@ O codigo abaixo ee para tratar linhas invalidas e substitui o codigo acima
	do
	{
		if (ReadNlFromFile(file, msg) == EOF) 
			return (0);

		invalid_line = 0;

		if (strstr(msg, "Logging Task Control Server"))	// Ignore this sentence
			invalid_line = 1;

		if (strstr(msg, "Expecting 1 on port 1381"))	// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "close Module"))		// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "x_ipcClose"))			// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "Clearing handler for message"))// Ignore this sentence
			invalid_line = 1;
			
		if (strstr(msg, "Central Abort"))		// Ignore this sentence
			invalid_line = 1;

	} while (invalid_line);
    
    *msgData = ParseMsg(msg);
    //printf("linha = %s\n", msg); // @@@ Alberto: esta lina ee util para debug

    if (COMVIEW_DEBUG) {
      fprintf(stderr, "ReadNl Got : %s\n", msg);
      fprintf(stderr, "Message type is %d\n", (*msgData)->type);
    }

    /* This next segment of code deals with the Log Window. There are a
       number of options that complicate the code; the user can select
       any of the following modes:

        1) Display all lines from log file
        2) Display only lines from the log file which are relevant 
	   to messages being sent between modules (this ignores the data
	   associated with a message, among other things).
        3) Either of the above with the ability to filter out lines
	   that have activity with an ignored module. */

    if ((count) && (listbox_msgt>=0)) { 

      /* if this is the second iteration through the while loop then
	 control never returned to Tcl, therefore the listbox variables
	 were not updated so it is done here. */
      actual_listbox_update(interp);
    }

    if (regexp) { check_regexp(msg, interp); }

    if ((display_all) || (logged_message_type((*msgData)->type))) {

      /* this does not actually update the listbox widget in Tk, it merely
	 updates some global variables that the graphical update function
	 accesses. This allows the Tcl code to look at the line and determine
	 whether or not to allow the line to be displayed. This feature is
	 used in order to ignore particular messages. */
      update_listbox_vars(msg, (*msgData)->type);

    } else {
      /* no show */
      listbox_msgt=-1;
    }

    count=1;
  } while (not_processed_msg((*msgData)->type));

  return (1);
}
Exemple #17
0
void CHtvDesign::SynHtAsymBlockRams(CHtvIdent *pHier)
{
    string inputFileName = g_htvArgs.GetInputFileName();

    CHtvIdentTblIter identIter(pHier->GetFlatIdentTbl());
    for (identIter.Begin(); !identIter.End(); identIter++) {
        if (!identIter->IsVariable() || (!identIter->IsHtQueue() && !identIter->IsHtMemory()))
            continue;

        if (!identIter->IsHtMrdBlockRam() && !identIter->IsHtMwrBlockRam())
            continue;

        CHtvIdent *pBlockRam = identIter();

        // Block Ram
        int addrWidth = pBlockRam->GetType()->GetHtMemoryAddrWidth1();
        addrWidth += pBlockRam->GetType()->GetHtMemoryAddrWidth2();

        int selWidth = pBlockRam->GetType()->GetHtMemorySelWidth();

        int dataWidth = pBlockRam->GetType()->GetType()->GetWidth();

        string cQueName = pBlockRam->GetName();
        if (cQueName.substr(0,2) == "r_" || cQueName.substr(0,2) == "m_")
            cQueName.replace(0, 2, "c_");
        else
            cQueName.insert(0, "c_");

        vector<int> refList(pBlockRam->GetDimenCnt(), 0);

        char buf[128];
        do {
            string refDimStr;
            string modDimStr;

            for (size_t i = 0; i < refList.size(); i += 1) {
                sprintf(buf, "$%d", refList[i]);
                refDimStr += buf;

                sprintf(buf, "$%d", refList[i]);
                modDimStr += buf;
            }

            bool bMultiple;
            CHtvIdent * pWriteMethod = FindUniqueAccessMethod(&pBlockRam->GetHierIdent()->GetWriterList(), bMultiple);

            if (bMultiple)
                ParseMsg(PARSE_FATAL, pBlockRam->GetLineInfo(), "ht_asym_block_ram write by muliple methods");

            CHtvIdent * pReadMethod = FindUniqueAccessMethod(&pBlockRam->GetHierIdent()->GetReaderList(), bMultiple);

            if (bMultiple)
                ParseMsg(PARSE_FATAL, pBlockRam->GetLineInfo(), "ht_asym_block_ram read by muliple methods");

            if (pReadMethod->GetClockIdent()->GetName() == pWriteMethod->GetClockIdent()->GetName()) {

                if (pBlockRam->GetType()->IsHtBlockRamDoReg()) {
                    if (identIter->IsHtMrdBlockRam()) {
                        m_bIs1CkDoRegHtMrdBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtBlockMrdRam1CkDoReg #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                    if (identIter->IsHtMwrBlockRam()) {
                        m_bIs1CkDoRegHtMwrBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtBlockMwrRam1CkDoReg #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                } else {
                    if (identIter->IsHtMrdBlockRam()) {
                        m_bIs1CkHtMrdBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtMrdBlockRam1Ck #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                    if (identIter->IsHtMwrBlockRam()) {
                        m_bIs1CkHtMwrBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtMwrBlockRam1Ck #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                }

                m_vFile.Print(".ck( %s ), ", pWriteMethod->GetClockIdent()->GetName().c_str());
            } else {
                if (pBlockRam->GetType()->IsHtBlockRamDoReg()) {
                    if (identIter->IsHtMrdBlockRam()) {
                        m_bIs2CkDoRegHtMrdBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtMrdBlockRam2CkDoReg #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                    if (identIter->IsHtMwrBlockRam()) {
                        m_bIs2CkDoRegHtMwrBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtMwrBlockRam2CkDoReg #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                } else {
                    if (identIter->IsHtMrdBlockRam()) {
                        m_bIs2CkHtMrdBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtMrdBlockRam2Ck #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                    if (identIter->IsHtMwrBlockRam()) {
                        m_bIs2CkHtMwrBlockRamsPresent = true;
                        m_vFile.Print("\n%s_HtMwrBlockRam2Ck #( .DATA_W(%d), .ADDR_W(%d), .SEL_W(%d) ) %s%s ( ",
                                      inputFileName.c_str(), dataWidth, addrWidth, selWidth, pBlockRam->GetName().c_str(), modDimStr.c_str());
                    }
                }
                m_vFile.Print(".rck( %s ), ", pReadMethod->GetClockIdent()->GetName().c_str());
                m_vFile.Print(".wck( %s ), ", pWriteMethod->GetClockIdent()->GetName().c_str());
            }

            m_vFile.Print(".we( %s_WrEn%s ), ", cQueName.c_str(), refDimStr.c_str());
            if (identIter->IsHtMrdBlockRam())
                m_vFile.Print(".ws( %s_WrSel%s ), ", cQueName.c_str(), refDimStr.c_str());
            m_vFile.Print(".wa( %s_WrAddr%s ), ", cQueName.c_str(), refDimStr.c_str());
            m_vFile.Print(".wd( %s_WrData%s ), ", cQueName.c_str(), refDimStr.c_str());
            if (identIter->IsHtMwrBlockRam())
                m_vFile.Print(".rs( %s_RdSel%s ), ", cQueName.c_str(), refDimStr.c_str());
            m_vFile.Print(".ra( %s_RdAddr%s ), ", cQueName.c_str(), refDimStr.c_str());
            m_vFile.Print(".rd( %s_RdData%s ) );\n", cQueName.c_str(), refDimStr.c_str());

        } while (!pBlockRam->DimenIter(refList));
    }
}
Exemple #18
0
void CHtvDesign::SynHtDistRams(CHtvIdent *pHier)
{
    string inputFileName = g_htvArgs.GetInputFileName();

    CHtvIdentTblIter identIter(pHier->GetFlatIdentTbl());
    for (identIter.Begin(); !identIter.End(); identIter++) {
        if (!identIter->IsVariable() || !identIter->IsHtMemory())
            continue;

        if (identIter->IsHtBlockRam() || identIter->IsHtMrdBlockRam() || identIter->IsHtMwrBlockRam() || identIter->IsHtQueue())
            continue;

        CHtvIdent *pDistRam = identIter();
        m_bIsHtDistRamsPresent = true;

        int addrWidth = pDistRam->GetType()->GetHtMemoryAddrWidth1();
        addrWidth += pDistRam->GetType()->GetHtMemoryAddrWidth2();

        vector<CHtDistRamWeWidth> *pWeWidth = pDistRam->GetHtDistRamWeWidth();

        for (size_t j = 0; j < pWeWidth->size(); j += 1) {
            int highBit = (*pWeWidth)[j].m_highBit;
            int lowBit = (*pWeWidth)[j].m_lowBit;

            size_t i;
            for (i = 0; i < m_htDistRamTypes.size(); i += 1) {
                if (m_htDistRamTypes[i].m_addrWidth == addrWidth &&
                        m_htDistRamTypes[i].m_dataWidth == highBit-lowBit+1)
                    break;
            }

            if (i == m_htDistRamTypes.size())
                m_htDistRamTypes.push_back(CHtDistRamType(addrWidth, highBit-lowBit+1));
        }

        string cQueName = pDistRam->GetName();
        if (cQueName.substr(0,2) == "r_" || cQueName.substr(0,2) == "m_")
            cQueName.replace(0, 2, "c_");
        else
            cQueName.insert(0, "c_");

        bool bMultiple;
        CHtvIdent * pMethod = FindUniqueAccessMethod(&pDistRam->GetHierIdent()->GetWriterList(), bMultiple);

        if (bMultiple)
            ParseMsg(PARSE_FATAL, pDistRam->GetLineInfo(), "ht_queue push by muliple methods");

        CHtvIdent *pClockIdent = pMethod->GetClockIdent();

        vector<int> refList(pDistRam->GetDimenCnt(), 0);

        char buf[128];
        do {
            string refDimStr;
            string modDimStr;

            for (size_t i = 0; i < refList.size(); i += 1) {
                sprintf(buf, "$%d", refList[i]);
                refDimStr += buf;

                sprintf(buf, "$%d", refList[i]);
                modDimStr += buf;
            }

            if (pWeWidth->size() == 1) {
                m_vFile.Print("\n%s_HtDistRam #( .DATA_WIDTH(%d), .ADDR_WIDTH(%d) ) %s%s ( ",
                              inputFileName.c_str(), pDistRam->GetWidth(), addrWidth, pDistRam->GetName().c_str(), modDimStr.c_str());

                m_vFile.Print(".clk( %s ), ", pClockIdent->GetName().c_str());
                m_vFile.Print(".we( %s_WrEn%s ), ", cQueName.c_str(), refDimStr.c_str());
                m_vFile.Print(".wa( %s_WrAddr%s ), ", cQueName.c_str(), refDimStr.c_str());
                m_vFile.Print(".din( %s_WrData%s ), ", cQueName.c_str(), refDimStr.c_str());
                m_vFile.Print(".ra( %s_RdAddr%s ), ", cQueName.c_str(), refDimStr.c_str());
                m_vFile.Print(".dout( %s_RdData%s ) );\n", cQueName.c_str(), refDimStr.c_str());

            } else {
                for (size_t j = 0; j < pWeWidth->size(); j += 1) {
                    int highBit = (*pWeWidth)[j].m_highBit;
                    int lowBit = (*pWeWidth)[j].m_lowBit;

                    m_vFile.Print("\n%s_HtDistRam #( .DATA_WIDTH(%d), .ADDR_WIDTH(%d) ) %s%s_%d_%d ( ",
                                  inputFileName.c_str(), highBit-lowBit+1, addrWidth,
                                  pDistRam->GetName().c_str(), modDimStr.c_str(), highBit, lowBit);

                    m_vFile.Print(".clk( %s ), ", pClockIdent->GetName().c_str());
                    m_vFile.Print(".we( %s_WrEn_%d_%d%s ), ", cQueName.c_str(), highBit, lowBit, refDimStr.c_str());
                    m_vFile.Print(".wa( %s_WrAddr%s ), ", cQueName.c_str(), refDimStr.c_str());
                    m_vFile.Print(".din( %s_WrData%s[%d:%d] ), ", cQueName.c_str(), refDimStr.c_str(), highBit, lowBit);
                    m_vFile.Print(".ra( %s_RdAddr%s ), ", cQueName.c_str(), refDimStr.c_str());
                    m_vFile.Print(".dout( %s_RdData%s[%d:%d] ) );\n", cQueName.c_str(), refDimStr.c_str(), highBit, lowBit);
                }
            }

        } while (!pDistRam->DimenIter(refList));
    }
}
Exemple #19
0
void CHtvDesign::SynHtDistRamWe(CHtvIdent *pHier, CHtvObject * pObj, CHtvObject * pRtnObj, CHtvOperand *pExpr, bool bIsAlwaysAt)
{
	// Synthesize a write enable assignment statement
	//   syntax is: variable = value
	//   write variable as single bit wide value per dist ram section

	if (!bIsAlwaysAt)
		m_vFile.Print("assign ");

	vector<CHtfeOperand *> &weIndexList = pExpr->GetOperand1()->GetIndexList();

	CHtvIdent *pWeIdent = pExpr->GetOperand1()->GetMember();
	vector<CHtDistRamWeWidth> *pWeWidth = pWeIdent->GetHtDistRamWeWidth();

	CHtvOperand *pOp2 = pExpr->GetOperand2();
	Assert(pOp2->IsConstValue());

	if ( (*pWeWidth).size() == 1) {

		bool bFoundSubExpr;
		bool bWriteIndex;
		FindSubExpr(pObj, pRtnObj, pExpr, bFoundSubExpr, bWriteIndex);

		if (!bWriteIndex) {
			PrintSubExpr(pObj, pRtnObj, pExpr);
			m_vFile.Print(";\n");
		}

		if (bFoundSubExpr) {
			m_vFile.DecIndentLevel();
			m_vFile.Print("end\n");
		}

	} else {

		int exprHighBit, exprLowBit;
		pExpr->GetOperand1()->GetDistRamWeWidth(exprHighBit, exprLowBit);

		for (size_t i = 0; i < (*pWeWidth).size(); i += 1) {
			int highBit = (*pWeWidth)[i].m_highBit;
			int lowBit = (*pWeWidth)[i].m_lowBit;

			if (!(exprLowBit < 0) && !(exprLowBit <= lowBit && highBit <= exprHighBit))
				continue;

			m_vFile.Print("%s_%d_%d", pWeIdent->GetName().c_str(), highBit, lowBit);

			for (size_t i = 0; i < weIndexList.size(); i += 1) {
				if (!weIndexList[i]->IsConstValue())
					ParseMsg(PARSE_FATAL, weIndexList[i]->GetLineInfo(), "Non-constant index not supported");
				m_vFile.Print("$%d", weIndexList[i]->GetConstValue().GetSint32());
			}

			m_vFile.Print(" = ");

			if (pOp2->IsScX())
				m_vFile.Print("1'bx;\n");
			else if (pOp2->GetConstValue().GetUint64() == 0)
				m_vFile.Print("1'b0;\n");
			else
				m_vFile.Print("1'b1;\n");
		}
	}
}
Exemple #20
0
int main(int argc, char *argv[])
{
    
    fd_set master;                  // master file descriptor list
    fd_set read_fds;                // temp file descriptor list for select()
    struct sockaddr_in remoteaddr;  // client address
    unsigned ServerPort;            // portnumber of server 
    int fdmax,fdmax_used;           // maximum file descriptor number and helper to find new max 
    int listener;                   // listening socket descriptor
    int newfd;                      // newly accept()ed socket descriptor
    char buf[256];                  // buffer for client data
    int nbytes;
    int addrlen;
    int i, j;
    int NewClient;                  // NewClient ID
    struct timeval timeout;         // timeout 
    int ret; 
    struct ClientListType *ptrNewClient;              // ptr to new & Active Client;
    struct ClientListType *ptrClientRightList;                          // array which contains rights of reg.Clients      
    struct ActiveClientStructType ActiveClientStruct;                       // struct which contains array of active cl.
    
    
    // some command line parsing
    
    if (argc>1) {  // first argument might be a port assignment
	if (*argv[1]=='?') { // ask for help
	    printf("Usage : %s PortNum\n",argv[0]);
	    exit(EXIT_SUCCESS);
	} else {
	    ServerPort=atol(argv[1]);
	}
    } else {
	ServerPort=TCP_CLIENT_PORT;
    }
    
    //  Init Client Access list
    InitClientAccessList(ptrClientRightAscList, &ptrClientRightList);
    
    // Init Active Client List
    InitActiveClientStruct(&ActiveClientStruct);
    
    
    printf("Setup instrument server version %s on port %d ...",VERSION, ServerPort);
    listener=InitTCPListener(ServerPort);
    if (listener<1) {
	perror("TCPListener");
    }
    printf("success\n");
    
    // setup master fd
    FD_ZERO(&master);              // clear the master and temp sets
    FD_ZERO(&read_fds);
    FD_SET(listener, &master);     // add the listener to the master set
    
    // keep track of the biggest file descriptor
    
    fdmax = listener; // so far, it's this one

    for(;;) { // main loop

        // setup fd's timeout and wait for incoming request
        read_fds = master;
        timeout.tv_sec=TCP_CLIENT_WDG;
        timeout.tv_usec=0;
        ret=select(fdmax+1, &read_fds, NULL, NULL, &timeout);
        
        if (ret == -1) { // select error we dare not to handle
            perror("select");
            exit(EXIT_FAILURE);
        }
	
        if (ret) { // lets see what we got
	    for(i = 0; i <= fdmax; i++) {
		if (FD_ISSET(i, &read_fds)) {                                // new msg on i. socket ...
		    if (i == listener) {                                     // listener -> new connection request
			addrlen = sizeof(remoteaddr);			
			if ((newfd = accept(listener, (struct sockaddr *)&remoteaddr,           // first we have to accept
					    &addrlen)) == -1) {
			    perror("accept");
			} else {
			    //Valid client ?
			    if ( ((ptrNewClient=ValidateAddress(&remoteaddr,ptrClientRightList))!=NULL) ) {
				//add new client to active list
				if ((NewClient=AddClientToList(&ActiveClientStruct,ptrNewClient,newfd))<0) { // couldn't add Client to list;
				    printf("no available sockets for fd %d\n",newfd);
				    close(newfd); // close connection
				} else {          // give a positive msg to the log and keep track of maxfd
				    printf("accepted new connection from %s\n",
					   ActiveClientStruct.ptrActiveClientArray[NewClient].ClientName);
				    FD_SET(newfd, &master); // add to master set  
				    if (newfd > fdmax) {    // keep trackof the maximum
					fdmax = newfd;
				    }
				} // endif AddClient
			    } else {   // couldn't find applicant in internal rights list, kick him out
				close(newfd);
				printf("deny access from %s closing..\n",inet_ntoa(remoteaddr.sin_addr));
			    } // endif ValidateAddress
			    
			} // endif accept
		    } else {                                                // handle data from a clients
			if ((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) { // got error or connection closed by client
			    if (nbytes == 0) {                              // connection closed
				ret=RemoveClientFromList(&ActiveClientStruct,i);
				printf("instrumentserver: %s on socket %d hung up\n", 
				       ActiveClientStruct.ptrActiveClientArray[ret].ClientName, i);
			    } else {
				perror("recv");
			    } // EndIf recv
			    close(i); // bye!
			    FD_CLR(i, &master); // remove from master set
			} else { // we got some data from a client
			    
			    // display whats in decimal for first
			    
			    ParseMsg(buf,nbytes,&ActiveClientStruct);
			    
			    for(j = 0; j <= fdmax; j++) {
				// send to everyone
				if (FD_ISSET(j, &master)) {
				    // except the listener and sender
				    if (j != listener && j != i) {
					if (send(j, buf, nbytes, 0) == -1) {
					    perror("send");
					} //endif send					
				    }  // sender and listener
				} // someone in master list
			    } //endfor all clients
			}
		    }
		}
	    }
	} else {
	    for (i = 0; i <= fdmax; i++) {
		if (FD_ISSET(i,&master)) {
		    printf("+");
		    fdmax_used=i;                               // find out what the highest used fd is
		} else {
		    printf(".");
		}
	    }
	    printf("\n");
	    fdmax=fdmax_used;                                  // garbage collection on max fdnum
	}
    } // for main loop
    
    
// release used memory
    
    ReleaseActiveClientStruct(&ActiveClientStruct);            // relase memory of ActiveClientStruct
    ReleaseClientAccessList(ptrClientRightList);               // relase memory of ClientRightList
    
    return EXIT_SUCCESS;
}
void
NetLobbyClient::DoUserList(NetPeer* peer, Text msg)
{
    List<NetLobbyParam> params;
    ParseMsg(msg, params);

    users.destroy();

    Text  user_name;
    Text  host_flag;
    Text  signature;
    Text  squadron;
    int   rank           = 0;
    int   flight_time    = 0;
    int   mission_count  = 0;
    int   kills          = 0;
    int   losses         = 0;

    for (int i = 0; i < params.size(); i++) {
        NetLobbyParam* p = params[i];

        int num = 0;
        sscanf_s(p->value, "%d", &num);

        if (p->name == "name")
        user_name = p->value;

        else if (p->name == "sig")
        signature = p->value;

        else if (p->name == "squad")
        squadron = p->value;

        else if (p->name == "rank")
        rank = num;

        else if (p->name == "time")
        flight_time = num;

        else if (p->name == "miss")
        mission_count = num;

        else if (p->name == "kill")
        kills = num;

        else if (p->name == "loss")
        losses = num;

        else if (p->name == "host") {
            host_flag = p->value;

            NetUser* u = new(__FILE__,__LINE__) NetUser(user_name);
            u->SetHost((host_flag == "true") ? true : false);
            u->SetSignature(signature);
            u->SetSquadron(squadron);
            u->SetRank(rank);
            u->SetFlightTime(flight_time);
            u->SetMissions(mission_count);
            u->SetKills(kills);
            u->SetLosses(losses);

            AddUser(u);
        }
    }

    params.destroy();
}