00001
00012 #include "DJI_Logging.h"
00013 #include "DJI_API.h"
00014 #include "DJI_Link.h"
00015 #include "DJI_Type.h"
00016 #include <pthread.h>
00017
00018 namespace DJI {
00019 namespace onboardSDK {
00020
00021 pthread_mutex_t _logging_lock = PTHREAD_MUTEX_INITIALIZER;
00022
00023 void printFrame(HardDriver *serialDevice, Header *header, bool onboardToAircraft) {
00024 pthread_mutex_lock(&_logging_lock);
00025
00026 uint32_t *crc32 = (uint32_t*) ((uint8_t*)header + header->length - 4);
00027
00028 if (!header->isAck) {
00029 __Command* command = (__Command*)((uint8_t*)header + sizeof(Header));
00030
00031 if (!onboardToAircraft && command->set_id == SET_BROADCAST) {
00032 pthread_mutex_unlock(&_logging_lock);
00033 return;
00034 }
00035
00036 API_LOG(serialDevice, DEBUG_LOG, "\n\n");
00037 if (onboardToAircraft) {
00038 API_LOG(serialDevice, DEBUG_LOG, "|---------------------Sending To Aircraft-------------------------------------------------------------|\n");
00039 } else {
00040 API_LOG(serialDevice, DEBUG_LOG, "|---------------------Received From Aircraft-----------------------------------------------------------|\n");
00041 }
00042
00043 API_LOG(serialDevice, DEBUG_LOG,
00044 "|<---------------------Header-------------------------------->|<---CMD frame data--->|<--Tail-->|\n");
00045 API_LOG(serialDevice, DEBUG_LOG,
00046 "|SOF |LEN |VER|SESSION|ACK|RES0|PADDING|ENC|RES1|SEQ |CRC16 |CMD SET|CMD ID|CMD VAL| CRC32 |\n");
00047 API_LOG(serialDevice, DEBUG_LOG,
00048 "|0x%2X|%4d|%3d|%7d|%3d|%4d|%7d|%3d|%4d|%6d|0x%04X| 0x%02X | 0x%02X | |0x%08X|\n", header->sof,
00049 header->length, header->version, header->sessionID, header->isAck,
00050 header->reversed0, header->padding, header->enc, header->reversed1,
00051 header->sequenceNumber, header->crc, command->set_id, command->id, *crc32);
00052
00053 if (command->set_id == SET_ACTIVATION && command->id == 0x00) {
00054
00055
00056
00057 }
00058 } else {
00059 API_LOG(serialDevice, DEBUG_LOG, "\n\n");
00060 if (onboardToAircraft) {
00061 API_LOG(serialDevice, DEBUG_LOG, "|---------------------Sending To Aircraft-------------------------------------------------------------|\n");
00062 } else {
00063 API_LOG(serialDevice, DEBUG_LOG, "|---------------------Received From Aircraft-----------------------------------------------------------|\n");
00064 }
00065
00066 API_LOG(serialDevice, DEBUG_LOG,
00067 "|<---------------------Header-------------------------------->|<-ACK frame data->|<--Tail-->|\n");
00068 API_LOG(serialDevice, DEBUG_LOG,
00069 "|SOF |LEN |VER|SESSION|ACK|RES0|PADDING|ENC|RES1|SEQ |CRC16 | ACK VAL | CRC32 |\n");
00070 API_LOG(serialDevice, DEBUG_LOG,
00071 "|0x%2X|%4d|%3d|%7d|%3d|%4d|%7d|%3d|%4d|%6d|0x%04X| ACK VAL |0x%08X|\n", header->sof,
00072 header->length, header->version, header->sessionID, header->isAck,
00073 header->reversed0, header->padding, header->enc, header->reversed1,
00074 header->sequenceNumber, header->crc, *crc32);
00075 }
00076 pthread_mutex_unlock(&_logging_lock);
00077 }
00078 }
00079 }