eARDATATRANSFER_ERROR ARDATATRANSFER_DataDownloader_New(ARDATATRANSFER_Manager_t *manager, ARUTILS_Manager_t *ftpListManager, ARUTILS_Manager_t *ftpDataManager, const char *remoteDirectory, const char *localDirectory, ARDATATRANSFER_DataDownloader_FileCompletionCallback_t fileCompletionCallback, void *fileCompletionArg) { eARDATATRANSFER_ERROR result = ARDATATRANSFER_OK; int resultSys = 0; ARSAL_PRINT(ARSAL_PRINT_DEBUG, ARDATATRANSFER_DATA_DOWNLOADER_TAG, ""); if (manager == NULL) { result = ARDATATRANSFER_ERROR_BAD_PARAMETER; } if (result == ARDATATRANSFER_OK) { if (manager->dataDownloader != NULL) { result = ARDATATRANSFER_ERROR_ALREADY_INITIALIZED; } else { manager->dataDownloader = (ARDATATRANSFER_DataDownloader_t *)calloc(1, sizeof(ARDATATRANSFER_DataDownloader_t)); if (manager->dataDownloader == NULL) { result = ARDATATRANSFER_ERROR_ALLOC; } } } if (result == ARDATATRANSFER_OK) { resultSys = ARSAL_Sem_Init(&manager->dataDownloader->threadSem, 0, 0); if (resultSys != 0) { result = ARDATATRANSFER_ERROR_SYSTEM; } } if (result == ARDATATRANSFER_OK) { manager->dataDownloader->isCanceled = 0; manager->dataDownloader->isRunning = 0; manager->dataDownloader->fileCompletionCallback = fileCompletionCallback; manager->dataDownloader->fileCompletionArg = fileCompletionArg; result = ARDATATRANSFER_DataDownloader_Initialize(manager, ftpListManager, ftpDataManager, remoteDirectory, localDirectory); } if (result != ARDATATRANSFER_OK && result != ARDATATRANSFER_ERROR_ALREADY_INITIALIZED) { ARDATATRANSFER_DataDownloader_Delete(manager); } return result; }
int ARSTREAM_ReaderTb_StartStreamTest (ARNETWORK_Manager_t *manager, const char *outPath) { int retVal = 0; uint8_t *firstFrame; uint32_t firstFrameSize; eARSTREAM_ERROR err; if (NULL != outPath) { outFile = fopen (outPath, "wb"); } else { outFile = NULL; } ARSTREAM_ReaderTb_initMultiBuffers (FRAME_MAX_SIZE); ARSAL_Sem_Init (&closeSem, 0, 0); firstFrame = ARSTREAM_ReaderTb_GetNextFreeBuffer (&firstFrameSize, 0); g_Reader = ARSTREAM_Reader_New (manager, DATA_BUFFER_ID, ACK_BUFFER_ID, ARSTREAM_ReaderTb_FrameCompleteCallback, firstFrame, firstFrameSize, ARSTREAM_TB_FRAG_SIZE, 0, NULL, &err); if (g_Reader == NULL) { ARSAL_PRINT (ARSAL_PRINT_ERROR, __TAG__, "Error during ARSTREAM_Reader_New call : %s", ARSTREAM_Error_ToString(err)); return 1; } pthread_t streamsend, streamread; pthread_create (&streamsend, NULL, ARSTREAM_Reader_RunDataThread, g_Reader); pthread_create (&streamread, NULL, ARSTREAM_Reader_RunAckThread, g_Reader); /* USER CODE */ running = 1; ARSAL_Sem_Wait (&closeSem); running = 0; /* END OF USER CODE */ ARSTREAM_Reader_StopReader (g_Reader); pthread_join (streamread, NULL); pthread_join (streamsend, NULL); ARSTREAM_Reader_Delete (&g_Reader); ARSAL_Sem_Destroy (&closeSem); return retVal; }
void test_http_connection_private(char *tmp) { ARUTILS_Http_Connection_t *connection = NULL; eARUTILS_ERROR result; ARSAL_Sem_t cancelSem; ARSAL_Sem_Init(&cancelSem, 0, 0); connection = ARUTILS_Http_Connection_New(&cancelSem, DEVICE_IP, HTTP_PORT, HTTPS_PROTOCOL_FALSE, "parrot", "__parrot", &result); printf("result %d\n", result); char localFilePath[512]; strcpy(localFilePath, tmp); strcat(localFilePath, "photo_20131001_235901.jpg"); result = ARUTILS_Http_Get(connection, "private/photo_20131001_235901.jpg", localFilePath, test_http_progress_callback, "progress: "); printf("result %d\n", result); result = ARUTILS_Http_Connection_Cancel(connection); printf("result %d\n", result); ARUTILS_Http_Connection_Delete(&connection); ARSAL_Sem_Destroy(&cancelSem); }
int main (int argc, char *argv[]) { // local declarations int failed = 0; ARDISCOVERY_Device_t *device = NULL; ARCONTROLLER_Device_t *deviceController = NULL; eARCONTROLLER_ERROR error = ARCONTROLLER_OK; eARCONTROLLER_DEVICE_STATE deviceState = ARCONTROLLER_DEVICE_STATE_MAX; pid_t child = 0; ARSAL_Sem_Init (&(stateSem), 0, 0); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "Select your Bebop : Bebop (1) ; Bebop2 (2)"); char answer = '1'; scanf("%c", &answer); if (answer == '2') { isBebop2 = 1; } if(isBebop2) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "-- Bebop 2 Piloting --"); } else { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "-- Bebop Piloting --"); } if (!failed) { if (DISPLAY_WITH_MPLAYER) { // fork the process to launch mplayer if ((child = fork()) == 0) { execlp("xterm", "xterm", "-e", "mplayer", "-demuxer", "h264es", "video_fifo.h264", "-benchmark", "-really-quiet", NULL); ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "Missing mplayer, you will not see the video. Please install mplayer and xterm."); return -1; } } if (DISPLAY_WITH_MPLAYER) { videoOut = fopen("./video_fifo.h264", "w"); } } #ifdef IHM ihm = IHM_New (&onInputEvent); if (ihm != NULL) { gErrorStr[0] = '\0'; ARSAL_Print_SetCallback (customPrintCallback); //use a custom callback to print, for not disturb ncurses IHM if(isBebop2) { IHM_PrintHeader (ihm, "-- Bebop 2 Piloting --"); } else { IHM_PrintHeader (ihm, "-- Bebop Piloting --"); } } else { ARSAL_PRINT (ARSAL_PRINT_ERROR, TAG, "Creation of IHM failed."); failed = 1; } #endif // create a discovery device if (!failed) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- init discovey device ... "); eARDISCOVERY_ERROR errorDiscovery = ARDISCOVERY_OK; device = ARDISCOVERY_Device_New (&errorDiscovery); if (errorDiscovery == ARDISCOVERY_OK) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, " - ARDISCOVERY_Device_InitWifi ..."); // create a Bebop drone discovery device (ARDISCOVERY_PRODUCT_ARDRONE) if(isBebop2) { errorDiscovery = ARDISCOVERY_Device_InitWifi (device, ARDISCOVERY_PRODUCT_BEBOP_2, "bebop2", BEBOP_IP_ADDRESS, BEBOP_DISCOVERY_PORT); } else { errorDiscovery = ARDISCOVERY_Device_InitWifi (device, ARDISCOVERY_PRODUCT_ARDRONE, "bebop", BEBOP_IP_ADDRESS, BEBOP_DISCOVERY_PORT); } if (errorDiscovery != ARDISCOVERY_OK) { failed = 1; ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "Discovery error :%s", ARDISCOVERY_Error_ToString(errorDiscovery)); } } else { ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "Discovery error :%s", ARDISCOVERY_Error_ToString(errorDiscovery)); failed = 1; } } // create a device controller if (!failed) { deviceController = ARCONTROLLER_Device_New (device, &error); if (error != ARCONTROLLER_OK) { ARSAL_PRINT (ARSAL_PRINT_ERROR, TAG, "Creation of deviceController failed."); failed = 1; } else { IHM_setCustomData(ihm, deviceController); } } if (!failed) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- delete discovey device ... "); ARDISCOVERY_Device_Delete (&device); } // add the state change callback to be informed when the device controller starts, stops... if (!failed) { error = ARCONTROLLER_Device_AddStateChangedCallback (deviceController, stateChanged, deviceController); if (error != ARCONTROLLER_OK) { ARSAL_PRINT (ARSAL_PRINT_ERROR, TAG, "add State callback failed."); failed = 1; } } // add the command received callback to be informed when a command has been received from the device if (!failed) { error = ARCONTROLLER_Device_AddCommandReceivedCallback (deviceController, commandReceived, deviceController); if (error != ARCONTROLLER_OK) { ARSAL_PRINT (ARSAL_PRINT_ERROR, TAG, "add callback failed."); failed = 1; } } // add the frame received callback to be informed when a streaming frame has been received from the device if (!failed) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- set Video callback ... "); error = ARCONTROLLER_Device_SetVideoStreamCallbacks (deviceController, decoderConfigCallback, didReceiveFrameCallback, NULL , NULL); if (error != ARCONTROLLER_OK) { failed = 1; ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- error :%", ARCONTROLLER_Error_ToString(error)); } } if (!failed) { IHM_PrintInfo(ihm, "Connecting ..."); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "Connecting ..."); error = ARCONTROLLER_Device_Start (deviceController); if (error != ARCONTROLLER_OK) { failed = 1; ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- error :%s", ARCONTROLLER_Error_ToString(error)); } } if (!failed) { // wait state update update ARSAL_Sem_Wait (&(stateSem)); deviceState = ARCONTROLLER_Device_GetState (deviceController, &error); if ((error != ARCONTROLLER_OK) || (deviceState != ARCONTROLLER_DEVICE_STATE_RUNNING)) { failed = 1; ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- deviceState :%d", deviceState); ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- error :%s", ARCONTROLLER_Error_ToString(error)); } } // send the command that tells to the Bebop to begin its streaming if (!failed) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- send StreamingVideoEnable ... "); error = deviceController->aRDrone3->sendMediaStreamingVideoEnable (deviceController->aRDrone3, 1); if (error != ARCONTROLLER_OK) { ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- error :%s", ARCONTROLLER_Error_ToString(error)); failed = 1; } } if (!failed) { IHM_PrintInfo(ihm, "Running ... ('t' to takeoff ; Spacebar to land ; 'e' for emergency ; Arrow keys and ('r','f','d','g') to move ; 'q' to quit)"); #ifdef IHM while (gIHMRun) { usleep(50); } #else ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- sleep 20 ... "); sleep(20); #endif } #ifdef IHM IHM_Delete (&ihm); #endif // we are here because of a disconnection or user has quit IHM, so safely delete everything if (deviceController != NULL) { deviceState = ARCONTROLLER_Device_GetState (deviceController, &error); if ((error == ARCONTROLLER_OK) && (deviceState != ARCONTROLLER_DEVICE_STATE_STOPPED)) { IHM_PrintInfo(ihm, "Disconnecting ..."); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "Disconnecting ..."); error = ARCONTROLLER_Device_Stop (deviceController); if (error == ARCONTROLLER_OK) { // wait state update update ARSAL_Sem_Wait (&(stateSem)); } } IHM_PrintInfo(ihm, ""); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "ARCONTROLLER_Device_Delete ..."); ARCONTROLLER_Device_Delete (&deviceController); if (DISPLAY_WITH_MPLAYER) { fflush (videoOut); fclose (videoOut); if (child > 0) { kill(child, SIGKILL); } } } ARSAL_Sem_Destroy (&(stateSem)); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "-- END --"); return EXIT_SUCCESS; }
ARDISCOVERY_Connection_ConnectionData_t* ARDISCOVERY_Connection_New (ARDISCOVERY_Connection_SendJsonCallback_t sendJsonCallback, ARDISCOVERY_Connection_ReceiveJsonCallback_t receiveJsonCallback, void *customData, eARDISCOVERY_ERROR *error) { /* - Create and initialize connection data - */ ARDISCOVERY_Connection_ConnectionData_t *connectionData = NULL; eARDISCOVERY_ERROR localError = ARDISCOVERY_OK; /* Check parameter */ if ((sendJsonCallback == NULL) || (receiveJsonCallback == NULL)) { localError = ARDISCOVERY_ERROR_BAD_PARAMETER; } if (localError == ARDISCOVERY_OK) { connectionData = malloc(sizeof(ARDISCOVERY_Connection_ConnectionData_t)); if (connectionData != NULL) { /* Initialize connectionData */ connectionData->txData.buffer = NULL; connectionData->txData.size = 0; connectionData->rxData.buffer = NULL; connectionData->rxData.size = 0; connectionData->isAlive = 0; ARSAL_Sem_Init (&(connectionData->runningSem), 0, 1); connectionData->sendJsoncallback = sendJsonCallback; connectionData->receiveJsoncallback = receiveJsonCallback; connectionData->customData = customData; connectionData->socket = -1; memset(&(connectionData->address), 0, sizeof(connectionData->address)); connectionData->abortPipe[0] = -1; connectionData->abortPipe[1] = -1; } else { localError = ARDISCOVERY_ERROR_ALLOC; } } /* Allocate reception buffer */ if (localError == ARDISCOVERY_OK) { connectionData->rxData.buffer = (uint8_t *) malloc (sizeof(uint8_t) * ARDISCOVERY_CONNECTION_RX_BUFFER_SIZE); if (connectionData->rxData.buffer != NULL) { connectionData->rxData.size = 0; } else { localError = ARDISCOVERY_ERROR_ALLOC; } } /* Allocate transmission buffer */ if (localError == ARDISCOVERY_OK) { connectionData->txData.buffer = (uint8_t *) malloc(sizeof(uint8_t) * ARDISCOVERY_CONNECTION_TX_BUFFER_SIZE); if (connectionData->txData.buffer != NULL) { connectionData->txData.size = 0; } else { localError = ARDISCOVERY_ERROR_ALLOC; } } /* initialize the abortPipe */ if (localError == ARDISCOVERY_OK) { if (pipe(connectionData->abortPipe) != 0) { localError = ARDISCOVERY_ERROR_PIPE_INIT; } } /* Delete connection data if an error occurred */ if (localError != ARDISCOVERY_OK) { ARDISCOVERY_Connection_Delete (&connectionData); } /* return error */ if (error != NULL) { *error = localError; } return connectionData; }
/*********************************** MAIN ****************************/ int main(int argc, char *argv[]) { //local declarations int failed = 0; ARDISCOVERY_Device_t *device = NULL; ARCONTROLLER_Device_t *deviceController = NULL; eARCONTROLLER_ERROR error = ARCONTROLLER_OK; eARCONTROLLER_DEVICE_STATE deviceState = ARCONTROLLER_DEVICE_STATE_MAX; pid_t child = 0; ARSAL_Sem_Init(&(stateSem), 0, 0); #ifdef _ROLLINGSPIDER_PILOTING_IHM_H_ ihm = IHM_New(&onInputEvent); if (ihm != NULL) { gErrorStr[0] = '\0'; ARSAL_Print_SetCallback(customPrintCallback); //use a custom callback to print, for not disturb ncurses IHM IHM_PrintHeader(ihm, "-- Rolling Spider Piloting --"); } else { ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "Creation of IHM failed."); failed = 1; } #endif //create a discovery device if(!failed){ ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- init discovery device ..."); eARDISCOVERY_ERROR errorDiscovery = ARDISCOVERY_OK; device = ARDISCOVERY_Device_New(&errorDiscovery); if (errorDiscovery == ARDISCOVERY_OK) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- ARDISCOVERY_Device_InitBLE ..."); // create a Rolling Spider discovery device (ARDISCOVERY_PRODUCT_JS) /**errorDiscovery = ARDISCOVERY_Device_InitBLE(device, ARDISCOVERY_PRODUCT_MINIDRONE,bleDeviceManager,BLEDevice);**/ } } // create a device controller if (!failed) { deviceController = ARCONTROLLER_Device_New(device, &error); if (error != ARCONTROLLER_OK) { ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "Creation of deviceController failed."); failed = 1; } else { IHM_setCustomData(ihm, deviceController); } } if (!failed) { ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- delete discovey device ... "); ARDISCOVERY_Device_Delete(&device); } //add commands received callback // add the command received callback to be informed when a command has been received from the device if (!failed) { error = ARCONTROLLER_Device_AddCommandReceivedCallback(deviceController, commandReceived, deviceController); if (error != ARCONTROLLER_OK) { ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "add callback failed."); failed = 1; } } // add the state change callback to be informed when the device controller starts, stops... if (!failed) { error = ARCONTROLLER_Device_AddStateChangedCallback(deviceController, stateChanged, deviceController); if (error != ARCONTROLLER_OK) { ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "add State callback failed."); failed = 1; } } // connecting to the minidrone if (!failed) { IHM_PrintInfo(ihm, "Connecting ..."); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "Connecting ..."); error = ARCONTROLLER_Device_Start(deviceController); if (error != ARCONTROLLER_OK) { failed = 1; ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- error :%s", ARCONTROLLER_Error_ToString(error)); } } //waiting for a state update if (!failed) { ARSAL_Sem_Wait(&(stateSem)); deviceState = ARCONTROLLER_Device_GetState(deviceController, &error); if ((error != ARCONTROLLER_OK) || (deviceState != ARCONTROLLER_DEVICE_STATE_RUNNING)) { failed = 1; ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- deviceState :%d", deviceState); ARSAL_PRINT(ARSAL_PRINT_ERROR, TAG, "- error :%s", ARCONTROLLER_Error_ToString(error)); } } //running step when the drone is ready to work if (!failed) { IHM_PrintInfo(ihm, "Running ... ('t' to takeoff; 'l' to land; 'e' for emergency; 'q' to quit)"); #ifdef _ROLLINGSPIDER_PILOTING_IHM_H_ while (gIHMRun) { usleep(50); } #else ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- sleep 20 ... "); sleep(20); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "- sleep end ... "); #endif } #ifdef _ROLLINGSPIDER_PILOTING_IHM_H_ IHM_Delete(&ihm); #endif // we are here because of a disconnection or user has quit IHM, so safely delete everything if (deviceController != NULL) { deviceState = ARCONTROLLER_Device_GetState(deviceController, &error); if ((error == ARCONTROLLER_OK) && (deviceState != ARCONTROLLER_DEVICE_STATE_STOPPED)) { IHM_PrintInfo(ihm, "Disconnecting ..."); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "Disconnecting ..."); error = ARCONTROLLER_Device_Stop(deviceController); if (error == ARCONTROLLER_OK) { // wait state update update ARSAL_Sem_Wait(&(stateSem)); } } IHM_PrintInfo(ihm, ""); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "ARCONTROLLER_Device_Delete ..."); ARCONTROLLER_Device_Delete(&deviceController); } ARSAL_Sem_Destroy(&(stateSem)); ARSAL_PRINT(ARSAL_PRINT_INFO, TAG, "-- END --"); return EXIT_SUCCESS; }