{"id":474284,"date":"2025-09-08T21:02:32","date_gmt":"2025-09-08T21:02:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=474284"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=474284","title":{"rendered":"<span>HackRF \u043d\u0430 Windows: \u0440\u0430\u0431\u043e\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 DLL \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Python-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p> <strong>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u043f\u0438\u0442\u043e\u043d\u0435 \u0441 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u043e\u043c HackRF One \u043f\u043e\u0434 Windows<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u043e\u043c HackRF \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 Python, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u00a0<code>pyhackrf<\/code>\u00a0\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Linux. \u042d\u0442\u043e \u043f\u043e\u0434\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u043e \u043c\u0435\u043d\u044f \u043a \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0434 Windows \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u044f\u043c\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 DLL. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043c\u043e\u0439 \u043e\u043f\u044b\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f.  <\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 DLL?<\/h3>\n<ul>\n<li>\n<p><code>pyhackrf<\/code>\u00a0\u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 Linux \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u00a0<a href=\"http:\/\/libhackrf.so\" rel=\"noopener noreferrer nofollow\"><code>libhackrf.so<\/code><\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 Windows\u00a0<a href=\"http:\/\/libhackrf.so\" rel=\"noopener noreferrer nofollow\"><code>libhackrf.so<\/code><\/a>\u00a0\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u00a0<code>hackrf.dll<\/code><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 DLL \u0447\u0435\u0440\u0435\u0437 Python \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u043d\u0430\u044f \u0441\u0432\u043e\u0431\u043e\u0434\u0430 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Python-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f HackRF<\/h3>\n<\/li>\n<\/ul>\n<p> \u041a\u043e\u0434 <code><strong>hackrf_<\/strong><\/code>dll.py<strong>  <\/strong><\/p>\n<pre><code class=\"python\">from ctypes import * import os import numpy as np  # \u041f\u0443\u0442\u044c \u043a DLL dll_path = os.path.join(os.path.dirname(__file__), \"hackrf.dll\") lib = CDLL(dll_path)  p_hackrf_device = c_void_p  # ==== \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 ==== lib.hackrf_init.restype = c_int lib.hackrf_exit.restype = c_int lib.hackrf_open.argtypes = [POINTER(p_hackrf_device)] lib.hackrf_open.restype = c_int lib.hackrf_close.argtypes = [p_hackrf_device] lib.hackrf_close.restype = c_int  lib.hackrf_set_freq.argtypes = [p_hackrf_device, c_uint64] lib.hackrf_set_sample_rate.argtypes = [p_hackrf_device, c_double] lib.hackrf_set_amp_enable.argtypes = [p_hackrf_device, c_uint8] lib.hackrf_set_lna_gain.argtypes = [p_hackrf_device, c_uint32] lib.hackrf_set_vga_gain.argtypes = [p_hackrf_device, c_uint32]  # ==== RX \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 ==== class hackrf_transfer(Structure):     _fields_ = [         (\"device\", c_void_p),         (\"buffer\", POINTER(c_byte)),         (\"buffer_length\", c_int),         (\"valid_length\", c_int),         (\"rx_ctx\", c_void_p),         (\"tx_ctx\", c_void_p),     ]  rx_callback_t = CFUNCTYPE(c_int, POINTER(hackrf_transfer)) tx_callback_t = CFUNCTYPE(c_int, POINTER(hackrf_transfer))  lib.hackrf_start_rx.argtypes = [p_hackrf_device, rx_callback_t, c_void_p] lib.hackrf_stop_rx.argtypes = [p_hackrf_device]  lib.hackrf_start_tx.argtypes = [p_hackrf_device, tx_callback_t, c_void_p] lib.hackrf_stop_tx.argtypes = [p_hackrf_device]   # ==== \u041a\u043b\u0430\u0441\u0441 HackRF ==== class HackRF:     def __init__(self):         self.dev = p_hackrf_device(None)         if lib.hackrf_init() != 0:             raise RuntimeError(\"HackRF init error\")         if lib.hackrf_open(pointer(self.dev)) != 0:             raise RuntimeError(\"HackRF open error\")         print(\"[INFO] HackRF \u043e\u0442\u043a\u0440\u044b\u0442!\")          self._rx_cb = None         self._tx_cb = None      # ---- \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 ----     def set_freq(self, freq_hz):         if lib.hackrf_set_freq(self.dev, int(freq_hz)) != 0:             raise RuntimeError(\"HackRF set_freq error\")         print(f\"[INFO] \u0427\u0430\u0441\u0442\u043e\u0442\u0430 {freq_hz} Hz\")      def set_sample_rate(self, rate_hz):         if lib.hackrf_set_sample_rate(self.dev, float(rate_hz)) != 0:             raise RuntimeError(\"HackRF set_sample_rate error\")         print(f\"[INFO] \u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 {rate_hz} Hz\")      def enable_amp(self, en=True):         if lib.hackrf_set_amp_enable(self.dev, 1 if en else 0) != 0:             raise RuntimeError(\"HackRF amp error\")         print(f\"[INFO] \u0423\u0441\u0438\u043b\u0438\u0442\u0435\u043b\u044c {'\u0432\u043a\u043b\u044e\u0447\u0435\u043d' if en else '\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d'}\")      def set_lna_gain(self, gain):         lib.hackrf_set_lna_gain(self.dev, int(gain))         print(f\"[INFO] LNA gain {gain}\")      def set_vga_gain(self, gain):         lib.hackrf_set_vga_gain(self.dev, int(gain))         print(f\"[INFO] VGA gain {gain}\")      # ---- \u041f\u0440\u0438\u0451\u043c ----     def start_rx(self, callback):         def rx_cb(trans_ptr):             t = trans_ptr.contents             length = t.valid_length             if length &lt;= 0:                 print(\"[RX] \u041f\u0443\u0441\u0442\u043e\u0439 \u0431\u0443\u0444\u0435\u0440\")                 return 0             buf = cast(t.buffer, POINTER(c_byte * length)).contents             raw = np.frombuffer(buf, dtype=np.int8, count=length)             iq = raw[0::2].astype(np.float32) + 1j * raw[1::2].astype(np.float32)              print(f\"[RX] \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e {len(iq)} \u0441\u044d\u043c\u043f\u043b\u043e\u0432\")             if callback:                 callback(iq)             return 0          self._rx_cb = rx_callback_t(rx_cb)         res = lib.hackrf_start_rx(self.dev, self._rx_cb, None)         if res != 0:             raise RuntimeError(\"hackrf_start_rx error\")         print(\"[INFO] \u041f\u0440\u0438\u0451\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\")      def stop_rx(self):         lib.hackrf_stop_rx(self.dev)         print(\"[INFO] \u041f\u0440\u0438\u0451\u043c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\")      # ---- \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 ----     def start_tx(self, callback):         def tx_cb(trans_ptr):             t = trans_ptr.contents             length = t.buffer_length             if length &lt;= 0:                 return 0              buf = (c_byte * length).from_address(addressof(t.buffer.contents))              if callback:                 iq = callback(length \/\/ 2)  # \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0435 \u043e\u0442\u0441\u0447\u0451\u0442\u044b I\/Q                 iq = np.array(iq, dtype=np.complex64)                 iq_i = np.clip(np.real(iq), -127, 127).astype(np.int8)                 iq_q = np.clip(np.imag(iq), -127, 127).astype(np.int8)                 interleaved = np.empty(length, dtype=np.int8)                 interleaved[0::2] = iq_i[:len(interleaved)\/\/2]                 interleaved[1::2] = iq_q[:len(interleaved)\/\/2]                 buf[:len(interleaved)] = interleaved              return 0          self._tx_cb = tx_callback_t(tx_cb)         res = lib.hackrf_start_tx(self.dev, self._tx_cb, None)         if res != 0:             raise RuntimeError(\"hackrf_start_tx error\")         print(\"[INFO] \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430\")      def stop_tx(self):         lib.hackrf_stop_tx(self.dev)         print(\"[INFO] \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430\")      # ---- \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 ----     def close(self):         lib.hackrf_close(self.dev)         lib.hackrf_exit()         print(\"[INFO] HackRF \u0437\u0430\u043a\u0440\u044b\u0442\") <\/code><\/pre>\n<p><strong> \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438  <\/strong><\/p>\n<pre><code class=\"python\">from hackrf_dll import HackRF import time  # \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 HackRF \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 with HackRF() as hackrf:     hackrf.set_freq(433_920_000)   # \u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0434\u0438\u043e\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f RC     hackrf.set_lna_gain(16)     hackrf.set_vga_gain(16)     hackrf.enable_amp()          # \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \"\u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430\" \u2014 \u043f\u0430\u0443\u0437\u0430     time.sleep(2) <\/code><\/pre>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<ul>\n<li>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441 <code>hackrf_dll<\/code> \u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0432 Windows.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439, \u0443\u0441\u0438\u043b\u0435\u043d\u0438\u0435\u043c \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430, \u043e\u0441\u0442\u0430\u0432\u0430\u044f\u0441\u044c \u043b\u0451\u0433\u043a\u043e\u0439 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u043d\u0438\u0442\u0435 \u0447\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0431\u0435\u0437 \u0430\u043d\u0442\u0435\u043d\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u0430\u043b\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a. \u0422\u0430\u043a \u0436\u0435 \u0430\u043d\u0442\u0435\u043d\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u044f \u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b\u0431\u0440\u0430\u043b\u0438. <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/944960\/\"> https:\/\/habr.com\/ru\/articles\/944960\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p> <strong>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u043f\u0438\u0442\u043e\u043d\u0435 \u0441 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u043e\u043c HackRF One \u043f\u043e\u0434 Windows<\/strong>. \u041a\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u043e\u043c HackRF \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 Python, \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u00a0<code>pyhackrf<\/code>\u00a0\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Linux. \u042d\u0442\u043e \u043f\u043e\u0434\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u043e \u043c\u0435\u043d\u044f \u043a \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0434 Windows \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u044f\u043c\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 DLL. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043c\u043e\u0439 \u043e\u043f\u044b\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f.  <\/p>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 DLL?<\/h3>\n<ul>\n<li>\n<p><code>pyhackrf<\/code>\u00a0\u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0442\u043e\u0447\u0435\u043d \u043f\u043e\u0434 Linux \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u00a0<a href=\"http:\/\/libhackrf.so\" rel=\"noopener noreferrer nofollow\"><code>libhackrf.so<\/code><\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0430 Windows\u00a0<a href=\"http:\/\/libhackrf.so\" rel=\"noopener noreferrer nofollow\"><code>libhackrf.so<\/code><\/a>\u00a0\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u00a0<code>hackrf.dll<\/code><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 DLL \u0447\u0435\u0440\u0435\u0437 Python \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u043d\u0430\u044f \u0441\u0432\u043e\u0431\u043e\u0434\u0430 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Python-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f HackRF<\/h3>\n<\/li>\n<\/ul>\n<p> \u041a\u043e\u0434 <code><strong>hackrf_<\/strong><\/code>dll.py<strong>  <\/strong><\/p>\n<pre><code class=\"python\">from ctypes import * import os import numpy as np  # \u041f\u0443\u0442\u044c \u043a DLL dll_path = os.path.join(os.path.dirname(__file__), \"hackrf.dll\") lib = CDLL(dll_path)  p_hackrf_device = c_void_p  # ==== \u041f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 ==== lib.hackrf_init.restype = c_int lib.hackrf_exit.restype = c_int lib.hackrf_open.argtypes = [POINTER(p_hackrf_device)] lib.hackrf_open.restype = c_int lib.hackrf_close.argtypes = [p_hackrf_device] lib.hackrf_close.restype = c_int  lib.hackrf_set_freq.argtypes = [p_hackrf_device, c_uint64] lib.hackrf_set_sample_rate.argtypes = [p_hackrf_device, c_double] lib.hackrf_set_amp_enable.argtypes = [p_hackrf_device, c_uint8] lib.hackrf_set_lna_gain.argtypes = [p_hackrf_device, c_uint32] lib.hackrf_set_vga_gain.argtypes = [p_hackrf_device, c_uint32]  # ==== RX \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 ==== class hackrf_transfer(Structure):     _fields_ = [         (\"device\", c_void_p),         (\"buffer\", POINTER(c_byte)),         (\"buffer_length\", c_int),         (\"valid_length\", c_int),         (\"rx_ctx\", c_void_p),         (\"tx_ctx\", c_void_p),     ]  rx_callback_t = CFUNCTYPE(c_int, POINTER(hackrf_transfer)) tx_callback_t = CFUNCTYPE(c_int, POINTER(hackrf_transfer))  lib.hackrf_start_rx.argtypes = [p_hackrf_device, rx_callback_t, c_void_p] lib.hackrf_stop_rx.argtypes = [p_hackrf_device]  lib.hackrf_start_tx.argtypes = [p_hackrf_device, tx_callback_t, c_void_p] lib.hackrf_stop_tx.argtypes = [p_hackrf_device]   # ==== \u041a\u043b\u0430\u0441\u0441 HackRF ==== class HackRF:     def __init__(self):         self.dev = p_hackrf_device(None)         if lib.hackrf_init() != 0:             raise RuntimeError(\"HackRF init error\")         if lib.hackrf_open(pointer(self.dev)) != 0:             raise RuntimeError(\"HackRF open error\")         print(\"[INFO] HackRF \u043e\u0442\u043a\u0440\u044b\u0442!\")          self._rx_cb = None         self._tx_cb = None      # ---- \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 ----     def set_freq(self, freq_hz):         if lib.hackrf_set_freq(self.dev, int(freq_hz)) != 0:             raise RuntimeError(\"HackRF set_freq error\")         print(f\"[INFO] \u0427\u0430\u0441\u0442\u043e\u0442\u0430 {freq_hz} Hz\")      def set_sample_rate(self, rate_hz):         if lib.hackrf_set_sample_rate(self.dev, float(rate_hz)) != 0:             raise RuntimeError(\"HackRF set_sample_rate error\")         print(f\"[INFO] \u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 {rate_hz} Hz\")      def enable_amp(self, en=True):         if lib.hackrf_set_amp_enable(self.dev, 1 if en else 0) != 0:             raise RuntimeError(\"HackRF amp error\")         print(f\"[INFO] \u0423\u0441\u0438\u043b\u0438\u0442\u0435\u043b\u044c {'\u0432\u043a\u043b\u044e\u0447\u0435\u043d' if en else '\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d'}\")      def set_lna_gain(self, gain):         lib.hackrf_set_lna_gain(self.dev, int(gain))         print(f\"[INFO] LNA gain {gain}\")      def set_vga_gain(self, gain):         lib.hackrf_set_vga_gain(self.dev, int(gain))         print(f\"[INFO] VGA gain {gain}\")      # ---- \u041f\u0440\u0438\u0451\u043c ----     def start_rx(self, callback):         def rx_cb(trans_ptr):             t = trans_ptr.contents             length = t.valid_length             if length &lt;= 0:                 print(\"[RX] \u041f\u0443\u0441\u0442\u043e\u0439 \u0431\u0443\u0444\u0435\u0440\")                 return 0             buf = cast(t.buffer, POINTER(c_byte * length)).contents             raw = np.frombuffer(buf, dtype=np.int8, count=length)             iq = raw[0::2].astype(np.float32) + 1j * raw[1::2].astype(np.float32)              print(f\"[RX] \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e {len(iq)} \u0441\u044d\u043c\u043f\u043b\u043e\u0432\")             if callback:                 callback(iq)             return 0          self._rx_cb = rx_callback_t(rx_cb)         res = lib.hackrf_start_rx(self.dev, self._rx_cb, None)         if res != 0:             raise RuntimeError(\"hackrf_start_rx error\")         print(\"[INFO] \u041f\u0440\u0438\u0451\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d\")      def stop_rx(self):         lib.hackrf_stop_rx(self.dev)         print(\"[INFO] \u041f\u0440\u0438\u0451\u043c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\")      # ---- \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 ----     def start_tx(self, callback):         def tx_cb(trans_ptr):             t = trans_ptr.contents             length = t.buffer_length             if length &lt;= 0:                 return 0              buf = (c_byte * length).from_address(addressof(t.buffer.contents))              if callback:                 iq = callback(length \/\/ 2)  # \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0435 \u043e\u0442\u0441\u0447\u0451\u0442\u044b I\/Q                 iq = np.array(iq, dtype=np.complex64)                 iq_i = np.clip(np.real(iq), -127, 127).astype(np.int8)                 iq_q = np.clip(np.imag(iq), -127, 127).astype(np.int8)                 interleaved = np.empty(length, dtype=np.int8)                 interleaved[0::2] = iq_i[:len(interleaved)\/\/2]                 interleaved[1::2] = iq_q[:len(interleaved)\/\/2]                 buf[:len(interleaved)] = interleaved              return 0          self._tx_cb = tx_callback_t(tx_cb)         res = lib.hackrf_start_tx(self.dev, self._tx_cb, None)         if res != 0:             raise RuntimeError(\"hackrf_start_tx error\")         print(\"[INFO] \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430\")      def stop_tx(self):         lib.hackrf_stop_tx(self.dev)         print(\"[INFO] \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430\")      # ---- \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 ----     def close(self):         lib.hackrf_close(self.dev)         lib.hackrf_exit()         print(\"[INFO] HackRF \u0437\u0430\u043a\u0440\u044b\u0442\") <\/code><\/pre>\n<p><strong> \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438  <\/strong><\/p>\n<pre><code class=\"python\">from hackrf_dll import HackRF import time  # \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 HackRF \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 with HackRF() as hackrf:     hackrf.set_freq(433_920_000)   # \u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0434\u0438\u043e\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f RC     hackrf.set_lna_gain(16)     hackrf.set_vga_gain(16)     hackrf.enable_amp()          # \u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \"\u0442\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430\" \u2014 \u043f\u0430\u0443\u0437\u0430     time.sleep(2) <\/code><\/pre>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<ul>\n<li>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441 <code>hackrf_dll<\/code> \u0434\u0430\u0451\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0438 \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0443\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0432 Windows.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439, \u0443\u0441\u0438\u043b\u0435\u043d\u0438\u0435\u043c \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430, \u043e\u0441\u0442\u0430\u0432\u0430\u044f\u0441\u044c \u043b\u0451\u0433\u043a\u043e\u0439 \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u043d\u0438\u0442\u0435 \u0447\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0431\u0435\u0437 \u0430\u043d\u0442\u0435\u043d\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u043f\u0430\u043b\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a. \u0422\u0430\u043a \u0436\u0435 \u0430\u043d\u0442\u0435\u043d\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u044f \u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b\u0431\u0440\u0430\u043b\u0438. <\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/944960\/\"> https:\/\/habr.com\/ru\/articles\/944960\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-474284","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474284"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/474284\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}