<commit_before>
from gateway.opencan.opencancontroller import CanOpenController
from gateway.evtcan.controller import EvtCanController
from gateway.can.device import CanOpenDevice
from gateway.settings.loader import buildController
from gateway.core.systemlogger import logger
import curses
import signal
import sys
#may want to inherit from our own custom code
class Terminal(object):

    def __init__(self):
        super()
        term = TermEvtCanController("INTEL_EVT_CAN.dbc")
        canopen = TermOpenController()

        #term = TermOpenController()
        buildController(term)
        buildController(canopen)

        self.screen = curses.initscr()
        self.screen.keypad(1)
        self.screen.nodelay(1)
        signal.signal(signal.SIGINT, self.close)
        curses.noecho()
        curses.cbreak()

        write_value = 0

        while True:

            values = canopen.motor.values.copy()

            new_press = self.screen.getch()
            if new_press == 261:#259 up
                write_value += 1
            if new_press == 260:#258 down
                write_value -= 1

            values['write_value'] = write_value

            self.screen.clear()
            row = 0
            for key in values.keys():
                log = str(key)+' : '+str(values[key])
                self.screen.addstr(row, 0, str(key)+' : '+str(values[key]))
                row = row + 1
            self.screen.refresh()

        #canopen.motor.sdo.write_values[0x2220] = number

    def start(self):
        pass

    def close(self, signum, frame):
        curses.nocbreak()
        self.screen.keypad(0)
        curses.echo()
        curses.endwin()
        sys.exit(1)

class TermEvtCanController(EvtCanController):

    def buildController(self):
        super().buildController()
        self.setupListener()
        self.addDevice(self.devices.fetchDevice("BMS0"))
        self.addDevice(self.devices.fetchDevice("BMS1"))
        self.addDevice(self.devices.fetchDevice("BMS2"))
        self.addDevice(self.devices.fetchDevice("BMS3"))
        self.controllerListener.addHandler('all',self.handleBroadCast)
        return True

    def handleBroadCast(self,nodeID, evtMessage):
        logger.debug("%s",evtMessage)


class TermOpenController(CanOpenController):

    def __init__(self):
        super().__init__()
        self.controllerListener.addHandler(0x00,self.handleBroadCast)

    def buildController(self):
        super().buildController()
        self.motor = CanOpenDevice(0x01,"MotorController.eds")
        self.addDevice(self.motor)
        return True

    def handleBroadCast(self,nodeID,value):
        print("Handle BroadCast")
<commit_msg>Oh boy, here it IS!!! Enable writing to throttle voltage from keyboard input<commit_after>
from gateway.opencan.opencancontroller import CanOpenController
from gateway.evtcan.controller import EvtCanController
from gateway.can.device import CanOpenDevice
from gateway.settings.loader import buildController
from gateway.core.systemlogger import logger
import curses
import signal
import sys
#may want to inherit from our own custom code
class Terminal(object):

    def __init__(self):
        super()
        term = TermEvtCanController("INTEL_EVT_CAN.dbc")
        canopen = TermOpenController()

        #term = TermOpenController()
        buildController(term)
        buildController(canopen)

        self.screen = curses.initscr()
        self.screen.keypad(1)
        self.screen.nodelay(1)
        signal.signal(signal.SIGINT, self.close)
        curses.noecho()
        curses.cbreak()

        write_value = 0

        while True:

            values = canopen.motor.values.copy()

            new_press = self.screen.getch()
            if new_press == 261:#259 up
                write_value += 1
            if new_press == 260:#258 down
                write_value -= 1

            values['write_value'] = write_value
            canopen.motor.sdo.write((), write_value, 0x2220)

            self.screen.clear()
            row = 0
            for key in values.keys():
                log = str(key)+' : '+str(values[key])
                self.screen.addstr(row, 0, str(key)+' : '+str(values[key]))
                row = row + 1
            self.screen.refresh()

        #canopen.motor.sdo.write_values[0x2220] = number

    def start(self):
        pass

    def close(self, signum, frame):
        curses.nocbreak()
        self.screen.keypad(0)
        curses.echo()
        curses.endwin()
        sys.exit(1)

class TermEvtCanController(EvtCanController):

    def buildController(self):
        super().buildController()
        self.setupListener()
        self.addDevice(self.devices.fetchDevice("BMS0"))
        self.addDevice(self.devices.fetchDevice("BMS1"))
        self.addDevice(self.devices.fetchDevice("BMS2"))
        self.addDevice(self.devices.fetchDevice("BMS3"))
        self.controllerListener.addHandler('all',self.handleBroadCast)
        return True

    def handleBroadCast(self,nodeID, evtMessage):
        logger.debug("%s",evtMessage)


class TermOpenController(CanOpenController):

    def __init__(self):
        super().__init__()
        self.controllerListener.addHandler(0x00,self.handleBroadCast)

    def buildController(self):
        super().buildController()
        self.motor = CanOpenDevice(0x01,"MotorController.eds")
        self.addDevice(self.motor)
        return True

    def handleBroadCast(self,nodeID,value):
        print("Handle BroadCast")

{'fraction_non_alphanumeric': 0.1058844896476571, 'fraction_numerical': 0.014347984017435525, 'mean_word_length': 2.4920735573874446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2816223', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1554, 'n_words': 307}