Пример #1
0
void FHE_Params::set(const Ring& R,
                     const vector<bigint>& primes,double r,int hwt)
{
  if (primes.size() != FFTData.size())
    throw runtime_error("wrong number of primes");

  for (size_t i = 0; i < FFTData.size(); i++)
    FFTData[i].init(R,primes[i]);

  Chi.set(R.phi_m(),hwt,r);

  set_sec(40);
}
Пример #2
0
/* Make a new message with a packet
 * Initialize data structures and make a new message with given packet,
 * whose header and data fields are given as parameters.
 * The message is composed of a header entry with meta data about message,
 * doubly linked list of multiple directory entries, and data pages.
 * This method creates as many directory entries as needed.
 */
_condorInMsg::_condorInMsg(const _condorMsgID mID,// the id of this message
				const bool last,		// the packet is last or not
				const int seq,		// seq. # of the packet
				const int len,		// length of the packet
				const void* data,		// data of the packet
                const char * MD5Keyid,  // MD5 key id
                const unsigned char * md,  // MD5 key id
                const char * EncKeyId,
				_condorInMsg* prev)	// pointer to previous message
								// in the bucket chain
{
	int destDirNo;
	int index;

	// initialize message id
	msgID.ip_addr = mID.ip_addr;
	msgID.pid = mID.pid;
	msgID.time = mID.time;
	msgID.msgNo = mID.msgNo;
   
	// initialize other data structures
	msgLen = len;
	lastNo = (last) ? seq : 0;
	received = 1;
	lastTime = time(NULL);
	passed = 0;
	curData = 0;
	curPacket = 0;

	// make directory entries as needed
	headDir = curDir = new _condorDirPage(NULL, 0);
	if(!curDir) {
		EXCEPT( "::InMsg, new DirPage failed. out of mem" );
	}
	destDirNo = seq / SAFE_MSG_NO_OF_DIR_ENTRY;
	while(curDir->dirNo != destDirNo) {
		curDir->nextDir = new _condorDirPage(curDir, curDir->dirNo + 1);
		if(!curDir->nextDir) {
		    EXCEPT("::InMsg, new DirPage failed. out of mem");
		}
		curDir = curDir->nextDir;
	}

	// make a packet and add to the appropriate directory entry
	index = seq % SAFE_MSG_NO_OF_DIR_ENTRY;
	curDir->dEntry[index].dLen = len;
	curDir->dEntry[index].dGram = (char *)malloc(len);
	if(!curDir->dEntry[index].dGram) {
		EXCEPT( "::InMsg, new char[%d] failed. out of mem", len );
	}
	memcpy(curDir->dEntry[index].dGram, data, len);

	// initialize temporary buffer to NULL
	tempBuf = NULL;
	tempBufLen = 0;

	prevMsg = prev;
	nextMsg = NULL;

    set_sec(MD5Keyid, md, EncKeyId);
}
Пример #3
0
int main(void)
{
    InitAll();
    InitRelayPins();

    BSP_LED_On(LED_GREEN);
    BSP_LED_On(LED_BLUE);

    BSP_LCD_GLASS_DisplayString((uint8_t*)"READY");

    // RIGHT:       00 - 27 min: blue led on, relay 1 on
    // RIGHT_OVERLAP: 28 - 29 min: same + green flashing
    // LEFT:        30 - 57 min:  green led on, relay 2 on
    // LEFT_OVERLAP:  58 - 59 min:  same + blue flashing
    // BOTH_OFF:    both relays off, both LEDs off, counters not active
    // BOTH_ON:     both relays on, both LEDs on, counters not active
    
    // USER press: BOTH_OFF
    // left button: jump to state LEFT
    // right button: jump to state RIGHT
    // left + right button: jump to state BOTH_ON
 
    const int TIME_OVERLAP = 2 * 60;
    const int TIME_RIGHT = 30 * 60 - TIME_OVERLAP;
    const int TIME_LEFT = 15 * 60 - TIME_OVERLAP;
        
    while (1)
    {
      switch(state) {
        case RESET_STATE:
          green_off();
          blue_off();
          relay_1_off();
          relay_2_off();
          relay_3_off();
          relay_4_off();
          set_sec(0);
          
          state = RIGHT;
          break;
        
        case RIGHT:
          if (prev_state != RIGHT) {
            prev_state = RIGHT;
            blue_on();
            green_off();
            relay_1_off();
            relay_2_on();
            set_sec(TIME_RIGHT);
          }
          if (!sec) {
            state = RIGHT_OVERLAP;
          }
          break;

        case RIGHT_OVERLAP:
          if (prev_state != RIGHT_OVERLAP) {
            prev_state = RIGHT_OVERLAP; 
            blue_on();
            relay_1_on();
            relay_2_on();
            set_sec(TIME_OVERLAP);
          }
          if (sec & 1) {
            green_on();
          }
          else {
            green_off();            
          }
          if (!sec) {
            state = LEFT;
          }
          break;

        case LEFT:
          if (prev_state != LEFT) {
            prev_state = LEFT;
            green_on();
            blue_off();
            relay_1_on();
            relay_2_off();
            set_sec(TIME_LEFT);
          }
          if (!sec) {
            state = LEFT_OVERLAP;
          }
          break;

        case LEFT_OVERLAP:
          if (prev_state != LEFT_OVERLAP) {
            prev_state = LEFT_OVERLAP;
            green_on();
            relay_1_on();
            relay_2_on();
            set_sec(TIME_OVERLAP);
          }
          if (sec & 1) {
            blue_on();
          }
          else {
            blue_off();            
          }
          if (!sec) {
            state = RIGHT;
          }
          break;

        case BOTH_OFF:
          if (prev_state != BOTH_OFF) {
            green_off();
            blue_off();
            relay_1_off();
            relay_2_off();            
            set_sec(0);
          }
          break;

        case BOTH_ON:
          if (prev_state != BOTH_ON) {
            green_on();
            blue_on();
            relay_1_on();
            relay_2_on();
            set_sec(0);
          }
          break;
      }

      // Read touch buttons
      int buttonId = getTouchButtons();

      // LEFT button
      if (buttonId == 0) {
        prev_state = RESET_STATE;
        state = LEFT;
      }

      // RIGHT button
      if (buttonId == 3) {
        prev_state = RESET_STATE;
        state = RIGHT;
      }
    }

  // Will never get here.
  return 0;
}