Exemplo n.º 1
0
    Message receive(zmq::socket_t& socket)
    {
      std::vector<std::string> address;
      std::string frame = receiveString(socket);
      // Do we have an address?
      while (frame.compare("") != 0)
      {
        address.push_back(frame);
        frame = receiveString(socket);
      }
      // address is a stack, so reverse it to get the right way around
      std::reverse(address.begin(), address.end());

      // We've just read the delimiter, so now get subject
      auto subjectString = receiveString(socket);
      //the underlying representation is (explicitly) an int so fairly safe
      Subject subject = (Subject)detail::unserialise<std::uint32_t>(subjectString);
      std::vector<std::string> data;
      while (true)
      {
        int isMore = 0;
        size_t moreSize = sizeof(isMore);
        socket.getsockopt(ZMQ_RCVMORE, &isMore, &moreSize);
        if (!isMore)
          break;
        data.push_back(receiveString(socket));
      }
      return Message(address, subject, data);
    }
Exemplo n.º 2
0
inline void receiveStackTrace(MPI_Comm localComm, MPI_Comm globalComm)
{
    int source0 = getProcId(localComm);
    receiveString(source0, localComm, globalComm);
    int source1 = getProcId(localComm) + getProcSize(localComm);
    receiveString(source1, localComm, globalComm);
}
Exemplo n.º 3
0
int WalnutCentral::addDevice(BluetoothDeviceAddress address) {
    char tx[MAX_BUF_SIZE];
    char rx[MAX_BUF_SIZE];
    int rx_len = 0;
  

    String tempStr = "AT+DEVADD=" + address.toString();
    tempStr.toCharArray(tx, MAX_BUF_SIZE);
    #ifdef PRINT_DEBUG_MESSAGES
        Serial.println(tx);
    #endif
    
    int err_code = sendString(tx, strlen(tx));
    if (err_code != 0) {
        return err_code;
    }
  
    err_code = receiveString(rx, &rx_len);
    if (err_code != 0) {
        return err_code;
    }

    if (strcmp(rx, "OK") == 0) {
        return 0;
    } else {
        return 1;
    }
}
Exemplo n.º 4
0
bool Socket::receive(RawMessage & oMessage)
{
	string aType;
	string aPayload;
	string aDest;

	std::string aMessageData;
	bool const aReceived = receiveString(aMessageData);
	if (aReceived)
	{
		size_t aEndDestFlag = aMessageData.find( " ", 0 );
		if (string::npos != aEndDestFlag)
		{
			aDest = aMessageData.substr(0, aEndDestFlag);

			size_t aEndTypeFlag = aMessageData.find(" ", aEndDestFlag + 1);
			if ( aEndTypeFlag != string::npos )
			{
				aType = aMessageData.substr( aEndDestFlag + 1, aEndTypeFlag - aEndDestFlag - 1 );
				aPayload = aMessageData.substr( aEndTypeFlag + 1 );
			}
		}

		oMessage._type = aType;
		oMessage._routingId = aDest;
		oMessage._payload = aPayload;
		ORWELL_LOG_DEBUG("Received message : type=" << aType << "- dest=" << aDest << "-");
	}
	return aReceived;
}
Exemplo n.º 5
0
/**
* Checks and changes state of keyring
*
*/
void updateState(void) {

	unsigned char * command = receiveString(); //Recieve command from serial

	
	//command = command[strlen(command)-1] = 0; // STrips last char fro string (line break (\n))

	if(!strcmp(command, "LOCK")) {

		lock();
		USART_putstring("LOCK!!");

	} else if (!strcmp(command, "UNLOCK") == 1) {


		unlock();
		USART_putstring("UNLOCK!!!!");



	} else {

		USART_putstring("SOMETHING!!!!");



	}



}
Exemplo n.º 6
0
void Client::receiveData(){
       if(type == -1)
           type = readType();
       switch(type){
       case Constants::STRING:
           receiveString();
           break;
       case Constants::IMAGE:
           receiveImage();
           break;
       };
}
Exemplo n.º 7
0
// Object class setting!
Object::Object(int socketDescriptor):socketDescriptor(socketDescriptor)
{
    tcpSocket=new QTcpSocket;
    bytesReceived=0;
    if(!tcpSocket->setSocketDescriptor(socketDescriptor)){
        emit error(tcpSocket->error());
        return;
    }

    qDebug()<<socketDescriptor;
    QObject::connect(tcpSocket,SIGNAL(readyRead()),
                     this,SLOT(receiveString()));
}
Exemplo n.º 8
0
int WalnutCentral::startScan() {
    char tx[MAX_BUF_SIZE];
    char rx[MAX_BUF_SIZE];
    int rx_len = 0;
  
    strcpy(tx, "AT+SCANSTART");
    int err_code = sendString(tx, strlen(tx));
    if (err_code != 0) {
        return err_code;
    }
  
    err_code = receiveString(rx, &rx_len);
    if (err_code != 0) {
        return err_code;
    }

    if (strcmp(rx, "OK") == 0) {
        return 0;
    } else {
        return 1;
    }
}
Exemplo n.º 9
0
int WalnutCentral::getAdvertisingMessage(uint8_t deviceIndex) {
    char tx[MAX_BUF_SIZE] = {0};
    char rx[MAX_BUF_SIZE];
    int rx_len = 0;
  
    sprintf(tx, "AT+ADV=%02d", deviceIndex);
    
    int err_code = sendString(tx, strlen(tx));
    if (err_code != 0) {
        return err_code;
    }
  
    err_code = receiveString(rx, &rx_len);
    if (err_code != 0) {
        return err_code;
    }

    if (strcmp(rx, "OK") == 0) {
        return 0;
    } else {
        return 1;
    }
}
Exemplo n.º 10
0
int WalnutCentral::setScanParameters() {
    char tx[MAX_BUF_SIZE];
    char rx[MAX_BUF_SIZE];
    int rx_len = 0;
  
    strcpy(tx, "AT+SCANSETP=1,0,1760,1680,0");
//    strcpy(tx, "AT+SCANSETP=1,0,A0,50,0");
    int err_code = sendString(tx, strlen(tx));
    if (err_code != 0) {
        return err_code;
    }
  
    err_code = receiveString(rx, &rx_len);
    if (err_code != 0) {
        return err_code;
    }

    if (strcmp(rx, "OK") == 0) {
        return 0;
    } else {
        return 1;
    }
}
Exemplo n.º 11
0
void command_handler(uint8_t command){
	uint16_t wbuf;
	uint8_t bufh, bufl;
	float fbuf;
	char sbuf[10];
	switch(command){

		/* read temperature in human readable form */

		case READ_TEMP:
		sendByte(command);
		fbuf = getTemperature( ADC_read() );
		floatToString(fbuf, sbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* read temperature in raw ADC counts */
		case READ_TEMP_RAW:
		sendByte(command);
		wbuf = ADC_read();
		HexToAscii(sbuf, 4, wbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* set operational voltage @25°C */

		case SET_UBIAS_A:
		// echo the command
		sendByte(command);
		// waiting for a 4 character string
		receiveString(sbuf, 4);
		sendString(EOM);
		// set ADC register to given value
		wbuf = AsciiToHex(sbuf, 4);
		// max 0x7FF
		ADC_REG = 0x7FF & wbuf;
		break;

		/* set the temperature progression coefficient */

		case SET_COEFF:
		// echo...
		sendByte(command);
		// waiting for a 2 character string
		receiveString(sbuf, 2);
		sendString(EOM);
//		Vcoef = AsciiToHex(sbuf, 2);
		// max value = 0x7F
//		Vcoef &= 0x7F;		
		break;

		/* read the calculated adjusted operational voltage */

		case READ_UADJ_A:
		sendByte(command);
		// get temperature
		fbuf = getTemperature( ADC_read() );
		// calculate temperature adjusted voltage
		wbuf = calcAdjustedBiasVoltage(fbuf);
		// create string
		HexToAscii(sbuf, 5, wbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* read temperature coefficient */

		case READ_COEFF:
		sendByte(command);
		sendString(EOM);
		break;

		/* print help */

		case PRINT_HELP:
		sendByte(command);
		sendString("HW Version x.x SW Version 2.0");
		sendString(EOM);
		break;

		/* print sipm info of module */
		case SIPM_INFO:
		sendByte(command);
		sendString(EOM);
		break;
		
		case DAC_CAL:
		sendByte(command);
		sendString(EOM);
		break;
	
		default:
		MPPC_status = ADDRESSED;
	}


}
Exemplo n.º 12
0
int WalnutCentral::begin(Stream &serial, const int rstPin) {
    _serial = &serial;
    _rstPin = rstPin;

    // Release Reset
    digitalWrite(rstPin, 0);
    delay(100);
    digitalWrite(rstPin, 1);
    
    // Wait for boot finished
    delay(1000);
    // TODO: Implement command or character to be received when booting up
    unsigned long startTime = millis();
//    bool timedOut = false;
//    const int RX_BUF_SIZE = 10;
//    char rx[MAX_BUF_SIZE] = {0};
//    int rx_len = 0;
//    uint8_t i = 0;
    char tx[MAX_BUF_SIZE];
    char rx[MAX_BUF_SIZE];
    int rx_len = 0;
    int err_code;

////    while (!_serial->available()) {
//    while (digitalRead(13) == 0) {
//        if (millis() - startTime > 30000) {
////            timedOut = true;
//            return 1;
//        }
//    }
//        
//    while (!_serial->available()) {
//        if (millis() - startTime > 30000) {
////            timedOut = true;
//            return 1;
//        }
//    }
//    int err_code = receiveString(rx, &rx_len);
//    if (err_code != 0) {
//        return err_code;
//    }
////    _serial->setTimeout(1000);
////    rx_len = _serial->readBytesUntil('\n', rx, MAX_BUF_SIZE);
////    if (rx_len > 1) {
////        rx[rx_len-1] = 0;
////        rx_len -= 1;
////    }
//
//    #ifdef PRINT_DEBUG_MESSAGES
//        Serial.print("receiveString: -");
//        Serial.print(rx);
//        Serial.print("- nbrOfBytes: ");
//        Serial.println(rx_len);
//    #endif
//  
//    if ((rx_len == 0) || (strcmp(rx, "B") != 0)) {
//        // Timeout
//        return 1; 
//    }
//
    strcpy(tx, "ATZ");
    err_code = sendString(tx, strlen(tx));
    if (err_code != 0) {
        return err_code;
    }
  
    err_code = receiveString(rx, &rx_len);
    if (err_code != 0) {
        return err_code;
    }
  
    // Check revision
    // TODO: Implement command on Walnut
  
}
Exemplo n.º 13
0
void TubeInterrupt(void) {

  in_isr = 1;

  // Check for R1 interrupt
  if (tubeRead(R1_STATUS) & A_BIT) {
    if (DEBUG) {
      printf("R1 irq\r\n");
    }
    unsigned char flag = tubeRead(R1_DATA);
    if (flag & 0x80) {
      // Escape
      in_isr = 0;
      // The escape handler is called with the escape flag value in R11
      // That's with this wrapper achieves
      _escape_handler_wrapper(flag & 0x40, env->handler[ESCAPE_HANDLER].handler);
    } else {
      // Event
      unsigned char y = receiveByte(R1_ID);
      unsigned char x = receiveByte(R1_ID);
      unsigned char a = receiveByte(R1_ID);
      in_isr = 0;
      env->handler[EVENT_HANDLER].handler(a, x, y);
    }
  }

  // Check for R4 interrupt
  if (tubeRead(R4_STATUS) & A_BIT) {
    if (DEBUG) {
      printf("R4 irq\r\n");
    }
    unsigned char type = tubeRead(R4_DATA);
    if (DEBUG) {
      printf("R4 type = %02x\r\n",type);
    }
    if (type == 0xff) {
      receiveByte(R2_ID); // always 0
      // Build the error block
      ErrorBlock_type *eblk = &isrErrorBlock;
      eblk->errorNum = receiveByte(R2_ID);
      receiveString(R2_ID, 0x00, eblk->errorMsg);
      in_isr = 0;
      // SWI OS_GenerateError need the error block in R0
      OS_GenerateError(eblk);
    } else {
      unsigned char id = receiveByte(R4_ID);
      if (type <= 4 || type == 6 || type == 7) {
        unsigned char a3 = receiveByte(R4_ID);
        unsigned char a2 = receiveByte(R4_ID);
        unsigned char a1 = receiveByte(R4_ID);
        unsigned char a0 = receiveByte(R4_ID);
        address = (unsigned char *)((a3 << 24) + (a2 << 16) + (a1 << 8) + a0);
        if (DEBUG) {
          printf("Transfer = %02x %02x %08x\r\n", type, id, (unsigned int)address);
        }
      } else {
        if (DEBUG) {
          printf("Transfer = %02x %02x\r\n", type, id);
        }
      }
      if (type == 5) {
        // Type 5 : tube release
      } else {
        // Every thing else has a sync byte
        receiveByte(R4_ID);
      }
      // The data transfers are done by polling the GPIO bits for IRQ and NMI
      count = 0;
      signature = 0;
      switch (type) {
      case 0:
        type_0_data_transfer();
        break;
      case 1:
        type_1_data_transfer();
        break;
      case 2:
        type_2_data_transfer();
        break;
      case 3:
        type_3_data_transfer();
        break;
      case 6:
        type_6_data_transfer();
        break;
      case 7:
        type_7_data_transfer();
        break;
      }
      if (DEBUG) {
        printf("count = %0x signature = %0x\r\n", count, signature);
      }
    }
  }
  in_isr = 0;
}