This commit is contained in:
Wolfgang Hottgenroth 2016-10-31 22:54:05 +01:00
commit bb4b7b5aa0
37 changed files with 6322 additions and 0 deletions

80
.cproject Normal file
View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="it.baeyens.arduino.core.toolChain.release.529393341">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="it.baeyens.arduino.core.toolChain.release.529393341" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="it.baeyens.arduino.core.toolChain.release.529393341" name="Release" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="it.baeyens.arduino.core.toolChain.release.529393341.148865277" name="/" resourcePath="">
<toolChain id="it.baeyens.arduino.core.toolChain.release.1153040966" name="Arduino Toolchain" superClass="it.baeyens.arduino.core.toolChain.release">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="it.baeyens.arduino.targetplatform.1319012492" name="Arduino Target" osList="all" superClass="it.baeyens.arduino.targetplatform"/>
<builder buildPath="${workspace_loc:/MqttCanGateway}/Release" id="it.baeyens.arduino.sketch.builder.679057398" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Arduino sketch builder" superClass="it.baeyens.arduino.sketch.builder"/>
<tool id="it.baeyens.arduino.tool.sketch.compiler.cpp.829286184" name="Arduino C++ Compiler" superClass="it.baeyens.arduino.tool.sketch.compiler.cpp">
<option id="it.baeyens.arduino.compiler.cpp.sketch.option.incpath.782027353" name="Include Paths (-I)" superClass="it.baeyens.arduino.compiler.cpp.sketch.option.incpath" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/core/core}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/Ethernet}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/SPI}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/MQTT}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/Metro}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/Streaming}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Mqtt433Gateway/core/core}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Mqtt433Gateway/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Mqtt433Gateway/RCSwitch}&quot;"/>
</option>
<inputType id="it.baeyens.arduino.compiler.cpp.sketch.input.1245900398" name="CPP source files" superClass="it.baeyens.arduino.compiler.cpp.sketch.input"/>
</tool>
<tool id="it.baeyens.arduino.tool.compiler.c.52124755" name="Arduino C Compiler" superClass="it.baeyens.arduino.tool.compiler.c">
<option id="it.baeyens.arduino.compiler.c.sketch.option.incpath.1259025011" name="Include Paths (-I)" superClass="it.baeyens.arduino.compiler.c.sketch.option.incpath" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/core/core}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/Ethernet}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/SPI}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/MQTT}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/Metro}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MqttCanGateway/Streaming}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Mqtt433Gateway/core/core}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Mqtt433Gateway/core/variant}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Mqtt433Gateway/RCSwitch}&quot;"/>
</option>
<inputType id="it.baeyens.arduino.compiler.c.sketch.input.1973835002" name="C Source Files" superClass="it.baeyens.arduino.compiler.c.sketch.input"/>
</tool>
<tool id="it.baeyens.arduino.tool.sketch.compiler.s.169355870" name="Arduino Assembler" superClass="it.baeyens.arduino.tool.sketch.compiler.s"/>
<tool id="it.baeyens.arduino.tool.ar.1101742557" name="Arduino archiver" superClass="it.baeyens.arduino.tool.ar"/>
<tool id="it.baeyens.arduino.tool.combine.1907141724" name="Arduino combiner" superClass="it.baeyens.arduino.tool.combine"/>
<tool id="it.baeyens.arduino.tool.objcopy.eep.1209401138" name="Arduino tool Create eeprom" superClass="it.baeyens.arduino.tool.objcopy.eep"/>
<tool id="it.baeyens.arduino.tool.objcopy.flash.1098943571" name="Arduino tool Create hex" superClass="it.baeyens.arduino.tool.objcopy.flash"/>
<tool id="it.baeyens.arduino.tool.size.161372956" name="Arduino tool Print Size" superClass="it.baeyens.arduino.tool.size"/>
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="Metro|Streaming|MQTT|CAN|SPI|Ethernet|libraries/**/?xamples/**|libraries/**/?xtras/**|libraries/**/test/**|libraries/**/third-party/**|libraries**/._*" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Ethernet"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTT"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Metro"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="SPI"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Streaming"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="MqttCanGateway.null.1016889897" name="MqttCanGateway"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="refreshScope"/>
</cproject>

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/Release/

45
.project Normal file
View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Mqtt433Gateway</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>it.baeyens.arduino.core.inoToCpp</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>it.baeyens.arduinonature</nature>
</natures>
<linkedResources>
<link>
<name>core/core</name>
<type>2</type>
<location>/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.14/cores/arduino</location>
</link>
<link>
<name>core/variant</name>
<type>2</type>
<location>/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.14/variants/standard</location>
</link>
</linkedResources>
</projectDescription>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="it.baeyens.arduino.core.toolChain.release.529393341" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="it.baeyens.arduino.toolchain.ArduinoLanguageProvider" console="false" env-hash="-495307737102899092" id="it.baeyens.arduino.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension>
</configuration>
</project>

View File

@ -0,0 +1,465 @@
eclipse.preferences.version=1
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ALT_SIZE_COMMAND/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ALT_SIZE_COMMAND/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ALT_SIZE_COMMAND/value="${A.COMPILER.PATH}${A.COMPILER.SIZE.CMD}" --format\=avr --mcu\=${A.BUILD.MCU} "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHITECTURE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHITECTURE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHITECTURE/value=AVR
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHIVE_FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHIVE_FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHIVE_FILE/value=arduino.ar
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHIVE_FILE_PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHIVE_FILE_PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.ARCHIVE_FILE_PATH/value=${A.BUILD.PATH}/${A.ARCHIVE_FILE}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.EXTENDED_FUSES/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.EXTENDED_FUSES/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.EXTENDED_FUSES/value=0x05
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.FILE/value=optiboot/optiboot_atmega328.hex
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.HIGH_FUSES/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.HIGH_FUSES/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.HIGH_FUSES/value=0xDE
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.LOCK_BITS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.LOCK_BITS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.LOCK_BITS/value=0x0F
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.LOW_FUSES/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.LOW_FUSES/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.LOW_FUSES/value=0xFF
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.TOOL/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.TOOL/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.TOOL/value=avrdude
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.UNLOCK_BITS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.UNLOCK_BITS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BOOTLOADER.UNLOCK_BITS/value=0x3F
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.ARCH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.ARCH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.ARCH/value=AVR
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.BOARD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.BOARD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.BOARD/value=AVR_UNO
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.CORE.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.CORE.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.CORE.PATH/value=${A.RUNTIME.PLATFORM.PATH}/cores/${A.BUILD.CORE}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.CORE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.CORE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.CORE/value=${JANTJE.BUILD_CORE}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.F_CPU/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.F_CPU/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.F_CPU/value=16000000L
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.MCU/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.MCU/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.MCU/value=atmega328p
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.PATH/value=${ProjDirPath}/${ConfigName}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.PROJECT_NAME/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.PROJECT_NAME/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.PROJECT_NAME/value=${ProjName}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.SYSTEM.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.SYSTEM.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.SYSTEM.PATH/value=${A.RUNTIME.PLATFORM.PATH}/system
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_FLAGS.WINDOWS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_FLAGS.WINDOWS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_FLAGS.WINDOWS/value=-DUSB_VID\=${A.BUILD.VID} -DUSB_PID\=${A.BUILD.PID} -DUSBCON -DUSB_MANUFACTURER\=\\"${A.BUILD.USB_MANUFACTURER}\\" -DUSB_PRODUCT\=\\"${A.BUILD.USB_PRODUCT}\\"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_FLAGS/value=-DUSB_VID\=${A.BUILD.VID} -DUSB_PID\=${A.BUILD.PID} '-DUSB_MANUFACTURER\=${A.BUILD.USB_MANUFACTURER}' '-DUSB_PRODUCT\=${A.BUILD.USB_PRODUCT}'
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_MANUFACTURER/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_MANUFACTURER/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.USB_MANUFACTURER/value="Unknown"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.VARIANT.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.VARIANT.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.VARIANT.PATH/value=${A.RUNTIME.PLATFORM.PATH}/variants/${A.BUILD.VARIANT}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.VARIANT/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.VARIANT/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.BUILD.VARIANT/value=${JANTJE.BUILD_VARIANT}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.CMD/value=avr-gcc-ar
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.AR.FLAGS/value=rcs
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.CMD/value=avr-gcc
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.CMD/value=avr-gcc
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.ELF.FLAGS/value=${A.COMPILER.WARNING_FLAGS} -Os -flto -fuse-linker-plugin -Wl,--gc-sections
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.C.FLAGS/value=-c -g -Os ${A.COMPILER.WARNING_FLAGS} -std\=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.CMD/value=avr-g++
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.CPP.FLAGS/value=-c -g -Os ${A.COMPILER.WARNING_FLAGS} -std\=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.CMD/value=avr-objcopy
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.ELF2HEX.FLAGS/value=-O ihex -R .eeprom
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.LDFLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.LDFLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.LDFLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.CMD/value=avr-objcopy
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.EEP.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.EEP.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.EEP.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.EEP.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.EEP.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.OBJCOPY.EEP.FLAGS/value=-O ihex -j .eeprom --set-section-flags\=.eeprom\=alloc,load --no-change-warnings --change-section-lma .eeprom\=0
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.PATH/value=${A.RUNTIME.TOOLS.AVR-GCC.PATH}/bin/
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.S.EXTRA_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.S.EXTRA_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.S.EXTRA_FLAGS/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.S.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.S.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.S.FLAGS/value=-c -g -x assembler-with-cpp -flto
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.SIZE.CMD/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.SIZE.CMD/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.SIZE.CMD/value=avr-size
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.ALL/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.ALL/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.ALL/value=-Wall -Wextra
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.DEFAULT/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.DEFAULT/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.DEFAULT/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.MORE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.MORE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.MORE/value=-Wall
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.NONE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.NONE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS.NONE/value=-w
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.COMPILER.WARNING_FLAGS/value=-w
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.DTS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.DTS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.DTS/value=0
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.LOCAL/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.LOCAL/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.LOCAL/value=1477954128
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.UTC/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.UTC/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.UTC/value=1477950528
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.ZONE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.ZONE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.EXTRA.TIME.ZONE/value=3600
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.NAME/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.NAME/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.NAME/value=Arduino/Genuino Uno
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PATH/value=${A.TOOLS.AVRDUDE.PATH}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.0/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.0/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.0/value=0x0043
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.1/value=0x0001
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.2/value=0x0043
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.3/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.3/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PID.3/value=0x0243
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PREPROC.INCLUDES.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PREPROC.INCLUDES.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PREPROC.INCLUDES.FLAGS/value=-w -x c++ -M -MG -MP
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PREPROC.MACROS.FLAGS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PREPROC.MACROS.FLAGS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.PREPROC.MACROS.FLAGS/value=-w -x c++ -E -CC
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.AR.CMD}" ${A.COMPILER.AR.FLAGS} ${A.COMPILER.AR.EXTRA_FLAGS} "${A.ARCHIVE_FILE_PATH}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN.2/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.AR.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.AR.CMD}" ${A.COMPILER.AR.FLAGS} ${A.COMPILER.AR.EXTRA_FLAGS} "${A.ARCHIVE_FILE_PATH}" "${A.OBJECT_FILE}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.C.ELF.CMD}" ${A.COMPILER.C.ELF.FLAGS} -mmcu\=${A.BUILD.MCU} ${A.COMPILER.C.ELF.EXTRA_FLAGS} -o "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.2/value=\
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.3/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.3/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN.3/value=\ "-L${A.BUILD.PATH}" -lm
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.COMBINE.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.C.ELF.CMD}" ${A.COMPILER.C.ELF.FLAGS} -mmcu\=${A.BUILD.MCU} ${A.COMPILER.C.ELF.EXTRA_FLAGS} -o "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf" ${A.OBJECT_FILES} "${A.BUILD.PATH}/${A.ARCHIVE_FILE}" "-L${A.BUILD.PATH}" -lm
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.C.CMD}" ${A.COMPILER.C.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.C.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.2/value=\ -o
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.3/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.3/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN.3/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.C.O.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.C.CMD}" ${A.COMPILER.C.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.C.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES} "${A.SOURCE_FILE}" -o "${A.OBJECT_FILE}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.CPP.CMD}" ${A.COMPILER.CPP.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.CPP.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.2/value=\ -o
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.3/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.3/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN.3/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.CPP.O.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.CPP.CMD}" ${A.COMPILER.CPP.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.CPP.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES} "${A.SOURCE_FILE}" -o "${A.OBJECT_FILE}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.EEP.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.EEP.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.EEP.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.OBJCOPY.CMD}" ${A.COMPILER.OBJCOPY.EEP.FLAGS} ${A.COMPILER.OBJCOPY.EEP.EXTRA_FLAGS} "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf" "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.eep"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.EEP.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.EEP.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.EEP.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.OBJCOPY.CMD}" ${A.COMPILER.OBJCOPY.EEP.FLAGS} ${A.COMPILER.OBJCOPY.EEP.EXTRA_FLAGS} "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf" "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.eep"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.HEX.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.HEX.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.HEX.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.ELF2HEX.CMD}" ${A.COMPILER.ELF2HEX.FLAGS} ${A.COMPILER.ELF2HEX.EXTRA_FLAGS} "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf" "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.hex"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.HEX.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.HEX.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OBJCOPY.HEX.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.ELF2HEX.CMD}" ${A.COMPILER.ELF2HEX.FLAGS} ${A.COMPILER.ELF2HEX.EXTRA_FLAGS} "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf" "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.hex"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OUTPUT.SAVE_FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OUTPUT.SAVE_FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OUTPUT.SAVE_FILE/value=${A.BUILD.PROJECT_NAME}.${A.BUILD.VARIANT}.hex
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OUTPUT.TMP_FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OUTPUT.TMP_FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.OUTPUT.TMP_FILE/value=${A.BUILD.PROJECT_NAME}.hex
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.PREPROC.INCLUDES/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.PREPROC.INCLUDES/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.PREPROC.INCLUDES/value="${A.COMPILER.PATH}${A.COMPILER.CPP.CMD}" ${A.COMPILER.CPP.FLAGS} ${A.PREPROC.INCLUDES.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.CPP.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES} "${A.SOURCE_FILE}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.PREPROC.MACROS/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.PREPROC.MACROS/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.PREPROC.MACROS/value="${A.COMPILER.PATH}${A.COMPILER.CPP.CMD}" ${A.COMPILER.CPP.FLAGS} ${A.PREPROC.MACROS.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.CPP.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES} "${A.SOURCE_FILE}" -o "${A.PREPROCESSED_FILE_PATH}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.C.CMD}" ${A.COMPILER.S.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.S.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.2/value=\ -o
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.3/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.3/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN.3/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.S.O.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.C.CMD}" ${A.COMPILER.S.FLAGS} -mmcu\=${A.BUILD.MCU} -DF_CPU\=${A.BUILD.F_CPU} -DARDUINO\=${A.RUNTIME.IDE.VERSION} -DARDUINO_${A.BUILD.BOARD} -DARDUINO_ARCH_${A.BUILD.ARCH} ${A.COMPILER.S.EXTRA_FLAGS} ${A.BUILD.EXTRA_FLAGS} ${A.INCLUDES} "${A.SOURCE_FILE}" -o "${A.OBJECT_FILE}"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.PATTERN.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.PATTERN.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.PATTERN.1/value="${A.COMPILER.PATH}${A.COMPILER.SIZE.CMD}" -A "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.PATTERN/value="${A.COMPILER.PATH}${A.COMPILER.SIZE.CMD}" -A "${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX.DATA/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX.DATA/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX.DATA/value=^(?\:\\.data|\\.bss|\\.noinit)\\s+([0-9]+).*
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX.EEPROM/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX.EEPROM/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX.EEPROM/value=^(?\:\\.eeprom)\\s+([0-9]+).*
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RECIPE.SIZE.REGEX/value=^(?\:\\.text|\\.data|\\.bootloader)\\s+([0-9]+).*
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.HARDWARE.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.HARDWARE.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.HARDWARE.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/packages/arduino/hardware
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.IDE.VERSION/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.IDE.VERSION/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.IDE.VERSION/value=10606
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.PLATFORM.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.PLATFORM.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.PLATFORM.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.14
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC-4.9.2-ATMEL3.5.3-ARDUINO2.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC-4.9.2-ATMEL3.5.3-ARDUINO2.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC-4.9.2-ATMEL3.5.3-ARDUINO2.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/tools/arduino/avr-gcc/4.9.2-atmel3.5.3-arduino2
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/tools/arduino/avr-gcc/4.9.2-atmel3.5.3-arduino2
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC4.9.2-ATMEL3.5.3-ARDUINO2.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC4.9.2-ATMEL3.5.3-ARDUINO2.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVR-GCC4.9.2-ATMEL3.5.3-ARDUINO2.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/tools/arduino/avr-gcc/4.9.2-atmel3.5.3-arduino2
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE-6.3.0-ARDUINO6.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE-6.3.0-ARDUINO6.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE-6.3.0-ARDUINO6.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/tools/arduino/avrdude/6.3.0-arduino6
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/tools/arduino/avrdude/6.3.0-arduino6
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE6.3.0-ARDUINO6.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE6.3.0-ARDUINO6.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.RUNTIME.TOOLS.AVRDUDE6.3.0-ARDUINO6.PATH/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/tools/arduino/avrdude/6.3.0-arduino6
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.SOFTWARE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.SOFTWARE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.SOFTWARE/value=baeyens
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PARAMS.QUIET/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PARAMS.QUIET/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PARAMS.QUIET/value=-q -q
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PARAMS.VERBOSE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PARAMS.VERBOSE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PARAMS.VERBOSE/value=-v
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.BOOTLOADER.PATTERN/value="${A.CMD.PATH}" "-C${A.CONFIG.PATH}" ${A.BOOTLOADER.VERBOSE} -p${A.BUILD.MCU} -c${A.PROTOCOL} ${A.PROGRAM.EXTRA_PARAMS} "-Uflash\:w\:${A.RUNTIME.PLATFORM.PATH}/bootloaders/${A.BOOTLOADER.FILE}\:i" -Ulock\:w\:${A.BOOTLOADER.LOCK_BITS}\:m
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.CMD.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.CMD.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.CMD.PATH/value=${A.PATH}/bin/avrdude
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.CONFIG.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.CONFIG.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.CONFIG.PATH/value=${A.PATH}/etc/avrdude.conf
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PARAMS.QUIET/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PARAMS.QUIET/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PARAMS.QUIET/value=-q -q
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PARAMS.VERBOSE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PARAMS.VERBOSE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PARAMS.VERBOSE/value=-v
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.ERASE.PATTERN/value="${A.CMD.PATH}" "-C${A.CONFIG.PATH}" ${A.ERASE.VERBOSE} -p${A.BUILD.MCU} -c${A.PROTOCOL} ${A.PROGRAM.EXTRA_PARAMS} -e -Ulock\:w\:${A.BOOTLOADER.UNLOCK_BITS}\:m -Uefuse\:w\:${A.BOOTLOADER.EXTENDED_FUSES}\:m -Uhfuse\:w\:${A.BOOTLOADER.HIGH_FUSES}\:m -Ulfuse\:w\:${A.BOOTLOADER.LOW_FUSES}\:m
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PATH/value=${A.RUNTIME.TOOLS.AVRDUDE.PATH}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.NOVERIFY/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.NOVERIFY/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.NOVERIFY/value=-V
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.QUIET/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.QUIET/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.QUIET/value=-q -q
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.VERBOSE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.VERBOSE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PARAMS.VERBOSE/value=-v
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.PROGRAM.PATTERN/value="${A.CMD.PATH}" "-C${A.CONFIG.PATH}" ${A.PROGRAM.VERBOSE} ${A.PROGRAM.VERIFY} -p${A.BUILD.MCU} -c${A.PROTOCOL} ${A.PROGRAM.EXTRA_PARAMS} "-Uflash\:w\:${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.hex\:i"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.NOVERIFY/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.NOVERIFY/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.NOVERIFY/value=-V
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.QUIET/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.QUIET/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.QUIET/value=-q -q
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.VERBOSE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.VERBOSE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PARAMS.VERBOSE/value=-v
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE.UPLOAD.PATTERN/value="${A.TOOLS.AVRDUDE.CMD.PATH}" "-C${A.TOOLS.AVRDUDE.CONFIG.PATH}" ${A.UPLOAD.VERBOSE} ${A.UPLOAD.VERIFY} -p${A.BUILD.MCU} -c${A.UPLOAD.PROTOCOL} -P${A.SERIAL.PORT} -b${A.UPLOAD.SPEED} -D "-Uflash\:w\:${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.hex\:i"
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE_REMOTE.UPLOAD.PATTERN/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE_REMOTE.UPLOAD.PATTERN/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.TOOLS.AVRDUDE_REMOTE.UPLOAD.PATTERN/value=/usr/bin/run-avrdude /tmp/sketch.hex ${A.UPLOAD.VERBOSE} -p${A.BUILD.MCU}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.MAXIMUM_DATA_SIZE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.MAXIMUM_DATA_SIZE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.MAXIMUM_DATA_SIZE/value=2048
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.MAXIMUM_SIZE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.MAXIMUM_SIZE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.MAXIMUM_SIZE/value=32256
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.PROTOCOL/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.PROTOCOL/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.PROTOCOL/value=arduino
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.SPEED/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.SPEED/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.SPEED/value=115200
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.TOOL/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.TOOL/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.UPLOAD.TOOL/value=avrdude
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VERSION/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VERSION/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VERSION/value=1.6.14
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.0/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.0/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.0/value=0x2341
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.1/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.1/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.1/value=0x2341
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.2/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.2/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.2/value=0x2A03
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.3/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.3/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/A.VID.3/value=0x2341
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.ARCHITECTURE_ID/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.ARCHITECTURE_ID/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.ARCHITECTURE_ID/value=avr
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARDS_FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARDS_FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARDS_FILE/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.14/boards.txt
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARD_ID/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARD_ID/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARD_ID/value=uno
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARD_NAME/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARD_NAME/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BOARD_NAME/value=Arduino/Genuino Uno
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BUILD_CORE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BUILD_CORE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BUILD_CORE/value=arduino
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BUILD_VARIANT/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BUILD_VARIANT/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.BUILD_VARIANT/value=standard
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.COM_PORT/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.COM_PORT/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.COM_PORT/value=/dev/ttyACM1
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.C.COMPILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.C.COMPILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.C.COMPILE/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.COMPILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.COMPILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.COMPILE/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.CPP.COMPILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.CPP.COMPILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.EXTRA.CPP.COMPILE/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PACKAGE.NAME/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PACKAGE.NAME/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PACKAGE.NAME/value=arduino
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PACKAGE_ID/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PACKAGE_ID/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PACKAGE_ID/value=arduino
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PLATFORM_FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PLATFORM_FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.PLATFORM_FILE/value=/opt/eclipse/eclipse-arduino/cpp-neon/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.14/platform.txt
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.Processor/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.Processor/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.Processor/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.REFERENCED_PLATFORM_FILE/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.REFERENCED_PLATFORM_FILE/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.REFERENCED_PLATFORM_FILE/value=
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.SIZE.SWITCH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.SIZE.SWITCH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.SIZE.SWITCH/value=${A.RECIPE.SIZE.PATTERN}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.WARNING_LEVEL/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.WARNING_LEVEL/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/JANTJE.WARNING_LEVEL/value=\ -Wall
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/PATH/delimiter=\:
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/PATH/operation=replace
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/PATH/value=${A.COMPILER.PATH}${PathDelimiter}${A.BUILD.GENERIC.PATH}${PathDelimiter}${PATH}
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/append=true
environment/project/it.baeyens.arduino.core.toolChain.release.529393341/appendContributed=true

471
Ethernet/Dhcp.cpp Normal file
View File

@ -0,0 +1,471 @@
// DHCP Library v0.3 - April 25, 2009
// Author: Jordan Terrell - blog.jordanterrell.com
#include "utility/w5100.h"
#include <string.h>
#include <stdlib.h>
#include "Dhcp.h"
#include "Arduino.h"
#include "utility/util.h"
int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
{
_dhcpLeaseTime=0;
_dhcpT1=0;
_dhcpT2=0;
_timeout = timeout;
_responseTimeout = responseTimeout;
// zero out _dhcpMacAddr
memset(_dhcpMacAddr, 0, 6);
reset_DHCP_lease();
memcpy((void*)_dhcpMacAddr, (void*)mac, 6);
_dhcp_state = STATE_DHCP_START;
return request_DHCP_lease();
}
void DhcpClass::reset_DHCP_lease(){
// zero out _dhcpSubnetMask, _dhcpGatewayIp, _dhcpLocalIp, _dhcpDhcpServerIp, _dhcpDnsServerIp
memset(_dhcpLocalIp, 0, 20);
}
//return:0 on error, 1 if request is sent and response is received
int DhcpClass::request_DHCP_lease(){
uint8_t messageType = 0;
// Pick an initial transaction ID
_dhcpTransactionId = random(1UL, 2000UL);
_dhcpInitialTransactionId = _dhcpTransactionId;
_dhcpUdpSocket.stop();
if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
{
// Couldn't get a socket
return 0;
}
presend_DHCP();
int result = 0;
unsigned long startTime = millis();
while(_dhcp_state != STATE_DHCP_LEASED)
{
if(_dhcp_state == STATE_DHCP_START)
{
_dhcpTransactionId++;
send_DHCP_MESSAGE(DHCP_DISCOVER, ((millis() - startTime) / 1000));
_dhcp_state = STATE_DHCP_DISCOVER;
}
else if(_dhcp_state == STATE_DHCP_REREQUEST){
_dhcpTransactionId++;
send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime)/1000));
_dhcp_state = STATE_DHCP_REQUEST;
}
else if(_dhcp_state == STATE_DHCP_DISCOVER)
{
uint32_t respId;
messageType = parseDHCPResponse(_responseTimeout, respId);
if(messageType == DHCP_OFFER)
{
// We'll use the transaction ID that the offer came with,
// rather than the one we were up to
_dhcpTransactionId = respId;
send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime) / 1000));
_dhcp_state = STATE_DHCP_REQUEST;
}
}
else if(_dhcp_state == STATE_DHCP_REQUEST)
{
uint32_t respId;
messageType = parseDHCPResponse(_responseTimeout, respId);
if(messageType == DHCP_ACK)
{
_dhcp_state = STATE_DHCP_LEASED;
result = 1;
//use default lease time if we didn't get it
if(_dhcpLeaseTime == 0){
_dhcpLeaseTime = DEFAULT_LEASE;
}
// Calculate T1 & T2 if we didn't get it
if(_dhcpT1 == 0){
// T1 should be 50% of _dhcpLeaseTime
_dhcpT1 = _dhcpLeaseTime >> 1;
}
if(_dhcpT2 == 0){
// T2 should be 87.5% (7/8ths) of _dhcpLeaseTime
_dhcpT2 = _dhcpLeaseTime - (_dhcpLeaseTime >> 3);
}
_renewInSec = _dhcpT1;
_rebindInSec = _dhcpT2;
}
else if(messageType == DHCP_NAK)
_dhcp_state = STATE_DHCP_START;
}
if(messageType == 255)
{
messageType = 0;
_dhcp_state = STATE_DHCP_START;
}
if(result != 1 && ((millis() - startTime) > _timeout))
break;
}
// We're done with the socket now
_dhcpUdpSocket.stop();
_dhcpTransactionId++;
_lastCheckLeaseMillis = millis();
return result;
}
void DhcpClass::presend_DHCP()
{
}
void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed)
{
uint8_t buffer[32];
memset(buffer, 0, 32);
IPAddress dest_addr( 255, 255, 255, 255 ); // Broadcast address
if (-1 == _dhcpUdpSocket.beginPacket(dest_addr, DHCP_SERVER_PORT))
{
// FIXME Need to return errors
return;
}
buffer[0] = DHCP_BOOTREQUEST; // op
buffer[1] = DHCP_HTYPE10MB; // htype
buffer[2] = DHCP_HLENETHERNET; // hlen
buffer[3] = DHCP_HOPS; // hops
// xid
unsigned long xid = htonl(_dhcpTransactionId);
memcpy(buffer + 4, &(xid), 4);
// 8, 9 - seconds elapsed
buffer[8] = ((secondsElapsed & 0xff00) >> 8);
buffer[9] = (secondsElapsed & 0x00ff);
// flags
unsigned short flags = htons(DHCP_FLAGSBROADCAST);
memcpy(buffer + 10, &(flags), 2);
// ciaddr: already zeroed
// yiaddr: already zeroed
// siaddr: already zeroed
// giaddr: already zeroed
//put data in W5100 transmit buffer
_dhcpUdpSocket.write(buffer, 28);
memset(buffer, 0, 32); // clear local buffer
memcpy(buffer, _dhcpMacAddr, 6); // chaddr
//put data in W5100 transmit buffer
_dhcpUdpSocket.write(buffer, 16);
memset(buffer, 0, 32); // clear local buffer
// leave zeroed out for sname && file
// put in W5100 transmit buffer x 6 (192 bytes)
for(int i = 0; i < 6; i++) {
_dhcpUdpSocket.write(buffer, 32);
}
// OPT - Magic Cookie
buffer[0] = (uint8_t)((MAGIC_COOKIE >> 24)& 0xFF);
buffer[1] = (uint8_t)((MAGIC_COOKIE >> 16)& 0xFF);
buffer[2] = (uint8_t)((MAGIC_COOKIE >> 8)& 0xFF);
buffer[3] = (uint8_t)(MAGIC_COOKIE& 0xFF);
// OPT - message type
buffer[4] = dhcpMessageType;
buffer[5] = 0x01;
buffer[6] = messageType; //DHCP_REQUEST;
// OPT - client identifier
buffer[7] = dhcpClientIdentifier;
buffer[8] = 0x07;
buffer[9] = 0x01;
memcpy(buffer + 10, _dhcpMacAddr, 6);
// OPT - host name
buffer[16] = hostName;
buffer[17] = strlen(HOST_NAME) + 6; // length of hostname + last 3 bytes of mac address
strcpy((char*)&(buffer[18]), HOST_NAME);
printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);
//put data in W5100 transmit buffer
_dhcpUdpSocket.write(buffer, 30);
if(messageType == DHCP_REQUEST)
{
buffer[0] = dhcpRequestedIPaddr;
buffer[1] = 0x04;
buffer[2] = _dhcpLocalIp[0];
buffer[3] = _dhcpLocalIp[1];
buffer[4] = _dhcpLocalIp[2];
buffer[5] = _dhcpLocalIp[3];
buffer[6] = dhcpServerIdentifier;
buffer[7] = 0x04;
buffer[8] = _dhcpDhcpServerIp[0];
buffer[9] = _dhcpDhcpServerIp[1];
buffer[10] = _dhcpDhcpServerIp[2];
buffer[11] = _dhcpDhcpServerIp[3];
//put data in W5100 transmit buffer
_dhcpUdpSocket.write(buffer, 12);
}
buffer[0] = dhcpParamRequest;
buffer[1] = 0x06;
buffer[2] = subnetMask;
buffer[3] = routersOnSubnet;
buffer[4] = dns;
buffer[5] = domainName;
buffer[6] = dhcpT1value;
buffer[7] = dhcpT2value;
buffer[8] = endOption;
//put data in W5100 transmit buffer
_dhcpUdpSocket.write(buffer, 9);
_dhcpUdpSocket.endPacket();
}
uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId)
{
uint8_t type = 0;
uint8_t opt_len = 0;
unsigned long startTime = millis();
while(_dhcpUdpSocket.parsePacket() <= 0)
{
if((millis() - startTime) > responseTimeout)
{
return 255;
}
delay(50);
}
// start reading in the packet
RIP_MSG_FIXED fixedMsg;
_dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED));
if(fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT)
{
transactionId = ntohl(fixedMsg.xid);
if(memcmp(fixedMsg.chaddr, _dhcpMacAddr, 6) != 0 || (transactionId < _dhcpInitialTransactionId) || (transactionId > _dhcpTransactionId))
{
// Need to read the rest of the packet here regardless
_dhcpUdpSocket.flush();
return 0;
}
memcpy(_dhcpLocalIp, fixedMsg.yiaddr, 4);
// Skip to the option part
// Doing this a byte at a time so we don't have to put a big buffer
// on the stack (as we don't have lots of memory lying around)
for (int i =0; i < (240 - (int)sizeof(RIP_MSG_FIXED)); i++)
{
_dhcpUdpSocket.read(); // we don't care about the returned byte
}
while (_dhcpUdpSocket.available() > 0)
{
switch (_dhcpUdpSocket.read())
{
case endOption :
break;
case padOption :
break;
case dhcpMessageType :
opt_len = _dhcpUdpSocket.read();
type = _dhcpUdpSocket.read();
break;
case subnetMask :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read(_dhcpSubnetMask, 4);
break;
case routersOnSubnet :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read(_dhcpGatewayIp, 4);
for (int i = 0; i < opt_len-4; i++)
{
_dhcpUdpSocket.read();
}
break;
case dns :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
for (int i = 0; i < opt_len-4; i++)
{
_dhcpUdpSocket.read();
}
break;
case dhcpServerIdentifier :
opt_len = _dhcpUdpSocket.read();
if ((_dhcpDhcpServerIp[0] == 0 && _dhcpDhcpServerIp[1] == 0 &&
_dhcpDhcpServerIp[2] == 0 && _dhcpDhcpServerIp[3] == 0) ||
IPAddress(_dhcpDhcpServerIp) == _dhcpUdpSocket.remoteIP())
{
_dhcpUdpSocket.read(_dhcpDhcpServerIp, sizeof(_dhcpDhcpServerIp));
}
else
{
// Skip over the rest of this option
while (opt_len--)
{
_dhcpUdpSocket.read();
}
}
break;
case dhcpT1value :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read((uint8_t*)&_dhcpT1, sizeof(_dhcpT1));
_dhcpT1 = ntohl(_dhcpT1);
break;
case dhcpT2value :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read((uint8_t*)&_dhcpT2, sizeof(_dhcpT2));
_dhcpT2 = ntohl(_dhcpT2);
break;
case dhcpIPaddrLeaseTime :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read((uint8_t*)&_dhcpLeaseTime, sizeof(_dhcpLeaseTime));
_dhcpLeaseTime = ntohl(_dhcpLeaseTime);
_renewInSec = _dhcpLeaseTime;
break;
default :
opt_len = _dhcpUdpSocket.read();
// Skip over the rest of this option
while (opt_len--)
{
_dhcpUdpSocket.read();
}
break;
}
}
}
// Need to skip to end of the packet regardless here
_dhcpUdpSocket.flush();
return type;
}
/*
returns:
0/DHCP_CHECK_NONE: nothing happened
1/DHCP_CHECK_RENEW_FAIL: renew failed
2/DHCP_CHECK_RENEW_OK: renew success
3/DHCP_CHECK_REBIND_FAIL: rebind fail
4/DHCP_CHECK_REBIND_OK: rebind success
*/
int DhcpClass::checkLease(){
int rc = DHCP_CHECK_NONE;
unsigned long now = millis();
unsigned long elapsed = now - _lastCheckLeaseMillis;
// if more then one sec passed, reduce the counters accordingly
if (elapsed >= 1000) {
// set the new timestamps
_lastCheckLeaseMillis = now - (elapsed % 1000);
elapsed = elapsed / 1000;
// decrease the counters by elapsed seconds
// we assume that the cycle time (elapsed) is fairly constant
// if the remainder is less than cycle time * 2
// do it early instead of late
if (_renewInSec < elapsed * 2)
_renewInSec = 0;
else
_renewInSec -= elapsed;
if (_rebindInSec < elapsed * 2)
_rebindInSec = 0;
else
_rebindInSec -= elapsed;
}
// if we have a lease but should renew, do it
if (_renewInSec == 0 &&_dhcp_state == STATE_DHCP_LEASED) {
_dhcp_state = STATE_DHCP_REREQUEST;
rc = 1 + request_DHCP_lease();
}
// if we have a lease or is renewing but should bind, do it
if (_rebindInSec == 0 && (_dhcp_state == STATE_DHCP_LEASED || _dhcp_state == STATE_DHCP_START)) {
// this should basically restart completely
_dhcp_state = STATE_DHCP_START;
reset_DHCP_lease();
rc = 3 + request_DHCP_lease();
}
return rc;
}
IPAddress DhcpClass::getLocalIp()
{
return IPAddress(_dhcpLocalIp);
}
IPAddress DhcpClass::getSubnetMask()
{
return IPAddress(_dhcpSubnetMask);
}
IPAddress DhcpClass::getGatewayIp()
{
return IPAddress(_dhcpGatewayIp);
}
IPAddress DhcpClass::getDhcpServerIp()
{
return IPAddress(_dhcpDhcpServerIp);
}
IPAddress DhcpClass::getDnsServerIp()
{
return IPAddress(_dhcpDnsServerIp);
}
void DhcpClass::printByte(char * buf, uint8_t n ) {
char *str = &buf[1];
buf[0]='0';
do {
unsigned long m = n;
n /= 16;
char c = m - 16 * n;
*str-- = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
}

177
Ethernet/Dhcp.h Normal file
View File

@ -0,0 +1,177 @@
// DHCP Library v0.3 - April 25, 2009
// Author: Jordan Terrell - blog.jordanterrell.com
#ifndef Dhcp_h
#define Dhcp_h
#include "EthernetUdp.h"
/* DHCP state machine. */
#define STATE_DHCP_START 0
#define STATE_DHCP_DISCOVER 1
#define STATE_DHCP_REQUEST 2
#define STATE_DHCP_LEASED 3
#define STATE_DHCP_REREQUEST 4
#define STATE_DHCP_RELEASE 5
#define DHCP_FLAGSBROADCAST 0x8000
/* UDP port numbers for DHCP */
#define DHCP_SERVER_PORT 67 /* from server to client */
#define DHCP_CLIENT_PORT 68 /* from client to server */
/* DHCP message OP code */
#define DHCP_BOOTREQUEST 1
#define DHCP_BOOTREPLY 2
/* DHCP message type */
#define DHCP_DISCOVER 1
#define DHCP_OFFER 2
#define DHCP_REQUEST 3
#define DHCP_DECLINE 4
#define DHCP_ACK 5
#define DHCP_NAK 6
#define DHCP_RELEASE 7
#define DHCP_INFORM 8
#define DHCP_HTYPE10MB 1
#define DHCP_HTYPE100MB 2
#define DHCP_HLENETHERNET 6
#define DHCP_HOPS 0
#define DHCP_SECS 0
#define MAGIC_COOKIE 0x63825363
#define MAX_DHCP_OPT 16
#define HOST_NAME "WIZnet"
#define DEFAULT_LEASE (900) //default lease time in seconds
#define DHCP_CHECK_NONE (0)
#define DHCP_CHECK_RENEW_FAIL (1)
#define DHCP_CHECK_RENEW_OK (2)
#define DHCP_CHECK_REBIND_FAIL (3)
#define DHCP_CHECK_REBIND_OK (4)
enum
{
padOption = 0,
subnetMask = 1,
timerOffset = 2,
routersOnSubnet = 3,
/* timeServer = 4,
nameServer = 5,*/
dns = 6,
/*logServer = 7,
cookieServer = 8,
lprServer = 9,
impressServer = 10,
resourceLocationServer = 11,*/
hostName = 12,
/*bootFileSize = 13,
meritDumpFile = 14,*/
domainName = 15,
/*swapServer = 16,
rootPath = 17,
extentionsPath = 18,
IPforwarding = 19,
nonLocalSourceRouting = 20,
policyFilter = 21,
maxDgramReasmSize = 22,
defaultIPTTL = 23,
pathMTUagingTimeout = 24,
pathMTUplateauTable = 25,
ifMTU = 26,
allSubnetsLocal = 27,
broadcastAddr = 28,
performMaskDiscovery = 29,
maskSupplier = 30,
performRouterDiscovery = 31,
routerSolicitationAddr = 32,
staticRoute = 33,
trailerEncapsulation = 34,
arpCacheTimeout = 35,
ethernetEncapsulation = 36,
tcpDefaultTTL = 37,
tcpKeepaliveInterval = 38,
tcpKeepaliveGarbage = 39,
nisDomainName = 40,
nisServers = 41,
ntpServers = 42,
vendorSpecificInfo = 43,
netBIOSnameServer = 44,
netBIOSdgramDistServer = 45,
netBIOSnodeType = 46,
netBIOSscope = 47,
xFontServer = 48,
xDisplayManager = 49,*/
dhcpRequestedIPaddr = 50,
dhcpIPaddrLeaseTime = 51,
/*dhcpOptionOverload = 52,*/
dhcpMessageType = 53,
dhcpServerIdentifier = 54,
dhcpParamRequest = 55,
/*dhcpMsg = 56,
dhcpMaxMsgSize = 57,*/
dhcpT1value = 58,
dhcpT2value = 59,
/*dhcpClassIdentifier = 60,*/
dhcpClientIdentifier = 61,
endOption = 255
};
typedef struct __attribute__((packed)) _RIP_MSG_FIXED
{
uint8_t op;
uint8_t htype;
uint8_t hlen;
uint8_t hops;
uint32_t xid;
uint16_t secs;
uint16_t flags;
uint8_t ciaddr[4];
uint8_t yiaddr[4];
uint8_t siaddr[4];
uint8_t giaddr[4];
uint8_t chaddr[6];
}RIP_MSG_FIXED;
class DhcpClass {
private:
uint32_t _dhcpInitialTransactionId;
uint32_t _dhcpTransactionId;
uint8_t _dhcpMacAddr[6];
uint8_t _dhcpLocalIp[4];
uint8_t _dhcpSubnetMask[4];
uint8_t _dhcpGatewayIp[4];
uint8_t _dhcpDhcpServerIp[4];
uint8_t _dhcpDnsServerIp[4];
uint32_t _dhcpLeaseTime;
uint32_t _dhcpT1, _dhcpT2;
unsigned long _renewInSec;
unsigned long _rebindInSec;
unsigned long _timeout;
unsigned long _responseTimeout;
unsigned long _lastCheckLeaseMillis;
uint8_t _dhcp_state;
EthernetUDP _dhcpUdpSocket;
int request_DHCP_lease();
void reset_DHCP_lease();
void presend_DHCP();
void send_DHCP_MESSAGE(uint8_t, uint16_t);
void printByte(char *, uint8_t);
uint8_t parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId);
public:
IPAddress getLocalIp();
IPAddress getSubnetMask();
IPAddress getGatewayIp();
IPAddress getDhcpServerIp();
IPAddress getDnsServerIp();
int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
int checkLease();
};
#endif

406
Ethernet/Dns.cpp Normal file
View File

@ -0,0 +1,406 @@
// Arduino DNS client for WizNet5100-based Ethernet shield
// (c) Copyright 2009-2010 MCQN Ltd.
// Released under Apache License, version 2.0
#include "utility/w5100.h"
#include "EthernetUdp.h"
#include "utility/util.h"
#include "Dns.h"
#include <string.h>
//#include <stdlib.h>
#include "Arduino.h"
#define SOCKET_NONE 255
// Various flags and header field values for a DNS message
#define UDP_HEADER_SIZE 8
#define DNS_HEADER_SIZE 12
#define TTL_SIZE 4
#define QUERY_FLAG (0)
#define RESPONSE_FLAG (1<<15)
#define QUERY_RESPONSE_MASK (1<<15)
#define OPCODE_STANDARD_QUERY (0)
#define OPCODE_INVERSE_QUERY (1<<11)
#define OPCODE_STATUS_REQUEST (2<<11)
#define OPCODE_MASK (15<<11)
#define AUTHORITATIVE_FLAG (1<<10)
#define TRUNCATION_FLAG (1<<9)
#define RECURSION_DESIRED_FLAG (1<<8)
#define RECURSION_AVAILABLE_FLAG (1<<7)
#define RESP_NO_ERROR (0)
#define RESP_FORMAT_ERROR (1)
#define RESP_SERVER_FAILURE (2)
#define RESP_NAME_ERROR (3)
#define RESP_NOT_IMPLEMENTED (4)
#define RESP_REFUSED (5)
#define RESP_MASK (15)
#define TYPE_A (0x0001)
#define CLASS_IN (0x0001)
#define LABEL_COMPRESSION_MASK (0xC0)
// Port number that DNS servers listen on
#define DNS_PORT 53
// Possible return codes from ProcessResponse
#define SUCCESS 1
#define TIMED_OUT -1
#define INVALID_SERVER -2
#define TRUNCATED -3
#define INVALID_RESPONSE -4
void DNSClient::begin(const IPAddress& aDNSServer)
{
iDNSServer = aDNSServer;
iRequestId = 0;
}
int DNSClient::inet_aton(const char* address, IPAddress& result)
{
// TODO: add support for "a", "a.b", "a.b.c" formats
uint16_t acc = 0; // Accumulator
uint8_t dots = 0;
while (*address)
{
char c = *address++;
if (c >= '0' && c <= '9')
{
acc = acc * 10 + (c - '0');
if (acc > 255) {
// Value out of [0..255] range
return 0;
}
}
else if (c == '.')
{
if (dots == 3) {
// Too much dots (there must be 3 dots)
return 0;
}
result[dots++] = acc;
acc = 0;
}
else
{
// Invalid char
return 0;
}
}
if (dots != 3) {
// Too few dots (there must be 3 dots)
return 0;
}
result[3] = acc;
return 1;
}
int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult)
{
int ret =0;
// See if it's a numeric IP address
if (inet_aton(aHostname, aResult))
{
// It is, our work here is done
return 1;
}
// Check we've got a valid DNS server to use
if (iDNSServer == INADDR_NONE)
{
return INVALID_SERVER;
}
// Find a socket to use
if (iUdp.begin(1024+(millis() & 0xF)) == 1)
{
// Try up to three times
int retries = 0;
// while ((retries < 3) && (ret <= 0))
{
// Send DNS request
ret = iUdp.beginPacket(iDNSServer, DNS_PORT);
if (ret != 0)
{
// Now output the request data
ret = BuildRequest(aHostname);
if (ret != 0)
{
// And finally send the request
ret = iUdp.endPacket();
if (ret != 0)
{
// Now wait for a response
int wait_retries = 0;
ret = TIMED_OUT;
while ((wait_retries < 3) && (ret == TIMED_OUT))
{
ret = ProcessResponse(5000, aResult);
wait_retries++;
}
}
}
}
retries++;
}
// We're done with the socket now
iUdp.stop();
}
return ret;
}
uint16_t DNSClient::BuildRequest(const char* aName)
{
// Build header
// 1 1 1 1 1 1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ID |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QDCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ANCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | NSCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | ARCOUNT |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// As we only support one request at a time at present, we can simplify
// some of this header
iRequestId = millis(); // generate a random ID
uint16_t twoByteBuffer;
// FIXME We should also check that there's enough space available to write to, rather
// FIXME than assume there's enough space (as the code does at present)
uint16_t _id = htons(iRequestId);
iUdp.write((uint8_t*)&_id, sizeof(_id));
twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
twoByteBuffer = htons(1); // One question record
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
twoByteBuffer = 0; // Zero answer records
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
// and zero additional records
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
// Build question
const char* start =aName;
const char* end =start;
uint8_t len;
// Run through the name being requested
while (*end)
{
// Find out how long this section of the name is
end = start;
while (*end && (*end != '.') )
{
end++;
}
if (end-start > 0)
{
// Write out the size of this section
len = end-start;
iUdp.write(&len, sizeof(len));
// And then write out the section
iUdp.write((uint8_t*)start, end-start);
}
start = end+1;
}
// We've got to the end of the question name, so
// terminate it with a zero-length section
len = 0;
iUdp.write(&len, sizeof(len));
// Finally the type and class of question
twoByteBuffer = htons(TYPE_A);
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
twoByteBuffer = htons(CLASS_IN); // Internet class of question
iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
// Success! Everything buffered okay
return 1;
}
uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
{
uint32_t startTime = millis();
// Wait for a response packet
while(iUdp.parsePacket() <= 0)
{
if((millis() - startTime) > aTimeout)
return TIMED_OUT;
delay(50);
}
// We've had a reply!
// Read the UDP header
uint8_t header[DNS_HEADER_SIZE]; // Enough space to reuse for the DNS header
// Check that it's a response from the right server and the right port
if ( (iDNSServer != iUdp.remoteIP()) ||
(iUdp.remotePort() != DNS_PORT) )
{
// It's not from who we expected
return INVALID_SERVER;
}
// Read through the rest of the response
if (iUdp.available() < DNS_HEADER_SIZE)
{
return TRUNCATED;
}
iUdp.read(header, DNS_HEADER_SIZE);
uint16_t header_flags = word(header[2], header[3]);
// Check that it's a response to this request
if ( (iRequestId != word(header[0], header[1])) ||
((header_flags & QUERY_RESPONSE_MASK) != (uint16_t)RESPONSE_FLAG) )
{
// Mark the entire packet as read
iUdp.flush();
return INVALID_RESPONSE;
}
// Check for any errors in the response (or in our request)
// although we don't do anything to get round these
if ( (header_flags & TRUNCATION_FLAG) || (header_flags & RESP_MASK) )
{
// Mark the entire packet as read
iUdp.flush();
return -5; //INVALID_RESPONSE;
}
// And make sure we've got (at least) one answer
uint16_t answerCount = word(header[6], header[7]);
if (answerCount == 0 )
{
// Mark the entire packet as read
iUdp.flush();
return -6; //INVALID_RESPONSE;
}
// Skip over any questions
for (uint16_t i =0; i < word(header[4], header[5]); i++)
{
// Skip over the name
uint8_t len;
do
{
iUdp.read(&len, sizeof(len));
if (len > 0)
{
// Don't need to actually read the data out for the string, just
// advance ptr to beyond it
while(len--)
{
iUdp.read(); // we don't care about the returned byte
}
}
} while (len != 0);
// Now jump over the type and class
for (int i =0; i < 4; i++)
{
iUdp.read(); // we don't care about the returned byte
}
}
// Now we're up to the bit we're interested in, the answer
// There might be more than one answer (although we'll just use the first
// type A answer) and some authority and additional resource records but
// we're going to ignore all of them.
for (uint16_t i =0; i < answerCount; i++)
{
// Skip the name
uint8_t len;
do
{
iUdp.read(&len, sizeof(len));
if ((len & LABEL_COMPRESSION_MASK) == 0)
{
// It's just a normal label
if (len > 0)
{
// And it's got a length
// Don't need to actually read the data out for the string,
// just advance ptr to beyond it
while(len--)
{
iUdp.read(); // we don't care about the returned byte
}
}
}
else
{
// This is a pointer to a somewhere else in the message for the
// rest of the name. We don't care about the name, and RFC1035
// says that a name is either a sequence of labels ended with a
// 0 length octet or a pointer or a sequence of labels ending in
// a pointer. Either way, when we get here we're at the end of
// the name
// Skip over the pointer
iUdp.read(); // we don't care about the returned byte
// And set len so that we drop out of the name loop
len = 0;
}
} while (len != 0);
// Check the type and class
uint16_t answerType;
uint16_t answerClass;
iUdp.read((uint8_t*)&answerType, sizeof(answerType));
iUdp.read((uint8_t*)&answerClass, sizeof(answerClass));
// Ignore the Time-To-Live as we don't do any caching
for (int i =0; i < TTL_SIZE; i++)
{
iUdp.read(); // we don't care about the returned byte
}
// And read out the length of this answer
// Don't need header_flags anymore, so we can reuse it here
iUdp.read((uint8_t*)&header_flags, sizeof(header_flags));
if ( (htons(answerType) == TYPE_A) && (htons(answerClass) == CLASS_IN) )
{
if (htons(header_flags) != 4)
{
// It's a weird size
// Mark the entire packet as read
iUdp.flush();
return -9;//INVALID_RESPONSE;
}
iUdp.read(aAddress.raw_address(), 4);
return SUCCESS;
}
else
{
// This isn't an answer type we're after, move onto the next one
for (uint16_t i =0; i < htons(header_flags); i++)
{
iUdp.read(); // we don't care about the returned byte
}
}
}
// Mark the entire packet as read
iUdp.flush();
// If we get here then we haven't found an answer
return -10;//INVALID_RESPONSE;
}

41
Ethernet/Dns.h Normal file
View File

@ -0,0 +1,41 @@
// Arduino DNS client for WizNet5100-based Ethernet shield
// (c) Copyright 2009-2010 MCQN Ltd.
// Released under Apache License, version 2.0
#ifndef DNSClient_h
#define DNSClient_h
#include <EthernetUdp.h>
class DNSClient
{
public:
// ctor
void begin(const IPAddress& aDNSServer);
/** Convert a numeric IP address string into a four-byte IP address.
@param aIPAddrString IP address to convert
@param aResult IPAddress structure to store the returned IP address
@result 1 if aIPAddrString was successfully converted to an IP address,
else error code
*/
int inet_aton(const char *aIPAddrString, IPAddress& aResult);
/** Resolve the given hostname to an IP address.
@param aHostname Name to be resolved
@param aResult IPAddress structure to store the returned IP address
@result 1 if aIPAddrString was successfully converted to an IP address,
else error code
*/
int getHostByName(const char* aHostname, IPAddress& aResult);
protected:
uint16_t BuildRequest(const char* aName);
uint16_t ProcessResponse(uint16_t aTimeout, IPAddress& aAddress);
IPAddress iDNSServer;
uint16_t iRequestId;
EthernetUDP iUdp;
};
#endif

136
Ethernet/Ethernet.cpp Normal file
View File

@ -0,0 +1,136 @@
#include "utility/w5100.h"
#include "Ethernet.h"
#include "Dhcp.h"
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
uint8_t EthernetClass::_state[MAX_SOCK_NUM] = {
0, 0, 0, 0 };
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
0, 0, 0, 0 };
int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout)
{
static DhcpClass s_dhcp;
_dhcp = &s_dhcp;
// Initialise the basic info
W5100.init();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac_address);
W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
SPI.endTransaction();
// Now try to get our config info from a DHCP server
int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout);
if(ret == 1)
{
// We've successfully found a DHCP server and got our configuration info, so set things
// accordingly
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
SPI.endTransaction();
_dnsServerAddress = _dhcp->getDnsServerIp();
}
return ret;
}
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
{
// Assume the DNS server will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress dns_server = local_ip;
dns_server[3] = 1;
begin(mac_address, local_ip, dns_server);
}
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
{
// Assume the gateway will be the machine on the same network as the local IP
// but with last octet being '1'
IPAddress gateway = local_ip;
gateway[3] = 1;
begin(mac_address, local_ip, dns_server, gateway);
}
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
{
IPAddress subnet(255, 255, 255, 0);
begin(mac_address, local_ip, dns_server, gateway, subnet);
}
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{
W5100.init();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setMACAddress(mac);
W5100.setIPAddress(local_ip.raw_address());
W5100.setGatewayIp(gateway.raw_address());
W5100.setSubnetMask(subnet.raw_address());
SPI.endTransaction();
_dnsServerAddress = dns_server;
}
int EthernetClass::maintain(){
int rc = DHCP_CHECK_NONE;
if(_dhcp != NULL){
//we have a pointer to dhcp, use it
rc = _dhcp->checkLease();
switch ( rc ){
case DHCP_CHECK_NONE:
//nothing done
break;
case DHCP_CHECK_RENEW_OK:
case DHCP_CHECK_REBIND_OK:
//we might have got a new IP.
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
SPI.endTransaction();
_dnsServerAddress = _dhcp->getDnsServerIp();
break;
default:
//this is actually a error, it will retry though
break;
}
}
return rc;
}
IPAddress EthernetClass::localIP()
{
IPAddress ret;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getIPAddress(ret.raw_address());
SPI.endTransaction();
return ret;
}
IPAddress EthernetClass::subnetMask()
{
IPAddress ret;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getSubnetMask(ret.raw_address());
SPI.endTransaction();
return ret;
}
IPAddress EthernetClass::gatewayIP()
{
IPAddress ret;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.getGatewayIp(ret.raw_address());
SPI.endTransaction();
return ret;
}
IPAddress EthernetClass::dnsServerIP()
{
return _dnsServerAddress;
}
EthernetClass Ethernet;

41
Ethernet/Ethernet.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef ethernet_h
#define ethernet_h
#include <inttypes.h>
//#include "w5100.h"
#include "IPAddress.h"
#include "EthernetClient.h"
#include "EthernetServer.h"
#include "Dhcp.h"
#define MAX_SOCK_NUM 4
class EthernetClass {
private:
IPAddress _dnsServerAddress;
DhcpClass* _dhcp;
public:
static uint8_t _state[MAX_SOCK_NUM];
static uint16_t _server_port[MAX_SOCK_NUM];
// Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
// configuration through DHCP.
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
int begin(uint8_t *mac_address, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
void begin(uint8_t *mac_address, IPAddress local_ip);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
int maintain();
IPAddress localIP();
IPAddress subnetMask();
IPAddress gatewayIP();
IPAddress dnsServerIP();
friend class EthernetClient;
friend class EthernetServer;
};
extern EthernetClass Ethernet;
#endif

177
Ethernet/EthernetClient.cpp Normal file
View File

@ -0,0 +1,177 @@
#include "utility/w5100.h"
#include "utility/socket.h"
extern "C" {
#include "string.h"
}
#include "Arduino.h"
#include "Ethernet.h"
#include "EthernetClient.h"
#include "EthernetServer.h"
#include "Dns.h"
uint16_t EthernetClient::_srcport = 49152; //Use IANA recommended ephemeral port range 49152-65535
EthernetClient::EthernetClient() : _sock(MAX_SOCK_NUM) {
}
EthernetClient::EthernetClient(uint8_t sock) : _sock(sock) {
}
int EthernetClient::connect(const char* host, uint16_t port) {
// Look up the host first
int ret = 0;
DNSClient dns;
IPAddress remote_addr;
dns.begin(Ethernet.dnsServerIP());
ret = dns.getHostByName(host, remote_addr);
if (ret == 1) {
return connect(remote_addr, port);
} else {
return ret;
}
}
int EthernetClient::connect(IPAddress ip, uint16_t port) {
if (_sock != MAX_SOCK_NUM)
return 0;
for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = socketStatus(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
_sock = i;
break;
}
}
if (_sock == MAX_SOCK_NUM)
return 0;
_srcport++;
if (_srcport == 0) _srcport = 49152; //Use IANA recommended ephemeral port range 49152-65535
socket(_sock, SnMR::TCP, _srcport, 0);
if (!::connect(_sock, rawIPAddress(ip), port)) {
_sock = MAX_SOCK_NUM;
return 0;
}
while (status() != SnSR::ESTABLISHED) {
delay(1);
if (status() == SnSR::CLOSED) {
_sock = MAX_SOCK_NUM;
return 0;
}
}
return 1;
}
size_t EthernetClient::write(uint8_t b) {
return write(&b, 1);
}
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
if (_sock == MAX_SOCK_NUM) {
setWriteError();
return 0;
}
if (!send(_sock, buf, size)) {
setWriteError();
return 0;
}
return size;
}
int EthernetClient::available() {
if (_sock != MAX_SOCK_NUM)
return recvAvailable(_sock);
return 0;
}
int EthernetClient::read() {
uint8_t b;
if ( recv(_sock, &b, 1) > 0 )
{
// recv worked
return b;
}
else
{
// No data available
return -1;
}
}
int EthernetClient::read(uint8_t *buf, size_t size) {
return recv(_sock, buf, size);
}
int EthernetClient::peek() {
uint8_t b;
// Unlike recv, peek doesn't check to see if there's any data available, so we must
if (!available())
return -1;
::peek(_sock, &b);
return b;
}
void EthernetClient::flush() {
::flush(_sock);
}
void EthernetClient::stop() {
if (_sock == MAX_SOCK_NUM)
return;
// attempt to close the connection gracefully (send a FIN to other side)
disconnect(_sock);
unsigned long start = millis();
// wait up to a second for the connection to close
uint8_t s;
do {
s = status();
if (s == SnSR::CLOSED)
break; // exit the loop
delay(1);
} while (millis() - start < 1000);
// if it hasn't closed, close it forcefully
if (s != SnSR::CLOSED)
close(_sock);
EthernetClass::_server_port[_sock] = 0;
_sock = MAX_SOCK_NUM;
}
uint8_t EthernetClient::connected() {
if (_sock == MAX_SOCK_NUM) return 0;
uint8_t s = status();
return !(s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::FIN_WAIT ||
(s == SnSR::CLOSE_WAIT && !available()));
}
uint8_t EthernetClient::status() {
if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
return socketStatus(_sock);
}
// the next function allows us to use the client returned by
// EthernetServer::available() as the condition in an if-statement.
EthernetClient::operator bool() {
return _sock != MAX_SOCK_NUM;
}
bool EthernetClient::operator==(const EthernetClient& rhs) {
return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM;
}
uint8_t EthernetClient::getSocketNumber() {
return _sock;
}

42
Ethernet/EthernetClient.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef ethernetclient_h
#define ethernetclient_h
#include "Arduino.h"
#include "Print.h"
#include "Client.h"
#include "IPAddress.h"
class EthernetClient : public Client {
public:
EthernetClient();
EthernetClient(uint8_t sock);
uint8_t status();
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
virtual int available();
virtual int read();
virtual int read(uint8_t *buf, size_t size);
virtual int peek();
virtual void flush();
virtual void stop();
virtual uint8_t connected();
virtual operator bool();
virtual bool operator==(const bool value) { return bool() == value; }
virtual bool operator!=(const bool value) { return bool() != value; }
virtual bool operator==(const EthernetClient&);
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
uint8_t getSocketNumber();
friend class EthernetServer;
using Print::write;
private:
static uint16_t _srcport;
uint8_t _sock;
};
#endif

View File

@ -0,0 +1,92 @@
#include "utility/w5100.h"
#include "utility/socket.h"
extern "C" {
#include "string.h"
}
#include "Ethernet.h"
#include "EthernetClient.h"
#include "EthernetServer.h"
EthernetServer::EthernetServer(uint16_t port)
{
_port = port;
}
void EthernetServer::begin()
{
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
EthernetClient client(sock);
if (client.status() == SnSR::CLOSED) {
socket(sock, SnMR::TCP, _port, 0);
listen(sock);
EthernetClass::_server_port[sock] = _port;
break;
}
}
}
void EthernetServer::accept()
{
int listening = 0;
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
EthernetClient client(sock);
if (EthernetClass::_server_port[sock] == _port) {
if (client.status() == SnSR::LISTEN) {
listening = 1;
}
else if (client.status() == SnSR::CLOSE_WAIT && !client.available()) {
client.stop();
}
}
}
if (!listening) {
begin();
}
}
EthernetClient EthernetServer::available()
{
accept();
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
EthernetClient client(sock);
if (EthernetClass::_server_port[sock] == _port) {
uint8_t s = client.status();
if (s == SnSR::ESTABLISHED || s == SnSR::CLOSE_WAIT) {
if (client.available()) {
// XXX: don't always pick the lowest numbered socket.
return client;
}
}
}
}
return EthernetClient(MAX_SOCK_NUM);
}
size_t EthernetServer::write(uint8_t b)
{
return write(&b, 1);
}
size_t EthernetServer::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
accept();
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
EthernetClient client(sock);
if (EthernetClass::_server_port[sock] == _port &&
client.status() == SnSR::ESTABLISHED) {
n += client.write(buffer, size);
}
}
return n;
}

22
Ethernet/EthernetServer.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef ethernetserver_h
#define ethernetserver_h
#include "Server.h"
class EthernetClient;
class EthernetServer :
public Server {
private:
uint16_t _port;
void accept();
public:
EthernetServer(uint16_t);
EthernetClient available();
virtual void begin();
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
using Print::write;
};
#endif

250
Ethernet/EthernetUdp.cpp Normal file
View File

@ -0,0 +1,250 @@
/*
* Udp.cpp: Library to send/receive UDP packets with the Arduino ethernet shield.
* This version only offers minimal wrapping of socket.c/socket.h
* Drop Udp.h/.cpp into the Ethernet library directory at hardware/libraries/Ethernet/
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
#include "utility/w5100.h"
#include "utility/socket.h"
#include "Ethernet.h"
#include "Udp.h"
#include "Dns.h"
/* Constructor */
EthernetUDP::EthernetUDP() : _sock(MAX_SOCK_NUM) {}
/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::begin(uint16_t port) {
if (_sock != MAX_SOCK_NUM)
return 0;
for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = socketStatus(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
}
}
if (_sock == MAX_SOCK_NUM)
return 0;
_port = port;
_remaining = 0;
socket(_sock, SnMR::UDP, _port, 0);
return 1;
}
/* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */
int EthernetUDP::available() {
return _remaining;
}
/* Release any resources being used by this EthernetUDP instance */
void EthernetUDP::stop()
{
if (_sock == MAX_SOCK_NUM)
return;
close(_sock);
EthernetClass::_server_port[_sock] = 0;
_sock = MAX_SOCK_NUM;
}
int EthernetUDP::beginPacket(const char *host, uint16_t port)
{
// Look up the host first
int ret = 0;
DNSClient dns;
IPAddress remote_addr;
dns.begin(Ethernet.dnsServerIP());
ret = dns.getHostByName(host, remote_addr);
if (ret == 1) {
return beginPacket(remote_addr, port);
} else {
return ret;
}
}
int EthernetUDP::beginPacket(IPAddress ip, uint16_t port)
{
_offset = 0;
return startUDP(_sock, rawIPAddress(ip), port);
}
int EthernetUDP::endPacket()
{
return sendUDP(_sock);
}
size_t EthernetUDP::write(uint8_t byte)
{
return write(&byte, 1);
}
size_t EthernetUDP::write(const uint8_t *buffer, size_t size)
{
uint16_t bytes_written = bufferData(_sock, _offset, buffer, size);
_offset += bytes_written;
return bytes_written;
}
int EthernetUDP::parsePacket()
{
// discard any remaining bytes in the last packet
while (_remaining) {
// could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
// should only occur if recv fails after telling us the data is there, lets
// hope the w5100 always behaves :)
read();
}
if (recvAvailable(_sock) > 0)
{
//HACK - hand-parse the UDP packet using TCP recv method
uint8_t tmpBuf[8];
int ret =0;
//read 8 header bytes and get IP and port from it
ret = recv(_sock,tmpBuf,8);
if (ret > 0)
{
_remoteIP = tmpBuf;
_remotePort = tmpBuf[4];
_remotePort = (_remotePort << 8) + tmpBuf[5];
_remaining = tmpBuf[6];
_remaining = (_remaining << 8) + tmpBuf[7];
// When we get here, any remaining bytes are the data
ret = _remaining;
}
return ret;
}
// There aren't any packets available
return 0;
}
int EthernetUDP::read()
{
uint8_t byte;
if ((_remaining > 0) && (recv(_sock, &byte, 1) > 0))
{
// We read things without any problems
_remaining--;
return byte;
}
// If we get here, there's no data available
return -1;
}
int EthernetUDP::read(unsigned char* buffer, size_t len)
{
if (_remaining > 0)
{
int got;
if (_remaining <= len)
{
// data should fit in the buffer
got = recv(_sock, buffer, _remaining);
}
else
{
// too much data for the buffer,
// grab as much as will fit
got = recv(_sock, buffer, len);
}
if (got > 0)
{
_remaining -= got;
return got;
}
}
// If we get here, there's no data available or recv failed
return -1;
}
int EthernetUDP::peek()
{
uint8_t b;
// Unlike recv, peek doesn't check to see if there's any data available, so we must.
// If the user hasn't called parsePacket yet then return nothing otherwise they
// may get the UDP header
if (!_remaining)
return -1;
::peek(_sock, &b);
return b;
}
void EthernetUDP::flush()
{
// TODO: we should wait for TX buffer to be emptied
}
/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::beginMulticast(IPAddress ip, uint16_t port)
{
if (_sock != MAX_SOCK_NUM)
return 0;
for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.readSnSR(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
}
}
if (_sock == MAX_SOCK_NUM)
return 0;
// Calculate MAC address from Multicast IP Address
byte mac[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 };
mac[3] = ip[1] & 0x7F;
mac[4] = ip[2];
mac[5] = ip[3];
W5100.writeSnDIPR(_sock, rawIPAddress(ip)); //239.255.0.1
W5100.writeSnDPORT(_sock, port);
W5100.writeSnDHAR(_sock,mac);
_remaining = 0;
socket(_sock, SnMR::UDP, port, SnMR::MULTI);
return 1;
}

102
Ethernet/EthernetUdp.h Normal file
View File

@ -0,0 +1,102 @@
/*
* Udp.cpp: Library to send/receive UDP packets with the Arduino ethernet shield.
* This version only offers minimal wrapping of socket.c/socket.h
* Drop Udp.h/.cpp into the Ethernet library directory at hardware/libraries/Ethernet/
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef ethernetudp_h
#define ethernetudp_h
#include <Udp.h>
#define UDP_TX_PACKET_MAX_SIZE 24
class EthernetUDP : public UDP {
private:
uint16_t _port; // local port to listen on
IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed
uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed
uint16_t _offset; // offset into the packet being sent
protected:
uint8_t _sock; // socket ID for Wiz5100
uint16_t _remaining; // remaining bytes of incoming packet yet to be processed
public:
EthernetUDP(); // Constructor
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual void stop(); // Finish with the UDP socket
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port);
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port);
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket();
// Write a single byte into the packet
virtual size_t write(uint8_t);
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size);
using Print::write;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket();
// Number of bytes remaining in the current packet
virtual int available();
// Read a single byte from the current packet
virtual int read();
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len);
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
// Return the next byte from the current packet without moving on to the next byte
virtual int peek();
virtual void flush(); // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() { return _remoteIP; };
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() { return _remotePort; };
};
#endif

469
Ethernet/utility/socket.cpp Normal file
View File

@ -0,0 +1,469 @@
#include "w5100.h"
#include "socket.h"
static uint16_t local_port;
/**
* @brief This Socket function initialize the channel in perticular mode, and set the port and wait for W5100 done it.
* @return 1 for success else 0.
*/
uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
{
if ((protocol == SnMR::TCP) || (protocol == SnMR::UDP) || (protocol == SnMR::IPRAW) || (protocol == SnMR::MACRAW) || (protocol == SnMR::PPPOE))
{
close(s);
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.writeSnMR(s, protocol | flag);
if (port != 0) {
W5100.writeSnPORT(s, port);
}
else {
local_port++; // if don't set the source port, set local_port number.
W5100.writeSnPORT(s, local_port);
}
W5100.execCmdSn(s, Sock_OPEN);
SPI.endTransaction();
return 1;
}
return 0;
}
uint8_t socketStatus(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
uint8_t status = W5100.readSnSR(s);
SPI.endTransaction();
return status;
}
/**
* @brief This function close the socket and parameter is "s" which represent the socket number
*/
void close(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.execCmdSn(s, Sock_CLOSE);
W5100.writeSnIR(s, 0xFF);
SPI.endTransaction();
}
/**
* @brief This function established the connection for the channel in passive (server) mode. This function waits for the request from the peer.
* @return 1 for success else 0.
*/
uint8_t listen(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
if (W5100.readSnSR(s) != SnSR::INIT) {
SPI.endTransaction();
return 0;
}
W5100.execCmdSn(s, Sock_LISTEN);
SPI.endTransaction();
return 1;
}
/**
* @brief This function established the connection for the channel in Active (client) mode.
* This function waits for the untill the connection is established.
*
* @return 1 for success else 0.
*/
uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port)
{
if
(
((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
(port == 0x00)
)
return 0;
// set destination IP
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.writeSnDIPR(s, addr);
W5100.writeSnDPORT(s, port);
W5100.execCmdSn(s, Sock_CONNECT);
SPI.endTransaction();
return 1;
}
/**
* @brief This function used for disconnect the socket and parameter is "s" which represent the socket number
* @return 1 for success else 0.
*/
void disconnect(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.execCmdSn(s, Sock_DISCON);
SPI.endTransaction();
}
/**
* @brief This function used to send the data in TCP mode
* @return 1 for success else 0.
*/
uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
{
uint8_t status=0;
uint16_t ret=0;
uint16_t freesize=0;
if (len > W5100.SSIZE)
ret = W5100.SSIZE; // check size not to exceed MAX size.
else
ret = len;
// if freebuf is available, start.
do
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
freesize = W5100.getTXFreeSize(s);
status = W5100.readSnSR(s);
SPI.endTransaction();
if ((status != SnSR::ESTABLISHED) && (status != SnSR::CLOSE_WAIT))
{
ret = 0;
break;
}
yield();
}
while (freesize < ret);
// copy data
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.send_data_processing(s, (uint8_t *)buf, ret);
W5100.execCmdSn(s, Sock_SEND);
/* +2008.01 bj */
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
{
/* m2008.01 [bj] : reduce code */
if ( W5100.readSnSR(s) == SnSR::CLOSED )
{
SPI.endTransaction();
close(s);
return 0;
}
SPI.endTransaction();
yield();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);
SPI.endTransaction();
return ret;
}
/**
* @brief This function is an application I/F function which is used to receive the data in TCP mode.
* It continues to wait for data as much as the application wants to receive.
*
* @return received data size for success else -1.
*/
int16_t recv(SOCKET s, uint8_t *buf, int16_t len)
{
// Check how much data is available
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
int16_t ret = W5100.getRXReceivedSize(s);
if ( ret == 0 )
{
// No data available.
uint8_t status = W5100.readSnSR(s);
if ( status == SnSR::LISTEN || status == SnSR::CLOSED || status == SnSR::CLOSE_WAIT )
{
// The remote end has closed its side of the connection, so this is the eof state
ret = 0;
}
else
{
// The connection is still up, but there's no data waiting to be read
ret = -1;
}
}
else if (ret > len)
{
ret = len;
}
if ( ret > 0 )
{
W5100.recv_data_processing(s, buf, ret);
W5100.execCmdSn(s, Sock_RECV);
}
SPI.endTransaction();
return ret;
}
int16_t recvAvailable(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
int16_t ret = W5100.getRXReceivedSize(s);
SPI.endTransaction();
return ret;
}
/**
* @brief Returns the first byte in the receive queue (no checking)
*
* @return
*/
uint16_t peek(SOCKET s, uint8_t *buf)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.recv_data_processing(s, buf, 1, 1);
SPI.endTransaction();
return 1;
}
/**
* @brief This function is an application I/F function which is used to send the data for other then TCP mode.
* Unlike TCP transmission, The peer's destination address and the port is needed.
*
* @return This function return send data size for success else -1.
*/
uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
{
uint16_t ret=0;
if (len > W5100.SSIZE) ret = W5100.SSIZE; // check size not to exceed MAX size.
else ret = len;
if
(
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
((port == 0x00)) ||(ret == 0)
)
{
/* +2008.01 [bj] : added return value */
ret = 0;
}
else
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.writeSnDIPR(s, addr);
W5100.writeSnDPORT(s, port);
// copy data
W5100.send_data_processing(s, (uint8_t *)buf, ret);
W5100.execCmdSn(s, Sock_SEND);
/* +2008.01 bj */
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
{
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
{
/* +2008.01 [bj]: clear interrupt */
W5100.writeSnIR(s, (SnIR::SEND_OK | SnIR::TIMEOUT)); /* clear SEND_OK & TIMEOUT */
SPI.endTransaction();
return 0;
}
SPI.endTransaction();
yield();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);
SPI.endTransaction();
}
return ret;
}
/**
* @brief This function is an application I/F function which is used to receive the data in other then
* TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well.
*
* @return This function return received data size for success else -1.
*/
uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
{
uint8_t head[8];
uint16_t data_len=0;
uint16_t ptr=0;
if ( len > 0 )
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
ptr = W5100.readSnRX_RD(s);
switch (W5100.readSnMR(s) & 0x07)
{
case SnMR::UDP :
W5100.read_data(s, ptr, head, 0x08);
ptr += 8;
// read peer's IP address, port number.
addr[0] = head[0];
addr[1] = head[1];
addr[2] = head[2];
addr[3] = head[3];
*port = head[4];
*port = (*port << 8) + head[5];
data_len = head[6];
data_len = (data_len << 8) + head[7];
W5100.read_data(s, ptr, buf, data_len); // data copy.
ptr += data_len;
W5100.writeSnRX_RD(s, ptr);
break;
case SnMR::IPRAW :
W5100.read_data(s, ptr, head, 0x06);
ptr += 6;
addr[0] = head[0];
addr[1] = head[1];
addr[2] = head[2];
addr[3] = head[3];
data_len = head[4];
data_len = (data_len << 8) + head[5];
W5100.read_data(s, ptr, buf, data_len); // data copy.
ptr += data_len;
W5100.writeSnRX_RD(s, ptr);
break;
case SnMR::MACRAW:
W5100.read_data(s, ptr, head, 2);
ptr+=2;
data_len = head[0];
data_len = (data_len<<8) + head[1] - 2;
W5100.read_data(s, ptr, buf, data_len);
ptr += data_len;
W5100.writeSnRX_RD(s, ptr);
break;
default :
break;
}
W5100.execCmdSn(s, Sock_RECV);
SPI.endTransaction();
}
return data_len;
}
/**
* @brief Wait for buffered transmission to complete.
*/
void flush(SOCKET s) {
// TODO
}
uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len)
{
uint16_t ret=0;
if (len > W5100.SSIZE)
ret = W5100.SSIZE; // check size not to exceed MAX size.
else
ret = len;
if (ret == 0)
return 0;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.send_data_processing(s, (uint8_t *)buf, ret);
W5100.execCmdSn(s, Sock_SEND);
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
{
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
{
/* in case of igmp, if send fails, then socket closed */
/* if you want change, remove this code. */
SPI.endTransaction();
close(s);
return 0;
}
SPI.endTransaction();
yield();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
}
W5100.writeSnIR(s, SnIR::SEND_OK);
SPI.endTransaction();
return ret;
}
uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len)
{
uint16_t ret =0;
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
if (len > W5100.getTXFreeSize(s))
{
ret = W5100.getTXFreeSize(s); // check size not to exceed MAX size.
}
else
{
ret = len;
}
W5100.send_data_processing_offset(s, offset, buf, ret);
SPI.endTransaction();
return ret;
}
int startUDP(SOCKET s, uint8_t* addr, uint16_t port)
{
if
(
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
((port == 0x00))
)
{
return 0;
}
else
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.writeSnDIPR(s, addr);
W5100.writeSnDPORT(s, port);
SPI.endTransaction();
return 1;
}
}
int sendUDP(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.execCmdSn(s, Sock_SEND);
/* +2008.01 bj */
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
{
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
{
/* +2008.01 [bj]: clear interrupt */
W5100.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
SPI.endTransaction();
return 0;
}
SPI.endTransaction();
yield();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);
SPI.endTransaction();
/* Sent ok */
return 1;
}

44
Ethernet/utility/socket.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef _SOCKET_H_
#define _SOCKET_H_
#include "utility/w5100.h"
extern uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag); // Opens a socket(TCP or UDP or IP_RAW mode)
extern uint8_t socketStatus(SOCKET s);
extern void close(SOCKET s); // Close socket
extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TCP connection (Active connection)
extern void disconnect(SOCKET s); // disconnect the connection
extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection)
extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP)
extern int16_t recv(SOCKET s, uint8_t * buf, int16_t len); // Receive data (TCP)
extern int16_t recvAvailable(SOCKET s);
extern uint16_t peek(SOCKET s, uint8_t *buf);
extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW)
extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW)
extern void flush(SOCKET s); // Wait for transmission to complete
extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len);
// Functions to allow buffered UDP send (i.e. where the UDP datagram is built up over a
// number of calls before being sent
/*
@brief This function sets up a UDP datagram, the data for which will be provided by one
or more calls to bufferData and then finally sent with sendUDP.
@return 1 if the datagram was successfully set up, or 0 if there was an error
*/
extern int startUDP(SOCKET s, uint8_t* addr, uint16_t port);
/*
@brief This function copies up to len bytes of data from buf into a UDP datagram to be
sent later by sendUDP. Allows datagrams to be built up from a series of bufferData calls.
@return Number of bytes successfully buffered
*/
uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len);
/*
@brief Send a UDP datagram built up from a sequence of startUDP followed by one or more
calls to bufferData.
@return 1 if the datagram was successfully sent, or 0 if there was an error
*/
int sendUDP(SOCKET s);
#endif
/* _SOCKET_H_ */

14
Ethernet/utility/util.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef UTIL_H
#define UTIL_H
#define htons(x) ( ((x)<< 8 & 0xFF00) | \
((x)>> 8 & 0x00FF) )
#define ntohs(x) htons(x)
#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
((x)<< 8 & 0x00FF0000UL) | \
((x)>> 8 & 0x0000FF00UL) | \
((x)>>24 & 0x000000FFUL) )
#define ntohl(x) htonl(x)
#endif

225
Ethernet/utility/w5100.cpp Normal file
View File

@ -0,0 +1,225 @@
/*
* Copyright (c) 2010 by Arduino LLC. All rights reserved.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#include <stdio.h>
#include <string.h>
#include "w5100.h"
// W5100 controller instance
W5100Class W5100;
#define TX_RX_MAX_BUF_SIZE 2048
#define TX_BUF 0x1100
#define RX_BUF (TX_BUF + TX_RX_MAX_BUF_SIZE)
#define TXBUF_BASE 0x4000
#define RXBUF_BASE 0x6000
void W5100Class::init(void)
{
delay(300);
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
SPI.begin();
initSS();
#else
SPI.begin(ETHERNET_SHIELD_SPI_CS);
// Set clock to 4Mhz (W5100 should support up to about 14Mhz)
SPI.setClockDivider(ETHERNET_SHIELD_SPI_CS, 21);
SPI.setDataMode(ETHERNET_SHIELD_SPI_CS, SPI_MODE0);
#endif
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
writeMR(1<<RST);
writeTMSR(0x55);
writeRMSR(0x55);
SPI.endTransaction();
for (int i=0; i<MAX_SOCK_NUM; i++) {
SBASE[i] = TXBUF_BASE + SSIZE * i;
RBASE[i] = RXBUF_BASE + RSIZE * i;
}
}
uint16_t W5100Class::getTXFreeSize(SOCKET s)
{
uint16_t val=0, val1=0;
do {
val1 = readSnTX_FSR(s);
if (val1 != 0)
val = readSnTX_FSR(s);
}
while (val != val1);
return val;
}
uint16_t W5100Class::getRXReceivedSize(SOCKET s)
{
uint16_t val=0,val1=0;
do {
val1 = readSnRX_RSR(s);
if (val1 != 0)
val = readSnRX_RSR(s);
}
while (val != val1);
return val;
}
void W5100Class::send_data_processing(SOCKET s, const uint8_t *data, uint16_t len)
{
// This is same as having no offset in a call to send_data_processing_offset
send_data_processing_offset(s, 0, data, len);
}
void W5100Class::send_data_processing_offset(SOCKET s, uint16_t data_offset, const uint8_t *data, uint16_t len)
{
uint16_t ptr = readSnTX_WR(s);
ptr += data_offset;
uint16_t offset = ptr & SMASK;
uint16_t dstAddr = offset + SBASE[s];
if (offset + len > SSIZE)
{
// Wrap around circular buffer
uint16_t size = SSIZE - offset;
write(dstAddr, data, size);
write(SBASE[s], data + size, len - size);
}
else {
write(dstAddr, data, len);
}
ptr += len;
writeSnTX_WR(s, ptr);
}
void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek)
{
uint16_t ptr;
ptr = readSnRX_RD(s);
read_data(s, ptr, data, len);
if (!peek)
{
ptr += len;
writeSnRX_RD(s, ptr);
}
}
void W5100Class::read_data(SOCKET s, volatile uint16_t src, volatile uint8_t *dst, uint16_t len)
{
uint16_t size;
uint16_t src_mask;
uint16_t src_ptr;
src_mask = src & RMASK;
src_ptr = RBASE[s] + src_mask;
if( (src_mask + len) > RSIZE )
{
size = RSIZE - src_mask;
read(src_ptr, (uint8_t *)dst, size);
dst += size;
read(RBASE[s], (uint8_t *) dst, len - size);
}
else
read(src_ptr, (uint8_t *) dst, len);
}
uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
{
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
setSS();
SPI.transfer(0xF0);
SPI.transfer(_addr >> 8);
SPI.transfer(_addr & 0xFF);
SPI.transfer(_data);
resetSS();
#else
SPI.transfer(ETHERNET_SHIELD_SPI_CS, 0xF0, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr >> 8, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr & 0xFF, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _data);
#endif
return 1;
}
uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
{
for (uint16_t i=0; i<_len; i++)
{
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
setSS();
SPI.transfer(0xF0);
SPI.transfer(_addr >> 8);
SPI.transfer(_addr & 0xFF);
_addr++;
SPI.transfer(_buf[i]);
resetSS();
#else
SPI.transfer(ETHERNET_SHIELD_SPI_CS, 0xF0, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr >> 8, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr & 0xFF, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _buf[i]);
_addr++;
#endif
}
return _len;
}
uint8_t W5100Class::read(uint16_t _addr)
{
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
setSS();
SPI.transfer(0x0F);
SPI.transfer(_addr >> 8);
SPI.transfer(_addr & 0xFF);
uint8_t _data = SPI.transfer(0);
resetSS();
#else
SPI.transfer(ETHERNET_SHIELD_SPI_CS, 0x0F, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr >> 8, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr & 0xFF, SPI_CONTINUE);
uint8_t _data = SPI.transfer(ETHERNET_SHIELD_SPI_CS, 0);
#endif
return _data;
}
uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
{
for (uint16_t i=0; i<_len; i++)
{
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
setSS();
SPI.transfer(0x0F);
SPI.transfer(_addr >> 8);
SPI.transfer(_addr & 0xFF);
_addr++;
_buf[i] = SPI.transfer(0);
resetSS();
#else
SPI.transfer(ETHERNET_SHIELD_SPI_CS, 0x0F, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr >> 8, SPI_CONTINUE);
SPI.transfer(ETHERNET_SHIELD_SPI_CS, _addr & 0xFF, SPI_CONTINUE);
_buf[i] = SPI.transfer(ETHERNET_SHIELD_SPI_CS, 0);
_addr++;
#endif
}
return _len;
}
void W5100Class::execCmdSn(SOCKET s, SockCMD _cmd) {
// Send command to socket
writeSnCR(s, _cmd);
// Wait for command to complete
while (readSnCR(s))
;
}

426
Ethernet/utility/w5100.h Normal file
View File

@ -0,0 +1,426 @@
/*
* Copyright (c) 2010 by Arduino LLC. All rights reserved.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#ifndef W5100_H_INCLUDED
#define W5100_H_INCLUDED
#include <SPI.h>
#define ETHERNET_SHIELD_SPI_CS 10
#define MAX_SOCK_NUM 4
typedef uint8_t SOCKET;
#define IDM_OR 0x8000
#define IDM_AR0 0x8001
#define IDM_AR1 0x8002
#define IDM_DR 0x8003
/*
class MR {
public:
static const uint8_t RST = 0x80;
static const uint8_t PB = 0x10;
static const uint8_t PPPOE = 0x08;
static const uint8_t LB = 0x04;
static const uint8_t AI = 0x02;
static const uint8_t IND = 0x01;
};
*/
/*
class IR {
public:
static const uint8_t CONFLICT = 0x80;
static const uint8_t UNREACH = 0x40;
static const uint8_t PPPoE = 0x20;
static const uint8_t SOCK0 = 0x01;
static const uint8_t SOCK1 = 0x02;
static const uint8_t SOCK2 = 0x04;
static const uint8_t SOCK3 = 0x08;
static inline uint8_t SOCK(SOCKET ch) { return (0x01 << ch); };
};
*/
class SnMR {
public:
static const uint8_t CLOSE = 0x00;
static const uint8_t TCP = 0x01;
static const uint8_t UDP = 0x02;
static const uint8_t IPRAW = 0x03;
static const uint8_t MACRAW = 0x04;
static const uint8_t PPPOE = 0x05;
static const uint8_t ND = 0x20;
static const uint8_t MULTI = 0x80;
};
enum SockCMD {
Sock_OPEN = 0x01,
Sock_LISTEN = 0x02,
Sock_CONNECT = 0x04,
Sock_DISCON = 0x08,
Sock_CLOSE = 0x10,
Sock_SEND = 0x20,
Sock_SEND_MAC = 0x21,
Sock_SEND_KEEP = 0x22,
Sock_RECV = 0x40
};
/*class SnCmd {
public:
static const uint8_t OPEN = 0x01;
static const uint8_t LISTEN = 0x02;
static const uint8_t CONNECT = 0x04;
static const uint8_t DISCON = 0x08;
static const uint8_t CLOSE = 0x10;
static const uint8_t SEND = 0x20;
static const uint8_t SEND_MAC = 0x21;
static const uint8_t SEND_KEEP = 0x22;
static const uint8_t RECV = 0x40;
};
*/
class SnIR {
public:
static const uint8_t SEND_OK = 0x10;
static const uint8_t TIMEOUT = 0x08;
static const uint8_t RECV = 0x04;
static const uint8_t DISCON = 0x02;
static const uint8_t CON = 0x01;
};
class SnSR {
public:
static const uint8_t CLOSED = 0x00;
static const uint8_t INIT = 0x13;
static const uint8_t LISTEN = 0x14;
static const uint8_t SYNSENT = 0x15;
static const uint8_t SYNRECV = 0x16;
static const uint8_t ESTABLISHED = 0x17;
static const uint8_t FIN_WAIT = 0x18;
static const uint8_t CLOSING = 0x1A;
static const uint8_t TIME_WAIT = 0x1B;
static const uint8_t CLOSE_WAIT = 0x1C;
static const uint8_t LAST_ACK = 0x1D;
static const uint8_t UDP = 0x22;
static const uint8_t IPRAW = 0x32;
static const uint8_t MACRAW = 0x42;
static const uint8_t PPPOE = 0x5F;
};
class IPPROTO {
public:
static const uint8_t IP = 0;
static const uint8_t ICMP = 1;
static const uint8_t IGMP = 2;
static const uint8_t GGP = 3;
static const uint8_t TCP = 6;
static const uint8_t PUP = 12;
static const uint8_t UDP = 17;
static const uint8_t IDP = 22;
static const uint8_t ND = 77;
static const uint8_t RAW = 255;
};
class W5100Class {
public:
void init();
/**
* @brief This function is being used for copy the data form Receive buffer of the chip to application buffer.
*
* It calculate the actual physical address where one has to read
* the data from Receive buffer. Here also take care of the condition while it exceed
* the Rx memory uper-bound of socket.
*/
void read_data(SOCKET s, volatile uint16_t src, volatile uint8_t * dst, uint16_t len);
/**
* @brief This function is being called by send() and sendto() function also.
*
* This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer
* register. User should read upper byte first and lower byte later to get proper value.
*/
void send_data_processing(SOCKET s, const uint8_t *data, uint16_t len);
/**
* @brief A copy of send_data_processing that uses the provided ptr for the
* write offset. Only needed for the "streaming" UDP API, where
* a single UDP packet is built up over a number of calls to
* send_data_processing_ptr, because TX_WR doesn't seem to get updated
* correctly in those scenarios
* @param ptr value to use in place of TX_WR. If 0, then the value is read
* in from TX_WR
* @return New value for ptr, to be used in the next call
*/
// FIXME Update documentation
void send_data_processing_offset(SOCKET s, uint16_t data_offset, const uint8_t *data, uint16_t len);
/**
* @brief This function is being called by recv() also.
*
* This function read the Rx read pointer register
* and after copy the data from receive buffer update the Rx write pointer register.
* User should read upper byte first and lower byte later to get proper value.
*/
void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek = 0);
inline void setGatewayIp(uint8_t *_addr);
inline void getGatewayIp(uint8_t *_addr);
inline void setSubnetMask(uint8_t *_addr);
inline void getSubnetMask(uint8_t *_addr);
inline void setMACAddress(uint8_t * addr);
inline void getMACAddress(uint8_t * addr);
inline void setIPAddress(uint8_t * addr);
inline void getIPAddress(uint8_t * addr);
inline void setRetransmissionTime(uint16_t timeout);
inline void setRetransmissionCount(uint8_t _retry);
void execCmdSn(SOCKET s, SockCMD _cmd);
uint16_t getTXFreeSize(SOCKET s);
uint16_t getRXReceivedSize(SOCKET s);
// W5100 Registers
// ---------------
private:
static uint8_t write(uint16_t _addr, uint8_t _data);
static uint16_t write(uint16_t addr, const uint8_t *buf, uint16_t len);
static uint8_t read(uint16_t addr);
static uint16_t read(uint16_t addr, uint8_t *buf, uint16_t len);
#define __GP_REGISTER8(name, address) \
static inline void write##name(uint8_t _data) { \
write(address, _data); \
} \
static inline uint8_t read##name() { \
return read(address); \
}
#define __GP_REGISTER16(name, address) \
static void write##name(uint16_t _data) { \
write(address, _data >> 8); \
write(address+1, _data & 0xFF); \
} \
static uint16_t read##name() { \
uint16_t res = read(address); \
res = (res << 8) + read(address + 1); \
return res; \
}
#define __GP_REGISTER_N(name, address, size) \
static uint16_t write##name(uint8_t *_buff) { \
return write(address, _buff, size); \
} \
static uint16_t read##name(uint8_t *_buff) { \
return read(address, _buff, size); \
}
public:
__GP_REGISTER8 (MR, 0x0000); // Mode
__GP_REGISTER_N(GAR, 0x0001, 4); // Gateway IP address
__GP_REGISTER_N(SUBR, 0x0005, 4); // Subnet mask address
__GP_REGISTER_N(SHAR, 0x0009, 6); // Source MAC address
__GP_REGISTER_N(SIPR, 0x000F, 4); // Source IP address
__GP_REGISTER8 (IR, 0x0015); // Interrupt
__GP_REGISTER8 (IMR, 0x0016); // Interrupt Mask
__GP_REGISTER16(RTR, 0x0017); // Timeout address
__GP_REGISTER8 (RCR, 0x0019); // Retry count
__GP_REGISTER8 (RMSR, 0x001A); // Receive memory size
__GP_REGISTER8 (TMSR, 0x001B); // Transmit memory size
__GP_REGISTER8 (PATR, 0x001C); // Authentication type address in PPPoE mode
__GP_REGISTER8 (PTIMER, 0x0028); // PPP LCP Request Timer
__GP_REGISTER8 (PMAGIC, 0x0029); // PPP LCP Magic Number
__GP_REGISTER_N(UIPR, 0x002A, 4); // Unreachable IP address in UDP mode
__GP_REGISTER16(UPORT, 0x002E); // Unreachable Port address in UDP mode
#undef __GP_REGISTER8
#undef __GP_REGISTER16
#undef __GP_REGISTER_N
// W5100 Socket registers
// ----------------------
private:
static inline uint8_t readSn(SOCKET _s, uint16_t _addr);
static inline uint8_t writeSn(SOCKET _s, uint16_t _addr, uint8_t _data);
static inline uint16_t readSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t len);
static inline uint16_t writeSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t len);
static const uint16_t CH_BASE = 0x0400;
static const uint16_t CH_SIZE = 0x0100;
#define __SOCKET_REGISTER8(name, address) \
static inline void write##name(SOCKET _s, uint8_t _data) { \
writeSn(_s, address, _data); \
} \
static inline uint8_t read##name(SOCKET _s) { \
return readSn(_s, address); \
}
#define __SOCKET_REGISTER16(name, address) \
static void write##name(SOCKET _s, uint16_t _data) { \
writeSn(_s, address, _data >> 8); \
writeSn(_s, address+1, _data & 0xFF); \
} \
static uint16_t read##name(SOCKET _s) { \
uint16_t res = readSn(_s, address); \
uint16_t res2 = readSn(_s,address + 1); \
res = res << 8; \
res2 = res2 & 0xFF; \
res = res | res2; \
return res; \
}
#define __SOCKET_REGISTER_N(name, address, size) \
static uint16_t write##name(SOCKET _s, uint8_t *_buff) { \
return writeSn(_s, address, _buff, size); \
} \
static uint16_t read##name(SOCKET _s, uint8_t *_buff) { \
return readSn(_s, address, _buff, size); \
}
public:
__SOCKET_REGISTER8(SnMR, 0x0000) // Mode
__SOCKET_REGISTER8(SnCR, 0x0001) // Command
__SOCKET_REGISTER8(SnIR, 0x0002) // Interrupt
__SOCKET_REGISTER8(SnSR, 0x0003) // Status
__SOCKET_REGISTER16(SnPORT, 0x0004) // Source Port
__SOCKET_REGISTER_N(SnDHAR, 0x0006, 6) // Destination Hardw Addr
__SOCKET_REGISTER_N(SnDIPR, 0x000C, 4) // Destination IP Addr
__SOCKET_REGISTER16(SnDPORT, 0x0010) // Destination Port
__SOCKET_REGISTER16(SnMSSR, 0x0012) // Max Segment Size
__SOCKET_REGISTER8(SnPROTO, 0x0014) // Protocol in IP RAW Mode
__SOCKET_REGISTER8(SnTOS, 0x0015) // IP TOS
__SOCKET_REGISTER8(SnTTL, 0x0016) // IP TTL
__SOCKET_REGISTER16(SnTX_FSR, 0x0020) // TX Free Size
__SOCKET_REGISTER16(SnTX_RD, 0x0022) // TX Read Pointer
__SOCKET_REGISTER16(SnTX_WR, 0x0024) // TX Write Pointer
__SOCKET_REGISTER16(SnRX_RSR, 0x0026) // RX Free Size
__SOCKET_REGISTER16(SnRX_RD, 0x0028) // RX Read Pointer
__SOCKET_REGISTER16(SnRX_WR, 0x002A) // RX Write Pointer (supported?)
#undef __SOCKET_REGISTER8
#undef __SOCKET_REGISTER16
#undef __SOCKET_REGISTER_N
private:
static const uint8_t RST = 7; // Reset BIT
static const int SOCKETS = 4;
static const uint16_t SMASK = 0x07FF; // Tx buffer MASK
static const uint16_t RMASK = 0x07FF; // Rx buffer MASK
public:
static const uint16_t SSIZE = 2048; // Max Tx buffer size
private:
static const uint16_t RSIZE = 2048; // Max Rx buffer size
uint16_t SBASE[SOCKETS]; // Tx buffer base address
uint16_t RBASE[SOCKETS]; // Rx buffer base address
private:
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
#define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
#if defined(ARDUINO_ARCH_AVR)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
inline static void initSS() { DDRB |= _BV(4); };
inline static void setSS() { PORTB &= ~_BV(4); };
inline static void resetSS() { PORTB |= _BV(4); };
#elif defined(__AVR_ATmega32U4__)
inline static void initSS() { DDRB |= _BV(6); };
inline static void setSS() { PORTB &= ~_BV(6); };
inline static void resetSS() { PORTB |= _BV(6); };
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
inline static void initSS() { DDRB |= _BV(0); };
inline static void setSS() { PORTB &= ~_BV(0); };
inline static void resetSS() { PORTB |= _BV(0); };
#else
inline static void initSS() { DDRB |= _BV(2); };
inline static void setSS() { PORTB &= ~_BV(2); };
inline static void resetSS() { PORTB |= _BV(2); };
#endif
#elif defined(__ARDUINO_ARC__)
inline static void initSS() { pinMode(10, OUTPUT); };
inline static void setSS() { digitalWrite(10, LOW); };
inline static void resetSS() { digitalWrite(10, HIGH); };
#else
inline static void initSS() {
*portModeRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
}
inline static void setSS() {
*portOutputRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) &= ~digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
}
inline static void resetSS() {
*portOutputRegister(digitalPinToPort(ETHERNET_SHIELD_SPI_CS)) |= digitalPinToBitMask(ETHERNET_SHIELD_SPI_CS);
}
#endif
#else
#define SPI_ETHERNET_SETTINGS ETHERNET_SHIELD_SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)
// initSS(), setSS(), resetSS() not needed with EXTENDED_CS_PIN_HANDLING
#endif
};
extern W5100Class W5100;
uint8_t W5100Class::readSn(SOCKET _s, uint16_t _addr) {
return read(CH_BASE + _s * CH_SIZE + _addr);
}
uint8_t W5100Class::writeSn(SOCKET _s, uint16_t _addr, uint8_t _data) {
return write(CH_BASE + _s * CH_SIZE + _addr, _data);
}
uint16_t W5100Class::readSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t _len) {
return read(CH_BASE + _s * CH_SIZE + _addr, _buf, _len);
}
uint16_t W5100Class::writeSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t _len) {
return write(CH_BASE + _s * CH_SIZE + _addr, _buf, _len);
}
void W5100Class::getGatewayIp(uint8_t *_addr) {
readGAR(_addr);
}
void W5100Class::setGatewayIp(uint8_t *_addr) {
writeGAR(_addr);
}
void W5100Class::getSubnetMask(uint8_t *_addr) {
readSUBR(_addr);
}
void W5100Class::setSubnetMask(uint8_t *_addr) {
writeSUBR(_addr);
}
void W5100Class::getMACAddress(uint8_t *_addr) {
readSHAR(_addr);
}
void W5100Class::setMACAddress(uint8_t *_addr) {
writeSHAR(_addr);
}
void W5100Class::getIPAddress(uint8_t *_addr) {
readSIPR(_addr);
}
void W5100Class::setIPAddress(uint8_t *_addr) {
writeSIPR(_addr);
}
void W5100Class::setRetransmissionTime(uint16_t _timeout) {
writeRTR(_timeout);
}
void W5100Class::setRetransmissionCount(uint8_t _retry) {
writeRCR(_retry);
}
#endif

590
MQTT/PubSubClient.cpp Normal file
View File

@ -0,0 +1,590 @@
/*
PubSubClient.cpp - A simple client for MQTT.
Nick O'Leary
http://knolleary.net
*/
#include "PubSubClient.h"
#include "Arduino.h"
PubSubClient::PubSubClient() {
this->_state = MQTT_DISCONNECTED;
this->_client = NULL;
this->stream = NULL;
setCallback(NULL);
}
PubSubClient::PubSubClient(Client& client) {
this->_state = MQTT_DISCONNECTED;
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(addr, port);
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(addr,port);
setClient(client);
setStream(stream);
}
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(addr, port);
setCallback(callback);
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(addr,port);
setCallback(callback);
setClient(client);
setStream(stream);
}
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(ip, port);
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(ip,port);
setClient(client);
setStream(stream);
}
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(ip, port);
setCallback(callback);
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(ip,port);
setCallback(callback);
setClient(client);
setStream(stream);
}
PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(domain,port);
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(domain,port);
setClient(client);
setStream(stream);
}
PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
this->_state = MQTT_DISCONNECTED;
setServer(domain,port);
setCallback(callback);
setClient(client);
this->stream = NULL;
}
PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
this->_state = MQTT_DISCONNECTED;
setServer(domain,port);
setCallback(callback);
setClient(client);
setStream(stream);
}
boolean PubSubClient::connect(const char *id) {
return connect(id,NULL,NULL,0,0,0,0);
}
boolean PubSubClient::connect(const char *id, const char *user, const char *pass) {
return connect(id,user,pass,0,0,0,0);
}
boolean PubSubClient::connect(const char *id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage) {
return connect(id,NULL,NULL,willTopic,willQos,willRetain,willMessage);
}
boolean PubSubClient::connect(const char *id, const char *user, const char *pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage) {
if (!connected()) {
int result = 0;
if (domain != NULL) {
result = _client->connect(this->domain, this->port);
} else {
result = _client->connect(this->ip, this->port);
}
if (result == 1) {
nextMsgId = 1;
// Leave room in the buffer for header and variable length field
uint16_t length = 5;
unsigned int j;
#if MQTT_VERSION == MQTT_VERSION_3_1
uint8_t d[9] = {0x00,0x06,'M','Q','I','s','d','p', MQTT_VERSION};
#define MQTT_HEADER_VERSION_LENGTH 9
#elif MQTT_VERSION == MQTT_VERSION_3_1_1
uint8_t d[7] = {0x00,0x04,'M','Q','T','T',MQTT_VERSION};
#define MQTT_HEADER_VERSION_LENGTH 7
#endif
for (j = 0;j<MQTT_HEADER_VERSION_LENGTH;j++) {
buffer[length++] = d[j];
}
uint8_t v;
if (willTopic) {
v = 0x06|(willQos<<3)|(willRetain<<5);
} else {
v = 0x02;
}
if(user != NULL) {
v = v|0x80;
if(pass != NULL) {
v = v|(0x80>>1);
}
}
buffer[length++] = v;
buffer[length++] = ((MQTT_KEEPALIVE) >> 8);
buffer[length++] = ((MQTT_KEEPALIVE) & 0xFF);
length = writeString(id,buffer,length);
if (willTopic) {
length = writeString(willTopic,buffer,length);
length = writeString(willMessage,buffer,length);
}
if(user != NULL) {
length = writeString(user,buffer,length);
if(pass != NULL) {
length = writeString(pass,buffer,length);
}
}
write(MQTTCONNECT,buffer,length-5);
lastInActivity = lastOutActivity = millis();
while (!_client->available()) {
unsigned long t = millis();
if (t-lastInActivity >= ((int32_t) MQTT_SOCKET_TIMEOUT*1000UL)) {
_state = MQTT_CONNECTION_TIMEOUT;
_client->stop();
return false;
}
}
uint8_t llen;
uint16_t len = readPacket(&llen);
if (len == 4) {
if (buffer[3] == 0) {
lastInActivity = millis();
pingOutstanding = false;
_state = MQTT_CONNECTED;
return true;
} else {
_state = buffer[3];
}
}
_client->stop();
} else {
_state = MQTT_CONNECT_FAILED;
}
return false;
}
return true;
}
// reads a byte into result
boolean PubSubClient::readByte(uint8_t * result) {
uint32_t previousMillis = millis();
while(!_client->available()) {
uint32_t currentMillis = millis();
if(currentMillis - previousMillis >= ((int32_t) MQTT_SOCKET_TIMEOUT * 1000)){
return false;
}
}
*result = _client->read();
return true;
}
// reads a byte into result[*index] and increments index
boolean PubSubClient::readByte(uint8_t * result, uint16_t * index){
uint16_t current_index = *index;
uint8_t * write_address = &(result[current_index]);
if(readByte(write_address)){
*index = current_index + 1;
return true;
}
return false;
}
uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
uint16_t len = 0;
if(!readByte(buffer, &len)) return 0;
bool isPublish = (buffer[0]&0xF0) == MQTTPUBLISH;
uint32_t multiplier = 1;
uint16_t length = 0;
uint8_t digit = 0;
uint16_t skip = 0;
uint8_t start = 0;
do {
if(!readByte(&digit)) return 0;
buffer[len++] = digit;
length += (digit & 127) * multiplier;
multiplier *= 128;
} while ((digit & 128) != 0);
*lengthLength = len-1;
if (isPublish) {
// Read in topic length to calculate bytes to skip over for Stream writing
if(!readByte(buffer, &len)) return 0;
if(!readByte(buffer, &len)) return 0;
skip = (buffer[*lengthLength+1]<<8)+buffer[*lengthLength+2];
start = 2;
if (buffer[0]&MQTTQOS1) {
// skip message id
skip += 2;
}
}
for (uint16_t i = start;i<length;i++) {
if(!readByte(&digit)) return 0;
if (this->stream) {
if (isPublish && len-*lengthLength-2>skip) {
this->stream->write(digit);
}
}
if (len < MQTT_MAX_PACKET_SIZE) {
buffer[len] = digit;
}
len++;
}
if (!this->stream && len > MQTT_MAX_PACKET_SIZE) {
len = 0; // This will cause the packet to be ignored.
}
return len;
}
boolean PubSubClient::loop() {
if (connected()) {
unsigned long t = millis();
if ((t - lastInActivity > MQTT_KEEPALIVE*1000UL) || (t - lastOutActivity > MQTT_KEEPALIVE*1000UL)) {
if (pingOutstanding) {
this->_state = MQTT_CONNECTION_TIMEOUT;
_client->stop();
return false;
} else {
buffer[0] = MQTTPINGREQ;
buffer[1] = 0;
_client->write(buffer,2);
lastOutActivity = t;
lastInActivity = t;
pingOutstanding = true;
}
}
if (_client->available()) {
uint8_t llen;
uint16_t len = readPacket(&llen);
uint16_t msgId = 0;
uint8_t *payload;
if (len > 0) {
lastInActivity = t;
uint8_t type = buffer[0]&0xF0;
if (type == MQTTPUBLISH) {
if (callback) {
uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2];
char topic[tl+1];
for (uint16_t i=0;i<tl;i++) {
topic[i] = buffer[llen+3+i];
}
topic[tl] = 0;
// msgId only present for QOS>0
if ((buffer[0]&0x06) == MQTTQOS1) {
msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1];
payload = buffer+llen+3+tl+2;
callback(topic,payload,len-llen-3-tl-2);
buffer[0] = MQTTPUBACK;
buffer[1] = 2;
buffer[2] = (msgId >> 8);
buffer[3] = (msgId & 0xFF);
_client->write(buffer,4);
lastOutActivity = t;
} else {
payload = buffer+llen+3+tl;
callback(topic,payload,len-llen-3-tl);
}
}
} else if (type == MQTTPINGREQ) {
buffer[0] = MQTTPINGRESP;
buffer[1] = 0;
_client->write(buffer,2);
} else if (type == MQTTPINGRESP) {
pingOutstanding = false;
}
}
}
return true;
}
return false;
}
boolean PubSubClient::publish(const char* topic, const char* payload) {
return publish(topic,(const uint8_t*)payload,strlen(payload),false);
}
boolean PubSubClient::publish(const char* topic, const char* payload, boolean retained) {
return publish(topic,(const uint8_t*)payload,strlen(payload),retained);
}
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength) {
return publish(topic, payload, plength, false);
}
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
if (connected()) {
if (MQTT_MAX_PACKET_SIZE < 5 + 2+strlen(topic) + plength) {
// Too long
return false;
}
// Leave room in the buffer for header and variable length field
uint16_t length = 5;
length = writeString(topic,buffer,length);
uint16_t i;
for (i=0;i<plength;i++) {
buffer[length++] = payload[i];
}
uint8_t header = MQTTPUBLISH;
if (retained) {
header |= 1;
}
return write(header,buffer,length-5);
}
return false;
}
boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
uint8_t llen = 0;
uint8_t digit;
unsigned int rc = 0;
uint16_t tlen;
unsigned int pos = 0;
unsigned int i;
uint8_t header;
unsigned int len;
if (!connected()) {
return false;
}
tlen = strlen(topic);
header = MQTTPUBLISH;
if (retained) {
header |= 1;
}
buffer[pos++] = header;
len = plength + 2 + tlen;
do {
digit = len % 128;
len = len / 128;
if (len > 0) {
digit |= 0x80;
}
buffer[pos++] = digit;
llen++;
} while(len>0);
pos = writeString(topic,buffer,pos);
rc += _client->write(buffer,pos);
for (i=0;i<plength;i++) {
rc += _client->write((char)pgm_read_byte_near(payload + i));
}
lastOutActivity = millis();
return rc == tlen + 4 + plength;
}
boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
uint8_t lenBuf[4];
uint8_t llen = 0;
uint8_t digit;
uint8_t pos = 0;
uint16_t rc;
uint16_t len = length;
do {
digit = len % 128;
len = len / 128;
if (len > 0) {
digit |= 0x80;
}
lenBuf[pos++] = digit;
llen++;
} while(len>0);
buf[4-llen] = header;
for (int i=0;i<llen;i++) {
buf[5-llen+i] = lenBuf[i];
}
#ifdef MQTT_MAX_TRANSFER_SIZE
uint8_t* writeBuf = buf+(4-llen);
uint16_t bytesRemaining = length+1+llen; //Match the length type
uint8_t bytesToWrite;
boolean result = true;
while((bytesRemaining > 0) && result) {
bytesToWrite = (bytesRemaining > MQTT_MAX_TRANSFER_SIZE)?MQTT_MAX_TRANSFER_SIZE:bytesRemaining;
rc = _client->write(writeBuf,bytesToWrite);
result = (rc == bytesToWrite);
bytesRemaining -= rc;
writeBuf += rc;
}
return result;
#else
rc = _client->write(buf+(4-llen),length+1+llen);
lastOutActivity = millis();
return (rc == 1+llen+length);
#endif
}
boolean PubSubClient::subscribe(const char* topic) {
return subscribe(topic, 0);
}
boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
if (qos < 0 || qos > 1) {
return false;
}
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
// Too long
return false;
}
if (connected()) {
// Leave room in the buffer for header and variable length field
uint16_t length = 5;
nextMsgId++;
if (nextMsgId == 0) {
nextMsgId = 1;
}
buffer[length++] = (nextMsgId >> 8);
buffer[length++] = (nextMsgId & 0xFF);
length = writeString((char*)topic, buffer,length);
buffer[length++] = qos;
return write(MQTTSUBSCRIBE|MQTTQOS1,buffer,length-5);
}
return false;
}
boolean PubSubClient::unsubscribe(const char* topic) {
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
// Too long
return false;
}
if (connected()) {
uint16_t length = 5;
nextMsgId++;
if (nextMsgId == 0) {
nextMsgId = 1;
}
buffer[length++] = (nextMsgId >> 8);
buffer[length++] = (nextMsgId & 0xFF);
length = writeString(topic, buffer,length);
return write(MQTTUNSUBSCRIBE|MQTTQOS1,buffer,length-5);
}
return false;
}
void PubSubClient::disconnect() {
buffer[0] = MQTTDISCONNECT;
buffer[1] = 0;
_client->write(buffer,2);
_state = MQTT_DISCONNECTED;
_client->stop();
lastInActivity = lastOutActivity = millis();
}
uint16_t PubSubClient::writeString(const char* string, uint8_t* buf, uint16_t pos) {
const char* idp = string;
uint16_t i = 0;
pos += 2;
while (*idp) {
buf[pos++] = *idp++;
i++;
}
buf[pos-i-2] = (i >> 8);
buf[pos-i-1] = (i & 0xFF);
return pos;
}
boolean PubSubClient::connected() {
boolean rc;
if (_client == NULL ) {
rc = false;
} else {
rc = (int)_client->connected();
if (!rc) {
if (this->_state == MQTT_CONNECTED) {
this->_state = MQTT_CONNECTION_LOST;
_client->flush();
_client->stop();
}
}
}
return rc;
}
PubSubClient& PubSubClient::setServer(uint8_t * ip, uint16_t port) {
IPAddress addr(ip[0],ip[1],ip[2],ip[3]);
return setServer(addr,port);
}
PubSubClient& PubSubClient::setServer(IPAddress ip, uint16_t port) {
this->ip = ip;
this->port = port;
this->domain = NULL;
return *this;
}
PubSubClient& PubSubClient::setServer(const char * domain, uint16_t port) {
this->domain = domain;
this->port = port;
return *this;
}
PubSubClient& PubSubClient::setCallback(MQTT_CALLBACK_SIGNATURE) {
this->callback = callback;
return *this;
}
PubSubClient& PubSubClient::setClient(Client& client){
this->_client = &client;
return *this;
}
PubSubClient& PubSubClient::setStream(Stream& stream){
this->stream = &stream;
return *this;
}
int PubSubClient::state() {
return this->_state;
}

144
MQTT/PubSubClient.h Normal file
View File

@ -0,0 +1,144 @@
/*
PubSubClient.h - A simple client for MQTT.
Nick O'Leary
http://knolleary.net
*/
#ifndef PubSubClient_h
#define PubSubClient_h
#include <Arduino.h>
#include "IPAddress.h"
#include "Client.h"
#include "Stream.h"
#define MQTT_VERSION_3_1 3
#define MQTT_VERSION_3_1_1 4
// MQTT_VERSION : Pick the version
//#define MQTT_VERSION MQTT_VERSION_3_1
#ifndef MQTT_VERSION
#define MQTT_VERSION MQTT_VERSION_3_1_1
#endif
// MQTT_MAX_PACKET_SIZE : Maximum packet size
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 128
#endif
// MQTT_KEEPALIVE : keepAlive interval in Seconds
#ifndef MQTT_KEEPALIVE
#define MQTT_KEEPALIVE 15
#endif
// MQTT_SOCKET_TIMEOUT: socket timeout interval in Seconds
#ifndef MQTT_SOCKET_TIMEOUT
#define MQTT_SOCKET_TIMEOUT 15
#endif
// MQTT_MAX_TRANSFER_SIZE : limit how much data is passed to the network client
// in each write call. Needed for the Arduino Wifi Shield. Leave undefined to
// pass the entire MQTT packet in each write call.
//#define MQTT_MAX_TRANSFER_SIZE 80
// Possible values for client.state()
#define MQTT_CONNECTION_TIMEOUT -4
#define MQTT_CONNECTION_LOST -3
#define MQTT_CONNECT_FAILED -2
#define MQTT_DISCONNECTED -1
#define MQTT_CONNECTED 0
#define MQTT_CONNECT_BAD_PROTOCOL 1
#define MQTT_CONNECT_BAD_CLIENT_ID 2
#define MQTT_CONNECT_UNAVAILABLE 3
#define MQTT_CONNECT_BAD_CREDENTIALS 4
#define MQTT_CONNECT_UNAUTHORIZED 5
#define MQTTCONNECT 1 << 4 // Client request to connect to Server
#define MQTTCONNACK 2 << 4 // Connect Acknowledgment
#define MQTTPUBLISH 3 << 4 // Publish message
#define MQTTPUBACK 4 << 4 // Publish Acknowledgment
#define MQTTPUBREC 5 << 4 // Publish Received (assured delivery part 1)
#define MQTTPUBREL 6 << 4 // Publish Release (assured delivery part 2)
#define MQTTPUBCOMP 7 << 4 // Publish Complete (assured delivery part 3)
#define MQTTSUBSCRIBE 8 << 4 // Client Subscribe request
#define MQTTSUBACK 9 << 4 // Subscribe Acknowledgment
#define MQTTUNSUBSCRIBE 10 << 4 // Client Unsubscribe request
#define MQTTUNSUBACK 11 << 4 // Unsubscribe Acknowledgment
#define MQTTPINGREQ 12 << 4 // PING Request
#define MQTTPINGRESP 13 << 4 // PING Response
#define MQTTDISCONNECT 14 << 4 // Client is Disconnecting
#define MQTTReserved 15 << 4 // Reserved
#define MQTTQOS0 (0 << 1)
#define MQTTQOS1 (1 << 1)
#define MQTTQOS2 (2 << 1)
#ifdef ESP8266
#include <functional>
#define MQTT_CALLBACK_SIGNATURE std::function<void(char*, uint8_t*, unsigned int)> callback
#else
#define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int)
#endif
class PubSubClient {
private:
Client* _client;
uint8_t buffer[MQTT_MAX_PACKET_SIZE];
uint16_t nextMsgId;
unsigned long lastOutActivity;
unsigned long lastInActivity;
bool pingOutstanding;
MQTT_CALLBACK_SIGNATURE;
uint16_t readPacket(uint8_t*);
boolean readByte(uint8_t * result);
boolean readByte(uint8_t * result, uint16_t * index);
boolean write(uint8_t header, uint8_t* buf, uint16_t length);
uint16_t writeString(const char* string, uint8_t* buf, uint16_t pos);
IPAddress ip;
const char* domain;
uint16_t port;
Stream* stream;
int _state;
public:
PubSubClient();
PubSubClient(Client& client);
PubSubClient(IPAddress, uint16_t, Client& client);
PubSubClient(IPAddress, uint16_t, Client& client, Stream&);
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
PubSubClient(uint8_t *, uint16_t, Client& client);
PubSubClient(uint8_t *, uint16_t, Client& client, Stream&);
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
PubSubClient(uint8_t *, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
PubSubClient(const char*, uint16_t, Client& client);
PubSubClient(const char*, uint16_t, Client& client, Stream&);
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
PubSubClient& setServer(IPAddress ip, uint16_t port);
PubSubClient& setServer(uint8_t * ip, uint16_t port);
PubSubClient& setServer(const char * domain, uint16_t port);
PubSubClient& setCallback(MQTT_CALLBACK_SIGNATURE);
PubSubClient& setClient(Client& client);
PubSubClient& setStream(Stream& stream);
boolean connect(const char* id);
boolean connect(const char* id, const char* user, const char* pass);
boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
void disconnect();
boolean publish(const char* topic, const char* payload);
boolean publish(const char* topic, const char* payload, boolean retained);
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
boolean publish_P(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
boolean subscribe(const char* topic);
boolean subscribe(const char* topic, uint8_t qos);
boolean unsubscribe(const char* topic);
boolean loop();
boolean connected();
int state();
};
#endif

73
Metro/Metro.cpp Normal file
View File

@ -0,0 +1,73 @@
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Metro.h"
Metro::Metro(unsigned long interval_millis)
{
this->autoreset = 0;
interval(interval_millis);
reset();
}
// New creator so I can use either the original check behavior or benjamin.soelberg's
// suggested one (see below).
// autoreset = 0 is benjamin.soelberg's check behavior
// autoreset != 0 is the original behavior
Metro::Metro(unsigned long interval_millis, uint8_t autoreset)
{
this->autoreset = autoreset; // Fix by Paul Bouchier
interval(interval_millis);
reset();
}
void Metro::interval(unsigned long interval_millis)
{
this->interval_millis = interval_millis;
}
// Benjamin.soelberg's check behavior:
// When a check is true, add the interval to the internal counter.
// This should guarantee a better overall stability.
// Original check behavior:
// When a check is true, add the interval to the current millis() counter.
// This method can add a certain offset over time.
char Metro::check()
{
if (millis() - this->previous_millis >= this->interval_millis) {
// As suggested by benjamin.soelberg@gmail.com, the following line
// this->previous_millis = millis();
// was changed to
// this->previous_millis += this->interval_millis;
// If the interval is set to 0 we revert to the original behavior
if (this->interval_millis <= 0 || this->autoreset ) {
this->previous_millis = millis();
} else {
this->previous_millis += this->interval_millis;
}
return 1;
}
return 0;
}
void Metro::reset()
{
this->previous_millis = millis();
}

26
Metro/Metro.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef Metro_h
#define Metro_h
#include <inttypes.h>
class Metro
{
public:
Metro(unsigned long interval_millis);
Metro(unsigned long interval_millis, uint8_t autoreset);
void interval(unsigned long interval_millis);
char check();
void reset();
private:
uint8_t autoreset;
unsigned long previous_millis, interval_millis;
};
#endif

22
Mqtt433Gateway.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "Mqtt433Gateway.h"
#include <Streaming.h>
#include <avr/wdt.h>
#include "mqttclient.h"
#include "s433client.h"
void setup() {
Serial.begin(115200);
Serial << "Mqtt433Gateway starting ..." << endl;
MqttClientNS::begin();
s433ClientNS::begin();
wdt_enable(WDTO_8S);
}
void loop() {
MqttClientNS::exec();
s433ClientNS::exec();
}

22
Mqtt433Gateway.h Normal file
View File

@ -0,0 +1,22 @@
// Only modify this file to include
// - function definitions (prototypes)
// - include files
// - extern variable definitions
// In the appropriate section
#ifndef _MqttCanGateway_H_
#define _MqttCanGateway_H_
#include "Arduino.h"
//add your includes for the project MqttCanGateway here
//end of add your includes here
//add your function definitions for the project MqttCanGateway here
//Do not add code below this line
#endif /* _MqttCanGateway_H_ */

696
RCSwitch/RCSwitch.cpp Normal file
View File

@ -0,0 +1,696 @@
/*
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat Özgür. All right reserved.
Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
- Dominik Fischer / dom_fischer(at)web(dot)de
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Andreas Steinel / A.<lastname>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
- Johann Richard / <first name>.<last name>(at)gmail(dot)com
- Vlad Gheorghe / <first name>.<last name>(at)gmail(dot)com https://github.com/vgheo
Project home: https://github.com/sui77/rc-switch/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "RCSwitch.h"
#ifdef RaspberryPi
// PROGMEM and _P functions are for AVR based microprocessors,
// so we must normalize these for the ARM processor:
#define PROGMEM
#define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
#endif
#ifdef ESP8266
// interrupt handler and related code must be in RAM on ESP8266,
// according to issue #46.
#define RECEIVE_ATTR ICACHE_RAM_ATTR
#else
#define RECEIVE_ATTR
#endif
/* Format for protocol definitions:
* {pulselength, Sync bit, "0" bit, "1" bit}
*
* pulselength: pulse length in microseconds, e.g. 350
* Sync bit: {1, 31} means 1 high pulse and 31 low pulses
* (perceived as a 31*pulselength long pulse, total length of sync bit is
* 32*pulselength microseconds), i.e:
* _
* | |_______________________________ (don't count the vertical bars)
* "0" bit: waveform for a data bit of value "0", {1, 3} means 1 high pulse
* and 3 low pulses, total length (1+3)*pulselength, i.e:
* _
* | |___
* "1" bit: waveform for a data bit of value "1", e.g. {3,1}:
* ___
* | |_
*
* These are combined to form Tri-State bits when sending or receiving codes.
*/
#ifdef ESP8266
static const RCSwitch::Protocol proto[] = {
#else
static const RCSwitch::Protocol PROGMEM proto[] = {
#endif
{ 350, { 1, 31 }, { 1, 3 }, { 3, 1 }, false }, // protocol 1
{ 650, { 1, 10 }, { 1, 2 }, { 2, 1 }, false }, // protocol 2
{ 100, { 30, 71 }, { 4, 11 }, { 9, 6 }, false }, // protocol 3
{ 380, { 1, 6 }, { 1, 3 }, { 3, 1 }, false }, // protocol 4
{ 500, { 6, 14 }, { 1, 2 }, { 2, 1 }, false }, // protocol 5
{ 450, { 23, 1 }, { 1, 2 }, { 2, 1 }, true } // protocol 6 (HT6P20B)
};
enum {
numProto = sizeof(proto) / sizeof(proto[0])
};
#if not defined( RCSwitchDisableReceiving )
unsigned long RCSwitch::nReceivedValue = 0;
unsigned int RCSwitch::nReceivedBitlength = 0;
unsigned int RCSwitch::nReceivedDelay = 0;
unsigned int RCSwitch::nReceivedProtocol = 0;
int RCSwitch::nReceiveTolerance = 60;
const unsigned int RCSwitch::nSeparationLimit = 4600;
// separationLimit: minimum microseconds between received codes, closer codes are ignored.
// according to discussion on issue #14 it might be more suitable to set the separation
// limit to the same time as the 'low' part of the sync signal for the current protocol.
unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES];
#endif
RCSwitch::RCSwitch() {
this->nTransmitterPin = -1;
this->setRepeatTransmit(10);
this->setProtocol(1);
#if not defined( RCSwitchDisableReceiving )
this->nReceiverInterrupt = -1;
this->setReceiveTolerance(60);
RCSwitch::nReceivedValue = 0;
#endif
}
/**
* Sets the protocol to send.
*/
void RCSwitch::setProtocol(Protocol protocol) {
this->protocol = protocol;
}
/**
* Sets the protocol to send, from a list of predefined protocols
*/
void RCSwitch::setProtocol(int nProtocol) {
if (nProtocol < 1 || nProtocol > numProto) {
nProtocol = 1; // TODO: trigger an error, e.g. "bad protocol" ???
}
#ifdef ESP8266
this->protocol = proto[nProtocol-1];
#else
memcpy_P(&this->protocol, &proto[nProtocol-1], sizeof(Protocol));
#endif
}
/**
* Sets the protocol to send with pulse length in microseconds.
*/
void RCSwitch::setProtocol(int nProtocol, int nPulseLength) {
setProtocol(nProtocol);
this->setPulseLength(nPulseLength);
}
/**
* Sets pulse length in microseconds
*/
void RCSwitch::setPulseLength(int nPulseLength) {
this->protocol.pulseLength = nPulseLength;
}
/**
* Sets Repeat Transmits
*/
void RCSwitch::setRepeatTransmit(int nRepeatTransmit) {
this->nRepeatTransmit = nRepeatTransmit;
}
/**
* Set Receiving Tolerance
*/
#if not defined( RCSwitchDisableReceiving )
void RCSwitch::setReceiveTolerance(int nPercent) {
RCSwitch::nReceiveTolerance = nPercent;
}
#endif
/**
* Enable transmissions
*
* @param nTransmitterPin Arduino Pin to which the sender is connected to
*/
void RCSwitch::enableTransmit(int nTransmitterPin) {
this->nTransmitterPin = nTransmitterPin;
pinMode(this->nTransmitterPin, OUTPUT);
}
/**
* Disable transmissions
*/
void RCSwitch::disableTransmit() {
this->nTransmitterPin = -1;
}
/**
* Switch a remote switch on (Type D REV)
*
* @param sGroup Code of the switch group (A,B,C,D)
* @param nDevice Number of the switch itself (1..3)
*/
void RCSwitch::switchOn(char sGroup, int nDevice) {
this->sendTriState( this->getCodeWordD(sGroup, nDevice, true) );
}
/**
* Switch a remote switch off (Type D REV)
*
* @param sGroup Code of the switch group (A,B,C,D)
* @param nDevice Number of the switch itself (1..3)
*/
void RCSwitch::switchOff(char sGroup, int nDevice) {
this->sendTriState( this->getCodeWordD(sGroup, nDevice, false) );
}
/**
* Switch a remote switch on (Type C Intertechno)
*
* @param sFamily Familycode (a..f)
* @param nGroup Number of group (1..4)
* @param nDevice Number of device (1..4)
*/
void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) {
this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, true) );
}
/**
* Switch a remote switch off (Type C Intertechno)
*
* @param sFamily Familycode (a..f)
* @param nGroup Number of group (1..4)
* @param nDevice Number of device (1..4)
*/
void RCSwitch::switchOff(char sFamily, int nGroup, int nDevice) {
this->sendTriState( this->getCodeWordC(sFamily, nGroup, nDevice, false) );
}
/**
* Switch a remote switch on (Type B with two rotary/sliding switches)
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
*/
void RCSwitch::switchOn(int nAddressCode, int nChannelCode) {
this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, true) );
}
/**
* Switch a remote switch off (Type B with two rotary/sliding switches)
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
*/
void RCSwitch::switchOff(int nAddressCode, int nChannelCode) {
this->sendTriState( this->getCodeWordB(nAddressCode, nChannelCode, false) );
}
/**
* Deprecated, use switchOn(const char* sGroup, const char* sDevice) instead!
* Switch a remote switch on (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param nChannelCode Number of the switch itself (1..5)
*/
void RCSwitch::switchOn(const char* sGroup, int nChannel) {
const char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };
this->switchOn(sGroup, code[nChannel]);
}
/**
* Deprecated, use switchOff(const char* sGroup, const char* sDevice) instead!
* Switch a remote switch off (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param nChannelCode Number of the switch itself (1..5)
*/
void RCSwitch::switchOff(const char* sGroup, int nChannel) {
const char* code[6] = { "00000", "10000", "01000", "00100", "00010", "00001" };
this->switchOff(sGroup, code[nChannel]);
}
/**
* Switch a remote switch on (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*/
void RCSwitch::switchOn(const char* sGroup, const char* sDevice) {
this->sendTriState( this->getCodeWordA(sGroup, sDevice, true) );
}
/**
* Switch a remote switch off (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*/
void RCSwitch::switchOff(const char* sGroup, const char* sDevice) {
this->sendTriState( this->getCodeWordA(sGroup, sDevice, false) );
}
/**
* Returns a char[13], representing the code word to be send.
*
*/
char* RCSwitch::getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
for (int i = 0; i < 5; i++) {
sReturn[nReturnPos++] = (sGroup[i] == '0') ? 'F' : '0';
}
for (int i = 0; i < 5; i++) {
sReturn[nReturnPos++] = (sDevice[i] == '0') ? 'F' : '0';
}
sReturn[nReturnPos++] = bStatus ? '0' : 'F';
sReturn[nReturnPos++] = bStatus ? 'F' : '0';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* Encoding for type B switches with two rotary/sliding switches.
*
* The code word is a tristate word and with following bit pattern:
*
* +-----------------------------+-----------------------------+----------+------------+
* | 4 bits address | 4 bits address | 3 bits | 1 bit |
* | switch group | switch number | not used | on / off |
* | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | FFF | on=F off=0 |
* +-----------------------------+-----------------------------+----------+------------+
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
* @param bStatus Whether to switch on (true) or off (false)
*
* @return char[13], representing a tristate code word of length 12
*/
char* RCSwitch::getCodeWordB(int nAddressCode, int nChannelCode, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) {
return 0;
}
for (int i = 1; i <= 4; i++) {
sReturn[nReturnPos++] = (nAddressCode == i) ? '0' : 'F';
}
for (int i = 1; i <= 4; i++) {
sReturn[nReturnPos++] = (nChannelCode == i) ? '0' : 'F';
}
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = bStatus ? 'F' : '0';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* Like getCodeWord (Type C = Intertechno)
*/
char* RCSwitch::getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
int nFamily = (int)sFamily - 'a';
if ( nFamily < 0 || nFamily > 15 || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) {
return 0;
}
// encode the family into four bits
sReturn[nReturnPos++] = (nFamily & 1) ? 'F' : '0';
sReturn[nReturnPos++] = (nFamily & 2) ? 'F' : '0';
sReturn[nReturnPos++] = (nFamily & 4) ? 'F' : '0';
sReturn[nReturnPos++] = (nFamily & 8) ? 'F' : '0';
// encode the device and group
sReturn[nReturnPos++] = ((nDevice-1) & 1) ? 'F' : '0';
sReturn[nReturnPos++] = ((nDevice-1) & 2) ? 'F' : '0';
sReturn[nReturnPos++] = ((nGroup-1) & 1) ? 'F' : '0';
sReturn[nReturnPos++] = ((nGroup-1) & 2) ? 'F' : '0';
// encode the status code
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = 'F';
sReturn[nReturnPos++] = bStatus ? 'F' : '0';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* Encoding for the REV Switch Type
*
* The code word is a tristate word and with following bit pattern:
*
* +-----------------------------+-------------------+----------+--------------+
* | 4 bits address | 3 bits address | 3 bits | 2 bits |
* | switch group | device number | not used | on / off |
* | A=1FFF B=F1FF C=FF1F D=FFF1 | 1=0FF 2=F0F 3=FF0 | 000 | on=10 off=01 |
* +-----------------------------+-------------------+----------+--------------+
*
* Source: http://www.the-intruder.net/funksteckdosen-von-rev-uber-arduino-ansteuern/
*
* @param sGroup Name of the switch group (A..D, resp. a..d)
* @param nDevice Number of the switch itself (1..3)
* @param bStatus Whether to switch on (true) or off (false)
*
* @return char[13], representing a tristate code word of length 12
*/
char* RCSwitch::getCodeWordD(char sGroup, int nDevice, bool bStatus) {
static char sReturn[13];
int nReturnPos = 0;
// sGroup must be one of the letters in "abcdABCD"
int nGroup = (sGroup >= 'a') ? (int)sGroup - 'a' : (int)sGroup - 'A';
if ( nGroup < 0 || nGroup > 3 || nDevice < 1 || nDevice > 3) {
return 0;
}
for (int i = 0; i < 4; i++) {
sReturn[nReturnPos++] = (nGroup == i) ? '1' : 'F';
}
for (int i = 1; i <= 3; i++) {
sReturn[nReturnPos++] = (nDevice == i) ? '1' : 'F';
}
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = '0';
sReturn[nReturnPos++] = bStatus ? '1' : '0';
sReturn[nReturnPos++] = bStatus ? '0' : '1';
sReturn[nReturnPos] = '\0';
return sReturn;
}
/**
* @param sCodeWord a tristate code word consisting of the letter 0, 1, F
*/
void RCSwitch::sendTriState(const char* sCodeWord) {
// turn the tristate code word into the corresponding bit pattern, then send it
unsigned long code = 0;
unsigned int length = 0;
for (const char* p = sCodeWord; *p; p++) {
code <<= 2L;
switch (*p) {
case '0':
// bit pattern 00
break;
case 'F':
// bit pattern 01
code |= 1L;
break;
case '1':
// bit pattern 11
code |= 3L;
break;
}
length += 2;
}
this->send(code, length);
}
/**
* @param sCodeWord a binary code word consisting of the letter 0, 1
*/
void RCSwitch::send(const char* sCodeWord) {
// turn the tristate code word into the corresponding bit pattern, then send it
unsigned long code = 0;
unsigned int length = 0;
for (const char* p = sCodeWord; *p; p++) {
code <<= 1L;
if (*p != '0')
code |= 1L;
length++;
}
this->send(code, length);
}
/**
* Transmit the first 'length' bits of the integer 'code'. The
* bits are sent from MSB to LSB, i.e., first the bit at position length-1,
* then the bit at position length-2, and so on, till finally the bit at position 0.
*/
void RCSwitch::send(unsigned long code, unsigned int length) {
if (this->nTransmitterPin == -1)
return;
#if not defined( RCSwitchDisableReceiving )
// make sure the receiver is disabled while we transmit
int nReceiverInterrupt_backup = nReceiverInterrupt;
if (nReceiverInterrupt_backup != -1) {
this->disableReceive();
}
#endif
for (int nRepeat = 0; nRepeat < nRepeatTransmit; nRepeat++) {
for (int i = length-1; i >= 0; i--) {
if (code & (1L << i))
this->transmit(protocol.one);
else
this->transmit(protocol.zero);
}
this->transmit(protocol.syncFactor);
}
#if not defined( RCSwitchDisableReceiving )
// enable receiver again if we just disabled it
if (nReceiverInterrupt_backup != -1) {
this->enableReceive(nReceiverInterrupt_backup);
}
#endif
}
/**
* Transmit a single high-low pulse.
*/
void RCSwitch::transmit(HighLow pulses) {
uint8_t firstLogicLevel = (this->protocol.invertedSignal) ? LOW : HIGH;
uint8_t secondLogicLevel = (this->protocol.invertedSignal) ? HIGH : LOW;
digitalWrite(this->nTransmitterPin, firstLogicLevel);
delayMicroseconds( this->protocol.pulseLength * pulses.high);
digitalWrite(this->nTransmitterPin, secondLogicLevel);
delayMicroseconds( this->protocol.pulseLength * pulses.low);
}
#if not defined( RCSwitchDisableReceiving )
/**
* Enable receiving data
*/
void RCSwitch::enableReceive(int interrupt) {
this->nReceiverInterrupt = interrupt;
this->enableReceive();
}
void RCSwitch::enableReceive() {
if (this->nReceiverInterrupt != -1) {
RCSwitch::nReceivedValue = 0;
RCSwitch::nReceivedBitlength = 0;
#if defined(RaspberryPi) // Raspberry Pi
wiringPiISR(this->nReceiverInterrupt, INT_EDGE_BOTH, &handleInterrupt);
#else // Arduino
attachInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);
#endif
}
}
/**
* Disable receiving data
*/
void RCSwitch::disableReceive() {
#if not defined(RaspberryPi) // Arduino
detachInterrupt(this->nReceiverInterrupt);
#endif // For Raspberry Pi (wiringPi) you can't unregister the ISR
this->nReceiverInterrupt = -1;
}
bool RCSwitch::available() {
return RCSwitch::nReceivedValue != 0;
}
void RCSwitch::resetAvailable() {
RCSwitch::nReceivedValue = 0;
}
unsigned long RCSwitch::getReceivedValue() {
return RCSwitch::nReceivedValue;
}
unsigned int RCSwitch::getReceivedBitlength() {
return RCSwitch::nReceivedBitlength;
}
unsigned int RCSwitch::getReceivedDelay() {
return RCSwitch::nReceivedDelay;
}
unsigned int RCSwitch::getReceivedProtocol() {
return RCSwitch::nReceivedProtocol;
}
unsigned int* RCSwitch::getReceivedRawdata() {
return RCSwitch::timings;
}
/* helper function for the receiveProtocol method */
static inline unsigned int diff(int A, int B) {
return abs(A - B);
}
/**
*
*/
bool RECEIVE_ATTR RCSwitch::receiveProtocol(const int p, unsigned int changeCount) {
#ifdef ESP8266
const Protocol &pro = proto[p-1];
#else
Protocol pro;
memcpy_P(&pro, &proto[p-1], sizeof(Protocol));
#endif
unsigned long code = 0;
//Assuming the longer pulse length is the pulse captured in timings[0]
const unsigned int syncLengthInPulses = ((pro.syncFactor.low) > (pro.syncFactor.high)) ? (pro.syncFactor.low) : (pro.syncFactor.high);
const unsigned int delay = RCSwitch::timings[0] / syncLengthInPulses;
const unsigned int delayTolerance = delay * RCSwitch::nReceiveTolerance / 100;
/* For protocols that start low, the sync period looks like
* _________
* _____________| |XXXXXXXXXXXX|
*
* |--1st dur--|-2nd dur-|-Start data-|
*
* The 3rd saved duration starts the data.
*
* For protocols that start high, the sync period looks like
*
* ______________
* | |____________|XXXXXXXXXXXXX|
*
* |-filtered out-|--1st dur--|--Start data--|
*
* The 2nd saved duration starts the data
*/
const unsigned int firstDataTiming = (pro.invertedSignal) ? (2) : (1);
for (unsigned int i = firstDataTiming; i < changeCount - 1; i += 2) {
code <<= 1;
if (diff(RCSwitch::timings[i], delay * pro.zero.high) < delayTolerance &&
diff(RCSwitch::timings[i + 1], delay * pro.zero.low) < delayTolerance) {
// zero
} else if (diff(RCSwitch::timings[i], delay * pro.one.high) < delayTolerance &&
diff(RCSwitch::timings[i + 1], delay * pro.one.low) < delayTolerance) {
// one
code |= 1;
} else {
// Failed
return false;
}
}
if (changeCount > 7) { // ignore very short transmissions: no device sends them, so this must be noise
RCSwitch::nReceivedValue = code;
RCSwitch::nReceivedBitlength = (changeCount - 1) / 2;
RCSwitch::nReceivedDelay = delay;
RCSwitch::nReceivedProtocol = p;
}
return true;
}
void RECEIVE_ATTR RCSwitch::handleInterrupt() {
static unsigned int changeCount = 0;
static unsigned long lastTime = 0;
static unsigned int repeatCount = 0;
const long time = micros();
const unsigned int duration = time - lastTime;
if (duration > RCSwitch::nSeparationLimit) {
// A long stretch without signal level change occurred. This could
// be the gap between two transmission.
if (diff(duration, RCSwitch::timings[0]) < 200) {
// This long signal is close in length to the long signal which
// started the previously recorded timings; this suggests that
// it may indeed by a a gap between two transmissions (we assume
// here that a sender will send the signal multiple times,
// with roughly the same gap between them).
repeatCount++;
if (repeatCount == 2) {
for(unsigned int i = 1; i <= numProto; i++) {
if (receiveProtocol(i, changeCount)) {
// receive succeeded for protocol i
break;
}
}
repeatCount = 0;
}
}
changeCount = 0;
}
// detect overflow
if (changeCount >= RCSWITCH_MAX_CHANGES) {
changeCount = 0;
repeatCount = 0;
}
RCSwitch::timings[changeCount++] = duration;
lastTime = time;
}
#endif

154
RCSwitch/RCSwitch.h Normal file
View File

@ -0,0 +1,154 @@
/*
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat Özgür. All right reserved.
Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
- Dominik Fischer / dom_fischer(at)web(dot)de
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
Project home: https://github.com/sui77/rc-switch/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _RCSwitch_h
#define _RCSwitch_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#elif defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
#include "Energia.h"
#elif defined(RPI) // Raspberry Pi
#define RaspberryPi
// Include libraries for RPi:
#include <string.h> /* memcpy */
#include <stdlib.h> /* abs */
#include <wiringPi.h>
#else
#include "WProgram.h"
#endif
#include <stdint.h>
// At least for the ATTiny X4/X5, receiving has to be disabled due to
// missing libm depencies (udivmodhi4)
#if defined( __AVR_ATtinyX5__ ) or defined ( __AVR_ATtinyX4__ )
#define RCSwitchDisableReceiving
#endif
// Number of maximum High/Low changes per packet.
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
#define RCSWITCH_MAX_CHANGES 67
class RCSwitch {
public:
RCSwitch();
void switchOn(int nGroupNumber, int nSwitchNumber);
void switchOff(int nGroupNumber, int nSwitchNumber);
void switchOn(const char* sGroup, int nSwitchNumber);
void switchOff(const char* sGroup, int nSwitchNumber);
void switchOn(char sFamily, int nGroup, int nDevice);
void switchOff(char sFamily, int nGroup, int nDevice);
void switchOn(const char* sGroup, const char* sDevice);
void switchOff(const char* sGroup, const char* sDevice);
void switchOn(char sGroup, int nDevice);
void switchOff(char sGroup, int nDevice);
void sendTriState(const char* sCodeWord);
void send(unsigned long code, unsigned int length);
void send(const char* sCodeWord);
#if not defined( RCSwitchDisableReceiving )
void enableReceive(int interrupt);
void enableReceive();
void disableReceive();
bool available();
void resetAvailable();
unsigned long getReceivedValue();
unsigned int getReceivedBitlength();
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();
#endif
void enableTransmit(int nTransmitterPin);
void disableTransmit();
void setPulseLength(int nPulseLength);
void setRepeatTransmit(int nRepeatTransmit);
#if not defined( RCSwitchDisableReceiving )
void setReceiveTolerance(int nPercent);
#endif
struct HighLow {
uint8_t high;
uint8_t low;
};
struct Protocol {
int pulseLength;
HighLow syncFactor;
HighLow zero;
HighLow one;
/** @brief if true inverts the high and low logic levels in the HighLow structs */
bool invertedSignal;
};
void setProtocol(Protocol protocol);
void setProtocol(int nProtocol);
void setProtocol(int nProtocol, int nPulseLength);
private:
char* getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus);
char* getCodeWordB(int nGroupNumber, int nSwitchNumber, bool bStatus);
char* getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus);
char* getCodeWordD(char group, int nDevice, bool bStatus);
void transmit(HighLow pulses);
#if not defined( RCSwitchDisableReceiving )
static void handleInterrupt();
static bool receiveProtocol(const int p, unsigned int changeCount);
int nReceiverInterrupt;
#endif
int nTransmitterPin;
int nRepeatTransmit;
Protocol protocol;
#if not defined( RCSwitchDisableReceiving )
static int nReceiveTolerance;
static unsigned long nReceivedValue;
static unsigned int nReceivedBitlength;
static unsigned int nReceivedDelay;
static unsigned int nReceivedProtocol;
const static unsigned int nSeparationLimit;
/*
* timings[0] contains sync timing, followed by a number of bits
*/
static unsigned int timings[RCSWITCH_MAX_CHANGES];
#endif
};
#endif

201
SPI/SPI.cpp Normal file
View File

@ -0,0 +1,201 @@
/*
* Copyright (c) 2010 by Cristian Maglie <c.maglie@arduino.cc>
* Copyright (c) 2014 by Paul Stoffregen <paul@pjrc.com> (Transaction API)
* Copyright (c) 2014 by Matthijs Kooijman <matthijs@stdin.nl> (SPISettings AVR)
* Copyright (c) 2014 by Andrew J. Kroll <xxxajk@gmail.com> (atomicity fixes)
* SPI Master library for arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#include "SPI.h"
SPIClass SPI;
uint8_t SPIClass::initialized = 0;
uint8_t SPIClass::interruptMode = 0;
uint8_t SPIClass::interruptMask = 0;
uint8_t SPIClass::interruptSave = 0;
#ifdef SPI_TRANSACTION_MISMATCH_LED
uint8_t SPIClass::inTransactionFlag = 0;
#endif
void SPIClass::begin()
{
uint8_t sreg = SREG;
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
if (!initialized) {
// Set SS to high so a connected chip will be "deselected" by default
uint8_t port = digitalPinToPort(SS);
uint8_t bit = digitalPinToBitMask(SS);
volatile uint8_t *reg = portModeRegister(port);
// if the SS pin is not already configured as an output
// then set it high (to enable the internal pull-up resistor)
if(!(*reg & bit)){
digitalWrite(SS, HIGH);
}
// When the SS pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
pinMode(SS, OUTPUT);
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
// automatically switches to Slave, so the data direction of
// the SS pin MUST be kept as OUTPUT.
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
// Set direction register for SCK and MOSI pin.
// MISO pin automatically overrides to INPUT.
// By doing this AFTER enabling SPI, we avoid accidentally
// clocking in a single bit since the lines go directly
// from "input" to SPI control.
// http://code.google.com/p/arduino/issues/detail?id=888
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
}
initialized++; // reference count
SREG = sreg;
}
void SPIClass::end() {
uint8_t sreg = SREG;
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
// Decrease the reference counter
if (initialized)
initialized--;
// If there are no more references disable SPI
if (!initialized) {
SPCR &= ~_BV(SPE);
interruptMode = 0;
#ifdef SPI_TRANSACTION_MISMATCH_LED
inTransactionFlag = 0;
#endif
}
SREG = sreg;
}
// mapping of interrupt numbers to bits within SPI_AVR_EIMSK
#if defined(__AVR_ATmega32U4__)
#define SPI_INT0_MASK (1<<INT0)
#define SPI_INT1_MASK (1<<INT1)
#define SPI_INT2_MASK (1<<INT2)
#define SPI_INT3_MASK (1<<INT3)
#define SPI_INT4_MASK (1<<INT6)
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
#define SPI_INT0_MASK (1<<INT0)
#define SPI_INT1_MASK (1<<INT1)
#define SPI_INT2_MASK (1<<INT2)
#define SPI_INT3_MASK (1<<INT3)
#define SPI_INT4_MASK (1<<INT4)
#define SPI_INT5_MASK (1<<INT5)
#define SPI_INT6_MASK (1<<INT6)
#define SPI_INT7_MASK (1<<INT7)
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
#define SPI_INT0_MASK (1<<INT4)
#define SPI_INT1_MASK (1<<INT5)
#define SPI_INT2_MASK (1<<INT0)
#define SPI_INT3_MASK (1<<INT1)
#define SPI_INT4_MASK (1<<INT2)
#define SPI_INT5_MASK (1<<INT3)
#define SPI_INT6_MASK (1<<INT6)
#define SPI_INT7_MASK (1<<INT7)
#else
#ifdef INT0
#define SPI_INT0_MASK (1<<INT0)
#endif
#ifdef INT1
#define SPI_INT1_MASK (1<<INT1)
#endif
#ifdef INT2
#define SPI_INT2_MASK (1<<INT2)
#endif
#endif
void SPIClass::usingInterrupt(uint8_t interruptNumber)
{
uint8_t mask = 0;
uint8_t sreg = SREG;
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
switch (interruptNumber) {
#ifdef SPI_INT0_MASK
case 0: mask = SPI_INT0_MASK; break;
#endif
#ifdef SPI_INT1_MASK
case 1: mask = SPI_INT1_MASK; break;
#endif
#ifdef SPI_INT2_MASK
case 2: mask = SPI_INT2_MASK; break;
#endif
#ifdef SPI_INT3_MASK
case 3: mask = SPI_INT3_MASK; break;
#endif
#ifdef SPI_INT4_MASK
case 4: mask = SPI_INT4_MASK; break;
#endif
#ifdef SPI_INT5_MASK
case 5: mask = SPI_INT5_MASK; break;
#endif
#ifdef SPI_INT6_MASK
case 6: mask = SPI_INT6_MASK; break;
#endif
#ifdef SPI_INT7_MASK
case 7: mask = SPI_INT7_MASK; break;
#endif
default:
interruptMode = 2;
break;
}
interruptMask |= mask;
if (!interruptMode)
interruptMode = 1;
SREG = sreg;
}
void SPIClass::notUsingInterrupt(uint8_t interruptNumber)
{
// Once in mode 2 we can't go back to 0 without a proper reference count
if (interruptMode == 2)
return;
uint8_t mask = 0;
uint8_t sreg = SREG;
noInterrupts(); // Protect from a scheduler and prevent transactionBegin
switch (interruptNumber) {
#ifdef SPI_INT0_MASK
case 0: mask = SPI_INT0_MASK; break;
#endif
#ifdef SPI_INT1_MASK
case 1: mask = SPI_INT1_MASK; break;
#endif
#ifdef SPI_INT2_MASK
case 2: mask = SPI_INT2_MASK; break;
#endif
#ifdef SPI_INT3_MASK
case 3: mask = SPI_INT3_MASK; break;
#endif
#ifdef SPI_INT4_MASK
case 4: mask = SPI_INT4_MASK; break;
#endif
#ifdef SPI_INT5_MASK
case 5: mask = SPI_INT5_MASK; break;
#endif
#ifdef SPI_INT6_MASK
case 6: mask = SPI_INT6_MASK; break;
#endif
#ifdef SPI_INT7_MASK
case 7: mask = SPI_INT7_MASK; break;
#endif
default:
break;
// this case can't be reached
}
interruptMask &= ~mask;
if (!interruptMask)
interruptMode = 0;
SREG = sreg;
}

324
SPI/SPI.h Normal file
View File

@ -0,0 +1,324 @@
/*
* Copyright (c) 2010 by Cristian Maglie <c.maglie@arduino.cc>
* Copyright (c) 2014 by Paul Stoffregen <paul@pjrc.com> (Transaction API)
* Copyright (c) 2014 by Matthijs Kooijman <matthijs@stdin.nl> (SPISettings AVR)
* Copyright (c) 2014 by Andrew J. Kroll <xxxajk@gmail.com> (atomicity fixes)
* SPI Master library for arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#ifndef _SPI_H_INCLUDED
#define _SPI_H_INCLUDED
#include <Arduino.h>
// SPI_HAS_TRANSACTION means SPI has beginTransaction(), endTransaction(),
// usingInterrupt(), and SPISetting(clock, bitOrder, dataMode)
#define SPI_HAS_TRANSACTION 1
// SPI_HAS_NOTUSINGINTERRUPT means that SPI has notUsingInterrupt() method
#define SPI_HAS_NOTUSINGINTERRUPT 1
// SPI_ATOMIC_VERSION means that SPI has atomicity fixes and what version.
// This way when there is a bug fix you can check this define to alert users
// of your code if it uses better version of this library.
// This also implies everything that SPI_HAS_TRANSACTION as documented above is
// available too.
#define SPI_ATOMIC_VERSION 1
// Uncomment this line to add detection of mismatched begin/end transactions.
// A mismatch occurs if other libraries fail to use SPI.endTransaction() for
// each SPI.beginTransaction(). Connect an LED to this pin. The LED will turn
// on if any mismatch is ever detected.
//#define SPI_TRANSACTION_MISMATCH_LED 5
#ifndef LSBFIRST
#define LSBFIRST 0
#endif
#ifndef MSBFIRST
#define MSBFIRST 1
#endif
#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
// define SPI_AVR_EIMSK for AVR boards with external interrupt pins
#if defined(EIMSK)
#define SPI_AVR_EIMSK EIMSK
#elif defined(GICR)
#define SPI_AVR_EIMSK GICR
#elif defined(GIMSK)
#define SPI_AVR_EIMSK GIMSK
#endif
class SPISettings {
public:
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) {
if (__builtin_constant_p(clock)) {
init_AlwaysInline(clock, bitOrder, dataMode);
} else {
init_MightInline(clock, bitOrder, dataMode);
}
}
SPISettings() {
init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0);
}
private:
void init_MightInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) {
init_AlwaysInline(clock, bitOrder, dataMode);
}
void init_AlwaysInline(uint32_t clock, uint8_t bitOrder, uint8_t dataMode)
__attribute__((__always_inline__)) {
// Clock settings are defined as follows. Note that this shows SPI2X
// inverted, so the bits form increasing numbers. Also note that
// fosc/64 appears twice
// SPR1 SPR0 ~SPI2X Freq
// 0 0 0 fosc/2
// 0 0 1 fosc/4
// 0 1 0 fosc/8
// 0 1 1 fosc/16
// 1 0 0 fosc/32
// 1 0 1 fosc/64
// 1 1 0 fosc/64
// 1 1 1 fosc/128
// We find the fastest clock that is less than or equal to the
// given clock rate. The clock divider that results in clock_setting
// is 2 ^^ (clock_div + 1). If nothing is slow enough, we'll use the
// slowest (128 == 2 ^^ 7, so clock_div = 6).
uint8_t clockDiv;
// When the clock is known at compiletime, use this if-then-else
// cascade, which the compiler knows how to completely optimize
// away. When clock is not known, use a loop instead, which generates
// shorter code.
if (__builtin_constant_p(clock)) {
if (clock >= F_CPU / 2) {
clockDiv = 0;
} else if (clock >= F_CPU / 4) {
clockDiv = 1;
} else if (clock >= F_CPU / 8) {
clockDiv = 2;
} else if (clock >= F_CPU / 16) {
clockDiv = 3;
} else if (clock >= F_CPU / 32) {
clockDiv = 4;
} else if (clock >= F_CPU / 64) {
clockDiv = 5;
} else {
clockDiv = 6;
}
} else {
uint32_t clockSetting = F_CPU / 2;
clockDiv = 0;
while (clockDiv < 6 && clock < clockSetting) {
clockSetting /= 2;
clockDiv++;
}
}
// Compensate for the duplicate fosc/64
if (clockDiv == 6)
clockDiv = 7;
// Invert the SPI2X bit
clockDiv ^= 0x1;
// Pack into the SPISettings class
spcr = _BV(SPE) | _BV(MSTR) | ((bitOrder == LSBFIRST) ? _BV(DORD) : 0) |
(dataMode & SPI_MODE_MASK) | ((clockDiv >> 1) & SPI_CLOCK_MASK);
spsr = clockDiv & SPI_2XCLOCK_MASK;
}
uint8_t spcr;
uint8_t spsr;
friend class SPIClass;
};
class SPIClass {
public:
// Initialize the SPI library
static void begin();
// If SPI is used from within an interrupt, this function registers
// that interrupt with the SPI library, so beginTransaction() can
// prevent conflicts. The input interruptNumber is the number used
// with attachInterrupt. If SPI is used from a different interrupt
// (eg, a timer), interruptNumber should be 255.
static void usingInterrupt(uint8_t interruptNumber);
// And this does the opposite.
static void notUsingInterrupt(uint8_t interruptNumber);
// Note: the usingInterrupt and notUsingInterrupt functions should
// not to be called from ISR context or inside a transaction.
// For details see:
// https://github.com/arduino/Arduino/pull/2381
// https://github.com/arduino/Arduino/pull/2449
// Before using SPI.transfer() or asserting chip select pins,
// this function is used to gain exclusive access to the SPI bus
// and configure the correct settings.
inline static void beginTransaction(SPISettings settings) {
if (interruptMode > 0) {
uint8_t sreg = SREG;
noInterrupts();
#ifdef SPI_AVR_EIMSK
if (interruptMode == 1) {
interruptSave = SPI_AVR_EIMSK;
SPI_AVR_EIMSK &= ~interruptMask;
SREG = sreg;
} else
#endif
{
interruptSave = sreg;
}
}
#ifdef SPI_TRANSACTION_MISMATCH_LED
if (inTransactionFlag) {
pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT);
digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH);
}
inTransactionFlag = 1;
#endif
SPCR = settings.spcr;
SPSR = settings.spsr;
}
// Write to the SPI bus (MOSI pin) and also receive (MISO pin)
inline static uint8_t transfer(uint8_t data) {
SPDR = data;
/*
* The following NOP introduces a small delay that can prevent the wait
* loop form iterating when running at the maximum speed. This gives
* about 10% more speed, even if it seems counter-intuitive. At lower
* speeds it is unnoticed.
*/
asm volatile("nop");
while (!(SPSR & _BV(SPIF))) ; // wait
return SPDR;
}
inline static uint16_t transfer16(uint16_t data) {
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out;
in.val = data;
if (!(SPCR & _BV(DORD))) {
SPDR = in.msb;
asm volatile("nop"); // See transfer(uint8_t) function
while (!(SPSR & _BV(SPIF))) ;
out.msb = SPDR;
SPDR = in.lsb;
asm volatile("nop");
while (!(SPSR & _BV(SPIF))) ;
out.lsb = SPDR;
} else {
SPDR = in.lsb;
asm volatile("nop");
while (!(SPSR & _BV(SPIF))) ;
out.lsb = SPDR;
SPDR = in.msb;
asm volatile("nop");
while (!(SPSR & _BV(SPIF))) ;
out.msb = SPDR;
}
return out.val;
}
inline static void transfer(void *buf, size_t count) {
if (count == 0) return;
uint8_t *p = (uint8_t *)buf;
SPDR = *p;
while (--count > 0) {
uint8_t out = *(p + 1);
while (!(SPSR & _BV(SPIF))) ;
uint8_t in = SPDR;
SPDR = out;
*p++ = in;
}
while (!(SPSR & _BV(SPIF))) ;
*p = SPDR;
}
// After performing a group of transfers and releasing the chip select
// signal, this function allows others to access the SPI bus
inline static void endTransaction(void) {
#ifdef SPI_TRANSACTION_MISMATCH_LED
if (!inTransactionFlag) {
pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT);
digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH);
}
inTransactionFlag = 0;
#endif
if (interruptMode > 0) {
#ifdef SPI_AVR_EIMSK
uint8_t sreg = SREG;
#endif
noInterrupts();
#ifdef SPI_AVR_EIMSK
if (interruptMode == 1) {
SPI_AVR_EIMSK = interruptSave;
SREG = sreg;
} else
#endif
{
SREG = interruptSave;
}
}
}
// Disable the SPI bus
static void end();
// This function is deprecated. New applications should use
// beginTransaction() to configure SPI settings.
inline static void setBitOrder(uint8_t bitOrder) {
if (bitOrder == LSBFIRST) SPCR |= _BV(DORD);
else SPCR &= ~(_BV(DORD));
}
// This function is deprecated. New applications should use
// beginTransaction() to configure SPI settings.
inline static void setDataMode(uint8_t dataMode) {
SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode;
}
// This function is deprecated. New applications should use
// beginTransaction() to configure SPI settings.
inline static void setClockDivider(uint8_t clockDiv) {
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (clockDiv & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK);
}
// These undocumented functions should not be used. SPI.transfer()
// polls the hardware flag which is automatically cleared as the
// AVR responds to SPI's interrupt
inline static void attachInterrupt() { SPCR |= _BV(SPIE); }
inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); }
private:
static uint8_t initialized;
static uint8_t interruptMode; // 0=none, 1=mask, 2=global
static uint8_t interruptMask; // which interrupts to mask
static uint8_t interruptSave; // temp storage, to restore state
#ifdef SPI_TRANSACTION_MISMATCH_LED
static uint8_t inTransactionFlag;
#endif
};
extern SPIClass SPI;
#endif

105
Streaming/Streaming.h Normal file
View File

@ -0,0 +1,105 @@
/*
Streaming.h - Arduino library for supporting the << streaming operator
Copyright (c) 2010-2012 Mikal Hart. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ARDUINO_STREAMING
#define ARDUINO_STREAMING
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define STREAMING_LIBRARY_VERSION 5
// Generic template
template<class T>
inline Print &operator <<(Print &stream, T arg)
{ stream.print(arg); return stream; }
struct _BASED
{
long val;
int base;
_BASED(long v, int b): val(v), base(b)
{}
};
#if ARDUINO >= 100
struct _BYTE_CODE
{
byte val;
_BYTE_CODE(byte v) : val(v)
{}
};
#define _BYTE(a) _BYTE_CODE(a)
inline Print &operator <<(Print &obj, const _BYTE_CODE &arg)
{ obj.write(arg.val); return obj; }
#else
#define _BYTE(a) _BASED(a, BYTE)
#endif
#define _HEX(a) _BASED(a, HEX)
#define _DEC(a) _BASED(a, DEC)
#define _OCT(a) _BASED(a, OCT)
#define _BIN(a) _BASED(a, BIN)
// Specialization for class _BASED
// Thanks to Arduino forum user Ben Combee who suggested this
// clever technique to allow for expressions like
// Serial << _HEX(a);
inline Print &operator <<(Print &obj, const _BASED &arg)
{ obj.print(arg.val, arg.base); return obj; }
#if ARDUINO >= 18
// Specialization for class _FLOAT
// Thanks to Michael Margolis for suggesting a way
// to accommodate Arduino 0018's floating point precision
// feature like this:
// Serial << _FLOAT(gps_latitude, 6); // 6 digits of precision
struct _FLOAT
{
float val;
int digits;
_FLOAT(double v, int d): val(v), digits(d)
{}
};
inline Print &operator <<(Print &obj, const _FLOAT &arg)
{ obj.print(arg.val, arg.digits); return obj; }
#endif
// Specialization for enum _EndLineCode
// Thanks to Arduino forum user Paul V. who suggested this
// clever technique to allow for expressions like
// Serial << "Hello!" << endl;
enum _EndLineCode { endl };
inline Print &operator <<(Print &obj, _EndLineCode arg)
{ obj.println(); return obj; }
#endif

154
mqttclient.cpp Normal file
View File

@ -0,0 +1,154 @@
/*
* mqttclient.cpp
*
* Created on: 03.03.2016
* Author: wn
*/
#include <stdlib.h>
#include "mqttclient.h"
#include <avr/wdt.h>
#include <Streaming.h>
#include <Ethernet.h>
#include <Metro.h>
#include <PubSubClient.h>
#include <stdio.h>
#include "s433client.h"
static const char MESSAGE_TOPIC[] = "IoT/Mqtt433Gateway/Message";
static const char WATCHDOG_TOPIC[] = "IoT/Watchdog";
void callback(char* topic, byte* payload, unsigned int length);
static uint8_t MAC[] = { 0x90, 0xA2, 0xDA, 0x00, 0x51, 0x0A };
const static char BROKER[] = "mqttbroker";
EthernetClient client;
PubSubClient mqttClient = PubSubClient(BROKER, 1883, callback, client);
uint8_t disconnectState = 0;
uint32_t disconnectTime = 0;
Metro minute = Metro(60000);
Metro second = Metro(1000);
uint32_t uptime;
void callback(char* topic, byte* payload, unsigned int length) {
const uint8_t BUFSIZE = 128;
if ((length + 1) >= BUFSIZE) { // 1 for terminating NUL
// Serial << "Received message too long, ignore it" << endl;
} else {
char buffer[BUFSIZE];
memcpy(buffer, payload, length);
*(buffer + length) = 0;
Serial << "Received message: " << length << ", " << String(topic) << ", " << String(buffer) << endl;
// 123454 24 1
// ^^^^^^ Message
// ^^ Length
// ^ Protocol
if (!(strcmp(topic, MESSAGE_TOPIC))) {
char *paramPtr = buffer;
Serial << paramPtr << endl;
uint32_t s433Message;
uint8_t s433Length;
uint8_t s433Protocol;
int8_t done = 0;
if ((paramPtr != 0) && (*paramPtr != 0)) {
char *dataPtr = strsep(&paramPtr, " ");
s433Message = strtol(dataPtr, NULL, 10);
done++;
}
if ((paramPtr != 0) && (*paramPtr != 0)) {
char *dataPtr = strsep(&paramPtr, " ");
s433Length = strtol(dataPtr, NULL, 10);
done++;
}
if ((paramPtr != 0) && (*paramPtr != 0)) {
char *dataPtr = strsep(&paramPtr, " ");
s433Protocol = strtol(dataPtr, NULL, 10);
done++;
}
if (done == 3) {
Serial << "complete message received" << endl;
Serial << "Message: " << s433Message << endl;
Serial << "Length: " << (uint16_t)s433Length << endl;
Serial << "Protocol: " << (uint16_t)s433Protocol << endl;;
s433ClientNS::sendMessage(s433Message, s433Length, s433Protocol);
} else if (done == -1) {
Serial << "error while evaluating message" << endl;
}
} else if (!strcmp(topic, WATCHDOG_TOPIC)) {
wdt_reset();
} else {
Serial << "Strange, unknown topic received" << endl;
}
}
}
void MqttClientNS::begin() {
Ethernet.begin(MAC);
Serial << "Got IP address: " << Ethernet.localIP() << endl;
disconnectState = 3;
disconnectTime = millis();
}
void MqttClientNS::exec() {
if ((disconnectState == 0) && (! mqttClient.loop())) {
disconnectState = 1;
}
switch (disconnectState) {
case 0:
// Serial.println("discState 0");
// everything fine
break;
case 1:
// Serial.println("discState 1");
mqttClient.disconnect();
disconnectTime = millis();
disconnectState = 2;
break;
case 2:
// Serial.println("discState 3");
if (disconnectTime + 2000 < millis()) {
disconnectState = 3;
}
break;
case 3:
// Serial.println("discState 3");
if (mqttClient.connect("Monitor")) {
mqttClient.subscribe(MESSAGE_TOPIC);
mqttClient.subscribe(WATCHDOG_TOPIC);
disconnectTime = millis();
mqttClient.publish("IoT/Mqtt433Gateway/Started", "Mqtt433Gateway started");
disconnectState = 0;
} else {
disconnectState = 1;
}
break;
default:
disconnectState = 0;
break;
}
if (second.check() == 1) {
uptime++;
// Serial.println("mqtt tick");
if (disconnectState == 0) {
String msg = String("{ \"metadata\": { \"device\": \"Mqtt433Gateway\" }, \"data\": { \"uptime\": ") + uptime + String("}}");
mqttClient.publish("IoT/Mqtt433Gateway/Heartbeat", (char*)msg.c_str());
}
}
}

19
mqttclient.h Normal file
View File

@ -0,0 +1,19 @@
/*
* mqttclient.h
*
* Created on: 03.03.2016
* Author: wn
*/
#ifndef MQTTCLIENT_H_
#define MQTTCLIENT_H_
#include <stdint.h>
namespace MqttClientNS {
void begin();
void exec();
};
#endif /* MQTTCLIENT_H_ */

31
s433client.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
* canclient.cpp
*
* Created on: Oct 31, 2016
* Author: wn
*/
#include "s433client.h"
#include <Streaming.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void s433ClientNS::begin() {
mySwitch.enableTransmit(10);
}
void s433ClientNS::exec() {
}
void s433ClientNS::sendMessage(uint32_t message, uint8_t length, uint8_t protocol) {
mySwitch.setProtocol(protocol);
mySwitch.send(message, length);
}

21
s433client.h Normal file
View File

@ -0,0 +1,21 @@
/*
* canclient.h
*
* Created on: Oct 31, 2016
* Author: wn
*/
#ifndef S433CLIENT_H_
#define S433CLIENT_H_
#include <stdint.h>
namespace s433ClientNS {
void begin();
void exec();
void sendMessage(uint32_t message, uint8_t length, uint8_t protocol);
};
#endif /* S433CLIENT_H_ */