The next generation of radar (radio detection and ranging) systems needs to be based on software-defined radio to adapt to variable environments, with higher carrier frequencies for smaller antennas and broadened bandwidth for increased resolution. Today's digital microwave components (synthesizers and analogue-to-digital converters) suffer from limited bandwidth with high noise at increasing frequencies, so that fully digital radar systems can work up to only a few gigahertz, and noisy analogue up- and downconversions are necessary for higher frequencies. In contrast, photonics provide high precision and ultrawide bandwidth, allowing both the flexible generation of extremely stable radio-frequency signals with arbitrary waveforms up to millimetre waves, and the detection of such signals and their precise direct digitization without downconversion. Until now, the photonics-based generation and detection of radio-frequency signals have been studied separately and have not been tested in a radar system. Here we present the development and the field trial results of a fully photonics-based coherent radar demonstrator carried out within the project PHODIR. The proposed architecture exploits a single pulsed laser for generating tunable radar signals and receiving their echoes, avoiding radio-frequency up- and downconversion and guaranteeing both the software-defined approach and high resolution. Its performance exceeds state-of-the-art electronics at carrier frequencies above two gigahertz, and the detection of non-cooperating aeroplanes confirms the effectiveness and expected precision of the system.