Skip to content

Commit

Permalink
dynamic options object
Browse files Browse the repository at this point in the history
  • Loading branch information
noursaidi committed May 26, 2022
1 parent 0ab1555 commit ebaf1a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
19 changes: 6 additions & 13 deletions bin/pubber
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,24 @@ else
if [[ $option == *"="* ]]; then
k=$(echo $option | cut -d'=' -f1)
v=$(echo $option | cut -d'=' -f2)
options[$k]=$v
else
options[$option]=$option
k=$option
v=$option
fi
printf -v options_json '%s"%s":"%s",' "$options_json" "$k" "$v"
done

extra_point="${options[extra_point]}"
no_hardware="${options[no_hardware]}"

if [ -n "${options[extra_field]}" ]; then
printf -v extra_field '"extraField": "%s",' "${options[extra_field]}"
fi

options_json="{${options_json%?}}"
cloud_region=`jq -r .cloud_region $site_path/cloud_iot_config.json`

cat <<EOF > /tmp/pubber_config.json
{
$extra_field
"extraPoint": "$extra_point",
"noHardware": "$no_hardware",
"projectId": "$project_id",
"sitePath": "$site_path",
"cloudRegion": "$cloud_region",
"deviceId": "$device_id",
"serialNo": "$serial"
"serialNo": "$serial",
"options": $options_json
}
EOF
$ROOT_DIR/pubber/bin/run /tmp/pubber_config.json
Expand Down
6 changes: 3 additions & 3 deletions pubber/src/main/java/daq/pubber/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package daq.pubber;

import java.util.HashMap;

/**
* General bucket of pubber configuration information.
*/
Expand All @@ -15,9 +17,7 @@ public class Configuration {
public String keyFile = "local/rsa_private.pkcs8";
public byte[] keyBytes;
public String algorithm = "RS256";
public Object extraField;
public String serialNo;
public String macAddr;
public String extraPoint;
public String noHardware;
public HashMap<String, String> options = new HashMap<>();
}
16 changes: 9 additions & 7 deletions pubber/src/main/java/daq/pubber/Pubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,25 +346,27 @@ private void initializeDevice() {
pullDeviceMessage();
}

info(String.format("Starting pubber %s, serial %s, mac %s, extra %s, gateway %s",
info(String.format("Starting pubber %s, serial %s, mac %, gateway %s, options %s",
configuration.deviceId, configuration.serialNo, configuration.macAddr,
configuration.extraField,
configuration.gatewayId));
configuration.gatewayId,
configuration.options.keySet()));

deviceState.system.operational = true;
deviceState.system.serial_no = configuration.serialNo;
deviceState.system.hardware.make = "BOS";
deviceState.system.hardware.model = "pubber";
deviceState.system.software = new HashMap<>();
deviceState.system.software.put("firmware", "v1");
devicePoints.extraField = configuration.extraField;

// Pubber runtime options
devicePoints.extraField = configuration.options.get("extra_field");

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

if (configuration.noHardware != null && !configuration.noHardware.isEmpty()) {
if (configuration.options.get("no_hardware") != null) {
deviceState.system.hardware = null;
}

Expand Down

0 comments on commit ebaf1a7

Please sign in to comment.