uint8_t TerminalReceiveChar(unsigned int timeout) { // Try to read a character from the USB library unsigned int start = GetMilliSeconds(); while (GetMilliSeconds() - start < timeout) { int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); if (!(ReceivedByte < 0)) { // got a character return((unsigned char)ReceivedByte); } } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { std::wcout << L"version : 2015.09.14" << std::endl; std::wcout << L"Usage : FbxExporter <path to fbx file> <outdir> [/fps:60|30|24] [/skipemptynodes] [/animstack:\"animstack name\"]" << std::endl; if (argc < 3) { std::wcerr << L"Invalid argument count" << std::endl; return -1; } std::wstring wInputPath(argv[1]); std::wstring wInputDir(argv[1]); std::wstring wInputFileName(argv[1]); auto lastDirSeparator = wInputDir.find_last_of(L'\\'); if (lastDirSeparator == wInputDir.npos) { wInputDir = L"."; } else { wInputDir.erase(lastDirSeparator); wInputFileName.erase(0, lastDirSeparator + 1); } std::wstring wOutputPath(argv[2]); CreateDirectory(wOutputPath.c_str(), nullptr); bool skipEmptyNodes = false; std::wstring animStackName; for (int i = 3; i < argc; ++i) { std::wstring warg = argv[i]; if (warg == L"/skipemptynodes") { skipEmptyNodes = true; } else if (warg.find(L"/fps:") == 0) { if (warg == L"/fps:60") { GlobalSettings::Current().AnimationsTimeMode = FbxTime::EMode::eFrames60; } else if (warg == L"/fps:30") { GlobalSettings::Current().AnimationsTimeMode = FbxTime::EMode::eFrames30; } else if (warg == L"/fps:24") { GlobalSettings::Current().AnimationsTimeMode = FbxTime::EMode::eFrames24; } else { std::wcerr << L"Unrecognized fps parameter" << std::endl; return -2; } } else if (warg.find(L"/animstack:") == 0) { animStackName = warg.substr(11); if (animStackName.size()>0 && animStackName[0] == L'\"') { animStackName.erase(0, 1); } if (animStackName.size() > 0 && animStackName[animStackName.size() - 1] == L'\"') { animStackName.erase(animStackName.size() - 1, 1); } } } FbxSceneLoader sceneLoader(wstringToUtf8(wInputPath)); auto animStackCount = sceneLoader.getScene()->GetSrcObjectCount<FbxAnimStack>(); if (animStackName.size() == 0) { GlobalSettings::Current().AnimStackIndex = 0; } else { for (auto ix = 0; ix < animStackCount; ++ix) { auto animStack = sceneLoader.getScene()->GetSrcObject<FbxAnimStack>(ix); if (utf8ToWstring(animStack->GetName()) == animStackName) { GlobalSettings::Current().AnimStackIndex = ix; } } } std::wcout << L"Animation stacks : " << std::endl; for (auto ix = 0; ix < animStackCount; ++ix) { auto animStack = sceneLoader.getScene()->GetSrcObject<FbxAnimStack>(ix); if (ix == GlobalSettings::Current().AnimStackIndex) { std::wcout << L"[X] "; sceneLoader.getScene()->SetCurrentAnimationStack(animStack); } else { std::wcout << L"[ ] "; } std::wcout << utf8ToWstring(animStack->GetName()); auto ts=animStack->GetLocalTimeSpan(); auto start = ts.GetStart(); auto stop = ts.GetStop(); std::wcout << L"(" << start.GetMilliSeconds() << L" - " << stop.GetMilliSeconds() << L")" << std::endl; } auto root = sceneLoader.rootNode(); BabylonScene babScene(*root, skipEmptyNodes); for (auto& mat : babScene.materials()) { exportTexture(mat.ambientTexture, wOutputPath); exportTexture(mat.diffuseTexture, wOutputPath); exportTexture(mat.specularTexture, wOutputPath); exportTexture(mat.emissiveTexture, wOutputPath); exportTexture(mat.reflectionTexture, wOutputPath); exportTexture(mat.bumpTexture, wOutputPath); } auto json = babScene.toJson(); if (L'\\' != *wOutputPath.crbegin()) { wOutputPath.append(L"\\"); } wOutputPath.append(wInputFileName); auto lastDot = wOutputPath.find_last_of(L'.'); wOutputPath.erase(lastDot); wOutputPath.append(L".babylon"); DeleteFile(wOutputPath.c_str()); std::ofstream stream(wOutputPath); json.serialize(stream); stream.flush(); return 0; }
/* * Writes Out information of one frame of the worm to a disk * in YAML format. * * Note the Worm object must have the following fields * Worm->frameNum * Worm->Segmented->Head * Worm->Segmented->Tail * Worm->Segmented->LeftBound * Worm->Segmented->RightBound * Worm->Segmented->Centerline * * and Params object must have * Params->DLPOn * Params->IllumSegCenter * Params->IllumSegRadius * Params->IllumLRC * * And more now! */ int AppendWormFrameToDisk(WormAnalysisData* Worm, WormAnalysisParam* Params, WriteOut* DataWriter){ CvFileStorage* fs=DataWriter->fs; cvStartWriteStruct(fs,NULL,CV_NODE_MAP,NULL); /** Frame Number Info **/ cvWriteInt(fs,"FrameNumber",Worm->frameNum); /** TimeStamp **/ cvWriteInt(fs,"sElapsed",GetSeconds(Worm->timestamp)); cvWriteInt(fs,"msRemElapsed",GetMilliSeconds(Worm->timestamp)); /** Segmentation Info **/ if(cvPointExists(Worm->Segmented->Head)){ cvStartWriteStruct(fs,"Head",CV_NODE_MAP,NULL); cvWriteInt(fs,"x",Worm->Segmented->Head->x); cvWriteInt(fs,"y",Worm->Segmented->Head->y); cvEndWriteStruct(fs); } if(cvPointExists(Worm->Segmented->Tail)){ cvStartWriteStruct(fs,"Tail",CV_NODE_MAP,NULL); cvWriteInt(fs,"x",Worm->Segmented->Tail->x); cvWriteInt(fs,"y",Worm->Segmented->Tail->y); cvEndWriteStruct(fs); } if(cvSeqExists(Worm->Segmented->LeftBound)) cvWrite(fs,"BoundaryA",Worm->Segmented->LeftBound); if(cvSeqExists(Worm->Segmented->RightBound)) cvWrite(fs,"BoundaryB",Worm->Segmented->RightBound); if(cvSeqExists(Worm->Segmented->Centerline)) cvWrite(fs,"SegmentedCenterline",Worm->Segmented->Centerline); /** Illumination Information **/ cvWriteInt(fs,"DLPIsOn",Params->DLPOn); cvWriteInt(fs,"FloodLightIsOn",Params->IllumFloodEverything); cvWriteInt(fs,"IllumInvert",Params->IllumInvert); cvWriteInt(fs,"IllumFlipLR",Params->IllumFlipLR); CvPoint origin=ConvertSlidlerToWormSpace(Params->IllumSquareOrig,Params->DefaultGridSize); cvStartWriteStruct(fs,"IllumRectOrigin",CV_NODE_MAP,NULL); cvWriteInt(fs,"x",origin.x); cvWriteInt(fs,"y",origin.y); cvEndWriteStruct(fs); cvStartWriteStruct(fs,"IllumRectRadius",CV_NODE_MAP,NULL); cvWriteInt(fs,"x",Params->IllumSquareRad.width); cvWriteInt(fs,"y",Params->IllumSquareRad.height); cvEndWriteStruct(fs); if (Params->stageTrackingOn){ cvStartWriteStruct(fs,"StageVelocity",CV_NODE_MAP,NULL); cvWriteInt(fs,"i",Worm->stageVelocity.x); cvWriteInt(fs,"j",Worm->stageVelocity.y); cvEndWriteStruct(fs); } /** Protocol Information **/ cvWriteInt(fs,"ProtocolIsOn",Params->ProtocolUse); cvWriteInt(fs,"ProtocolStep",Params->ProtocolStep); cvEndWriteStruct(fs); return 0; }
EipStatus NetworkHandlerInitialize(void) { #ifdef WIN32 WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); WSAStartup(wVersionRequested, &wsaData); #endif /* clear the master an temp sets */ FD_ZERO(&master); FD_ZERO(&read_fds); /* create a new TCP socket */ if ((g_network_status.tcp_listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) { OPENER_TRACE_ERR("error allocating socket stream listener, %d\n", errno); return kEipStatusError; } int nOptVal = 1; if (setsockopt(g_network_status.tcp_listener, SOL_SOCKET, SO_REUSEADDR, (char *)&nOptVal, sizeof(nOptVal)) == -1) { OPENER_TRACE_ERR("error setting socket option SO_REUSEADDR on nTCPListener\n"); return kEipStatusError; } /* create a new UDP unicast socket */ if ((g_network_status.udp_unicast_listener = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { OPENER_TRACE_ERR("error allocating udp listener socket, %d\n", errno); return kEipStatusError; } if (setsockopt(g_network_status.udp_unicast_listener, SOL_SOCKET, SO_REUSEADDR, (char *)&nOptVal, sizeof(nOptVal)) == -1) { OPENER_TRACE_ERR("error setting socket option SO_REUSEADDR on nUDPListener\n"); return kEipStatusError; } /* create a new UDP broadcast socket */ if ((g_network_status.udp_broadcast_listener = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { OPENER_TRACE_ERR("error allocating udp listener socket, %d\n", errno); return kEipStatusError; } if (setsockopt(g_network_status.udp_broadcast_listener, SOL_SOCKET, SO_REUSEADDR, (char *)&nOptVal, sizeof(nOptVal)) == -1) { OPENER_TRACE_ERR("error setting socket option SO_REUSEADDR on nUDPListener\n"); return kEipStatusError; } /* set up unicast udp socket */ struct sockaddr_in unicast_address = { .sin_family = AF_INET, .sin_port = htons(kOpenerEthernetPort), .sin_addr.s_addr = interface_configuration_.ip_address }; if ((bind(g_network_status.udp_unicast_listener, (struct sockaddr *) &unicast_address, sizeof(struct sockaddr))) == -1) { int error_code = WSAGetLastError(); OPENER_TRACE_ERR("error with udp bind: %d, %s\n", error_code, strerror(error_code)); return kEipStatusError; } struct sockaddr_in my_address = { .sin_family = AF_INET, .sin_port = htons(kOpenerEthernetPort), .sin_addr.s_addr = htonl(INADDR_ANY) }; /* bind the new socket to port 0xAF12 (CIP) */ if ((bind(g_network_status.tcp_listener, (struct sockaddr *) &my_address, sizeof(struct sockaddr))) == -1) { OPENER_TRACE_ERR("error with bind: %s\n", strerror(errno)); return kEipStatusError; } /* enable the udp socket to receive broadcast messages*/ int y = 1; if (0 > setsockopt(g_network_status.udp_broadcast_listener, SOL_SOCKET, SO_BROADCAST, (char *)&y, sizeof(int))) { OPENER_TRACE_ERR("error with setting broadcast receive for udp socket: %s\n", strerror(errno)); return kEipStatusError; } if ((bind(g_network_status.udp_broadcast_listener, (struct sockaddr *) &my_address, sizeof(struct sockaddr))) == -1) { OPENER_TRACE_ERR("error with udp bind: %s\n", strerror(errno)); return kEipStatusError; } /* switch socket in listen mode */ if ((listen(g_network_status.tcp_listener, MAX_NO_OF_TCP_SOCKETS)) == -1) { OPENER_TRACE_ERR("networkhandler: error with listen: %s\n", strerror(errno)); return kEipStatusError; } /* add the listener socket to the master set */ FD_SET(g_network_status.tcp_listener, &master); FD_SET(g_network_status.udp_broadcast_listener, &master); FD_SET(g_network_status.udp_unicast_listener, &master); /* keep track of the biggest file descriptor */ fdmax = GetMaxSocket(g_network_status.tcp_listener, g_network_status.udp_unicast_listener, g_network_status.udp_broadcast_listener, -1); last_time = GetMilliSeconds(); /* initialize time keeping */ g_network_status.elapsed_time = 0; return kEipStatusOk; } EipStatus NetworkHandlerProcessOnce(void) { int fd; int res; read_fds = master; time_value.tv_sec = 0; time_value.tv_usec = ( g_network_status.elapsed_time < kOpenerTimerTickInMilliSeconds ? kOpenerTimerTickInMilliSeconds - g_network_status.elapsed_time : 0) * 1000; /* 10 ms */ res = select(fdmax + 1, &read_fds, 0, 0, &time_value); if (res == -1) { if (EINTR == errno) /* we have somehow been interrupted. The default behavior is to go back into the select loop. */ { return kEipStatusOk; } else { OPENER_TRACE_ERR("networkhandler: error with select: %s\n", strerror(errno)); return kEipStatusError; } } if (res > 0) { CheckAndHandleTcpListenerSocket(); CheckAndHandleUdpBroadCastSocket(); CheckAndHandleUdpUnicastSocket(); CheckAndHandleConsumingUdpSockets(); for (fd = 0; fd <= fdmax; fd++) { if (true == checkSocketSet(fd)) { /* if it is still checked it is a TCP receive */ if (kEipStatusError == handleDataOnTCPSocket(fd)) /* if error */ { CloseSocket(fd); CloseSession(fd); /* clean up session and close the socket */ } } } } actual_time = GetMilliSeconds(); g_network_status.elapsed_time += actual_time - last_time; last_time = actual_time; /* check if we had been not able to update the connection manager for several OPENER_TIMER_TICK. * This should compensate the jitter of the windows timer */ while (g_network_status.elapsed_time >= kOpenerTimerTickInMilliSeconds) { /* call manage_connections() in connection manager every OPENER_TIMER_TICK ms */ ManageConnections(); g_network_status.elapsed_time -= kOpenerTimerTickInMilliSeconds; } return kEipStatusOk; }