|
@@ -25,7 +25,6 @@
|
|
* @note The packetType, payloadLength and payload have to be preset!
|
|
* @note The packetType, payloadLength and payload have to be preset!
|
|
*
|
|
*
|
|
* @param[in, out] transportLayer transport layer instance to work on
|
|
* @param[in, out] transportLayer transport layer instance to work on
|
|
- * @param[in] packetType type of packet to send
|
|
|
|
* @param[in] packet packet to send
|
|
* @param[in] packet packet to send
|
|
* @return errorcode
|
|
* @return errorcode
|
|
*/
|
|
*/
|
|
@@ -58,6 +57,47 @@ static shellmatta_retCode_t shellmatta_transport_send(shellmatta_transport_layer
|
|
header->payloadLength);
|
|
header->payloadLength);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief check a search packet and return if our UUID is in the search range
|
|
|
|
+ * @param[in, out] transportLayer transport layer instance to work on
|
|
|
|
+ * @param[in] packet search packet
|
|
|
|
+ * @return true - UUID in passed range
|
|
|
|
+ */
|
|
|
|
+static bool shellmatta_transport_search(shellmatta_transport_layer_t *transportLayer,
|
|
|
|
+ shellmatta_transport_packet_t *packet)
|
|
|
|
+{
|
|
|
|
+ bool match = true;
|
|
|
|
+ uint32_t i;
|
|
|
|
+ uint8_t *uuid1;
|
|
|
|
+ uint8_t *uuid2;
|
|
|
|
+
|
|
|
|
+ /** -# check packet length */
|
|
|
|
+ if(SHELLMATTA_TRANPORT_UUID_LENGTH != packet->header.payloadLength)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ uuid1 = (uint8_t *)&packet->payload[0u];
|
|
|
|
+ uuid2 = (uint8_t *)&packet->payload[SHELLMATTA_TRANPORT_UUID_LENGTH];
|
|
|
|
+
|
|
|
|
+ /** -# compare UUID with range */
|
|
|
|
+ for(i = 0u; i < (SHELLMATTA_TRANPORT_UUID_LENGTH - 1u); i ++)
|
|
|
|
+ {
|
|
|
|
+ if((transportLayer->uuid[i] < uuid1[i]) || (transportLayer->uuid[i] > uuid2[i]))
|
|
|
|
+ {
|
|
|
|
+ match = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** -# explicitly check lowest digit - this is not inclusive to the lower limit */
|
|
|
|
+ if((transportLayer->uuid[i] <= uuid1[i]) || (transportLayer->uuid[i] > uuid2[i]))
|
|
|
|
+ {
|
|
|
|
+ match = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return match;
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @brief Initializes the transportLayerInst
|
|
* @brief Initializes the transportLayerInst
|
|
* @param[in, out] transportLayer transport layer instance to work on
|
|
* @param[in, out] transportLayer transport layer instance to work on
|
|
@@ -80,12 +120,14 @@ shellmatta_retCode_t shellmatta_transport_init( shellmatta_transport_layer_t
|
|
* @param[in, out] handle shellmatta handle of the instance
|
|
* @param[in, out] handle shellmatta handle of the instance
|
|
* @param[in] mandatory enforce using the transport layer
|
|
* @param[in] mandatory enforce using the transport layer
|
|
* @param[in] disableAutoFlush enforce manual flushing of the output packet
|
|
* @param[in] disableAutoFlush enforce manual flushing of the output packet
|
|
|
|
+ * @param[in] uuid UUID for multidrop search (default NULL)
|
|
* @param[in] customCrcFct use a custom crc generation (default NULL)
|
|
* @param[in] customCrcFct use a custom crc generation (default NULL)
|
|
* @return errorcode
|
|
* @return errorcode
|
|
*/
|
|
*/
|
|
shellmatta_retCode_t shellmatta_transport_configure(shellmatta_handle_t handle,
|
|
shellmatta_retCode_t shellmatta_transport_configure(shellmatta_handle_t handle,
|
|
bool mandatory,
|
|
bool mandatory,
|
|
bool disableAutoFlush,
|
|
bool disableAutoFlush,
|
|
|
|
+ uint8_t uuid[SHELLMATTA_TRANPORT_UUID_LENGTH],
|
|
shellmatta_transport_crc_t customCrcFct)
|
|
shellmatta_transport_crc_t customCrcFct)
|
|
{
|
|
{
|
|
shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
shellmatta_retCode_t ret = SHELLMATTA_OK;
|
|
@@ -106,6 +148,11 @@ shellmatta_retCode_t shellmatta_transport_configure(shellmatta_handle_t
|
|
{
|
|
{
|
|
transportLayer->active = true;
|
|
transportLayer->active = true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if(NULL != uuid)
|
|
|
|
+ {
|
|
|
|
+ (void)memcpy(transportLayer->uuid, uuid, SHELLMATTA_TRANPORT_UUID_LENGTH);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -290,7 +337,14 @@ shellmatta_retCode_t shellmatta_transport_process(shellmatta_transport_layer_t
|
|
break;
|
|
break;
|
|
|
|
|
|
case SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_REQUEST:
|
|
case SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_REQUEST:
|
|
- /** @todo implement */
|
|
|
|
|
|
+ /** -# check if our own uuid is inside the passed range */
|
|
|
|
+ if(true == shellmatta_transport_search(transportLayer, &transportLayer->inPacket))
|
|
|
|
+ {
|
|
|
|
+ intPacket.header.packetType = SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND;
|
|
|
|
+ intPacket.header.payloadLength = SHELLMATTA_TRANPORT_UUID_LENGTH;
|
|
|
|
+ (void)memcpy(intPacket.payload, transportLayer->uuid, SHELLMATTA_TRANPORT_UUID_LENGTH);
|
|
|
|
+ (void)shellmatta_transport_send(transportLayer, (shellmatta_transport_packet_t *)&intPacket);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
|
|
|
|
case SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND:
|
|
case SHELLMATTA_TRANSPORT_PACKET_SEARCH_DEVICE_RESPOND:
|