The field version of the solarnano grid on the ionQubes

Fork of SolarNanoGridv3 by SONG Project

Revision:
26:10e8b9908631
Parent:
22:93fde34d9a94
Child:
27:512cf6199b1d
--- a/SolarNanoGrid.cpp	Wed Jun 15 01:53:07 2016 +0000
+++ b/SolarNanoGrid.cpp	Tue Jun 21 08:55:54 2016 +0000
@@ -230,4 +230,105 @@
     
 }
 
+
+void doNewConfig(Serial *pc)
+{
+//  H : Role
+//  300 : Version
+//  2540001 : Community_ID
+//  FF00 : ID
+//  5a : Channel
+
+    char * name = "/sd/config.ini";
+    char buffer[32];
+    char CommunityIDbuff[32];
+    char IDbuff[32];
+    char channelbuff[32];
+    char Role;
+    FILE *fp;
+    INFO("");c
+    INFO("***********************************");
+    INFO("*** Creating a new config file. ***");
+    INFO("***********************************");
+    INFO("");
+    fp = fopen(name, "w");
+    //Empty buffer
+    while (pc->readable()) {
+        pc->getc();
+    }
+    
+    char resp='k';
+    
+    do {
+        INFO("Enter Role (B-Battery, H-Hmi, L-Locker, U-Utility, X-Exit:");
+        buffer[0] = 'k';
+        while(1){
+            // Get a user input:
+            pc->scanf("%c",buffer);
+            // Check the input:
+            if ((buffer[0]=='X') ||(buffer[0]=='x')) {
+                INFO("Exiting...");
+                return;
+            }
+            if((buffer[0]=='B')||(buffer[0]=='b')||(buffer[0]=='H')||(buffer[0]=='h')||(buffer[0]=='L')||(buffer[0]=='l')||(buffer[0]=='U')||(buffer[0]=='u')){
+                break;
+            }
+            // If we get here, the input sucks:
+            INFO("Invalid selection, please enter the Role (B-Battery, H-Hmi, L-Locker, U-Utility, X-Exit:");
+        }
+        // Save the result:
+        Role = buffer[0];
+        INFO("Role = %c, selected.", Role);
+        INFO("");
+        
+        // Get the Community ID:
+        INFO("Enter community ID (Decimal int: e.g. 2540001):");
+        pc->scanf("%s",CommunityIDbuff);
+        INFO("Community ID= %s",CommunityIDbuff);
+        INFO("");
+        
+        // Get the ID:
+        INFO("Enter ID: (Hex: Locker (2 Bytes) Pod(1 Byte) Battery number (1Byte) e.g 01a1)");
+        pc->scanf("%s",IDbuff);
+        INFO("Locker ID= %s",IDbuff);
+        INFO("");
+        
+        // Get the Channel:
+        INFO("Enter Channel: (default: 5a)");
+        pc->scanf("%s",channelbuff);
+        INFO("Channel %s",channelbuff);
+        INFO("");
+        
+        // Display the results:
+        INFO("The new configuration file is:");
+        INFO("");
+        INFO("%c : Role",Role);
+        INFO("300 : Version");
+        INFO("%s : CommunityID",CommunityIDbuff);
+        INFO("%s : ID",IDbuff);
+        INFO("%s : channel",channelbuff);
+        INFO("");
+        //Save the result to a file:
+        INFO("Saving the new file to: %s...", name);
+        fp = fopen(name, "w");
+        fprintf (fp,"%c : Role\n\r",Role);
+        fprintf (fp,"300 : Version\n\r");
+        fprintf (fp,"%s : CommunityID\r\n",CommunityIDbuff);
+        fprintf (fp,"%s : ID\r\n",IDbuff);
+        fprintf (fp,"%s : channel\r\n",channelbuff);
+        fclose(fp);
+        INFO("Config file updated.");
+        
+        // Ask if we want to continue:
+        INFO("OK? (y/n)");
+        pc->scanf("%s",&buffer);
+        resp = buffer[0];
+        INFO("%c", resp);
+        
+    } while(resp!='y' and resp!='Y');
+    
+    INFO("Exiting...");
+    INFO("");
+    return;
+}
     
\ No newline at end of file