Arnaud, thanks for the reply, we tried your suggestion and and made the callback only move the message to a separate queue in a non blocking way, but sadly the problem persisted.
we tried making a version the only receives without sending messages, and it didn't crash even once, we also made one that sent messages without receiving and it crashed regularly, so we are certain the problem has something to do with sending messages.
the version that only sends:
Code: Select all
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//#include <semphr.h>
//#include <unistd.h>
#include "app.h"
#include "FreeRTOS.h"
#include "task.h"
#include "deck.h"
#include "radiolink.h"
#include "configblock.h"
#define DEBUG_MODULE "P2P"
#include "debug.h"
#include "log.h"
#include "param.h"
#include "commander.h"
#include "deck_digital.h"
#include "deck_analog.h"
#define MESSAGE "warning!!!"
#define MESSAGE_LENGHT 11
void appMain()
{
DEBUG_PRINT("Waiting for activation ...\n");
static P2PPacket p_reply;
p_reply.port = 0x00;
uint64_t address = configblockGetRadioAddress();
uint8_t my_id = (uint8_t)((address)&0x00000000ff);
p_reply.data[0] = my_id;
//Put a string in the payload
char *str = "warning!!!";
memcpy(&p_reply.data[1], str, sizeof(char) * MESSAGE_LENGHT);
// Set the size, which is the amount of bytes the payload with ID and the string
p_reply.size = sizeof(char) * MESSAGE_LENGHT + 1;
while (1)
{
radiolinkSendP2PPacketBroadcast(&p_reply);
vTaskDelay(M2T(100));
}
}
the version that only receives:
Code: Select all
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//#include <semphr.h>
//#include <unistd.h>
#include "app.h"
#include "FreeRTOS.h"
#include "task.h"
#include "deck.h"
#include "radiolink.h"
#include "configblock.h"
#define DEBUG_MODULE "P2P"
#include "debug.h"
#include "log.h"
#include "param.h"
#include "commander.h"
#include "deck_digital.h"
#include "deck_analog.h"
#define MESSAGE "warning!!!"
#define MESSAGE_LENGHT 11
// A linked list (LL) node to store a queue entry
struct QNode
{
P2PPacket key;
struct QNode *next;
};
// The queue, front stores the front node of LL and rear stores the
// last node of LL
struct Queue
{
struct QNode *front, *rear;
};
struct QNode *newNode(P2PPacket k);
struct Queue *createQueue();
void enQueue(struct Queue *q, P2PPacket k);
void deQueue(struct Queue *q);
uint8_t Mutex;
uint8_t len;
struct Queue *P2PPacket_que;
void p2pcallbackHandler(P2PPacket *p)
{
/*
P2PPacket tmp = *p;
while (Mutex == 1)
{
}
Mutex = 1;
if(len < 20)
{
enQueue(P2PPacket_que, tmp);
len++;
}
Mutex = 0;
*/
len++;
DEBUG_PRINT("%d num, from %d\n", len, p->data[0]);
}
void appMain()
{
DEBUG_PRINT("Waiting for activation ...\n");
P2PPacket_que = createQueue();
Mutex = 0;
len = 0;
uint16_t idUp = logGetVarId("range", "up");
uint16_t up = logGetUint(idUp);
paramVarId_t idEstimator = paramGetVarId("motorPowerSet", "enable");
uint8_t new_value = 1;
paramSetInt(idEstimator, new_value);
// In itialize the p2p packet
static P2PPacket p_reply;
p_reply.port = 0x00;
// Get the current address of the crazyflie and obtain
// the last two digits and send it as the first byte
// of the payload
uint64_t address = configblockGetRadioAddress();
uint8_t my_id = (uint8_t)((address)&0x00000000ff);
p_reply.data[0] = my_id;
//Put a string in the payload
char *str = "warning!!!";
memcpy(&p_reply.data[1], str, sizeof(char) * MESSAGE_LENGHT);
// Set the size, which is the amount of bytes the payload with ID and the string
p_reply.size = sizeof(char) * MESSAGE_LENGHT + 1;
// Register the callback function so that the CF can receive packets as well.
p2pRegisterCB(p2pcallbackHandler);
while (1)
{
vTaskDelay(M2T(500));
up = logGetUint(idUp);
if (up < 300.f && up > 0.001f)
{
radiolinkSendP2PPacketBroadcast(&p_reply);
}
/*
while (P2PPacket_que->front != NULL)
{
DEBUG_PRINT("recived\n");
radiolinkSendP2PPacketBroadcast(&p_reply);
paramVarId_t idEstimator = paramGetVarId("motorPowerSet", "m1");
uint16_t new_value = 10000;
paramSetInt(idEstimator, new_value);
vTaskDelay(M2T(300));
new_value = 0;
paramSetInt(idEstimator, new_value);
while (Mutex == 1)
{
}
Mutex = 1;
deQueue(P2PPacket_que);
len--;
Mutex = 0;
}
*/
}
}
// A utility function to create a new linked list node.
struct QNode *newNode(P2PPacket k)
{
struct QNode *temp = (struct QNode *)malloc(sizeof(struct QNode));
temp->key = k;
temp->next = NULL;
return temp;
}
// A utility function to create an empty queue
struct Queue *createQueue()
{
struct Queue *q = (struct Queue *)malloc(sizeof(struct Queue));
q->front = q->rear = NULL;
return q;
}
// The function to add a key k to q
void enQueue(struct Queue *q, P2PPacket k)
{
// Create a new LL node
struct QNode *temp = newNode(k);
// If queue is empty, then new node is front and rear both
if (q->rear == NULL)
{
q->front = q->rear = temp;
return;
}
// Add the new node at the end of queue and change rear
q->rear->next = temp;
q->rear = temp;
}
// Function to remove a key from given queue q
void deQueue(struct Queue *q)
{
// If queue is empty, return NULL.
if (q->front == NULL)
return;
// Store previous front and move front one node ahead
struct QNode *temp = q->front;
q->front = q->front->next;
// If front becomes NULL, then change rear also as NULL
if (q->front == NULL)
q->rear = NULL;
free(temp);
}
the simplified callback version:
Code: Select all
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
//#include <semphr.h>
//#include <unistd.h>
#include "app.h"
#include "FreeRTOS.h"
#include "task.h"
#include "deck.h"
#include "radiolink.h"
#include "configblock.h"
#define DEBUG_MODULE "P2P"
#include "debug.h"
#include "log.h"
#include "param.h"
#include "commander.h"
#include "deck_digital.h"
#include "deck_analog.h"
#define MESSAGE "warning!!!"
#define MESSAGE_LENGHT 11
// A linked list (LL) node to store a queue entry
struct QNode
{
P2PPacket key;
struct QNode *next;
};
// The queue, front stores the front node of LL and rear stores the
// last node of LL
struct Queue
{
struct QNode *front, *rear;
};
struct QNode *newNode(P2PPacket k);
struct Queue *createQueue();
void enQueue(struct Queue *q, P2PPacket k);
void deQueue(struct Queue *q);
uint8_t Mutex;
uint8_t len;
struct Queue *P2PPacket_que;
void p2pcallbackHandler(P2PPacket *p)
{
P2PPacket tmp = *p;
if (Mutex == 1)
{
}
Mutex = 1;
if(len < 20)
{
enQueue(P2PPacket_que, tmp);
len++;
}
Mutex = 0;
}
void appMain()
{
DEBUG_PRINT("Waiting for activation ...\n");
P2PPacket_que = createQueue();
Mutex = 0;
len = 0;
uint16_t idUp = logGetVarId("range", "up");
uint16_t up = logGetUint(idUp);
paramVarId_t idEstimator = paramGetVarId("motorPowerSet", "enable");
uint8_t new_value = 1;
paramSetInt(idEstimator, new_value);
// In itialize the p2p packet
static P2PPacket p_reply;
p_reply.port = 0x00;
// Get the current address of the crazyflie and obtain
// the last two digits and send it as the first byte
// of the payload
uint64_t address = configblockGetRadioAddress();
uint8_t my_id = (uint8_t)((address)&0x00000000ff);
p_reply.data[0] = my_id;
//Put a string in the payload
char *str = "warning!!!";
memcpy(&p_reply.data[1], str, sizeof(char) * MESSAGE_LENGHT);
// Set the size, which is the amount of bytes the payload with ID and the string
p_reply.size = sizeof(char) * MESSAGE_LENGHT + 1;
// Register the callback function so that the CF can receive packets as well.
p2pRegisterCB(p2pcallbackHandler);
while (1)
{
vTaskDelay(M2T(500));
up = logGetUint(idUp);
if (up < 300.f && up > 0.001f)
{
radiolinkSendP2PPacketBroadcast(&p_reply);
}
while (P2PPacket_que->front != NULL)
{
DEBUG_PRINT("recived\n");
radiolinkSendP2PPacketBroadcast(&p_reply);
paramVarId_t idEstimator = paramGetVarId("motorPowerSet", "m1");
uint16_t new_value = 10000;
paramSetInt(idEstimator, new_value);
vTaskDelay(M2T(300));
new_value = 0;
paramSetInt(idEstimator, new_value);
while (Mutex == 1)
{
}
Mutex = 1;
deQueue(P2PPacket_que);
len--;
Mutex = 0;
}
}
}
// A utility function to create a new linked list node.
struct QNode *newNode(P2PPacket k)
{
struct QNode *temp = (struct QNode *)malloc(sizeof(struct QNode));
temp->key = k;
temp->next = NULL;
return temp;
}
// A utility function to create an empty queue
struct Queue *createQueue()
{
struct Queue *q = (struct Queue *)malloc(sizeof(struct Queue));
q->front = q->rear = NULL;
return q;
}
// The function to add a key k to q
void enQueue(struct Queue *q, P2PPacket k)
{
// Create a new LL node
struct QNode *temp = newNode(k);
// If queue is empty, then new node is front and rear both
if (q->rear == NULL)
{
q->front = q->rear = temp;
return;
}
// Add the new node at the end of queue and change rear
q->rear->next = temp;
q->rear = temp;
}
// Function to remove a key from given queue q
void deQueue(struct Queue *q)
{
// If queue is empty, return NULL.
if (q->front == NULL)
return;
// Store previous front and move front one node ahead
struct QNode *temp = q->front;
q->front = q->front->next;
// If front becomes NULL, then change rear also as NULL
if (q->front == NULL)
q->rear = NULL;
free(temp);
}
as for the motors locking up, the problem indeed was to not flip them.
please answer if you have any more suggestion or know of any way for us to better find the source of the crash.