class Message(object): def __init__(self): self.dac = DAC() # dac create self.response = '' # This will be the response to send to the client self.message = '' # Message that server got self.msg_parse_info() # Create every information to provide msg parsing self.parse_dict() # Create parse dictionary self.common_dict() # create common dictionary def take_msg(self, data): self.message = data.decode("ascii") print('This is the received message from the server: ', self.message) self.msg_handle(self.message) self.message = "" def send_response(self): if self.response != '': print('Sending response: ', self.response) x = self.response self.response = '' return x def __del__(self): self.dac.__del__() pass
def __init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name): Stepper.__init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name) self.dac = DAC(dac_channel) self.dacvalue = 0x00 # The voltage value on the VREF self.state = (1 << Stepper_00A4.SLEEP) | (1 << Stepper_00A4.RESET) | ( 1 << Stepper_00A4.ENABLED) # The initial state of the inputs self.current_enabled = True self.update()
def __init__(self): self.dac = DAC() # dac create self.response = '' # This will be the response to send to the client self.message = '' # Message that server got self.msg_parse_info() # Create every information to provide msg parsing self.parse_dict() # Create parse dictionary self.common_dict() # create common dictionary
def setUp(self): """ Setup function TestTypes for class DAC """ self.DACObj = DAC(tx_data, circuit_simulation, bypass) self.tx_data_in = self.DACObj.tx_data_in self.circuit_simulation = self.DACObj.circuit_simulation self.bypass = self.DACObj.bypass pass
def applyDAC(self, offset_value=0, IM_DD=True, time_interval=None): """Converts tx_data into dac values.""" # if not bypassing dac if not Global.bypass_dict["DAC"]: # Creates DAC object self.dac_obj = DAC(tx_data=self.tx_data_list_in, time_interval=time_interval, sync_obj=self.sync_obj) # Converts the 'tx_data' list into 'dac_tx_data' list self.dac_obj.convertsToAnalog(offset_value=offset_value) # Get the list of dac tx_data self.dac_tx_data_list = self.dac_obj.getDacTxData() else: #### Bypass DAC # self.dac_tx_data_list = self.tx_data_list_in max_tx = np.max( [np.max(tx_symbol) for tx_symbol in self.tx_data_list_in]) min_tx = np.min( [np.min(tx_symbol) for tx_symbol in self.tx_data_list_in]) # number of points in current time interval number_of_points = int(time_interval / Global.time_step) # Do interpolation (convertion to analog). Zero-hold order. self.dac_tx_data_list = [lib.interpolateData(np.arange(0, len(dac_tx))*time_interval/len(dac_tx), dac_tx, number_of_points) \ for dac_tx in self.dac_tx_data_list] self.dac_tx_data_list = [lib.adjustRange(tx_symbol,\ Global.VDD_tx, Global.VSS_rx,\ max_tx, min_tx,\ offset_value) \ for tx_symbol in self.tx_data_list_in] # Applies zero clipping (by default, for IM_DD) if IM_DD: self.dac_tx_data_list = [lib.zeroClip(dac_tx) \ for dac_tx in self.dac_tx_data_list]
class Stepper_00A4(Stepper): revision = "A4" SLEEP = 6 ENABLED = 4 RESET = 7 DECAY = 5 def __init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name): Stepper.__init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name) self.dac = DAC(dac_channel) self.dacvalue = 0x00 # The voltage value on the VREF self.state = (1 << Stepper_00A4.SLEEP) | (1 << Stepper_00A4.RESET) | ( 1 << Stepper_00A4.ENABLED) # The initial state of the inputs self.update() def set_enabled(self, force_update=False): """ Sets the Stepper enabled """ if not self.enabled: self.state &= ~(1 << Stepper_00A4.ENABLED) self.enabled = True self.update() def set_disabled(self, force_update=False): """ Sets the Stepper disabled """ if self.enabled: self.state |= (1 << Stepper_00A4.ENABLED) self.enabled = False self.update() def enable_sleepmode(self, force_update=False): """Logic high to enable device, logic low to enter low-power sleep mode. Internal pulldown.""" self.state &= ~(1 << Stepper_00A4.SLEEP) self.update() def disable_sleepmode(self, force_update=False): """ Disables sleepmode (awake) """ self.state |= (1 << Stepper_00A4.SLEEP) self.update() def reset(self, force_update=False): """nReset - Active-low reset input initializes the indexer logic and disables the H-bridge outputs. Internal pulldown.""" self.state &= ~(1 << Stepper_00A4.RESET) self.update() time.sleep(0.001) self.state |= (1 << Stepper_00A4.RESET) self.update() def set_microstepping(self, value, force_update=False): """ Microstepping (default = 0) 0 to 5 """ if not value in [0, 1, 2, 3, 4, 5 ]: # Full, half, 1/4, 1/8, 1/16, 1/32. logging.warning( "Tried to set illegal microstepping value: {0} for stepper {1}" .format(value, self.name)) return self.microstepping = value self.microsteps = 2**value # 2^val # Keep bit 0, 4, 5, 6 intact but replace bit 1, 2, 3 self.state = int( "0b" + bin(self.state)[2:].rjust(8, '0')[:4] + bin(value)[2:].rjust(3, '0')[::-1] + "0", 2) #self.state = int("0b"+bin(self.state)[2:].rjust(8, '0')[:4]+bin(value)[2:].rjust(3, '0')+bin(self.state)[-1:], 2) self.mmPrStep = 1.0 / (self.steps_pr_mm * self.microsteps) # update the Path class with new values stepper_num = Path.axis_to_index(self.name) Path.steps_pr_meter[stepper_num] = self.get_steps_pr_meter() logging.debug("Updated stepper " + self.name + " to microstepping " + str(value) + " = " + str(self.microsteps)) self.update() def set_current_value(self, iChop): """ Current chopping limit (This is the value you can change) """ self.current_value = iChop rSense = 0.1 # Resistance for the v_out = iChop * 5.0 * rSense # Calculated voltage out from the DAC self.dac.set_voltage(v_out) def set_decay(self, value, force_update=False): """ Decay mode, look in the data sheet """ if value not in [0, 1]: logging.warning( "Ivalid decay value. Use 0 or 1. Got: {}".format(value)) return self.decay = value self.state &= ~(1 << Stepper_00A4.DECAY) # bit 5 self.state |= (value << Stepper_00A4.DECAY) self.update() def update(self): # Invert shizzle self.shift_reg.set_state(self.state)
def __init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name): Stepper.__init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name) self.dac = DAC(dac_channel) self.dacvalue = 0x00 # The voltage value on the VREF self.state = (1<<Stepper_00A4.SLEEP)|(1<<Stepper_00A4.RESET)| (1<<Stepper_00A4.ENABLED) # The initial state of the inputs self.update()
class Stepper_00A4(Stepper): revision = "A4" SLEEP = 6 ENABLED = 4 RESET = 7 DECAY = 5 def __init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name): Stepper.__init__(self, stepPin, dirPin, faultPin, dac_channel, shiftreg_nr, name) self.dac = DAC(dac_channel) self.dacvalue = 0x00 # The voltage value on the VREF self.state = (1<<Stepper_00A4.SLEEP)|(1<<Stepper_00A4.RESET)| (1<<Stepper_00A4.ENABLED) # The initial state of the inputs self.update() def set_enabled(self, force_update=False): """ Sets the Stepper enabled """ if not self.enabled: self.state &= ~(1 << Stepper_00A4.ENABLED) self.enabled = True self.update() def set_disabled(self, force_update=False): """ Sets the Stepper disabled """ if self.enabled: self.state |= (1 << Stepper_00A4.ENABLED) self.enabled = False self.update() def enable_sleepmode(self, force_update=False): """Logic high to enable device, logic low to enter low-power sleep mode. Internal pulldown.""" self.state &= ~(1 << Stepper_00A4.SLEEP) self.update() def disable_sleepmode(self, force_update=False): """ Disables sleepmode (awake) """ self.state |= (1<<Stepper_00A4.SLEEP) self.update() def reset(self, force_update=False): """nReset - Active-low reset input initializes the indexer logic and disables the H-bridge outputs. Internal pulldown.""" self.state &= ~(1 << Stepper_00A4.RESET) self.update() time.sleep(0.001) self.state |= (1 << Stepper_00A4.RESET) self.update() def set_microstepping(self, value, force_update=False): """ Microstepping (default = 0) 0 to 5 """ if not value in [0, 1, 2, 3, 4, 5]: # Full, half, 1/4, 1/8, 1/16, 1/32. logging.warning("Tried to set illegal microstepping value: {0} for stepper {1}".format(value, self.name)) return self.microstepping = value self.microsteps = 2**value # 2^val # Keep bit 0, 4, 5, 6 intact but replace bit 1, 2, 3 self.state = int("0b"+bin(self.state)[2:].rjust(8, '0')[:4]+bin(value)[2:].rjust(3, '0')[::-1]+"0", 2) #self.state = int("0b"+bin(self.state)[2:].rjust(8, '0')[:4]+bin(value)[2:].rjust(3, '0')+bin(self.state)[-1:], 2) self.mmPrStep = 1.0/(self.steps_pr_mm*self.microsteps) # update the Printer class with new values stepper_num = self.printer.axis_to_index(self.name) self.printer.steps_pr_meter[stepper_num] = self.get_steps_pr_meter() logging.debug("Updated stepper "+self.name+" to microstepping "+str(value)+" = "+str(self.microsteps)) self.update() def set_current_value(self, iChop): """ Current chopping limit (This is the value you can change) """ self.current_value = iChop rSense = 0.1 # Resistance for the v_out = iChop * 5.0 * rSense # Calculated voltage out from the DAC self.dac.set_voltage(v_out) def set_decay(self, value, force_update=False): """ Decay mode, look in the data sheet """ if value not in [0, 1]: logging.warning("Invalid decay value. Use 0 or 1. Got: {}".format(value)) return self.decay = value self.state &= ~(1 << Stepper_00A4.DECAY) # bit 5 self.state |= (value << Stepper_00A4.DECAY) self.update() def update(self): # Invert shizzle self.shift_reg.set_state(self.state)
class Transmitter(object): def __init__(self, transmitter_config, tx_data_list, sync_obj): """Constructor of transmitter. Receives a array of lights.""" # Create sync object, and set debug and simulation path self.sync_obj = sync_obj self.DEBUG = self.sync_obj.getDebug( "Transmitter") or self.sync_obj.getDebug("all") self.sync_obj.appendToSimulationPath("Transmitter") if self.DEBUG: print('Running Transmitter...') # Contains list of dicts with all information needed to configure the lights on the Transmitter. Each position has a dict, with the type of light, the position for each lamp, and angle. Can be used to configure more than one array of lamps. self.transmitter_config = transmitter_config # List of data to be transmitted, after modulation. self.tx_data_list_in = tx_data_list # # Flag to bypass the creation of light sources ???????????????? # self.bypass = Global.bypass_dict["Transmitter"] pass @sync_track def createAllLamps(self): """Get the transmitter_config, and for each position (each dict), create a different lamp.""" # start all_lamp_array self.all_lamp_arrays = [] # For each lamp array, get its dictionary for lamp_array_dict in self.transmitter_config: # start lamp_array lamp_array = [] # For each lamp in the lamp array for idx in range(0, len(lamp_array_dict["light_type"])): # Create array of lamps lamp_array.append( self.createLamp( light_type=lamp_array_dict["light_type"][idx], position=lamp_array_dict["position"][idx], angle=lamp_array_dict["angle"][idx])) # List of all lamp arrays self.all_lamp_arrays.append(lamp_array) @sync_track def createLamp(self, light_type, position, angle): """Create a lamp, which is an array of LightSource objects.""" # Create light source object light_obj = LightSource(light_type=light_type, position=position, angle=angle, sync_obj=self.sync_obj) return light_obj @sync_track def applyFilter(self, filter_order=20, cuttof=400e6, filter_type='low'): """Apply digital filter. Cutoff in Hz.""" # sig = tx_data # lib.butterFilter(tx_data, cuttof=100e6) # lib.butterFilter(tx_data, cuttof=1e3, filter_type = 'hp') # return [lib.butterFilter(tx_data, cuttof=10e6)\ self.tx_data_list_in = [lib.butterFilter(tx_data, cuttof = cuttof, \ filter_order = filter_order, filter_type = filter_type)\ for tx_data in self.tx_data_list_in] # return [lib.butterFilter(tx_data, cuttof = cuttof, \ # filter_order = filter_order, filter_type = filter_type)\ # for tx_data in self.tx_data_list_in] # for tx_data in self.tx_data_list_in: # plotDebug(tx_data) # output_signal = signal.filtfilt(b, a, tx_data) # plotDebug(output_signal) @sync_track def applyDAC(self, offset_value=0, IM_DD=True, time_interval=None): """Converts tx_data into dac values.""" # if not bypassing dac if not Global.bypass_dict["DAC"]: # Creates DAC object self.dac_obj = DAC(tx_data=self.tx_data_list_in, time_interval=time_interval, sync_obj=self.sync_obj) # Converts the 'tx_data' list into 'dac_tx_data' list self.dac_obj.convertsToAnalog(offset_value=offset_value) # Get the list of dac tx_data self.dac_tx_data_list = self.dac_obj.getDacTxData() else: #### Bypass DAC # self.dac_tx_data_list = self.tx_data_list_in max_tx = np.max( [np.max(tx_symbol) for tx_symbol in self.tx_data_list_in]) min_tx = np.min( [np.min(tx_symbol) for tx_symbol in self.tx_data_list_in]) # number of points in current time interval number_of_points = int(time_interval / Global.time_step) # Do interpolation (convertion to analog). Zero-hold order. self.dac_tx_data_list = [lib.interpolateData(np.arange(0, len(dac_tx))*time_interval/len(dac_tx), dac_tx, number_of_points) \ for dac_tx in self.dac_tx_data_list] self.dac_tx_data_list = [lib.adjustRange(tx_symbol,\ Global.VDD_tx, Global.VSS_rx,\ max_tx, min_tx,\ offset_value) \ for tx_symbol in self.tx_data_list_in] # Applies zero clipping (by default, for IM_DD) if IM_DD: self.dac_tx_data_list = [lib.zeroClip(dac_tx) \ for dac_tx in self.dac_tx_data_list] @sync_track def calculatesOpticalPower(self): """Calculates what is the optical power provided for each time step, as tx_optical (given input dac_values).""" # If not bypassing the light source, calculate optical power based on it. if not Global.bypass_dict["LightSource"]: # Create all configured lamps, and pass the input info to all of them. # Next, should sum up their impact. self.createAllLamps() # TODO -- DO SOME CALCULATIONS BASED ON INPUT LIGHT # self.tx_optical_out_list = self.dac_tx_data_list raise ValueError( f"\n\n***Error --> Simulation for light sources not supported yet, at bypass_dict['LightSource'] = <{Global.bypass_dict['LightSource']}>!\n" ) else: # If bypassing, just pass the dac value forward self.tx_optical_out_list = self.dac_tx_data_list @sync_track def getTransmitterConfig(self): """Returns value of self.transmitter_config""" return self.transmitter_config @sync_track def setTransmitterConfig(self, transmitter_config): """Set new value for self.transmitter_config""" self.transmitter_config = transmitter_config @sync_track def getTxDataListIn(self): """Returns value of self.tx_data_list_in""" return self.tx_data_list_in @sync_track def setTxDataListIn(self, tx_data_list_in): """Set new value for self.tx_data_list_in""" self.tx_data_list_in = tx_data_list_in @sync_track def getDacTxDataList(self): """Returns value of self.dac_tx_data_list""" return self.dac_tx_data_list @sync_track def setDacTxDataList(self, dac_tx_data_list): """Set new value for self.dac_tx_data_list""" self.dac_tx_data_list = dac_tx_data_list @sync_track def getTxOpticalOutList(self): """Returns value of self.tx_optical_out_list""" return self.tx_optical_out_list @sync_track def setTxOpticalOutList(self, tx_optical_out_list): """Set new value for self.tx_optical_out_list""" self.tx_optical_out_list = tx_optical_out_list def getSyncObj(self): """Returns value of self.sync_obj""" return self.sync_obj def setSyncObj(self, sync_obj): """Set new value for self.sync_obj""" self.sync_obj = sync_obj
def PE_output(self): print( "---------------------Crossbar Configurations-----------------------" ) crossbar.xbar_output(self) print( "------------------------DAC Configurations-------------------------" ) DAC.DAC_output(self) print( "------------------------ADC Configurations-------------------------" ) ADC.ADC_output(self) print( "-------------------------PE Configurations-------------------------" ) print("total crossbar number in one PE:", self.PE_xbar_num) print(" the number of crossbars sharing a set of interfaces:", self.PE_multiplex_xbar_num) print("total utilization rate:", self.PE_utilization) print("total DAC number in one PE:", self.PE_DAC_num) print(" the number of DAC in one set of interfaces:", self.PE_multiplex_DAC_num) print("total ADC number in one PE:", self.PE_ADC_num) print(" the number of ADC in one set of interfaces:", self.PE_multiplex_ADC_num) print( "---------------------PE Area Simulation Results--------------------" ) print("PE area:", self.PE_area, "um^2") print(" crossbar area:", self.PE_xbar_area, "um^2") print(" DAC area:", self.PE_DAC_area, "um^2") print(" ADC area:", self.PE_ADC_area, "um^2") print(" digital part area:", self.PE_digital_area, "um^2") print( "--------------------PE Latency Simulation Results-----------------" ) print("PE read latency:", self.PE_read_latency, "ns") print(" crossbar read latency:", self.PE_xbar_read_latency, "ns") print(" DAC read latency:", self.PE_DAC_read_latency, "ns") print(" ADC read latency:", self.PE_ADC_read_latency, "ns") print(" digital part read latency:", self.PE_digital_read_latency, "ns") print("PE write latency:", self.PE_write_latency, "ns") print(" crossbar write latency:", self.PE_xbar_write_latency, "ns") print(" DAC write latency:", self.PE_DAC_write_latency, "ns") print(" ADC write latency:", self.PE_ADC_write_latency, "ns") print(" digital part write latency:", self.PE_digital_write_latency, "ns") print( "--------------------PE Power Simulation Results-------------------" ) print("PE read power:", self.PE_read_power, "W") print(" crossbar read power:", self.PE_xbar_read_power, "W") print(" DAC read power:", self.PE_DAC_read_power, "W") print(" ADC read power:", self.PE_ADC_read_power, "W") print(" digital part read power:", self.PE_digital_read_power, "W") print("PE write power:", self.PE_write_power, "W") print(" crossbar write power:", self.PE_xbar_write_power, "W") print(" DAC write power:", self.PE_DAC_write_power, "W") print(" ADC write power:", self.PE_ADC_write_power, "W") print(" digital part write power:", self.PE_digital_write_power, "W") print( "------------------PE Energy Simulation Results--------------------" ) print("PE read energy:", self.PE_read_energy, "nJ") print(" crossbar read energy:", self.PE_xbar_read_energy, "nJ") print(" DAC read energy:", self.PE_DAC_read_energy, "nJ") print(" ADC read energy:", self.PE_ADC_read_energy, "nJ") print(" digital part read energy:", self.PE_digital_read_energy, "nJ") print("PE write energy:", self.PE_write_energy, "nJ") print(" crossbar write energy:", self.PE_xbar_write_energy, "nJ") print(" DAC write energy:", self.PE_DAC_write_energy, "nJ") print(" ADC write energy:", self.PE_ADC_write_energy, "nJ") print(" digital part write energy:", self.PE_digital_write_energy, "nJ") print( "-----------------------------------------------------------------" )
def __init__(self, SimConfig_path): crossbar.__init__(self, SimConfig_path) DAC.__init__(self, SimConfig_path) ADC.__init__(self, SimConfig_path) PE_config = cp.ConfigParser() PE_config.read(SimConfig_path) __xbar_polarity = int( PE_config.get('Process element level', 'Xbar_Polarity')) # self.PE_multiplex_xbar_num = list( # map(int, PE_config.get('Process element level', 'Multiplex_Xbar_Num').split(','))) if __xbar_polarity == 1: self.PE_multiplex_xbar_num = [1, 1] else: assert __xbar_polarity == 2, "Crossbar polarity must be 1 or 2" self.PE_multiplex_xbar_num = [1, 2] self.group_num = int( PE_config.get('Process element level', 'Group_Num')) if self.group_num == 0: self.group_num = 1 self.num_occupied_group = 0 self.PE_xbar_num = self.group_num * self.PE_multiplex_xbar_num[ 0] * self.PE_multiplex_xbar_num[1] # self.polarity = PE_config.get('Algorithm Configuration', 'Weight_Polarity') # if self.polarity == 2: # assert self.PE_xbar_num[1]%2 == 0 self.PE_simulation_level = int( PE_config.get('Algorithm Configuration', 'Simulation_Level')) self.PE_xbar_list = [] self.PE_xbar_enable = [] for i in range(self.group_num): self.PE_xbar_list.append([]) self.PE_xbar_enable.append([]) for j in range(self.PE_multiplex_xbar_num[0] * self.PE_multiplex_xbar_num[1]): __xbar = crossbar(SimConfig_path) self.PE_xbar_list[i].append(__xbar) self.PE_xbar_enable[i].append(0) self.PE_multiplex_ADC_num = int( PE_config.get('Process element level', 'ADC_Num')) self.PE_multiplex_DAC_num = int( PE_config.get('Process element level', 'DAC_Num')) self.PE_ADC_num = 0 self.PE_DAC_num = 0 self.input_demux = 0 self.input_demux_power = 0 self.input_demux_area = 0 self.output_mux = 0 self.output_mux_power = 0 self.output_mux_area = 0 self.calculate_ADC_num() self.calculate_DAC_num() self.PE_adder = adder(SimConfig_path) self.PE_adder_num = 0 self.PE_shiftreg = shiftreg(SimConfig_path) self.PE_utilization = 0 self.PE_max_occupied_column = 0 self.PE_area = 0 self.PE_xbar_area = 0 self.PE_ADC_area = 0 self.PE_DAC_area = 0 self.PE_adder_area = 0 self.PE_shiftreg_area = 0 self.PE_input_demux_area = 0 self.PE_output_mux_area = 0 self.PE_digital_area = 0 self.PE_read_power = 0 self.PE_xbar_read_power = 0 self.PE_ADC_read_power = 0 self.PE_DAC_read_power = 0 self.PE_adder_read_power = 0 self.PE_shiftreg_read_power = 0 self.input_demux_read_power = 0 self.output_mux_read_power = 0 self.PE_digital_read_power = 0 self.PE_write_power = 0 self.PE_xbar_write_power = 0 self.PE_ADC_write_power = 0 self.PE_DAC_write_power = 0 self.PE_adder_write_power = 0 self.PE_shiftreg_write_power = 0 self.input_demux_write_power = 0 self.output_mux_write_power = 0 self.PE_digital_write_power = 0 self.PE_read_latency = 0 self.PE_xbar_read_latency = 0 self.PE_ADC_read_latency = 0 self.PE_DAC_read_latency = 0 self.PE_adder_read_latency = 0 self.PE_shiftreg_read_latency = 0 self.input_demux_read_latency = 0 self.output_mux_read_latency = 0 self.PE_digital_read_latency = 0 self.PE_write_latency = 0 self.PE_xbar_write_latency = 0 self.PE_ADC_write_latency = 0 self.PE_DAC_write_latency = 0 self.PE_adder_write_latency = 0 self.PE_shiftreg_write_latency = 0 self.input_demux_write_latency = 0 self.output_mux_write_latency = 0 self.PE_digital_write_latency = 0 self.PE_read_energy = 0 self.PE_xbar_read_energy = 0 self.PE_ADC_read_energy = 0 self.PE_DAC_read_energy = 0 self.PE_adder_read_energy = 0 self.PE_shiftreg_read_energy = 0 self.input_demux_read_energy = 0 self.output_mux_read_energy = 0 self.PE_digital_read_energy = 0 self.PE_write_energy = 0 self.PE_xbar_write_energy = 0 self.PE_ADC_write_energy = 0 self.PE_DAC_write_energy = 0 self.PE_adder_write_energy = 0 self.PE_shiftreg_write_energy = 0 self.input_demux_write_energy = 0 self.output_mux_write_energy = 0 self.PE_digital_write_energy = 0 self.calculate_inter_PE_connection()