├── README.md ├── build ├── dfu.js ├── doit └── makefile ├── core-common-lib ├── .gitignore ├── CC3000_Host_Driver │ ├── build.mk │ ├── cc3000_common.c │ ├── cc3000_common.h │ ├── evnt_handler.c │ ├── evnt_handler.h │ ├── hci.c │ ├── hci.h │ ├── host_driver_version.h │ ├── netapp.c │ ├── netapp.h │ ├── nvmem.c │ ├── nvmem.h │ ├── security.c │ ├── security.h │ ├── socket.c │ ├── socket.h │ ├── wlan.c │ └── wlan.h ├── CMSIS │ ├── Device │ │ └── ST │ │ │ └── STM32F10x │ │ │ └── Include │ │ │ ├── stm32f10x.h │ │ │ └── system_stm32f10x.h │ └── Include │ │ ├── arm_common_tables.h │ │ ├── arm_math.h │ │ ├── core_cm3.h │ │ ├── core_cmFunc.h │ │ └── core_cmInstr.h ├── README.md ├── SPARK_Firmware_Driver │ ├── inc │ │ ├── cc3000_spi.h │ │ ├── config.h │ │ ├── debug.h │ │ ├── hw_config.h │ │ ├── panic.h │ │ ├── panic_codes.h │ │ ├── platform_config.h │ │ ├── spark_macros.h │ │ ├── spi.h │ │ ├── sst25vf_spi.h │ │ ├── stm32f10x_conf.h │ │ └── usb_pwr.h │ └── src │ │ ├── build.mk │ │ ├── cc3000_spi.c │ │ ├── debug.c │ │ ├── hw_config.c │ │ ├── panic.c │ │ ├── sst25vf_spi.c │ │ ├── system_stm32f10x.c │ │ └── usb_pwr.c ├── STM32F10x_StdPeriph_Driver │ ├── inc │ │ ├── misc.h │ │ ├── stm32f10x_adc.h │ │ ├── stm32f10x_bkp.h │ │ ├── stm32f10x_can.h │ │ ├── stm32f10x_cec.h │ │ ├── stm32f10x_crc.h │ │ ├── stm32f10x_dac.h │ │ ├── stm32f10x_dbgmcu.h │ │ ├── stm32f10x_dma.h │ │ ├── stm32f10x_exti.h │ │ ├── stm32f10x_flash.h │ │ ├── stm32f10x_fsmc.h │ │ ├── stm32f10x_gpio.h │ │ ├── stm32f10x_i2c.h │ │ ├── stm32f10x_iwdg.h │ │ ├── stm32f10x_pwr.h │ │ ├── stm32f10x_rcc.h │ │ ├── stm32f10x_rtc.h │ │ ├── stm32f10x_sdio.h │ │ ├── stm32f10x_spi.h │ │ ├── stm32f10x_tim.h │ │ ├── stm32f10x_usart.h │ │ └── stm32f10x_wwdg.h │ └── src │ │ ├── build.mk │ │ ├── misc.c │ │ ├── stm32f10x_adc.c │ │ ├── stm32f10x_bkp.c │ │ ├── stm32f10x_can.c │ │ ├── stm32f10x_cec.c │ │ ├── stm32f10x_crc.c │ │ ├── stm32f10x_dac.c │ │ ├── stm32f10x_dbgmcu.c │ │ ├── stm32f10x_dma.c │ │ ├── stm32f10x_exti.c │ │ ├── stm32f10x_flash.c │ │ ├── stm32f10x_fsmc.c │ │ ├── stm32f10x_gpio.c │ │ ├── stm32f10x_i2c.c │ │ ├── stm32f10x_iwdg.c │ │ ├── stm32f10x_pwr.c │ │ ├── stm32f10x_rcc.c │ │ ├── stm32f10x_rtc.c │ │ ├── stm32f10x_sdio.c │ │ ├── stm32f10x_spi.c │ │ ├── stm32f10x_tim.c │ │ ├── stm32f10x_usart.c │ │ └── stm32f10x_wwdg.c ├── STM32_USB-FS-Device_Driver │ ├── inc │ │ ├── usb_core.h │ │ ├── usb_def.h │ │ ├── usb_init.h │ │ ├── usb_int.h │ │ ├── usb_lib.h │ │ ├── usb_mem.h │ │ ├── usb_regs.h │ │ ├── usb_sil.h │ │ └── usb_type.h │ └── src │ │ ├── build.mk │ │ ├── usb_core.c │ │ ├── usb_init.c │ │ ├── usb_int.c │ │ ├── usb_mem.c │ │ ├── usb_regs.c │ │ └── usb_sil.c ├── build │ ├── .gitignore │ └── makefile └── license.txt ├── core-communication-lib ├── .gitignore ├── Makefile ├── README.md ├── build │ ├── .gitignore │ └── makefile ├── lib │ └── tropicssl │ │ ├── include │ │ └── tropicssl │ │ │ ├── aes.h │ │ │ ├── bignum.h │ │ │ ├── bn_mul.h │ │ │ ├── config.h │ │ │ ├── padlock.h │ │ │ ├── rsa.h │ │ │ └── sha1.h │ │ └── library │ │ ├── Makefile │ │ ├── aes.c │ │ ├── bignum.c │ │ ├── build.mk │ │ ├── padlock.c │ │ ├── rsa.c │ │ └── sha1.c ├── license.txt ├── src │ ├── build.mk │ ├── coap.cpp │ ├── coap.h │ ├── events.cpp │ ├── events.h │ ├── handshake.cpp │ ├── handshake.h │ ├── spark_descriptor.h │ ├── spark_protocol.cpp │ └── spark_protocol.h └── tests │ ├── ConstructorFixture.cpp │ ├── ConstructorFixture.h │ ├── Main.cpp │ ├── TestAES.cpp │ ├── TestCoAP.cpp │ ├── TestDescriptor.cpp │ ├── TestEvents.cpp │ ├── TestHandshake.cpp │ ├── TestQueue.cpp │ ├── TestSparkProtocol.cpp │ ├── TestStateMachine.cpp │ ├── TestUserFunctions.cpp │ └── UnitTest++ │ ├── Makefile │ └── src │ ├── AssertException.cpp │ ├── AssertException.h │ ├── CheckMacros.h │ ├── Checks.cpp │ ├── Checks.h │ ├── Config.h │ ├── CurrentTest.cpp │ ├── CurrentTest.h │ ├── DeferredTestReporter.cpp │ ├── DeferredTestReporter.h │ ├── DeferredTestResult.cpp │ ├── DeferredTestResult.h │ ├── ExecuteTest.h │ ├── MemoryOutStream.cpp │ ├── MemoryOutStream.h │ ├── Posix │ ├── SignalTranslator.cpp │ ├── SignalTranslator.h │ ├── TimeHelpers.cpp │ └── TimeHelpers.h │ ├── ReportAssert.cpp │ ├── ReportAssert.h │ ├── Test.cpp │ ├── Test.h │ ├── TestDetails.cpp │ ├── TestDetails.h │ ├── TestList.cpp │ ├── TestList.h │ ├── TestMacros.h │ ├── TestReporter.cpp │ ├── TestReporter.h │ ├── TestReporterStdout.cpp │ ├── TestReporterStdout.h │ ├── TestResults.cpp │ ├── TestResults.h │ ├── TestRunner.cpp │ ├── TestRunner.h │ ├── TestSuite.h │ ├── TimeConstraint.cpp │ ├── TimeConstraint.h │ ├── TimeHelpers.h │ ├── UnitTest++.h │ ├── Win32 │ ├── TimeHelpers.cpp │ └── TimeHelpers.h │ ├── XmlTestReporter.cpp │ └── XmlTestReporter.h ├── core-firmware ├── .gitignore ├── README.md ├── build │ ├── .gitignore │ ├── dfu.js │ ├── doit │ ├── html │ │ ├── bed.html │ │ └── jquery-mobile │ └── makefile ├── inc │ ├── Base64.h │ ├── SparkWebSocketServer.h │ ├── application.h │ ├── main.h │ ├── spark_disable_cloud.h │ ├── spark_disable_wlan.h │ ├── spark_utilities.h │ ├── spark_wiring.h │ ├── spark_wiring_i2c.h │ ├── spark_wiring_interrupts.h │ ├── spark_wiring_ipaddress.h │ ├── spark_wiring_network.h │ ├── spark_wiring_print.h │ ├── spark_wiring_printable.h │ ├── spark_wiring_servo.h │ ├── spark_wiring_spi.h │ ├── spark_wiring_stream.h │ ├── spark_wiring_string.h │ ├── spark_wiring_tcpclient.h │ ├── spark_wiring_tcpserver.h │ ├── spark_wiring_time.h │ ├── spark_wiring_udp.h │ ├── spark_wiring_usartserial.h │ ├── spark_wiring_usbserial.h │ ├── spark_wiring_wifi.h │ ├── spark_wlan.h │ ├── stm32_it.h │ ├── usb_conf.h │ ├── usb_desc.h │ ├── usb_istr.h │ ├── usb_prop.h │ └── wifi_credentials_reader.h ├── license.txt ├── linker │ ├── linker_stm32f10x_md.ld │ └── linker_stm32f10x_md_dfu.ld ├── src │ ├── ADXL335.cpp │ ├── ADXL335.h │ ├── Base64.cpp │ ├── Base64.h │ ├── Bed.cpp │ ├── Bed.h │ ├── MD5.h │ ├── SparkWebSocketServer.cpp │ ├── SparkWebSocketServer.h │ ├── application.cpp │ ├── application.cpp-tinker │ ├── build.mk │ ├── build.mk~ │ ├── main.cpp │ ├── newlib_stubs.cpp │ ├── spark_utilities.cpp │ ├── spark_wiring.cpp │ ├── spark_wiring_i2c.cpp │ ├── spark_wiring_interrupts.cpp │ ├── spark_wiring_ipaddress.cpp │ ├── spark_wiring_network.cpp │ ├── spark_wiring_print.cpp │ ├── spark_wiring_servo.cpp │ ├── spark_wiring_spi.cpp │ ├── spark_wiring_stream.cpp │ ├── spark_wiring_string.cpp │ ├── spark_wiring_tcpclient.cpp │ ├── spark_wiring_tcpserver.cpp │ ├── spark_wiring_time.cpp │ ├── spark_wiring_udp.cpp │ ├── spark_wiring_usartserial.cpp │ ├── spark_wiring_usbserial.cpp │ ├── spark_wiring_wifi.cpp │ ├── spark_wlan.cpp │ ├── stm32_it.cpp │ ├── usb_desc.cpp │ ├── usb_endp.cpp │ ├── usb_istr.cpp │ ├── usb_prop.cpp │ └── wifi_credentials_reader.cpp └── startup │ ├── build.mk │ └── startup_stm32f10x_md.S ├── example ├── application.cpp ├── html-tinker.mp4 └── tinker.js ├── html └── spark │ ├── css │ └── html5reset.css │ ├── imgs │ ├── spark-small.png │ └── spark.png │ ├── index.html │ └── js │ ├── jcanvas.min.js │ ├── jquery-1.11.0.min.js │ ├── tinker.js │ └── tinker.js~ ├── inc ├── Base64.h ├── SparkWebSocketServer.h ├── spark_wiring_tcpclient.h └── spark_wiring_tcpserver.h └── src ├── Base64.cpp ├── SparkWebSocketServer.cpp ├── application.cpp ├── build.mk ├── spark_wiring_tcpclient.cpp └── spark_wiring_tcpserver.cpp /README.md: -------------------------------------------------------------------------------- 1 | Simple "local" (cloud disabled) websocket server implementation for the sparkcoe (https://www.spark.io/) ported from https://github.com/brandenhall/Arduino-Websocket.git. 2 | The server, by default handles up-to 4 simultaneous clients. 3 | 4 | In the demo below, On the right, html5 +WebSocket that is connected to a sparkcore, on the left you see the serial output from the core. You can change the state of the digital pins by clicking on the pins, clicking on the analog pins will read the analog values. 5 | 6 | 7 | 8 | [![ScreenShot](https://i1.ytimg.com/vi/B886_m16s6s/1.jpg?time=1399011012908)](https://www.youtube.com/watch?v=B886_m16s6s&feature=youtu.be) 9 | 10 | 11 | NOTE, I have only tested this with local builds, so try it with sparkulator on your own risk :). 12 | 13 | To build, simply run make in core-firmware/build. 14 | 15 | The applicaiton.cpp is a simplified version of the tinker firmware that I used for my testing and currently can handle: digitalread, digitalwrite, analogread and analogwrite. When I get a chance I will add something like Spark.publish... 16 | applicaiton.cpp requires Serial connection, the core will halt the execution in the setup (the RGB led will flash blue, green and pink) until the serial communication is established. 17 | 18 | example syntax to how communicate with tinker firmware 19 | 20 | /digitalwrite?D3=HIGH 21 | /digitalread?D3 22 | 23 | If you develop on Linux and if you have nodejs installed read on. 24 | After flashing the core for the first time with, you can use "doit" in the core-firmware/build folder, "doit" will put the core in the dfu mode, compile, and flash the core again. 25 | 26 | tinker.js in the example folder can be used for demo and or testing, currently it has loop that will turn on/off the first four digital outputs on the core. 27 | Note you have to change the : in the tinker.js 28 | 29 | 30 | -------------------------------------------------------------------------------- /build/dfu.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #EXPRESS OR 4 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #MERCHANTABILITY, 5 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO #EVENT SHALL THE 6 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR #OTHER 7 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #ARISING FROM, 8 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #DEALINGS IN 9 | * THE SOFTWARE. 10 | * Copyright (c) 2014 NaAl (h20@alocreative.com) 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | */ 21 | var WebSocket = require('ws') 22 | , ws = new WebSocket('ws://:PORT'); 23 | ws.on('open', function() { 24 | ws.send('/dfu'); 25 | }); 26 | ws.on('message', function(message) { 27 | console.log('received: %s', message); 28 | if(message == "going to dfu mode") { 29 | setInterval(function() { 30 | process.exit(0); 31 | }, 3000); 32 | } 33 | 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /build/doit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ###################################################################################### 3 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #EXPRESS OR 4 | #MPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #MERCHANTABILITY, 5 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO #EVENT SHALL THE 6 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR #OTHER 7 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #ARISING FROM, 8 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #DEALINGS IN 9 | #THE SOFTWARE. 10 | #Copyright (c) 2014 NaAl (h20@alocreative.com) 11 | #Permission is hereby granted, free of charge, to any person obtaining a copy 12 | #of this software and associated documentation files (the "Software"), to deal 13 | #in the Software without restriction, including without limitation the rights 14 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | #copies of the Software, and to permit persons to whom the Software is 16 | #furnished to do so, subject to the following conditions: 17 | 18 | #The above copyright notice and this permission notice shall be included in 19 | #all copies or substantial portions of the Software. 20 | ###################################################################################### 21 | nodejs dfu.js 22 | echo "make $*" 23 | make $* 24 | if [ "$?" == "0" ]; then 25 | sudo dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin 26 | fi 27 | -------------------------------------------------------------------------------- /core-common-lib/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | # Debug folder 20 | Debug/* 21 | 22 | # Release folder 23 | Release/* 24 | 25 | # build folder 26 | *.map 27 | *.lst 28 | *.d 29 | *.o 30 | 31 | # Platform-specific settings 32 | .settings/* 33 | .cproject 34 | .project 35 | -------------------------------------------------------------------------------- /core-common-lib/CC3000_Host_Driver/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_CC3000_PATH = CC3000_Host_Driver 8 | 9 | # Add tropicssl include to all objects built for this target 10 | INCLUDE_DIRS += $(TARGET_CC3000_PATH) 11 | 12 | # C source files included in this build. 13 | CSRC += $(TARGET_CC3000_PATH)/cc3000_common.c 14 | CSRC += $(TARGET_CC3000_PATH)/evnt_handler.c 15 | CSRC += $(TARGET_CC3000_PATH)/hci.c 16 | CSRC += $(TARGET_CC3000_PATH)/netapp.c 17 | CSRC += $(TARGET_CC3000_PATH)/nvmem.c 18 | CSRC += $(TARGET_CC3000_PATH)/security.c 19 | CSRC += $(TARGET_CC3000_PATH)/socket.c 20 | CSRC += $(TARGET_CC3000_PATH)/wlan.c 21 | 22 | # C++ source files included in this build. 23 | CPPSRC += 24 | 25 | # ASM source files included in this build. 26 | ASRC += 27 | 28 | -------------------------------------------------------------------------------- /core-common-lib/CC3000_Host_Driver/host_driver_version.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * host_driver_version.h - CC3000 Host Driver Implementation. 4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * Neither the name of Texas Instruments Incorporated nor the names of 19 | * its contributors may be used to endorse or promote products derived 20 | * from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | *****************************************************************************/ 35 | #ifndef __HOST_DRIVER_VERSION_H__ 36 | #define __HOST_DRIVER_VERSION_H__ 37 | 38 | #define DRIVER_VERSION_NUMBER 14 39 | 40 | 41 | 42 | #endif // __VERSION_H__ 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /core-common-lib/CMSIS/Device/ST/STM32F10x/Include/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | Released into the public domain. 4 | This work is free: you can redistribute it and/or modify it under the terms of 5 | Creative Commons Zero license v1.0 6 | 7 | This work is licensed under the Creative Commons Zero 1.0 United States License. 8 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 9 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 10 | California, 94105, USA. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. 15 | ****************************************************************************** 16 | */ 17 | 18 | 19 | /** @addtogroup CMSIS 20 | * @{ 21 | */ 22 | 23 | /** @addtogroup stm32f10x_system 24 | * @{ 25 | */ 26 | 27 | /** 28 | * @brief Define to prevent recursive inclusion 29 | */ 30 | #ifndef __SYSTEM_STM32F10X_H 31 | #define __SYSTEM_STM32F10X_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** @addtogroup STM32F10x_System_Includes 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | 46 | /** @addtogroup STM32F10x_System_Exported_types 47 | * @{ 48 | */ 49 | 50 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @addtogroup STM32F10x_System_Exported_Constants 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @addtogroup STM32F10x_System_Exported_Macros 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @addtogroup STM32F10x_System_Exported_Functions 73 | * @{ 74 | */ 75 | 76 | extern void SystemInit(void); 77 | extern void SystemCoreClockUpdate(void); 78 | /** 79 | * @} 80 | */ 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif /*__SYSTEM_STM32F10X_H */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | -------------------------------------------------------------------------------- /core-common-lib/CMSIS/Include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 11. November 2010 5 | * $Revision: V1.0.2 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Version 1.0.2 2010/11/11 15 | * Documentation updated. 16 | * 17 | * Version 1.0.1 2010/10/05 18 | * Production release and review comments incorporated. 19 | * 20 | * Version 1.0.0 2010/09/20 21 | * Production release and review comments incorporated. 22 | * -------------------------------------------------------------------- */ 23 | 24 | #ifndef _ARM_COMMON_TABLES_H 25 | #define _ARM_COMMON_TABLES_H 26 | 27 | #include "arm_math.h" 28 | 29 | extern const uint16_t armBitRevTable[1024]; 30 | extern const q15_t armRecipTableQ15[64]; 31 | extern const q31_t armRecipTableQ31[64]; 32 | extern const q31_t realCoefAQ31[1024]; 33 | extern const q31_t realCoefBQ31[1024]; 34 | extern const float32_t twiddleCoef[6144]; 35 | extern const q31_t twiddleCoefQ31[6144]; 36 | extern const q15_t twiddleCoefQ15[6144]; 37 | 38 | #endif /* ARM_COMMON_TABLES_H */ 39 | -------------------------------------------------------------------------------- /core-common-lib/README.md: -------------------------------------------------------------------------------- 1 | # core-common-lib 2 | 3 | This repository holds all the common firmware libraries used by the Spark's main core firmware. 4 | 5 | Follow [this link](https://github.com/spark/core-firmware/blob/master/README.md) to find out how to build and use this repository. 6 | 7 | #### CREDITS AND ATTRIBUTIONS 8 | 9 | The Spark application team: Zachary Crockett, Satish Nair, Zach Supalla, David Middlecamp and Mohit Bhoite. 10 | 11 | The core-common-lib uses the GNU GCC toolchain for ARM Cortex-M processors, ARM's CMSIS libraries, TI's CC3000 host driver libraries and STM32 standard peripheral libraries. 12 | 13 | #### LICENSE 14 | Unless stated elsewhere, file headers or otherwise, the license as stated in the LICENSE file. 15 | 16 | #### CONTRIBUTE 17 | 18 | Want to contribute to the Spark Core project? Follow [this link]() to find out how. 19 | 20 | #### CONNECT 21 | 22 | Having problems or have awesome suggestions? Connect with us [here.](https://community.sparkdevices.com/) 23 | 24 | #### VERSION HISTORY 25 | 26 | Latest Version: v1.0.0 27 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/cc3000_spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file cc3000_spi.h 4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite 5 | * @version V1.0.0 6 | * @date 29-March-2013 7 | * @brief This file contains all the functions prototypes for the 8 | * CC3000 SPI firmware driver. 9 | ****************************************************************************** 10 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __CC3000_SPI_H 29 | #define __CC3000_SPI_H 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include 33 | #include "hw_config.h" 34 | #include "cc3000_common.h" 35 | #include "hci.h" 36 | #include "wlan.h" 37 | 38 | #define FALSE 0x00 39 | #define TRUE !FALSE 40 | 41 | #define READ 0x03 42 | #define WRITE 0x01 43 | 44 | #define HI(value) (((value) & 0xFF00) >> 8) 45 | #define LO(value) ((value) & 0x00FF) 46 | 47 | #define ASSERT_CS() CC3000_CS_LOW() 48 | #define DEASSERT_CS() CC3000_CS_HIGH() 49 | 50 | 51 | #define HEADERS_SIZE_EVNT (SPI_HEADER_SIZE + 5) 52 | #define MAX_PACKET_PAYLOAD_SIZE 1014 53 | #define RX_SPI_BUFFER_SIZE (MAX_PACKET_PAYLOAD_SIZE+HEADERS_SIZE_EVNT) 54 | #define TX_SPI_BUFFER_SIZE (MAX_PACKET_PAYLOAD_SIZE+HEADERS_SIZE_EVNT) 55 | 56 | typedef void (*gcSpiHandleRx)(void *p); 57 | typedef void (*gcSpiHandleTx)(void); 58 | 59 | extern unsigned char wlan_rx_buffer[RX_SPI_BUFFER_SIZE]; 60 | extern unsigned char wlan_tx_buffer[TX_SPI_BUFFER_SIZE]; 61 | 62 | /* CC3000 SPI Protocol API */ 63 | extern void SpiOpen(gcSpiHandleRx pfRxHandler); 64 | extern void SpiClose(void); 65 | extern long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength); 66 | extern void SpiResumeSpi(void); 67 | extern void SPI_DMA_IntHandler(void); 68 | extern void SPI_EXTI_IntHandler(void); 69 | 70 | #endif /* __CC3000_SPI_H */ 71 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * config.h 3 | * 4 | * Created on: Jan 31, 2014 5 | * Author: david_s5 6 | */ 7 | 8 | #ifndef CONFIG_H_ 9 | #define CONFIG_H_ 10 | 11 | #if !defined(RELEASE_BUILD) && !defined(DEBUG_BUILD) 12 | #warning "Defaulting to Release Build" 13 | #define RELEASE_BUILD 14 | #undef DEBUG_BUILD 15 | #endif 16 | 17 | 18 | #if defined(DEBUG_BUILD) 19 | #define DBGMCU_SETTINGS (DBGMCU_CR_DBG_SLEEP|DBGMCU_CR_DBG_STOP|DBGMCU_CR_DBG_STANDBY|DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP) 20 | #else 21 | #define USE_ONLY_PANIC // Define to remove all Logging and only have Panic 22 | #define DBGMCU_SETTINGS (DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP) 23 | #endif 24 | // define to include __FILE__ information within the debug output 25 | #define INCLUDE_FILE_INFO_IN_DEBUG 26 | #define MAX_DEBUG_MESSAGE_LENGTH 120 27 | 28 | #define RESET_ON_CFOD 1 // 1 Will do reset 0 will not 29 | #define MAX_SEC_WAIT_CONNECT 8 // Number of second a TCP, spark will wait 30 | #define MAX_FAILED_CONNECTS 2 // Number of time a connect can fail 31 | #define DEFAULT_SEC_INACTIVITY 0 32 | #define DEFAULT_SEC_NETOPS 20 33 | 34 | #endif /* CONFIG_H_ */ 35 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/panic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * panic.h 3 | * 4 | * Created on: Jan 31, 2014 5 | * Author: david_s5 6 | */ 7 | // The panic module will send SOS followed by 900 ms delay 8 | // followed by 300 blinks of the value of code 9 | /// ...---... code ...---... 10 | 11 | 12 | #ifndef PANIC_H_ 13 | #define PANIC_H_ 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | #define def_panic_codes(_class,led,code) code, 19 | typedef enum { 20 | NotUsedPanicCode = 0, // Not used 21 | #include "panic_codes.h" 22 | } ePanicCode; 23 | #undef def_panic_codes 24 | 25 | void panic_(ePanicCode code); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* PANIC_H_ */ 32 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/panic_codes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * panic.h 3 | * 4 | * Created on: Jan 31, 2014 5 | * Author: david_s5 6 | */ 7 | // Add a panic code def_panic_codes(_class, led, code) 8 | // the panic module will send SOS followed by 900 ms delay 9 | // followed by 300 blinks of the value of code 10 | /// ...---... code ...---... 11 | 12 | def_panic_codes(Faults,RGB_COLOR_RED,HardFault) 13 | def_panic_codes(Faults,RGB_COLOR_RED,NMIFault) 14 | def_panic_codes(Faults,RGB_COLOR_RED,MemManage) 15 | def_panic_codes(Faults,RGB_COLOR_RED,BusFault) 16 | def_panic_codes(Faults,RGB_COLOR_RED,UsageFault) 17 | 18 | def_panic_codes(Cloud,RGB_COLOR_RED,InvalidLenth) 19 | 20 | def_panic_codes(System,RGB_COLOR_RED,Exit) 21 | def_panic_codes(System,RGB_COLOR_RED,OutOfHeap) 22 | 23 | def_panic_codes(System,RGB_COLOR_RED,SPIOverRun) 24 | 25 | def_panic_codes(Software,RGB_COLOR_RED,AssertionFailure) 26 | def_panic_codes(Software,RGB_COLOR_RED,InvalidCase) 27 | def_panic_codes(Software,RGB_COLOR_RED,PureVirtualCall) 28 | 29 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/spark_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * spark_macros.h 3 | * 4 | * Created on: Jan 31, 2014 5 | * Author: david_s5 6 | */ 7 | 8 | #ifndef SPARK_MACROS_H_ 9 | #define SPARK_MACROS_H_ 10 | 11 | #if !defined(arraySize) 12 | # define arraySize(a) (sizeof((a))/sizeof((a[0]))) 13 | #endif 14 | 15 | #define INVALID_CASE(c) PANIC(InvalidCase,"Invalid Case %d",(c)) 16 | #define UNUSED(var) (void)(var) 17 | 18 | #define _CAT(a, b) a ## b 19 | #define CAT(a, b) _CAT(a, b) 20 | 21 | #define CCASSERT(predicate) _x_CCASSERT_LINE(predicate, __LINE__) 22 | #define _x_CCASSERT_LINE(predicate, line) typedef char CAT(constraint_violated_on_line_,line)[2*((predicate)!=0)-1]; 23 | 24 | // Seconds to Us 25 | #define S2u(s) ((s)*1000000) 26 | // Mili Seconds to Us 27 | #define MS2u(m) ((m)*1000) 28 | 29 | // Seconds to Ms 30 | #define S2M(s) ((s)*1000) 31 | 32 | #endif /* SPARK_MACROS_H_ */ 33 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi.h 4 | * @authors Zac 5 | * @version V1.0.0 6 | * @date 28-April-2013 7 | * @brief SPI 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | 27 | #ifndef SPI_H_ 28 | #define SPI_H_ 29 | 30 | #include "cc3000_spi.h" 31 | 32 | #endif /* SPI_H_ */ 33 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/inc/usb_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_pwr.h 4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite 5 | * @version V1.0.0 6 | * @date 24-April-2013 7 | * @brief Connection/disconnection & power management header 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_PWR_H 28 | #define __USB_PWR_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | typedef enum _RESUME_STATE 33 | { 34 | RESUME_EXTERNAL, 35 | RESUME_INTERNAL, 36 | RESUME_LATER, 37 | RESUME_WAIT, 38 | RESUME_START, 39 | RESUME_ON, 40 | RESUME_OFF, 41 | RESUME_ESOF 42 | } RESUME_STATE; 43 | 44 | typedef enum _DEVICE_STATE 45 | { 46 | UNCONNECTED, 47 | ATTACHED, 48 | POWERED, 49 | SUSPENDED, 50 | ADDRESSED, 51 | CONFIGURED 52 | } DEVICE_STATE; 53 | 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* Exported macro ------------------------------------------------------------*/ 56 | /* Exported functions ------------------------------------------------------- */ 57 | void Suspend(void); 58 | void Resume_Init(void); 59 | void Resume(RESUME_STATE eResumeSetVal); 60 | RESULT PowerOn(void); 61 | RESULT PowerOff(void); 62 | 63 | /* External variables --------------------------------------------------------*/ 64 | extern __IO uint32_t bDeviceState; /* USB device status */ 65 | extern __IO bool fSuspendEnabled; /* true when suspend is possible */ 66 | 67 | #endif /*__USB_PWR_H*/ 68 | 69 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/src/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_SPARK_PATH = SPARK_Firmware_Driver 8 | TARGET_SPARK_SRC_PATH = $(TARGET_SPARK_PATH)/src 9 | 10 | # Add tropicssl include to all objects built for this target 11 | INCLUDE_DIRS += $(TARGET_SPARK_PATH)/inc 12 | 13 | # C source files included in this build. 14 | CSRC += $(TARGET_SPARK_SRC_PATH)/cc3000_spi.c 15 | CSRC += $(TARGET_SPARK_SRC_PATH)/hw_config.c 16 | CSRC += $(TARGET_SPARK_SRC_PATH)/sst25vf_spi.c 17 | CSRC += $(TARGET_SPARK_SRC_PATH)/system_stm32f10x.c 18 | CSRC += $(TARGET_SPARK_SRC_PATH)/usb_pwr.c 19 | CSRC += $(TARGET_SPARK_SRC_PATH)/debug.c 20 | CSRC += $(TARGET_SPARK_SRC_PATH)/panic.c 21 | 22 | # C++ source files included in this build. 23 | CPPSRC += 24 | 25 | # ASM source files included in this build. 26 | ASRC += 27 | 28 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/src/debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.c 3 | * 4 | * Created on: Jan 31, 2014 5 | * Author: david_s5 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "config.h" 13 | #include "hw_config.h" 14 | #include "spark_macros.h" 15 | #include "debug.h" 16 | 17 | 18 | uint32_t log_level_at_run_time = LOG_LEVEL_AT_RUN_TIME; 19 | 20 | void log_print_(int level, int line, const char *func, const char *file, const char *msg, ...) 21 | { 22 | char _buffer[MAX_DEBUG_MESSAGE_LENGTH]; 23 | static char * levels[] = { 24 | "", 25 | "LOG ", 26 | "DEBUG", 27 | "WARN ", 28 | "ERROR", 29 | "PANIC", 30 | }; 31 | va_list args; 32 | va_start(args, msg); 33 | file = file ? strrchr(file,'/') + 1 : ""; 34 | int trunc = snprintf(_buffer, arraySize(_buffer), "%010lu:<%s> %s %s(%d):", GetSystem1MsTick(), levels[level], func, file, line); 35 | if (debug_output_) 36 | { 37 | debug_output_(_buffer); 38 | if (trunc > arraySize(_buffer)) 39 | { 40 | debug_output_("..."); 41 | } 42 | } 43 | trunc = vsnprintf(_buffer,arraySize(_buffer), msg, args); 44 | if (debug_output_) 45 | { 46 | debug_output_(_buffer); 47 | if (trunc > arraySize(_buffer)) 48 | { 49 | debug_output_("..."); 50 | } 51 | debug_output_("\r\n"); 52 | } 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /core-common-lib/SPARK_Firmware_Driver/src/panic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pnaic.c 3 | * 4 | * Created on: Jan 31, 2014 5 | * Author: david_s5 6 | */ 7 | 8 | #include 9 | #include "hw_config.h" 10 | #include "spark_macros.h" 11 | #include "panic.h" 12 | #include "debug.h" 13 | 14 | 15 | #define LOOPSPERMSEC 5483 16 | 17 | typedef struct { 18 | uint32_t led; 19 | uint16_t count; 20 | } flash_codes_t; 21 | 22 | 23 | #define def_panic_codes(_class,led,code) {led, code}, 24 | static const flash_codes_t flash_codes[] = { 25 | {0,0}, //NotUsedPanicCode 26 | #include "panic_codes.h" 27 | }; 28 | #undef def_panic_codes 29 | 30 | /**************************************************************************** 31 | * Public Functions 32 | ****************************************************************************/ 33 | 34 | void panic_(ePanicCode code) 35 | { 36 | __disable_irq(); 37 | // Flush any serial message to help the poor bugger debug this; 38 | flash_codes_t pcd = flash_codes[code]; 39 | LED_SetRGBColor(RGB_COLOR_RED); 40 | LED_On(LED_RGB); 41 | uint16_t c; 42 | int loops = 2; 43 | if (debug_output_)(debug_output_("!")); 44 | LED_Off(LED_RGB); 45 | while(loops) { 46 | // preamble 47 | KICK_WDT(); 48 | for (c = 3; c; c--) { 49 | LED_SetRGBColor(pcd.led); 50 | LED_On(LED_RGB); 51 | Delay_Microsecond(MS2u(150)); 52 | LED_Off(LED_RGB); 53 | Delay_Microsecond(MS2u(100)); 54 | } 55 | 56 | Delay_Microsecond(MS2u(100)); 57 | for (c = 3; c; c--) { 58 | LED_SetRGBColor(pcd.led); 59 | LED_On(LED_RGB); 60 | Delay_Microsecond(MS2u(300)); 61 | LED_Off(LED_RGB); 62 | Delay_Microsecond(MS2u(100)); 63 | } 64 | Delay_Microsecond(MS2u(100)); 65 | 66 | for (c = 3; c; c--) { 67 | LED_SetRGBColor(pcd.led); 68 | LED_On(LED_RGB); 69 | Delay_Microsecond(MS2u(150)); 70 | LED_Off(LED_RGB); 71 | Delay_Microsecond(MS2u(100)); 72 | } 73 | 74 | // pause 75 | Delay_Microsecond(MS2u(900)); 76 | // play code 77 | for (c = code; c; c--) { 78 | LED_SetRGBColor(pcd.led); 79 | LED_On(LED_RGB); 80 | Delay_Microsecond(MS2u(300)); 81 | LED_Off(LED_RGB); 82 | Delay_Microsecond(MS2u(300)); 83 | } 84 | // pause 85 | Delay_Microsecond(MS2u(800)); 86 | #ifdef RELEASE_BUILD 87 | if (--loops == 0) NVIC_SystemReset(); 88 | #endif 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /core-common-lib/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.6.1 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | Released into the public domain. 11 | This work is free: you can redistribute it and/or modify it under the terms of 12 | Creative Commons Zero license v1.0 13 | 14 | This work is licensed under the Creative Commons Zero 1.0 United States License. 15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 17 | California, 94105, USA. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 21 | or FITNESS FOR A PARTICULAR PURPOSE. 22 | * 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __STM32F10x_CRC_H 28 | #define __STM32F10x_CRC_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Includes ------------------------------------------------------------------*/ 35 | #include "stm32f10x.h" 36 | 37 | /** @addtogroup STM32F10x_StdPeriph_Driver 38 | * @{ 39 | */ 40 | 41 | /** @addtogroup CRC 42 | * @{ 43 | */ 44 | 45 | /** @defgroup CRC_Exported_Types 46 | * @{ 47 | */ 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /** @defgroup CRC_Exported_Constants 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup CRC_Exported_Macros 62 | * @{ 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup CRC_Exported_Functions 70 | * @{ 71 | */ 72 | 73 | void CRC_ResetDR(void); 74 | uint32_t CRC_CalcCRC(uint32_t Data); 75 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 76 | uint32_t CRC_GetCRC(void); 77 | void CRC_SetIDRegister(uint8_t IDValue); 78 | uint8_t CRC_GetIDRegister(void); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* __STM32F10x_CRC_H */ 85 | /** 86 | * @} 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | -------------------------------------------------------------------------------- /core-common-lib/STM32F10x_StdPeriph_Driver/src/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_STDPERIPH_PATH = STM32F10x_StdPeriph_Driver 8 | TARGET_STDPERIPH_SRC_PATH = $(TARGET_STDPERIPH_PATH)/src 9 | 10 | # Add tropicssl include to all objects built for this target 11 | INCLUDE_DIRS += $(TARGET_STDPERIPH_PATH)/inc 12 | 13 | # C source files included in this build. 14 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/misc.c 15 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_adc.c 16 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_bkp.c 17 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_crc.c 18 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_dma.c 19 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_exti.c 20 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_flash.c 21 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_gpio.c 22 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_i2c.c 23 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_iwdg.c 24 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_pwr.c 25 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_rcc.c 26 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_rtc.c 27 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_spi.c 28 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_tim.c 29 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_usart.c 30 | 31 | # C++ source files included in this build. 32 | CPPSRC += 33 | 34 | # ASM source files included in this build. 35 | ASRC += 36 | 37 | -------------------------------------------------------------------------------- /core-common-lib/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Na2l/spark-websocket-server/30b8495ec597deb4e5bd5577b3861aafd7934d28/core-common-lib/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /core-common-lib/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Na2l/spark-websocket-server/30b8495ec597deb4e5bd5577b3861aafd7934d28/core-common-lib/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /core-common-lib/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Na2l/spark-websocket-server/30b8495ec597deb4e5bd5577b3861aafd7934d28/core-common-lib/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | Released into the public domain. 4 | This work is free: you can redistribute it and/or modify it under the terms of 5 | Creative Commons Zero license v1.0 6 | 7 | This work is licensed under the Creative Commons Zero 1.0 United States License. 8 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 9 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 10 | California, 94105, USA. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. 15 | ****************************************************************************** 16 | */ 17 | 18 | /* Define to prevent recursive inclusion -------------------------------------*/ 19 | #ifndef __USB_DEF_H 20 | #define __USB_DEF_H 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | /* Exported types ------------------------------------------------------------*/ 24 | typedef enum _RECIPIENT_TYPE 25 | { 26 | DEVICE_RECIPIENT, /* Recipient device */ 27 | INTERFACE_RECIPIENT, /* Recipient interface */ 28 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 29 | OTHER_RECIPIENT 30 | } RECIPIENT_TYPE; 31 | 32 | 33 | typedef enum _STANDARD_REQUESTS 34 | { 35 | GET_STATUS = 0, 36 | CLEAR_FEATURE, 37 | RESERVED1, 38 | SET_FEATURE, 39 | RESERVED2, 40 | SET_ADDRESS, 41 | GET_DESCRIPTOR, 42 | SET_DESCRIPTOR, 43 | GET_CONFIGURATION, 44 | SET_CONFIGURATION, 45 | GET_INTERFACE, 46 | SET_INTERFACE, 47 | TOTAL_sREQUEST, /* Total number of Standard request */ 48 | SYNCH_FRAME = 12 49 | } STANDARD_REQUESTS; 50 | 51 | /* Definition of "USBwValue" */ 52 | typedef enum _DESCRIPTOR_TYPE 53 | { 54 | DEVICE_DESCRIPTOR = 1, 55 | CONFIG_DESCRIPTOR, 56 | STRING_DESCRIPTOR, 57 | INTERFACE_DESCRIPTOR, 58 | ENDPOINT_DESCRIPTOR 59 | } DESCRIPTOR_TYPE; 60 | 61 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 62 | typedef enum _FEATURE_SELECTOR 63 | { 64 | ENDPOINT_STALL, 65 | DEVICE_REMOTE_WAKEUP 66 | } FEATURE_SELECTOR; 67 | 68 | /* Exported constants --------------------------------------------------------*/ 69 | /* Definition of "USBbmRequestType" */ 70 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 71 | #define STANDARD_REQUEST 0x00 /* Standard request */ 72 | #define CLASS_REQUEST 0x20 /* Class request */ 73 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 74 | 75 | #define RECIPIENT 0x1F /* Mask to get recipient */ 76 | 77 | /* Exported macro ------------------------------------------------------------*/ 78 | /* Exported functions ------------------------------------------------------- */ 79 | 80 | #endif /* __USB_DEF_H */ 81 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_init.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Initialization routines & global variables 8 | ****************************************************************************** 9 | Released into the public domain. 10 | This work is free: you can redistribute it and/or modify it under the terms of 11 | Creative Commons Zero license v1.0 12 | 13 | This work is licensed under the Creative Commons Zero 1.0 United States License. 14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 16 | California, 94105, USA. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | or FITNESS FOR A PARTICULAR PURPOSE. 21 | ****************************************************************************** 22 | */ 23 | 24 | 25 | /* Define to prevent recursive inclusion -------------------------------------*/ 26 | #ifndef __USB_INIT_H 27 | #define __USB_INIT_H 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Exported macro ------------------------------------------------------------*/ 33 | /* Exported functions ------------------------------------------------------- */ 34 | void USB_Init(void); 35 | 36 | /* External variables --------------------------------------------------------*/ 37 | /* The number of current endpoint, it will be used to specify an endpoint */ 38 | extern uint8_t EPindex; 39 | /* The number of current device, it is an index to the Device_Table */ 40 | /*extern uint8_t Device_no; */ 41 | /* Points to the DEVICE_INFO structure of current device */ 42 | /* The purpose of this register is to speed up the execution */ 43 | extern DEVICE_INFO* pInformation; 44 | /* Points to the DEVICE_PROP structure of current device */ 45 | /* The purpose of this register is to speed up the execution */ 46 | extern DEVICE_PROP* pProperty; 47 | /* Temporary save the state of Rx & Tx status. */ 48 | /* Whenever the Rx or Tx state is changed, its value is saved */ 49 | /* in this variable first and will be set to the EPRB or EPRA */ 50 | /* at the end of interrupt process */ 51 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 52 | 53 | extern uint16_t SaveState ; 54 | extern uint16_t wInterrupt_Mask; 55 | 56 | #endif /* __USB_INIT_H */ 57 | 58 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_int.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes 8 | ****************************************************************************** 9 | Released into the public domain. 10 | This work is free: you can redistribute it and/or modify it under the terms of 11 | Creative Commons Zero license v1.0 12 | 13 | This work is licensed under the Creative Commons Zero 1.0 United States License. 14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 16 | California, 94105, USA. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | or FITNESS FOR A PARTICULAR PURPOSE. 21 | * 22 | ****************************************************************************** 23 | */ 24 | 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_INT_H 28 | #define __USB_INT_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void CTR_LP(void); 36 | void CTR_HP(void); 37 | 38 | /* External variables --------------------------------------------------------*/ 39 | 40 | #endif /* __USB_INT_H */ 41 | 42 | 43 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_lib.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief USB library include files 8 | ****************************************************************************** 9 | Released into the public domain. 10 | This work is free: you can redistribute it and/or modify it under the terms of 11 | Creative Commons Zero license v1.0 12 | 13 | This work is licensed under the Creative Commons Zero 1.0 United States License. 14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 16 | California, 94105, USA. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | or FITNESS FOR A PARTICULAR PURPOSE. 21 | * 22 | ****************************************************************************** 23 | */ 24 | 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_LIB_H 28 | #define __USB_LIB_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "hw_config.h" 32 | #include "usb_type.h" 33 | #include "usb_regs.h" 34 | #include "usb_def.h" 35 | #include "usb_core.h" 36 | #include "usb_init.h" 37 | #include "usb_sil.h" 38 | #include "usb_mem.h" 39 | #include "usb_int.h" 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported constants --------------------------------------------------------*/ 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* Exported functions ------------------------------------------------------- */ 45 | /* External variables --------------------------------------------------------*/ 46 | 47 | #endif /* __USB_LIB_H */ 48 | 49 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_mem.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Utility prototypes functions for memory/PMA transfers 8 | ****************************************************************************** 9 | Released into the public domain. 10 | This work is free: you can redistribute it and/or modify it under the terms of 11 | Creative Commons Zero license v1.0 12 | 13 | This work is licensed under the Creative Commons Zero 1.0 United States License. 14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 16 | California, 94105, USA. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | or FITNESS FOR A PARTICULAR PURPOSE. 21 | * 22 | ****************************************************************************** 23 | */ 24 | 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_MEM_H 28 | #define __USB_MEM_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 36 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 37 | 38 | /* External variables --------------------------------------------------------*/ 39 | 40 | #endif /*__USB_MEM_H*/ 41 | 42 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_sil.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Simplified Interface Layer function prototypes. 8 | ****************************************************************************** 9 | Released into the public domain. 10 | This work is free: you can redistribute it and/or modify it under the terms of 11 | Creative Commons Zero license v1.0 12 | 13 | This work is licensed under the Creative Commons Zero 1.0 United States License. 14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 16 | California, 94105, USA. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | or FITNESS FOR A PARTICULAR PURPOSE. 21 | * 22 | ****************************************************************************** 23 | */ 24 | 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_SIL_H 28 | #define __USB_SIL_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | 36 | uint32_t USB_SIL_Init(void); 37 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize); 38 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer); 39 | 40 | /* External variables --------------------------------------------------------*/ 41 | 42 | #endif /* __USB_SIL_H */ 43 | 44 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_type.h 4 | * @author MCD Application Team 5 | * @version V4.0.0 6 | * @date 28-August-2012 7 | * @brief Type definitions used by the USB Library 8 | ****************************************************************************** 9 | Released into the public domain. 10 | This work is free: you can redistribute it and/or modify it under the terms of 11 | Creative Commons Zero license v1.0 12 | 13 | This work is licensed under the Creative Commons Zero 1.0 United States License. 14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/ 15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, 16 | California, 94105, USA. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 | or FITNESS FOR A PARTICULAR PURPOSE. 21 | * 22 | ****************************************************************************** 23 | */ 24 | 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_TYPE_H 28 | #define __USB_TYPE_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | #ifndef NULL 35 | #define NULL ((void *)0) 36 | #endif 37 | 38 | #ifndef __cplusplus 39 | typedef enum 40 | { 41 | false = 0, true = !false 42 | } 43 | bool; 44 | #endif 45 | 46 | /* Exported macro ------------------------------------------------------------*/ 47 | /* Exported functions ------------------------------------------------------- */ 48 | /* External variables --------------------------------------------------------*/ 49 | 50 | #endif /* __USB_TYPE_H */ 51 | 52 | -------------------------------------------------------------------------------- /core-common-lib/STM32_USB-FS-Device_Driver/src/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_USB_FS_PATH = STM32_USB-FS-Device_Driver 8 | TARGET_USB_FS_SRC_PATH = $(TARGET_USB_FS_PATH)/src 9 | 10 | # Add tropicssl include to all objects built for this target 11 | INCLUDE_DIRS += $(TARGET_USB_FS_PATH)/inc 12 | 13 | # C source files included in this build. 14 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_core.c 15 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_init.c 16 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_int.c 17 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_mem.c 18 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_regs.c 19 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_sil.c 20 | 21 | # C++ source files included in this build. 22 | CPPSRC += 23 | 24 | # ASM source files included in this build. 25 | ASRC += 26 | 27 | -------------------------------------------------------------------------------- /core-common-lib/build/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled objects and dependancies 2 | obj/ -------------------------------------------------------------------------------- /core-communication-lib/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | *.dSYM 14 | 15 | # Executables 16 | *.exe 17 | *.out 18 | *.app 19 | tests/testSparkCoreCommunication 20 | 21 | # Debug folder 22 | Debug/* 23 | 24 | # Release folder 25 | Release/* 26 | 27 | # build folder 28 | *.map 29 | *.lst 30 | *.d 31 | *.o 32 | 33 | # Platform-specific settings 34 | .settings/* 35 | .cproject 36 | .project 37 | .DS_Store 38 | -------------------------------------------------------------------------------- /core-communication-lib/Makefile: -------------------------------------------------------------------------------- 1 | CXX ?= g++ 2 | CXXFLAGS ?= -g -Wall -W -Winline -ansi 3 | CXXFLAGS += -Ilib/tropicssl/include -Isrc -Itests/UnitTest++/src 4 | LDFLAGS ?= 5 | RM = rm 6 | 7 | .SUFFIXES: .o .cpp 8 | 9 | name = SparkCoreCommunication 10 | lib = src/lib$(name).a 11 | test = tests/test$(name) 12 | testlibdir = tests/UnitTest++ 13 | testlib = $(testlibdir)/libUnitTest++.a 14 | testrunner = tests/Main.cpp 15 | ssllibdir = lib/tropicssl/library 16 | ssllib = $(ssllibdir)/libtropicssl.a 17 | 18 | objects = src/handshake.o \ 19 | src/coap.o \ 20 | src/spark_protocol.o \ 21 | src/events.o 22 | 23 | testobjects = tests/ConstructorFixture.o \ 24 | tests/TestHandshake.o \ 25 | tests/TestAES.o \ 26 | tests/TestCoAP.o \ 27 | tests/TestQueue.o \ 28 | tests/TestStateMachine.o \ 29 | tests/TestSparkProtocol.o \ 30 | tests/TestDescriptor.o \ 31 | tests/TestUserFunctions.o \ 32 | tests/TestEvents.o 33 | 34 | 35 | all: $(lib) 36 | 37 | $(lib): $(objects) 38 | @echo Creating spark communication library... 39 | @$(AR) cr $(lib) $(objects) 40 | 41 | .cpp.o: 42 | @$(CXX) $(CXXFLAGS) -c -o $@ $< 43 | 44 | clean: 45 | -@$(RM) $(objects) $(lib) $(testobjects) 2> /dev/null 46 | 47 | 48 | ############### tests ############# 49 | 50 | test: $(lib) $(testlib) $(testobjects) $(ssllib) 51 | @$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(test) $(testlib) \ 52 | $(lib) $(ssllib) $(testobjects) $(testrunner) 53 | @echo running unit tests... 54 | @./$(test) 55 | 56 | $(testlib): 57 | $(MAKE) -C $(testlibdir) 58 | 59 | testclean: 60 | $(MAKE) -C $(testlibdir) clean 61 | 62 | 63 | ############# ssl library ########### 64 | 65 | $(ssllib): 66 | $(MAKE) -C $(ssllibdir) 67 | 68 | sslclean: 69 | $(MAKE) -C $(ssllibdir) clean 70 | -------------------------------------------------------------------------------- /core-communication-lib/README.md: -------------------------------------------------------------------------------- 1 | # Core Communication Library 2 | 3 | This repository holds the firmware libraries used for the communication between the Spark Core and the Cloud service. 4 | 5 | Follow [this link](https://github.com/spark/core-firmware/blob/master/README.md) to find out how to build and use this repository. 6 | 7 | ### SECURITY OVERVIEW 8 | 9 | * [RSA encrypt initial handshake message to cloud](https://github.com/spark/core-communication-lib/blob/master/src/spark_protocol.cpp#L102) 10 | * [Decrypt return message from Cloud with an RSA private key on the Core](https://github.com/spark/core-communication-lib/blob/master/src/handshake.cpp#L53) 11 | * [Verify HMAC signature](https://github.com/spark/core-communication-lib/blob/master/src/spark_protocol.cpp#L1022) 12 | * If everything checks out, AES-128-CBC session key is saved and IV is rotated with every message exchanged 13 | * [encrypt](https://github.com/spark/core-communication-lib/blob/master/src/spark_protocol.cpp#L989) 14 | * [decrypt](https://github.com/spark/core-communication-lib/blob/master/src/spark_protocol.cpp#L267) 15 | 16 | ### CREDITS AND ATTRIBUTIONS 17 | 18 | The Spark application team: Zachary Crockett, Satish Nair, Zach Supalla, David Middlecamp and Mohit Bhoite. 19 | 20 | The core-communication-lib uses the GNU GCC toolchain for ARM Cortex-M processors and XySSL/TropicSSL libraries. 21 | 22 | ### LICENSE 23 | Unless stated elsewhere, file headers or otherwise, the license as stated in the LICENSE file. 24 | 25 | ### CONTRIBUTE 26 | 27 | Want to contribute to the Spark Core project? Follow [this link]() to find out how. 28 | 29 | ### CONNECT 30 | 31 | Having problems or have awesome suggestions? Connect with us [here.](https://community.sparkdevices.com/) 32 | 33 | ### VERSION HISTORY 34 | 35 | Latest Version: v1.0.0 36 | 37 | 38 | -------------------------------------------------------------------------------- /core-communication-lib/build/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled objects and dependancies 2 | obj/ -------------------------------------------------------------------------------- /core-communication-lib/lib/tropicssl/library/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Also see "include/tropicssl/config.h" 3 | 4 | # Suggested value for TROPICSSL_CFLAGS_EXTRA_WARNINGS to pass 5 | # on the command line, for gcc (GCC) 4.4.6 20120305 6 | # (Red Hat 4.4.6-4): 7 | # 8 | # make all 'TROPICSSL_CFLAGS_EXTRA_WARNINGS= -Wextra -Wformat=2 9 | # -fstrict-aliasing -Wstrict-aliasing -Wfloat-equal 10 | # -Wundef -Wpointer-arith -Wbad-function-cast 11 | # -Wcast-qual -Wcast-align -Wwrite-strings -Waddress 12 | # -Waggregate-return -Wstrict-prototypes 13 | # -Wold-style-declaration -Wold-style-definition 14 | # -Wmissing-parameter-type -Wmissing-prototypes 15 | # -Wmissing-declarations -Wmissing-field-initializers 16 | # -Wmissing-noreturn -Wmissing-format-attribute -Wpacked 17 | # -Wredundant-decls -Wnested-externs' 18 | # 19 | 20 | CFLAGS = -I../include -D_FILE_OFFSET_BITS=64 -Wall $(TROPICSSL_CFLAGS_EXTRA_WARNINGS) 21 | OFLAGS = -Os 22 | 23 | ifndef TROPICSSL_CFLAGS_NO_WARNINGS_AS_ERRORS 24 | CFLAGS += -Werror 25 | endif # TROPICSSL_CFLAGS_NO_WARNINGS_AS_ERRORS 26 | 27 | # MicroBlaze specific options: 28 | # CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift 29 | 30 | # To compile on Plan9: 31 | # CFLAGS += -D_BSD_EXTENSION 32 | 33 | # To compile as a shared library: 34 | ifdef TROPICSSL_SHARED 35 | CFLAGS += -fPIC 36 | endif # TROPICSSL_SHARED 37 | 38 | DLEXT=so 39 | # OSX shared library extension: 40 | # DLEXT=dylib 41 | 42 | # OBJS= aes.o arc4.o base64.o \ 43 | # bignum.o certs.o debug.o \ 44 | # des.o dhm.o havege.o \ 45 | # md2.o md4.o md5.o \ 46 | # net.o padlock.o rsa.o \ 47 | # sha1.o sha2.o sha4.o \ 48 | # ssl_cli.o ssl_srv.o ssl_tls.o \ 49 | # timing.o x509parse.o xtea.o \ 50 | # camellia.o 51 | OBJS = aes.o bignum.o padlock.o rsa.o sha1.o 52 | 53 | .PHONY: all 54 | 55 | ifdef TROPICSSL_SHARED 56 | all: shared 57 | else # TROPICSSL_SHARED 58 | all: static 59 | endif # TROPICSSL_SHARED 60 | 61 | .PHONY: static 62 | 63 | static: libtropicssl.a 64 | 65 | .PHONY: shared 66 | 67 | shared: libtropicssl.$(DLEXT) 68 | 69 | libtropicssl.a: $(OBJS) 70 | @echo " AR $@" 71 | $(AR) r $@ $(OBJS) 72 | @echo " RL $@" 73 | ranlib $@ 74 | 75 | libtropicssl.so: libtropicssl.a 76 | @echo " LD $@" 77 | $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS) 78 | 79 | libtropicssl.dylib: libtropicssl.a 80 | @echo " LD $@" 81 | $(CC) -dynamiclib -o $@ $(OBJS) 82 | 83 | .c.o: 84 | @echo " CC $<" 85 | $(CC) $(CFLAGS) $(OFLAGS) -c $< 86 | 87 | .PHONY: clean 88 | 89 | clean: 90 | rm -f *.o libtropicssl.* 91 | 92 | -------------------------------------------------------------------------------- /core-communication-lib/lib/tropicssl/library/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_LIB_TROPICSSL_PATH = lib/tropicssl 8 | TARGET_LIB_TROPICSSL_LIB_PATH = $(TARGET_LIB_TROPICSSL_PATH)/library 9 | 10 | # Add tropicssl include to all objects built for this target 11 | INCLUDE_DIRS += $(TARGET_LIB_TROPICSSL_PATH)/include 12 | 13 | # C source files included in this build. 14 | CSRC += $(TARGET_LIB_TROPICSSL_LIB_PATH)/aes.c 15 | CSRC += $(TARGET_LIB_TROPICSSL_LIB_PATH)/bignum.c 16 | CSRC += $(TARGET_LIB_TROPICSSL_LIB_PATH)/padlock.c 17 | CSRC += $(TARGET_LIB_TROPICSSL_LIB_PATH)/rsa.c 18 | CSRC += $(TARGET_LIB_TROPICSSL_LIB_PATH)/sha1.c 19 | 20 | # C++ source files included in this build. 21 | CPPSRC += 22 | 23 | # ASM source files included in this build. 24 | ASRC += 25 | 26 | -------------------------------------------------------------------------------- /core-communication-lib/src/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_SRC_PATH = src 8 | 9 | # Add tropicssl include to all objects built for this target 10 | INCLUDE_DIRS += $(TARGET_SRC_PATH) 11 | 12 | # C source files included in this build. 13 | CSRC += 14 | 15 | # C++ source files included in this build. 16 | CPPSRC += $(TARGET_SRC_PATH)/coap.cpp 17 | CPPSRC += $(TARGET_SRC_PATH)/handshake.cpp 18 | CPPSRC += $(TARGET_SRC_PATH)/spark_protocol.cpp 19 | CPPSRC += $(TARGET_SRC_PATH)/events.cpp 20 | 21 | # ASM source files included in this build. 22 | ASRC += 23 | 24 | -------------------------------------------------------------------------------- /core-communication-lib/src/coap.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file coap.cpp 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 15-Nov-2013 7 | * @brief COAP 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This program is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this program; if not, see . 23 | ****************************************************************************** 24 | */ 25 | #include "coap.h" 26 | 27 | CoAPCode::Enum CoAP::code(const unsigned char *message) 28 | { 29 | switch (message[1]) 30 | { 31 | case 0x00: return CoAPCode::EMPTY; 32 | case 0x01: return CoAPCode::GET; 33 | case 0x02: return CoAPCode::POST; 34 | case 0x03: return CoAPCode::PUT; 35 | default: return CoAPCode::ERROR; 36 | } 37 | } 38 | 39 | CoAPType::Enum CoAP::type(const unsigned char *message) 40 | { 41 | switch (message[0] & 0x30) 42 | { 43 | case 0x00: return CoAPType::CON; 44 | case 0x10: return CoAPType::NON; 45 | default: 46 | case 0x20: return CoAPType::ACK; 47 | case 0x30: return CoAPType::RESET; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core-communication-lib/src/coap.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file coap.h 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 15-Nov-2013 7 | * @brief COAP 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | namespace CoAPMessageType { 26 | enum Enum { 27 | HELLO, 28 | DESCRIBE, 29 | FUNCTION_CALL, 30 | VARIABLE_REQUEST, 31 | UPDATE_BEGIN, 32 | UPDATE_DONE, 33 | CHUNK, 34 | KEY_CHANGE, 35 | SIGNAL_START, 36 | SIGNAL_STOP, 37 | EMPTY_ACK, 38 | PING, 39 | ERROR 40 | }; 41 | } 42 | 43 | namespace CoAPCode { 44 | enum Enum { 45 | GET, 46 | POST, 47 | PUT, 48 | EMPTY, 49 | ERROR 50 | }; 51 | } 52 | 53 | namespace CoAPType { 54 | enum Enum { 55 | CON, 56 | NON, 57 | ACK, 58 | RESET 59 | }; 60 | } 61 | 62 | class CoAP 63 | { 64 | public: 65 | static CoAPCode::Enum code(const unsigned char *message); 66 | static CoAPType::Enum type(const unsigned char *message); 67 | }; 68 | -------------------------------------------------------------------------------- /core-communication-lib/src/events.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file events.cpp 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 26-Feb-2014 7 | * @brief Internal CoAP event message creation 8 | ****************************************************************************** 9 | Copyright (c) 2014 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | #include "events.h" 26 | #include 27 | 28 | size_t event(uint8_t buf[], uint16_t message_id, const char *event_name, 29 | const char *data, int ttl, EventType::Enum event_type) 30 | { 31 | uint8_t *p = buf; 32 | *p++ = 0x50; // non-confirmable, no token 33 | *p++ = 0x02; // code 0.02 POST request 34 | *p++ = message_id >> 8; 35 | *p++ = message_id & 0xff; 36 | *p++ = 0xb1; 37 | *p++ = event_type; 38 | 39 | size_t name_data_len = strnlen(event_name, 63); 40 | p += event_name_uri_path(p, event_name, name_data_len); 41 | 42 | if (60 != ttl) 43 | { 44 | *p++ = 0x33; 45 | *p++ = (ttl >> 16) & 0xff; 46 | *p++ = (ttl >> 8) & 0xff; 47 | *p++ = ttl & 0xff; 48 | } 49 | 50 | if (NULL != data) 51 | { 52 | name_data_len = strnlen(data, 63); 53 | 54 | *p++ = 0xff; 55 | memcpy(p, data, name_data_len); 56 | p += name_data_len; 57 | } 58 | 59 | return p - buf; 60 | } 61 | 62 | size_t event_name_uri_path(uint8_t buf[], const char *name, size_t name_len) 63 | { 64 | if (name_len < 13) 65 | { 66 | buf[0] = name_len; 67 | memcpy(buf + 1, name, name_len); 68 | return name_len + 1; 69 | } 70 | else 71 | { 72 | buf[0] = 0x0d; 73 | buf[1] = name_len - 13; 74 | memcpy(buf + 2, name, name_len); 75 | return name_len + 2; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /core-communication-lib/src/events.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file events.h 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 26-Feb-2014 7 | * @brief Internal CoAP event message creation 8 | ****************************************************************************** 9 | Copyright (c) 2014 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | #ifndef __EVENTS_H 26 | #define __EVENTS_H 27 | 28 | #include 29 | #include 30 | 31 | namespace EventType { 32 | enum Enum { 33 | PUBLIC = 'e', 34 | PRIVATE = 'E' 35 | }; 36 | } 37 | 38 | size_t event(uint8_t buf[], uint16_t message_id, const char *event_name, 39 | const char *data, int ttl, EventType::Enum event_type); 40 | 41 | size_t event_name_uri_path(uint8_t buf[], const char *name, size_t name_len); 42 | 43 | #endif // __EVENTS_H 44 | -------------------------------------------------------------------------------- /core-communication-lib/src/handshake.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file handshake.h 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 15-Nov-2013 7 | * @brief HANDSHAKE 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | #include "tropicssl/rsa.h" 26 | #include "tropicssl/sha1.h" 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | int ciphertext_from_nonce_and_id(const unsigned char *nonce, 34 | const unsigned char *id, 35 | const unsigned char *pubkey, 36 | unsigned char *ciphertext); 37 | 38 | int decipher_aes_credentials(const unsigned char *private_key, 39 | const unsigned char *ciphertext, 40 | unsigned char *aes_credentials); 41 | 42 | void calculate_ciphertext_hmac(const unsigned char *ciphertext, 43 | const unsigned char *hmac_key, 44 | unsigned char *hmac); 45 | 46 | int verify_signature(const unsigned char *signature, 47 | const unsigned char *pubkey, 48 | const unsigned char *expected_hmac); 49 | 50 | void init_rsa_context_with_public_key(rsa_context *rsa, 51 | const unsigned char *pubkey); 52 | 53 | void init_rsa_context_with_private_key(rsa_context *rsa, 54 | const unsigned char *private_key); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /core-communication-lib/src/spark_descriptor.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_descriptor.h 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 15-Nov-2013 7 | * @brief SPARK DESCRIPTOR 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | // Deferring to ASN.1 type codes 27 | namespace SparkReturnType { 28 | enum Enum { 29 | BOOLEAN = 1, 30 | INT = 2, 31 | STRING = 4, 32 | DOUBLE = 9 33 | }; 34 | } 35 | 36 | struct SparkDescriptor 37 | { 38 | int (*num_functions)(void); 39 | void (*copy_function_key)(char *destination, int function_index); 40 | int (*call_function)(const char *function_key, const char *arg); 41 | 42 | int (*num_variables)(void); 43 | void (*copy_variable_key)(char *destination, int variable_index); 44 | SparkReturnType::Enum (*variable_type)(const char *variable_key); 45 | void *(*get_variable)(const char *variable_key); 46 | 47 | bool (*was_ota_upgrade_successful)(void); 48 | void (*ota_upgrade_status_sent)(void); 49 | }; 50 | -------------------------------------------------------------------------------- /core-communication-lib/tests/ConstructorFixture.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ConstructorFixture.h 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 10-Jan-2014 7 | * @brief Fixture for testing SparkProtocol 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __CONSTRUCTOR_FIXTURE_H 27 | #define __CONSTRUCTOR_FIXTURE_H 28 | 29 | #include 30 | #include "spark_protocol.h" 31 | 32 | struct ConstructorFixture 33 | { 34 | static const uint8_t nonce[41]; 35 | static const char id[13]; 36 | static uint8_t pubkey[295]; 37 | static uint8_t private_key[613]; 38 | static const uint8_t signed_encrypted_credentials[385]; 39 | static int bytes_sent[2]; 40 | static int bytes_received[2]; 41 | static uint8_t sent_buf_0[256]; 42 | static uint8_t sent_buf_1[256]; 43 | static int mock_send(const unsigned char *buf, int buflen); 44 | static int mock_receive(unsigned char *buf, int buflen); 45 | static uint8_t message_to_receive[34]; 46 | static bool function_called; 47 | static int mock_num_functions(void); 48 | static void mock_copy_function_key(char *destination, int function_index); 49 | static int mock_call_function(const char *function_key, const char *arg); 50 | static int mock_num_variables(void); 51 | static void mock_copy_variable_key(char *destination, int variable_index); 52 | static void *mock_get_variable(const char *variable_key); 53 | static void mock_signal(bool on); 54 | static bool signal_called_with; 55 | static int variable_to_get; 56 | static system_tick_t next_millis; 57 | static system_tick_t mock_millis(void); 58 | static bool mock_ota_status_check(void); 59 | static SparkReturnType::Enum mock_variable_type(const char *variable_key); 60 | 61 | ConstructorFixture(); 62 | SparkKeys keys; 63 | SparkCallbacks callbacks; 64 | SparkDescriptor descriptor; 65 | SparkProtocol spark_protocol; 66 | }; 67 | 68 | #endif // __CONSTRUCTOR_FIXTURE_H 69 | -------------------------------------------------------------------------------- /core-communication-lib/tests/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "UnitTest++.h" 2 | 3 | int main(int, char const *[]) 4 | { 5 | return UnitTest::RunAllTests(); 6 | } 7 | -------------------------------------------------------------------------------- /core-communication-lib/tests/TestAES.cpp: -------------------------------------------------------------------------------- 1 | #include "UnitTest++.h" 2 | #include "tropicssl/aes.h" 3 | 4 | struct AESFixture 5 | { 6 | static const uint8_t credentials[40]; 7 | static const uint8_t ciphertext[32]; 8 | static const uint8_t plaintext[32]; 9 | }; 10 | 11 | const uint8_t AESFixture::credentials[40] = { 12 | 0x50, 0x8e, 0x8a, 0xfd, 0x78, 0x73, 0x23, 0x38, 13 | 0x67, 0xd6, 0x56, 0xc0, 0xca, 0x46, 0x04, 0x8e, 14 | 0x0a, 0xbb, 0x06, 0xe3, 0x9b, 0xc5, 0x7e, 0x2c, 15 | 0x9b, 0xce, 0x0b, 0xdf, 0xc5, 0x52, 0xc8, 0x2d, 16 | 0xf6, 0x48, 0x0d, 0x23, 0xc5, 0x0e, 0x2d, 0x6d }; 17 | 18 | const uint8_t AESFixture::ciphertext[32] = { 19 | 0xcf, 0x05, 0x07, 0x47, 0x67, 0x64, 0x15, 0x8c, 20 | 0x7b, 0x63, 0xd0, 0x4c, 0x9d, 0x17, 0xe0, 0x12, 21 | 0xc2, 0xc1, 0x84, 0x10, 0x5b, 0xdd, 0x5e, 0x36, 22 | 0xb8, 0xad, 0x8f, 0x61, 0xdb, 0x7e, 0x85, 0xd1 }; 23 | 24 | const uint8_t AESFixture::plaintext[32] = { 25 | 0x53, 0x75, 0x70, 0x65, 0x72, 0x20, 0x73, 0x65, 26 | 0x63, 0x72, 0x65, 0x74, 0x20, 0x6d, 0x65, 0x73, 27 | 0x73, 0x61, 0x67, 0x65, 0x0a, 0x0b, 0x0b, 0x0b, 28 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }; 29 | 30 | 31 | TEST_FIXTURE(AESFixture, SuccessfullyDecryptsOpenSSLExample) 32 | { 33 | unsigned char buf[32]; 34 | memcpy(buf, ciphertext, 32); 35 | 36 | unsigned char iv[16]; 37 | memcpy(iv, credentials + 16, 16); 38 | 39 | aes_context ctx; 40 | aes_setkey_dec(&ctx, credentials, 128); 41 | aes_crypt_cbc(&ctx, AES_DECRYPT, 32, iv, buf, buf); 42 | 43 | CHECK_ARRAY_EQUAL(plaintext, buf, 32); 44 | } 45 | 46 | TEST_FIXTURE(AESFixture, EncryptsSameAsOpenSSL) 47 | { 48 | uint8_t buf[32]; 49 | memcpy(buf, plaintext, 32); 50 | 51 | unsigned char iv[16]; 52 | memcpy(iv, credentials + 16, 16); 53 | 54 | aes_context ctx; 55 | aes_setkey_enc(&ctx, credentials, 128); 56 | /* Note length 21, without PKCS #7 padding */ 57 | aes_crypt_cbc(&ctx, AES_ENCRYPT, 21, iv, buf, buf); 58 | 59 | CHECK_ARRAY_EQUAL(ciphertext, buf, 32); 60 | } 61 | 62 | TEST(AESSelfTestSucceeds) 63 | { 64 | CHECK_EQUAL(0, aes_self_test(0)); 65 | } 66 | -------------------------------------------------------------------------------- /core-communication-lib/tests/TestDescriptor.cpp: -------------------------------------------------------------------------------- 1 | #include "UnitTest++.h" 2 | #include "spark_descriptor.h" 3 | 4 | struct FunctionFixture { 5 | static int execute_a_function(const char *func_key, const char *arg); 6 | static int get_number_of_funcs(void); 7 | static void copy_a_function_key(char *destination, int function_index); 8 | }; 9 | 10 | int FunctionFixture::execute_a_function(const char *func_key, 11 | const char *arg) 12 | { 13 | const char *prevent_warning; 14 | prevent_warning = func_key; 15 | prevent_warning = arg; 16 | return 99; 17 | } 18 | 19 | int FunctionFixture::get_number_of_funcs(void) 20 | { 21 | return 3; 22 | } 23 | 24 | void FunctionFixture::copy_a_function_key(char *destination, int function_index) 25 | { 26 | const char *function_keys[] = { 27 | "brew\0\0\0\0\0\0\0\0", "clean\0\0\0\0\0\0\0", "bean_alert\0\0" }; 28 | memcpy(destination, function_keys[function_index], 12); 29 | } 30 | 31 | SUITE(Descriptor) 32 | { 33 | TEST_FIXTURE(FunctionFixture, DescriptorKnowsNumberOfRegisteredFunctions) 34 | { 35 | SparkDescriptor descriptor; 36 | descriptor.num_functions = get_number_of_funcs; 37 | CHECK_EQUAL(3, descriptor.num_functions()); 38 | } 39 | 40 | TEST_FIXTURE(FunctionFixture, DescriptorCanAccessArrayOfFunctionKeys) 41 | { 42 | SparkDescriptor descriptor; 43 | descriptor.copy_function_key = copy_a_function_key; 44 | char buf[12]; 45 | descriptor.copy_function_key(buf, 2); 46 | CHECK_EQUAL("bean_alert\0\0", buf); 47 | } 48 | 49 | TEST_FIXTURE(FunctionFixture, DescriptorCanCallRegisteredFunction) 50 | { 51 | SparkDescriptor descriptor; 52 | descriptor.call_function = execute_a_function; 53 | const char *function_key = "brew"; 54 | const char *arg = "32,240"; 55 | int return_value = descriptor.call_function(function_key, arg); 56 | CHECK_EQUAL(99, return_value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core-communication-lib/tests/TestStateMachine.cpp: -------------------------------------------------------------------------------- 1 | #include "UnitTest++.h" 2 | #include "spark_protocol.h" 3 | 4 | SUITE(StateMachine) 5 | { 6 | TEST(InitialStateIs_READ_NONCE) 7 | { 8 | SparkProtocol spark_protocol; 9 | ProtocolState::Enum state = spark_protocol.state(); 10 | CHECK_EQUAL(ProtocolState::READ_NONCE, state); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core-communication-lib/tests/TestUserFunctions.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file TestUserFunctions.cpp 4 | * @authors Zachary Crockett 5 | * @version V1.0.0 6 | * @date 10-Jan-2014 7 | * @brief User Function Tests 8 | ****************************************************************************** 9 | Copyright (c) 2014 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #include "UnitTest++.h" 27 | #include "spark_protocol.h" 28 | #include "ConstructorFixture.h" 29 | 30 | SUITE(UserFunctions) 31 | { 32 | TEST_FIXTURE(ConstructorFixture, ArgLen63Succeeds) 33 | { 34 | uint8_t function_call[82] = { 35 | 0x00, 0x50, 36 | 0x94, 0x57, 0x84, 0x8C, 0xDF, 0x53, 0xC1, 0xC2, 37 | 0xF3, 0x59, 0x0C, 0x64, 0xDF, 0xBB, 0x19, 0xB1, 38 | 0x58, 0x55, 0x63, 0x4D, 0x4C, 0x5F, 0x83, 0xA4, 39 | 0xC9, 0x5B, 0x0A, 0x94, 0xDA, 0x62, 0x58, 0x58, 40 | 0x58, 0x1E, 0x17, 0xED, 0x66, 0x0A, 0x3E, 0xEB, 41 | 0x12, 0x10, 0x4C, 0x91, 0x1B, 0xCE, 0x7B, 0x5A, 42 | 0x92, 0xD0, 0x00, 0x45, 0x91, 0x28, 0x5A, 0x99, 43 | 0xE0, 0xAD, 0x43, 0x24, 0x28, 0x46, 0xB6, 0x94, 44 | 0x30, 0x80, 0x6C, 0xD8, 0xF9, 0x0D, 0x15, 0x6F, 45 | 0xFD, 0x5E, 0xCE, 0xB2, 0xFE, 0x57, 0xE8, 0xE3 }; 46 | memcpy(message_to_receive, function_call, 82); 47 | spark_protocol.handshake(); 48 | bytes_received[0] = bytes_sent[0] = 0; 49 | bool success = spark_protocol.event_loop(); 50 | CHECK(success); 51 | } 52 | 53 | TEST_FIXTURE(ConstructorFixture, ArgLen64Fails) 54 | { 55 | uint8_t function_call[82] = { 56 | 0x00, 0x50, 57 | 0x46, 0xE5, 0xBA, 0xEB, 0xD5, 0x31, 0xA3, 0x03, 58 | 0x42, 0x59, 0x19, 0x08, 0x35, 0xCF, 0xC1, 0x63, 59 | 0xF0, 0xED, 0x7F, 0x75, 0x39, 0xFF, 0x6E, 0xDD, 60 | 0x6E, 0xD1, 0x50, 0xA2, 0xAC, 0xC0, 0x39, 0x77, 61 | 0xA3, 0x06, 0x70, 0x88, 0xF8, 0xAC, 0x68, 0x69, 62 | 0xCA, 0xCD, 0xAC, 0x7B, 0x62, 0x74, 0xAF, 0x53, 63 | 0x3E, 0xE2, 0xC4, 0x21, 0x07, 0x8C, 0x67, 0xD1, 64 | 0x3E, 0x2D, 0x6A, 0x76, 0x70, 0x2D, 0x57, 0x55, 65 | 0x82, 0x89, 0xD0, 0xC2, 0xB9, 0x8E, 0x1C, 0xE2, 66 | 0x6E, 0xE3, 0x5E, 0x20, 0xC2, 0x7B, 0x19, 0x1D }; 67 | memcpy(message_to_receive, function_call, 82); 68 | spark_protocol.handshake(); 69 | bytes_received[0] = bytes_sent[0] = 0; 70 | bool success = spark_protocol.event_loop(); 71 | CHECK(!success); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/Makefile: -------------------------------------------------------------------------------- 1 | CXX = g++ 2 | CXXFLAGS ?= -g -Wall -W -Winline -ansi 3 | LDFLAGS ?= 4 | SED = sed 5 | MV = mv 6 | RM = rm 7 | 8 | .SUFFIXES: .o .cpp 9 | 10 | lib = libUnitTest++.a 11 | 12 | src = src/AssertException.cpp \ 13 | src/Test.cpp \ 14 | src/Checks.cpp \ 15 | src/TestRunner.cpp \ 16 | src/TestResults.cpp \ 17 | src/TestReporter.cpp \ 18 | src/TestReporterStdout.cpp \ 19 | src/ReportAssert.cpp \ 20 | src/TestList.cpp \ 21 | src/TimeConstraint.cpp \ 22 | src/TestDetails.cpp \ 23 | src/MemoryOutStream.cpp \ 24 | src/DeferredTestReporter.cpp \ 25 | src/DeferredTestResult.cpp \ 26 | src/XmlTestReporter.cpp \ 27 | src/CurrentTest.cpp 28 | 29 | ifeq ($(MSYSTEM), MINGW32) 30 | src += src/Win32/TimeHelpers.cpp 31 | else 32 | src += src/Posix/SignalTranslator.cpp \ 33 | src/Posix/TimeHelpers.cpp 34 | endif 35 | 36 | objects = $(patsubst %.cpp, %.o, $(src)) 37 | dependencies = $(subst .o,.d,$(objects)) 38 | 39 | define make-depend 40 | $(CXX) $(CXXFLAGS) -M $1 | \ 41 | $(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp 42 | $(SED) -e 's/#.*//' \ 43 | -e 's/^[^:]*: *//' \ 44 | -e 's/ *\\$$//' \ 45 | -e '/^$$/ d' \ 46 | -e 's/$$/ :/' $3.tmp >> $3.tmp 47 | $(MV) $3.tmp $3 48 | endef 49 | 50 | 51 | all: $(lib) 52 | 53 | 54 | $(lib): $(objects) 55 | @echo Creating $(lib) library... 56 | @ar cr $(lib) $(objects) 57 | 58 | clean: 59 | -@$(RM) $(objects) $(dependencies) $(lib) 2> /dev/null 60 | 61 | %.o : %.cpp 62 | @echo $< 63 | @$(call make-depend,$<,$@,$(subst .o,.d,$@)) 64 | @$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<) 65 | 66 | 67 | ifneq "$(MAKECMDGOALS)" "clean" 68 | -include $(dependencies) 69 | endif 70 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/AssertException.cpp: -------------------------------------------------------------------------------- 1 | #include "AssertException.h" 2 | #include 3 | 4 | namespace UnitTest { 5 | 6 | AssertException::AssertException(char const* description, char const* filename, int lineNumber) 7 | : m_lineNumber(lineNumber) 8 | { 9 | using namespace std; 10 | 11 | strcpy(m_description, description); 12 | strcpy(m_filename, filename); 13 | } 14 | 15 | AssertException::~AssertException() throw() 16 | { 17 | } 18 | 19 | char const* AssertException::what() const throw() 20 | { 21 | return m_description; 22 | } 23 | 24 | char const* AssertException::Filename() const 25 | { 26 | return m_filename; 27 | } 28 | 29 | int AssertException::LineNumber() const 30 | { 31 | return m_lineNumber; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/AssertException.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_ASSERTEXCEPTION_H 2 | #define UNITTEST_ASSERTEXCEPTION_H 3 | 4 | #include 5 | 6 | 7 | namespace UnitTest { 8 | 9 | class AssertException : public std::exception 10 | { 11 | public: 12 | AssertException(char const* description, char const* filename, int lineNumber); 13 | virtual ~AssertException() throw(); 14 | 15 | virtual char const* what() const throw(); 16 | 17 | char const* Filename() const; 18 | int LineNumber() const; 19 | 20 | private: 21 | char m_description[512]; 22 | char m_filename[256]; 23 | int m_lineNumber; 24 | }; 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Checks.cpp: -------------------------------------------------------------------------------- 1 | #include "Checks.h" 2 | #include 3 | 4 | namespace UnitTest { 5 | 6 | namespace { 7 | 8 | void CheckStringsEqual(TestResults& results, char const* expected, char const* actual, 9 | TestDetails const& details) 10 | { 11 | using namespace std; 12 | 13 | if (strcmp(expected, actual)) 14 | { 15 | UnitTest::MemoryOutStream stream; 16 | stream << "Expected " << expected << " but was " << actual; 17 | 18 | results.OnTestFailure(details, stream.GetText()); 19 | } 20 | } 21 | 22 | } 23 | 24 | 25 | void CheckEqual(TestResults& results, char const* expected, char const* actual, 26 | TestDetails const& details) 27 | { 28 | CheckStringsEqual(results, expected, actual, details); 29 | } 30 | 31 | void CheckEqual(TestResults& results, char* expected, char* actual, 32 | TestDetails const& details) 33 | { 34 | CheckStringsEqual(results, expected, actual, details); 35 | } 36 | 37 | void CheckEqual(TestResults& results, char* expected, char const* actual, 38 | TestDetails const& details) 39 | { 40 | CheckStringsEqual(results, expected, actual, details); 41 | } 42 | 43 | void CheckEqual(TestResults& results, char const* expected, char* actual, 44 | TestDetails const& details) 45 | { 46 | CheckStringsEqual(results, expected, actual, details); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Config.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_CONFIG_H 2 | #define UNITTEST_CONFIG_H 3 | 4 | // Standard defines documented here: http://predef.sourceforge.net 5 | 6 | #if defined(_MSC_VER) 7 | #pragma warning(disable:4127) // conditional expression is constant 8 | #pragma warning(disable:4702) // unreachable code 9 | #pragma warning(disable:4722) // destructor never returns, potential memory leak 10 | 11 | #if (_MSC_VER == 1200) // VC6 12 | #pragma warning(disable:4786) 13 | #pragma warning(disable:4290) 14 | #endif 15 | #endif 16 | 17 | #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ 18 | defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 19 | #define UNITTEST_POSIX 20 | #endif 21 | 22 | #if defined(__MINGW32__) 23 | #define UNITTEST_MINGW 24 | #endif 25 | 26 | // by default, MemoryOutStream is implemented in terms of std::ostringstream, which can be expensive. 27 | // uncomment this line to use the custom MemoryOutStream (no deps on std::ostringstream). 28 | 29 | //#define UNITTEST_USE_CUSTOM_STREAMS 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/CurrentTest.cpp: -------------------------------------------------------------------------------- 1 | #include "CurrentTest.h" 2 | #include 3 | 4 | namespace UnitTest { 5 | 6 | TestResults*& CurrentTest::Results() 7 | { 8 | static TestResults* testResults = NULL; 9 | return testResults; 10 | } 11 | 12 | const TestDetails*& CurrentTest::Details() 13 | { 14 | static const TestDetails* testDetails = NULL; 15 | return testDetails; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/CurrentTest.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_CURRENTTESTRESULTS_H 2 | #define UNITTEST_CURRENTTESTRESULTS_H 3 | 4 | namespace UnitTest { 5 | 6 | class TestResults; 7 | class TestDetails; 8 | 9 | namespace CurrentTest 10 | { 11 | TestResults*& Results(); 12 | const TestDetails*& Details(); 13 | } 14 | 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/DeferredTestReporter.cpp: -------------------------------------------------------------------------------- 1 | #include "DeferredTestReporter.h" 2 | #include "TestDetails.h" 3 | 4 | using namespace UnitTest; 5 | 6 | void DeferredTestReporter::ReportTestStart(TestDetails const& details) 7 | { 8 | m_results.push_back(DeferredTestResult(details.suiteName, details.testName)); 9 | } 10 | 11 | void DeferredTestReporter::ReportFailure(TestDetails const& details, char const* failure) 12 | { 13 | DeferredTestResult& r = m_results.back(); 14 | r.failed = true; 15 | r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure)); 16 | r.failureFile = details.filename; 17 | } 18 | 19 | void DeferredTestReporter::ReportTestFinish(TestDetails const&, float secondsElapsed) 20 | { 21 | DeferredTestResult& r = m_results.back(); 22 | r.timeElapsed = secondsElapsed; 23 | } 24 | 25 | DeferredTestReporter::DeferredTestResultList& DeferredTestReporter::GetResults() 26 | { 27 | return m_results; 28 | } 29 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/DeferredTestReporter.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_DEFERREDTESTREPORTER_H 2 | #define UNITTEST_DEFERREDTESTREPORTER_H 3 | 4 | #include "TestReporter.h" 5 | #include "DeferredTestResult.h" 6 | #include "Config.h" 7 | 8 | #include 9 | 10 | namespace UnitTest 11 | { 12 | 13 | class DeferredTestReporter : public TestReporter 14 | { 15 | public: 16 | virtual void ReportTestStart(TestDetails const& details); 17 | virtual void ReportFailure(TestDetails const& details, char const* failure); 18 | virtual void ReportTestFinish(TestDetails const& details, float secondsElapsed); 19 | 20 | typedef std::vector< DeferredTestResult > DeferredTestResultList; 21 | DeferredTestResultList& GetResults(); 22 | 23 | private: 24 | DeferredTestResultList m_results; 25 | }; 26 | 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/DeferredTestResult.cpp: -------------------------------------------------------------------------------- 1 | #include "DeferredTestResult.h" 2 | #include "Config.h" 3 | 4 | namespace UnitTest 5 | { 6 | 7 | DeferredTestResult::DeferredTestResult() 8 | : suiteName("") 9 | , testName("") 10 | , failureFile("") 11 | , timeElapsed(0.0f) 12 | , failed(false) 13 | { 14 | } 15 | 16 | DeferredTestResult::DeferredTestResult(char const* suite, char const* test) 17 | : suiteName(suite) 18 | , testName(test) 19 | , failureFile("") 20 | , timeElapsed(0.0f) 21 | , failed(false) 22 | { 23 | } 24 | 25 | DeferredTestResult::~DeferredTestResult() 26 | { 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/DeferredTestResult.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_DEFERREDTESTRESULT_H 2 | #define UNITTEST_DEFERREDTESTRESULT_H 3 | 4 | #include "Config.h" 5 | 6 | #include 7 | #include 8 | 9 | namespace UnitTest 10 | { 11 | 12 | struct DeferredTestResult 13 | { 14 | DeferredTestResult(); 15 | DeferredTestResult(char const* suite, char const* test); 16 | ~DeferredTestResult(); 17 | 18 | std::string suiteName; 19 | std::string testName; 20 | std::string failureFile; 21 | 22 | typedef std::pair< int, std::string > Failure; 23 | typedef std::vector< Failure > FailureVec; 24 | FailureVec failures; 25 | 26 | float timeElapsed; 27 | bool failed; 28 | }; 29 | 30 | } 31 | 32 | #endif //UNITTEST_DEFERREDTESTRESULT_H 33 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/ExecuteTest.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_EXECUTE_TEST_H 2 | #define UNITTEST_EXECUTE_TEST_H 3 | 4 | #include "TestDetails.h" 5 | #include "MemoryOutStream.h" 6 | #include "AssertException.h" 7 | #include "CurrentTest.h" 8 | 9 | #ifdef UNITTEST_POSIX 10 | #include "Posix/SignalTranslator.h" 11 | #endif 12 | 13 | namespace UnitTest { 14 | 15 | template< typename T > 16 | void ExecuteTest(T& testObject, TestDetails const& details) 17 | { 18 | CurrentTest::Details() = &details; 19 | 20 | try 21 | { 22 | #ifdef UNITTEST_POSIX 23 | UNITTEST_THROW_SIGNALS 24 | #endif 25 | testObject.RunImpl(); 26 | } 27 | catch (AssertException const& e) 28 | { 29 | CurrentTest::Results()->OnTestFailure( 30 | TestDetails(details.testName, details.suiteName, e.Filename(), e.LineNumber()), e.what()); 31 | } 32 | catch (std::exception const& e) 33 | { 34 | MemoryOutStream stream; 35 | stream << "Unhandled exception: " << e.what(); 36 | CurrentTest::Results()->OnTestFailure(details, stream.GetText()); 37 | } 38 | catch (...) 39 | { 40 | CurrentTest::Results()->OnTestFailure(details, "Unhandled exception: Crash!"); 41 | } 42 | } 43 | 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/MemoryOutStream.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_MEMORYOUTSTREAM_H 2 | #define UNITTEST_MEMORYOUTSTREAM_H 3 | 4 | #include "Config.h" 5 | 6 | #ifndef UNITTEST_USE_CUSTOM_STREAMS 7 | 8 | #include 9 | 10 | namespace UnitTest 11 | { 12 | 13 | class MemoryOutStream : public std::ostringstream 14 | { 15 | public: 16 | MemoryOutStream() {} 17 | ~MemoryOutStream() {} 18 | char const* GetText() const; 19 | 20 | private: 21 | MemoryOutStream(MemoryOutStream const&); 22 | void operator =(MemoryOutStream const&); 23 | 24 | mutable std::string m_text; 25 | }; 26 | 27 | } 28 | 29 | #else 30 | 31 | #include 32 | 33 | namespace UnitTest 34 | { 35 | 36 | class MemoryOutStream 37 | { 38 | public: 39 | explicit MemoryOutStream(int const size = 256); 40 | ~MemoryOutStream(); 41 | 42 | char const* GetText() const; 43 | 44 | MemoryOutStream& operator << (char const* txt); 45 | MemoryOutStream& operator << (int n); 46 | MemoryOutStream& operator << (long n); 47 | MemoryOutStream& operator << (unsigned long n); 48 | MemoryOutStream& operator << (float f); 49 | MemoryOutStream& operator << (double d); 50 | MemoryOutStream& operator << (void const* p); 51 | MemoryOutStream& operator << (unsigned int s); 52 | 53 | enum { GROW_CHUNK_SIZE = 32 }; 54 | int GetCapacity() const; 55 | 56 | private: 57 | void operator= (MemoryOutStream const&); 58 | void GrowBuffer(int capacity); 59 | 60 | int m_capacity; 61 | char* m_buffer; 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Posix/SignalTranslator.cpp: -------------------------------------------------------------------------------- 1 | #include "SignalTranslator.h" 2 | 3 | namespace UnitTest { 4 | 5 | sigjmp_buf* SignalTranslator::s_jumpTarget = 0; 6 | 7 | namespace { 8 | 9 | void SignalHandler(int sig) 10 | { 11 | siglongjmp(*SignalTranslator::s_jumpTarget, sig ); 12 | } 13 | 14 | } 15 | 16 | 17 | SignalTranslator::SignalTranslator() 18 | { 19 | m_oldJumpTarget = s_jumpTarget; 20 | s_jumpTarget = &m_currentJumpTarget; 21 | 22 | struct sigaction action; 23 | action.sa_flags = 0; 24 | action.sa_handler = SignalHandler; 25 | sigemptyset( &action.sa_mask ); 26 | 27 | sigaction( SIGSEGV, &action, &m_old_SIGSEGV_action ); 28 | sigaction( SIGFPE , &action, &m_old_SIGFPE_action ); 29 | sigaction( SIGTRAP, &action, &m_old_SIGTRAP_action ); 30 | sigaction( SIGBUS , &action, &m_old_SIGBUS_action ); 31 | sigaction( SIGILL , &action, &m_old_SIGBUS_action ); 32 | } 33 | 34 | SignalTranslator::~SignalTranslator() 35 | { 36 | sigaction( SIGILL , &m_old_SIGBUS_action , 0 ); 37 | sigaction( SIGBUS , &m_old_SIGBUS_action , 0 ); 38 | sigaction( SIGTRAP, &m_old_SIGTRAP_action, 0 ); 39 | sigaction( SIGFPE , &m_old_SIGFPE_action , 0 ); 40 | sigaction( SIGSEGV, &m_old_SIGSEGV_action, 0 ); 41 | 42 | s_jumpTarget = m_oldJumpTarget; 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Posix/SignalTranslator.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_SIGNALTRANSLATOR_H 2 | #define UNITTEST_SIGNALTRANSLATOR_H 3 | 4 | #include 5 | #include 6 | 7 | namespace UnitTest { 8 | 9 | class SignalTranslator 10 | { 11 | public: 12 | SignalTranslator(); 13 | ~SignalTranslator(); 14 | 15 | static sigjmp_buf* s_jumpTarget; 16 | 17 | private: 18 | sigjmp_buf m_currentJumpTarget; 19 | sigjmp_buf* m_oldJumpTarget; 20 | 21 | struct sigaction m_old_SIGFPE_action; 22 | struct sigaction m_old_SIGTRAP_action; 23 | struct sigaction m_old_SIGSEGV_action; 24 | struct sigaction m_old_SIGBUS_action; 25 | struct sigaction m_old_SIGABRT_action; 26 | struct sigaction m_old_SIGALRM_action; 27 | }; 28 | 29 | #if !defined (__GNUC__) 30 | #define UNITTEST_EXTENSION 31 | #else 32 | #define UNITTEST_EXTENSION __extension__ 33 | #endif 34 | 35 | #define UNITTEST_THROW_SIGNALS \ 36 | UnitTest::SignalTranslator sig; \ 37 | if (UNITTEST_EXTENSION sigsetjmp(*UnitTest::SignalTranslator::s_jumpTarget, 1) != 0) \ 38 | throw ("Unhandled system exception"); 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Posix/TimeHelpers.cpp: -------------------------------------------------------------------------------- 1 | #include "TimeHelpers.h" 2 | #include 3 | 4 | namespace UnitTest { 5 | 6 | Timer::Timer() 7 | { 8 | m_startTime.tv_sec = 0; 9 | m_startTime.tv_usec = 0; 10 | } 11 | 12 | void Timer::Start() 13 | { 14 | gettimeofday(&m_startTime, 0); 15 | } 16 | 17 | double Timer::GetTimeInMs() const 18 | { 19 | struct timeval currentTime; 20 | gettimeofday(¤tTime, 0); 21 | 22 | double const dsecs = currentTime.tv_sec - m_startTime.tv_sec; 23 | double const dus = currentTime.tv_usec - m_startTime.tv_usec; 24 | 25 | return (dsecs * 1000.0) + (dus / 1000.0); 26 | } 27 | 28 | void TimeHelpers::SleepMs(int ms) 29 | { 30 | usleep(ms * 1000); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Posix/TimeHelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TIMEHELPERS_H 2 | #define UNITTEST_TIMEHELPERS_H 3 | 4 | #include 5 | 6 | namespace UnitTest { 7 | 8 | class Timer 9 | { 10 | public: 11 | Timer(); 12 | void Start(); 13 | double GetTimeInMs() const; 14 | 15 | private: 16 | struct timeval m_startTime; 17 | }; 18 | 19 | 20 | namespace TimeHelpers 21 | { 22 | void SleepMs (int ms); 23 | } 24 | 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/ReportAssert.cpp: -------------------------------------------------------------------------------- 1 | #include "ReportAssert.h" 2 | #include "AssertException.h" 3 | 4 | namespace UnitTest { 5 | 6 | void ReportAssert(char const* description, char const* filename, int lineNumber) 7 | { 8 | throw AssertException(description, filename, lineNumber); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/ReportAssert.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_ASSERT_H 2 | #define UNITTEST_ASSERT_H 3 | 4 | namespace UnitTest { 5 | 6 | void ReportAssert(char const* description, char const* filename, int lineNumber); 7 | 8 | } 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "Config.h" 2 | #include "Test.h" 3 | #include "TestList.h" 4 | #include "TestResults.h" 5 | #include "AssertException.h" 6 | #include "MemoryOutStream.h" 7 | #include "ExecuteTest.h" 8 | 9 | #ifdef UNITTEST_POSIX 10 | #include "Posix/SignalTranslator.h" 11 | #endif 12 | 13 | namespace UnitTest { 14 | 15 | TestList& Test::GetTestList() 16 | { 17 | static TestList s_list; 18 | return s_list; 19 | } 20 | 21 | Test::Test(char const* testName, char const* suiteName, char const* filename, int lineNumber) 22 | : m_details(testName, suiteName, filename, lineNumber) 23 | , next(0) 24 | , m_timeConstraintExempt(false) 25 | { 26 | } 27 | 28 | Test::~Test() 29 | { 30 | } 31 | 32 | void Test::Run() 33 | { 34 | ExecuteTest(*this, m_details); 35 | } 36 | 37 | void Test::RunImpl() const 38 | { 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Test.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TEST_H 2 | #define UNITTEST_TEST_H 3 | 4 | #include "TestDetails.h" 5 | 6 | namespace UnitTest { 7 | 8 | class TestResults; 9 | class TestList; 10 | 11 | class Test 12 | { 13 | public: 14 | explicit Test(char const* testName, char const* suiteName = "DefaultSuite", char const* filename = "", int lineNumber = 0); 15 | virtual ~Test(); 16 | void Run(); 17 | 18 | TestDetails const m_details; 19 | Test* next; 20 | mutable bool m_timeConstraintExempt; 21 | 22 | static TestList& GetTestList(); 23 | 24 | virtual void RunImpl() const; 25 | 26 | private: 27 | Test(Test const&); 28 | Test& operator =(Test const&); 29 | }; 30 | 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestDetails.cpp: -------------------------------------------------------------------------------- 1 | #include "TestDetails.h" 2 | 3 | namespace UnitTest { 4 | 5 | TestDetails::TestDetails(char const* testName_, char const* suiteName_, char const* filename_, int lineNumber_) 6 | : suiteName(suiteName_) 7 | , testName(testName_) 8 | , filename(filename_) 9 | , lineNumber(lineNumber_) 10 | { 11 | } 12 | 13 | TestDetails::TestDetails(const TestDetails& details, int lineNumber_) 14 | : suiteName(details.suiteName) 15 | , testName(details.testName) 16 | , filename(details.filename) 17 | , lineNumber(lineNumber_) 18 | { 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestDetails.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTDETAILS_H 2 | #define UNITTEST_TESTDETAILS_H 3 | 4 | namespace UnitTest { 5 | 6 | class TestDetails 7 | { 8 | public: 9 | TestDetails(char const* testName, char const* suiteName, char const* filename, int lineNumber); 10 | TestDetails(const TestDetails& details, int lineNumber); 11 | 12 | char const* const suiteName; 13 | char const* const testName; 14 | char const* const filename; 15 | int const lineNumber; 16 | 17 | TestDetails(TestDetails const&); // Why is it public? --> http://gcc.gnu.org/bugs.html#cxx_rvalbind 18 | private: 19 | TestDetails& operator=(TestDetails const&); 20 | }; 21 | 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestList.cpp: -------------------------------------------------------------------------------- 1 | #include "TestList.h" 2 | #include "Test.h" 3 | 4 | #include 5 | 6 | namespace UnitTest { 7 | 8 | TestList::TestList() 9 | : m_head(0) 10 | , m_tail(0) 11 | { 12 | } 13 | 14 | void TestList::Add(Test* test) 15 | { 16 | if (m_tail == 0) 17 | { 18 | assert(m_head == 0); 19 | m_head = test; 20 | m_tail = test; 21 | } 22 | else 23 | { 24 | m_tail->next = test; 25 | m_tail = test; 26 | } 27 | } 28 | 29 | Test* TestList::GetHead() const 30 | { 31 | return m_head; 32 | } 33 | 34 | ListAdder::ListAdder(TestList& list, Test* test) 35 | { 36 | list.Add(test); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestList.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTLIST_H 2 | #define UNITTEST_TESTLIST_H 3 | 4 | 5 | namespace UnitTest { 6 | 7 | class Test; 8 | 9 | class TestList 10 | { 11 | public: 12 | TestList(); 13 | void Add (Test* test); 14 | 15 | Test* GetHead() const; 16 | 17 | private: 18 | Test* m_head; 19 | Test* m_tail; 20 | }; 21 | 22 | 23 | class ListAdder 24 | { 25 | public: 26 | ListAdder(TestList& list, Test* test); 27 | }; 28 | 29 | } 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestReporter.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReporter.h" 2 | 3 | namespace UnitTest { 4 | 5 | 6 | TestReporter::~TestReporter() 7 | { 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestReporter.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTREPORTER_H 2 | #define UNITTEST_TESTREPORTER_H 3 | 4 | namespace UnitTest { 5 | 6 | class TestDetails; 7 | 8 | class TestReporter 9 | { 10 | public: 11 | virtual ~TestReporter(); 12 | 13 | virtual void ReportTestStart(TestDetails const& test) = 0; 14 | virtual void ReportFailure(TestDetails const& test, char const* failure) = 0; 15 | virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed) = 0; 16 | virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed) = 0; 17 | }; 18 | 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestReporterStdout.cpp: -------------------------------------------------------------------------------- 1 | #include "TestReporterStdout.h" 2 | #include 3 | 4 | #include "TestDetails.h" 5 | 6 | // cstdio doesn't pull in namespace std on VC6, so we do it here. 7 | #if defined(_MSC_VER) && (_MSC_VER == 1200) 8 | namespace std {} 9 | #endif 10 | 11 | namespace UnitTest { 12 | 13 | void TestReporterStdout::ReportFailure(TestDetails const& details, char const* failure) 14 | { 15 | #if defined(__APPLE__) || defined(__GNUG__) 16 | char const* const errorFormat = "%s:%d: error: Failure in %s: %s\n"; 17 | #else 18 | char const* const errorFormat = "%s(%d): error: Failure in %s: %s\n"; 19 | #endif 20 | 21 | using namespace std; 22 | printf(errorFormat, details.filename, details.lineNumber, details.testName, failure); 23 | } 24 | 25 | void TestReporterStdout::ReportTestStart(TestDetails const& /*test*/) 26 | { 27 | } 28 | 29 | void TestReporterStdout::ReportTestFinish(TestDetails const& /*test*/, float) 30 | { 31 | } 32 | 33 | void TestReporterStdout::ReportSummary(int const totalTestCount, int const failedTestCount, 34 | int const failureCount, float secondsElapsed) 35 | { 36 | using namespace std; 37 | 38 | if (failureCount > 0) 39 | printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount); 40 | else 41 | printf("Success: %d tests passed.\n", totalTestCount); 42 | 43 | printf("Test time: %.2f seconds.\n", secondsElapsed); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestReporterStdout.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTREPORTERSTDOUT_H 2 | #define UNITTEST_TESTREPORTERSTDOUT_H 3 | 4 | #include "TestReporter.h" 5 | 6 | namespace UnitTest { 7 | 8 | class TestReporterStdout : public TestReporter 9 | { 10 | private: 11 | virtual void ReportTestStart(TestDetails const& test); 12 | virtual void ReportFailure(TestDetails const& test, char const* failure); 13 | virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed); 14 | virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); 15 | }; 16 | 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestResults.cpp: -------------------------------------------------------------------------------- 1 | #include "TestResults.h" 2 | #include "TestReporter.h" 3 | 4 | #include "TestDetails.h" 5 | 6 | namespace UnitTest { 7 | 8 | TestResults::TestResults(TestReporter* testReporter) 9 | : m_testReporter(testReporter) 10 | , m_totalTestCount(0) 11 | , m_failedTestCount(0) 12 | , m_failureCount(0) 13 | , m_currentTestFailed(false) 14 | { 15 | } 16 | 17 | void TestResults::OnTestStart(TestDetails const& test) 18 | { 19 | ++m_totalTestCount; 20 | m_currentTestFailed = false; 21 | if (m_testReporter) 22 | m_testReporter->ReportTestStart(test); 23 | } 24 | 25 | void TestResults::OnTestFailure(TestDetails const& test, char const* failure) 26 | { 27 | ++m_failureCount; 28 | if (!m_currentTestFailed) 29 | { 30 | ++m_failedTestCount; 31 | m_currentTestFailed = true; 32 | } 33 | 34 | if (m_testReporter) 35 | m_testReporter->ReportFailure(test, failure); 36 | } 37 | 38 | void TestResults::OnTestFinish(TestDetails const& test, float secondsElapsed) 39 | { 40 | if (m_testReporter) 41 | m_testReporter->ReportTestFinish(test, secondsElapsed); 42 | } 43 | 44 | int TestResults::GetTotalTestCount() const 45 | { 46 | return m_totalTestCount; 47 | } 48 | 49 | int TestResults::GetFailedTestCount() const 50 | { 51 | return m_failedTestCount; 52 | } 53 | 54 | int TestResults::GetFailureCount() const 55 | { 56 | return m_failureCount; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestResults.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTRESULTS_H 2 | #define UNITTEST_TESTRESULTS_H 3 | 4 | namespace UnitTest { 5 | 6 | class TestReporter; 7 | class TestDetails; 8 | 9 | class TestResults 10 | { 11 | public: 12 | explicit TestResults(TestReporter* reporter = 0); 13 | 14 | void OnTestStart(TestDetails const& test); 15 | void OnTestFailure(TestDetails const& test, char const* failure); 16 | void OnTestFinish(TestDetails const& test, float secondsElapsed); 17 | 18 | int GetTotalTestCount() const; 19 | int GetFailedTestCount() const; 20 | int GetFailureCount() const; 21 | 22 | private: 23 | TestReporter* m_testReporter; 24 | int m_totalTestCount; 25 | int m_failedTestCount; 26 | int m_failureCount; 27 | 28 | bool m_currentTestFailed; 29 | 30 | TestResults(TestResults const&); 31 | TestResults& operator =(TestResults const&); 32 | }; 33 | 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestRunner.cpp: -------------------------------------------------------------------------------- 1 | #include "TestRunner.h" 2 | #include "TestResults.h" 3 | #include "TestReporter.h" 4 | #include "TestReporterStdout.h" 5 | #include "TimeHelpers.h" 6 | #include "MemoryOutStream.h" 7 | 8 | #include 9 | 10 | 11 | namespace UnitTest { 12 | 13 | int RunAllTests() 14 | { 15 | TestReporterStdout reporter; 16 | TestRunner runner(reporter); 17 | return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0); 18 | } 19 | 20 | 21 | TestRunner::TestRunner(TestReporter& reporter) 22 | : m_reporter(&reporter) 23 | , m_result(new TestResults(&reporter)) 24 | , m_timer(new Timer) 25 | { 26 | m_timer->Start(); 27 | } 28 | 29 | TestRunner::~TestRunner() 30 | { 31 | delete m_result; 32 | delete m_timer; 33 | } 34 | 35 | int TestRunner::Finish() const 36 | { 37 | float const secondsElapsed = static_cast(m_timer->GetTimeInMs() / 1000.0); 38 | m_reporter->ReportSummary(m_result->GetTotalTestCount(), 39 | m_result->GetFailedTestCount(), 40 | m_result->GetFailureCount(), 41 | secondsElapsed); 42 | 43 | return m_result->GetFailureCount(); 44 | } 45 | 46 | bool TestRunner::IsTestInSuite(const Test* const curTest, char const* suiteName) const 47 | { 48 | using namespace std; 49 | return (suiteName == NULL) || !strcmp(curTest->m_details.suiteName, suiteName); 50 | } 51 | 52 | void TestRunner::RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const 53 | { 54 | CurrentTest::Results() = result; 55 | 56 | Timer testTimer; 57 | testTimer.Start(); 58 | 59 | result->OnTestStart(curTest->m_details); 60 | 61 | curTest->Run(); 62 | 63 | double const testTimeInMs = testTimer.GetTimeInMs(); 64 | if (maxTestTimeInMs > 0 && testTimeInMs > maxTestTimeInMs && !curTest->m_timeConstraintExempt) 65 | { 66 | MemoryOutStream stream; 67 | stream << "Global time constraint failed. Expected under " << maxTestTimeInMs << 68 | "ms but took " << testTimeInMs << "ms."; 69 | 70 | result->OnTestFailure(curTest->m_details, stream.GetText()); 71 | } 72 | 73 | result->OnTestFinish(curTest->m_details, static_cast(testTimeInMs/1000.0)); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestRunner.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTRUNNER_H 2 | #define UNITTEST_TESTRUNNER_H 3 | 4 | #include "Test.h" 5 | #include "TestList.h" 6 | #include "CurrentTest.h" 7 | 8 | namespace UnitTest { 9 | 10 | class TestReporter; 11 | class TestResults; 12 | class Timer; 13 | 14 | int RunAllTests(); 15 | 16 | struct True 17 | { 18 | bool operator()(const Test* const) const 19 | { 20 | return true; 21 | } 22 | }; 23 | 24 | class TestRunner 25 | { 26 | public: 27 | explicit TestRunner(TestReporter& reporter); 28 | ~TestRunner(); 29 | 30 | template 31 | int RunTestsIf(TestList const& list, char const* suiteName, 32 | const Predicate& predicate, int maxTestTimeInMs) const 33 | { 34 | Test* curTest = list.GetHead(); 35 | 36 | while (curTest != 0) 37 | { 38 | if (IsTestInSuite(curTest, suiteName) && predicate(curTest)) 39 | RunTest(m_result, curTest, maxTestTimeInMs); 40 | 41 | curTest = curTest->next; 42 | } 43 | 44 | return Finish(); 45 | } 46 | 47 | private: 48 | TestReporter* m_reporter; 49 | TestResults* m_result; 50 | Timer* m_timer; 51 | 52 | int Finish() const; 53 | bool IsTestInSuite(const Test* const curTest, char const* suiteName) const; 54 | void RunTest(TestResults* const result, Test* const curTest, int const maxTestTimeInMs) const; 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TestSuite.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TESTSUITE_H 2 | #define UNITTEST_TESTSUITE_H 3 | 4 | namespace UnitTestSuite 5 | { 6 | inline char const* GetSuiteName () 7 | { 8 | return "DefaultSuite"; 9 | } 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TimeConstraint.cpp: -------------------------------------------------------------------------------- 1 | #include "TimeConstraint.h" 2 | #include "TestResults.h" 3 | #include "MemoryOutStream.h" 4 | #include "CurrentTest.h" 5 | 6 | namespace UnitTest { 7 | 8 | 9 | TimeConstraint::TimeConstraint(int ms, TestDetails const& details) 10 | : m_details(details) 11 | , m_maxMs(ms) 12 | { 13 | m_timer.Start(); 14 | } 15 | 16 | TimeConstraint::~TimeConstraint() 17 | { 18 | double const totalTimeInMs = m_timer.GetTimeInMs(); 19 | if (totalTimeInMs > m_maxMs) 20 | { 21 | MemoryOutStream stream; 22 | stream << "Time constraint failed. Expected to run test under " << m_maxMs << 23 | "ms but took " << totalTimeInMs << "ms."; 24 | 25 | UnitTest::CurrentTest::Results()->OnTestFailure(m_details, stream.GetText()); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TimeConstraint.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TIMECONSTRAINT_H 2 | #define UNITTEST_TIMECONSTRAINT_H 3 | 4 | #include "TimeHelpers.h" 5 | 6 | namespace UnitTest { 7 | 8 | class TestResults; 9 | class TestDetails; 10 | 11 | class TimeConstraint 12 | { 13 | public: 14 | TimeConstraint(int ms, TestDetails const& details); 15 | ~TimeConstraint(); 16 | 17 | private: 18 | void operator=(TimeConstraint const&); 19 | TimeConstraint(TimeConstraint const&); 20 | 21 | Timer m_timer; 22 | TestDetails const& m_details; 23 | int const m_maxMs; 24 | }; 25 | 26 | #define UNITTEST_TIME_CONSTRAINT(ms) \ 27 | UnitTest::TimeConstraint unitTest__timeConstraint__(ms, UnitTest::TestDetails(m_details, __LINE__)) 28 | 29 | #define UNITTEST_TIME_CONSTRAINT_EXEMPT() do { m_timeConstraintExempt = true; } while (0) 30 | 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/TimeHelpers.h: -------------------------------------------------------------------------------- 1 | #include "Config.h" 2 | 3 | #if defined UNITTEST_POSIX 4 | #include "Posix/TimeHelpers.h" 5 | #else 6 | #include "Win32/TimeHelpers.h" 7 | #endif 8 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/UnitTest++.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTESTCPP_H 2 | #define UNITTESTCPP_H 3 | 4 | //lint -esym(1509,*Fixture) 5 | 6 | #include "Config.h" 7 | #include "Test.h" 8 | #include "TestList.h" 9 | #include "TestSuite.h" 10 | #include "TestResults.h" 11 | 12 | #include "TestMacros.h" 13 | 14 | #include "CheckMacros.h" 15 | #include "TestRunner.h" 16 | #include "TimeConstraint.h" 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Win32/TimeHelpers.cpp: -------------------------------------------------------------------------------- 1 | #include "TimeHelpers.h" 2 | #include 3 | 4 | namespace UnitTest { 5 | 6 | Timer::Timer() 7 | : m_threadHandle(::GetCurrentThread()) 8 | , m_startTime(0) 9 | { 10 | #if defined(_MSC_VER) && (_MSC_VER == 1200) // VC6 doesn't have DWORD_PTR? 11 | typedef unsigned long DWORD_PTR; 12 | #endif 13 | 14 | DWORD_PTR systemMask; 15 | ::GetProcessAffinityMask(GetCurrentProcess(), &m_processAffinityMask, &systemMask); 16 | ::SetThreadAffinityMask(m_threadHandle, 1); 17 | ::QueryPerformanceFrequency(reinterpret_cast< LARGE_INTEGER* >(&m_frequency)); 18 | ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); 19 | } 20 | 21 | void Timer::Start() 22 | { 23 | m_startTime = GetTime(); 24 | } 25 | 26 | double Timer::GetTimeInMs() const 27 | { 28 | __int64 const elapsedTime = GetTime() - m_startTime; 29 | double const seconds = double(elapsedTime) / double(m_frequency); 30 | return seconds * 1000.0; 31 | } 32 | 33 | __int64 Timer::GetTime() const 34 | { 35 | LARGE_INTEGER curTime; 36 | ::SetThreadAffinityMask(m_threadHandle, 1); 37 | ::QueryPerformanceCounter(&curTime); 38 | ::SetThreadAffinityMask(m_threadHandle, m_processAffinityMask); 39 | return curTime.QuadPart; 40 | } 41 | 42 | void TimeHelpers::SleepMs(int const ms) 43 | { 44 | ::Sleep(ms); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/Win32/TimeHelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_TIMEHELPERS_H 2 | #define UNITTEST_TIMEHELPERS_H 3 | 4 | #include "../Config.h" 5 | 6 | 7 | #ifdef UNITTEST_MINGW 8 | #ifndef __int64 9 | #define __int64 long long 10 | #endif 11 | #endif 12 | 13 | namespace UnitTest { 14 | 15 | class Timer 16 | { 17 | public: 18 | Timer(); 19 | void Start(); 20 | double GetTimeInMs() const; 21 | 22 | private: 23 | __int64 GetTime() const; 24 | 25 | void* m_threadHandle; 26 | 27 | #if defined(_WIN64) 28 | unsigned __int64 m_processAffinityMask; 29 | #else 30 | unsigned long m_processAffinityMask; 31 | #endif 32 | 33 | __int64 m_startTime; 34 | __int64 m_frequency; 35 | }; 36 | 37 | 38 | namespace TimeHelpers 39 | { 40 | void SleepMs (int ms); 41 | } 42 | 43 | 44 | } 45 | 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /core-communication-lib/tests/UnitTest++/src/XmlTestReporter.h: -------------------------------------------------------------------------------- 1 | #ifndef UNITTEST_XMLTESTREPORTER_H 2 | #define UNITTEST_XMLTESTREPORTER_H 3 | 4 | #include "DeferredTestReporter.h" 5 | 6 | #include 7 | 8 | namespace UnitTest 9 | { 10 | 11 | class XmlTestReporter : public DeferredTestReporter 12 | { 13 | public: 14 | explicit XmlTestReporter(std::ostream& ostream); 15 | 16 | virtual void ReportSummary(int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); 17 | 18 | private: 19 | XmlTestReporter(XmlTestReporter const&); 20 | XmlTestReporter& operator=(XmlTestReporter const&); 21 | 22 | void AddXmlElement(std::ostream& os, char const* encoding); 23 | void BeginResults(std::ostream& os, int totalTestCount, int failedTestCount, int failureCount, float secondsElapsed); 24 | void EndResults(std::ostream& os); 25 | void BeginTest(std::ostream& os, DeferredTestResult const& result); 26 | void AddFailure(std::ostream& os, DeferredTestResult const& result); 27 | void EndTest(std::ostream& os, DeferredTestResult const& result); 28 | 29 | std::ostream& m_ostream; 30 | }; 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /core-firmware/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | # Debug folder 20 | Debug/* 21 | 22 | # Release folder 23 | Release/* 24 | 25 | # build folder 26 | *.map 27 | *.lst 28 | *.d 29 | *.o 30 | 31 | # Platform-specific settings 32 | .settings/* 33 | .cproject 34 | .project 35 | 36 | # Raisonance RIDE Project 37 | RIDE/* 38 | 39 | # backup folder 40 | backup/* 41 | 42 | # Arduino libraries 43 | libraries/Arduino/ 44 | 45 | # TropicSSL libraries 46 | libraries/Tropicssl/ 47 | -------------------------------------------------------------------------------- /core-firmware/build/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled objects and dependancies 2 | obj/ -------------------------------------------------------------------------------- /core-firmware/build/dfu.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #EXPRESS OR 4 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #MERCHANTABILITY, 5 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO #EVENT SHALL THE 6 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR #OTHER 7 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #ARISING FROM, 8 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #DEALINGS IN 9 | * THE SOFTWARE. 10 | * Copyright (c) 2014 NaAl (h20@alocreative.com) 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | */ 21 | var WebSocket = require('ws') 22 | , ws = new WebSocket('ws://:PORT'); 23 | ws.on('open', function() { 24 | ws.send('/dfu'); 25 | }); 26 | ws.on('message', function(message) { 27 | console.log('received: %s', message); 28 | if(message == "going to dfu mode") { 29 | setInterval(function() { 30 | process.exit(0); 31 | }, 3000); 32 | } 33 | 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /core-firmware/build/doit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ###################################################################################### 3 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #EXPRESS OR 4 | #MPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #MERCHANTABILITY, 5 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO #EVENT SHALL THE 6 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR #OTHER 7 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #ARISING FROM, 8 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #DEALINGS IN 9 | #THE SOFTWARE. 10 | #Copyright (c) 2014 NaAl (h20@alocreative.com) 11 | #Permission is hereby granted, free of charge, to any person obtaining a copy 12 | #of this software and associated documentation files (the "Software"), to deal 13 | #in the Software without restriction, including without limitation the rights 14 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | #copies of the Software, and to permit persons to whom the Software is 16 | #furnished to do so, subject to the following conditions: 17 | 18 | #The above copyright notice and this permission notice shall be included in 19 | #all copies or substantial portions of the Software. 20 | ###################################################################################### 21 | nodejs dfu.js 22 | echo "make $*" 23 | make $* 24 | if [ "$?" == "0" ]; then 25 | sudo dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin 26 | fi 27 | -------------------------------------------------------------------------------- /core-firmware/build/html/bed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 33 | 34 |
35 | 36 |

Page Header

37 |
38 | 39 |
40 | 41 | bunch of text
42 | bunch of text
43 | bunch of text
44 | bunch of text
45 | bunch of text
46 | bunch of text
47 | bunch of text
48 | bunch of text
49 | bunch of text
50 | bunch of text
51 | bunch of text
52 | bunch of text
53 | bunch of text
54 | bunch of text
55 | bunch of text
56 | bunch of text
57 | bunch of text
58 | bunch of text
59 | bunch of text
60 | bunch of text
61 | bunch of text
62 | bunch of text
63 | bunch of text
64 | bunch of text
65 | bunch of text
66 | bunch of text
67 | bunch of text
68 | bunch of text
69 | bunch of text
70 | bunch of text
71 | bunch of text
72 | bunch of text
73 | bunch of text
74 | bunch of text
75 | bunch of text
76 | bunch of text
77 | bunch of text
78 | 79 |
80 | 81 |
82 |

Page Footer

83 |
84 |
85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /core-firmware/build/html/jquery-mobile: -------------------------------------------------------------------------------- 1 | /home/naal/dev/tools/html/jquery-mobile/ -------------------------------------------------------------------------------- /core-firmware/inc/Base64.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASE64_H 2 | #define _BASE64_H 3 | 4 | /* b64_alphabet: 5 | * Description: Base64 alphabet table, a mapping between integers 6 | * and base64 digits 7 | * Notes: This is an extern here but is defined in Base64.c 8 | */ 9 | extern const char b64_alphabet[]; 10 | 11 | /* base64_encode: 12 | * Description: 13 | * Encode a string of characters as base64 14 | * Parameters: 15 | * output: the output buffer for the encoding, stores the encoded string 16 | * input: the input buffer for the encoding, stores the binary to be encoded 17 | * inputLen: the length of the input buffer, in bytes 18 | * Return value: 19 | * Returns the length of the encoded string 20 | * Requirements: 21 | * 1. output must not be null or empty 22 | * 2. input must not be null 23 | * 3. inputLen must be greater than or equal to 0 24 | */ 25 | int base64_encode(char *output, char *input, int inputLen); 26 | 27 | /* base64_decode: 28 | * Description: 29 | * Decode a base64 encoded string into bytes 30 | * Parameters: 31 | * output: the output buffer for the decoding, 32 | * stores the decoded binary 33 | * input: the input buffer for the decoding, 34 | * stores the base64 string to be decoded 35 | * inputLen: the length of the input buffer, in bytes 36 | * Return value: 37 | * Returns the length of the decoded string 38 | * Requirements: 39 | * 1. output must not be null or empty 40 | * 2. input must not be null 41 | * 3. inputLen must be greater than or equal to 0 42 | */ 43 | int base64_decode(char *output, char *input, int inputLen); 44 | 45 | /* base64_enc_len: 46 | * Description: 47 | * Returns the length of a base64 encoded string whose decoded 48 | * form is inputLen bytes long 49 | * Parameters: 50 | * inputLen: the length of the decoded string 51 | * Return value: 52 | * The length of a base64 encoded string whose decoded form 53 | * is inputLen bytes long 54 | * Requirements: 55 | * None 56 | */ 57 | int base64_enc_len(int inputLen); 58 | 59 | /* base64_dec_len: 60 | * Description: 61 | * Returns the length of the decoded form of a 62 | * base64 encoded string 63 | * Parameters: 64 | * input: the base64 encoded string to be measured 65 | * inputLen: the length of the base64 encoded string 66 | * Return value: 67 | * Returns the length of the decoded form of a 68 | * base64 encoded string 69 | * Requirements: 70 | * 1. input must not be null 71 | * 2. input must be greater than or equal to zero 72 | */ 73 | int base64_dec_len(char *input, int inputLen); 74 | 75 | #endif // _BASE64_H 76 | -------------------------------------------------------------------------------- /core-firmware/inc/application.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file application.h 4 | * @authors Satish Nair, Zachary Crockett, Zach Supalla and Mohit Bhoite 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief User Application File Header 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef APPLICATION_H_ 27 | #define APPLICATION_H_ 28 | 29 | #define SPARK_CORE (1) 30 | 31 | #include "spark_wiring.h" 32 | #include "spark_wiring_interrupts.h" 33 | #include "spark_wiring_string.h" 34 | #include "spark_wiring_print.h" 35 | #include "spark_wiring_usartserial.h" 36 | #include "spark_wiring_usbserial.h" 37 | #include "spark_wiring_spi.h" 38 | #include "spark_wiring_i2c.h" 39 | #include "spark_wiring_servo.h" 40 | #include "spark_wiring_wifi.h" 41 | #include "spark_wiring_network.h" 42 | #include "spark_wiring_tcpclient.h" 43 | #include "spark_wiring_tcpserver.h" 44 | #include "spark_wiring_udp.h" 45 | #include "spark_wiring_time.h" 46 | 47 | #endif /* APPLICATION_H_ */ 48 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_disable_cloud.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_disable_cloud.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 6-March-2014 7 | * @brief Header to be included to prevent the core from connecting to cloud 8 | ****************************************************************************** 9 | Copyright (c) 2013-14 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __SPARK_DISABLE_CLOUD_H 28 | #define __SPARK_DISABLE_CLOUD_H 29 | 30 | class SparkDisableCloud { 31 | public: 32 | SparkDisableCloud() 33 | { 34 | SPARK_CLOUD_CONNECT = 0; 35 | } 36 | }; 37 | 38 | SparkDisableCloud sparkDisableCloud; 39 | 40 | #endif /* __SPARK_DISABLE_CLOUD_H */ 41 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_disable_wlan.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_disable_wlan.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 6-March-2014 7 | * @brief Header to be included to prevent the core from starting the wlan 8 | ****************************************************************************** 9 | Copyright (c) 2013-14 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __SPARK_DISABLE_WLAN_H 28 | #define __SPARK_DISABLE_WLAN_H 29 | 30 | class SparkDisableWlan { 31 | public: 32 | SparkDisableWlan() 33 | { 34 | SPARK_WLAN_SETUP = 0; 35 | } 36 | }; 37 | 38 | SparkDisableWlan sparkDisableWlan; 39 | 40 | #endif /* __SPARK_DISABLE_WLAN_H */ 41 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_i2c.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_i2c.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_I2C_H 28 | #define __SPARK_WIRING_I2C_H 29 | 30 | #include "spark_wiring_stream.h" 31 | 32 | #define BUFFER_LENGTH 32 33 | #define EVENT_TIMEOUT 10 34 | 35 | class TwoWire : public Stream 36 | { 37 | private: 38 | static I2C_InitTypeDef I2C_InitStructure; 39 | 40 | static bool I2C_SetAsSlave; 41 | static bool I2C_Enabled; 42 | 43 | static uint8_t rxBuffer[]; 44 | static uint8_t rxBufferIndex; 45 | static uint8_t rxBufferLength; 46 | 47 | static uint8_t txAddress; 48 | static uint8_t txBuffer[]; 49 | static uint8_t txBufferIndex; 50 | static uint8_t txBufferLength; 51 | 52 | static uint8_t transmitting; 53 | static void (*user_onRequest)(void); 54 | static void (*user_onReceive)(int); 55 | static void onRequestService(void); 56 | static void onReceiveService(uint8_t*, int); 57 | public: 58 | TwoWire(); 59 | void begin(); 60 | void begin(uint8_t); 61 | void begin(int); 62 | void beginTransmission(uint8_t); 63 | void beginTransmission(int); 64 | uint8_t endTransmission(void); 65 | uint8_t endTransmission(uint8_t); 66 | uint8_t requestFrom(uint8_t, uint8_t); 67 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t); 68 | uint8_t requestFrom(int, int); 69 | uint8_t requestFrom(int, int, int); 70 | virtual size_t write(uint8_t); 71 | virtual size_t write(const uint8_t *, size_t); 72 | virtual int available(void); 73 | virtual int read(void); 74 | virtual int peek(void); 75 | virtual void flush(void); 76 | void onReceive( void (*)(int) ); 77 | void onRequest( void (*)(void) ); 78 | 79 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 80 | inline size_t write(long n) { return write((uint8_t)n); } 81 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 82 | inline size_t write(int n) { return write((uint8_t)n); } 83 | using Print::write; 84 | 85 | static bool isEnabled(void); 86 | }; 87 | 88 | extern TwoWire Wire; 89 | 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_interrupts.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_interrupts.h 4 | * @author Mohit Bhoite 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_interrupts.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2004-05 Hernando Barragan 11 | Modified 24 November 2006 by David A. Mellis 12 | Modified 1 August 2010 by Mark Sproul 13 | 14 | This library is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation, either 17 | version 3 of the License, or (at your option) any later version. 18 | 19 | This library is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | Lesser General Public License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public 25 | License along with this library; if not, see . 26 | ****************************************************************************** 27 | */ 28 | #ifndef __SPARK_WIRING_INTERRUPTS_H 29 | #define __SPARK_WIRING_INTERRUPTS_H 30 | 31 | #include "spark_wiring.h" 32 | 33 | /* 34 | *Interrupts 35 | */ 36 | 37 | typedef enum InterruptMode { 38 | CHANGE, 39 | RISING, 40 | FALLING 41 | } InterruptMode; 42 | 43 | typedef void (*voidFuncPtr)(void); 44 | 45 | void attachInterrupt(uint16_t pin, voidFuncPtr handler, InterruptMode mode); 46 | void detachInterrupt(uint16_t pin); 47 | void interrupts(void); 48 | void noInterrupts(void); 49 | 50 | #endif /* SPARK_WIRING_INTERRUPTS_H_ */ 51 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_ipaddress.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_ipaddress.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 10-Nov-2013 7 | * @brief Header for spark_wiring_ipaddress.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2011 Adrian McEwen 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_IPADDRESS_H 28 | #define __SPARK_WIRING_IPADDRESS_H 29 | 30 | #include "spark_wiring.h" 31 | 32 | class IPAddress : public Printable { 33 | private: 34 | uint8_t _address[4]; // IPv4 address 35 | // Access the raw byte array containing the address. Because this returns a pointer 36 | // to the internal structure rather than a copy of the address this function should only 37 | // be used when you know that the usage of the returned uint8_t* will be transient and not 38 | // stored. 39 | uint8_t* raw_address() { return _address; }; 40 | 41 | public: 42 | // Constructors 43 | IPAddress(); 44 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 45 | IPAddress(uint32_t address); 46 | IPAddress(const uint8_t *address); 47 | 48 | virtual ~IPAddress() {} 49 | 50 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 51 | // to a four-byte uint8_t array is expected 52 | //operator uint32_t() { return *((uint32_t*)_address); }; 53 | //bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; 54 | bool operator==(const uint8_t* addr); 55 | 56 | // Overloaded index operator to allow getting and setting individual octets of the address 57 | uint8_t operator[](int index) const { return _address[index]; }; 58 | uint8_t& operator[](int index) { return _address[index]; }; 59 | 60 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 61 | IPAddress& operator=(const uint8_t *address); 62 | IPAddress& operator=(uint32_t address); 63 | 64 | virtual size_t printTo(Print& p) const; 65 | 66 | friend class TCPClient; 67 | friend class TCPServer; 68 | friend class UDP; 69 | }; 70 | 71 | const IPAddress INADDR_NONE(0,0,0,0); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_network.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_network.h 4 | * @author Satish Nair, Timothy Brown 5 | * @version V1.0.0 6 | * @date 18-Mar-2014 7 | * @brief Header for spark_wiring_network.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __SPARK_WIRING_NETWORK_H 27 | #define __SPARK_WIRING_NETWORK_H 28 | 29 | #include "spark_wiring.h" 30 | 31 | class NetworkClass 32 | { 33 | public: 34 | NetworkClass(); 35 | 36 | uint8_t* macAddress(uint8_t* mac); 37 | IPAddress localIP(); 38 | IPAddress subnetMask(); 39 | IPAddress gatewayIP(); 40 | char* SSID(); 41 | int8_t RSSI(); 42 | uint32_t ping(IPAddress remoteIP); 43 | uint32_t ping(IPAddress remoteIP, uint8_t nTries); 44 | 45 | friend class TCPClient; 46 | friend class TCPServer; 47 | 48 | private: 49 | uint32_t _functionStart; 50 | uint8_t _loopCount; 51 | int8_t _returnValue; 52 | }; 53 | 54 | extern NetworkClass Network; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_print.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_print.h 4 | * @author Mohit Bhoite 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_print.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2010 David A. Mellis. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_PRINT_ 28 | #define __SPARK_WIRING_PRINT_ 29 | 30 | #include // for size_t 31 | #include 32 | #include 33 | #include 34 | #include // for uint8_t 35 | 36 | #include "spark_wiring_string.h" 37 | #include "spark_wiring_printable.h" 38 | 39 | #define DEC 10 40 | #define HEX 16 41 | #define OCT 8 42 | #define BIN 2 43 | 44 | class Print 45 | { 46 | private: 47 | int write_error; 48 | size_t printNumber(unsigned long, uint8_t); 49 | size_t printFloat(double, uint8_t); 50 | protected: 51 | void setWriteError(int err = 1) { write_error = err; } 52 | public: 53 | Print() : write_error(0) {} 54 | virtual ~Print() {} 55 | 56 | int getWriteError() { return write_error; } 57 | void clearWriteError() { setWriteError(0); } 58 | 59 | virtual size_t write(uint8_t) = 0; 60 | size_t write(const char *str) { 61 | if (str == NULL) return 0; 62 | return write((const uint8_t *)str, strlen(str)); 63 | } 64 | virtual size_t write(const uint8_t *buffer, size_t size); 65 | 66 | size_t print(const String &); 67 | size_t print(const char[]); 68 | size_t print(char); 69 | size_t print(unsigned char, int = DEC); 70 | size_t print(int, int = DEC); 71 | size_t print(unsigned int, int = DEC); 72 | size_t print(long, int = DEC); 73 | size_t print(unsigned long, int = DEC); 74 | size_t print(double, int = 2); 75 | size_t print(const Printable&); 76 | 77 | size_t println(const String &s); 78 | size_t println(const char[]); 79 | size_t println(char); 80 | size_t println(unsigned char, int = DEC); 81 | size_t println(int, int = DEC); 82 | size_t println(unsigned int, int = DEC); 83 | size_t println(long, int = DEC); 84 | size_t println(unsigned long, int = DEC); 85 | size_t println(double, int = 2); 86 | size_t println(const Printable&); 87 | size_t println(void); 88 | }; 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_printable.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_printable.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 10-Nov-2013 7 | * @brief Header for spark_wiring_printable.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2011 Adrian McEwen. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_PRINTABLE_H 28 | #define __SPARK_WIRING_PRINTABLE_H 29 | 30 | class Print; 31 | 32 | /** The Printable class provides a way for new classes to allow themselves to be printed. 33 | By deriving from Printable and implementing the printTo method, it will then be possible 34 | for users to print out instances of this class by passing them into the usual 35 | Print::print and Print::println methods. 36 | */ 37 | 38 | class Printable 39 | { 40 | public: 41 | virtual size_t printTo(Print& p) const = 0; 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_spi.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_spi.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2010 by Cristian Maglie 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_SPI_H 28 | #define __SPARK_WIRING_SPI_H 29 | 30 | #include "spark_wiring.h" 31 | 32 | #define SPI_MODE0 0x00 33 | #define SPI_MODE1 0x01 34 | #define SPI_MODE2 0x02 35 | #define SPI_MODE3 0x03 36 | 37 | #define SPI_CLOCK_DIV2 SPI_BaudRatePrescaler_2 38 | #define SPI_CLOCK_DIV4 SPI_BaudRatePrescaler_4 39 | #define SPI_CLOCK_DIV8 SPI_BaudRatePrescaler_8 40 | #define SPI_CLOCK_DIV16 SPI_BaudRatePrescaler_16 41 | #define SPI_CLOCK_DIV32 SPI_BaudRatePrescaler_32 42 | #define SPI_CLOCK_DIV64 SPI_BaudRatePrescaler_64 43 | #define SPI_CLOCK_DIV128 SPI_BaudRatePrescaler_128 44 | #define SPI_CLOCK_DIV256 SPI_BaudRatePrescaler_256 45 | 46 | class SPIClass { 47 | private: 48 | static SPI_InitTypeDef SPI_InitStructure; 49 | 50 | static bool SPI_Bit_Order_Set; 51 | static bool SPI_Data_Mode_Set; 52 | static bool SPI_Clock_Divider_Set; 53 | static bool SPI_Enabled; 54 | 55 | public: 56 | static void begin(); 57 | static void begin(uint16_t); 58 | static void end(); 59 | 60 | static void setBitOrder(uint8_t); 61 | static void setDataMode(uint8_t); 62 | static void setClockDivider(uint8_t); 63 | 64 | static byte transfer(byte _data); 65 | 66 | static void attachInterrupt(); 67 | static void detachInterrupt(); 68 | 69 | static bool isEnabled(void); 70 | }; 71 | 72 | extern SPIClass SPI; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_tcpclient.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_tcpclient.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_tcpclient.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __SPARK_WIRING_TCPCLIENT_H 27 | #define __SPARK_WIRING_TCPCLIENT_H 28 | 29 | #include "spark_wiring.h" 30 | 31 | #define TCPCLIENT_BUF_MAX_SIZE 512 32 | 33 | class TCPClient : public Stream { 34 | 35 | public: 36 | TCPClient(); 37 | TCPClient(uint8_t sock); 38 | virtual ~TCPClient() {}; 39 | 40 | uint8_t status(); 41 | virtual int connect(IPAddress ip, uint16_t port); 42 | virtual int connect(const char *host, uint16_t port); 43 | virtual size_t write(uint8_t); 44 | virtual size_t write(const uint8_t *buffer, size_t size); 45 | virtual int available(); 46 | virtual int read(); 47 | virtual int read(uint8_t *buffer, size_t size); 48 | virtual int peek(); 49 | virtual void flush(); 50 | virtual void stop(); 51 | virtual bool connected(); 52 | virtual operator bool(); 53 | virtual bool equals(TCPClient &tcpClient); 54 | void resetIp() { 55 | ip[0]=0; 56 | ip[1]=0; 57 | ip[2]=0; 58 | ip[3]=0; 59 | ip[4]=0; 60 | } 61 | void setIp (IPAddress &address, uint8_t port){ 62 | ip[0]=address[0]; 63 | ip[1]=address[1]; 64 | ip[2]=address[2]; 65 | ip[3]=address[3]; 66 | ip[4]=port; 67 | 68 | } 69 | void getIP(String &str) { 70 | str+=ip[0]; 71 | str+="."; 72 | str+=ip[1]; 73 | str+="."; 74 | str+=ip[2]; 75 | str+="."; 76 | str+=ip[3]; 77 | str+="."; 78 | str+=ip[4]; 79 | } 80 | friend class TCPServer; 81 | 82 | using Print::write; 83 | 84 | private: 85 | uint16_t _srcport; 86 | unsigned short ip[5]; 87 | 88 | long _sock; 89 | uint8_t _buffer[TCPCLIENT_BUF_MAX_SIZE]; 90 | uint16_t _offset; 91 | uint16_t _total; 92 | inline int bufferCount(); 93 | inline int isWanReady(); 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_tcpserver.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_tcpserver.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_tcpserver.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __SPARK_WIRING_TCPSERVER_H 27 | #define __SPARK_WIRING_TCPSERVER_H 28 | 29 | #include "spark_wiring.h" 30 | #include "spark_wiring_tcpclient.h" 31 | class TCPClient; 32 | 33 | class TCPServer : public Print { 34 | private: 35 | uint16_t _port; 36 | long _sock; 37 | 38 | public: 39 | TCPServer(uint16_t); 40 | 41 | TCPClient *available(); 42 | virtual void begin(); 43 | virtual size_t write(uint8_t); 44 | virtual size_t write(const uint8_t *buf, size_t size); 45 | 46 | using Print::write; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_udp.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_udp.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_udp.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2008 Bjoern Hartmann 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_UDP_H 28 | #define __SPARK_WIRING_UDP_H 29 | 30 | #include "spark_wiring.h" 31 | 32 | #define RX_BUF_MAX_SIZE 512 33 | 34 | class UDP : public Stream { 35 | private: 36 | uint8_t _sock; 37 | uint16_t _port; 38 | IPAddress _remoteIP; 39 | uint16_t _remotePort; 40 | sockaddr _remoteSockAddr; 41 | socklen_t _remoteSockAddrLen; 42 | uint8_t _buffer[RX_BUF_MAX_SIZE]; 43 | uint16_t _offset; 44 | uint16_t _total; 45 | inline int isWanReady(); 46 | uint8_t connected(); 47 | public: 48 | UDP(); 49 | 50 | virtual uint8_t begin(uint16_t); 51 | virtual void stop(); 52 | virtual int beginPacket(IPAddress ip, uint16_t port); 53 | virtual int beginPacket(const char *host, uint16_t port); 54 | virtual int endPacket(); 55 | virtual size_t write(uint8_t); 56 | virtual size_t write(const uint8_t *buffer, size_t size); 57 | virtual int parsePacket(); 58 | virtual int available(); 59 | virtual int read(); 60 | virtual int read(unsigned char* buffer, size_t len); 61 | virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); }; 62 | virtual int peek(); 63 | virtual void flush(); 64 | virtual IPAddress remoteIP() { return _remoteIP; }; 65 | virtual uint16_t remotePort() { return _remotePort; }; 66 | 67 | using Print::write; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_usartserial.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_usartserial.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_usartserial.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_USARTSERIAL_H 28 | #define __SPARK_WIRING_USARTSERIAL_H 29 | 30 | #include "spark_wiring_stream.h" 31 | 32 | struct ring_buffer; 33 | 34 | class USARTSerial : public Stream 35 | { 36 | private: 37 | static USART_InitTypeDef USART_InitStructure; 38 | static bool USARTSerial_Enabled; 39 | ring_buffer *_rx_buffer; 40 | ring_buffer *_tx_buffer; 41 | bool transmitting; 42 | 43 | public: 44 | USARTSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer); 45 | virtual ~USARTSerial() {}; 46 | void begin(unsigned long); 47 | void begin(unsigned long, uint8_t); 48 | void end(); 49 | 50 | virtual int available(void); 51 | virtual int peek(void); 52 | virtual int read(void); 53 | virtual void flush(void); 54 | virtual size_t write(uint8_t); 55 | 56 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 57 | inline size_t write(long n) { return write((uint8_t)n); } 58 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 59 | inline size_t write(int n) { return write((uint8_t)n); } 60 | 61 | using Print::write; // pull in write(str) and write(buf, size) from Print 62 | 63 | operator bool(); 64 | 65 | static bool isEnabled(void); 66 | 67 | }; 68 | 69 | extern USARTSerial Serial1; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_usbserial.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_usbserial.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_usbserial.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #ifndef __SPARK_WIRING_USBSERIAL_H 28 | #define __SPARK_WIRING_USBSERIAL_H 29 | 30 | #include "spark_wiring_stream.h" 31 | 32 | class USBSerial : public Stream 33 | { 34 | private: 35 | 36 | public: 37 | // public methods 38 | USBSerial(); 39 | 40 | void begin(long speed); 41 | void end(); 42 | int peek(); 43 | 44 | virtual size_t write(uint8_t byte); 45 | virtual int read(); 46 | virtual int available(); 47 | virtual void flush(); 48 | 49 | using Print::write; 50 | }; 51 | 52 | extern void USB_USART_Init(uint32_t baudRate); 53 | extern uint8_t USB_USART_Available_Data(void); 54 | extern int32_t USB_USART_Receive_Data(void); 55 | extern void USB_USART_Send_Data(uint8_t Data); 56 | 57 | extern USBSerial Serial; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /core-firmware/inc/spark_wiring_wifi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_wifi.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 7-Mar-2014 7 | * @brief Header for spark_wiring_wifi.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013-14 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __SPARK_WIRING_WIFI_H 27 | #define __SPARK_WIRING_WIFI_H 28 | 29 | #include "spark_wiring.h" 30 | 31 | typedef enum 32 | { 33 | WIFI_OFF = 0, WIFI_CONNECTING = 1, WIFI_ON = 2 34 | } WiFi_Status_TypeDef; 35 | 36 | class WiFiClass 37 | { 38 | public: 39 | WiFiClass() {} 40 | ~WiFiClass() {} 41 | 42 | static void on(void); 43 | static void off(void); 44 | static WiFi_Status_TypeDef status(void); 45 | }; 46 | 47 | extern WiFiClass WiFi; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /core-firmware/inc/stm32_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_it.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __STM32_IT_H 28 | #define __STM32_IT_H 29 | 30 | extern "C" { 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "platform_config.h" 34 | #include "cc3000_spi.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | 40 | /* Exported macro ------------------------------------------------------------*/ 41 | 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | void ADC1_2_IRQHandler(void); 54 | void USART2_IRQHandler(void); 55 | void I2C1_EV_IRQHandler(void); 56 | void I2C1_ER_IRQHandler(void); 57 | void SPI1_IRQHandler(void); 58 | void EXTI0_IRQHandler(void); 59 | void EXTI1_IRQHandler(void); 60 | void EXTI2_IRQHandler(void); 61 | void EXTI3_IRQHandler(void); 62 | void EXTI4_IRQHandler(void); 63 | void EXTI9_5_IRQHandler(void); 64 | void EXTI15_10_IRQHandler(void); 65 | void TIM1_CC_IRQHandler(void); 66 | void RTC_IRQHandler(void); 67 | void RTCAlarm_IRQHandler(void); 68 | void DMA1_Channel5_IRQHandler(void); 69 | void USB_LP_CAN1_RX0_IRQHandler(void); 70 | 71 | } 72 | 73 | #endif /* __STM32_IT_H */ 74 | 75 | -------------------------------------------------------------------------------- /core-firmware/inc/usb_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 24-April-2013 7 | * @brief Descriptor Header for Virtual COM Port Device 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_DESC_H 28 | #define __USB_DESC_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported define -----------------------------------------------------------*/ 35 | #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 36 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 37 | #define USB_STRING_DESCRIPTOR_TYPE 0x03 38 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 39 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 40 | 41 | #define VIRTUAL_COM_PORT_DATA_SIZE 64 42 | #define VIRTUAL_COM_PORT_INT_SIZE 8 43 | 44 | #define VIRTUAL_COM_PORT_SIZ_DEVICE_DESC 18 45 | #define VIRTUAL_COM_PORT_SIZ_CONFIG_DESC 67 46 | #define VIRTUAL_COM_PORT_SIZ_STRING_LANGID 4 47 | #define VIRTUAL_COM_PORT_SIZ_STRING_VENDOR 38 48 | #define VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT 50 49 | #define VIRTUAL_COM_PORT_SIZ_STRING_SERIAL 26 50 | 51 | #define STANDARD_ENDPOINT_DESC_SIZE 0x09 52 | 53 | /* Exported functions ------------------------------------------------------- */ 54 | extern const uint8_t Virtual_Com_Port_DeviceDescriptor[VIRTUAL_COM_PORT_SIZ_DEVICE_DESC]; 55 | extern const uint8_t Virtual_Com_Port_ConfigDescriptor[VIRTUAL_COM_PORT_SIZ_CONFIG_DESC]; 56 | 57 | extern const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID]; 58 | extern const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR]; 59 | extern const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT]; 60 | extern uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL]; 61 | 62 | #endif /* __USB_DESC_H */ 63 | -------------------------------------------------------------------------------- /core-firmware/inc/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 24-April-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_ISTR_H 28 | #define __USB_ISTR_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usb_conf.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | 38 | extern "C" void USB_Istr(void); 39 | 40 | /* function prototypes Automatically built defining related macros */ 41 | 42 | extern "C" void EP1_IN_Callback(void); 43 | void EP2_IN_Callback(void); 44 | void EP3_IN_Callback(void); 45 | void EP4_IN_Callback(void); 46 | void EP5_IN_Callback(void); 47 | void EP6_IN_Callback(void); 48 | void EP7_IN_Callback(void); 49 | 50 | void EP1_OUT_Callback(void); 51 | void EP2_OUT_Callback(void); 52 | extern "C" void EP3_OUT_Callback(void); 53 | void EP4_OUT_Callback(void); 54 | void EP5_OUT_Callback(void); 55 | void EP6_OUT_Callback(void); 56 | void EP7_OUT_Callback(void); 57 | 58 | #ifdef CTR_CALLBACK 59 | void CTR_Callback(void); 60 | #endif 61 | 62 | #ifdef DOVR_CALLBACK 63 | void DOVR_Callback(void); 64 | #endif 65 | 66 | #ifdef ERR_CALLBACK 67 | void ERR_Callback(void); 68 | #endif 69 | 70 | #ifdef WKUP_CALLBACK 71 | void WKUP_Callback(void); 72 | #endif 73 | 74 | #ifdef SUSP_CALLBACK 75 | void SUSP_Callback(void); 76 | #endif 77 | 78 | #ifdef RESET_CALLBACK 79 | void RESET_Callback(void); 80 | #endif 81 | 82 | #ifdef SOF_CALLBACK 83 | extern "C" void SOF_Callback(void); 84 | #endif 85 | 86 | #ifdef ESOF_CALLBACK 87 | void ESOF_Callback(void); 88 | #endif 89 | #endif /*__USB_ISTR_H*/ 90 | 91 | -------------------------------------------------------------------------------- /core-firmware/inc/wifi_credentials_reader.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file wifi_credentials_reader.h 4 | * @author Zachary Crockett and Satish Nair 5 | * @version V1.0.0 6 | * @date 24-April-2013 7 | * @brief header for wifi_credentials_reader.cpp 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | #include 26 | #include "spark_wiring_usbserial.h" 27 | 28 | typedef void (*ConnectCallback)(const char *ssid, 29 | const char *password, 30 | unsigned long security_type); 31 | 32 | class WiFiCredentialsReader 33 | { 34 | public: 35 | WiFiCredentialsReader(ConnectCallback connect_callback); 36 | void read(void); 37 | 38 | private: 39 | USBSerial serial; 40 | ConnectCallback connect_callback; 41 | char ssid[33]; 42 | char password[65]; 43 | char security_type_string[2]; 44 | 45 | void print(const char *s); 46 | void read_line(char *dst, int max_len); 47 | }; 48 | -------------------------------------------------------------------------------- /core-firmware/src/ADXL335.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ADXL335.cpp 3 | * 4 | * Created on: Mar 19, 2014 5 | * Author: naal 6 | */ 7 | 8 | #include "ADXL335.h" 9 | #include 10 | ADXL335::ADXL335(unsigned xP, unsigned yP, unsigned zP) { 11 | xPin = xP; 12 | yPin = yP; 13 | zPin = zP; 14 | } 15 | 16 | void ADXL335::update() { 17 | //read the analog values from the accelerometer 18 | double xRead = analogRead(xPin); 19 | double yRead = 255; 20 | if (yPin != 255) { 21 | yRead = analogRead(yPin); 22 | } 23 | double zRead = analogRead(zPin); 24 | //convert read values to degrees -90 to 90 - Needed for atan2 25 | double xAng = 255; 26 | if (xPin != 255) { 27 | xAng = map(xRead, MIN_VAL, MAX_VAL, -90, 90); 28 | } 29 | double yAng = 255; 30 | if (yPin != 255) { 31 | yAng = map(yRead, MIN_VAL, MAX_VAL, -90, 90); 32 | } 33 | double zAng = 255; 34 | if (zPin != 255) { 35 | zAng = map(zRead, MIN_VAL, MAX_VAL, -90, 90); 36 | } 37 | //Caculate 360deg values like so: atan2(-yAng, -zAng) 38 | //atan2 outputs the value of -π to π (radians) 39 | //We are then converting the radians to degrees 40 | angle_x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI); 41 | 42 | angle_y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI); 43 | angle_z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI); 44 | 45 | } 46 | 47 | double ADXL335::getXDeg() { 48 | return angle_x; 49 | } 50 | 51 | double ADXL335::getYDeg() { 52 | return angle_y; 53 | } 54 | 55 | double ADXL335::getZDeg() { 56 | return angle_z; 57 | } 58 | 59 | void ADXL335::dump(USBSerial &serial, char *debug) { 60 | //Output the caculations 61 | serial.print(debug); 62 | serial.print(", x: "); 63 | serial.print(getXDeg()); 64 | 65 | serial.print(" y: "); 66 | serial.print(getYDeg()); 67 | 68 | serial.print(" z: "); 69 | serial.println(getZDeg()); 70 | } 71 | -------------------------------------------------------------------------------- /core-firmware/src/ADXL335.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ADXL335.h 3 | * 4 | * Created on: Mar 19, 2014 5 | * Author: naal 6 | */ 7 | 8 | #ifndef ADXL335_H_ 9 | #define ADXL335_H_ 10 | #include 11 | #include "spark_wiring_usbserial.h" 12 | #define __ADXL335_H__ 13 | 14 | #define ADC_ref 5.0 15 | #define analog_resolution 1024.0 16 | 17 | #define zero_x 1.60156 18 | #define zero_y 1.60156 19 | #define zero_z 1.64551 20 | 21 | #define sensitivity_x 0.33 22 | #define sensitivity_y 0.33 23 | #define sensitivity_z 0.31 24 | #define PI 3.14159265 25 | #define HALF_PI 1.57079 26 | #define TWO_PI 6.283185 27 | #define DEG_TO_RAD 0.01745329 28 | #define RAD_TO_DEG 57.2957786 29 | #define MIN_VAL 1600 30 | #define MAX_VAL 2400 31 | 32 | class ADXL335 { 33 | public: 34 | ADXL335(unsigned xPin = A0, unsigned yPin = A1, unsigned zPin = A2); 35 | /** 36 | * call this before getting sensor values. 37 | */ 38 | void update(); 39 | 40 | double getXDeg(); 41 | double getYDeg(); 42 | double getZDeg(); 43 | void dump(USBSerial &serial, char *debug); 44 | 45 | float angle_x; 46 | float angle_y; 47 | float angle_z; 48 | 49 | private: 50 | unsigned int xPin; 51 | unsigned int yPin; 52 | unsigned int zPin; 53 | 54 | }; 55 | 56 | #endif /* ADXL335_H_ */ 57 | -------------------------------------------------------------------------------- /core-firmware/src/Base64.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASE64_H 2 | #define _BASE64_H 3 | 4 | /* b64_alphabet: 5 | * Description: Base64 alphabet table, a mapping between integers 6 | * and base64 digits 7 | * Notes: This is an extern here but is defined in Base64.c 8 | */ 9 | extern const char b64_alphabet[]; 10 | 11 | /* base64_encode: 12 | * Description: 13 | * Encode a string of characters as base64 14 | * Parameters: 15 | * output: the output buffer for the encoding, stores the encoded string 16 | * input: the input buffer for the encoding, stores the binary to be encoded 17 | * inputLen: the length of the input buffer, in bytes 18 | * Return value: 19 | * Returns the length of the encoded string 20 | * Requirements: 21 | * 1. output must not be null or empty 22 | * 2. input must not be null 23 | * 3. inputLen must be greater than or equal to 0 24 | */ 25 | int base64_encode(char *output, char *input, int inputLen); 26 | 27 | /* base64_decode: 28 | * Description: 29 | * Decode a base64 encoded string into bytes 30 | * Parameters: 31 | * output: the output buffer for the decoding, 32 | * stores the decoded binary 33 | * input: the input buffer for the decoding, 34 | * stores the base64 string to be decoded 35 | * inputLen: the length of the input buffer, in bytes 36 | * Return value: 37 | * Returns the length of the decoded string 38 | * Requirements: 39 | * 1. output must not be null or empty 40 | * 2. input must not be null 41 | * 3. inputLen must be greater than or equal to 0 42 | */ 43 | int base64_decode(char *output, char *input, int inputLen); 44 | 45 | /* base64_enc_len: 46 | * Description: 47 | * Returns the length of a base64 encoded string whose decoded 48 | * form is inputLen bytes long 49 | * Parameters: 50 | * inputLen: the length of the decoded string 51 | * Return value: 52 | * The length of a base64 encoded string whose decoded form 53 | * is inputLen bytes long 54 | * Requirements: 55 | * None 56 | */ 57 | int base64_enc_len(int inputLen); 58 | 59 | /* base64_dec_len: 60 | * Description: 61 | * Returns the length of the decoded form of a 62 | * base64 encoded string 63 | * Parameters: 64 | * input: the base64 encoded string to be measured 65 | * inputLen: the length of the base64 encoded string 66 | * Return value: 67 | * Returns the length of the decoded form of a 68 | * base64 encoded string 69 | * Requirements: 70 | * 1. input must not be null 71 | * 2. input must be greater than or equal to zero 72 | */ 73 | int base64_dec_len(char *input, int inputLen); 74 | 75 | #endif // _BASE64_H 76 | -------------------------------------------------------------------------------- /core-firmware/src/Bed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Bed.h 3 | * 4 | * Created on: Mar 23, 2014 5 | * Author: naal 6 | */ 7 | 8 | #ifndef BED_H_ 9 | #define BED_H 10 | #include "application.h" 11 | #include "ADXL335.h" 12 | #include 13 | 14 | 15 | static const ushort HIS_PINS[]= {D0,D1,D2,D3}; 16 | static const ushort HER_PINS[]= {D4,D5,D6,D7}; 17 | class Bed { 18 | public: 19 | Bed(ADXL335 head, ADXL335 legs, uint32_t hAddress, bool his); 20 | virtual ~Bed(); 21 | void saveHeadPos(int pos, uint8_t deg, bool final=false); 22 | void saveLegsPos(int pos, uint8_t deg, bool final=false); 23 | void dump(); 24 | void update(); 25 | void stop(); 26 | double getLegX(); 27 | double getHeadX(); 28 | 29 | void gotoPos(int pos); 30 | 31 | void toString(String &tmp) { 32 | tmp+="head: ["; 33 | tmp+=positions[0]; 34 | tmp+=","; 35 | tmp+=positions[1]; 36 | tmp+=","; 37 | tmp+=positions[2]; 38 | tmp+=","; 39 | tmp+=positions[3]; 40 | tmp+="] legs:["; 41 | tmp+=positions[4]; 42 | tmp+=","; 43 | tmp+=positions[5]; 44 | tmp+=","; 45 | tmp+=positions[6]; 46 | tmp+=","; 47 | tmp+=positions[7]; 48 | tmp+="]"; 49 | } 50 | //sprintf(tmp, "his head: [%d, %d, %d, %d]\n his legs: [%d, %d, %d, %d]", 51 | // headPosition[0], headPosition[1], headPosition[2], headPosition[3]); 52 | void dump(USBSerial &serial) { 53 | String test; 54 | toString(test); 55 | serial.println(test); 56 | } 57 | 58 | private : 59 | typedef double (Bed::*fptr)(void); // typedef for better readability 60 | fptr getIt(bool head) { 61 | if(head) { 62 | return &Bed::getHeadX; 63 | } 64 | return &Bed::getLegX; 65 | } 66 | bool shouldContinue(double val1, uint8_t val2, bool up); 67 | void adjust(bool head, ushort pin, uint8_t value, bool up); 68 | void load(); 69 | bool hisBed; 70 | uint8_t positions[8]; 71 | 72 | uint32_t flashAddress; 73 | 74 | ADXL335 headSensor; 75 | ADXL335 legsSensor; 76 | 77 | }; 78 | 79 | #endif /* BED_H_ */ 80 | -------------------------------------------------------------------------------- /core-firmware/src/MD5.h: -------------------------------------------------------------------------------- 1 | /* MD5.H - header file for MD5C.C 2 | * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 3 | * rights reserved. 4 | * 5 | * License to copy and use this software is granted provided that it 6 | * is identified as the "RSA Data Security, Inc. MD5 Message-Digest 7 | * Algorithm" in all material mentioning or referencing this software 8 | * or this function. 9 | * 10 | * License is also granted to make and use derivative works provided 11 | * that such works are identified as "derived from the RSA Data 12 | * Security, Inc. MD5 Message-Digest Algorithm" in all material 13 | * mentioning or referencing the derived work. 14 | * 15 | * RSA Data Security, Inc. makes no representations concerning either 16 | * the merchantability of this software or the suitability of this 17 | * software for any particular purpose. It is provided "as is" 18 | * without express or implied warranty of any kind. 19 | * These notices must be retained in any copies of any part of this 20 | * documentation and/or software. 21 | */ 22 | 23 | /* MD5 context. */ 24 | typedef struct { 25 | UINT4 state[4]; /* state (ABCD) */ 26 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ 27 | unsigned char buffer[64]; /* input buffer */ 28 | } MD5_CTX; 29 | 30 | void MD5Init (MD5_CTX *); 31 | void MD5Update (MD5_CTX *, unsigned char *, unsigned int); 32 | void MD5Final (unsigned char [16], MD5_CTX *); 33 | 34 | /* Function used by Websockets implementation */ 35 | void MD5 (unsigned char [], unsigned char [], unsigned int); -------------------------------------------------------------------------------- /core-firmware/src/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_SRC_PATH = src 8 | 9 | # Add include to all objects built for this target 10 | INCLUDE_DIRS += inc 11 | 12 | # C source files included in this build. 13 | CSRC += 14 | 15 | # C++ source files included in this build. 16 | CPPSRC += $(TARGET_SRC_PATH)/application.cpp 17 | CPPSRC += $(TARGET_SRC_PATH)/SparkWebSocketServer.cpp 18 | CPPSRC += $(TARGET_SRC_PATH)/Base64.cpp 19 | CPPSRC += $(TARGET_SRC_PATH)/main.cpp 20 | CPPSRC += $(TARGET_SRC_PATH)/newlib_stubs.cpp 21 | CPPSRC += $(TARGET_SRC_PATH)/spark_utilities.cpp 22 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring.cpp 23 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_i2c.cpp 24 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_interrupts.cpp 25 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_ipaddress.cpp 26 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_network.cpp 27 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_print.cpp 28 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_servo.cpp 29 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_spi.cpp 30 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_stream.cpp 31 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_string.cpp 32 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_tcpclient.cpp 33 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_tcpserver.cpp 34 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_time.cpp 35 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_udp.cpp 36 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_usartserial.cpp 37 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_usbserial.cpp 38 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_wifi.cpp 39 | CPPSRC += $(TARGET_SRC_PATH)/spark_wlan.cpp 40 | CPPSRC += $(TARGET_SRC_PATH)/stm32_it.cpp 41 | CPPSRC += $(TARGET_SRC_PATH)/usb_desc.cpp 42 | CPPSRC += $(TARGET_SRC_PATH)/usb_endp.cpp 43 | CPPSRC += $(TARGET_SRC_PATH)/usb_istr.cpp 44 | CPPSRC += $(TARGET_SRC_PATH)/usb_prop.cpp 45 | CPPSRC += $(TARGET_SRC_PATH)/wifi_credentials_reader.cpp 46 | 47 | # ASM source files included in this build. 48 | ASRC += 49 | 50 | -------------------------------------------------------------------------------- /core-firmware/src/build.mk~: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_SRC_PATH = src 8 | 9 | # Add include to all objects built for this target 10 | INCLUDE_DIRS += inc 11 | 12 | # C source files included in this build. 13 | CSRC += 14 | 15 | # C++ source files included in this build. 16 | CPPSRC += $(TARGET_SRC_PATH)/application.cpp 17 | CPPSRC += $(TARGET_SRC_PATH)/ADXL335.cpp 18 | CPPSRC += $(TARGET_SRC_PATH)/SparkWebSocketServer.cpp 19 | CPPSRC += $(TARGET_SRC_PATH)/Bed.cpp 20 | CPPSRC += $(TARGET_SRC_PATH)/main.cpp 21 | CPPSRC += $(TARGET_SRC_PATH)/newlib_stubs.cpp 22 | CPPSRC += $(TARGET_SRC_PATH)/spark_utilities.cpp 23 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring.cpp 24 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_i2c.cpp 25 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_interrupts.cpp 26 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_ipaddress.cpp 27 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_network.cpp 28 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_print.cpp 29 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_servo.cpp 30 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_spi.cpp 31 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_stream.cpp 32 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_string.cpp 33 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_tcpclient.cpp 34 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_tcpserver.cpp 35 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_time.cpp 36 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_udp.cpp 37 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_usartserial.cpp 38 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_usbserial.cpp 39 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_wifi.cpp 40 | CPPSRC += $(TARGET_SRC_PATH)/spark_wlan.cpp 41 | CPPSRC += $(TARGET_SRC_PATH)/stm32_it.cpp 42 | CPPSRC += $(TARGET_SRC_PATH)/usb_desc.cpp 43 | CPPSRC += $(TARGET_SRC_PATH)/usb_endp.cpp 44 | CPPSRC += $(TARGET_SRC_PATH)/usb_istr.cpp 45 | CPPSRC += $(TARGET_SRC_PATH)/usb_prop.cpp 46 | CPPSRC += $(TARGET_SRC_PATH)/wifi_credentials_reader.cpp 47 | 48 | # ASM source files included in this build. 49 | ASRC += 50 | 51 | -------------------------------------------------------------------------------- /core-firmware/src/spark_wiring_ipaddress.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_ipaddress.cpp 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 10-Nov-2013 7 | * @brief 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2011 Adrian McEwen 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #include "spark_wiring_ipaddress.h" 28 | 29 | IPAddress::IPAddress() 30 | { 31 | memset(_address, 0, sizeof(_address)); 32 | } 33 | 34 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 35 | { 36 | _address[0] = first_octet; 37 | _address[1] = second_octet; 38 | _address[2] = third_octet; 39 | _address[3] = fourth_octet; 40 | } 41 | 42 | IPAddress::IPAddress(uint32_t address) 43 | { 44 | memcpy(_address, &address, sizeof(_address)); 45 | } 46 | 47 | IPAddress::IPAddress(const uint8_t *address) 48 | { 49 | memcpy(_address, address, sizeof(_address)); 50 | } 51 | 52 | IPAddress& IPAddress::operator=(const uint8_t *address) 53 | { 54 | memcpy(_address, address, sizeof(_address)); 55 | return *this; 56 | } 57 | 58 | IPAddress& IPAddress::operator=(uint32_t address) 59 | { 60 | memcpy(_address, (const uint8_t *)&address, sizeof(_address)); 61 | return *this; 62 | } 63 | 64 | bool IPAddress::operator==(const uint8_t* addr) 65 | { 66 | return memcmp(addr, _address, sizeof(_address)) == 0; 67 | } 68 | 69 | size_t IPAddress::printTo(Print& p) const 70 | { 71 | size_t n = 0; 72 | for (int i =0; i < 3; i++) 73 | { 74 | n += p.print(_address[i], DEC); 75 | n += p.print('.'); 76 | } 77 | n += p.print(_address[3], DEC); 78 | return n; 79 | } 80 | -------------------------------------------------------------------------------- /core-firmware/src/spark_wiring_usbserial.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_usbserial.cpp 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Wrapper for wiring usb serial module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation, either 15 | version 3 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public 23 | License along with this library; if not, see . 24 | ****************************************************************************** 25 | */ 26 | 27 | #include "spark_wiring_usbserial.h" 28 | 29 | // 30 | // Constructor 31 | // 32 | USBSerial::USBSerial() 33 | { 34 | } 35 | 36 | // 37 | // Public methods 38 | // 39 | 40 | void USBSerial::begin(long speed) 41 | { 42 | USB_USART_Init(speed); 43 | } 44 | 45 | void USBSerial::end() 46 | { 47 | //To Do 48 | } 49 | 50 | 51 | // Read data from buffer 52 | int USBSerial::read() 53 | { 54 | return USB_USART_Receive_Data(); 55 | } 56 | 57 | int USBSerial::available() 58 | { 59 | return USB_USART_Available_Data(); 60 | } 61 | 62 | size_t USBSerial::write(uint8_t byte) 63 | { 64 | USB_USART_Send_Data(byte); 65 | 66 | return 1; 67 | } 68 | 69 | void USBSerial::flush() 70 | { 71 | //To Do 72 | } 73 | 74 | int USBSerial::peek() 75 | { 76 | return -1; 77 | } 78 | 79 | // Preinstantiate Objects ////////////////////////////////////////////////////// 80 | 81 | USBSerial Serial; 82 | -------------------------------------------------------------------------------- /core-firmware/src/spark_wiring_wifi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_wifi.cpp 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 7-Mar-2013 7 | * @brief WiFi utility class to help users manage the WiFi connection 8 | ****************************************************************************** 9 | Copyright (c) 2013-14 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #include "spark_wiring_wifi.h" 27 | 28 | void WiFiClass::on(void) 29 | { 30 | extern void (*announce_presence)(void); 31 | if(announce_presence != Multicast_Presence_Announcement) 32 | { 33 | //Get the setup executed once if not done already 34 | SPARK_WLAN_Setup(Multicast_Presence_Announcement); 35 | SPARK_WLAN_SETUP = 1; 36 | } 37 | SPARK_WLAN_SLEEP = 0; //Logic to call wlan_start() inside SPARK_WLAN_Loop() 38 | } 39 | 40 | void WiFiClass::off(void) 41 | { 42 | SPARK_WLAN_SLEEP = 1; //Logic to call wlan_stop() inside SPARK_WLAN_Loop() 43 | } 44 | 45 | WiFi_Status_TypeDef WiFiClass::status(void) 46 | { 47 | if(SPARK_WLAN_STARTED) 48 | { 49 | if(!WLAN_DHCP) 50 | { 51 | return WIFI_CONNECTING; 52 | } 53 | return WIFI_ON; 54 | } 55 | return WIFI_OFF; 56 | } 57 | 58 | WiFiClass WiFi; 59 | -------------------------------------------------------------------------------- /core-firmware/startup/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_STARTUP_PATH = startup 8 | 9 | # Add include to all objects built for this target 10 | INCLUDE_DIRS += 11 | 12 | # C source files included in this build. 13 | CSRC += 14 | 15 | # C++ source files included in this build. 16 | CPPSRC += 17 | 18 | # ASM source files included in this build. 19 | ASRC += $(TARGET_STARTUP_PATH)/startup_stm32f10x_md.S 20 | 21 | -------------------------------------------------------------------------------- /example/html-tinker.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Na2l/spark-websocket-server/30b8495ec597deb4e5bd5577b3861aafd7934d28/example/html-tinker.mp4 -------------------------------------------------------------------------------- /example/tinker.js: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #EXPRESS OR 4 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #MERCHANTABILITY, 5 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO #EVENT SHALL THE 6 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR #OTHER 7 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #ARISING FROM, 8 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #DEALINGS IN 9 | * THE SOFTWARE. 10 | * Copyright (c) 2014 NaAl (h20@alocreative.com) 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | */ 21 | 22 | var digital = [ 'D0', 'D1', 'D2', 'D3']; 23 | var analog = [ 'A0', 'A1', 'A2', 'A3']; 24 | var cmdArray =[ 'digitalwrite', 'digitalread', /*'analogwrite', 'analogread' */]; 25 | var pinIndex=0; 26 | var cmdIndex=0; 27 | var state=true; 28 | var WebSocket = require('ws') 29 | , ws = new WebSocket('ws://:'); 30 | 31 | ws.on('open', function() { 32 | console.log('connected'); 33 | 34 | }); 35 | ws.on('close', function(message) { 36 | console.log('closed'); 37 | 38 | }); 39 | ws.on('message', function(message) { 40 | console.log('received: %s', message); 41 | 42 | }); 43 | function test() { 44 | 45 | setInterval(function() { 46 | if(pinIndex>=digital.length) { 47 | pinIndex=0; 48 | state=!state; 49 | cmdIndex++; 50 | } 51 | if(cmdIndex>=cmdArray.length) { 52 | cmdIndex=0 53 | pinIndex=0; 54 | } 55 | var sendThis='/'+cmdArray[cmdIndex]+'?'; 56 | if(cmdIndex<2) { 57 | sendThis+=digital[pinIndex]+'='+(state?'HIGH':'LOW'); 58 | } else { 59 | sendThis+=analog[pinIndex]; 60 | } 61 | 62 | 63 | 64 | console.log('sending: '+sendThis); 65 | ws.send(sendThis); 66 | pinIndex++; 67 | }, 2000); 68 | 69 | } 70 | test(); 71 | -------------------------------------------------------------------------------- /html/spark/css/html5reset.css: -------------------------------------------------------------------------------- 1 | /* 2 | html5doctor.com Reset Stylesheet 3 | v1.6.1 4 | Last Updated: 2010-09-17 5 | Author: Richard Clark - http://richclarkdesign.com 6 | Twitter: @rich_clark 7 | */ 8 | 9 | /* 10 | html, body, div, span, object, iframe, 11 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 12 | abbr, address, cite, code, 13 | del, dfn, em, img, ins, kbd, q, samp, 14 | small, strong, sub, sup, var, 15 | b, i, 16 | dl, dt, dd, ol, ul, li, 17 | fieldset, form, label, legend, 18 | table, caption, tbody, tfoot, thead, tr, th, td, 19 | article, aside, canvas, details, figcaption, figure, 20 | footer, header, hgroup, menu, nav, section, summary, 21 | time, mark, audio, video { 22 | margin:0; 23 | padding:0; 24 | border:0; 25 | outline:0; 26 | font-size:100%; 27 | vertical-align:baseline; 28 | background:transparent; 29 | } 30 | */ 31 | body { 32 | line-height:1; 33 | } 34 | 35 | article,aside,details,figcaption,figure, 36 | footer,header,hgroup,menu,nav,section { 37 | display:block; 38 | } 39 | 40 | nav ul { 41 | list-style:none; 42 | padding:0px; margin: 0px; 43 | } 44 | 45 | blockquote, q { 46 | quotes:none; 47 | } 48 | 49 | blockquote:before, blockquote:after, 50 | q:before, q:after { 51 | content:''; 52 | content:none; 53 | } 54 | 55 | a { 56 | margin:0; 57 | padding:0; 58 | font-size:100%; 59 | vertical-align:baseline; 60 | background:transparent; 61 | } 62 | 63 | /* change colours to suit your needs */ 64 | ins { 65 | background-color:#ff9; 66 | color:#000; 67 | text-decoration:none; 68 | } 69 | 70 | /* change colours to suit your needs */ 71 | mark { 72 | background-color:#ff9; 73 | color:#000; 74 | font-style:italic; 75 | font-weight:bold; 76 | } 77 | 78 | del { 79 | text-decoration: line-through; 80 | } 81 | 82 | abbr[title], dfn[title] { 83 | border-bottom:1px dotted; 84 | cursor:help; 85 | } 86 | 87 | table { 88 | border-collapse:collapse; 89 | border-spacing:0; 90 | } 91 | 92 | /* change border colour to suit your needs */ 93 | hr { 94 | display:block; 95 | height:1px; 96 | border:0; 97 | border-top:1px solid #cccccc; 98 | margin:1em 0; 99 | padding:0; 100 | } 101 | 102 | input, select { 103 | vertical-align:middle; 104 | } -------------------------------------------------------------------------------- /html/spark/imgs/spark-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Na2l/spark-websocket-server/30b8495ec597deb4e5bd5577b3861aafd7934d28/html/spark/imgs/spark-small.png -------------------------------------------------------------------------------- /html/spark/imgs/spark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Na2l/spark-websocket-server/30b8495ec597deb4e5bd5577b3861aafd7934d28/html/spark/imgs/spark.png -------------------------------------------------------------------------------- /html/spark/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spark 6 | 7 | 8 | 9 | 10 | 23 | 31 | 32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /inc/Base64.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASE64_H 2 | #define _BASE64_H 3 | 4 | /* b64_alphabet: 5 | * Description: Base64 alphabet table, a mapping between integers 6 | * and base64 digits 7 | * Notes: This is an extern here but is defined in Base64.c 8 | */ 9 | extern const char b64_alphabet[]; 10 | 11 | /* base64_encode: 12 | * Description: 13 | * Encode a string of characters as base64 14 | * Parameters: 15 | * output: the output buffer for the encoding, stores the encoded string 16 | * input: the input buffer for the encoding, stores the binary to be encoded 17 | * inputLen: the length of the input buffer, in bytes 18 | * Return value: 19 | * Returns the length of the encoded string 20 | * Requirements: 21 | * 1. output must not be null or empty 22 | * 2. input must not be null 23 | * 3. inputLen must be greater than or equal to 0 24 | */ 25 | int base64_encode(char *output, char *input, int inputLen); 26 | 27 | /* base64_decode: 28 | * Description: 29 | * Decode a base64 encoded string into bytes 30 | * Parameters: 31 | * output: the output buffer for the decoding, 32 | * stores the decoded binary 33 | * input: the input buffer for the decoding, 34 | * stores the base64 string to be decoded 35 | * inputLen: the length of the input buffer, in bytes 36 | * Return value: 37 | * Returns the length of the decoded string 38 | * Requirements: 39 | * 1. output must not be null or empty 40 | * 2. input must not be null 41 | * 3. inputLen must be greater than or equal to 0 42 | */ 43 | int base64_decode(char *output, char *input, int inputLen); 44 | 45 | /* base64_enc_len: 46 | * Description: 47 | * Returns the length of a base64 encoded string whose decoded 48 | * form is inputLen bytes long 49 | * Parameters: 50 | * inputLen: the length of the decoded string 51 | * Return value: 52 | * The length of a base64 encoded string whose decoded form 53 | * is inputLen bytes long 54 | * Requirements: 55 | * None 56 | */ 57 | int base64_enc_len(int inputLen); 58 | 59 | /* base64_dec_len: 60 | * Description: 61 | * Returns the length of the decoded form of a 62 | * base64 encoded string 63 | * Parameters: 64 | * input: the base64 encoded string to be measured 65 | * inputLen: the length of the base64 encoded string 66 | * Return value: 67 | * Returns the length of the decoded form of a 68 | * base64 encoded string 69 | * Requirements: 70 | * 1. input must not be null 71 | * 2. input must be greater than or equal to zero 72 | */ 73 | int base64_dec_len(char *input, int inputLen); 74 | 75 | #endif // _BASE64_H 76 | -------------------------------------------------------------------------------- /inc/spark_wiring_tcpclient.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_tcpclient.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_tcpclient.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __SPARK_WIRING_TCPCLIENT_H 27 | #define __SPARK_WIRING_TCPCLIENT_H 28 | 29 | #include "spark_wiring.h" 30 | 31 | #define TCPCLIENT_BUF_MAX_SIZE 512 32 | 33 | class TCPClient : public Stream { 34 | 35 | public: 36 | TCPClient(); 37 | TCPClient(uint8_t sock); 38 | virtual ~TCPClient() {}; 39 | 40 | uint8_t status(); 41 | virtual int connect(IPAddress ip, uint16_t port); 42 | virtual int connect(const char *host, uint16_t port); 43 | virtual size_t write(uint8_t); 44 | virtual size_t write(const uint8_t *buffer, size_t size); 45 | virtual int available(); 46 | virtual int read(); 47 | virtual int read(uint8_t *buffer, size_t size); 48 | virtual int peek(); 49 | virtual void flush(); 50 | virtual void stop(); 51 | virtual bool connected(); 52 | virtual operator bool(); 53 | virtual bool equals(TCPClient &tcpClient); 54 | void resetIp() { 55 | ip[0]=0; 56 | ip[1]=0; 57 | ip[2]=0; 58 | ip[3]=0; 59 | ip[4]=0; 60 | } 61 | void setIp (IPAddress &address, uint8_t port){ 62 | ip[0]=address[0]; 63 | ip[1]=address[1]; 64 | ip[2]=address[2]; 65 | ip[3]=address[3]; 66 | ip[4]=port; 67 | 68 | } 69 | void getIP(String &str) { 70 | str+=ip[0]; 71 | str+="."; 72 | str+=ip[1]; 73 | str+="."; 74 | str+=ip[2]; 75 | str+="."; 76 | str+=ip[3]; 77 | str+="."; 78 | str+=ip[4]; 79 | } 80 | friend class TCPServer; 81 | 82 | using Print::write; 83 | 84 | private: 85 | uint16_t _srcport; 86 | unsigned short ip[5]; 87 | 88 | long _sock; 89 | uint8_t _buffer[TCPCLIENT_BUF_MAX_SIZE]; 90 | uint16_t _offset; 91 | uint16_t _total; 92 | inline int bufferCount(); 93 | inline int isWanReady(); 94 | }; 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /inc/spark_wiring_tcpserver.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spark_wiring_tcpserver.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 13-March-2013 7 | * @brief Header for spark_wiring_tcpserver.cpp module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | #ifndef __SPARK_WIRING_TCPSERVER_H 27 | #define __SPARK_WIRING_TCPSERVER_H 28 | 29 | #include "spark_wiring.h" 30 | #include "spark_wiring_tcpclient.h" 31 | class TCPClient; 32 | 33 | class TCPServer : public Print { 34 | private: 35 | uint16_t _port; 36 | long _sock; 37 | 38 | public: 39 | TCPServer(uint16_t); 40 | 41 | TCPClient *available(); 42 | virtual void begin(); 43 | virtual size_t write(uint8_t); 44 | virtual size_t write(const uint8_t *buf, size_t size); 45 | 46 | using Print::write; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/build.mk: -------------------------------------------------------------------------------- 1 | # This file is a makefile included from the top level makefile which 2 | # defines the sources built for the target. 3 | 4 | # Define the prefix to this directory. 5 | # Note: The name must be unique within this build and should be 6 | # based on the root of the project 7 | TARGET_SRC_PATH = src 8 | 9 | # Add include to all objects built for this target 10 | INCLUDE_DIRS += inc 11 | 12 | # C source files included in this build. 13 | CSRC += 14 | 15 | # C++ source files included in this build. 16 | CPPSRC += $(TARGET_SRC_PATH)/application.cpp 17 | CPPSRC += $(TARGET_SRC_PATH)/SparkWebSocketServer.cpp 18 | CPPSRC += $(TARGET_SRC_PATH)/Base64.cpp 19 | CPPSRC += $(TARGET_SRC_PATH)/main.cpp 20 | CPPSRC += $(TARGET_SRC_PATH)/newlib_stubs.cpp 21 | CPPSRC += $(TARGET_SRC_PATH)/spark_utilities.cpp 22 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring.cpp 23 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_i2c.cpp 24 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_interrupts.cpp 25 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_ipaddress.cpp 26 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_network.cpp 27 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_print.cpp 28 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_servo.cpp 29 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_spi.cpp 30 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_stream.cpp 31 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_string.cpp 32 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_tcpclient.cpp 33 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_tcpserver.cpp 34 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_time.cpp 35 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_udp.cpp 36 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_usartserial.cpp 37 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_usbserial.cpp 38 | CPPSRC += $(TARGET_SRC_PATH)/spark_wiring_wifi.cpp 39 | CPPSRC += $(TARGET_SRC_PATH)/spark_wlan.cpp 40 | CPPSRC += $(TARGET_SRC_PATH)/stm32_it.cpp 41 | CPPSRC += $(TARGET_SRC_PATH)/usb_desc.cpp 42 | CPPSRC += $(TARGET_SRC_PATH)/usb_endp.cpp 43 | CPPSRC += $(TARGET_SRC_PATH)/usb_istr.cpp 44 | CPPSRC += $(TARGET_SRC_PATH)/usb_prop.cpp 45 | CPPSRC += $(TARGET_SRC_PATH)/wifi_credentials_reader.cpp 46 | 47 | # ASM source files included in this build. 48 | ASRC += 49 | 50 | --------------------------------------------------------------------------------