import pickle

channels = {
    'vfdnameplatehz':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_NameplateHz',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhpressureshutdownlimit':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'DH_Pressure_Shutdown',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhtempstartuplimit':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'DH_Temp_Startup',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhtempstartupenabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'DH_Temp_Startup_Enabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdmotorpoles':{
        'data_type':'UINT',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_MotorPoles',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdnameplatehp':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_NameplateHP',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdacceltime':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'VFD_AccelTime',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressurealarmdelay':{
        'data_type':'UDINT',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_Alarm_Delay',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressureeumin':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_EU_Min',
        'last_time_uploaded':0,
        'last_value':''
    },
    'offmode':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'Off_Mode',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfddisabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'VFD_Disabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressureeumax':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_EU_Max',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdspeedref':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'VFD_SpeedRef',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhpressurestartup':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'DH_Pressure_Startup',
        'last_time_uploaded':0,
        'last_value':''
    },
    'handmode':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'Hand_Mode',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdmaxfreq':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_MaxFreq',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhtempshutdownenabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'DH_Temp_Shutdown_Enabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhpressureshutdownenabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'DH_Pressure_Shutdown_Enabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdnameplatefla':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_NameplateFLA',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressuretransducerenabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_Transducer_Enabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressurealarmstartupdelay':{
        'data_type':'DINT',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_Alarm_Startup_Delay',
        'last_time_uploaded':0,
        'last_value':''
    },
    'automode':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'Auto_Mode',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdnameplaterpm':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_NameplateRPM',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdnameplateolcurrent':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_NameplateOLCurrent',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressurehisp':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_Hi_SP',
        'last_time_uploaded':0,
        'last_value':''
    },
    'downholetoolenabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'Downhole_Tool_Enabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdnameplatevolts':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_NameplateVolts',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfdminfreq':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'cfg_MinFreq',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhtempshutdown':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'DH_Temp_Shutdown',
        'last_time_uploaded':0,
        'last_value':''
    },
    'vfddeceltime':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'VFD_DecelTime',
        'last_time_uploaded':0,
        'last_value':''
    },
    'dhpressurestartupenabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'DH_Pressure_Startup_Enabled',
        'last_time_uploaded':0,
        'last_value':''
    },
    'tubingpressurelosp':{
        'data_type':'REAL',
        'change_amount':0.5,
        'max_time_between_uploads':3600,
        'tag':'TubingPressure_Lo_SP',
        'last_time_uploaded':0,
        'last_value':''
    },
    'remoteshutdowndisabled':{
        'data_type':'BOOL',
        'change_amount':None,
        'max_time_between_uploads':3600,
        'tag':'Remote_Shutdown_Disabled',
        'last_time_uploaded':0,
        'last_value':''
    }
}

for ch in channels.keys():
    # def vfdipp_dhpressureshutdownlimit(self, name, value):
    #       print("!!! Trying to set DH_Pressure_Shutdown to {0}".format(value))
    #       return u800.writeMicroTag(addr, "DH_Pressure_Shutdown", float(value))

    print("def vfdipp_{0}(self, name, value):".format(ch))
    print(" print('trying to set {0} to <>'.format(value))".format(channels[ch]['tag']))
    if channels[ch]['data_type'] == 'REAL':
        print(" return u800.writeMicroTag(addr, '{0}', float(value))".format(channels[ch]['tag']))
    elif (channels[ch]['data_type'] == 'BOOL') or (channels[ch]['data_type'][-3:] == "INT"):
        print(" return u800.writeMicroTag(addr, '{0}', int(value))".format(channels[ch]['tag']))
    else:
        print("!!!! DIDNT WORK FOR {0}".format(ch))
    print("")

print("====\nChannels to Update to RW\n====\n")
for ch in sorted(channels.keys()):
    print("[] - {0}".format(ch))
