Site icon Renzo Mischianti

How does receiveInitialMessage return uint8_t?

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;
}
Exit mobile version