Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional pubber opts #338

Merged
merged 5 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions bin/pubber
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

ROOT_DIR=$(realpath $(dirname $0)/..)

if [ $# != 4 ]; then
echo $0 SITE_PATH PROJECT_ID DEVICE_ID SERIAL_NO
if [[ "${#}" -lt "4" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? $# is a lot easier to read! (Also, quotes are unnecessary with [[, since it's an explicit different parser to avoid the extra clutter!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use (( instead as per style guide

echo $0 SITE_PATH PROJECT_ID DEVICE_ID SERIAL_NO [options] ...
false
fi

Expand All @@ -23,4 +23,35 @@ $ROOT_DIR/pubber/bin/build > /dev/null

echo Running tools version `(cd $ROOT_DIR; git describe)`

$ROOT_DIR/pubber/bin/run $project_id $site_path $device_id $serial_no
if [[ "${#}" -gt "0" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would flip the if condition so the short branch is first, rather than after the else (just makes it easier to read)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition flipped

declare -A options
for option in $*; do
if [[ $option == *"="* ]]; then
k=$(echo $option | cut -d'=' -f1)
v=$(echo $option | cut -d'=' -f2)
options[$k]=$v
else
options[$option]=$option
fi
done

extra_field="${options[extra_field]}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used? I would expect somewhere in this PR to see how the added functionality is used...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraField is an existing pubber config, extra_field provides access to it. I'll update the documentation to describe the additional functionality

extra_point="${options[extra_point]}"

cloud_region=`jq -r .cloud_region $site_path/cloud_iot_config.json`

cat <<EOF > /tmp/pubber_config.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent seems too much?

{
"projectId": "$project_id",
"sitePath": "$site_path",
"cloudRegion": "$cloud_region",
"deviceId": "$device_id",
"serialNo": "$serial",
"extraField": "$extra_field",
"extraPoint": "$extra_point"
}
EOF
$ROOT_DIR/pubber/bin/run /tmp/pubber_config.json
else
$ROOT_DIR/pubber/bin/run $project_id $site_path $device_id $serial_no
fi
1 change: 1 addition & 0 deletions pubber/src/main/java/daq/pubber/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public class Configuration {
public Object extraField;
public String serialNo;
public String macAddr;
public String extraPoint;
}
4 changes: 4 additions & 0 deletions pubber/src/main/java/daq/pubber/Pubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ private void initializeDevice() {
deviceState.system.software.put("firmware", "v1");
devicePoints.extraField = configuration.extraField;

if (configuration.extraPoint != null && !configuration.extraPoint.isEmpty()) {
addPoint(makePoint(configuration.extraPoint,
makePointPointsetModel(true, 50, 50, "Celsius")));
}
markStateDirty(0);
}

Expand Down