def genEEPROMHEADER(jsonData):
    """
    Generates the C/CPP header file that can be used for accessing memory
    locations in EEPROM.

    :param jsonData: Contains the json data loaded in from the config files
    :type  jsonData: Dict between the the config file and the JSON data that it contains

    :return: Header file contents
    :rtype: string
    """
    headerOut = ""
    headerOut += genGeneric.autogenWarnStart("EEPROM Layout Config", os.path.abspath(__file__), commentChar="//")
    headerOut += "\n#ifndef EEPROM_LAYOUT_HEADER_H_\n"
    headerOut += "#define EEPROM_LAYOUT_HEADER_H_\n\n"
    headerOut += "#include <stdint.h>\n\n"

    layoutVersionIDs = {}
    # Create struct definitions
    for layout in jsonData['EEPROMLAYOUT']:
        layoutVersionIDs[int(layout['VersionID'])] = layout['VersionName'].lower().replace(" ", "_")

        headerOut += "// EEPROM Layout Version ID " + layout['VersionID'] + "\n"
        headerOut += "struct " + genGeneric.makeCName(layout['VersionName'], "variable") + " {\n"
        for memLoc in layout['Data']:
            # Create variable type
            if (memLoc['Data Type'] == "H" or memLoc['Data Type'] == "I" or memLoc['Data Type'] == "L" or memLoc['Data Type'] == "Q"):
                headerOut += "\tuint" + str(int(memLoc['Size'])*8) + "_t "
            elif (memLoc['Data Type'] == "h" or memLoc['Data Type'] == "i" or memLoc['Data Type'] == "l" or memLoc['Data Type'] == "q"):
                headerOut += "\tint" + str(int(memLoc['Size'])*8) + "_t "
            elif (memLoc['Data Type'] == "f"):
                headerOut += "\tfloat "
            elif (memLoc['Data Type'] == "d"):
                headerOut += "\tdouble "
            elif (memLoc['Data Type'] == "c"):
                headerOut += "\tchar "
            elif (memLoc['Data Type'] == "s" or memLoc['Data Type'] == "p"):
                headerOut += "\tchar[] "
            elif (memLoc['Data Type'] == "P"):
                headerOut += "\tvoid *"
            # Add name after variable type
            headerOut += memLoc['Name'].replace(" ", "_") + ";\n"
        headerOut += "}" + " __attribute((aligned (1)))" + "; // " + genGeneric.makeCName(layout['VersionName'], "variable") + "\n\n"

    # Create enum of versionIDs
    headerOut += "enum layoutVersionIDs {\n"
    for ID in layoutVersionIDs:
        headerOut += "\t" + genGeneric.makeCName(layoutVersionIDs[ID], "#define") + ", \t // " + str(ID) + "\n"
    headerOut += "\tMAX_LAYOUT_VERSION_IDS\n"
    headerOut += "};\n\n"

    headerOut += "\n#endif // EEPROM_LAYOUT_HEADER_H_\n\n"
    headerOut += genGeneric.autogenWarnEnd("EEPROM Layout Config", os.path.abspath(__file__), commentChar="//")
    return headerOut
def getLatex(jsonData):
    """
    This function uses the HARDWARE config file to generate a latex file that
    can later be compiled into the ARD as the "Hardware" section.

    :param jsonData: Contains the json data loaded in from the config files
    :type  jsonData: Dict between the the config file and the JSON data that it contains

    :return: Latex file contents
    :rtype: string
    """
    # Sort hardware based on hardware type
    PTs = []
    TCs = []
    RTDs = []
    HEs = []
    for ID in jsonData['HARDWARE']:
        try:
            if (ID['Hardware Type'] == "Pressure Transducer"):
                PTs.append(ID)
            elif (ID['Hardware Type'] == "Thermocouple"):
                TCs.append(ID)
            elif (ID['Hardware Type'] == "RTD"):
                RTDs.append(ID)
            elif (ID['Hardware Type'] == "Hall Effect Sensor"):
                HEs.append(ID)
            else:
                print(f"Invalid ID Hardware Type: \"{ID['Hardware Type']}\"")
                return ""
        except KeyError:
            print("Invalid Key 'Hardware Type' in :")
            print(ID)
            return ""
    # Parse hardware configs to latex
    texHARDWARE = genHARDWARETex(PTs, TCs, RTDs, HEs, jsonData['EEPROM'])
    # Check for error in latex generation
    if (texHARDWARE == ""):
        return ""

    # Create latex
    texOut = ""
    texOut += genGeneric.autogenWarnStart("Hardware Config",
                                          os.path.abspath(__file__))
    texOut += "\section{Hardware}\n"
    texOut += texHARDWARE
    texOut += "\\newpage\n"
    texOut += genGeneric.autogenWarnEnd("Hardware Config",
                                        os.path.abspath(__file__))
    return texOut
Esempio n. 3
0
def getHeader(jsonData):
    """Generates a C/C++ header file from the CAN config file.

    :param jsonData: Contains the json data loaded in from the config files
    :type  jsonData: Dict between the the config file and the JSON data that it contains

    :return: Contents of the header file
    :rtype: string
    """
    headerOut = ""
    headerOut += genGeneric.autogenWarnStart("CAN Config", os.path.abspath(__file__), commentChar="//")

    headerOut += genCANHeader(jsonData['CAN'], jsonData['STATES'])

    headerOut += genGeneric.autogenWarnEnd("CAN Config", os.path.abspath(__file__), commentChar="//")
    return headerOut
def getLatex(jsonData):
    """
    Generates the latex that will be used in the "EEPROM Layouts" section of the ARD.

    :param jsonData: Contains the json data loaded in from the config files
    :type  jsonData: Dict between the the config file and the JSON data that it contains

    :return: Latex file contents
    :rtype: string
    """
    texOut = ""
    texOut += genGeneric.autogenWarnStart("EEPROM Layouts", os.path.abspath(__file__))
    
    texOut += "\section{EEPROM Layouts}\n"
    texOut += genLayoutVersionIDs(jsonData['EEPROMLAYOUT'])

    for layout in jsonData['EEPROMLAYOUT']:
        texOut += genEEPROMTex(layout)
    
    texOut += genGeneric.autogenWarnEnd("EEPROM Layouts", os.path.abspath(__file__))
    return texOut
Esempio n. 5
0
def getLatex(jsonData):
    """This function uses the CAN config file to generate a latex file that
    can later be compiled into the ARD as the "CAN IDs" section.

    :param jsonData: Contains the json data loaded in from the config files
    :type  jsonData: Dict between the the config file and the JSON data that it contains

    :return: Latex file contents
    :rtype: string
    """
    texOut = ""
    texOut += genGeneric.autogenWarnStart("CAN Config", os.path.abspath(__file__))
    
    texOut += "\section{CAN IDs}\n"

    texOut += "\subsection{CAN Bus Load Calculations}\n"
    canBusFrequencies = [100000, 250000, 500000, 1000000]
    bestCase, worstCase = getCANBusLoad(jsonData['CAN'])
    texOut += "The current CAN Bus config requires between " + str(bestCase) + " bits and " + str(worstCase) + " bits to be sent on the CAN bus every second.\n\n"
    texOut += "\\begin{flushleft}"
    texOut += "\\begin{tabular}{|c|c|c|}\hline\n"
    texOut += "\tFrequency & Best Case & Worst Case \\\\\hline\n"
    for frequency in canBusFrequencies:
        texOut += "\t"
        if (frequency >= 1000000):
            texOut += str(int(frequency/1000000)) + "MHz"
        elif (frequency >= 1000):
            texOut += str(int(frequency/1000)) + "KHz"
        else:
            texOut += str(int(frequency)) + "Hz"
        
        texOut += " & " + str(round(bestCase / frequency, 2)*100) + "\% & " + str(round(worstCase / frequency, 2)*100) + "\%\\\\\hline\n"
    texOut += "\end{tabular}\n"
    texOut += "\end{flushleft}"
    for ID in jsonData['CAN']:
        texOut += genCANTex(ID)

    texOut += genGeneric.autogenWarnEnd("CAN Config", os.path.abspath(__file__))
    
    return texOut