Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make paramSetXXX() functions non-blocking #1235

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/modules/interface/param_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,17 @@ unsigned int paramGetUint(paramVarId_t varid);

/** Set int value of an int parameter (1-4 bytes)
*
* An update is also send to the client
* NOTE: The update to the client will be added to the output queue. If
* the Crazyflie is not connected to a client, the queue may fill up and
* this call will block until the queue is emptied.This could be avoided
* by setting the CONFIG_PARAM_SILENT_UPDATES flag.
*
* An update is also send to the client
*
* @param varId variable ID, returned by paramGetVarId()
* @param valuei Value to set in the variable
*/
void paramSetInt(paramVarId_t varid, int valuei);

/** Set float value of a float parameter
*
* An update is also send to the client
* NOTE: The update to the client will be added to the output queue. If
* the Crazyflie is not connected to a client, the queue may fill up and
* this call will block until the queue is emptied.This could be avoided
* by setting the CONFIG_PARAM_SILENT_UPDATES flag.
*
* An update is also send to the client
*
* @param varId variable ID, returned by paramGetVarId()
* @param valuef Value to set in the variable
*/
Expand Down
13 changes: 10 additions & 3 deletions src/modules/src/param_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Crazyflie control firmware
*
* Copyright (C) 2011-2021 Bitcraze AB
* Copyright (C) 2011-2023 Bitcraze AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -27,6 +27,7 @@
#include <errno.h>

#include "config.h"
#include "FreeRTOS.h"
#include "param_logic.h"
#include "storage.h"
#include "crc32.h"
Expand Down Expand Up @@ -576,7 +577,10 @@ void paramSetInt(paramVarId_t varid, int valuei)
pk.data[1] = varid.id & 0xffu;
pk.data[2] = (varid.id >> 8) & 0xffu;
pk.size = 3 + paramSize;
crtpSendPacketBlock(&pk);
const int sendResult = crtpSendPacket(&pk);
if (sendResult == errQUEUE_FULL) {
DEBUG_PRINT("WARNING: Param update not sent\n");
}
#endif

paramNotifyChanged(varid.index);
Expand All @@ -598,7 +602,10 @@ void paramSetFloat(paramVarId_t varid, float valuef)
pk.size = 3;
memcpy(&pk.data[2], &valuef, 4);
pk.size += 4;
crtpSendPacketBlock(&pk);
const int sendResult = crtpSendPacket(&pk);
if (sendResult == errQUEUE_FULL) {
DEBUG_PRINT("WARNING: Param update not sent\n");
}
#endif

paramNotifyChanged(varid.index);
Expand Down
14 changes: 7 additions & 7 deletions test/modules/src/test_param_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void testSetUint8(void) {
// Fixture
uint8_t expected = UINT8_MAX - 1;

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);
paramVarId_t varid = paramGetVarId("myGroup", "myUint8");

// Test
Expand All @@ -97,7 +97,7 @@ void testSetUint16(void) {
// Fixture
uint16_t expected = UINT16_MAX - 1;

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);
paramVarId_t varid = paramGetVarId("myGroup", "myUint16");

// Test
Expand All @@ -111,7 +111,7 @@ void testSetUint32(void) {
// Fixture
uint32_t expected = UINT32_MAX - 1;

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);
paramVarId_t varid = paramGetVarId("myGroup", "myUint32");

// Test
Expand All @@ -125,7 +125,7 @@ void testSetInt8(void) {
// Fixture
uint8_t expected = INT8_MAX - 1;

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);
paramVarId_t varid = paramGetVarId("myGroup", "myInt8");

// Test
Expand All @@ -139,7 +139,7 @@ void testSetInt16(void) {
// Fixture
uint16_t expected =UINT16_MAX - 1;

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);
paramVarId_t varid = paramGetVarId("myGroup", "myInt16");

// Test
Expand All @@ -153,7 +153,7 @@ void testSetInt32(void) {
// Fixture
uint32_t expected = INT32_MAX - 1;

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);
paramVarId_t varid = paramGetVarId("myGroup", "myInt32");

// Test
Expand Down Expand Up @@ -268,7 +268,7 @@ void testPersistentSetGetFloat(void) {

paramVarId_t varid = paramGetVarId("myGroup", "myPersistentFloat");

crtpSendPacketBlock_StubWithCallback(crtpReply);
crtpSendPacket_StubWithCallback(crtpReply);

// Test
paramSetFloat(varid, expected);
Expand Down