Foo-Manroot / foo-manroot.github.io

Personal web-page
https://foo-manroot.github.io/
GNU General Public License v3.0
2 stars 1 forks source link

no work https://github.com/pcotret/gnuradio-tutorial #2

Closed girs1982 closed 1 year ago

girs1982 commented 1 year ago

image can compile cpp module, but cant add on flow graf

girs1982 commented 1 year ago

self.time_delta += len (samples) and how it understand , how check time in microseconds?

girs1982 commented 1 year ago

maybe some threshold wrong ?

image

maybe i wrong get time? but i do expiriment on arduino and gnu rtl , times was == , and nothing , in samples have big pause it crash decoding

girs1982 commented 1 year ago

self.time_delta += len (samples) it wrong , but how get timestamps betwen 0 - 1 states ?

right will : for i in range(0, len(input_items[0])): self.time_delta += 1

it will add input samples if 2e6 , 1 microsecond == 2 samples? right?

def decodestarline (self) :
    if (self.difTime >900 and self.difTime <1100 and self.staline_state ==0  and self.lastRxValue==1):
       #print("starline preambule")
       self.starline_counter_pre +=1
       if self.starline_counter_pre == 6:
            print("starline preambule")
            self.staline_state = 1  
            print(self.difTime)              
    # preambule good      
    elif (self.staline_state==1):
        if (self.difTime >350 and self.difTime <650 and self.lastRxValue==1): 
            self.packet.append ("0")
            self.bValidPacket = True
        elif (self.difTime >150 and self.difTime <350 and self.lastRxValue==1): 
            self.packet.append ("1")
            self.bValidPacket = True
        else: 
            self.staline_state = 1 
            self.starline_counter=0
        if(self.bValidPacket ==True):
           self.starline_counter+=1
           if(self.starline_counter==64):
              print("getcode")
              self.starline_counter=0 
              self.staline_state=0
              self.starline_counter_pre=0                           
              #bin_strstar = str (self.packet)                                 
             # print(self.packet)  
              print(self.packet)                                
              self.packet = []
              self.time_delta = 0 
girs1982 commented 1 year ago

new code for starline , was breack on 2 paket , what wrong ? maybe python speed slow and cant don it?

""" Embedded Python Blocks:

Each this file is saved, GRC will instantiate the first class it finds to get в секунде миллион микросекунд т.е делитель 2 ports and parameters of your block. The arguments to init will be the parameters. All of them are required to have default values! """ import time import numpy as np from gnuradio import gr from datetime import datetime class blk (gr.sync_block): """ Block to decode the data on an already squared signal, comprised of 0's and 1's. """

def __init__ (self
            , baseband_freq = 600
            , sample_rate = 2e6
            , sink_file = None):  # only default arguments here
    """
    Constructor.

    Args:
        baseband_freq -> Frequency of the baseband signal

        sample_rate -> Number of samples per second

        sink_file -> File to dump the packets. If it's 'None', prints them on STDOUT
    """
    gr.sync_block.__init__(
        self,
        name = 'OOK to bin sink',
        in_sig = [np.float32],
        out_sig = []
    )

    # Number of samples to discern long and short bursts
    #   sample_rate / baseband_freq = samples_per_period
    self.threshold = (sample_rate / baseband_freq) / 2

    self.sink_file = sink_file

    self.time_delta = 0 # Timer to measure the time between edges

    self.rising_timestamps = []
    self.falling_timestamps = []
    self.previous_sample = 0  #posl sig rx
    self.lastRxValue = 1
    self.Rxpin = 0  #posl sig rx

    # Counter to determine the end of a packet. If more than (2 * threshold) samples
    # are set to 0, the packet is done
    self.allzero_count = 0
    self.starline_counter_pre = 0
    self.starline_counter = 0
    self.staline_state = 0
    self.bValidPacket=False
    self.lastRxTime=0
    self.lastRx=0
    self.difTime=0
    self.tempTime=0
    self.packet = [] # List to store the bits of the packet
    self.starline_code= [0,0,0,0,0,0,0,0]
    self.state = 0
    self.sym_count = 0
    self.bit_count = 0
    self.byte = 0
    self.sym = 0
    self.packet = []        
    self.dt = datetime.now()
    self.mic=self.dt.microsecond

def reset_state(self):
    self.state = 0
    self.sym_count = 0
    self.bit_count = 0
    self.byte = 0
    self.sym = 0
    self.packet = []
def decodestarline (self) :
    if (self.difTime >900*2 and self.difTime <1100*2 and self.staline_state ==0  and self.lastRx==1):
       #print("starline preambule")
       self.starline_counter_pre +=1
       if self.starline_counter_pre == 6:
            print("starline preambule")
            self.staline_state = 1  
            # print(self.difTime)              
    # preambule good      
    elif (self.staline_state==1):
        if (self.difTime >350*2 and self.difTime <650*2 and self.lastRx==1): 
            self.packet.append ("0")
            self.bValidPacket = True
        elif (self.difTime >150*2 and self.difTime <350*2 and self.lastRx==1): 
            self.packet.append ("1")
            self.bValidPacket = True
        else: 
            self.staline_state = 1 
            self.starline_counter=0
        if(self.bValidPacket ==True):
           self.starline_counter+=1
           print(self.starline_counter)
           if(self.starline_counter==64):
              print("getcode")
              self.starline_counter=0 
              self.staline_state=0
              self.starline_counter_pre=0                           
              #bin_strstar = str (self.packet)                                 
             # print(self.packet)  
              print(self.packet)                                
              self.packet = []

def work (self, input_items, *args, **kwargs):

    samples = input_items [0]

    in0 = input_items[0]
    processed = 0    

    for i in range(0, len(input_items[0])):
        self.time_delta += 1
        self.Rxpin=round(input_items[0][i])
        if(self.Rxpin!=self.lastRx):
            self.tempTime=self.time_delta
            self.difTime=self.tempTime-self.lastRxTime
            self.decodestarline()
            self.lastRxTime=self.tempTime
            self.lastRx=self.Rxpin

    # for sym in in0:
        # print(in0)

    #self.time_delta += len (samples)

    # if self.time_delta>1000000 and self.time_delta<2000005:
        # print(self.time_delta)
        # print(self.Rxpin)

    #self.consume(0, len(input_items[0]))     ///uvelichivaet kakto v hz   

    #print(self.time_delta)

    return len (samples)
Foo-Manroot commented 1 year ago

I'm still lost as to what you want me to help you with (I don't know anything about that other protocol you mentioned)

However, it is indeed very possible that Python is too slow for what you're trying (creating 2e6 samples per second). Besides, my code was quite shitty and could probably use a few optimisations.

That's why I suggested you to simply use your C++ code, which you already had implemented and working. In theory, adapting it should be just a matter of moving the functionality (which you already have) to the correct function: the constructor, start(), stop(), ...

girs1982 commented 1 year ago

I'm still lost as to what you want me to help you with (I don't know anything about that other protocol you mentioned)

However, it is indeed very possible that Python is too slow for what you're trying (creating 2e6 samples per second). Besides, my code was quite shitty and could probably use a few optimisations.

That's why I suggested you to simply use your C++ code, which you already had implemented and working. In theory, adapting it should be just a matter of moving the functionality (which you already have) to the correct function: the constructor, start(), stop(), ...

i later will try cpp , the preambule work good, but all of next pckets no work, on python , cpp cant build and install to gnu radio , my block was noavalible , i will it later on 3.7 version gnuradio , many versions do it very hard

girs1982 commented 1 year ago

I DONE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! https://www.youtube.com/watch?v=s1wNv0usPj4

you can give cpp and source)))

Foo-Manroot commented 1 year ago

Congratulations! 😊