How does receiveInitialMessage return uint8_t?

Home Forums The libraries hosted on the site EByte LoRa e220 UART devices LLCC68 How does receiveInitialMessage return uint8_t?

Viewing 1 reply thread
  • Author
    Posts
    • #25727
      george_santiago
      Participant

        Hi Renzo

        The LoRa_E220::receiveInitialMessage function returns a char value, but I would like the returned value to be uint8_t.
        I’m identifying my messages by number:

        struct msg_01 {
        	uint8_t type;
        	char message[8];
        	byte temperature[4];
        };
        
        struct msg_02 {
        	uint8_t type;
        	char txt[10];
        	byte distance[4];
                bool ack;
        };

        So instead of using a String as in the provided example:

        	char type[5]; // first part of structure
        	ResponseContainer rs = e220ttl.receiveInitialMessage(sizeof(type));
        	String typeStr = rs.data;

        I would use a uint8_t like this:

        	uint8_t type; // first part of structure
        	ResponseContainer rs = e220ttl.receiveInitialMessage(sizeof(type));
        	uint8_t typeStr = rs.data;

        If I change char buff[size]; (line 131 in ‘LoRa_E220.cpp’) to uint8_t buff[size];, with the aim that LoRa_E220::receiveInitialMessage returns a uint8_t would this change cause a bug?

        ResponseContainer LoRa_E220::receiveInitialMessage(uint8_t size){
        	ResponseContainer rc;
        	rc.status.code = E220_SUCCESS;
        	char buff[size];
        	uint8_t len = this->serialDef.stream->readBytes(buff, size);
        	if (len!=size) {
        		if (len==0){
        			rc.status.code = ERR_E220_NO_RESPONSE_FROM_DEVICE;
        		}else{
        			rc.status.code = ERR_E220_DATA_SIZE_NOT_MATCH;
        		}
        		return rc;
        	}
        
        	rc.data = buff; // malloc(sizeof (moduleInformation));
        
        	return rc;
        }
      • #25745
        Renzo Mischianti
        Keymaster

          Hi George,
          It seems that It’s ok.
          You can also use a byte or char as a number.
          Bye Renzo

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.
      Exit mobile version