More calculators coming soon!
program amphour; {$APPTYPE Console} {$RESource ahres.res} uses windows, SysUtils,urlmon,math, Classes; type TNL5=record FirstValue,LastValue:extended; HError:hresult; data:string; end; var CONST_HOUR_VALUE,hdt:TDateTime; ah,a,h:extended; sh,sah,sa,sd:string; dd,mIndex,i:integer; nl5opt:tstringlist; nl5:tnl5; function StrToFloatDef(const S:String; def:extended):extended; begin try result:=strtofloat(s) except result:=def; end; end; function nl5requestoutput(nl5opt:tstringlist;param:string;outp:extended):TNL5; var nl5filen,nl5url:array[0..max_path]of char; nl5ans:tstringlist; begin result.HError:=urldownloadtocachefile(nil,strfmt(nl5url, 'http://localhost:%u/?%s=%g',[strtointdef(nl5opt.values['nl5port'],80), nl5opt.values[param],outp]),nl5filen,max_path+1,0,nil); if nl5.HError=s_ok then begin nl5ans:=tstringlist.Create; nl5ans.LoadFromFile(nl5filen); result.data:=nl5ans.Text; nl5ans.Free; end; end; function nl5requestinput(nl5opt:tstringlist;param:string;intype:char):tnl5; var nl5filen,nl5url:array[0..max_path]of char; nl5ans:tstringlist; begin result.HError:=urldownloadtocachefile(nil,strfmt(nl5url, 'http://localhost:%u/?%s(%s)',[strtointdef(nl5opt.values['nl5port'],80),intype, nl5opt.values[param]]),nl5filen,max_path+1,0,nil); if nl5.HError=s_ok then begin nl5ans:=tstringlist.Create; nl5ans.LoadFromFile(nl5filen); result.data:=nl5ans.Text; nl5ans.CommaText:=nl5ans[0]; result.FirstValue:=strtofloatdef(nl5ans[0],0); result.LastValue:=strtofloatdef(nl5ans[nl5ans.count-1],0); nl5ans.Free; end; deletefile(nl5filen); end; label mysub; begin if paramstr(1)='/?'then begin writeln('Usage: ',extractfilename(paramstr(0)),' [nl5port=port nl5options]'); writeln('nl5port=port Spefifies the HTTP Link port.(default port 80)'); writeln; writeln('NL5 Options:'); writeln('bat_loadinp= Spefifies the NL5 component to get its battery load current from'); writeln('bat_loadout= NL5 Current Source to set the amphour load.'); exitprocess(0); end; SetConsoleTitle('AmpHour Calculator'); const_hour_Value:=EncodeTime(1,0,0,0); nl5opt:=tstringlist.Create; for i:=1to paramcount do nl5opt.Add(paramstr(i)); mysub: sh:='0';sa:='0';sah:='';sd:='0';hdt:=0; writeln('Leave one answer blank'); write('Enter Discharge time(hh:mm:ss):'); readln(sh); if sh<>'' then begin write('Enter discharge days(optional):'); readln(sd); if sd='' then sd:='0'; end; write('Enter AmpHour rating(in Amphours):'); readln(sah); if(nl5opt.Values['bat_loadinp']='')and(nl5opt.Values['bat_loadout']='') then begin write('Enter current draw in Amps:'); readln(sa); end else begin if nl5opt.Values['bat_loadinp']<>''then begin nl5:=nl5requestinput( nl5opt,'bat_loadinp','I'); sa:=floattostr(nl5.LastValue); if nl5.herror<>s_ok then begin writeln('URLErr:',inttohex(nl5.herror,0)); exitprocess(1);end; end; end; if sa='' then sa:='0'; if sah='' then sah:='0'; a:=StrTofloat(sa); ah:=strtofloat(sah); if ((sh='')and(ah=0))or((ah=0)and(a=0))or((sh='')and(a=0))then begin writeln('Error in one or more variables, please check to make sure only numbers are entered and only one answer is blank'); write('Try Again(Yes/no)? '); readln(sh); if pos('Y',Uppercase(sh))>0 then goto mysub else exitprocess(0); end; if sh<>'' then try hdt:=dd+StrToTime(sh); except on e:exception do begin writeln('Error:',e.message); write('Try Again(Yes/No)?'); readln(sh); if pos('Y',uppercase(sh))>0 then sh:= 'TRY_AGAIN' else sh:= 'EXIT'; end; end; if sh='TRY_AGAIN' then goto mysub; if sh='EXIT' then exitprocess(0); if a*ah*hdt<>0 then begin writeln('You didnt leave any answer blank'); write('Try Again(Yes/No)?'); readln(sh); if pos('Y',uppercase(sh))>0 then goto mysub else exitprocess(0); end; if sh='' then hdt :=(ah/a)*const_hour_value; h:=hdt/const_hour_value; if a=0 then a:=ah/h; if ah=0 then ah:=a*h; nl5:=nl5requestoutput(nl5opt,'bat_loadout',a); if nl5.HError<>s_ok then writeln('URLErr:',inttohex(nl5.HError,0)); Writeln('Duration: ',Trunc(hdt),' days ',formatdatetime('hh:mm:ss',hdt)); writeln('AmpHour Rating:',floattostr(ah)); writeln('Current Draw:',floattostr(a),' Amps'); write('Do you want to try again(Yes/No)?'); readln(sh); if pos('Y',Uppercase(sh))>0 then goto mysub; end.