Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
NetworkParameters.cpp@8:26e49e6955bd, 2017-07-31 (annotated)
- Committer:
- jmitc91516
- Date:
- Mon Jul 31 15:37:57 2017 +0000
- Revision:
- 8:26e49e6955bd
- Parent:
- 1:a5258871b33d
Method ramp scrolling improved, and more bitmaps moved to QSPI memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 1:a5258871b33d | 1 | #include "NetworkParameters.h" |
jmitc91516 | 1:a5258871b33d | 2 | #include "EasyGUITouchAreaIndices.h" |
jmitc91516 | 1:a5258871b33d | 3 | #include "SettingsHandler.h" |
jmitc91516 | 1:a5258871b33d | 4 | #include "GetGCStatusLoop.h" |
jmitc91516 | 1:a5258871b33d | 5 | #include "NumericKeypadPageHandler.h" |
jmitc91516 | 1:a5258871b33d | 6 | #include "EthernetKeypadPageHandler.h" |
jmitc91516 | 1:a5258871b33d | 7 | |
jmitc91516 | 1:a5258871b33d | 8 | #include <string.h> |
jmitc91516 | 1:a5258871b33d | 9 | |
jmitc91516 | 1:a5258871b33d | 10 | #include <stdio.h> |
jmitc91516 | 1:a5258871b33d | 11 | #include <stdlib.h> |
jmitc91516 | 1:a5258871b33d | 12 | |
jmitc91516 | 1:a5258871b33d | 13 | |
jmitc91516 | 1:a5258871b33d | 14 | |
jmitc91516 | 1:a5258871b33d | 15 | /* |
jmitc91516 | 1:a5258871b33d | 16 | Displays the specified easyGUI 'structure' (or page, to use a more easily understood term). |
jmitc91516 | 1:a5258871b33d | 17 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 18 | */ |
jmitc91516 | 1:a5258871b33d | 19 | extern void DisplayEasyGuiStructure(int structureIndex, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, bool updateEasyGUIVariables = true); |
jmitc91516 | 1:a5258871b33d | 20 | |
jmitc91516 | 1:a5258871b33d | 21 | |
jmitc91516 | 1:a5258871b33d | 22 | /* |
jmitc91516 | 1:a5258871b33d | 23 | Draws the background bitmap. It fills the screen, so you do not need to call GuiLib_Clear. |
jmitc91516 | 1:a5258871b33d | 24 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 25 | */ |
jmitc91516 | 1:a5258871b33d | 26 | extern void DrawBackgroundBitmap(void); |
jmitc91516 | 1:a5258871b33d | 27 | #define USING_BACKGROUND_BITMAP |
jmitc91516 | 1:a5258871b33d | 28 | |
jmitc91516 | 1:a5258871b33d | 29 | /* |
jmitc91516 | 1:a5258871b33d | 30 | Converts three eight-bit colour values to the corresponding 16-bit RGB565 value. |
jmitc91516 | 1:a5258871b33d | 31 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 32 | */ |
jmitc91516 | 1:a5258871b33d | 33 | GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue); |
jmitc91516 | 1:a5258871b33d | 34 | /* |
jmitc91516 | 1:a5258871b33d | 35 | Displays the specified text string at the specified location in the currently-displayed easyGUI page. |
jmitc91516 | 1:a5258871b33d | 36 | |
jmitc91516 | 1:a5258871b33d | 37 | Defined in main.cpp - and omits the 'ALLOW_DEBUG_PRINTS' #define |
jmitc91516 | 1:a5258871b33d | 38 | */ |
jmitc91516 | 1:a5258871b33d | 39 | extern void SpecialDebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y); |
jmitc91516 | 1:a5258871b33d | 40 | |
jmitc91516 | 1:a5258871b33d | 41 | |
jmitc91516 | 1:a5258871b33d | 42 | |
jmitc91516 | 1:a5258871b33d | 43 | /* |
jmitc91516 | 1:a5258871b33d | 44 | Note that this class is a singleton - we do not need or want there to be more than one instance of it |
jmitc91516 | 1:a5258871b33d | 45 | (we do not want multiple values for the IP address, etc, nor will we show |
jmitc91516 | 1:a5258871b33d | 46 | more than one easyGUI 'EthernetParametersPage' to the user at the same time). |
jmitc91516 | 1:a5258871b33d | 47 | */ |
jmitc91516 | 1:a5258871b33d | 48 | NetworkParameters * NetworkParameters::theNetworkParametersInstance = NULL; |
jmitc91516 | 1:a5258871b33d | 49 | |
jmitc91516 | 1:a5258871b33d | 50 | |
jmitc91516 | 1:a5258871b33d | 51 | /* |
jmitc91516 | 1:a5258871b33d | 52 | We distinguish the 'active' field - i.e. the one being edited by the user - |
jmitc91516 | 1:a5258871b33d | 53 | from the inactive fields, by its background colour |
jmitc91516 | 1:a5258871b33d | 54 | */ |
jmitc91516 | 1:a5258871b33d | 55 | #define EXPERIMENTING_WITH_COLORS |
jmitc91516 | 1:a5258871b33d | 56 | const GuiConst_INTCOLOR NetworkParameters::inactiveFieldBackgroundColour = SixteenBitColorValue(192, 192, 192); // Grey |
jmitc91516 | 1:a5258871b33d | 57 | #ifdef EXPERIMENTING_WITH_COLORS |
jmitc91516 | 1:a5258871b33d | 58 | const GuiConst_INTCOLOR NetworkParameters::activeFieldBackgroundColour = SixteenBitColorValue(255, 255, 0); // Yellow |
jmitc91516 | 1:a5258871b33d | 59 | #else |
jmitc91516 | 1:a5258871b33d | 60 | const GuiConst_INTCOLOR NetworkParameters::activeFieldBackgroundColour = SixteenBitColorValue(255, 255, 255); // White |
jmitc91516 | 1:a5258871b33d | 61 | #endif // EXPERIMENTING_WITH_COLORS |
jmitc91516 | 1:a5258871b33d | 62 | |
jmitc91516 | 1:a5258871b33d | 63 | //#define USE_BACKGROUND_COLOURS // Else leave them all white |
jmitc91516 | 1:a5258871b33d | 64 | //#define TOUCH_VALUES_DIRECTLY |
jmitc91516 | 1:a5258871b33d | 65 | |
jmitc91516 | 1:a5258871b33d | 66 | /* |
jmitc91516 | 1:a5258871b33d | 67 | Convenient default values |
jmitc91516 | 1:a5258871b33d | 68 | */ |
jmitc91516 | 1:a5258871b33d | 69 | const unsigned int NetworkParameters::defaultPortNumber = 3456; |
jmitc91516 | 1:a5258871b33d | 70 | const unsigned int NetworkParameters::defaultIPAddress[4] = {192, 168, 1, 200}; |
jmitc91516 | 1:a5258871b33d | 71 | const unsigned int NetworkParameters::defaultSubnetMask[4] = {255, 255, 255, 0}; |
jmitc91516 | 1:a5258871b33d | 72 | const unsigned int NetworkParameters::defaultGatewayAddress[4] = {192, 168, 1, 254}; |
jmitc91516 | 1:a5258871b33d | 73 | |
jmitc91516 | 1:a5258871b33d | 74 | |
jmitc91516 | 1:a5258871b33d | 75 | /* |
jmitc91516 | 1:a5258871b33d | 76 | Singleton class - return the one and only instance, first creating it if necessary. |
jmitc91516 | 1:a5258871b33d | 77 | */ |
jmitc91516 | 1:a5258871b33d | 78 | NetworkParameters * NetworkParameters::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 79 | { |
jmitc91516 | 1:a5258871b33d | 80 | if (theNetworkParametersInstance == NULL) { |
jmitc91516 | 1:a5258871b33d | 81 | theNetworkParametersInstance = new NetworkParameters(newUsbDevice, newUsbHostGC); |
jmitc91516 | 1:a5258871b33d | 82 | } |
jmitc91516 | 1:a5258871b33d | 83 | |
jmitc91516 | 1:a5258871b33d | 84 | return theNetworkParametersInstance; |
jmitc91516 | 1:a5258871b33d | 85 | } |
jmitc91516 | 1:a5258871b33d | 86 | |
jmitc91516 | 1:a5258871b33d | 87 | // Singleton class - private constructor |
jmitc91516 | 1:a5258871b33d | 88 | NetworkParameters::NetworkParameters(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 89 | { |
jmitc91516 | 1:a5258871b33d | 90 | // Note that we do not use these values here - |
jmitc91516 | 1:a5258871b33d | 91 | // but we do need to pass them to the (main.cpp) function DisplayEasyGUIStructure |
jmitc91516 | 1:a5258871b33d | 92 | usbDevice = newUsbDevice; |
jmitc91516 | 1:a5258871b33d | 93 | usbHostGC = newUsbHostGC; |
jmitc91516 | 1:a5258871b33d | 94 | |
jmitc91516 | 1:a5258871b33d | 95 | portNumber = defaultPortNumber; |
jmitc91516 | 1:a5258871b33d | 96 | |
jmitc91516 | 1:a5258871b33d | 97 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 98 | ipAddress[index] = defaultIPAddress[index]; |
jmitc91516 | 1:a5258871b33d | 99 | subnetMask[index] = defaultSubnetMask[index]; |
jmitc91516 | 1:a5258871b33d | 100 | gatewayAddress[index] = defaultGatewayAddress[index]; |
jmitc91516 | 1:a5258871b33d | 101 | } |
jmitc91516 | 1:a5258871b33d | 102 | |
jmitc91516 | 1:a5258871b33d | 103 | useDHCP = false; |
jmitc91516 | 1:a5258871b33d | 104 | |
jmitc91516 | 1:a5258871b33d | 105 | ReadFromQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 106 | |
jmitc91516 | 1:a5258871b33d | 107 | //#define WANT_ETHERNET_DEBUG |
jmitc91516 | 1:a5258871b33d | 108 | #ifdef WANT_ETHERNET_DEBUG |
jmitc91516 | 1:a5258871b33d | 109 | char dbg[600]; |
jmitc91516 | 1:a5258871b33d | 110 | int dbg1; |
jmitc91516 | 1:a5258871b33d | 111 | char dbg2[100]; |
jmitc91516 | 1:a5258871b33d | 112 | char dbg3[100]; |
jmitc91516 | 1:a5258871b33d | 113 | char dbg4[100]; |
jmitc91516 | 1:a5258871b33d | 114 | int dbg5; |
jmitc91516 | 1:a5258871b33d | 115 | |
jmitc91516 | 1:a5258871b33d | 116 | dbg1 = GetPortNumber(); |
jmitc91516 | 1:a5258871b33d | 117 | GetIPAddressAsString(dbg2); |
jmitc91516 | 1:a5258871b33d | 118 | GetSubnetMaskAsString(dbg3); |
jmitc91516 | 1:a5258871b33d | 119 | GetGatewayAddressAsString(dbg4); |
jmitc91516 | 1:a5258871b33d | 120 | dbg5 = GetUseDHCP(); |
jmitc91516 | 1:a5258871b33d | 121 | |
jmitc91516 | 1:a5258871b33d | 122 | sprintf(dbg, "Ethernet port: %d, IP: \"%s\", mask: \"%s\", gateway: \"%s\", useDHCP: %d", dbg1, dbg2, dbg3, dbg4, dbg5); |
jmitc91516 | 1:a5258871b33d | 123 | SpecialDebugPrint(dbg, 100, 70); |
jmitc91516 | 1:a5258871b33d | 124 | #undef WANT_ETHERNET_DEBUG |
jmitc91516 | 1:a5258871b33d | 125 | #endif // WANT_ETHERNET_DEBUG |
jmitc91516 | 1:a5258871b33d | 126 | |
jmitc91516 | 1:a5258871b33d | 127 | indexOfVariablesCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 128 | |
jmitc91516 | 1:a5258871b33d | 129 | variablesForTouchArea[0].touchAreaIndex = NETWORK_PARAMS_PORT_VALUE; |
jmitc91516 | 1:a5258871b33d | 130 | variablesForTouchArea[0].easyGUIVariablePtr = GuiVar_ethernetPort; |
jmitc91516 | 1:a5258871b33d | 131 | variablesForTouchArea[0].internalVariablePtr = &portNumber; |
jmitc91516 | 1:a5258871b33d | 132 | variablesForTouchArea[0].maxValue = 65535; |
jmitc91516 | 1:a5258871b33d | 133 | variablesForTouchArea[0].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetPortBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 134 | strcpy(variablesForTouchArea[0].variableName, "Port"); |
jmitc91516 | 1:a5258871b33d | 135 | |
jmitc91516 | 1:a5258871b33d | 136 | |
jmitc91516 | 1:a5258871b33d | 137 | variablesForTouchArea[1].touchAreaIndex = NETWORK_PARAMS_IP1_VALUE; |
jmitc91516 | 1:a5258871b33d | 138 | variablesForTouchArea[1].easyGUIVariablePtr = GuiVar_ethernetIP1; |
jmitc91516 | 1:a5258871b33d | 139 | variablesForTouchArea[1].internalVariablePtr = &(ipAddress[0]); |
jmitc91516 | 1:a5258871b33d | 140 | variablesForTouchArea[1].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 141 | variablesForTouchArea[1].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetIP1BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 142 | strcpy(variablesForTouchArea[1].variableName, "IP Address 1"); |
jmitc91516 | 1:a5258871b33d | 143 | |
jmitc91516 | 1:a5258871b33d | 144 | variablesForTouchArea[2].touchAreaIndex = NETWORK_PARAMS_IP2_VALUE; |
jmitc91516 | 1:a5258871b33d | 145 | variablesForTouchArea[2].easyGUIVariablePtr = GuiVar_ethernetIP2; |
jmitc91516 | 1:a5258871b33d | 146 | variablesForTouchArea[2].internalVariablePtr = &(ipAddress[1]); |
jmitc91516 | 1:a5258871b33d | 147 | variablesForTouchArea[2].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 148 | variablesForTouchArea[2].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetIP2BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 149 | strcpy(variablesForTouchArea[2].variableName, "IP Address 2"); |
jmitc91516 | 1:a5258871b33d | 150 | |
jmitc91516 | 1:a5258871b33d | 151 | variablesForTouchArea[3].touchAreaIndex = NETWORK_PARAMS_IP3_VALUE; |
jmitc91516 | 1:a5258871b33d | 152 | variablesForTouchArea[3].easyGUIVariablePtr = GuiVar_ethernetIP3; |
jmitc91516 | 1:a5258871b33d | 153 | variablesForTouchArea[3].internalVariablePtr = &(ipAddress[2]); |
jmitc91516 | 1:a5258871b33d | 154 | variablesForTouchArea[3].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 155 | variablesForTouchArea[3].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetIP3BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 156 | strcpy(variablesForTouchArea[3].variableName, "IP Address 3"); |
jmitc91516 | 1:a5258871b33d | 157 | |
jmitc91516 | 1:a5258871b33d | 158 | variablesForTouchArea[4].touchAreaIndex = NETWORK_PARAMS_IP4_VALUE; |
jmitc91516 | 1:a5258871b33d | 159 | variablesForTouchArea[4].easyGUIVariablePtr = GuiVar_ethernetIP4; |
jmitc91516 | 1:a5258871b33d | 160 | variablesForTouchArea[4].internalVariablePtr = &(ipAddress[3]); |
jmitc91516 | 1:a5258871b33d | 161 | variablesForTouchArea[4].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 162 | variablesForTouchArea[4].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetIP4BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 163 | strcpy(variablesForTouchArea[4].variableName, "IP Address 4"); |
jmitc91516 | 1:a5258871b33d | 164 | |
jmitc91516 | 1:a5258871b33d | 165 | |
jmitc91516 | 1:a5258871b33d | 166 | variablesForTouchArea[5].touchAreaIndex = NETWORK_PARAMS_MASK1_VALUE; |
jmitc91516 | 1:a5258871b33d | 167 | variablesForTouchArea[5].easyGUIVariablePtr = GuiVar_ethernetMask1; |
jmitc91516 | 1:a5258871b33d | 168 | variablesForTouchArea[5].internalVariablePtr = &(subnetMask[0]); |
jmitc91516 | 1:a5258871b33d | 169 | variablesForTouchArea[5].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 170 | variablesForTouchArea[5].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetMask1BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 171 | strcpy(variablesForTouchArea[5].variableName, "Subnet mask 1"); |
jmitc91516 | 1:a5258871b33d | 172 | |
jmitc91516 | 1:a5258871b33d | 173 | variablesForTouchArea[6].touchAreaIndex = NETWORK_PARAMS_MASK2_VALUE; |
jmitc91516 | 1:a5258871b33d | 174 | variablesForTouchArea[6].easyGUIVariablePtr = GuiVar_ethernetMask2; |
jmitc91516 | 1:a5258871b33d | 175 | variablesForTouchArea[6].internalVariablePtr = &(subnetMask[1]); |
jmitc91516 | 1:a5258871b33d | 176 | variablesForTouchArea[6].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 177 | variablesForTouchArea[6].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetMask2BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 178 | strcpy(variablesForTouchArea[6].variableName, "Subnet mask 2"); |
jmitc91516 | 1:a5258871b33d | 179 | |
jmitc91516 | 1:a5258871b33d | 180 | variablesForTouchArea[7].touchAreaIndex = NETWORK_PARAMS_MASK3_VALUE; |
jmitc91516 | 1:a5258871b33d | 181 | variablesForTouchArea[7].easyGUIVariablePtr = GuiVar_ethernetMask3; |
jmitc91516 | 1:a5258871b33d | 182 | variablesForTouchArea[7].internalVariablePtr = &(subnetMask[2]); |
jmitc91516 | 1:a5258871b33d | 183 | variablesForTouchArea[7].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 184 | variablesForTouchArea[7].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetMask3BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 185 | strcpy(variablesForTouchArea[7].variableName, "Subnet mask 3"); |
jmitc91516 | 1:a5258871b33d | 186 | |
jmitc91516 | 1:a5258871b33d | 187 | variablesForTouchArea[8].touchAreaIndex = NETWORK_PARAMS_MASK4_VALUE; |
jmitc91516 | 1:a5258871b33d | 188 | variablesForTouchArea[8].easyGUIVariablePtr = GuiVar_ethernetMask4; |
jmitc91516 | 1:a5258871b33d | 189 | variablesForTouchArea[8].internalVariablePtr = &(subnetMask[3]); |
jmitc91516 | 1:a5258871b33d | 190 | variablesForTouchArea[8].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 191 | variablesForTouchArea[8].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetMask4BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 192 | strcpy(variablesForTouchArea[8].variableName, "Subnet mask 4"); |
jmitc91516 | 1:a5258871b33d | 193 | |
jmitc91516 | 1:a5258871b33d | 194 | |
jmitc91516 | 1:a5258871b33d | 195 | variablesForTouchArea[9].touchAreaIndex = NETWORK_PARAMS_GATEWAY1_VALUE; |
jmitc91516 | 1:a5258871b33d | 196 | variablesForTouchArea[9].easyGUIVariablePtr = GuiVar_ethernetGateway1; |
jmitc91516 | 1:a5258871b33d | 197 | variablesForTouchArea[9].internalVariablePtr = &(gatewayAddress[0]); |
jmitc91516 | 1:a5258871b33d | 198 | variablesForTouchArea[9].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 199 | variablesForTouchArea[9].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetGateway1BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 200 | strcpy(variablesForTouchArea[9].variableName, "Gateway 1"); |
jmitc91516 | 1:a5258871b33d | 201 | |
jmitc91516 | 1:a5258871b33d | 202 | variablesForTouchArea[10].touchAreaIndex = NETWORK_PARAMS_GATEWAY2_VALUE; |
jmitc91516 | 1:a5258871b33d | 203 | variablesForTouchArea[10].easyGUIVariablePtr = GuiVar_ethernetGateway2; |
jmitc91516 | 1:a5258871b33d | 204 | variablesForTouchArea[10].internalVariablePtr = &(gatewayAddress[1]); |
jmitc91516 | 1:a5258871b33d | 205 | variablesForTouchArea[10].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 206 | variablesForTouchArea[10].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetGateway2BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 207 | strcpy(variablesForTouchArea[10].variableName, "Gateway 2"); |
jmitc91516 | 1:a5258871b33d | 208 | |
jmitc91516 | 1:a5258871b33d | 209 | variablesForTouchArea[11].touchAreaIndex = NETWORK_PARAMS_GATEWAY3_VALUE; |
jmitc91516 | 1:a5258871b33d | 210 | variablesForTouchArea[11].easyGUIVariablePtr = GuiVar_ethernetGateway3; |
jmitc91516 | 1:a5258871b33d | 211 | variablesForTouchArea[11].internalVariablePtr = &(gatewayAddress[2]); |
jmitc91516 | 1:a5258871b33d | 212 | variablesForTouchArea[11].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 213 | variablesForTouchArea[11].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetGateway3BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 214 | strcpy(variablesForTouchArea[11].variableName, "Gateway 3"); |
jmitc91516 | 1:a5258871b33d | 215 | |
jmitc91516 | 1:a5258871b33d | 216 | variablesForTouchArea[12].touchAreaIndex = NETWORK_PARAMS_GATEWAY4_VALUE; |
jmitc91516 | 1:a5258871b33d | 217 | variablesForTouchArea[12].easyGUIVariablePtr = GuiVar_ethernetGateway4; |
jmitc91516 | 1:a5258871b33d | 218 | variablesForTouchArea[12].internalVariablePtr = &(gatewayAddress[3]); |
jmitc91516 | 1:a5258871b33d | 219 | variablesForTouchArea[12].maxValue = 255; |
jmitc91516 | 1:a5258871b33d | 220 | variablesForTouchArea[12].easyGUIBackgroundColorVariablePtr = &GuiVar_ethernetGateway4BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 221 | strcpy(variablesForTouchArea[12].variableName, "Gateway 4"); |
jmitc91516 | 1:a5258871b33d | 222 | } |
jmitc91516 | 1:a5258871b33d | 223 | |
jmitc91516 | 1:a5258871b33d | 224 | |
jmitc91516 | 1:a5258871b33d | 225 | // Private destructor also |
jmitc91516 | 1:a5258871b33d | 226 | NetworkParameters::~NetworkParameters() |
jmitc91516 | 1:a5258871b33d | 227 | { |
jmitc91516 | 1:a5258871b33d | 228 | } |
jmitc91516 | 1:a5258871b33d | 229 | |
jmitc91516 | 1:a5258871b33d | 230 | |
jmitc91516 | 1:a5258871b33d | 231 | /* |
jmitc91516 | 1:a5258871b33d | 232 | Saves the current parameter values to QSPI settings, |
jmitc91516 | 1:a5258871b33d | 233 | so they are maintained even when the user powers off |
jmitc91516 | 1:a5258871b33d | 234 | |
jmitc91516 | 1:a5258871b33d | 235 | No arguments, no return value |
jmitc91516 | 1:a5258871b33d | 236 | */ |
jmitc91516 | 1:a5258871b33d | 237 | void NetworkParameters::SaveToQSPISettings(void) |
jmitc91516 | 1:a5258871b33d | 238 | { |
jmitc91516 | 1:a5258871b33d | 239 | // Put values to QSPI settings, using SettingsHandler member functions |
jmitc91516 | 1:a5258871b33d | 240 | |
jmitc91516 | 1:a5258871b33d | 241 | SettingsHandler::PutIntegerValueToQSPISettings("PortNumber", portNumber); |
jmitc91516 | 1:a5258871b33d | 242 | |
jmitc91516 | 1:a5258871b33d | 243 | SettingsHandler::PutIntegerValueToQSPISettings("IPAddress0", ipAddress[0]); |
jmitc91516 | 1:a5258871b33d | 244 | SettingsHandler::PutIntegerValueToQSPISettings("IPAddress1", ipAddress[1]); |
jmitc91516 | 1:a5258871b33d | 245 | SettingsHandler::PutIntegerValueToQSPISettings("IPAddress2", ipAddress[2]); |
jmitc91516 | 1:a5258871b33d | 246 | SettingsHandler::PutIntegerValueToQSPISettings("IPAddress3", ipAddress[3]); |
jmitc91516 | 1:a5258871b33d | 247 | |
jmitc91516 | 1:a5258871b33d | 248 | SettingsHandler::PutIntegerValueToQSPISettings("SubnetMask0", subnetMask[0]); |
jmitc91516 | 1:a5258871b33d | 249 | SettingsHandler::PutIntegerValueToQSPISettings("SubnetMask1", subnetMask[1]); |
jmitc91516 | 1:a5258871b33d | 250 | SettingsHandler::PutIntegerValueToQSPISettings("SubnetMask2", subnetMask[2]); |
jmitc91516 | 1:a5258871b33d | 251 | SettingsHandler::PutIntegerValueToQSPISettings("SubnetMask3", subnetMask[3]); |
jmitc91516 | 1:a5258871b33d | 252 | |
jmitc91516 | 1:a5258871b33d | 253 | SettingsHandler::PutIntegerValueToQSPISettings("GatewayAddress0", gatewayAddress[0]); |
jmitc91516 | 1:a5258871b33d | 254 | SettingsHandler::PutIntegerValueToQSPISettings("GatewayAddress1", gatewayAddress[1]); |
jmitc91516 | 1:a5258871b33d | 255 | SettingsHandler::PutIntegerValueToQSPISettings("GatewayAddress2", gatewayAddress[2]); |
jmitc91516 | 1:a5258871b33d | 256 | SettingsHandler::PutIntegerValueToQSPISettings("GatewayAddress3", gatewayAddress[3]); |
jmitc91516 | 1:a5258871b33d | 257 | |
jmitc91516 | 1:a5258871b33d | 258 | SettingsHandler::PutIntegerValueToQSPISettings("UseDHCP", (useDHCP ? 1 : 0) ); |
jmitc91516 | 1:a5258871b33d | 259 | } |
jmitc91516 | 1:a5258871b33d | 260 | |
jmitc91516 | 1:a5258871b33d | 261 | |
jmitc91516 | 1:a5258871b33d | 262 | /* |
jmitc91516 | 1:a5258871b33d | 263 | Reads the current parameter values from QSPI settings, |
jmitc91516 | 1:a5258871b33d | 264 | so they are maintained even when the user powers off |
jmitc91516 | 1:a5258871b33d | 265 | |
jmitc91516 | 1:a5258871b33d | 266 | No arguments, no return value |
jmitc91516 | 1:a5258871b33d | 267 | */ |
jmitc91516 | 1:a5258871b33d | 268 | void NetworkParameters::ReadFromQSPISettings(void) |
jmitc91516 | 1:a5258871b33d | 269 | { |
jmitc91516 | 1:a5258871b33d | 270 | // Get values from QSPI settings, using SettingsHandler member functions |
jmitc91516 | 1:a5258871b33d | 271 | |
jmitc91516 | 1:a5258871b33d | 272 | portNumber = SettingsHandler::GetIntegerValueFromQSPISettings("PortNumber", defaultPortNumber); |
jmitc91516 | 1:a5258871b33d | 273 | |
jmitc91516 | 1:a5258871b33d | 274 | ipAddress[0] = SettingsHandler::GetIntegerValueFromQSPISettings("IPAddress0", defaultIPAddress[0]); |
jmitc91516 | 1:a5258871b33d | 275 | ipAddress[1] = SettingsHandler::GetIntegerValueFromQSPISettings("IPAddress1", defaultIPAddress[1]); |
jmitc91516 | 1:a5258871b33d | 276 | ipAddress[2] = SettingsHandler::GetIntegerValueFromQSPISettings("IPAddress2", defaultIPAddress[2]); |
jmitc91516 | 1:a5258871b33d | 277 | ipAddress[3] = SettingsHandler::GetIntegerValueFromQSPISettings("IPAddress3", defaultIPAddress[3]); |
jmitc91516 | 1:a5258871b33d | 278 | |
jmitc91516 | 1:a5258871b33d | 279 | subnetMask[0] = SettingsHandler::GetIntegerValueFromQSPISettings("SubnetMask0", defaultSubnetMask[0]); |
jmitc91516 | 1:a5258871b33d | 280 | subnetMask[1] = SettingsHandler::GetIntegerValueFromQSPISettings("SubnetMask1", defaultSubnetMask[1]); |
jmitc91516 | 1:a5258871b33d | 281 | subnetMask[2] = SettingsHandler::GetIntegerValueFromQSPISettings("SubnetMask2", defaultSubnetMask[2]); |
jmitc91516 | 1:a5258871b33d | 282 | subnetMask[3] = SettingsHandler::GetIntegerValueFromQSPISettings("SubnetMask3", defaultSubnetMask[3]); |
jmitc91516 | 1:a5258871b33d | 283 | |
jmitc91516 | 1:a5258871b33d | 284 | gatewayAddress[0] = SettingsHandler::GetIntegerValueFromQSPISettings("GatewayAddress0", defaultGatewayAddress[0]); |
jmitc91516 | 1:a5258871b33d | 285 | gatewayAddress[1] = SettingsHandler::GetIntegerValueFromQSPISettings("GatewayAddress1", defaultGatewayAddress[1]); |
jmitc91516 | 1:a5258871b33d | 286 | gatewayAddress[2] = SettingsHandler::GetIntegerValueFromQSPISettings("GatewayAddress2", defaultGatewayAddress[2]); |
jmitc91516 | 1:a5258871b33d | 287 | gatewayAddress[3] = SettingsHandler::GetIntegerValueFromQSPISettings("GatewayAddress3", defaultGatewayAddress[3]); |
jmitc91516 | 1:a5258871b33d | 288 | |
jmitc91516 | 1:a5258871b33d | 289 | useDHCP = (SettingsHandler::GetIntegerValueFromQSPISettings("UseDHCP", 0) != 0); // Default to false |
jmitc91516 | 1:a5258871b33d | 290 | } |
jmitc91516 | 1:a5258871b33d | 291 | |
jmitc91516 | 1:a5258871b33d | 292 | /* |
jmitc91516 | 1:a5258871b33d | 293 | Gets the current parameters - i.e. the values we are actually using |
jmitc91516 | 1:a5258871b33d | 294 | for the Ethernet link - from the specified EthernetInterface instance, |
jmitc91516 | 1:a5258871b33d | 295 | and saves them as the "real" values, so that we can restore them |
jmitc91516 | 1:a5258871b33d | 296 | (a) on entering the page (called from TouchCallback in main.cpp), |
jmitc91516 | 1:a5258871b33d | 297 | and (b) when the user presses Cancel. |
jmitc91516 | 1:a5258871b33d | 298 | |
jmitc91516 | 1:a5258871b33d | 299 | Args: a pointer to the EthernetInterface instance |
jmitc91516 | 1:a5258871b33d | 300 | |
jmitc91516 | 1:a5258871b33d | 301 | No return code |
jmitc91516 | 1:a5258871b33d | 302 | */ |
jmitc91516 | 1:a5258871b33d | 303 | void NetworkParameters::SaveRealValues(EthernetInterface *eth) |
jmitc91516 | 1:a5258871b33d | 304 | { |
jmitc91516 | 1:a5258871b33d | 305 | realPortNumber = portNumber; |
jmitc91516 | 1:a5258871b33d | 306 | |
jmitc91516 | 1:a5258871b33d | 307 | SetIPAddressFromString(eth->getIPAddress()); |
jmitc91516 | 1:a5258871b33d | 308 | SetSubnetMaskFromString(eth->getNetworkMask()); |
jmitc91516 | 1:a5258871b33d | 309 | SetGatewayAddressFromString(eth->getGateway()); |
jmitc91516 | 1:a5258871b33d | 310 | |
jmitc91516 | 1:a5258871b33d | 311 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 312 | realIPAddress[index] = ipAddress[index]; |
jmitc91516 | 1:a5258871b33d | 313 | realSubnetMask[index] = subnetMask[index]; |
jmitc91516 | 1:a5258871b33d | 314 | realGatewayAddress[index] = gatewayAddress[index]; |
jmitc91516 | 1:a5258871b33d | 315 | } |
jmitc91516 | 1:a5258871b33d | 316 | } |
jmitc91516 | 1:a5258871b33d | 317 | |
jmitc91516 | 1:a5258871b33d | 318 | |
jmitc91516 | 1:a5258871b33d | 319 | /* |
jmitc91516 | 1:a5258871b33d | 320 | Restores the current parameter values to the 'real' values. |
jmitc91516 | 1:a5258871b33d | 321 | It is up the caller to display these to the user. |
jmitc91516 | 1:a5258871b33d | 322 | ************************************************ |
jmitc91516 | 1:a5258871b33d | 323 | |
jmitc91516 | 1:a5258871b33d | 324 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 325 | */ |
jmitc91516 | 1:a5258871b33d | 326 | void NetworkParameters::RestoreRealValues(void) |
jmitc91516 | 1:a5258871b33d | 327 | { |
jmitc91516 | 1:a5258871b33d | 328 | portNumber = realPortNumber; |
jmitc91516 | 1:a5258871b33d | 329 | |
jmitc91516 | 1:a5258871b33d | 330 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 331 | ipAddress[index] = realIPAddress[index]; |
jmitc91516 | 1:a5258871b33d | 332 | subnetMask[index] = realSubnetMask[index]; |
jmitc91516 | 1:a5258871b33d | 333 | gatewayAddress[index] = realGatewayAddress[index]; |
jmitc91516 | 1:a5258871b33d | 334 | } |
jmitc91516 | 1:a5258871b33d | 335 | } |
jmitc91516 | 1:a5258871b33d | 336 | |
jmitc91516 | 1:a5258871b33d | 337 | |
jmitc91516 | 1:a5258871b33d | 338 | /* |
jmitc91516 | 1:a5258871b33d | 339 | Sets the background colours of all 'editable' fields to the 'inactive' colour. |
jmitc91516 | 1:a5258871b33d | 340 | |
jmitc91516 | 1:a5258871b33d | 341 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 342 | */ |
jmitc91516 | 1:a5258871b33d | 343 | void NetworkParameters::SetAllFieldBackgroundColoursToInactive(void) |
jmitc91516 | 1:a5258871b33d | 344 | { |
jmitc91516 | 1:a5258871b33d | 345 | GuiVar_ethernetPortBackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 346 | |
jmitc91516 | 1:a5258871b33d | 347 | GuiVar_ethernetIP1BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 348 | GuiVar_ethernetIP2BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 349 | GuiVar_ethernetIP3BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 350 | GuiVar_ethernetIP4BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 351 | |
jmitc91516 | 1:a5258871b33d | 352 | GuiVar_ethernetMask1BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 353 | GuiVar_ethernetMask2BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 354 | GuiVar_ethernetMask3BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 355 | GuiVar_ethernetMask4BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 356 | |
jmitc91516 | 1:a5258871b33d | 357 | GuiVar_ethernetGateway1BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 358 | GuiVar_ethernetGateway2BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 359 | GuiVar_ethernetGateway3BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 360 | GuiVar_ethernetGateway4BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 361 | } |
jmitc91516 | 1:a5258871b33d | 362 | |
jmitc91516 | 1:a5258871b33d | 363 | /* |
jmitc91516 | 1:a5258871b33d | 364 | Sets the background colours of all 'editable' fields to the 'inactive' colour. |
jmitc91516 | 1:a5258871b33d | 365 | |
jmitc91516 | 1:a5258871b33d | 366 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 367 | */ |
jmitc91516 | 1:a5258871b33d | 368 | void NetworkParameters::SetAllFieldBackgroundColoursToWhite(void) |
jmitc91516 | 1:a5258871b33d | 369 | { |
jmitc91516 | 1:a5258871b33d | 370 | GuiVar_ethernetPortBackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 371 | |
jmitc91516 | 1:a5258871b33d | 372 | GuiVar_ethernetIP1BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 373 | GuiVar_ethernetIP2BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 374 | GuiVar_ethernetIP3BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 375 | GuiVar_ethernetIP4BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 376 | |
jmitc91516 | 1:a5258871b33d | 377 | GuiVar_ethernetMask1BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 378 | GuiVar_ethernetMask2BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 379 | GuiVar_ethernetMask3BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 380 | GuiVar_ethernetMask4BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 381 | |
jmitc91516 | 1:a5258871b33d | 382 | GuiVar_ethernetGateway1BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 383 | GuiVar_ethernetGateway2BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 384 | GuiVar_ethernetGateway3BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 385 | GuiVar_ethernetGateway4BackgroundColour = 0xFFFF; |
jmitc91516 | 1:a5258871b33d | 386 | } |
jmitc91516 | 1:a5258871b33d | 387 | |
jmitc91516 | 1:a5258871b33d | 388 | |
jmitc91516 | 1:a5258871b33d | 389 | /* |
jmitc91516 | 1:a5258871b33d | 390 | Caller is telling us it is about to display the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 391 | and that we should do whatever we have to do to get it ready, |
jmitc91516 | 1:a5258871b33d | 392 | before the caller displays it. |
jmitc91516 | 1:a5258871b33d | 393 | |
jmitc91516 | 1:a5258871b33d | 394 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 395 | */ |
jmitc91516 | 1:a5258871b33d | 396 | void NetworkParameters::DisplayingEasyGUIPage(bool updateEasyGUIVariables) |
jmitc91516 | 1:a5258871b33d | 397 | { |
jmitc91516 | 1:a5258871b33d | 398 | if(updateEasyGUIVariables) { |
jmitc91516 | 1:a5258871b33d | 399 | UpdateEasyGUIVariablesFromInternalValues(); |
jmitc91516 | 1:a5258871b33d | 400 | } |
jmitc91516 | 1:a5258871b33d | 401 | |
jmitc91516 | 1:a5258871b33d | 402 | #ifdef USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 403 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 404 | #else |
jmitc91516 | 1:a5258871b33d | 405 | SetAllFieldBackgroundColoursToWhite(); |
jmitc91516 | 1:a5258871b33d | 406 | #endif |
jmitc91516 | 1:a5258871b33d | 407 | |
jmitc91516 | 1:a5258871b33d | 408 | indexOfVariablesCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 409 | |
jmitc91516 | 1:a5258871b33d | 410 | // UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 411 | } |
jmitc91516 | 1:a5258871b33d | 412 | |
jmitc91516 | 1:a5258871b33d | 413 | |
jmitc91516 | 1:a5258871b33d | 414 | /* |
jmitc91516 | 1:a5258871b33d | 415 | Outputs the port number as a null-terminated string, in the form of an integer |
jmitc91516 | 1:a5258871b33d | 416 | with 1-5 digits. If the value is zero, it will be returned as "0", not as an empty string. |
jmitc91516 | 1:a5258871b33d | 417 | |
jmitc91516 | 1:a5258871b33d | 418 | Args: a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 419 | It is up to the caller to make sure this is long enough, i.e. at least 6 bytes long |
jmitc91516 | 1:a5258871b33d | 420 | ********************** |
jmitc91516 | 1:a5258871b33d | 421 | No return code |
jmitc91516 | 1:a5258871b33d | 422 | */ |
jmitc91516 | 1:a5258871b33d | 423 | void NetworkParameters::GetPortNumberAsString(char *portBuffer) |
jmitc91516 | 1:a5258871b33d | 424 | { |
jmitc91516 | 1:a5258871b33d | 425 | if(portNumber == 0) { |
jmitc91516 | 1:a5258871b33d | 426 | portBuffer[0] = '0'; |
jmitc91516 | 1:a5258871b33d | 427 | portBuffer[1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 428 | |
jmitc91516 | 1:a5258871b33d | 429 | return; |
jmitc91516 | 1:a5258871b33d | 430 | } |
jmitc91516 | 1:a5258871b33d | 431 | |
jmitc91516 | 1:a5258871b33d | 432 | if(portNumber >= 65535) { |
jmitc91516 | 1:a5258871b33d | 433 | portBuffer[0] = '6'; |
jmitc91516 | 1:a5258871b33d | 434 | portBuffer[1] = '5'; |
jmitc91516 | 1:a5258871b33d | 435 | portBuffer[2] = '5'; |
jmitc91516 | 1:a5258871b33d | 436 | portBuffer[3] = '3'; |
jmitc91516 | 1:a5258871b33d | 437 | portBuffer[4] = '5'; |
jmitc91516 | 1:a5258871b33d | 438 | portBuffer[5] = '\0'; |
jmitc91516 | 1:a5258871b33d | 439 | |
jmitc91516 | 1:a5258871b33d | 440 | return; |
jmitc91516 | 1:a5258871b33d | 441 | } |
jmitc91516 | 1:a5258871b33d | 442 | |
jmitc91516 | 1:a5258871b33d | 443 | // 'else' - value is between 0 and 65535 |
jmitc91516 | 1:a5258871b33d | 444 | sprintf(portBuffer, "%5u", portNumber); |
jmitc91516 | 1:a5258871b33d | 445 | return; |
jmitc91516 | 1:a5258871b33d | 446 | |
jmitc91516 | 1:a5258871b33d | 447 | } |
jmitc91516 | 1:a5258871b33d | 448 | |
jmitc91516 | 1:a5258871b33d | 449 | |
jmitc91516 | 1:a5258871b33d | 450 | /* |
jmitc91516 | 1:a5258871b33d | 451 | Set the port number from a null-terminated string |
jmitc91516 | 1:a5258871b33d | 452 | |
jmitc91516 | 1:a5258871b33d | 453 | Args: a pointer to a buffer that contains the string. |
jmitc91516 | 1:a5258871b33d | 454 | |
jmitc91516 | 1:a5258871b33d | 455 | No return code |
jmitc91516 | 1:a5258871b33d | 456 | */ |
jmitc91516 | 1:a5258871b33d | 457 | void NetworkParameters::SetPortNumberFromString(char *portBuffer) |
jmitc91516 | 1:a5258871b33d | 458 | { |
jmitc91516 | 1:a5258871b33d | 459 | unsigned int temp; |
jmitc91516 | 1:a5258871b33d | 460 | sscanf(portBuffer, "%u", &temp); |
jmitc91516 | 1:a5258871b33d | 461 | |
jmitc91516 | 1:a5258871b33d | 462 | // 'temp' is unsigned, so cannot be less than zero |
jmitc91516 | 1:a5258871b33d | 463 | if(temp > 65535) { |
jmitc91516 | 1:a5258871b33d | 464 | portNumber = 65535; |
jmitc91516 | 1:a5258871b33d | 465 | return; |
jmitc91516 | 1:a5258871b33d | 466 | } |
jmitc91516 | 1:a5258871b33d | 467 | |
jmitc91516 | 1:a5258871b33d | 468 | // 'else' |
jmitc91516 | 1:a5258871b33d | 469 | portNumber = temp; |
jmitc91516 | 1:a5258871b33d | 470 | } |
jmitc91516 | 1:a5258871b33d | 471 | |
jmitc91516 | 1:a5258871b33d | 472 | |
jmitc91516 | 1:a5258871b33d | 473 | /* |
jmitc91516 | 1:a5258871b33d | 474 | Outputs the specified field of the IP address as a null-terminated string, in the form of an integer |
jmitc91516 | 1:a5258871b33d | 475 | with 1-3 digits. If the value is zero, it will be returned as "0", not as an empty string. |
jmitc91516 | 1:a5258871b33d | 476 | |
jmitc91516 | 1:a5258871b33d | 477 | Args: the index to the field (value 0 through 3) |
jmitc91516 | 1:a5258871b33d | 478 | a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 479 | It is up to the caller to make sure this is long enough, i.e. at least 4 bytes long |
jmitc91516 | 1:a5258871b33d | 480 | ********************** |
jmitc91516 | 1:a5258871b33d | 481 | No return code |
jmitc91516 | 1:a5258871b33d | 482 | */ |
jmitc91516 | 1:a5258871b33d | 483 | void NetworkParameters::GetIPAddressFieldAsString(int fieldIndex, char *ipAddressBuffer, bool wantLeadingSpaces) |
jmitc91516 | 1:a5258871b33d | 484 | { |
jmitc91516 | 1:a5258871b33d | 485 | // By default, we pad the field with leading spaces, |
jmitc91516 | 1:a5258871b33d | 486 | // to try and keep it a constant width |
jmitc91516 | 1:a5258871b33d | 487 | if((fieldIndex >= 0) && (fieldIndex < 4)) { |
jmitc91516 | 1:a5258871b33d | 488 | if(ipAddress[fieldIndex] == 0) { |
jmitc91516 | 1:a5258871b33d | 489 | if(wantLeadingSpaces) { |
jmitc91516 | 1:a5258871b33d | 490 | ipAddressBuffer[0] = ' '; |
jmitc91516 | 1:a5258871b33d | 491 | ipAddressBuffer[1] = ' '; |
jmitc91516 | 1:a5258871b33d | 492 | ipAddressBuffer[2] = '0'; |
jmitc91516 | 1:a5258871b33d | 493 | ipAddressBuffer[3] = '\0'; |
jmitc91516 | 1:a5258871b33d | 494 | } else { |
jmitc91516 | 1:a5258871b33d | 495 | ipAddressBuffer[0] = '0'; |
jmitc91516 | 1:a5258871b33d | 496 | ipAddressBuffer[1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 497 | } |
jmitc91516 | 1:a5258871b33d | 498 | |
jmitc91516 | 1:a5258871b33d | 499 | return; |
jmitc91516 | 1:a5258871b33d | 500 | } |
jmitc91516 | 1:a5258871b33d | 501 | |
jmitc91516 | 1:a5258871b33d | 502 | if(ipAddress[fieldIndex] >= 255) { |
jmitc91516 | 1:a5258871b33d | 503 | ipAddressBuffer[0] = '2'; |
jmitc91516 | 1:a5258871b33d | 504 | ipAddressBuffer[1] = '5'; |
jmitc91516 | 1:a5258871b33d | 505 | ipAddressBuffer[2] = '5'; |
jmitc91516 | 1:a5258871b33d | 506 | ipAddressBuffer[3] = '\0'; |
jmitc91516 | 1:a5258871b33d | 507 | |
jmitc91516 | 1:a5258871b33d | 508 | return; |
jmitc91516 | 1:a5258871b33d | 509 | } |
jmitc91516 | 1:a5258871b33d | 510 | |
jmitc91516 | 1:a5258871b33d | 511 | // 'else' - value is between 0 and 255 |
jmitc91516 | 1:a5258871b33d | 512 | if(wantLeadingSpaces) { |
jmitc91516 | 1:a5258871b33d | 513 | sprintf(ipAddressBuffer, "%3u", ipAddress[fieldIndex]); |
jmitc91516 | 1:a5258871b33d | 514 | } else { |
jmitc91516 | 1:a5258871b33d | 515 | sprintf(ipAddressBuffer, "%u", ipAddress[fieldIndex]); |
jmitc91516 | 1:a5258871b33d | 516 | } |
jmitc91516 | 1:a5258871b33d | 517 | return; |
jmitc91516 | 1:a5258871b33d | 518 | } |
jmitc91516 | 1:a5258871b33d | 519 | |
jmitc91516 | 1:a5258871b33d | 520 | // 'else' - invalid index |
jmitc91516 | 1:a5258871b33d | 521 | ipAddressBuffer[0] = '\0'; |
jmitc91516 | 1:a5258871b33d | 522 | } |
jmitc91516 | 1:a5258871b33d | 523 | |
jmitc91516 | 1:a5258871b33d | 524 | |
jmitc91516 | 1:a5258871b33d | 525 | /* |
jmitc91516 | 1:a5258871b33d | 526 | Sets the specified field of the IP address from a null-terminated string |
jmitc91516 | 1:a5258871b33d | 527 | |
jmitc91516 | 1:a5258871b33d | 528 | Args: the index to the field (value 0 through 3) |
jmitc91516 | 1:a5258871b33d | 529 | a pointer to a buffer that contains the string. |
jmitc91516 | 1:a5258871b33d | 530 | |
jmitc91516 | 1:a5258871b33d | 531 | No return code |
jmitc91516 | 1:a5258871b33d | 532 | */ |
jmitc91516 | 1:a5258871b33d | 533 | void NetworkParameters::SetIPAddressFieldFromString(int fieldIndex, char *ipAddressBuffer) |
jmitc91516 | 1:a5258871b33d | 534 | { |
jmitc91516 | 1:a5258871b33d | 535 | if((fieldIndex >= 0) && (fieldIndex < 4)) { |
jmitc91516 | 1:a5258871b33d | 536 | unsigned int temp; |
jmitc91516 | 1:a5258871b33d | 537 | sscanf(ipAddressBuffer, "%u", &temp); |
jmitc91516 | 1:a5258871b33d | 538 | |
jmitc91516 | 1:a5258871b33d | 539 | // 'temp' is unsigned, so cannot be less than zero |
jmitc91516 | 1:a5258871b33d | 540 | if(temp > 255) { |
jmitc91516 | 1:a5258871b33d | 541 | ipAddress[fieldIndex] = 255; |
jmitc91516 | 1:a5258871b33d | 542 | return; |
jmitc91516 | 1:a5258871b33d | 543 | } |
jmitc91516 | 1:a5258871b33d | 544 | |
jmitc91516 | 1:a5258871b33d | 545 | // 'else' |
jmitc91516 | 1:a5258871b33d | 546 | ipAddress[fieldIndex] = temp; |
jmitc91516 | 1:a5258871b33d | 547 | } |
jmitc91516 | 1:a5258871b33d | 548 | } |
jmitc91516 | 1:a5258871b33d | 549 | |
jmitc91516 | 1:a5258871b33d | 550 | |
jmitc91516 | 1:a5258871b33d | 551 | /* |
jmitc91516 | 1:a5258871b33d | 552 | Outputs the specified field of the subnet mask as a null-terminated string, in the form of an integer |
jmitc91516 | 1:a5258871b33d | 553 | with 1-3 digits. If the value is zero, it will be returned as "0", not as an empty string. |
jmitc91516 | 1:a5258871b33d | 554 | |
jmitc91516 | 1:a5258871b33d | 555 | Args: the index to the field (value 0 through 3) |
jmitc91516 | 1:a5258871b33d | 556 | a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 557 | It is up to the caller to make sure this is long enough, i.e. at least 4 bytes long |
jmitc91516 | 1:a5258871b33d | 558 | ********************** |
jmitc91516 | 1:a5258871b33d | 559 | No return code |
jmitc91516 | 1:a5258871b33d | 560 | */ |
jmitc91516 | 1:a5258871b33d | 561 | void NetworkParameters::GetSubnetMaskFieldAsString(int fieldIndex, char *subnetMaskBuffer, bool wantLeadingSpaces) |
jmitc91516 | 1:a5258871b33d | 562 | { |
jmitc91516 | 1:a5258871b33d | 563 | // By default, we pad the field with leading spaces, |
jmitc91516 | 1:a5258871b33d | 564 | // to try and keep it a constant width |
jmitc91516 | 1:a5258871b33d | 565 | if((fieldIndex >= 0) && (fieldIndex < 4)) { |
jmitc91516 | 1:a5258871b33d | 566 | if(subnetMask[fieldIndex] == 0) { |
jmitc91516 | 1:a5258871b33d | 567 | if(wantLeadingSpaces) { |
jmitc91516 | 1:a5258871b33d | 568 | subnetMaskBuffer[0] = ' '; |
jmitc91516 | 1:a5258871b33d | 569 | subnetMaskBuffer[1] = ' '; |
jmitc91516 | 1:a5258871b33d | 570 | subnetMaskBuffer[2] = '0'; |
jmitc91516 | 1:a5258871b33d | 571 | subnetMaskBuffer[3] = '\0'; |
jmitc91516 | 1:a5258871b33d | 572 | } else { |
jmitc91516 | 1:a5258871b33d | 573 | subnetMaskBuffer[0] = '0'; |
jmitc91516 | 1:a5258871b33d | 574 | subnetMaskBuffer[1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 575 | } |
jmitc91516 | 1:a5258871b33d | 576 | return; |
jmitc91516 | 1:a5258871b33d | 577 | } |
jmitc91516 | 1:a5258871b33d | 578 | |
jmitc91516 | 1:a5258871b33d | 579 | if(subnetMask[fieldIndex] >= 255) { |
jmitc91516 | 1:a5258871b33d | 580 | subnetMaskBuffer[0] = '2'; |
jmitc91516 | 1:a5258871b33d | 581 | subnetMaskBuffer[1] = '5'; |
jmitc91516 | 1:a5258871b33d | 582 | subnetMaskBuffer[2] = '5'; |
jmitc91516 | 1:a5258871b33d | 583 | subnetMaskBuffer[3] = '\0'; |
jmitc91516 | 1:a5258871b33d | 584 | |
jmitc91516 | 1:a5258871b33d | 585 | return; |
jmitc91516 | 1:a5258871b33d | 586 | } |
jmitc91516 | 1:a5258871b33d | 587 | |
jmitc91516 | 1:a5258871b33d | 588 | // 'else' - value is between 0 and 255 |
jmitc91516 | 1:a5258871b33d | 589 | if(wantLeadingSpaces) { |
jmitc91516 | 1:a5258871b33d | 590 | sprintf(subnetMaskBuffer, "%3u", subnetMask[fieldIndex]); |
jmitc91516 | 1:a5258871b33d | 591 | } else { |
jmitc91516 | 1:a5258871b33d | 592 | sprintf(subnetMaskBuffer, "%u", subnetMask[fieldIndex]); |
jmitc91516 | 1:a5258871b33d | 593 | } |
jmitc91516 | 1:a5258871b33d | 594 | return; |
jmitc91516 | 1:a5258871b33d | 595 | } |
jmitc91516 | 1:a5258871b33d | 596 | |
jmitc91516 | 1:a5258871b33d | 597 | // 'else' - invalid index |
jmitc91516 | 1:a5258871b33d | 598 | subnetMaskBuffer[0] = '\0'; |
jmitc91516 | 1:a5258871b33d | 599 | } |
jmitc91516 | 1:a5258871b33d | 600 | |
jmitc91516 | 1:a5258871b33d | 601 | |
jmitc91516 | 1:a5258871b33d | 602 | /* |
jmitc91516 | 1:a5258871b33d | 603 | Sets the specified field of the subnet mask from a null-terminated string |
jmitc91516 | 1:a5258871b33d | 604 | |
jmitc91516 | 1:a5258871b33d | 605 | Args: the index to the field (value 0 through 3) |
jmitc91516 | 1:a5258871b33d | 606 | a pointer to a buffer that contains the string. |
jmitc91516 | 1:a5258871b33d | 607 | |
jmitc91516 | 1:a5258871b33d | 608 | No return code |
jmitc91516 | 1:a5258871b33d | 609 | */ |
jmitc91516 | 1:a5258871b33d | 610 | void NetworkParameters::SetSubnetMaskFieldFromString(int fieldIndex, char *subnetMaskBuffer) |
jmitc91516 | 1:a5258871b33d | 611 | { |
jmitc91516 | 1:a5258871b33d | 612 | if((fieldIndex >= 0) && (fieldIndex < 4)) { |
jmitc91516 | 1:a5258871b33d | 613 | unsigned int temp; |
jmitc91516 | 1:a5258871b33d | 614 | sscanf(subnetMaskBuffer, "%u", &temp); |
jmitc91516 | 1:a5258871b33d | 615 | |
jmitc91516 | 1:a5258871b33d | 616 | // 'temp' is unsigned, so cannot be less than zero |
jmitc91516 | 1:a5258871b33d | 617 | if(temp > 255) { |
jmitc91516 | 1:a5258871b33d | 618 | subnetMask[fieldIndex] = 255; |
jmitc91516 | 1:a5258871b33d | 619 | return; |
jmitc91516 | 1:a5258871b33d | 620 | } |
jmitc91516 | 1:a5258871b33d | 621 | |
jmitc91516 | 1:a5258871b33d | 622 | // 'else' |
jmitc91516 | 1:a5258871b33d | 623 | subnetMask[fieldIndex] = temp; |
jmitc91516 | 1:a5258871b33d | 624 | } |
jmitc91516 | 1:a5258871b33d | 625 | } |
jmitc91516 | 1:a5258871b33d | 626 | |
jmitc91516 | 1:a5258871b33d | 627 | |
jmitc91516 | 1:a5258871b33d | 628 | /* |
jmitc91516 | 1:a5258871b33d | 629 | Outputs the specified field of the gateway address as a null-terminated string, in the form of an integer |
jmitc91516 | 1:a5258871b33d | 630 | with 1-3 digits. If the value is zero, it will be returned as "0", not as an empty string. |
jmitc91516 | 1:a5258871b33d | 631 | |
jmitc91516 | 1:a5258871b33d | 632 | Args: the index to the field (value 0 through 3) |
jmitc91516 | 1:a5258871b33d | 633 | a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 634 | It is up to the caller to make sure this is long enough, i.e. at least 4 bytes long |
jmitc91516 | 1:a5258871b33d | 635 | ********************** |
jmitc91516 | 1:a5258871b33d | 636 | No return code |
jmitc91516 | 1:a5258871b33d | 637 | */ |
jmitc91516 | 1:a5258871b33d | 638 | void NetworkParameters::GetGatewayAddressFieldAsString(int fieldIndex, char *gatewayAddressBuffer, bool wantLeadingSpaces) |
jmitc91516 | 1:a5258871b33d | 639 | { |
jmitc91516 | 1:a5258871b33d | 640 | // By default, we pad the field with leading spaces, |
jmitc91516 | 1:a5258871b33d | 641 | // to try and keep it a constant width |
jmitc91516 | 1:a5258871b33d | 642 | if((fieldIndex >= 0) && (fieldIndex < 4)) { |
jmitc91516 | 1:a5258871b33d | 643 | if(gatewayAddress[fieldIndex] == 0) { |
jmitc91516 | 1:a5258871b33d | 644 | if(wantLeadingSpaces) { |
jmitc91516 | 1:a5258871b33d | 645 | gatewayAddressBuffer[0] = ' '; |
jmitc91516 | 1:a5258871b33d | 646 | gatewayAddressBuffer[1] = ' '; |
jmitc91516 | 1:a5258871b33d | 647 | gatewayAddressBuffer[2] = '0'; |
jmitc91516 | 1:a5258871b33d | 648 | gatewayAddressBuffer[3] = '\0'; |
jmitc91516 | 1:a5258871b33d | 649 | } else { |
jmitc91516 | 1:a5258871b33d | 650 | gatewayAddressBuffer[0] = '0'; |
jmitc91516 | 1:a5258871b33d | 651 | gatewayAddressBuffer[1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 652 | } |
jmitc91516 | 1:a5258871b33d | 653 | return; |
jmitc91516 | 1:a5258871b33d | 654 | } |
jmitc91516 | 1:a5258871b33d | 655 | |
jmitc91516 | 1:a5258871b33d | 656 | if(gatewayAddress[fieldIndex] >= 255) { |
jmitc91516 | 1:a5258871b33d | 657 | gatewayAddressBuffer[0] = '2'; |
jmitc91516 | 1:a5258871b33d | 658 | gatewayAddressBuffer[1] = '5'; |
jmitc91516 | 1:a5258871b33d | 659 | gatewayAddressBuffer[2] = '5'; |
jmitc91516 | 1:a5258871b33d | 660 | gatewayAddressBuffer[3] = '\0'; |
jmitc91516 | 1:a5258871b33d | 661 | |
jmitc91516 | 1:a5258871b33d | 662 | return; |
jmitc91516 | 1:a5258871b33d | 663 | } |
jmitc91516 | 1:a5258871b33d | 664 | |
jmitc91516 | 1:a5258871b33d | 665 | // 'else' - value is between 0 and 255 |
jmitc91516 | 1:a5258871b33d | 666 | if(wantLeadingSpaces) { |
jmitc91516 | 1:a5258871b33d | 667 | sprintf(gatewayAddressBuffer, "%3u", gatewayAddress[fieldIndex]); |
jmitc91516 | 1:a5258871b33d | 668 | } else { |
jmitc91516 | 1:a5258871b33d | 669 | sprintf(gatewayAddressBuffer, "%u", gatewayAddress[fieldIndex]); |
jmitc91516 | 1:a5258871b33d | 670 | } |
jmitc91516 | 1:a5258871b33d | 671 | return; |
jmitc91516 | 1:a5258871b33d | 672 | } |
jmitc91516 | 1:a5258871b33d | 673 | |
jmitc91516 | 1:a5258871b33d | 674 | // 'else' - invalid index |
jmitc91516 | 1:a5258871b33d | 675 | gatewayAddressBuffer[0] = '\0'; |
jmitc91516 | 1:a5258871b33d | 676 | } |
jmitc91516 | 1:a5258871b33d | 677 | |
jmitc91516 | 1:a5258871b33d | 678 | |
jmitc91516 | 1:a5258871b33d | 679 | /* |
jmitc91516 | 1:a5258871b33d | 680 | Sets the specified field of the gateway address from a null-terminated string |
jmitc91516 | 1:a5258871b33d | 681 | |
jmitc91516 | 1:a5258871b33d | 682 | Args: the index to the field (value 0 through 3) |
jmitc91516 | 1:a5258871b33d | 683 | a pointer to a buffer that contains the string. |
jmitc91516 | 1:a5258871b33d | 684 | |
jmitc91516 | 1:a5258871b33d | 685 | No return code |
jmitc91516 | 1:a5258871b33d | 686 | */ |
jmitc91516 | 1:a5258871b33d | 687 | void NetworkParameters::SetGatewayAddressFieldFromString(int fieldIndex, char *gatewayAddressBuffer) |
jmitc91516 | 1:a5258871b33d | 688 | { |
jmitc91516 | 1:a5258871b33d | 689 | if((fieldIndex >= 0) && (fieldIndex < 4)) { |
jmitc91516 | 1:a5258871b33d | 690 | unsigned int temp; |
jmitc91516 | 1:a5258871b33d | 691 | sscanf(gatewayAddressBuffer, "%u", &temp); |
jmitc91516 | 1:a5258871b33d | 692 | |
jmitc91516 | 1:a5258871b33d | 693 | // 'temp' is unsigned, so cannot be less than zero |
jmitc91516 | 1:a5258871b33d | 694 | if(temp > 255) { |
jmitc91516 | 1:a5258871b33d | 695 | gatewayAddress[fieldIndex] = 255; |
jmitc91516 | 1:a5258871b33d | 696 | return; |
jmitc91516 | 1:a5258871b33d | 697 | } |
jmitc91516 | 1:a5258871b33d | 698 | |
jmitc91516 | 1:a5258871b33d | 699 | // 'else' |
jmitc91516 | 1:a5258871b33d | 700 | gatewayAddress[fieldIndex] = temp; |
jmitc91516 | 1:a5258871b33d | 701 | } |
jmitc91516 | 1:a5258871b33d | 702 | } |
jmitc91516 | 1:a5258871b33d | 703 | |
jmitc91516 | 1:a5258871b33d | 704 | |
jmitc91516 | 1:a5258871b33d | 705 | /* |
jmitc91516 | 1:a5258871b33d | 706 | Outputs the IP address as a null-terminated string, in the conventional form, |
jmitc91516 | 1:a5258871b33d | 707 | i.e. as four integers, each of which can be 1-3 digits, separated by dots, e.g. "123.456.789.123". |
jmitc91516 | 1:a5258871b33d | 708 | If any of the values is zero, it will appear as "0", not as an empty string - but other than that, |
jmitc91516 | 1:a5258871b33d | 709 | there will be no leading zeroes. |
jmitc91516 | 1:a5258871b33d | 710 | |
jmitc91516 | 1:a5258871b33d | 711 | Args: a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 712 | It is up to the caller to make sure this is long enough, i.e. at least 16 bytes long |
jmitc91516 | 1:a5258871b33d | 713 | ********************** |
jmitc91516 | 1:a5258871b33d | 714 | No return code |
jmitc91516 | 1:a5258871b33d | 715 | */ |
jmitc91516 | 1:a5258871b33d | 716 | void NetworkParameters::GetIPAddressAsString(char *ipAddressBuffer) |
jmitc91516 | 1:a5258871b33d | 717 | { |
jmitc91516 | 1:a5258871b33d | 718 | char ipAddressField0[10]; |
jmitc91516 | 1:a5258871b33d | 719 | char ipAddressField1[10]; |
jmitc91516 | 1:a5258871b33d | 720 | char ipAddressField2[10]; |
jmitc91516 | 1:a5258871b33d | 721 | char ipAddressField3[10]; |
jmitc91516 | 1:a5258871b33d | 722 | |
jmitc91516 | 1:a5258871b33d | 723 | GetIPAddressFieldAsString(0, ipAddressField0, false); |
jmitc91516 | 1:a5258871b33d | 724 | GetIPAddressFieldAsString(1, ipAddressField1, false); |
jmitc91516 | 1:a5258871b33d | 725 | GetIPAddressFieldAsString(2, ipAddressField2, false); |
jmitc91516 | 1:a5258871b33d | 726 | GetIPAddressFieldAsString(3, ipAddressField3, false); |
jmitc91516 | 1:a5258871b33d | 727 | |
jmitc91516 | 1:a5258871b33d | 728 | sprintf(ipAddressBuffer, "%s.%s.%s.%s", ipAddressField0, ipAddressField1, ipAddressField2, ipAddressField3); |
jmitc91516 | 1:a5258871b33d | 729 | } |
jmitc91516 | 1:a5258871b33d | 730 | |
jmitc91516 | 1:a5258871b33d | 731 | /* |
jmitc91516 | 1:a5258871b33d | 732 | Sets our IP address from the string passed to it, which we expect to be in the conventional form, |
jmitc91516 | 1:a5258871b33d | 733 | i.e. as four integers, each of which can be 1-3 digits, separated by dots, e.g. "123.456.789.123". |
jmitc91516 | 1:a5258871b33d | 734 | |
jmitc91516 | 1:a5258871b33d | 735 | Args: a pointer to a buffer which contains the string. |
jmitc91516 | 1:a5258871b33d | 736 | |
jmitc91516 | 1:a5258871b33d | 737 | No return code |
jmitc91516 | 1:a5258871b33d | 738 | */ |
jmitc91516 | 1:a5258871b33d | 739 | void NetworkParameters::SetIPAddressFromString(char *ipAddressBuffer) |
jmitc91516 | 1:a5258871b33d | 740 | { |
jmitc91516 | 1:a5258871b33d | 741 | char fieldBuff[20]; |
jmitc91516 | 1:a5258871b33d | 742 | int fieldBuffIndex; |
jmitc91516 | 1:a5258871b33d | 743 | int ipAddressBufferIndex; |
jmitc91516 | 1:a5258871b33d | 744 | |
jmitc91516 | 1:a5258871b33d | 745 | ipAddressBufferIndex = 0; |
jmitc91516 | 1:a5258871b33d | 746 | for (int ipAddressIndex = 0; ipAddressIndex < 4; ++ipAddressIndex) { |
jmitc91516 | 1:a5258871b33d | 747 | fieldBuffIndex = 0; |
jmitc91516 | 1:a5258871b33d | 748 | while((ipAddressBuffer[ipAddressBufferIndex] != '\0') && (ipAddressBuffer[ipAddressBufferIndex] != '.')){ |
jmitc91516 | 1:a5258871b33d | 749 | fieldBuff[fieldBuffIndex++] = ipAddressBuffer[ipAddressBufferIndex++]; |
jmitc91516 | 1:a5258871b33d | 750 | } |
jmitc91516 | 1:a5258871b33d | 751 | fieldBuff[fieldBuffIndex] = '\0'; |
jmitc91516 | 1:a5258871b33d | 752 | |
jmitc91516 | 1:a5258871b33d | 753 | SetIPAddressFieldFromString(ipAddressIndex, fieldBuff); |
jmitc91516 | 1:a5258871b33d | 754 | |
jmitc91516 | 1:a5258871b33d | 755 | if(ipAddressBuffer[ipAddressBufferIndex] == '\0') break; |
jmitc91516 | 1:a5258871b33d | 756 | |
jmitc91516 | 1:a5258871b33d | 757 | ++ipAddressBufferIndex; // Point to next field |
jmitc91516 | 1:a5258871b33d | 758 | } |
jmitc91516 | 1:a5258871b33d | 759 | } |
jmitc91516 | 1:a5258871b33d | 760 | |
jmitc91516 | 1:a5258871b33d | 761 | |
jmitc91516 | 1:a5258871b33d | 762 | /* |
jmitc91516 | 1:a5258871b33d | 763 | Outputs the subnet mask as a null-terminated string, in the conventional form, |
jmitc91516 | 1:a5258871b33d | 764 | i.e. as four integers, each of which can be 1-3 digits, separated by dots, e.g. "123.456.789.123". |
jmitc91516 | 1:a5258871b33d | 765 | If any of the values is zero, it will appear as "0", not as an empty string - but other than that, |
jmitc91516 | 1:a5258871b33d | 766 | there will be no leading zeroes. |
jmitc91516 | 1:a5258871b33d | 767 | |
jmitc91516 | 1:a5258871b33d | 768 | Args: a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 769 | It is up to the caller to make sure this is long enough, i.e. at least 16 bytes long |
jmitc91516 | 1:a5258871b33d | 770 | ********************** |
jmitc91516 | 1:a5258871b33d | 771 | No return code |
jmitc91516 | 1:a5258871b33d | 772 | */ |
jmitc91516 | 1:a5258871b33d | 773 | void NetworkParameters::GetSubnetMaskAsString(char *subnetMaskBuffer) |
jmitc91516 | 1:a5258871b33d | 774 | { |
jmitc91516 | 1:a5258871b33d | 775 | char subnetMaskField0[10]; |
jmitc91516 | 1:a5258871b33d | 776 | char subnetMaskField1[10]; |
jmitc91516 | 1:a5258871b33d | 777 | char subnetMaskField2[10]; |
jmitc91516 | 1:a5258871b33d | 778 | char subnetMaskField3[10]; |
jmitc91516 | 1:a5258871b33d | 779 | |
jmitc91516 | 1:a5258871b33d | 780 | GetSubnetMaskFieldAsString(0, subnetMaskField0, false); |
jmitc91516 | 1:a5258871b33d | 781 | GetSubnetMaskFieldAsString(1, subnetMaskField1, false); |
jmitc91516 | 1:a5258871b33d | 782 | GetSubnetMaskFieldAsString(2, subnetMaskField2, false); |
jmitc91516 | 1:a5258871b33d | 783 | GetSubnetMaskFieldAsString(3, subnetMaskField3, false); |
jmitc91516 | 1:a5258871b33d | 784 | |
jmitc91516 | 1:a5258871b33d | 785 | sprintf(subnetMaskBuffer, "%s.%s.%s.%s", subnetMaskField0, subnetMaskField1, subnetMaskField2, subnetMaskField3); |
jmitc91516 | 1:a5258871b33d | 786 | } |
jmitc91516 | 1:a5258871b33d | 787 | |
jmitc91516 | 1:a5258871b33d | 788 | /* |
jmitc91516 | 1:a5258871b33d | 789 | Sets our subnet mask from the string passed to it, which we expect to be in the conventional form, |
jmitc91516 | 1:a5258871b33d | 790 | i.e. as four integers, each of which can be 1-3 digits, separated by dots, e.g. "123.456.789.123". |
jmitc91516 | 1:a5258871b33d | 791 | |
jmitc91516 | 1:a5258871b33d | 792 | Args: a pointer to a buffer which contains the string. |
jmitc91516 | 1:a5258871b33d | 793 | |
jmitc91516 | 1:a5258871b33d | 794 | No return code |
jmitc91516 | 1:a5258871b33d | 795 | */ |
jmitc91516 | 1:a5258871b33d | 796 | void NetworkParameters::SetSubnetMaskFromString(char *subnetMaskBuffer) |
jmitc91516 | 1:a5258871b33d | 797 | { |
jmitc91516 | 1:a5258871b33d | 798 | char fieldBuff[20]; |
jmitc91516 | 1:a5258871b33d | 799 | int fieldBuffIndex; |
jmitc91516 | 1:a5258871b33d | 800 | int subnetMaskBufferIndex; |
jmitc91516 | 1:a5258871b33d | 801 | |
jmitc91516 | 1:a5258871b33d | 802 | subnetMaskBufferIndex = 0; |
jmitc91516 | 1:a5258871b33d | 803 | for (int subnetMaskIndex = 0; subnetMaskIndex < 4; ++subnetMaskIndex) { |
jmitc91516 | 1:a5258871b33d | 804 | fieldBuffIndex = 0; |
jmitc91516 | 1:a5258871b33d | 805 | while((subnetMaskBuffer[subnetMaskBufferIndex] != '\0') && (subnetMaskBuffer[subnetMaskBufferIndex] != '.')){ |
jmitc91516 | 1:a5258871b33d | 806 | fieldBuff[fieldBuffIndex++] = subnetMaskBuffer[subnetMaskBufferIndex++]; |
jmitc91516 | 1:a5258871b33d | 807 | } |
jmitc91516 | 1:a5258871b33d | 808 | fieldBuff[fieldBuffIndex] = '\0'; |
jmitc91516 | 1:a5258871b33d | 809 | |
jmitc91516 | 1:a5258871b33d | 810 | SetSubnetMaskFieldFromString(subnetMaskIndex, fieldBuff); |
jmitc91516 | 1:a5258871b33d | 811 | |
jmitc91516 | 1:a5258871b33d | 812 | if(subnetMaskBuffer[subnetMaskBufferIndex] == '\0') break; |
jmitc91516 | 1:a5258871b33d | 813 | |
jmitc91516 | 1:a5258871b33d | 814 | ++subnetMaskBufferIndex; // Point to next field |
jmitc91516 | 1:a5258871b33d | 815 | } |
jmitc91516 | 1:a5258871b33d | 816 | } |
jmitc91516 | 1:a5258871b33d | 817 | |
jmitc91516 | 1:a5258871b33d | 818 | |
jmitc91516 | 1:a5258871b33d | 819 | /* |
jmitc91516 | 1:a5258871b33d | 820 | Outputs the gateway address as a null-terminated string, in the conventional form, |
jmitc91516 | 1:a5258871b33d | 821 | i.e. as four integers, each of which can be 1-3 digits, separated by dots, e.g. "123.456.789.123". |
jmitc91516 | 1:a5258871b33d | 822 | If any of the values is zero, it will appear as "0", not as an empty string - but other than that, |
jmitc91516 | 1:a5258871b33d | 823 | there will be no leading zeroes. |
jmitc91516 | 1:a5258871b33d | 824 | |
jmitc91516 | 1:a5258871b33d | 825 | Args: a pointer to a buffer to contain the string. |
jmitc91516 | 1:a5258871b33d | 826 | It is up to the caller to make sure this is long enough, i.e. at least 16 bytes long |
jmitc91516 | 1:a5258871b33d | 827 | ********************** |
jmitc91516 | 1:a5258871b33d | 828 | No return code |
jmitc91516 | 1:a5258871b33d | 829 | */ |
jmitc91516 | 1:a5258871b33d | 830 | void NetworkParameters::GetGatewayAddressAsString(char *gatewayAddressBuffer) |
jmitc91516 | 1:a5258871b33d | 831 | { |
jmitc91516 | 1:a5258871b33d | 832 | char gatewayAddressField0[10]; |
jmitc91516 | 1:a5258871b33d | 833 | char gatewayAddressField1[10]; |
jmitc91516 | 1:a5258871b33d | 834 | char gatewayAddressField2[10]; |
jmitc91516 | 1:a5258871b33d | 835 | char gatewayAddressField3[10]; |
jmitc91516 | 1:a5258871b33d | 836 | |
jmitc91516 | 1:a5258871b33d | 837 | GetGatewayAddressFieldAsString(0, gatewayAddressField0, false); |
jmitc91516 | 1:a5258871b33d | 838 | GetGatewayAddressFieldAsString(1, gatewayAddressField1, false); |
jmitc91516 | 1:a5258871b33d | 839 | GetGatewayAddressFieldAsString(2, gatewayAddressField2, false); |
jmitc91516 | 1:a5258871b33d | 840 | GetGatewayAddressFieldAsString(3, gatewayAddressField3, false); |
jmitc91516 | 1:a5258871b33d | 841 | |
jmitc91516 | 1:a5258871b33d | 842 | sprintf(gatewayAddressBuffer, "%s.%s.%s.%s", gatewayAddressField0, gatewayAddressField1, gatewayAddressField2, gatewayAddressField3); |
jmitc91516 | 1:a5258871b33d | 843 | } |
jmitc91516 | 1:a5258871b33d | 844 | |
jmitc91516 | 1:a5258871b33d | 845 | /* |
jmitc91516 | 1:a5258871b33d | 846 | Sets our gateway address from the string passed to it, which we expect to be in the conventional form, |
jmitc91516 | 1:a5258871b33d | 847 | i.e. as four integers, each of which can be 1-3 digits, separated by dots, e.g. "123.456.789.123". |
jmitc91516 | 1:a5258871b33d | 848 | |
jmitc91516 | 1:a5258871b33d | 849 | Args: a pointer to a buffer which contains the string. |
jmitc91516 | 1:a5258871b33d | 850 | |
jmitc91516 | 1:a5258871b33d | 851 | No return code |
jmitc91516 | 1:a5258871b33d | 852 | */ |
jmitc91516 | 1:a5258871b33d | 853 | void NetworkParameters::SetGatewayAddressFromString(char *gatewayAddressBuffer) |
jmitc91516 | 1:a5258871b33d | 854 | { |
jmitc91516 | 1:a5258871b33d | 855 | char fieldBuff[20]; |
jmitc91516 | 1:a5258871b33d | 856 | int fieldBuffIndex; |
jmitc91516 | 1:a5258871b33d | 857 | int gatewayAddressBufferIndex; |
jmitc91516 | 1:a5258871b33d | 858 | |
jmitc91516 | 1:a5258871b33d | 859 | gatewayAddressBufferIndex = 0; |
jmitc91516 | 1:a5258871b33d | 860 | for (int gatewayAddressIndex = 0; gatewayAddressIndex < 4; ++gatewayAddressIndex) { |
jmitc91516 | 1:a5258871b33d | 861 | fieldBuffIndex = 0; |
jmitc91516 | 1:a5258871b33d | 862 | while((gatewayAddressBuffer[gatewayAddressBufferIndex] != '\0') && (gatewayAddressBuffer[gatewayAddressBufferIndex] != '.')){ |
jmitc91516 | 1:a5258871b33d | 863 | fieldBuff[fieldBuffIndex++] = gatewayAddressBuffer[gatewayAddressBufferIndex++]; |
jmitc91516 | 1:a5258871b33d | 864 | } |
jmitc91516 | 1:a5258871b33d | 865 | fieldBuff[fieldBuffIndex] = '\0'; |
jmitc91516 | 1:a5258871b33d | 866 | |
jmitc91516 | 1:a5258871b33d | 867 | SetGatewayAddressFieldFromString(gatewayAddressIndex, fieldBuff); |
jmitc91516 | 1:a5258871b33d | 868 | |
jmitc91516 | 1:a5258871b33d | 869 | if(gatewayAddressBuffer[gatewayAddressBufferIndex] == '\0') break; |
jmitc91516 | 1:a5258871b33d | 870 | |
jmitc91516 | 1:a5258871b33d | 871 | ++gatewayAddressBufferIndex; // Point to next field |
jmitc91516 | 1:a5258871b33d | 872 | } |
jmitc91516 | 1:a5258871b33d | 873 | } |
jmitc91516 | 1:a5258871b33d | 874 | |
jmitc91516 | 1:a5258871b33d | 875 | |
jmitc91516 | 1:a5258871b33d | 876 | /* |
jmitc91516 | 1:a5258871b33d | 877 | Tells the caller whether or not the specified touch index is on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 878 | and therefore needs to be handled by this class. |
jmitc91516 | 1:a5258871b33d | 879 | |
jmitc91516 | 1:a5258871b33d | 880 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 881 | |
jmitc91516 | 1:a5258871b33d | 882 | Return code: true if the touch area represents a network parameter, false if not |
jmitc91516 | 1:a5258871b33d | 883 | */ |
jmitc91516 | 1:a5258871b33d | 884 | bool NetworkParameters::TouchAreaIsNetworkParameter(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 885 | { |
jmitc91516 | 1:a5258871b33d | 886 | if((touchAreaIndex >= MIN_NETWORK_PARAM) && (touchAreaIndex <= MAX_NETWORK_PARAM)) { |
jmitc91516 | 1:a5258871b33d | 887 | return true; |
jmitc91516 | 1:a5258871b33d | 888 | } |
jmitc91516 | 1:a5258871b33d | 889 | |
jmitc91516 | 1:a5258871b33d | 890 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 891 | return false; |
jmitc91516 | 1:a5258871b33d | 892 | } |
jmitc91516 | 1:a5258871b33d | 893 | |
jmitc91516 | 1:a5258871b33d | 894 | |
jmitc91516 | 1:a5258871b33d | 895 | /* |
jmitc91516 | 1:a5258871b33d | 896 | Tells the caller if the specified touch area corresponds to a value the user can edit |
jmitc91516 | 1:a5258871b33d | 897 | on the easyGUI 'EthernetParametersPage', and if so, which one. |
jmitc91516 | 1:a5258871b33d | 898 | |
jmitc91516 | 1:a5258871b33d | 899 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 900 | |
jmitc91516 | 1:a5258871b33d | 901 | Returns the index of the corresponding entry in our 'variablesForTouchArea' array, |
jmitc91516 | 1:a5258871b33d | 902 | or -1 if there is no such entry. It is up to the caller to check for -1 |
jmitc91516 | 1:a5258871b33d | 903 | ************************************** |
jmitc91516 | 1:a5258871b33d | 904 | */ |
jmitc91516 | 1:a5258871b33d | 905 | int NetworkParameters::GetIndexOfVariablesToEditForTouchArea(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 906 | { |
jmitc91516 | 1:a5258871b33d | 907 | for (int index = 0; index < COUNT_OF_VARIABLES_FOR_TOUCH_AREAS; ++index) { |
jmitc91516 | 1:a5258871b33d | 908 | if(variablesForTouchArea[index].touchAreaIndex == touchAreaIndex) { |
jmitc91516 | 1:a5258871b33d | 909 | return index; |
jmitc91516 | 1:a5258871b33d | 910 | } |
jmitc91516 | 1:a5258871b33d | 911 | } |
jmitc91516 | 1:a5258871b33d | 912 | |
jmitc91516 | 1:a5258871b33d | 913 | // 'else' no Network Parameters variable corresponds to the specified touch area |
jmitc91516 | 1:a5258871b33d | 914 | return -1; |
jmitc91516 | 1:a5258871b33d | 915 | } |
jmitc91516 | 1:a5258871b33d | 916 | |
jmitc91516 | 1:a5258871b33d | 917 | |
jmitc91516 | 1:a5258871b33d | 918 | /* |
jmitc91516 | 1:a5258871b33d | 919 | If the specified touch area represents a key or field on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 920 | this function performs whatever action is appropriate for it. Provided so that the caller |
jmitc91516 | 1:a5258871b33d | 921 | can (in effect) say "if this is one of yours, deal with it", without needing to know |
jmitc91516 | 1:a5258871b33d | 922 | anything about what this class does, or how it handles the keys on that easyGUI page. |
jmitc91516 | 1:a5258871b33d | 923 | |
jmitc91516 | 1:a5258871b33d | 924 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 925 | |
jmitc91516 | 1:a5258871b33d | 926 | Returns true if it dealt with the touch area (so the caller need not do anything else |
jmitc91516 | 1:a5258871b33d | 927 | with the value), or false if it did not deal with the touch area (implying that it |
jmitc91516 | 1:a5258871b33d | 928 | was not a touch area on the easyGUI 'EthernetParametersPage', and so the caller |
jmitc91516 | 1:a5258871b33d | 929 | must deal with it some other way). |
jmitc91516 | 1:a5258871b33d | 930 | */ |
jmitc91516 | 1:a5258871b33d | 931 | bool NetworkParameters::DealWithTouch(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 932 | { |
jmitc91516 | 1:a5258871b33d | 933 | if(TouchAreaIsNetworkParameter(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 934 | |
jmitc91516 | 1:a5258871b33d | 935 | #ifdef TOUCH_VALUES_DIRECTLY |
jmitc91516 | 1:a5258871b33d | 936 | // Has the user selected a field to edit - |
jmitc91516 | 1:a5258871b33d | 937 | // if so, we will have an entry in our 'variablesForTouchArea' array that corresponds with this touch area |
jmitc91516 | 1:a5258871b33d | 938 | int indexOfVariablesToEdit = GetIndexOfVariablesToEditForTouchArea(touchAreaIndex); |
jmitc91516 | 1:a5258871b33d | 939 | if(indexOfVariablesToEdit != -1) { |
jmitc91516 | 1:a5258871b33d | 940 | // User has selected a field to edit |
jmitc91516 | 1:a5258871b33d | 941 | indexOfVariablesCurrentlyBeingEdited = indexOfVariablesToEdit; |
jmitc91516 | 1:a5258871b33d | 942 | NumericKeypadPageHandler* numericKeypadPageHandler = NumericKeypadPageHandler::GetInstance(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 943 | if(numericKeypadPageHandler != NULL) { |
jmitc91516 | 1:a5258871b33d | 944 | |
jmitc91516 | 1:a5258871b33d | 945 | numericKeypadPageHandler->StartEditing(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].easyGUIVariablePtr); |
jmitc91516 | 1:a5258871b33d | 946 | |
jmitc91516 | 1:a5258871b33d | 947 | // We need the numeric keypad to update the easyGUI variable *and* our internal variable - they must always match |
jmitc91516 | 1:a5258871b33d | 948 | numericKeypadPageHandler->SetEasyGUIVariableToEdit(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].easyGUIVariablePtr); |
jmitc91516 | 1:a5258871b33d | 949 | numericKeypadPageHandler->SetInternalVariableToEdit(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].internalVariablePtr); |
jmitc91516 | 1:a5258871b33d | 950 | |
jmitc91516 | 1:a5258871b33d | 951 | numericKeypadPageHandler->SetEasyGUICallingPage(GuiStruct_EthernetParametersPage_50); |
jmitc91516 | 1:a5258871b33d | 952 | numericKeypadPageHandler->SetEditVariableRange(0, variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].maxValue); |
jmitc91516 | 1:a5258871b33d | 953 | numericKeypadPageHandler->SetEditVariableName(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].variableName); |
jmitc91516 | 1:a5258871b33d | 954 | |
jmitc91516 | 1:a5258871b33d | 955 | numericKeypadPageHandler->DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 956 | } |
jmitc91516 | 1:a5258871b33d | 957 | return true; |
jmitc91516 | 1:a5258871b33d | 958 | } |
jmitc91516 | 1:a5258871b33d | 959 | #endif // TOUCH_VALUES_DIRECTLY |
jmitc91516 | 1:a5258871b33d | 960 | |
jmitc91516 | 1:a5258871b33d | 961 | if(touchAreaIndex == NETWORK_PARAMS_PORT_EDIT) { |
jmitc91516 | 1:a5258871b33d | 962 | indexOfVariablesCurrentlyBeingEdited = 0; // Port |
jmitc91516 | 1:a5258871b33d | 963 | NumericKeypadPageHandler* numericKeypadPageHandler = NumericKeypadPageHandler::GetInstance(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 964 | if(numericKeypadPageHandler != NULL) { |
jmitc91516 | 1:a5258871b33d | 965 | |
jmitc91516 | 1:a5258871b33d | 966 | numericKeypadPageHandler->StartEditing(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].easyGUIVariablePtr); |
jmitc91516 | 1:a5258871b33d | 967 | |
jmitc91516 | 1:a5258871b33d | 968 | // We need the numeric keypad to update the easyGUI variable *and* our internal variable - they must always match |
jmitc91516 | 1:a5258871b33d | 969 | numericKeypadPageHandler->SetEasyGUIVariableToEdit(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].easyGUIVariablePtr); |
jmitc91516 | 1:a5258871b33d | 970 | numericKeypadPageHandler->SetInternalVariableToEdit(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].internalVariablePtr); |
jmitc91516 | 1:a5258871b33d | 971 | |
jmitc91516 | 1:a5258871b33d | 972 | numericKeypadPageHandler->SetEasyGUICallingPage(GuiStruct_EthernetParametersPage_50); |
jmitc91516 | 1:a5258871b33d | 973 | numericKeypadPageHandler->SetEditVariableRange(0, variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].maxValue); |
jmitc91516 | 1:a5258871b33d | 974 | numericKeypadPageHandler->SetEditVariableName(variablesForTouchArea[indexOfVariablesCurrentlyBeingEdited].variableName); |
jmitc91516 | 1:a5258871b33d | 975 | |
jmitc91516 | 1:a5258871b33d | 976 | numericKeypadPageHandler->DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 977 | } |
jmitc91516 | 1:a5258871b33d | 978 | return true; |
jmitc91516 | 1:a5258871b33d | 979 | } |
jmitc91516 | 1:a5258871b33d | 980 | |
jmitc91516 | 1:a5258871b33d | 981 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 982 | |
jmitc91516 | 1:a5258871b33d | 983 | if(DealWithIPEditButton(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 984 | return true; |
jmitc91516 | 1:a5258871b33d | 985 | } |
jmitc91516 | 1:a5258871b33d | 986 | |
jmitc91516 | 1:a5258871b33d | 987 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 988 | |
jmitc91516 | 1:a5258871b33d | 989 | if(DealWithMaskEditButton(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 990 | return true; |
jmitc91516 | 1:a5258871b33d | 991 | } |
jmitc91516 | 1:a5258871b33d | 992 | |
jmitc91516 | 1:a5258871b33d | 993 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 994 | |
jmitc91516 | 1:a5258871b33d | 995 | if(DealWithGatewayEditButton(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 996 | return true; |
jmitc91516 | 1:a5258871b33d | 997 | } |
jmitc91516 | 1:a5258871b33d | 998 | |
jmitc91516 | 1:a5258871b33d | 999 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 1000 | |
jmitc91516 | 1:a5258871b33d | 1001 | if(DealWithCancelButton(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 1002 | return true; |
jmitc91516 | 1:a5258871b33d | 1003 | } |
jmitc91516 | 1:a5258871b33d | 1004 | |
jmitc91516 | 1:a5258871b33d | 1005 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 1006 | |
jmitc91516 | 1:a5258871b33d | 1007 | if(DealWithApplyButton(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 1008 | return true; |
jmitc91516 | 1:a5258871b33d | 1009 | } |
jmitc91516 | 1:a5258871b33d | 1010 | |
jmitc91516 | 1:a5258871b33d | 1011 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 1012 | |
jmitc91516 | 1:a5258871b33d | 1013 | if(DealWithUseDHCPButton(touchAreaIndex)) { |
jmitc91516 | 1:a5258871b33d | 1014 | return true; |
jmitc91516 | 1:a5258871b33d | 1015 | } |
jmitc91516 | 1:a5258871b33d | 1016 | |
jmitc91516 | 1:a5258871b33d | 1017 | return false; // Not dealt with touch area |
jmitc91516 | 1:a5258871b33d | 1018 | } |
jmitc91516 | 1:a5258871b33d | 1019 | |
jmitc91516 | 1:a5258871b33d | 1020 | // 'else' not one of our touch areas... |
jmitc91516 | 1:a5258871b33d | 1021 | return false; |
jmitc91516 | 1:a5258871b33d | 1022 | } |
jmitc91516 | 1:a5258871b33d | 1023 | |
jmitc91516 | 1:a5258871b33d | 1024 | |
jmitc91516 | 1:a5258871b33d | 1025 | /* |
jmitc91516 | 1:a5258871b33d | 1026 | If the specified touch area represents the Apply button on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 1027 | this function will apply the current values on that page. In theory, this should mean closing |
jmitc91516 | 1:a5258871b33d | 1028 | the current Ethernet connection, if any, and setting up a new one with the new values. However, |
jmitc91516 | 1:a5258871b33d | 1029 | in practice the EthernetInterface class does not seem to be able to do this (while the first |
jmitc91516 | 1:a5258871b33d | 1030 | call to the EthernetInterface 'init' method succeeds, subsequent calls crash). So we write |
jmitc91516 | 1:a5258871b33d | 1031 | our current values to QSPI memory, and then force the entire application to restart, |
jmitc91516 | 1:a5258871b33d | 1032 | knowing that when it does so, GetGCStatusLoop::MainLoopWithEthernet will call us back |
jmitc91516 | 1:a5258871b33d | 1033 | to get the new Ethernet parameters from QSPI memory before calling the EthernetInterface 'init' method. |
jmitc91516 | 1:a5258871b33d | 1034 | |
jmitc91516 | 1:a5258871b33d | 1035 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 1036 | |
jmitc91516 | 1:a5258871b33d | 1037 | Returns true if the specified touch area is the Apply button, false if not |
jmitc91516 | 1:a5258871b33d | 1038 | (we are just telling the caller whether it needs to do anything else with this value) |
jmitc91516 | 1:a5258871b33d | 1039 | */ |
jmitc91516 | 1:a5258871b33d | 1040 | bool NetworkParameters::DealWithApplyButton(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 1041 | { |
jmitc91516 | 1:a5258871b33d | 1042 | if(touchAreaIndex == NETWORK_PARAMS_APPLY_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 1043 | |
jmitc91516 | 1:a5258871b33d | 1044 | useDHCP = false; |
jmitc91516 | 1:a5258871b33d | 1045 | |
jmitc91516 | 1:a5258871b33d | 1046 | UpdateInternalValuesFromEasyGUIVariables(); |
jmitc91516 | 1:a5258871b33d | 1047 | |
jmitc91516 | 1:a5258871b33d | 1048 | SaveToQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 1049 | |
jmitc91516 | 1:a5258871b33d | 1050 | GetGCStatusLoop* getGCStatusLoop = GetGCStatusLoop::GetInstance(); |
jmitc91516 | 1:a5258871b33d | 1051 | if(getGCStatusLoop != NULL) { |
jmitc91516 | 1:a5258871b33d | 1052 | getGCStatusLoop->ForceRestart(); // This is the only way to make the new values take effect |
jmitc91516 | 1:a5258871b33d | 1053 | } |
jmitc91516 | 1:a5258871b33d | 1054 | |
jmitc91516 | 1:a5258871b33d | 1055 | return true; |
jmitc91516 | 1:a5258871b33d | 1056 | } |
jmitc91516 | 1:a5258871b33d | 1057 | |
jmitc91516 | 1:a5258871b33d | 1058 | // 'else' not the Apply button |
jmitc91516 | 1:a5258871b33d | 1059 | return false; |
jmitc91516 | 1:a5258871b33d | 1060 | } |
jmitc91516 | 1:a5258871b33d | 1061 | |
jmitc91516 | 1:a5258871b33d | 1062 | |
jmitc91516 | 1:a5258871b33d | 1063 | /* |
jmitc91516 | 1:a5258871b33d | 1064 | If the specified touch area represents the Cancel button on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 1065 | this function will reset the current values on that page to the 'real' values - |
jmitc91516 | 1:a5258871b33d | 1066 | i.e. the ones we are actually using for the Ethernet link. |
jmitc91516 | 1:a5258871b33d | 1067 | |
jmitc91516 | 1:a5258871b33d | 1068 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 1069 | |
jmitc91516 | 1:a5258871b33d | 1070 | Returns true if the specified touch area is the Cancel button, false if not |
jmitc91516 | 1:a5258871b33d | 1071 | (we are just telling the caller whether it needs to do anything else with this value) |
jmitc91516 | 1:a5258871b33d | 1072 | */ |
jmitc91516 | 1:a5258871b33d | 1073 | bool NetworkParameters::DealWithCancelButton(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 1074 | { |
jmitc91516 | 1:a5258871b33d | 1075 | if(touchAreaIndex == NETWORK_PARAMS_CANCEL_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 1076 | |
jmitc91516 | 1:a5258871b33d | 1077 | RestoreRealValues(); |
jmitc91516 | 1:a5258871b33d | 1078 | UpdateEasyGUIVariablesFromInternalValues(); |
jmitc91516 | 1:a5258871b33d | 1079 | |
jmitc91516 | 1:a5258871b33d | 1080 | #ifdef USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 1081 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 1082 | #else |
jmitc91516 | 1:a5258871b33d | 1083 | SetAllFieldBackgroundColoursToWhite(); |
jmitc91516 | 1:a5258871b33d | 1084 | #endif |
jmitc91516 | 1:a5258871b33d | 1085 | |
jmitc91516 | 1:a5258871b33d | 1086 | indexOfVariablesCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 1087 | |
jmitc91516 | 1:a5258871b33d | 1088 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 1089 | |
jmitc91516 | 1:a5258871b33d | 1090 | return true; |
jmitc91516 | 1:a5258871b33d | 1091 | } |
jmitc91516 | 1:a5258871b33d | 1092 | |
jmitc91516 | 1:a5258871b33d | 1093 | // 'else' not the Cancel button |
jmitc91516 | 1:a5258871b33d | 1094 | return false; |
jmitc91516 | 1:a5258871b33d | 1095 | } |
jmitc91516 | 1:a5258871b33d | 1096 | |
jmitc91516 | 1:a5258871b33d | 1097 | |
jmitc91516 | 1:a5258871b33d | 1098 | /* |
jmitc91516 | 1:a5258871b33d | 1099 | If the specified touch area represents the "Use DHCP" button on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 1100 | this function will restart the Ethernet connection using DHCP to obtain the IP address, etc, values, |
jmitc91516 | 1:a5258871b33d | 1101 | instead of using the explicit ones shown on this page. In theory, this should mean closing |
jmitc91516 | 1:a5258871b33d | 1102 | the current Ethernet connection, if any, and setting up a new one with the new values. However, |
jmitc91516 | 1:a5258871b33d | 1103 | in practice the EthernetInterface class does not seem to be able to do this (while the first |
jmitc91516 | 1:a5258871b33d | 1104 | call to the EthernetInterface 'init' method succeeds, subsequent calls crash). So we write |
jmitc91516 | 1:a5258871b33d | 1105 | "UseDHCP = true" to QSPI memory, and then force the entire application to restart, |
jmitc91516 | 1:a5258871b33d | 1106 | knowing that when it does so, GetGCStatusLoop::MainLoopWithEthernet will call us back |
jmitc91516 | 1:a5258871b33d | 1107 | to get the new Ethernet parameters from QSPI memory, see that "UseDHCP" is set true, |
jmitc91516 | 1:a5258871b33d | 1108 | and call the appropriate EthernetInterface 'init' method. |
jmitc91516 | 1:a5258871b33d | 1109 | |
jmitc91516 | 1:a5258871b33d | 1110 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 1111 | |
jmitc91516 | 1:a5258871b33d | 1112 | Returns true if the specified touch area is the "Use DHCP" button, false if not |
jmitc91516 | 1:a5258871b33d | 1113 | (we are just telling the caller whether it needs to do anything else with this value) |
jmitc91516 | 1:a5258871b33d | 1114 | */ |
jmitc91516 | 1:a5258871b33d | 1115 | bool NetworkParameters::DealWithUseDHCPButton(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 1116 | { |
jmitc91516 | 1:a5258871b33d | 1117 | if(touchAreaIndex == NETWORK_PARAMS_DHCP_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 1118 | |
jmitc91516 | 1:a5258871b33d | 1119 | useDHCP = true; |
jmitc91516 | 1:a5258871b33d | 1120 | |
jmitc91516 | 1:a5258871b33d | 1121 | UpdateInternalValuesFromEasyGUIVariables(); |
jmitc91516 | 1:a5258871b33d | 1122 | |
jmitc91516 | 1:a5258871b33d | 1123 | SaveToQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 1124 | |
jmitc91516 | 1:a5258871b33d | 1125 | GetGCStatusLoop* getGCStatusLoop = GetGCStatusLoop::GetInstance(); |
jmitc91516 | 1:a5258871b33d | 1126 | if(getGCStatusLoop != NULL) { |
jmitc91516 | 1:a5258871b33d | 1127 | getGCStatusLoop->ForceRestart(); // This is the only way to make the new values take effect |
jmitc91516 | 1:a5258871b33d | 1128 | } |
jmitc91516 | 1:a5258871b33d | 1129 | |
jmitc91516 | 1:a5258871b33d | 1130 | return true; |
jmitc91516 | 1:a5258871b33d | 1131 | } |
jmitc91516 | 1:a5258871b33d | 1132 | |
jmitc91516 | 1:a5258871b33d | 1133 | // 'else' not the Apply button |
jmitc91516 | 1:a5258871b33d | 1134 | return false; |
jmitc91516 | 1:a5258871b33d | 1135 | } |
jmitc91516 | 1:a5258871b33d | 1136 | |
jmitc91516 | 1:a5258871b33d | 1137 | |
jmitc91516 | 1:a5258871b33d | 1138 | /* |
jmitc91516 | 1:a5258871b33d | 1139 | If the specified touch area represents the "Edit IP address" button on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 1140 | this function invokes the EthernetKeypadPageHandler to do that. |
jmitc91516 | 1:a5258871b33d | 1141 | |
jmitc91516 | 1:a5258871b33d | 1142 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 1143 | |
jmitc91516 | 1:a5258871b33d | 1144 | Returns true if the specified touch area is the "Edit IP address" button, false if not |
jmitc91516 | 1:a5258871b33d | 1145 | (we are just telling the caller whether it needs to do anything else with this value) |
jmitc91516 | 1:a5258871b33d | 1146 | */ |
jmitc91516 | 1:a5258871b33d | 1147 | bool NetworkParameters::DealWithIPEditButton(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 1148 | { |
jmitc91516 | 1:a5258871b33d | 1149 | if(touchAreaIndex == NETWORK_PARAMS_IP_EDIT) { |
jmitc91516 | 1:a5258871b33d | 1150 | |
jmitc91516 | 1:a5258871b33d | 1151 | EthernetKeypadPageHandler* ethernetKeypadPageHandler = EthernetKeypadPageHandler::GetInstance(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 1152 | if(ethernetKeypadPageHandler != NULL) { |
jmitc91516 | 1:a5258871b33d | 1153 | |
jmitc91516 | 1:a5258871b33d | 1154 | ethernetKeypadPageHandler->SetEasyGUIOctetVariablesToEdit(GuiVar_ethernetIP1, GuiVar_ethernetIP2, GuiVar_ethernetIP3, GuiVar_ethernetIP4); |
jmitc91516 | 1:a5258871b33d | 1155 | ethernetKeypadPageHandler->SetInternalOctetVariablesToEdit(&(ipAddress[0]), &(ipAddress[1]), &(ipAddress[2]), &(ipAddress[3])); |
jmitc91516 | 1:a5258871b33d | 1156 | |
jmitc91516 | 1:a5258871b33d | 1157 | ethernetKeypadPageHandler->StartEditing("IP Address"); |
jmitc91516 | 1:a5258871b33d | 1158 | } |
jmitc91516 | 1:a5258871b33d | 1159 | |
jmitc91516 | 1:a5258871b33d | 1160 | return true; |
jmitc91516 | 1:a5258871b33d | 1161 | } |
jmitc91516 | 1:a5258871b33d | 1162 | |
jmitc91516 | 1:a5258871b33d | 1163 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 1164 | return false; |
jmitc91516 | 1:a5258871b33d | 1165 | } |
jmitc91516 | 1:a5258871b33d | 1166 | |
jmitc91516 | 1:a5258871b33d | 1167 | |
jmitc91516 | 1:a5258871b33d | 1168 | /* |
jmitc91516 | 1:a5258871b33d | 1169 | If the specified touch area represents the "Edit subnet mask" button on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 1170 | this function invokes the EthernetKeypadPageHandler to do that. |
jmitc91516 | 1:a5258871b33d | 1171 | |
jmitc91516 | 1:a5258871b33d | 1172 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 1173 | |
jmitc91516 | 1:a5258871b33d | 1174 | Returns true if the specified touch area is the "Edit subnet mask" button, false if not |
jmitc91516 | 1:a5258871b33d | 1175 | (we are just telling the caller whether it needs to do anything else with this value) |
jmitc91516 | 1:a5258871b33d | 1176 | */ |
jmitc91516 | 1:a5258871b33d | 1177 | bool NetworkParameters::DealWithMaskEditButton(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 1178 | { |
jmitc91516 | 1:a5258871b33d | 1179 | if(touchAreaIndex == NETWORK_PARAMS_MASK_EDIT) { |
jmitc91516 | 1:a5258871b33d | 1180 | |
jmitc91516 | 1:a5258871b33d | 1181 | EthernetKeypadPageHandler* ethernetKeypadPageHandler = EthernetKeypadPageHandler::GetInstance(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 1182 | if(ethernetKeypadPageHandler != NULL) { |
jmitc91516 | 1:a5258871b33d | 1183 | |
jmitc91516 | 1:a5258871b33d | 1184 | ethernetKeypadPageHandler->SetEasyGUIOctetVariablesToEdit(GuiVar_ethernetMask1, GuiVar_ethernetMask2, GuiVar_ethernetMask3, GuiVar_ethernetMask4); |
jmitc91516 | 1:a5258871b33d | 1185 | ethernetKeypadPageHandler->SetInternalOctetVariablesToEdit(&(subnetMask[0]), &(subnetMask[1]), &(subnetMask[2]), &(subnetMask[3])); |
jmitc91516 | 1:a5258871b33d | 1186 | |
jmitc91516 | 1:a5258871b33d | 1187 | ethernetKeypadPageHandler->StartEditing("Subnet Mask"); |
jmitc91516 | 1:a5258871b33d | 1188 | } |
jmitc91516 | 1:a5258871b33d | 1189 | |
jmitc91516 | 1:a5258871b33d | 1190 | return true; |
jmitc91516 | 1:a5258871b33d | 1191 | } |
jmitc91516 | 1:a5258871b33d | 1192 | |
jmitc91516 | 1:a5258871b33d | 1193 | // 'else'... |
jmitc91516 | 1:a5258871b33d | 1194 | return false; |
jmitc91516 | 1:a5258871b33d | 1195 | } |
jmitc91516 | 1:a5258871b33d | 1196 | |
jmitc91516 | 1:a5258871b33d | 1197 | |
jmitc91516 | 1:a5258871b33d | 1198 | /* |
jmitc91516 | 1:a5258871b33d | 1199 | If the specified touch area represents the "Edit gateway" button on the easyGUI 'EthernetParametersPage', |
jmitc91516 | 1:a5258871b33d | 1200 | this function invokes the EthernetKeypadPageHandler to do that. |
jmitc91516 | 1:a5258871b33d | 1201 | |
jmitc91516 | 1:a5258871b33d | 1202 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 1203 | |
jmitc91516 | 1:a5258871b33d | 1204 | Returns true if the specified touch area is the "Edit gateway" button, false if not |
jmitc91516 | 1:a5258871b33d | 1205 | (we are just telling the caller whether it needs to do anything else with this value) |
jmitc91516 | 1:a5258871b33d | 1206 | */ |
jmitc91516 | 1:a5258871b33d | 1207 | bool NetworkParameters::DealWithGatewayEditButton(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 1208 | { |
jmitc91516 | 1:a5258871b33d | 1209 | if(touchAreaIndex == NETWORK_PARAMS_GATEWAY_EDIT) { |
jmitc91516 | 1:a5258871b33d | 1210 | |
jmitc91516 | 1:a5258871b33d | 1211 | EthernetKeypadPageHandler* ethernetKeypadPageHandler = EthernetKeypadPageHandler::GetInstance(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 1212 | if(ethernetKeypadPageHandler != NULL) { |
jmitc91516 | 1:a5258871b33d | 1213 | |
jmitc91516 | 1:a5258871b33d | 1214 | ethernetKeypadPageHandler->SetEasyGUIOctetVariablesToEdit(GuiVar_ethernetGateway1, GuiVar_ethernetGateway2, GuiVar_ethernetGateway3, GuiVar_ethernetGateway4); |
jmitc91516 | 1:a5258871b33d | 1215 | ethernetKeypadPageHandler->SetInternalOctetVariablesToEdit(&(gatewayAddress[0]), &(gatewayAddress[1]), &(gatewayAddress[2]), &(gatewayAddress[3])); |
jmitc91516 | 1:a5258871b33d | 1216 | |
jmitc91516 | 1:a5258871b33d | 1217 | ethernetKeypadPageHandler->StartEditing("Gateway"); |
jmitc91516 | 1:a5258871b33d | 1218 | } |
jmitc91516 | 1:a5258871b33d | 1219 | |
jmitc91516 | 1:a5258871b33d | 1220 | return true; |
jmitc91516 | 1:a5258871b33d | 1221 | } |
jmitc91516 | 1:a5258871b33d | 1222 | |
jmitc91516 | 1:a5258871b33d | 1223 | return false; |
jmitc91516 | 1:a5258871b33d | 1224 | } |
jmitc91516 | 1:a5258871b33d | 1225 | |
jmitc91516 | 1:a5258871b33d | 1226 | |
jmitc91516 | 1:a5258871b33d | 1227 | /* |
jmitc91516 | 1:a5258871b33d | 1228 | For each of our internal (private) variables, make it equal to the value |
jmitc91516 | 1:a5258871b33d | 1229 | of the corresponding easyGUI variable (the value displayed to the user) |
jmitc91516 | 1:a5258871b33d | 1230 | |
jmitc91516 | 1:a5258871b33d | 1231 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 1232 | */ |
jmitc91516 | 1:a5258871b33d | 1233 | void NetworkParameters::UpdateInternalValuesFromEasyGUIVariables(void) |
jmitc91516 | 1:a5258871b33d | 1234 | { |
jmitc91516 | 1:a5258871b33d | 1235 | SetPortNumberFromString(GuiVar_ethernetPort); |
jmitc91516 | 1:a5258871b33d | 1236 | |
jmitc91516 | 1:a5258871b33d | 1237 | SetIPAddressFieldFromString(0, GuiVar_ethernetIP1); |
jmitc91516 | 1:a5258871b33d | 1238 | SetIPAddressFieldFromString(1, GuiVar_ethernetIP2); |
jmitc91516 | 1:a5258871b33d | 1239 | SetIPAddressFieldFromString(2, GuiVar_ethernetIP3); |
jmitc91516 | 1:a5258871b33d | 1240 | SetIPAddressFieldFromString(3, GuiVar_ethernetIP4); |
jmitc91516 | 1:a5258871b33d | 1241 | |
jmitc91516 | 1:a5258871b33d | 1242 | SetSubnetMaskFieldFromString(0, GuiVar_ethernetMask1); |
jmitc91516 | 1:a5258871b33d | 1243 | SetSubnetMaskFieldFromString(1, GuiVar_ethernetMask2); |
jmitc91516 | 1:a5258871b33d | 1244 | SetSubnetMaskFieldFromString(2, GuiVar_ethernetMask3); |
jmitc91516 | 1:a5258871b33d | 1245 | SetSubnetMaskFieldFromString(3, GuiVar_ethernetMask4); |
jmitc91516 | 1:a5258871b33d | 1246 | |
jmitc91516 | 1:a5258871b33d | 1247 | SetGatewayAddressFieldFromString(0, GuiVar_ethernetGateway1); |
jmitc91516 | 1:a5258871b33d | 1248 | SetGatewayAddressFieldFromString(1, GuiVar_ethernetGateway2); |
jmitc91516 | 1:a5258871b33d | 1249 | SetGatewayAddressFieldFromString(2, GuiVar_ethernetGateway3); |
jmitc91516 | 1:a5258871b33d | 1250 | SetGatewayAddressFieldFromString(3, GuiVar_ethernetGateway4); |
jmitc91516 | 1:a5258871b33d | 1251 | } |
jmitc91516 | 1:a5258871b33d | 1252 | |
jmitc91516 | 1:a5258871b33d | 1253 | |
jmitc91516 | 1:a5258871b33d | 1254 | /* |
jmitc91516 | 1:a5258871b33d | 1255 | For each of our internal (private) variables, copy its value |
jmitc91516 | 1:a5258871b33d | 1256 | to the corresponding easyGUI variable (the value displayed to the user) |
jmitc91516 | 1:a5258871b33d | 1257 | |
jmitc91516 | 1:a5258871b33d | 1258 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 1259 | */ |
jmitc91516 | 1:a5258871b33d | 1260 | void NetworkParameters::UpdateEasyGUIVariablesFromInternalValues(void) |
jmitc91516 | 1:a5258871b33d | 1261 | { |
jmitc91516 | 1:a5258871b33d | 1262 | GetPortNumberAsString(GuiVar_ethernetPort); |
jmitc91516 | 1:a5258871b33d | 1263 | |
jmitc91516 | 1:a5258871b33d | 1264 | GetIPAddressFieldAsString(0, GuiVar_ethernetIP1); |
jmitc91516 | 1:a5258871b33d | 1265 | GetIPAddressFieldAsString(1, GuiVar_ethernetIP2); |
jmitc91516 | 1:a5258871b33d | 1266 | GetIPAddressFieldAsString(2, GuiVar_ethernetIP3); |
jmitc91516 | 1:a5258871b33d | 1267 | GetIPAddressFieldAsString(3, GuiVar_ethernetIP4); |
jmitc91516 | 1:a5258871b33d | 1268 | |
jmitc91516 | 1:a5258871b33d | 1269 | GetSubnetMaskFieldAsString(0, GuiVar_ethernetMask1); |
jmitc91516 | 1:a5258871b33d | 1270 | GetSubnetMaskFieldAsString(1, GuiVar_ethernetMask2); |
jmitc91516 | 1:a5258871b33d | 1271 | GetSubnetMaskFieldAsString(2, GuiVar_ethernetMask3); |
jmitc91516 | 1:a5258871b33d | 1272 | GetSubnetMaskFieldAsString(3, GuiVar_ethernetMask4); |
jmitc91516 | 1:a5258871b33d | 1273 | |
jmitc91516 | 1:a5258871b33d | 1274 | GetGatewayAddressFieldAsString(0, GuiVar_ethernetGateway1); |
jmitc91516 | 1:a5258871b33d | 1275 | GetGatewayAddressFieldAsString(1, GuiVar_ethernetGateway2); |
jmitc91516 | 1:a5258871b33d | 1276 | GetGatewayAddressFieldAsString(2, GuiVar_ethernetGateway3); |
jmitc91516 | 1:a5258871b33d | 1277 | GetGatewayAddressFieldAsString(3, GuiVar_ethernetGateway4); |
jmitc91516 | 1:a5258871b33d | 1278 | } |
jmitc91516 | 1:a5258871b33d | 1279 | |
jmitc91516 | 1:a5258871b33d | 1280 | |
jmitc91516 | 1:a5258871b33d | 1281 | /* |
jmitc91516 | 1:a5258871b33d | 1282 | (Re)display the easyGUI 'EthernetParametersPage' - |
jmitc91516 | 1:a5258871b33d | 1283 | e.g. after the caller has updated one or more of the easyGUI variables |
jmitc91516 | 1:a5258871b33d | 1284 | included in the page, and wants to display the new value to the user. |
jmitc91516 | 1:a5258871b33d | 1285 | |
jmitc91516 | 1:a5258871b33d | 1286 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 1287 | */ |
jmitc91516 | 1:a5258871b33d | 1288 | void NetworkParameters::UpdateEasyGUIPage(void) |
jmitc91516 | 1:a5258871b33d | 1289 | { |
jmitc91516 | 1:a5258871b33d | 1290 | #define WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 1291 | #ifdef WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 1292 | #ifdef USING_BACKGROUND_BITMAP |
jmitc91516 | 1:a5258871b33d | 1293 | DrawBackgroundBitmap(); |
jmitc91516 | 1:a5258871b33d | 1294 | #else |
jmitc91516 | 1:a5258871b33d | 1295 | GuiLib_Clear(); |
jmitc91516 | 1:a5258871b33d | 1296 | #endif |
jmitc91516 | 1:a5258871b33d | 1297 | #undef WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 1298 | #endif |
jmitc91516 | 1:a5258871b33d | 1299 | GuiLib_ShowScreen(GuiStruct_EthernetParametersPage_50, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW); |
jmitc91516 | 1:a5258871b33d | 1300 | |
jmitc91516 | 1:a5258871b33d | 1301 | GuiLib_Refresh(); |
jmitc91516 | 1:a5258871b33d | 1302 | } |