close all
clear all


VV = [0    3    6    12    18    24    30    36    42    48    54    60];
II = [0.0  2.24 3.16  4.47  5.48  6.32  7.07  7.75  8.37  8.94  9.49  10.0];


figure
plot(VV,II,'-x');
xlabel('Voltage');
ylabel('Current (Amps)');


t = tcpip('192.168.1.5',666);
fopen(t);

if(strcmp(get(t,'status'),'closed'))
   error('tcp/ip connection not opened succesfully, quiting');
end


while (get(t, 'BytesAvailable') > 0)  %Read all available junk
    A = fread(t,get(t, 'BytesAvailable'));
end

 get_cmd = 'zippy';%'GetCurrProfile';
 fprintf(t, get_cmd);
 while (get(t, 'BytesAvailable') == 0)  %Wait for response
 end









reply = input('Send Table to PTO Controller? Y/N [Y]: ', 's');
if isempty(reply)
    reply = 'Y';
end

if(reply == 'Y' || reply == 'y')
  if(t.Status == 'open')
     N = length(VV);
     set_cmd = ['SetCurrProfile ' num2str(N) ' '];
     for i = 1:N
         set_cmd = [set_cmd ' ' num2str(VV(i),3) ' ' num2str(II(i),3)];
     end
     fprintf(t, Set_cmd);
     disp('set_cmd command sent, use GetCurrentProfile to check it was received correctly');
  else
     disp('telnet connection not open');
  end
else
  disp('PTO controller not updated'); 
end

fclose(t);