<commit_before>#!/usr/bin/python

import serial  #need this added from base python package
import struct
import time

#Print out some help if the module is ran directly.

def readme():
	print "this is the help text"	

if __name__ == "__main__":
    print readme()

class stream:
  'connect to a file or serial port'
  
  def __init__(self,type,path):
    self.type = type
    self.path = path
    
    if self.type == "S":
      self.ser = serial.Serial(self.path,38400)
      print "Opening ",self.ser.portstr
      
    #TODO add type for file stream
    
  def read(self, bytes):
    return self.ser.read(bytes)

  def write(self, data):
    self.ser.write(data)
  
  def inWaiting(self):
    return self.ser.inWaiting()

class bus:
  'functions to read/write from the carrier/bryant bus'
  #attaches to the stream and handles specifics of timing and framing

  def __init__(self,stream):
    self.stream = stream
    self.locked = 0
    self.starttime = 0
    self.timetrigger = False
    self.lastfunc = ''
    self.timeout = 0.02
  
  def read(self):
    head = self.stream.read(8)

    #check to make sure we're looking at the header
    while not self.locked:
      self.locked = 0
      if head[1]=='\x01' or head[1]=='\xF1':
        if head[3]=='\x01':
          if head[5]=='\x00' and head[6]=='\x00':
            self.locked = 1
      if self.locked == 0:
        #print "not locked - discarding 1 byte"
        head = head[1:]
        head += self.stream.read(1)
    
    #set lastfunc for testing before write
    self.lastfunc = ByteToHex(head[7])
    #get the length to read from the header
    readlen = int(ByteToHex(head[4]),16)
    #read len+2 for data and checksum (the rest of the frame)
    data = self.stream.read(2+readlen)  
    return head + data
  
  def write(self,data):
    #blocking call to test when it is ok to write - then write if OK
    #return 0 = no action
    #return 1 = item written
    #return 2 = paused, but no write
    
    #mark the current time
    self.starttime = time.clock()<commit_msg>update read function<commit_after>#!/usr/bin/python

import serial  #need this added from base python package
import struct
import time

#Print out some help if the module is ran directly.

def readme():
	print "this is the help text"	

if __name__ == "__main__":
    print readme()

class stream:
  'connect to a file or serial port'
  
  def __init__(self,type,path):
    self.type = type
    self.path = path
    
    if self.type == "S":
      self.ser = serial.Serial(self.path,38400)
      print "Opening ",self.ser.portstr
      
    #TODO add type for file stream
    
  def read(self, bytes):
    return self.ser.read(bytes)

  def write(self, data):
    self.ser.write(data)
  
  def inWaiting(self):
    return self.ser.inWaiting()

class bus:
  'functions to read/write from the carrier/bryant bus'
  #attaches to the stream and handles specifics of timing and framing

  def __init__(self,stream):
    self.stream = stream
    self.locked = 0
    self.starttime = 0
    self.timetrigger = False
    self.lastfunc = ''
    self.timeout = 0.02
    self.buf= ""
  
  def read(self):
    frame = ""
    self.locked = 0

    #make sure we have enough data in the buffer to check for the size of the frame
    while len(self.buf)<10:
      self.buf += self.stream.read(1)
	
    #fill the buffer to the frame size, then check the crc
    while not self.locked:
      frame_len = ord(self.buf[4])+10
      if len(self.buf) >= frame_len:
        frame = self.buf[:frame_len]
		#calculate crc of the frame
        crc16 = 0x0000
        for ch in frame:
          crc16 = calcByte(ch, crc16)
        if crc16 == 0:
          self.locked = 1
        else:
          print "SEEKING"
          self.buf = self.buf[1:]
      else:
        self.buf += self.stream.read(1)
    
    #set lastfunc for testing before write
    self.lastfunc = ByteToHex(frame[7])
	
    #cut data that will be returned off the beginning of the buffer
    self.buf = self.buf[frame_len:]

    return frame
  
  def write(self,data):
    #blocking call to test when it is ok to write - then write if OK
    #return 0 = no action
    #return 1 = item written
    #return 2 = paused, but no write
    
    #mark the current time
    self.starttime = time.clock()
{'fraction_non_alphanumeric': 0.10084230229293402, 'fraction_numerical': 0.018249883013570427, 'mean_word_length': 2.455941794664511, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 4, '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': '848277', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1381, 'n_words': 473}