Beispiel #1
0
static void UsbConnectionLost ( void )
{
  SerialPrintStr( "Connection lost on the native USB port." EOL );

  BusPirateConnection_Terminate();
  ResetBuffers();

  // Note that at this point there may still be outgoing data in the USB buffer inside the Atmel Software Framework
  // (or may be that is directly the chip's USB hardware buffer). If the USB cable was not removed, this data
  // will not be lost. I have tested that data written here with udi_cdc_write_buf() gets received twice
  // by the next program that connects to the CDC serial port, which seems strange. I guess the host side (Linux)
  // will buffer up any received data and then deliver it to the next client that connects to CDC the serial port,
  // as long as the USB cable remains put. I could not find any ASF API near udi_cdc_write_buf() in order
  // to discard any outgoing data from the ASF buffer.
  //
  // For the reasons above, I guess that any serial port client on the host side (Linux) should read and
  // discard all stale data upon connect. After all, the Bus Pirate protocol is of the master/slave type,
  // so the client should have nothing to say until the master sends the first command.
  //
  // Enabling the condition below will generate stale data for test purposes, but I am not sure
  // whether this is an ASF bug. After all, any data written after getting the connection lost notification
  // should be automatically discarded.
  //
  // Another way to generate stale data is with this bash command:
  //     printf "help\r">/dev/jtagdue1
  // The next time you connect to /dev/jtagdue1 you will get the help text,
  // you can test it with this bash command:
  //     cat /dev/jtagdue1

  if ( false )
  {
    udi_cdc_write_buf( "stale-test-data", 15 );
  }
}
Beispiel #2
0
	void SetResampling(int samplerate)
	{
		mOutputSamplesPerSec = samplerate;
		mResampleRatio = double(samplerate) / double(mSSpec.rate);
		//mResample = true;
		ResetBuffers();
	}
Beispiel #3
0
void CRenderer::DrawBatch()
{
	if ( GetVBSize() > 0 )
	{
		IwGxLightingOff();
		IwGxSetMaterial( mCurrMtl ); 
		IwGxSetUVStream( mUVB );
		IwGxSetColStream(mCB, mCBSize); 
		IwGxSetVertStreamScreenSpaceSubPixel( mVB, mVBSize );
		if ( mIBSize == 0 )
		{
			IwGxDrawPrims(mBuffType, NULL, mVBSize);
		}
		else
		{
			IwGxDrawPrims(mBuffType, mIB, mIBSize);
		}
		
		
		mCurrMtl = NULL;
		//DefaultMaterial();
	
		IwGxFlush(); 
		IwGxSetColStream(NULL); 
		//IwGxSetUVStream( NULL );
		ResetBuffers();
	}
}
Beispiel #4
0
bool CUrlParts::AllocateBuffers(int iNum)
{
	if(Allocated == true)
		ResetBuffers();
	szScheme = (LPTSTR) malloc( (iNum+1) * sizeof(TCHAR));
	//Check
	if(!szScheme)
		return false;
	szHostName = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	szUserName = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	szPassword = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	szUrlPath = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	szExtraInfo = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	szFileName = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	szFileExtension = (LPTSTR) malloc((iNum+1) * sizeof(TCHAR));
	//Check the last one
	if(!szFileExtension)
		return false;
	szScheme[iNum] = _T('\0');
	szHostName[iNum] = _T('\0');
	szUserName[iNum] = _T('\0');
	szPassword[iNum] = _T('\0');
	szUrlPath[iNum] = _T('\0');
	szExtraInfo[iNum] = _T('\0');
	szFileName[iNum] = _T('\0');
	szFileExtension[iNum] = _T('\0');
	return true;
}
Beispiel #5
0
static void UsbConnectionEstablished ( void )
{
  SerialPrintStr( "Connection opened on the native USB port." EOL );

  // SerialPrint( "Rx buffer size: %u, Tx buffer size: %u" EOL, unsigned(USB_RX_BUFFER_SIZE), unsigned(USB_TX_BUFFER_SIZE) );

  ResetBuffers();
  BusPirateConnection_Init( &s_usbTxBuffer );
}
Beispiel #6
0
void CRenderer::AllocBuffers()
{
	IwAssert(RENDER, (mVB == NULL && mUVB == NULL && mCB == NULL) );

	mVB  = (CIwSVec2*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(CIwSVec2) );
	mUVB = (CIwSVec2*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(CIwSVec2) );
	mCB  = (CIwColour*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(CIwColour) );
	mIB  = (uint16*)calloc( RENDER_MAX_BUFF_SIZE, sizeof(uint16) );
	ResetBuffers();

}
Beispiel #7
0
	uint32_t GetBuffer(int16_t *buff, uint32_t len)
	{
		auto now = hrc::now();
		auto dur = std::chrono::duration_cast<ms>(now-mLastGetBuffer).count();
		//Disconnected, try reconnect after every 1sec, hopefully game retries to read samples
		if (mPAready == 3 && dur >= 1000)
		{
			mLastGetBuffer = now;
			int ret = pf_pa_context_connect (mPContext,
				mServer,
				PA_CONTEXT_NOFLAGS,
				NULL
			);

			OSDebugOut("pa_context_connect %s\n", pf_pa_strerror(ret));
		}
		else
			mLastGetBuffer = now;

		// Something cocked up and game didn't poll usb over 5 secs
		if (dur > 5000)
			ResetBuffers();

		mOutSamples += len;

		// init time point
		if (mLastOut.time_since_epoch().count() == 0)
			mLastOut = now;

		auto diff = std::chrono::duration_cast<us>(now-mLastOut).count();

		if (diff >= int64_t(1e6))
		{
			mTimeAdjust = (mOutSamples / (diff / 1e6)) / mOutputSamplesPerSec;
			//if(mTimeAdjust > 1.0) mTimeAdjust = 1.0; //If game is in 'turbo mode', just return zero samples or...?
			OSDebugOut("timespan: %" PRId64 " sampling: %f adjust: %f\n", diff, float(mOutSamples) / diff * 1e6, mTimeAdjust);
			mLastOut = now;
			mOutSamples = 0;
		}

		std::lock_guard<std::mutex> lk(mMutex);
		uint32_t totalLen = MIN(len * mSSpec.channels, mResampledBuffer.size());
		OSDebugOut("Resampled buffer size: %zd, copy: %zd\n", mResampledBuffer.size(), totalLen);
		if (totalLen > 0)
		{
			memcpy(buff, &mResampledBuffer[0], sizeof(short) * totalLen);
			mResampledBuffer.erase(mResampledBuffer.begin(), mResampledBuffer.begin() + totalLen);
		}

		return totalLen / mSSpec.channels;
	}
Beispiel #8
0
inline int CTransparencyRenderer::AllocBuffers (void)
{
if (m_data.depthBuffer.Buffer ())
	return 1;
if (!m_data.depthBuffer.Create (ITEM_DEPTHBUFFER_SIZE))
	return 0;
if (!m_data.itemLists.Create (ITEM_BUFFER_SIZE)) {
	m_data.depthBuffer.Destroy ();
	return 0;
	}
m_data.nFreeItems = 0;
ResetBuffers ();
return 1;
}
Beispiel #9
0
void CRenderer::Begin()
{
	s3eDeviceYield(0);
	IwGxLightingOff();
	//IwGxLightingAmbient(true);
	IwGxSetScreenSpaceOrg( &CIwSVec2::g_Zero );
	//IwGxSetScreenSpaceSlot( 0 );
	//IwGxLightingDiffuse( false );
	IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); 

	if (mIsResetDeviceparam)
	{
		mIsResetDeviceparam = false;
		UpdateDeviceParams();
		if ( mOnResetparams != NULL )
		{
			mOnResetparams();
		}		
	}

	ResetBuffers();
}
Beispiel #10
0
// dt of 2d function using squared distance
void DistanceTransform::DistanceTransform2D( ArrayGrid<double> *pGridInOut )
{
   int width = pGridInOut->GetWidth();
   int height = pGridInOut->GetHeight();
   int n  = std::max( width, height );

   // allocate memory buffers just once per image instead of for every row and every column
   mpValuesIn = new double[ n ];
   mpDistanceTransformValues = new double[n];
   mpParabolaLocations = new int[n];            // Locations of parabolas in lower envelope
   mpParabolaBoundary = new double[n+1];     // Locations of boundaries between parabolas

   // transform along columns
   for (int x = 0; x < width; x++)
   {
      pGridInOut->GetColumnCopy( x, mpValuesIn );

      DistanceTransform1D( height );
      for (int y = 0; y < height; y++)
      {
         pGridInOut->SetValue( x, y, mpDistanceTransformValues[ y ] );
      }
   }

   // transform along rows
   for (int y = 0; y < height; y++)
   {
      pGridInOut->GetRowCopy( y, mpValuesIn );
      DistanceTransform1D( width );
      for (int x = 0; x < width; x++)
      {
         pGridInOut->SetValue(x, y, mpDistanceTransformValues[x]);
      }
   }
   ResetBuffers();
}
Beispiel #11
0
AdvImageLayout::~AdvImageLayout()
{
	ResetBuffers();
}
Beispiel #12
0
DistanceTransform::~DistanceTransform()
{
    ResetBuffers();
}
Beispiel #13
0
/*
 * Open next disk archive file.
 */
int
DkNextArchiveFile(void)
{
	static upath_t tarFileName;
	FileInfo_t *file;
	int copy;
	int retry;
	int error = 0;
	boolean_t oprmsg = B_TRUE;

	file = IoThread->io_file;
	copy = file->copy;

	if (diskArchiveOpen == B_FALSE ||
	    seqnum != file->ar[copy].section.position) {

		if (diskArchiveOpen) {
			(void) SamrftClose(IoThread->io_rftHandle);
			diskArchiveOpen = B_FALSE;
		}

		/*
		 * Generate tar file name.
		 */
		seqnum = file->ar[copy].section.position;
		(void) DiskVolsGenFileName(seqnum, tarFileName,
		    sizeof (tarFileName));

		snprintf(fullpath, sizeof (fullpath), "%s/%s",
		    diskVolume->DvPath, tarFileName);
		snprintf(volpath, sizeof (volpath), "%s", diskVolume->DvPath);

		Trace(TR_FILES, "Open file '%s' (0x%llx)", fullpath, seqnum);

		if (lastdvavail == B_FALSE &&
		    strncmp(volpath, lastdv, sizeof (volpath)) == 0) {
			retry = 1;		/* No retry */
			oprmsg = B_FALSE;
		} else {
			retry = file->retry;
		}
		error = -1;

		while (error == -1 && retry-- > 0) {
			int rc;

			rc = SamrftOpen(IoThread->io_rftHandle, fullpath,
			    O_RDONLY | O_LARGEFILE, NULL);
			if (rc == 0) {
				error = 0;
			} else {
				Trace(TR_ERR, "Unable to open file: %s "
				    "errno: %d", fullpath, errno);
				if (retry > 0) {
					sleep(5);
				} else if ((oprmsg == B_FALSE) &&
				    (errno == ENOENT)) {
					/*
					 * Failed to open a diskvol for the
					 * second time in a row.
					 * Set ENODEV if disk archive volume
					 * is not available.
					 */
					if (DiskVolsIsAvail(NULL,
					    diskVolume, B_FALSE,
					    DVA_stager) != B_TRUE) {
						SetErrno = ENODEV;
						Trace(TR_ERR, "Diskvolume "
						    "'dk.%s' not available."
						    " errno: %d",
						    Stream->vsn, errno);
					}
				}
			}
		}

		/*
		 * A new disk archive file.  Invalidate buffers and set
		 * current position to beginning of file.
		 */
		if (error == 0) {
			ResetBuffers();
			diskArchiveOpen = B_TRUE;
			IoThread->io_position = 0;
			lastdvavail = B_TRUE;
		} else {
			char errbuf[132];

			if (diskVolume->DvHost != NULL &&
			    diskVolume->DvHost[0] != '\0') {
				snprintf(errbuf, sizeof (errbuf), "%s:%s",
				    diskVolume->DvHost, fullpath);
			} else {
				strncpy(errbuf, fullpath, sizeof (errbuf));
			}
			lastdvavail = B_FALSE;
		}
		strncpy(lastdv, volpath, sizeof (volpath));
	}

	if (error != 0) {
		char errbuf[132];

		if (oprmsg == B_TRUE) {
			PostOprMsg(State->errmsg, 19208, fullpath);
			sleep(5);
			ClearOprMsg(State->errmsg);
		}

		if (diskVolume->DvHost != NULL &&
		    diskVolume->DvHost[0] != '\0') {
			snprintf(errbuf, sizeof (errbuf), "%s:%s",
			    diskVolume->DvHost, fullpath);
		} else {
			strncpy(errbuf, fullpath, sizeof (errbuf));
		}
		WarnSyscallError(HERE, "open", errbuf);
	}
	return (error);
}
Beispiel #14
0
	void Start()
	{
		ResetBuffers();
		mPaused = false;
	}
Beispiel #15
0
/*
 * Stage all files in the stream.
 */
static void
copyStream()
{
	int rval;
	FileInfo_t *file;
	int dcache;
	boolean_t reject;

	StageInit(Stream->vsn);

	/* Set loading flag for this stream. */
	PthreadMutexLock(&Stream->mutex);
	SET_FLAG(Stream->flags, SR_LOADING);
	PthreadMutexUnlock(&Stream->mutex);

	rval = LoadVolume();

	/* Reject if mount/open failed. */
	if (rval != 0) {
		PthreadMutexLock(&Stream->mutex);
		removeDcachedFile(Stream, rval);

		if (rval == ENODEV) {
			Stream->context = 0;
			PthreadMutexUnlock(&Stream->mutex);
			rejectRequest(0, B_TRUE);
			SET_FLAG(Instance->ci_flags, CI_shutdown);
		} else {
			PthreadMutexUnlock(&Stream->mutex);
			SendCustMsg(HERE, 19017, Stream->vsn);
			rejectRequest(rval, B_TRUE);
		}

		StageEnd();
		return;
	}

	/* VSN load has completed. */
	checkBuffers(Stream->vsn);

	PthreadMutexLock(&Stream->mutex);
	CLEAR_FLAG(Stream->flags, SR_LOADING);

	Instance->ci_seqnum = Stream->seqnum;
	reject = B_FALSE;

	/*
	 * Copy all files in stage stream request.  The files have
	 * been ordered to eliminate backward media positioning.
	 */

	while (STREAM_IS_VALID() && reject == B_FALSE) {

		/* Stop staging if parent died. */
		if (getppid() == 1) {
			SetErrno = 0;		/* set for trace */
			Trace(TR_ERR, "Detected stager daemon exit");

			Stream->first = EOS;
			SET_FLAG(Instance->ci_flags, CI_shutdown);
			break;
		}

		file = GetFile(Stream->first);

		PthreadMutexLock(&file->mutex);
		PthreadMutexUnlock(&Stream->mutex);

		/*
		 * If the first vsn, clear bytes read count.
		 * And if multivolume and stage -n set, initialize
		 * residual length.
		 */
		if (file->vsn_cnt == 0) {
			file->read = 0;
			if (GET_FLAG(file->flags, FI_MULTIVOL) &&
			    GET_FLAG(file->flags, FI_STAGE_NEVER)) {
				file->residlen = file->len;
			} else {
				file->residlen = 0;
			}
		}

		SET_FLAG(file->flags, FI_ACTIVE);

		PthreadMutexUnlock(&file->mutex);

		/* Set file in io control structure for archive read thread. */
		setIoThread(file);

		/* Log stage start. */
		file->eq = IoThread->io_drive;
		LogIt(LOG_STAGE_START, file);

		/*
		 * Check if last request was canceled.  If the last request
		 * was canceled, invalidate i/o buffers and clear cancel
		 * flag in the control structure.
		 */
		if (GET_FLAG(IoThread->io_flags, IO_cancel)) {
			ResetBuffers();
			CLEAR_FLAG(IoThread->io_flags, IO_cancel);
		}

		/*
		 * Next archive file.  If disk archive, we may be opening
		 * a disk archive tarball.
		 */
		if ((rval = NextArchiveFile()) == 0) {
			/* Prepare filesystem to receive staged file. */
			dcache = DiskCacheOpen(file);

		} else {
			/* Unable to open disk archive.  Error request. */
			Trace(TR_ERR, "Unable to open disk archive "
			    "copy: %d inode: %d.%d errno: %d",
			    file->copy + 1, file->id.ino, file->id.gen, errno);
			dcache = -1;
			file->error = errno;
			SendErrorResponse(file);
		}

		if (dcache >= 0 && rval == 0) {
			/*
			 * Notify reader thread that next file in stream
			 * is ready to be staged.
			 */
			ThreadStatePost(&IoThread->io_readReady);

			/* Write data to disk cache. */
			rval = DiskCacheWrite(file, dcache);

			if (rval != 0) {
				SendErrorResponse(file);

				/* Check if number of stream errors exceeded. */
				reject = ifMaxStreamErrors(file);
			}

			ThreadStateWait(&IoThread->io_readDone);

		} else if (rval != 0 && dcache >= 0) {
			/* Setup for error handling. */
			SetFileError(file, dcache, 0, EIO);
			SendErrorResponse(file);
		}

		EndArchiveFile();

		/* Remove file from stream before marking it as done. */
		PthreadMutexLock(&Stream->mutex);
		Stream->first = file->next;

		/* Device not available. */
		if (file->error == ENODEV) {
			SetErrno = 0;	/* set for trace */
			Trace(TR_ERR, "No device available");

			reject = B_TRUE;
			if (NumOpenFiles <= 0 && Instance->ci_first == NULL) {
				SET_FLAG(Instance->ci_flags, CI_shutdown);
				Instance->ci_busy = B_TRUE;
			}
		}

		/* Mark file staging as done. */
		SetStageDone(file);
		Stream->count--;

		if (Stream->first == EOS) {
			Stream->last = EOS;
		}

	}

	/* Reject rest of stages in this stream. */
	if (reject == B_TRUE) {
		if (Stream->first > EOS) {
			removeDcachedFile(Stream, ENODEV);
		}
		PthreadMutexUnlock(&Stream->mutex);
		rejectRequest(ENODEV, B_FALSE);
		PthreadMutexLock(&Stream->mutex);
	}

	/* Remove copy request, no one is waiting on it. */
	RemoveMapFile(copyRequestPath, Request, sizeof (CopyRequestInfo_t));
	Request = NULL;

	/* Ready to unload.  Mark stream as done. */
	SET_FLAG(Stream->flags, SR_DONE);
	PthreadMutexUnlock(&Stream->mutex);

	UnloadVolume();

	/*
	 * Unmap pages of memory.  Stream's memory
	 * mapped file is removed in parent.
	 */
	UnMapFile(Stream, sizeof (StreamInfo_t));
	Stream = NULL;

	StageEnd();
}
Beispiel #16
0
static void* MainChatbotServer()
{
	sprintf(serverLogfileName,"LOGS/serverlog%d.txt",port);
	ServerStartup(); //   get initial control over the mutex so we can start. - on linux if thread dies, we must reacquire here 
	// we now own the chatlock
	clock_t lastTime = ElapsedMilliseconds(); 

	if (setjmp(scriptJump[MAIN_RECOVERY])) // crashes come back to here
	{
		printf("***Server exception\r\n");
		ReportBug("***Server exception\r\n");
#ifdef WIN32
		char* bad = GetUserVariable("$crashmsg");
		if (*bad) strcpy(outputFeed,bad);
		else strcpy(outputFeed,"Hey, sorry. I forgot what I was thinking about.");
		ServerTransferDataToClient("");
#endif
		ResetBuffers(); //   in the event of a trapped bug, return here, we will still own the chatlock
	}
    chatbotExists = true;   //  if a client can get the chatlock now, he will be happy
	Log(SERVERLOG,"Server ready\r\n");
	printf("Server ready: %s\r\n",serverLogfileName);
#ifdef WIN32
 _try { // catch crashes in windows
#endif
	int counter = 0;
	while (1)
	{
		ServerGetChatLock();
		startServerTime = ElapsedMilliseconds(); 

		// chatlock mutex controls whether server is processing data or client can hand server data.
		// That we now have it means a client has data for us.
		// we own the chatLock again from here on so no new client can try to pass in data. 
		// CLIENT has passed server in globals:  clientBuffer (ip,user,bot,message)
		// We will send back his answer in clientBuffer, overwriting it.
		char user[MAX_WORD_SIZE];
		char bot[MAX_WORD_SIZE];
		char* ip = clientBuffer;
		char* ptr = ip;
		// incoming is 4 strings together:  ip, username, botname, message
		ptr += strlen(ip) + 1;	// ptr to username
		strcpy(user,ptr); // allow user var to be overwriteable, hence a copy
		ptr += strlen(ptr) + 1; // ptr to botname
		strcpy(bot,ptr);
		ptr += strlen(ptr) + 1; // ptr to message
		strcpy(inputFeed,ptr); // xfer user message to our incoming feed
		echo = false;

		PerformChat(user,bot,inputFeed,ip,outputFeed);	// this takes however long it takes, exclusive control of chatbot.
#ifdef STATSERVER
		clock_t now = ElapsedMilliseconds();
		if ( (now / 1000) > (lastTime / 1000)) // starting different second
		{
			printf("%d\r\n",counter);
			counter = 0;
			lastTime = now; 
		}
		++counter;
		if ((now-startServerTime) > 2000) 
		{
			printf("Compute Stall? %d\r\n",now-startServerTime);
		}
#endif		
	ServerTransferDataToClient(priorMessage);
	}
#ifdef WIN32
		}_except (true) {
			ReportBug("crash\r\n"); Crash();}
#endif
	return NULL;
}
Beispiel #17
0
CUrlParts::~CUrlParts()
{
	ResetBuffers();
}
Beispiel #18
0
TInt DChannelComm::DoControl(TInt aFunction, TAny* a1, TAny* a2)
	{

	TCommConfigV01 c;
	TInt r = KErrNone;

	switch (aFunction)
		{
		case RBusDevComm::EControlConfig:
			{
			//get the current configuration
			TPtrC8 cfg((const TUint8*)&iConfig, sizeof(iConfig));
			r = Kern::ThreadDesWrite(iClient, a1, cfg, 0, KTruncateToMaxLength, iClient);
			break;
			}

		case RBusDevComm::EControlSetConfig:
			{
			if (AreAnyPending())	
				Kern::PanicCurrentThread(_L("D32COMM"), ESetConfigWhileRequestPending);
			else
				{
				memclr(&c, sizeof(c));
				TPtr8 cfg((TUint8*)&c, 0, sizeof(c));
				r = Kern::ThreadDesRead(iClient, a1, cfg, 0, 0);
				if (r == KErrNone)
					r = SetConfig(c);	//set the new configuration
				}
			break;
			}

		case RBusDevComm::EControlCaps:
			{
			//get capabilities
			TCommCaps2 caps;
			PddCaps(caps);	//call ipdd->Caps
			r = Kern::ThreadDesWrite(iClient, a1, caps, 0, KTruncateToMaxLength, iClient);
			break;
			}

		case RBusDevComm::EControlSignals:
			{
			r = Signals();
			break;
			}

		case RBusDevComm::EControlSetSignals:
			{
//			if (((TUint)a1)&((TUint)a2))	//can't set and clear at same time
//				{
//				Kern::PanicCurrentThread(_L("D32COMM"), ESetSignalsSetAndClear);
//				}
//			else
				{

				SetSignals((TUint)a1, (TUint)a2);
				}
			break;
			}

		case RBusDevComm::EControlQueryReceiveBuffer:
			r = RxCount();
			break;

		case RBusDevComm::EControlResetBuffers:
			if (AreAnyPending())
				Kern::PanicCurrentThread(_L("D32COMM"), EResetBuffers);
			else
				ResetBuffers(ETrue);
			break;

		case RBusDevComm::EControlReceiveBufferLength:
			r = RxBufferSize();
			break;

		case RBusDevComm::EControlSetReceiveBufferLength:
			if (AreAnyPending())
				Kern::PanicCurrentThread(_L("D32COMM"), ESetReceiveBufferLength);
			else
				r = SetRxBufferSize((TInt)a1);
			break;

		case RBusDevComm::EControlMinTurnaroundTime:
			r = iTurnaroundMicroSeconds;			// used saved value
			break;

		case RBusDevComm::EControlSetMinTurnaroundTime:
				{
				if ((TInt)a1<0)
					a1=(TAny*)0;
				iTurnaroundMicroSeconds = (TUint)a1;			// save this
				TUint newTurnaroundMilliSeconds = (TUint)a1/1000;	// convert to ms
				if(newTurnaroundMilliSeconds != iTurnaroundMinMilliSeconds)
					{
					// POLICY: if a new turnaround time is set before the previous running timer has expired and a
					// write request has been queued, the transmission goes ahead immediately
					TurnaroundClear();
					if(newTurnaroundMilliSeconds > 0)
						{
						r = TurnaroundSet(newTurnaroundMilliSeconds);
						}
					}
				}
			break;

		default:
			r = KErrNotSupported;
			}
		return(r);
		}
Beispiel #19
0
int HandlerInPack6( const void *buf, unsigned len )
{
   struct packet56 *pack;
   struct sostrts *srts;
   struct errusoi *ko;
   struct sac *s, *f27;
   struct f18_dmv *f18;
   struct form199_dmv *f199;
   unsigned sa, sp , sr , sv , sn , n , i , j , j1 , ii;
   char b[sizeof(struct form199_dmv)];
	unsigned char *buff;
	unsigned short cksum_in=0,cksum_calc=0;

   if( verbose > 1 ) {
      printf( "HandlerInPack6(%d):", len );
      for( i = 0; i < len; i++ ) printf( " %02x", *( (char *)buf + i ) );
      printf( "\n" ); 
   }

   pack = (struct packet56 *)buf;
   srts = (struct sostrts *)&outpack0.word_sost_rts_1;
   ko = (struct errusoi *)&outpack0.k_o;

   switch( pack->head.code ) {
   case 0x41:
      if( verbose > 0 ) printf( "R999: Output abort (41)!\n" );
      break;
   case 0x90:
      outpack0.link = KRK_DATA_OK;
      n = pack->data[0];
      if( n == 0 ) n = 256;
      s =   (struct sac *)&pack->data[1];  
      sa = s->a0 + s->a1 * 10 + s->a2 * 100 + s->a3 * 1000 + s->a4 * 10000 + 
         s->a5 * 100000;
      sp = s->p0 + s->p1 * 10 + s->p2 * 100 + s->p3 * 1000 + s->p4 * 10000 + 
         s->p5 * 100000;
      sr = s->r0 + s->r1 * 10 + s->r2 * 100 + s->r3 * 1000;
      sv = s->v0 + s->v1 * 10 + s->v2 * 100 + s->v3 * 1000;
      sn = *(short *)( (char *)s + sizeof(struct sac) );
      if( verbose > 0 ) {
         printf( "R999(%d): SAC f=%d k=%d a=%d p=%d r=%d v=%d n=%d.\n",  n, s->nf, s->kvi, sa, sp, sr, sv, sn );
        // printf( "R999: MODE recv=%d addr=%d sa=%d .\n",  mode.recv3, mode.addr3, sa );
      }
		//бортовой номер
	    mode.a0 = s->p0;		mode.a1 = s->p1;
		mode.a2 = s->p2;		mode.a3 = s->p3;
		mode.a4 = s->p4;		mode.a5 = s->p5;
		mode.p0 = s->a0;		mode.p1 = s->a1;
		mode.p2 = s->a2;		mode.p3 = s->a3;
		mode.p4 = s->a4;		mode.p5 = s->a5;
		
      if( ( sa != mode.addr3 ) || !mode.recv3 ) { if( verbose > 0 ) printf( "R999: Ignore packet.\n" );  break;  }
      if( s->nf == 18 ) {
         if( s->kvi == 10 ) { //формюл¤ры ÷”2
			f18 = (struct f18_dmv *)&pack->data[1];
            for( ii = 0; ii < f18->nform; ii++ ) 	
			{
				//--------------------------- проверка контрольной суммы -------------------
				buff = (unsigned char *) &f18->form[ii];
				cksum_calc=crc16(buff, sizeof(struct formrls)-2);
				if (cksum_calc!=f18->form[ii].cksum) 
				{
					outpack0.link = KRK_CKSUM_ERR;
					printf("KRK_CKSUM_ERR (form%d) in=%04x calc=%04x\n",ii,f18->form[ii].cksum,cksum_calc);
				}
				outpack0.r999_cu2.form[ii] = f18->form[ii];
			}
			if (outpack0.link == KRK_CKSUM_ERR) break;
			outpack0.r999_cu2.s = f18->s; //копируем —ј„
            if( f18->nform > 3 ) f18->nform = 3;
            outpack0.r999_cu2.nform = f18->nform; //кол-во формул¤ров
			printf("nform=%d to Danya\n",outpack0.r999_cu2.nform);
            outpack0.r999.cr++;
			if( !mode.mo1a && mode.mn1 ) outpack0.link = KRK_DATA_AND_TRANS;
			else
			{
				f27 = (struct sac *)b;
				memset( f27, 0, sizeof(struct sac) );
				f27->ps = 1;
				f27->vr = 0;
				f27->kvi = 2;
				f27->nf = 27;
				f27->r0 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) % 10;
				f27->r1 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) / 10;
				f27->r2 = ( ( count.out6 / 10000 ) % 1000 ) / 100;
				f27->r3 = ( count.out6 / 10000 ) / 1000;
				f27->v0 = f27->v1 = f27->v2 = f27->v3 = 0;
				f27->a0 = s->p0;//бортовой номер
				f27->a1 = s->p1;
				f27->a2 = s->p2;
				f27->a3 = s->p3;
				f27->a4 = s->p4;
				f27->a5 = s->p5;
				f27->p0 = s->a0;
				f27->p1 = s->a1;
				f27->p2 = s->a2;
				f27->p3 = s->a3;
				f27->p4 = s->a4;
				f27->p5 = s->a5;
				WriteC2( f27, sizeof(struct sac) );
				count.out6++;
			}
         }
		 if( s->kvi == 15 ) {
		    printf("SMS in\n");
			
            memcpy( &outpack0.r999_sms.sach18[0], s, sizeof (struct sac) );
			outpack0.r999_sms.nword=40;
            memcpy( &outpack0.r999_sms.sms[0], (char *)s + sizeof(struct sac) + sizeof(short) , 80 );
			
			buff = (unsigned char *) &outpack0.r999_sms.sms[0]; //проверка контрольной суммы
			 memcpy( &cksum_in, (char *)s + sizeof(struct sac) + sizeof(short) + 80, 2 );
			 cksum_calc=crc16(buff, 80);
			if (cksum_in!=cksum_calc) 
			{
				outpack0.link = KRK_CKSUM_ERR;
				printf("KRK_CKSUM_ERR (sms) in=%04x calc=%04x\n",cksum_in,cksum_calc);
				break;
			}
			
			//printf("SMS:  "); for(j=0;j<102;j++) printf("%02x ",pack->data[j]);printf("\n");
			
			for(j=0;j<5;j++) 
			{
				for(j1=0;j1<16;j1++) in_aes[j1]=outpack0.r999_sms.sms[j1+j*16];
				InvCipher();
				for(j1=0;j1<16;j1++) outpack0.r999_sms.sms[j1+j*16]=out_aes[j1];		
			}

            outpack0.r999.cr++;
			if( !mode.mo1a && mode.mn1 ) outpack0.link = KRK_DATA_AND_TRANS;
			else
			{
				f27 = (struct sac *)b;
				memset( f27, 0, sizeof(struct sac) );
				f27->ps = 1;
				f27->vr = 0;
				f27->kvi = 15;
				f27->nf = 27;
				f27->r0 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) % 10;
				f27->r1 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) / 10;
				f27->r2 = ( ( count.out6 / 10000 ) % 1000 ) / 100;
				f27->r3 = ( count.out6 / 10000 ) / 1000;
				f27->v0 = f27->v1 = f27->v2 = f27->v3 = 0;
				f27->a0 = s->p0;//бортовой номер
				f27->a1 = s->p1;
				f27->a2 = s->p2;
				f27->a3 = s->p3;
				f27->a4 = s->p4;
				f27->a5 = s->p5;
				f27->p0 = s->a0;
				f27->p1 = s->a1;
				f27->p2 = s->a2;
				f27->p3 = s->a3;
				f27->p4 = s->a4;
				f27->p5 = s->a5;
				WriteC2( f27, sizeof(struct sac) );
				count.out6++;
			}
         }
		 else {
            memcpy( &outpack0.r999.sach18, s, sizeof(struct sac) );
//            if( sn > 121 ) sn = 121;
            if( sn > 103 ) sn = 103;
            outpack0.r999.nword = sn;
            memcpy( outpack0.r999.word, (char *)s + 
               sizeof(struct sac) + sizeof(short), sn * 2 );
            outpack0.r999.cr++;
         }
         SendOutPack0();
         ControlLed5( 1 );
      }
      if( s->nf == 26 ) {
		if( !mode.mo1a && mode.mn1 ) outpack0.link = KRK_SWITCH_TRANS;
		else
		{
			outpack0.link = KRK_LINK_OK;
			f27 = (struct sac *)b;
			memset( f27, 0, sizeof(struct sac) );
			f27->ps = 1;
			f27->vr = 0;
			f27->kvi = 2;
			f27->nf = 27;
			f27->r0 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) % 10;
			f27->r1 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) / 10;
			f27->r2 = ( ( count.out6 / 10000 ) % 1000 ) / 100;
			f27->r3 = ( count.out6 / 10000 ) / 1000;
			f27->v0 = f27->v1 = f27->v2 = f27->v3 = 0;
			f27->a0 = s->p0;
			f27->a1 = s->p1;
			f27->a2 = s->p2;
			f27->a3 = s->p3;
			f27->a4 = s->p4;
			f27->a5 = s->p5;
			f27->p0 = s->a0;
			f27->p1 = s->a1;
			f27->p2 = s->a2;
			f27->p3 = s->a3;
			f27->p4 = s->a4;
			f27->p5 = s->a5;
			WriteC2( f27, sizeof(struct sac) );
			count.out6++;
		}
      }
      if( s->nf == 27 ) {
		if( s->kvi == 15 ) {outpack0.link = KRK_SMS_OK;}//printf("SMS OK\n\n");}
		else outpack0.link = KRK_LINK_OK;
         if( stat.link ) {
            ResetBuffers();
            outpack0.cr_com++;
         }
      }
      if( s->nf == 193 ) {
         f199 = (struct form199_dmv *)b;
         memset( f199, 0, sizeof(struct form199_dmv) );
         memcpy( f199, s, sizeof(struct form193) );
         f199->s.ps = 1;
         f199->s.vr = 0;
         f199->s.kvi = 2;
         f199->s.nf = 199;
         f199->s.r0 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) % 10;
         f199->s.r1 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) / 10;
         f199->s.r2 = ( ( count.out6 / 10000 ) % 1000 ) / 100;
         f199->s.r3 = ( count.out6 / 10000 ) / 1000;
         f199->s.v0 = f199->s.v1 = f199->s.v2 = f199->s.v3 = 0;
         f199->s.a0 = s->p0;
         f199->s.a1 = s->p1;
         f199->s.a2 = s->p2;
         f199->s.a3 = s->p3;
         f199->s.a4 = s->p4;
         f199->s.a5 = s->p5;
         f199->s.p0 = s->a0;
         f199->s.p1 = s->a1;
         f199->s.p2 = s->a2;
         f199->s.p3 = s->a3;
         f199->s.p4 = s->a4;
         f199->s.p5 = s->a5;
         WriteC2( f199, sizeof(struct form199_dmv) );
         count.out6++;
      }
      if( s->nf == 199 ) {
         f199 = (struct form199_dmv *)s;
         switch(f199->kfs) {
         case 34:
         case 39:
            outpack0.link = KRK_MODE_REO;
            break;
         default:
            outpack0.link = KRK_CMD_OK;
            break;
         }
         if( stat.link ) {
            ResetBuffers();
            outpack0.cr_com++;
         }
      }
      if( s->nf == 203 ) {
         f199 = (struct form199_dmv *)b;
         memset( f199, 0, sizeof(struct form199_dmv) );
         f199->s.ps = 1;
         f199->s.vr = 0;
         f199->s.kvi = 2;
         f199->s.nf = 199;
         f199->s.r0 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) % 10;
         f199->s.r1 = ( ( ( count.out6 / 10000 ) % 1000 ) % 100 ) / 10;
         f199->s.r2 = ( ( count.out6 / 10000 ) % 1000 ) / 100;
         f199->s.r3 = ( count.out6 / 10000 ) / 1000;
         f199->s.v0 = f199->s.v1 = f199->s.v2 = f199->s.v3 = 0;
         f199->s.a0 = s->p0;
         f199->s.a1 = s->p1;
         f199->s.a2 = s->p2;
         f199->s.a3 = s->p3;
         f199->s.a4 = s->p4;
         f199->s.a5 = s->p5;
         f199->s.p0 = s->a0;
         f199->s.p1 = s->a1;
         f199->s.p2 = s->a2;
         f199->s.p3 = s->a3;
         f199->s.p4 = s->a4;
         f199->s.p5 = s->a5;
         f199->t1 = 0x00;
         f199->t2 = 0x1d;
         f199->kfs = 34;
         WriteC2( f199, sizeof(struct form199_dmv) );
         count.out6++;
      }
      break;
   case 0xf0:
      if( verbose > 1 ) {
         printf( "R999: Input flag (F0).\n" );
      }
      ReadStC2();
      break;
   case 0xf1:
      if( verbose > 0 ) {
         printf( "R999: Input overload (F1)!\n" );
      }
      ReadStC2();
      break;
   default:
      break;
   }

   if( srts->svc1 || srts->svc2 || srts->dmv || srts->usoi ) {
      srts->rts = 1;
   } else {
      srts->rts = 0;
   }

   return( 0 );
}
Beispiel #20
0
/* WIN32 MOD, CopyFile is a win32 API!*/
INT lz_CopyFile(INT doshSource, INT doshDest, PLZINFO pLZI)
{
   DWORD ucbRead, ucbWritten;

   // !!! Assumes pLZI parm is valid.  No sanity check (should be done above in caller).

   // Rewind input file again.
   if (FSEEK(doshSource, 0L, SEEK_SET) != 0L) {
      return(LZERROR_BADINHANDLE);
   }

   // Rewind output file.
   if (doshDest != NO_DOSH &&
       FSEEK(doshDest, 0L, SEEK_SET) != 0L) {
      return( LZERROR_BADOUTHANDLE );
   }

   // Set up a fresh buffer state.
   ResetBuffers();

   while ((ucbRead = FREAD(doshSource, pLZI->rgbyteInBuf, pLZI->ucbInBufLen)) > 0U &&
#ifdef LZA_DLL
           ucbRead != (DWORD)(-1))
#else
           FERROR() == 0)
#endif
   {
      if ((ucbWritten = FWRITE(doshDest, pLZI->rgbyteInBuf, ucbRead)) != ucbRead)
#ifdef LZA_DLL
         if (ucbWritten != (DWORD)(-1)) {
#else
         if (FERROR() != 0) {
#endif
            return(LZERROR_BADOUTHANDLE);
         }
         else {
            return(LZERROR_WRITE);
         }

      pLZI->cblOutSize += ucbWritten;

      if (ucbRead != pLZI->ucbInBufLen)
         break;
   }

#ifdef LZA_DLL
   // here, ucbRead ==  0,    EOF (proper loop termination)
   //               == -1,    bad DOS handle
   if (ucbRead == (DWORD)(-1)) {
#else
   // here, FERROR() == 0U,   EOF (proper loop termination)
   //                != 0U,   bad DOS handle
   if (FERROR() != 0U) {
#endif
      return(LZERROR_BADINHANDLE);
   }

   // Copy successful - return number of bytes copied.
   return(TRUE);
}


/*
** int ExpandOrCopyFile(int doshDource, int doshDest);
**
** Expands one file to another.
**
** Arguments:  doshSource - source DOS file handle
**             doshDest   - destination DOS file handle
**
** Returns:    int - TRUE if expansion finished successfully.  One of the
**                   LZERROR_ codes if not.
**
** Globals:    none
*/
INT ExpandOrCopyFile(INT doshSource, INT doshDest, PLZINFO pLZI)
{
   INT f;
   FH FHInfo;                 // compressed header info struct
   BOOL bExpandingFile;

   // !!! Assumes pLZI parm is valid.  No sanity check (should be done above in caller).

   // Get compressed file header.
   if (GetHdr(&FHInfo, doshSource, &pLZI->cblInSize) != TRUE
       && pLZI->cblInSize >= (LONG)HEADER_LEN)
      // read error occurred
      return(LZERROR_BADINHANDLE);

   // Expand or copy input file to output file.
   bExpandingFile = (IsCompressed(& FHInfo) == TRUE);

   if (bExpandingFile)
   {
      switch (FHInfo.byteAlgorithm)
      {
         case ALG_FIRST:
            f = LZDecode(doshSource, doshDest, (LONG)FHInfo.cbulUncompSize - 1L,
               TRUE, TRUE, pLZI);
            break;

#if 0
         case ALG_LZ:
            f = LZDecode(doshSource, doshDest, (LONG)FHInfo.cbulUncompSize - 1L,
               TRUE, FALSE, pLZI);
            break;
#endif

         default:
            f = LZERROR_UNKNOWNALG;
            break;
      }
   }
   else
      f = lz_CopyFile(doshSource, doshDest, pLZI);

   if (f != TRUE)
      return(f);

   // Flush output buffer to file.
   if ((f = FlushOutputBuffer(doshDest, pLZI)) != TRUE)
      return(f);

   // Copy date and time stamp from source file to destination file.
   if ((f = CopyDateTimeStamp(doshSource, doshDest)) != TRUE)
      return(f);

   // Did we expand the exact number of bytes we expected to from the
   // compressed file header entry?
   if (bExpandingFile &&
       (DWORD)pLZI->cblOutSize != FHInfo.cbulUncompSize)
      return(LZERROR_READ);

   // Expansion / copying finished successfully.
   return(TRUE);
}


/*
** int Expand(char ARG_PTR *pszSource, char ARG_PTR *pszDest, BOOL bDoRename);
**
** Expands one file to another.
**
** Arguments:  pszSource - name of file to compress
**             pszDest   - name of compressed output file
**             bDoRename - flag for output file renaming
**
** Returns:    int - TRUE if expansion finished successfully.  One of the
**                   LZERROR_ codes if not.
**
** Globals:    none
*/
INT Expand(
   NOTIFYPROC pfnNotify,
   CHAR ARG_PTR *pszSource,
   CHAR ARG_PTR *pszDest,
   BOOL bDoRename,
   PLZINFO pLZI)
{
   INT doshSource,            // input file handle
       doshDest,              // output file handle
       f;
   FH FHInfo;                 // compressed header info struct
   CHAR szDestFileName[MAX_PATH];

   // Sanity check
   if (!pLZI) {
      return(LZERROR_GLOBLOCK);
   }

   // Set up input file handle. Set cblInSize to length of input file.
   if ((f = GetIOHandle(pszSource, READ_IT, & doshSource, &pLZI->cblInSize)) != TRUE)
      return(f);

   if (GetHdr(&FHInfo, doshSource, &pLZI->cblInSize) != TRUE &&
       pLZI->cblInSize >= (LONG)HEADER_LEN)
   {
      // Read error occurred.
      FCLOSE(doshSource);
      return(LZERROR_BADINHANDLE);
   }

   // Create destination file name.

   STRCPY(szDestFileName, pszDest);

#if 0
   if (bDoRename == TRUE && FHInfo.byteAlgorithm != ALG_FIRST)
#else
   if (bDoRename == TRUE)
#endif
   {
      // Rename output file using expanded file name extension character
      // stored in compressed file header.
      MakeExpandedName(szDestFileName, FHInfo.byteExtensionChar);
   }

   // Ask if we should compress this file.
   if (! (*pfnNotify)(pszSource, szDestFileName, (WORD)
                      (IsCompressed(&FHInfo) ?  NOTIFY_START_EXPAND : NOTIFY_START_COPY)))
   {
      // Don't expand / copy file.  This error condition should be handled in
      // pfnNotify, so indicate that it is not necessary for the caller to
      // display an error message.
      FCLOSE(doshSource);
      return(BLANK_ERROR);
   }

   // Set up output file handle.
   if ((f = GetIOHandle(szDestFileName, WRITE_IT, & doshDest, &pLZI->cblInSize)) != TRUE)
   {
      FCLOSE(doshSource);
      return(f);
   }

   // Expand or copy input file into output file.
   f = ExpandOrCopyFile(doshSource, doshDest, pLZI);

   // Close files.
   FCLOSE(doshSource);
   FCLOSE(doshDest);

   return(f);
}
Beispiel #21
0
/*
 * New media loaded.  Check if data in buffers
 * is validate and can be reused.
 */
static void
checkBuffers(
	char *new_vsn)
{
	u_longlong_t currentPos;

	/* If first request for this thread, allocate buffers. */
	if (IoThread->io_numBuffers == 0) {
		allocBuffers();
		strcpy(Instance->ci_vsn, new_vsn);
		return;
	}

	/* If disk archiving, invalidate buffers. */
	if (IoThread->io_flags & IO_diskArchiving) {
		ResetBuffers();
		IoThread->io_position = 0;
		strcpy(Instance->ci_vsn, new_vsn);
		return;
	}

	/* Get current position of removable media file. */
	currentPos = GetPosition();

	Trace(TR_FILES, "Get position %lld block size %d",
	    currentPos, GetBlockSize());

	/*
	 * If we loaded the same VSN as last time this proc was
	 * active, the buffers may be valid and thus data in the buffers
	 * can be reused.  If this is not the same VSN, invalidate
	 * the buffers and save VSN label in the thread's context.
	 */
	if (strcmp(Instance->ci_vsn, new_vsn) != 0) {
		int blockSize;

		/*
		 * New media.  If block size has changed set new mau
		 * information.  If necessary, reallocate buffers based
		 * on the new block size.
		 */
		blockSize = GetBlockSize();
		if (IoThread->io_blockSize != blockSize) {
			freeBuffers();
			allocBuffers();
		} else {
			ResetBuffers();
		}

		strcpy(Instance->ci_vsn, new_vsn);

	} else if (IoThread->io_position != currentPos) {

		/*
		 * The last known media position does not match the
		 * removable media file's position.  Since the position has
		 * changed, buffers must be invalidated.
		 */
		ResetBuffers();

	}

	/*
	 * Archive read thread needs mount position to maintain
	 * position on the media.
	 */
	IoThread->io_position = currentPos;
}