Skip to content

Commit

Permalink
code copied from SVN repo
Browse files Browse the repository at this point in the history
  • Loading branch information
RTL-pub committed Dec 7, 2018
1 parent c31d8a1 commit bb560ec
Show file tree
Hide file tree
Showing 32 changed files with 8,798 additions and 2 deletions.
78 changes: 78 additions & 0 deletions Makefile
@@ -0,0 +1,78 @@

VPATH := src:test:examples
#CFLAGS += -g
CFLAGS += -Wall -Iinc $(EXCFLAGS)

#Set the following for cross compilation
ifndef RANLIB
CXX=g++
CC=gcc
AR=ar
RANLIB=ranlib
endif

ifndef ARFLAGS
ARFLAGS=rv
endif

ifndef ODIR
ODIR = ./
endif

$(ODIR)/%.o : %.c
$(CC) -c $(CFLAGS) -o $@ $<
$(ODIR)/%.o : %.cpp
$(CXX) -c $(CFLAGS) -o $@ $<

# Three libs: One with all source code (large), one with
# JParserValFact (medium), and one with JDecoder.c (small)

CORESRC = BaAtoi.c BufPrint.c JEncoder.c JParser.c
JSONSRC = AllocatorIntf.c JVal.c JDecoder.c $(CORESRC)
VALFACTSRC = AllocatorIntf.c JVal.c $(CORESRC)
DECODERSRC = JDecoder.c $(CORESRC)


.PHONY: all libs examples c_example clean

#All examples: C and C++
all: libs
$(MAKE) examples

#Example using C only (no C++)
c_example: libs
$(MAKE) m2mled$(EXT)

libs: obj
$(MAKE) ODIR=obj/jd EXCFLAGS=-DNO_JVAL_DEPENDENCY libJDecoder.a
$(MAKE) ODIR=obj libJSON.a libValFact.a

obj:
mkdir obj
cd obj&&mkdir jd

libJSON.a: $(JSONSRC:%.c=$(ODIR)/%.o)
$(AR) $(ARFLAGS) $@ $^
$(RANLIB) $@

libValFact.a: $(VALFACTSRC:%.c=$(ODIR)/%.o)
$(AR) $(ARFLAGS) $@ $^
$(RANLIB) $@

libJDecoder.a: $(DECODERSRC:%.c=$(ODIR)/%.o)
$(AR) $(ARFLAGS) $@ $^
$(RANLIB) $@

examples: test1$(EXT) staticalloc$(EXT) m2mled$(EXT)

test1$(EXT): test1.o
$(CXX) -o $@ $^ -L. -lJSON $(EXTRALIBS)

staticalloc$(EXT): StaticAllocatorEx.o
$(CXX) -o $@ $^ -L. -lValFact $(EXTRALIBS)

m2mled$(EXT): m2m-led.o solib.o
$(CC) -o $@ $^ -L. -lJDecoder $(EXTRALIBS)

clean:
rm -rf obj *.a *.o
35 changes: 33 additions & 2 deletions README.md
@@ -1,2 +1,33 @@
# JSON
JSON C/C++ Library for IoT Communication
# JSON C/C++ Library for IoT Communication

The JSON C library is designed specifically for use in resource constrained micro controllers.

See the [JSON C/C++ Library home page](https://realtimelogic.com/products/json/) for details.

**The library can be used in three modes:**

* Using dynamic allocation (Complexity level: easy)
* Using static allocation based on the [JSON Parser Value Factory](https://realtimelogic.com/ba/doc/en/C/reference/html/structJParserValFact.html) (Complexity level: moderate)
* Using static allocation based on the [JSON Decoder](https://realtimelogic.com/ba/doc/en/C/reference/html/structJDecoder.html) class (Complexity level: advanced)

A detailed explanation on the three different modes can be found in the [reference manual](https://realtimelogic.com/ba/doc/en/C/reference/html/md_en_C_md_JSON.html) .

# Examples

* The m2m-led.c example is using the JSON parser in continuous stream parser mode and is using the more complex JSON Decoder setup.
* The StaticAllocatorEx.cpp shows how to use a static allocator with the JSON Parser Value Factory.
* Generic test/example program: test/test1.cpp

# Compiling

Decide if you want to use the more complex JDecoder with static allocation or the easier to use JSON Parser Value Factory (JParserValFact) with dynamic allocation or static allocation. See the documentation for details regarding these two classes.

* If using JParserValFact, include all C files in the build, except JDecoder.c
* If using JDecoder, include all C files in the build, except JVal.c and define the macro NO_JVAL_DEPENDENCY when compiling the code. See the comment at the top of the source file JEncoder.c for details.

The included example Makefile, which is configured for GCC, builds 3 libraries. See the Makefile for details.

NOTE: The C files in the src directory MUST be compiled by a C compiler and not by a C++ compiler. Files ending with .c must be compiled by a C compiler and files ending with .cpp must be compiled by a C++ compiler.



Binary file added ServerCode/IoT.zip
Binary file not shown.
12 changes: 12 additions & 0 deletions ServerCode/README.txt
@@ -0,0 +1,12 @@

IoT.zip includes the server side code for the m2m-led.c example program.

The code is designed for the Mako Server: https://makoserver.net/

You may connect m2m-led.c to your own server as follows:
1: edit m2m-led.c and set the address macro to "localhost"
2: Compile the m2mled example
3: Download and unpack the Mako Server in any directory
4: Start the server example as follows: path2mako/mako -lIoT::IoT.zip
5: Start m2mled

86 changes: 86 additions & 0 deletions VcMake/JDecoder.vcxproj
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\BaAtoi.c" />
<ClCompile Include="..\src\BufPrint.c" />
<ClCompile Include="..\src\JDecoder.c" />
<ClCompile Include="..\src\JEncoder.c" />
<ClCompile Include="..\src\JParser.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{75262908-FF79-4187-9902-34CD3A887CEB}</ProjectGuid>
<RootNamespace>m2m-led</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\jd\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\jd\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\inc</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NO_JVAL_DEPENDENCY</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DisableSpecificWarnings>4996;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>minnow.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>Debug</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\inc</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NO_JVAL_DEPENDENCY</PreprocessorDefinitions>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<Optimization>Full</Optimization>
<StringPooling>true</StringPooling>
</ClCompile>
<Link>
<AdditionalDependencies>minnow.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>Release</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
90 changes: 90 additions & 0 deletions VcMake/JSON.vcxproj
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\AllocatorIntf.c" />
<ClCompile Include="..\src\BaAtoi.c" />
<ClCompile Include="..\src\BufPrint.c" />
<ClCompile Include="..\src\JDecoder.c" />
<ClCompile Include="..\src\JEncoder.c" />
<ClCompile Include="..\src\JParser.c" />
<ClCompile Include="..\src\JVal.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6991B964-4C52-4096-A2E9-F852355ACCCB}</ProjectGuid>
<RootNamespace>m2m-led</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\inc</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DisableSpecificWarnings>4996;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>minnow.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>Debug</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\inc</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<Optimization>Full</Optimization>
<StringPooling>true</StringPooling>
</ClCompile>
<Link>
<AdditionalDependencies>minnow.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>Release</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
89 changes: 89 additions & 0 deletions VcMake/ValFact.vcxproj
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\AllocatorIntf.c" />
<ClCompile Include="..\src\BaAtoi.c" />
<ClCompile Include="..\src\BufPrint.c" />
<ClCompile Include="..\src\JEncoder.c" />
<ClCompile Include="..\src\JParser.c" />
<ClCompile Include="..\src\JVal.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{13DF4164-3E75-49F3-A257-64F88265C0C0}</ProjectGuid>
<RootNamespace>m2m-led</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\inc</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DisableSpecificWarnings>4996;4127;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<AdditionalDependencies>minnow.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>Debug</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\inc</AdditionalIncludeDirectories>
<PreprocessorDefinitions>
</PreprocessorDefinitions>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<WholeProgramOptimization>true</WholeProgramOptimization>
<Optimization>Full</Optimization>
<StringPooling>true</StringPooling>
</ClCompile>
<Link>
<AdditionalDependencies>minnow.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalLibraryDirectories>Release</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

0 comments on commit bb560ec

Please sign in to comment.