Пример #1
0
static void parseTX(
    const uint8_t *&p
)
{
    uint8_t *txHash = 0;
    const uint8_t *txStart = p;

    if(gNeedTXHash && !skip) {
        const uint8_t *txEnd = p;
        parseTX<true>(txEnd);
        txHash = allocHash256();
        sha256Twice(txHash, txStart, txEnd - txStart);
    }

    if(!skip) startTX(p, txHash);

        SKIP(uint32_t, version, p);

        parseInputs<skip>(p, txHash);

        if(gNeedTXHash && !skip)
            gTXMap[txHash] = p;

        parseOutputs<skip, false>(p, txHash);

        SKIP(uint32_t, lockTime, p);

    if(!skip) endTX(p);
}
Пример #2
0
void sendFrame(uint8_t ch, Mod_Master_Frame_TypeDef* aframe)
{
	if (ch != 2) return;
	
	aframe->respOK = FALSE;
	
	setTimeoutCheck(MOD_TIMER_STOP);
	setFrameCheck(MOD_TIMER_STOP);
	stopUART();
	
	aframe->request = FALSE;
	aframe->txCursor = 0;
	aframe->txOK = FALSE;



	
	aframe->modState = Mod_State_Sending;
	//for (ch = 0; ch < 100; ch ++)
	
	startTX();
	UART2_SendData8(aframe->txframe[0]);
	UART2_TIEN = TRUE;
	
	return;
}
static bool writePacket(Client* c, uint8_t command, uint8_t* payload, uint8_t pLength)
{
	c->workBuffer[0] = pLength + 5;
	c->workBuffer[1] = command;
	if (payload != NULL)
	{
		for (uint8_t i = 2; i < pLength + 2; i++)
		{
			c->workBuffer[i] = payload[i - 2];
		}
	}
	uint32_t crcCode = HAL_CRC_Calculate(c->peripheral_CRC, (uint32_t*)(c->workBuffer), pLength + 2);
	crcCode ^= 0xffffffff;
	c->workBuffer[pLength + 2] = crcCode & 0x000000FF;
	c->workBuffer[pLength + 3] = (crcCode & 0x0000FF00) >> 8;
	c->workBuffer[pLength + 4] = (crcCode & 0x00FF0000) >> 16;
	c->workBuffer[pLength + 5] = (crcCode & 0xFF000000) >> 24;

	// see if packet will fit in transmit buffer
	if ((int)(pLength) + 6 > 256 - c->txBuf.available(&c->txBuf))
	{
		return false;
	}

	// write packet into tx buffer
	for (int i = 0; i < pLength + 6; i++)
	{
		c->txBuf.Buf[c->txBuf.pT++] = c->workBuffer[i];
	}
	c->txBuf.isFull = (c->txBuf.pT == c->txBuf.pH);

	startTX(c, false, true, false);

	return true;
}
Пример #4
0
void main(void)
{
  char pinStatus = 0, TXon = 0, boxOpen = 0;
  long int runTime = 0;             //
  
   /* device setup */
  set32MHzXOSC();
  timerSetup(TICKS_FREQ025, T1_PRE);     
  timer4Setup(T4_PRE); 
//  CSPT = 0xFF;
//  PICTL |= BIT7;
  
  P0DIR |= 0x8C;                        //P0 BIT2,3,7 are output, BIT1,4,5,6 are input
  if (P0 & BOX) P0 = RED_LED;
  else P0 = GREEN_LED;

  /* interrupt setup */
   setT1int();             //TIMER1 interrupts
   setT4int();             //TIMER4 interrupts
  //void setP0int();       //Port 0 interrupts
  
  while(P0 & BOX);              //wait for box to close before reading setup parameters
  T1_ovf_cnt = 0;               //restart transmitting period after closing the box
  pinStatus = readPin();
  setupTX(pinStatus);
  
  IEN0 |= BIT7;                                 //enable global interrupts.
  T1CTL |= BIT0;                                //start timer1 in free running mode
  
  if (pinStatus == 0x02) runTime = 322;         //total run time is approx. 3 hours
  else runTime = 18;                            //total run time is approx. 10 minutes
  
  while(T1_ovf_cnt < runTime)       //stop program after XXX hours
  {
    while(!(P0 & BOX) && T1_ovf_cnt < runTime)     //Box is closed 
    {
      if (!TXon)
      {
        if (pinStatus == 0x22) freqSweep(FREQ2395, FREQ2507, 4);
        else startTX();
        TXon = 1;
      }
    }
    stopTX();
    TXon = 0;
//    if (P0 & BOX) boxOpen = 1;
//    else 
//    {
//      while(P0 & BOX);              //wait for box to close before reading setup parameters
//    }
    while (P0 & BOX) boxOpen = 1;
    if (boxOpen == 1) T1_ovf_cnt = 0;               //restart transmitting period after closing the box
    pinStatus = readPin();
    setupTX(pinStatus);
    if (pinStatus == 0x02) runTime = 645;         //total run time is approx. 6 hours
    else runTime = 18;                            //total run time is approx. 10 minutes
    boxOpen = 0;
  }
  stopTX();
}
void tickInterupt(Client* c)
{
	// If we are waiting for an Ack,
	// we need to resend the last publish after timeout
	// TODO: Need to change this to a one time pulse using timer, achieves 1 asynchronous callback.
	if (c->ackOutstanding)
	{
		uint32_t now = HAL_GetTick();
		if (now - c->lastOutAct > 500)
		{
			startTX(c, true, false, false);
		}
	}
}
Пример #6
0
void freqSweep(char startFreq, char endFreq, char deltaFreq)
{
  char freqNo = (endFreq - startFreq)/deltaFreq;        //number of frequency sweep points
  stopTX(); 
  for (char i = 0; (i < freqNo) && !(P0 & BOX); i++)
  {
    rfTXConfig(startFreq, trans_power);     //set TX parameters
    T4CTL |= BIT4;                              //start timer4 operation
    startTX();                                  //start TX
    while (!(P0 & BOX) & T4_ovf_cnt < 15);      //wait 2 seconds for each frequency
    T4CTL &= ~BIT4;                             //pause timer4 operation
    T4_ovf_cnt = 0;
    stopTX();           
    startFreq += deltaFreq;                     //move to next frequency
  }    
}
Пример #7
0
void main(void)
{
  long int runTime = 0;
  char boxOpen = 0;
  
   /* device setup */
  set32MHzXOSC();
  timerSetup(TICKS_FREQ025, T1_PRE);     
  timer4Setup(T4_PRE); 
//  CSPT = 0xFF;
//  PICTL |= BIT7;
  
  P0DIR |= 0x8C;                        //P0 BIT2,3,7 are output, BIT1,4,5,6 are input
//  if (P0 & BOX) P0 = RED_LED;
//  else P0 = GREEN_LED;

  /* interrupt setup */
   setT1int();             //TIMER1 interrupts
   setT4int();             //TIMER4 interrupts
//   setP0int();       //Port 0 interrupts
  
//  while(P0 & BOX);              //wait for box to close before reading setup parameters
  T1_ovf_cnt = 0;               //restart transmitting period after closing the box
  TXFreq = FREQ2400;
  
  IEN0 |= BIT7;                                 //enable global interrupts.
  T1CTL |= BIT0;                                //start timer1 in free running mode
  
  runTime = 9;
  rfTXConfig(FREQ2455, OUTPUT_POWER);
  startTX();
  while(T1_ovf_cnt < runTime)       //stop program after 'runTime' no. of T1 overflow.
  {
    while ((P0 & BOX) && (T1_ovf_cnt < runTime));
    stopTX();      
    while (P0 & BOX) boxOpen = 1;
    if (boxOpen == 1) T1_ovf_cnt = 0;               //restart transmitting period after closing the box
    
    runTime = 9;                  //total run time is approx. 10 minutes
    boxOpen = 0;
  }

  stopTX();
}
static void rxHandlePacket(Client* c, uint8_t* packetStart)
{
	bool rxSeqFlag = (packetStart[1] & 0x80) > 0;
	switch (packetStart[1] & 0x7F)
	{
	// Connection established with destination
	case PROTOCOL_CONNACK:
		if (packetStart[0] == 5)
		{
			c->state = STATE_CONNECTED;
		}
		break;
	// Incoming data
	case PROTOCOL_PUBLISH:
		writePacket(c, PROTOCOL_ACK | (packetStart[1] & 0x80), NULL, 0);
		if (rxSeqFlag == c->expectedRxSeqFlag)
		{
			c->expectedRxSeqFlag = !c->expectedRxSeqFlag;
			if (packetStart[0] > 5)
			{
				for (uint8_t i = 0; i < packetStart[0] - 5; i++)
				{
					c->readBuf.Buf[c->readBuf.pT++] = packetStart[2 + i];
				}
				c->readBuf.isFull = (c->readBuf.pH == c->readBuf.pT);
			}
		}
		break;
	// Protocol Acknowledge
	case PROTOCOL_ACK:
		if (c->ackOutstanding)
		{
			if (rxSeqFlag == c->expectedAckSeq)
			{
				c->ackOutstanding = false;
				startTX(c, false, false, true);
			}
		}
		break;
	}
}
// Callback hook ups
void uartTxCompleteCallback(Client* c)
{
	startTX(c, false, false, false);
}
Пример #10
0
static void parseTX(
    const Block   *block,
    const uint8_t *&p
) {
    auto txStart = p;
    uint8_t *txHash = 0;

    if(gNeedTXHash && !skip) {
        auto txEnd = p;
        txHash = allocHash256();
        parseTX<true>(block, txEnd);
        sha256Twice(txHash, txStart, txEnd - txStart);
    }

    if(!skip) {
        startTX(p, txHash);
    }

        #if defined(CLAM)
            LOAD(uint32_t, nVersion, p);
        #else
            SKIP(uint32_t, nVersion, p);
        #endif

        #if defined(PEERCOIN) || defined(CLAM) || defined(JUMBUCKS)
            SKIP(uint32_t, nTime, p);
        #endif

        parseInputs<skip>(block, p, txHash);

        Chunk *txo = 0;
        size_t txoOffset = -1;
        const uint8_t *outputsStart = p;
        if(gNeedTXHash && !skip) {
            txo = Chunk::alloc();
            txoOffset = block->chunk->getOffset() + (p - block->chunk->getData());
            gTXOMap[txHash] = txo;
        }

        parseOutputs<skip, false>(p, txHash);

        if(txo) {
            size_t txoSize = p - outputsStart;
            txo->init(
                block->chunk->getMap(),
                txoSize,
                txoOffset
            );
        }

        SKIP(uint32_t, lockTime, p);

        #if defined(CLAM)
            if(1<nVersion) {
                LOAD_VARINT(strCLAMSpeechLen, p);
                p += strCLAMSpeechLen;
            }
        #endif

    if(!skip) {
        endTX(p);
    }
}