Skip to content

Commit

Permalink
Merge branch 'feature/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
elcojacobs committed Dec 3, 2015
2 parents 4c7dfa3 + 4671d78 commit eac6909
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 115 deletions.
12 changes: 8 additions & 4 deletions LogMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
A copy of this file is included with the python script, so it can parse it to extract the log strings.
The python script receives the messages as a few IDs and values in a JSON string.
It uses this file to expand that to the full message.
Not storing the full strings, but only the ID on the controller saves a lot of PROGMEM space.
Not storing the full strings, but only the ID on the Arduino saves a lot of PROGMEM space.
At startup the python script extracts the version number from this file and compares it to its own local copy.
It will give a warning when the two strings do not match.
*/

/* bump this version number when changing this file and copy the new version to the brewpi-script repository. */
#define BREWPI_LOG_MESSAGES_VERSION 1
#define BREWPI_LOG_MESSAGES_VERSION 2

#define MSG(errorID, errorString, ...) errorID

Expand All @@ -52,12 +52,16 @@ enum errorMessages{
// PiLink.cpp
MSG(ERROR_EXPECTED_BRACKET, "Expected { got %c", character),

MSG(ERROR_ONEWIRE_INIT_FAILED, "OneWire initialization failed"),
MSG(ERROR_DEVICE_ALREADY_INSTALLED, "This hardware device is already installed at slot %d. Uninstall it first.", slot),
MSG(ERROR_FUNCTION_ALREADY_INSTALLED, "This device function is already installed at slot %d. Uninstall it first.", slot)

}; // END enum errorMessages

enum warningMessages{
// PiLink.cpp
MSG(WARNING_COULD_NOT_PROCESS_SETTING, "Could not process setting"),
MSG(WARNING_INVALID_COMMAND, "Invalid command received by controller: %c", character),
MSG(WARNING_INVALID_COMMAND, "Invalid command received by Arduino: %c", character),

// OneWireTempSensor.cpp
MSG(WARNING_TEMP_SENSOR_DISCONNECTED, "Temperature sensor disconnected pin %d, address %s", pinNr, addressString),
Expand All @@ -82,7 +86,7 @@ enum infoMessages{
MSG(INFO_INSTALL_SWITCH_SENSOR, "installing switch sensor with function %d", config.deviceFunction),
MSG(INFO_INSTALL_DEVICE, "Installing device f=%d", config.deviceFunction),
MSG(INFO_MATCHING_DEVICE, "Matching device at slot %d", out.slot),
MSG(INFO_SETTING_ACTIVATOR_STATE, "Setting activator state %d", state),
MSG(INFO_SETTING_ACTUATOR_VALUE, "Setting actuator value %d", val),

// PiLink.cpp
MSG(INFO_RECEIVED_SETTING, "Received new setting: %s = %s", key, val),
Expand Down
80 changes: 54 additions & 26 deletions MigrateSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,62 @@

MigrateSettingsDefaultRestoreValidity = [
SettingMigrate('tempFormat', '0', '1000', []),
SettingMigrate('tempSetMin', '0', '1000', []),
SettingMigrate('tempSetMax', '0', '1000', []),
SettingMigrate('Kp', '0', '1000', []),
SettingMigrate('Ki', '0', '1000', []),
SettingMigrate('Kd', '0', '1000', []),
SettingMigrate('iMaxErr', '0', '1000', []),
SettingMigrate('pidMax', '0.2.4', '1000', []),
SettingMigrate('idleRangeH', '0', '1000', []),
SettingMigrate('idleRangeL', '0', '1000', []),
SettingMigrate('heatTargetH', '0', '1000', []),
SettingMigrate('heatTargetL', '0', '1000', []),
SettingMigrate('coolTargetH', '0', '1000', []),
SettingMigrate('coolTargetL', '0', '1000', []),
SettingMigrate('maxHeatTimeForEst', '0', '1000', []),
SettingMigrate('maxCoolTimeForEst', '0', '1000', []),
SettingMigrate('fridgeFastFilt', '0.2.0', '1000', []),
SettingMigrate('fridgeSlowFilt', '0.2.0', '1000', []),
SettingMigrate('fridgeSlopeFilt', '0.2.0', '1000', []),
SettingMigrate('beerFastFilt', '0.2.0', '1000', []),
SettingMigrate('beerSlowFilt', '0.2.3', '1000', []),
SettingMigrate('beerSlopeFilt', '0.2.3', '1000', []),
SettingMigrate('lah', '0', '1000', []),
SettingMigrate('hs', '0', '1000', []),
SettingMigrate('heatEst', '0', '1000', []),
SettingMigrate('coolEst', '0', '1000', []),
SettingMigrate('tempSetMin', '0', '0.2.11', []),
SettingMigrate('tempSetMax', '0', '0.2.11', []),
SettingMigrate('Kp', '0', '0.2.11', []),
SettingMigrate('Ki', '0', '0.2.11', []),
SettingMigrate('Kd', '0', '0.2.11', []),
SettingMigrate('iMaxErr', '0', '0.2.11', []),
SettingMigrate('pidMax', '0.2.4', '0.2.11', []),
SettingMigrate('idleRangeH', '0', '0.2.11', []),
SettingMigrate('idleRangeL', '0', '0.2.11', []),
SettingMigrate('heatTargetH', '0', '0.2.11', []),
SettingMigrate('heatTargetL', '0', '0.2.11', []),
SettingMigrate('coolTargetH', '0', '0.2.11', []),
SettingMigrate('coolTargetL', '0', '0.2.11', []),
SettingMigrate('maxHeatTimeForEst', '0', '0.2.11', []),
SettingMigrate('maxCoolTimeForEst', '0', '0.2.11', []),
SettingMigrate('fridgeFastFilt', '0.2.0', '0.2.11', []),
SettingMigrate('fridgeSlowFilt', '0.2.0', '0.2.11', []),
SettingMigrate('fridgeSlopeFilt', '0.2.0', '0.2.11', []),
SettingMigrate('beerFastFilt', '0.2.0', '0.2.11', []),
SettingMigrate('beerSlowFilt', '0.2.3', '0.2.11', []),
SettingMigrate('beerSlopeFilt', '0.2.3', '0.2.11', []),
SettingMigrate('lah', '0', '0.2.11', []),
SettingMigrate('hs', '0', '0.2.11', []),
SettingMigrate('heatEst', '0', '0.2.11', []),
SettingMigrate('coolEst', '0', '0.2.11', []),
SettingMigrate('fridgeSet', '0', '1000', []),
SettingMigrate('beerSet', '0', '1000', []),
SettingMigrate('mode', '0', '1000', [])
SettingMigrate('mode', '0', '1000', []),

SettingMigrate('heater1_kp', '0.4.0', '1000', []),
SettingMigrate('heater1_ti', '0.4.0', '1000', []),
SettingMigrate('heater1_td', '0.4.0', '1000', []),
SettingMigrate('heater1_infilt', '0.4.0', '1000', []),
SettingMigrate('heater1_dfilt', '0.4.0', '1000', []),
SettingMigrate('heater2_kp', '0.4.0', '1000', []),
SettingMigrate('heater2_ti', '0.4.0', '1000', []),
SettingMigrate('heater2_td', '0.4.0', '1000', []),
SettingMigrate('heater2_infilt', '0.4.0', '1000', []),
SettingMigrate('heater2_dfilt', '0.4.0', '1000', []),
SettingMigrate('cooler_kp', '0.4.0', '1000', []),
SettingMigrate('cooler_ti', '0.4.0', '1000', []),
SettingMigrate('cooler_td', '0.4.0', '1000', []),
SettingMigrate('cooler_infilt', '0.4.0', '1000', []),
SettingMigrate('cooler_dfilt', '0.4.0', '1000', []),
SettingMigrate('beer2fridge_kp', '0.4.0', '1000', []),
SettingMigrate('beer2fridge_ti', '0.4.0', '1000', []),
SettingMigrate('beer2fridge_td', '0.4.0', '1000', []),
SettingMigrate('beer2fridge_infilt', '0.4.0', '1000', []),
SettingMigrate('beer2fridge_dfilt', '0.4.0', '1000', []),
SettingMigrate('beer2fridge_pidMax', '0.4.0', '1000', []),
SettingMigrate('minCoolTime', '0.4.0', '1000', []),
SettingMigrate('minCoolIdleTime', '0.4.0', '1000', []),
SettingMigrate('heater1PwmPeriod', '0.4.0', '1000', []),
SettingMigrate('heater2PwmPeriod', '0.4.0', '1000', []),
SettingMigrate('coolerPwmPeriod', '0.4.0', '1000', []),
SettingMigrate('deadTime', '0.4.0', '1000', [])
]

class MigrateSettings:
Expand Down
71 changes: 34 additions & 37 deletions brewpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,13 @@ def printStdErr(*objs):
compatibleHwVersion = "0.2.4"

# Control Settings
cs = dict(mode='b', beerSet=20.0, fridgeSet=20.0, heatEstimator=0.2, coolEstimator=5)
cs = dict(mode='b', beerSet=20.0, fridgeSet=20.0)

# Control Constants
cc = dict(tempFormat="C", tempSetMin=1.0, tempSetMax=30.0, pidMax=10.0, Kp=20.000, Ki=0.600, Kd=-3.000, iMaxErr=0.500,
idleRangeH=1.000, idleRangeL=-1.000, heatTargetH=0.301, heatTargetL=-0.199, coolTargetH=0.199,
coolTargetL=-0.301, maxHeatTimeForEst="600", maxCoolTimeForEst="1200", fridgeFastFilt="1", fridgeSlowFilt="4",
fridgeSlopeFilt="3", beerFastFilt="3", beerSlowFilt="5", beerSlopeFilt="4", lah=0, hs=0)
cc = dict()

# Control variables
cv = dict(beerDiff=0.000, diffIntegral=0.000, beerSlope=0.000, p=0.000, i=0.000, d=0.000, estPeak=0.000,
negPeakEst=0.000, posPeakEst=0.000, negPeak=0.000, posPeak=0.000)
# Control variables (json string, sent directly to browser without decoding)
cv = ""

# listState = "", "d", "h", "dh" to reflect whether the list is up to date for installed (d) and available (h)
deviceList = dict(listState="", installed=[], available=[])
Expand Down Expand Up @@ -501,7 +497,7 @@ def renameTempKey(key):
cs['dataLogging'] = config['dataLogging']
conn.send(json.dumps(cs))
elif messageType == "getControlVariables":
conn.send(json.dumps(cv))
conn.send(cv)
elif messageType == "refreshControlConstants":
ser.write("c")
raise socket.timeout
Expand All @@ -523,40 +519,31 @@ def renameTempKey(key):
except ValueError:
logMessage("Cannot convert temperature '" + value + "' to float")
continue
if cc['tempSetMin'] <= newTemp <= cc['tempSetMax']:
cs['mode'] = 'b'
# round to 2 dec, python will otherwise produce 6.999999999
cs['beerSet'] = round(newTemp, 2)
ser.write("j{mode:b, beerSet:" + json.dumps(cs['beerSet']) + "}")
logMessage("Notification: Beer temperature set to " +
str(cs['beerSet']) +
" degrees in web interface")
raise socket.timeout # go to serial communication to update controller
else:
logMessage("Beer temperature setting " + str(newTemp) +
" is outside of allowed range " +
str(cc['tempSetMin']) + " - " + str(cc['tempSetMax']) +
". These limits can be changed in advanced settings.")

cs['mode'] = 'b'
# round to 2 dec, python will otherwise produce 6.999999999
cs['beerSet'] = round(newTemp, 2)
ser.write("j{mode:b, beerSet:" + json.dumps(cs['beerSet']) + "}")
logMessage("Notification: Beer temperature set to " +
str(cs['beerSet']) +
" degrees in web interface")
raise socket.timeout # go to serial communication to update controller

elif messageType == "setFridge": # new constant fridge temperature received
try:
newTemp = float(value)
except ValueError:
logMessage("Cannot convert temperature '" + value + "' to float")
continue

if cc['tempSetMin'] <= newTemp <= cc['tempSetMax']:
cs['mode'] = 'f'
cs['fridgeSet'] = round(newTemp, 2)
ser.write("j{mode:f, fridgeSet:" + json.dumps(cs['fridgeSet']) + "}")
logMessage("Notification: Fridge temperature set to " +
str(cs['fridgeSet']) +
" degrees in web interface")
raise socket.timeout # go to serial communication to update controller
else:
logMessage("Fridge temperature setting " + str(newTemp) +
" is outside of allowed range " +
str(cc['tempSetMin']) + " - " + str(cc['tempSetMax']) +
". These limits can be changed in advanced settings.")
cs['mode'] = 'f'
cs['fridgeSet'] = round(newTemp, 2)
ser.write("j{mode:f, fridgeSet:" + json.dumps(cs['fridgeSet']) + "}")
logMessage("Notification: Fridge temperature set to " +
str(cs['fridgeSet']) +
" degrees in web interface")
raise socket.timeout # go to serial communication to update controller

elif messageType == "setOff": # cs['mode'] set to OFF
cs['mode'] = 'o'
ser.write("j{mode:o}")
Expand Down Expand Up @@ -697,6 +684,13 @@ def renameTempKey(key):
continue
ser.write("U" + json.dumps(configStringJson))
deviceList['listState'] = "" # invalidate local copy
elif messageType == "writeDevice":
try:
configStringJson = json.loads(value) # load as JSON to check syntax
except json.JSONDecodeError:
logMessage("Error: invalid JSON parameter string received: " + value)
continue
ser.write("d" + json.dumps(configStringJson))
elif messageType == "getVersion":
if hwVersion:
response = hwVersion.__dict__
Expand All @@ -706,6 +700,9 @@ def renameTempKey(key):
response = {}
response_str = json.dumps(response)
conn.send(response_str)
elif messageType == "resetController":
logMessage("Resetting controller to factory defaults")
ser.write("E")
else:
logMessage("Error: Received invalid message on socket: " + message)

Expand Down Expand Up @@ -812,7 +809,7 @@ def renameTempKey(key):
# do not print this to the log file. This is requested continuously.
elif line[0] == 'V':
# Control settings received
cv = json.loads(line[2:])
cv = line[2:] # keep as string, do not decode
elif line[0] == 'N':
pass # version number received. Do nothing, just ignore
elif line[0] == 'h':
Expand Down
1 change: 1 addition & 0 deletions brewpiVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def getVersionFromSerial(ser):
retry = True
while 1: # read all lines from serial
loopTime = time.time()
line = None
try:
line = ser.readline()
except SerialException as e:
Expand Down
Loading

0 comments on commit eac6909

Please sign in to comment.