Changeset 364 for asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter
- Timestamp:
- Feb 1, 2019, 9:57:09 PM (5 years ago)
- Location:
- asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/.cproject
r345 r364 22 22 <storageModule moduleId="com.renesas.cdt.managedbuild.core.toolchainInfo"> 23 23 <option id="toolchain.id" value="RENESAS_GCC_RX"/> 24 <option id="toolchain.version" value="4.8.4.201 703"/>24 <option id="toolchain.version" value="4.8.4.201803"/> 25 25 </storageModule> 26 26 <storageModule moduleId="cdtBuildSystem" version="4.0.0"> … … 37 37 <option id="com.renesas.cdt.managedbuild.gcc.core.option.debug.warnStackSize.43669503" name="Warn if stack size exceeds the limit (-Wstack-usage) (H')" superClass="com.renesas.cdt.managedbuild.gcc.core.option.debug.warnStackSize" useByScannerDiscovery="false" value="100" valueType="string"/> 38 38 <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.renesas.cdt.managedbuild.gcc.core.targetPlatform.1762358251" isAbstract="false" osList="all" superClass="com.renesas.cdt.managedbuild.gcc.core.targetPlatform"/> 39 <builder buildPath="${workspace_loc:/app1_usb_watt_meter}/Debug" id="com.renesas.cdt.managedbuild.gcc.core.builder.464862236" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="GCC for Renesas Builder" parallelBuildOn=" false" superClass="com.renesas.cdt.managedbuild.gcc.core.builder"/>39 <builder buildPath="${workspace_loc:/app1_usb_watt_meter}/Debug" id="com.renesas.cdt.managedbuild.gcc.core.builder.464862236" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="GCC for Renesas Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.renesas.cdt.managedbuild.gcc.core.builder"/> 40 40 <tool id="com.renesas.cdt.managedbuild.gcc.rx.tool.libgen.1229888266" name="Library Generator" superClass="com.renesas.cdt.managedbuild.gcc.rx.tool.libgen"> 41 41 <option id="com.renesas.cdt.managedbuild.gcc.rx.option.selectlibrary.1883557018" name="Select Library" superClass="com.renesas.cdt.managedbuild.gcc.rx.option.selectlibrary" useByScannerDiscovery="true" value="com.renesas.cdt.managedbuild.gcc.core.option.librarygenerator.settings.selectLibrary.newLib" valueType="enumerated"/> … … 91 91 <storageModule moduleId="com.renesas.cdt.managedbuild.core.toolchainInfo"> 92 92 <option id="toolchain.id" value="RENESAS_GCC_RX"/> 93 <option id="toolchain.version" value="4.8.4.201 703"/>93 <option id="toolchain.version" value="4.8.4.201803"/> 94 94 </storageModule> 95 95 <storageModule moduleId="cdtBuildSystem" version="4.0.0"> … … 106 106 <option id="com.renesas.cdt.managedbuild.gcc.core.option.debug.warnStackSize.1468234416" name="Warn if stack size exceeds the limit (-Wstack-usage) (H')" superClass="com.renesas.cdt.managedbuild.gcc.core.option.debug.warnStackSize" useByScannerDiscovery="false" value="100" valueType="string"/> 107 107 <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.renesas.cdt.managedbuild.gcc.core.targetPlatform.1984029138" isAbstract="false" osList="all" superClass="com.renesas.cdt.managedbuild.gcc.core.targetPlatform"/> 108 <builder buildPath="${workspace_loc:/app1_usb_watt_meter}/DebugCitrus" id="com.renesas.cdt.managedbuild.gcc.core.builder.1277953315" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="GCC for Renesas Builder" parallelBuildOn=" false" superClass="com.renesas.cdt.managedbuild.gcc.core.builder"/>108 <builder buildPath="${workspace_loc:/app1_usb_watt_meter}/DebugCitrus" id="com.renesas.cdt.managedbuild.gcc.core.builder.1277953315" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="GCC for Renesas Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.renesas.cdt.managedbuild.gcc.core.builder"/> 109 109 <tool id="com.renesas.cdt.managedbuild.gcc.rx.tool.libgen.70642658" name="Library Generator" superClass="com.renesas.cdt.managedbuild.gcc.rx.tool.libgen"> 110 110 <option id="com.renesas.cdt.managedbuild.gcc.rx.option.selectlibrary.1213984969" name="Select Library" superClass="com.renesas.cdt.managedbuild.gcc.rx.option.selectlibrary" useByScannerDiscovery="true" value="com.renesas.cdt.managedbuild.gcc.core.option.librarygenerator.settings.selectLibrary.newLib" valueType="enumerated"/> … … 160 160 <storageModule moduleId="com.renesas.cdt.managedbuild.core.toolchainInfo"> 161 161 <option id="toolchain.id" value="RENESAS_GCC_RX"/> 162 <option id="toolchain.version" value="4.8.4.201 703"/>162 <option id="toolchain.version" value="4.8.4.201803"/> 163 163 </storageModule> 164 164 <storageModule moduleId="cdtBuildSystem" version="4.0.0"> … … 175 175 <option id="com.renesas.cdt.managedbuild.gcc.core.option.debug.warnStackSize.748885427" name="Warn if stack size exceeds the limit (-Wstack-usage) (H')" superClass="com.renesas.cdt.managedbuild.gcc.core.option.debug.warnStackSize" useByScannerDiscovery="false" value="100" valueType="string"/> 176 176 <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.renesas.cdt.managedbuild.gcc.core.targetPlatform.1713664515" isAbstract="false" osList="all" superClass="com.renesas.cdt.managedbuild.gcc.core.targetPlatform"/> 177 <builder buildPath="${workspace_loc:/app1_usb_watt_meter}/DebugEther" id="com.renesas.cdt.managedbuild.gcc.core.builder.1421742244" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="GCC for Renesas Builder" parallelBuildOn=" false" superClass="com.renesas.cdt.managedbuild.gcc.core.builder"/>177 <builder buildPath="${workspace_loc:/app1_usb_watt_meter}/DebugEther" id="com.renesas.cdt.managedbuild.gcc.core.builder.1421742244" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="GCC for Renesas Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.renesas.cdt.managedbuild.gcc.core.builder"/> 178 178 <tool id="com.renesas.cdt.managedbuild.gcc.rx.tool.libgen.899711517" name="Library Generator" superClass="com.renesas.cdt.managedbuild.gcc.rx.tool.libgen"> 179 179 <option id="com.renesas.cdt.managedbuild.gcc.rx.option.selectlibrary.898818532" name="Select Library" superClass="com.renesas.cdt.managedbuild.gcc.rx.option.selectlibrary" useByScannerDiscovery="true" value="com.renesas.cdt.managedbuild.gcc.core.option.librarygenerator.settings.selectLibrary.newLib" valueType="enumerated"/> … … 224 224 <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> 225 225 <storageModule moduleId="refreshScope" versionNumber="2"> 226 <configuration configurationName="DebugEther"/> 226 227 <configuration configurationName="DebugCitrus"> 227 228 <resource resourceType="PROJECT" workspacePath="/app1_usb_watt_meter"/> -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/Debug/Makefile
r342 r364 170 170 CDEFS := -DTOPPERS_OMIT_TECS $(CDEFS) 171 171 endif 172 CDEFS := $(CDEFS) -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR -D ECHONET_USE_MALLOC -DHAVE_CONFIG_H -DWOLFSSL_USER_SETTINGS -DRamDisk=binary_______ntshell_src_rom_fs_bin_start172 CDEFS := $(CDEFS) -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR -DNOUSE_MPF_NET_BUF -DECHONET_USE_MALLOC -DHAVE_CONFIG_H -DWOLFSSL_USER_SETTINGS -DRamDisk=binary_______ntshell_src_rom_fs_bin_start 173 173 INCLUDES := -I. -I$(SRCDIR)/include -I$(SRCDIR) \ 174 174 -I$(SRCDIR)/../btstack/include \ … … 184 184 -I$(SRCDIR)/../curl-7.57.0 \ 185 185 $(INCLUDES) 186 LDFLAGS := $(LDFLAGS) - Wl,-Map=$(OBJNAME).map,--cref -L.186 LDFLAGS := $(LDFLAGS) -L. 187 187 LIBS := $(LIBS) $(CXXLIBS) 188 188 CFLAGS = $(COPTS) $(CDEFS) $(INCLUDES) … … 206 206 APPL_ASMOBJS := 207 207 ifdef USE_CXX 208 APPL_CXXOBJS := main.o ntshell_main.o echonet_main.o client.o 208 APPL_CXXOBJS := main.o ntshell_main.o echonet_main.o client.o jsonsl.o 209 209 APPL_COBJS := $(APPL_COBJS) 210 210 else 211 APPL_COBJS := $(APPL_COBJS) main.o ntshell_main.o echonet_main.o client.o 211 APPL_COBJS := $(APPL_COBJS) main.o ntshell_main.o echonet_main.o client.o jsonsl.o 212 212 endif 213 213 APPL_COBJS := $(APPL_COBJS) log_output.o vasyslog.o t_perror.o strerror.o … … 218 218 endif 219 219 220 221 # 222 # ネットワークサービスの定義 223 # 224 NO_USE_TINET_LIBRARY = true 225 226 # ネットワークインタフェースの選択、何れか一つ選択する。 227 NET_IF = ether 228 229 # イーサネット・ディバイスドライバの選択 230 NET_DEV = if_btusb 231 232 # ネットワーク層の選択 233 #SUPPORT_INET6 = true 234 SUPPORT_INET4 = true 235 236 # API に組込む機能の選択 237 #API_CFG_IP4MAPPED_ADDR = true 238 239 # トランスポート層の選択 240 SUPPORT_TCP = true 241 SUPPORT_UDP = true 242 243 # IGMPを有効に設定 244 SUPPORT_IGMP = true 245 246 # 247 # ネットワークサービスの Makefile のインクルード 248 # 249 include $(SRCDIR)/$(TINETDIR)/Makefile.tinet 220 ifdef TINETDIR 221 # 222 # ネットワークサービスの定義 223 # 224 NO_USE_TINET_LIBRARY = true 225 226 # ネットワークインタフェースの選択、何れか一つ選択する。 227 NET_IF = ether 228 229 # イーサネット・ディバイスドライバの選択 230 NET_DEV = if_btusb 231 232 # ネットワーク層の選択 233 #SUPPORT_INET6 = true 234 SUPPORT_INET4 = true 235 236 # API に組込む機能の選択 237 #API_CFG_IP4MAPPED_ADDR = true 238 239 # トランスポート層の選択 240 SUPPORT_TCP = true 241 SUPPORT_UDP = true 242 243 # IGMPを有効に設定 244 SUPPORT_IGMP = true 245 246 # 247 # ネットワークサービスの Makefile のインクルード 248 # 249 include $(SRCDIR)/$(TINETDIR)/Makefile.tinet 250 endif 250 251 251 252 # … … 267 268 all: tecs | $(DEPDIR) 268 269 # @$(MAKE) check 269 @$(MAKE) check $(OBJNAME).bin270 # @$(MAKE) check $(OBJNAME).bin 270 271 # @$(MAKE) check $(OBJNAME).srec 272 @$(MAKE) check $(OBJNAME).mot 271 273 else 272 274 #all: check 273 all: check $(OBJNAME).bin275 #all: check $(OBJNAME).bin 274 276 #all: check $(OBJNAME).srec 277 all: check $(OBJNAME).mot 275 278 endif 276 279 … … 280 283 # コンフィギュレータに関する定義 281 284 # 282 CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T ../../ntshell/echonet/echonet.trb:echonet -T $(TARGETDIR)/target_kernel.trb:kernel 283 CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \ 285 ifndef TINETDIR 286 CFG_TRB := -T $(TARGETDIR)/target_kernel.trb 287 CFG_TABS := --api-table $(SRCDIR)/kernel/kernel_api.def \ 288 --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS) 289 else 290 CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T ../../ntshell/echonet/echonet.trb:echonet -T $(TARGETDIR)/target_kernel.trb:kernel 291 CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \ 284 292 --api-table ../../ntshell/echonet/echonet_api.def:echonet \ 285 293 --api-table $(SRCDIR)/kernel/kernel_api.def:kernel \ … … 287 295 --symval-table ../../ntshell/echonet/echonet_sym.def \ 288 296 --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS) 297 endif 289 298 CFG_ASMOBJS := $(CFG_ASMOBJS) 290 299 CFG_COBJS := kernel_cfg.o echonet_cfg.o $(CFG_COBJS) … … 432 441 433 442 # 443 # 並列makeのための依存関係の定義 444 # 445 $(APPL_OBJS) $(SYSSVC_OBJS): | kernel_cfg.timestamp 446 $(APPL_ASMOBJS) $(SYSSVC_ASMOBJS) $(KERNEL_ASMOBJS) $(CFG_ASMOBJS): \ 447 | offset.timestamp 448 449 # 434 450 # 特別な依存関係の定義 435 451 # … … 440 456 # 441 457 $(OBJFILE): $(ALL_OBJS) $(LIBS_DEP) 442 $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJ_LDFLAGS) -o $(OBJFILE) \458 $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJ_LDFLAGS) -o $(OBJFILE) -Wl,-Map=$(OBJNAME).map,--cref \ 443 459 $(START_OBJS) $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) \ 444 460 -Wl,--start-group $(ALL_LIBS) -Wl,--end-group $(END_OBJS) … … 469 485 $(OBJNAME).srec: $(OBJFILE) 470 486 $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).srec 487 488 $(OBJNAME).mot: $(OBJFILE) 489 $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).mot 471 490 472 491 # -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/DebugCitrus/Makefile
r342 r364 170 170 CDEFS := -DTOPPERS_OMIT_TECS $(CDEFS) 171 171 endif 172 CDEFS := $(CDEFS) -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR -D ECHONET_USE_MALLOC -DHAVE_CONFIG_H -DWOLFSSL_USER_SETTINGS -DRamDisk=binary_______ntshell_src_rom_fs_bin_start172 CDEFS := $(CDEFS) -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR -DNOUSE_MPF_NET_BUF -DECHONET_USE_MALLOC -DHAVE_CONFIG_H -DWOLFSSL_USER_SETTINGS -DRamDisk=binary_______ntshell_src_rom_fs_bin_start 173 173 INCLUDES := -I. -I$(SRCDIR)/include -I$(SRCDIR) \ 174 174 -I$(SRCDIR)/../btstack/include \ … … 184 184 -I$(SRCDIR)/../curl-7.57.0 \ 185 185 $(INCLUDES) 186 LDFLAGS := $(LDFLAGS) - Wl,-Map=$(OBJNAME).map,--cref -L.186 LDFLAGS := $(LDFLAGS) -L. 187 187 LIBS := $(LIBS) $(CXXLIBS) 188 188 CFLAGS = $(COPTS) $(CDEFS) $(INCLUDES) … … 206 206 APPL_ASMOBJS := 207 207 ifdef USE_CXX 208 APPL_CXXOBJS := main.o ntshell_main.o echonet_main.o client.o 208 APPL_CXXOBJS := main.o ntshell_main.o echonet_main.o client.o jsonsl.o 209 209 APPL_COBJS := $(APPL_COBJS) 210 210 else 211 APPL_COBJS := $(APPL_COBJS) main.o ntshell_main.o echonet_main.o client.o 211 APPL_COBJS := $(APPL_COBJS) main.o ntshell_main.o echonet_main.o client.o jsonsl.o 212 212 endif 213 213 APPL_COBJS := $(APPL_COBJS) log_output.o vasyslog.o t_perror.o strerror.o … … 218 218 endif 219 219 220 221 # 222 # ネットワークサービスの定義 223 # 224 NO_USE_TINET_LIBRARY = true 225 226 # ネットワークインタフェースの選択、何れか一つ選択する。 227 NET_IF = ether 228 229 # イーサネット・ディバイスドライバの選択 230 NET_DEV = if_btusb 231 232 # ネットワーク層の選択 233 #SUPPORT_INET6 = true 234 SUPPORT_INET4 = true 235 236 # API に組込む機能の選択 237 #API_CFG_IP4MAPPED_ADDR = true 238 239 # トランスポート層の選択 240 SUPPORT_TCP = true 241 SUPPORT_UDP = true 242 243 # IGMPを有効に設定 244 SUPPORT_IGMP = true 245 246 # 247 # ネットワークサービスの Makefile のインクルード 248 # 249 include $(SRCDIR)/$(TINETDIR)/Makefile.tinet 220 ifdef TINETDIR 221 # 222 # ネットワークサービスの定義 223 # 224 NO_USE_TINET_LIBRARY = true 225 226 # ネットワークインタフェースの選択、何れか一つ選択する。 227 NET_IF = ether 228 229 # イーサネット・ディバイスドライバの選択 230 NET_DEV = if_btusb 231 232 # ネットワーク層の選択 233 #SUPPORT_INET6 = true 234 SUPPORT_INET4 = true 235 236 # API に組込む機能の選択 237 #API_CFG_IP4MAPPED_ADDR = true 238 239 # トランスポート層の選択 240 SUPPORT_TCP = true 241 SUPPORT_UDP = true 242 243 # IGMPを有効に設定 244 SUPPORT_IGMP = true 245 246 # 247 # ネットワークサービスの Makefile のインクルード 248 # 249 include $(SRCDIR)/$(TINETDIR)/Makefile.tinet 250 endif 250 251 251 252 # … … 267 268 all: tecs | $(DEPDIR) 268 269 # @$(MAKE) check 269 @$(MAKE) check $(OBJNAME).bin270 # @$(MAKE) check $(OBJNAME).bin 270 271 # @$(MAKE) check $(OBJNAME).srec 272 @$(MAKE) check $(OBJNAME).mot 271 273 else 272 274 #all: check 273 all: check $(OBJNAME).bin275 #all: check $(OBJNAME).bin 274 276 #all: check $(OBJNAME).srec 277 all: check $(OBJNAME).mot 275 278 endif 276 279 … … 280 283 # コンフィギュレータに関する定義 281 284 # 282 CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T ../../ntshell/echonet/echonet.trb:echonet -T $(TARGETDIR)/target_kernel.trb:kernel 283 CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \ 285 ifndef TINETDIR 286 CFG_TRB := -T $(TARGETDIR)/target_kernel.trb 287 CFG_TABS := --api-table $(SRCDIR)/kernel/kernel_api.def \ 288 --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS) 289 else 290 CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T ../../ntshell/echonet/echonet.trb:echonet -T $(TARGETDIR)/target_kernel.trb:kernel 291 CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \ 284 292 --api-table ../../ntshell/echonet/echonet_api.def:echonet \ 285 293 --api-table $(SRCDIR)/kernel/kernel_api.def:kernel \ … … 287 295 --symval-table ../../ntshell/echonet/echonet_sym.def \ 288 296 --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS) 297 endif 289 298 CFG_ASMOBJS := $(CFG_ASMOBJS) 290 299 CFG_COBJS := kernel_cfg.o echonet_cfg.o $(CFG_COBJS) … … 432 441 433 442 # 443 # 並列makeのための依存関係の定義 444 # 445 $(APPL_OBJS) $(SYSSVC_OBJS): | kernel_cfg.timestamp 446 $(APPL_ASMOBJS) $(SYSSVC_ASMOBJS) $(KERNEL_ASMOBJS) $(CFG_ASMOBJS): \ 447 | offset.timestamp 448 449 # 434 450 # 特別な依存関係の定義 435 451 # … … 440 456 # 441 457 $(OBJFILE): $(ALL_OBJS) $(LIBS_DEP) 442 $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJ_LDFLAGS) -o $(OBJFILE) \458 $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJ_LDFLAGS) -o $(OBJFILE) -Wl,-Map=$(OBJNAME).map,--cref \ 443 459 $(START_OBJS) $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) \ 444 460 -Wl,--start-group $(ALL_LIBS) -Wl,--end-group $(END_OBJS) … … 469 485 $(OBJNAME).srec: $(OBJFILE) 470 486 $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).srec 487 488 $(OBJNAME).mot: $(OBJFILE) 489 $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).mot 471 490 472 491 # -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/DebugEther/Makefile
r342 r364 170 170 CDEFS := -DTOPPERS_OMIT_TECS $(CDEFS) 171 171 endif 172 CDEFS := $(CDEFS) -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR -D ECHONET_USE_MALLOC -DHAVE_CONFIG_H -DWOLFSSL_USER_SETTINGS -DRamDisk=binary_______ntshell_src_rom_fs_bin_start172 CDEFS := $(CDEFS) -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR -DNOUSE_MPF_NET_BUF -DECHONET_USE_MALLOC -DHAVE_CONFIG_H -DWOLFSSL_USER_SETTINGS -DRamDisk=binary_______ntshell_src_rom_fs_bin_start 173 173 INCLUDES := -I. -I$(SRCDIR)/include -I$(SRCDIR) \ 174 174 -I$(SRCDIR)/../btstack/include \ … … 184 184 -I$(SRCDIR)/../curl-7.57.0 \ 185 185 $(INCLUDES) 186 LDFLAGS := $(LDFLAGS) - Wl,-Map=$(OBJNAME).map,--cref -L.186 LDFLAGS := $(LDFLAGS) -L. 187 187 LIBS := $(LIBS) $(CXXLIBS) 188 188 CFLAGS = $(COPTS) $(CDEFS) $(INCLUDES) … … 206 206 APPL_ASMOBJS := 207 207 ifdef USE_CXX 208 APPL_CXXOBJS := main.o ntshell_main.o echonet_main.o client.o 208 APPL_CXXOBJS := main.o ntshell_main.o echonet_main.o client.o jsonsl.o 209 209 APPL_COBJS := $(APPL_COBJS) 210 210 else 211 APPL_COBJS := $(APPL_COBJS) main.o ntshell_main.o echonet_main.o client.o 211 APPL_COBJS := $(APPL_COBJS) main.o ntshell_main.o echonet_main.o client.o jsonsl.o 212 212 endif 213 213 APPL_COBJS := $(APPL_COBJS) log_output.o vasyslog.o t_perror.o strerror.o … … 218 218 endif 219 219 220 221 #222 # ネットワークサービスの定義223 #224 NO_USE_TINET_LIBRARY = true225 226 # ネットワークインタフェースの選択、何れか一つ選択する。227 NET_IF = ether228 229 # イーサネット・ディバイスドライバの選択220 ifdef TINETDIR 221 # 222 # ネットワークサービスの定義 223 # 224 NO_USE_TINET_LIBRARY = true 225 226 # ネットワークインタフェースの選択、何れか一つ選択する。 227 NET_IF = ether 228 229 # イーサネット・ディバイスドライバの選択 230 230 NET_DEV = if_rx62n 231 231 232 # ネットワーク層の選択 233 #SUPPORT_INET6 = true 234 SUPPORT_INET4 = true 235 236 # API に組込む機能の選択 237 #API_CFG_IP4MAPPED_ADDR = true 238 239 # トランスポート層の選択 240 SUPPORT_TCP = true 241 SUPPORT_UDP = true 242 243 # IGMPを有効に設定 244 SUPPORT_IGMP = true 245 246 # 247 # ネットワークサービスの Makefile のインクルード 248 # 249 include $(SRCDIR)/$(TINETDIR)/Makefile.tinet 232 # ネットワーク層の選択 233 #SUPPORT_INET6 = true 234 SUPPORT_INET4 = true 235 236 # API に組込む機能の選択 237 #API_CFG_IP4MAPPED_ADDR = true 238 239 # トランスポート層の選択 240 SUPPORT_TCP = true 241 SUPPORT_UDP = true 242 243 # IGMPを有効に設定 244 SUPPORT_IGMP = true 245 246 # 247 # ネットワークサービスの Makefile のインクルード 248 # 249 include $(SRCDIR)/$(TINETDIR)/Makefile.tinet 250 endif 250 251 251 252 # … … 267 268 all: tecs | $(DEPDIR) 268 269 # @$(MAKE) check 269 @$(MAKE) check $(OBJNAME).bin270 # @$(MAKE) check $(OBJNAME).bin 270 271 # @$(MAKE) check $(OBJNAME).srec 272 @$(MAKE) check $(OBJNAME).mot 271 273 else 272 274 #all: check 273 all: check $(OBJNAME).bin275 #all: check $(OBJNAME).bin 274 276 #all: check $(OBJNAME).srec 277 all: check $(OBJNAME).mot 275 278 endif 276 279 … … 280 283 # コンフィギュレータに関する定義 281 284 # 282 CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T ../../ntshell/echonet/echonet.trb:echonet -T $(TARGETDIR)/target_kernel.trb:kernel 283 CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \ 285 ifndef TINETDIR 286 CFG_TRB := -T $(TARGETDIR)/target_kernel.trb 287 CFG_TABS := --api-table $(SRCDIR)/kernel/kernel_api.def \ 288 --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS) 289 else 290 CFG_TRB := -T $(TINET_ROOT)/tinet.trb:tcpip -T ../../ntshell/echonet/echonet.trb:echonet -T $(TARGETDIR)/target_kernel.trb:kernel 291 CFG_TABS := --api-table $(TINET_ROOT)/tcpip_api.def:tcpip \ 284 292 --api-table ../../ntshell/echonet/echonet_api.def:echonet \ 285 293 --api-table $(SRCDIR)/kernel/kernel_api.def:kernel \ … … 287 295 --symval-table ../../ntshell/echonet/echonet_sym.def \ 288 296 --symval-table $(SRCDIR)/kernel/kernel_sym.def $(CFG_TABS) 297 endif 289 298 CFG_ASMOBJS := $(CFG_ASMOBJS) 290 299 CFG_COBJS := kernel_cfg.o echonet_cfg.o $(CFG_COBJS) … … 432 441 433 442 # 443 # 並列makeのための依存関係の定義 444 # 445 $(APPL_OBJS) $(SYSSVC_OBJS): | kernel_cfg.timestamp 446 $(APPL_ASMOBJS) $(SYSSVC_ASMOBJS) $(KERNEL_ASMOBJS) $(CFG_ASMOBJS): \ 447 | offset.timestamp 448 449 # 434 450 # 特別な依存関係の定義 435 451 # … … 440 456 # 441 457 $(OBJFILE): $(ALL_OBJS) $(LIBS_DEP) 442 $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJ_LDFLAGS) -o $(OBJFILE) \458 $(LINK) $(CFLAGS) $(LDFLAGS) $(OBJ_LDFLAGS) -o $(OBJFILE) -Wl,-Map=$(OBJNAME).map,--cref \ 443 459 $(START_OBJS) $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) \ 444 460 -Wl,--start-group $(ALL_LIBS) -Wl,--end-group $(END_OBJS) … … 469 485 $(OBJNAME).srec: $(OBJFILE) 470 486 $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).srec 487 488 $(OBJNAME).mot: $(OBJFILE) 489 $(OBJCOPY) -O srec -S $(OBJFILE) $(OBJNAME).mot 471 490 472 491 # -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/src/client.c
r350 r364 1 1 /* 2 2 * TOPPERS ECHONET Lite Communication Middleware 3 * 3 * 4 4 * Copyright (C) 2016 Cores Co., Ltd. Japan 5 * 5 * 6 6 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ 7 7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 … … 26 26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを 27 27 * 免責すること. 28 * 28 * 29 29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お 30 30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 … … 32 32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ 33 33 * の責任を負わない. 34 * 34 * 35 35 * @(#) $Id$ 36 36 */ … … 48 48 #include "ff.h" 49 49 #include "util/ntstdio.h" 50 #include "client.h" 51 #include "jsonsl.h" 50 52 51 53 #define SKIP_PEER_VERIFICATION 52 54 //#define SKIP_HOSTNAME_VERIFICATION 55 56 const char SCOPE_DRIVE_FILE[] = "https://www.googleapis.com/auth/drive.file"; 57 const char GRANT_TYPE_DEVICE[] = "http://oauth.net/grant_type/device/1.0"; 58 53 59 char response[80]; 54 extern ntstdio_t ntstdio; 60 char errbuf[CURL_ERROR_SIZE]; 61 62 google_drive_t google_drive; 63 64 void curl_setopt_common(CURL *curl); 65 int google_drive_error_callback(jsonsl_t jsn, jsonsl_error_t err, 66 struct jsonsl_state_st *state, char *errat); 67 void google_drive_state_callback(jsonsl_t jsn, jsonsl_action_t action, 68 struct jsonsl_state_st *state, const char *buf); 55 69 56 70 void client_init(void) 57 71 { 72 google_drive_t *gd = &google_drive; 73 jsonsl_t jsn; 74 75 memset(gd, 0, sizeof(google_drive_t)); 76 memcpy(gd->fname, "1:/log/20160101000000.log", sizeof(gd->fname)); 77 78 jsn = gd->jsn = jsonsl_new(3); 79 jsn->data = gd; 80 jsn->error_callback = google_drive_error_callback; 81 jsn->action_callback = google_drive_state_callback; 82 jsonsl_enable_all_callbacks(jsn); 83 58 84 //uITRON4_minit(ITRON_POOL_SIZE); 59 85 … … 61 87 } 62 88 63 size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp) 64 { 65 int rest = size * nmemb; 89 size_t write_callback(void *buffer, size_t size, size_t nmemb, void *arg) 90 { 91 google_drive_t *gd = (google_drive_t *)arg; 92 jsonsl_t jsn = gd->jsn; 93 size_t len = size * nmemb, pos; 94 jsonsl_char_t data; 95 96 for (pos = 0; pos < len; pos++) { 97 data = *((jsonsl_char_t *)&((uint8_t *)buffer)[pos]); 98 99 if ((gd->jsn_buf_pos >= 0) && (gd->jsn_buf_pos < sizeof(gd->jsn_buf))) 100 gd->jsn_buf[gd->jsn_buf_pos++] = data; 101 jsonsl_feed(jsn, &data, 1); 102 } 103 104 return len; 105 } 106 107 void get_device_id_state_start(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 108 { 109 switch (gd->state) { 110 case psRoot: 111 if (state->level != 2) { 112 break; 113 } 114 else if (strcmp(buf, "device_code") == 0) { 115 gd->state = psDeviceCode; 116 } 117 else if (strcmp(buf, "user_code") == 0) { 118 gd->state = psUserCode; 119 } 120 else if (strcmp(buf, "expires_in") == 0) { 121 gd->state = psExpiresIn; 122 } 123 else if (strcmp(buf, "interval") == 0) { 124 gd->state = psInterval; 125 } 126 else if (strcmp(buf, "verification_url") == 0) { 127 gd->state = psVerificationUrl; 128 } 129 else if (strcmp(buf, "error") == 0) { 130 gd->state = psError; 131 } 132 else if (strcmp(buf, "error_description") == 0) { 133 gd->state = psErrorDescription; 134 } 135 break; 136 case psDeviceCode: 137 if (state->type == JSONSL_T_STRING) { 138 strlcpy(gd->credential.device_code, buf, sizeof(gd->credential.device_code)); 139 gd->state = psRoot; 140 } 141 break; 142 case psUserCode: 143 if (state->type == JSONSL_T_STRING) { 144 strlcpy(gd->credential.user_code, buf, sizeof(gd->credential.user_code)); 145 gd->state = psRoot; 146 } 147 break; 148 case psExpiresIn: 149 if (state->type == JSONSL_T_SPECIAL) { 150 gd->credential.expires_in = atoi(buf); 151 gd->state = psRoot; 152 } 153 break; 154 case psInterval: 155 if (state->type == JSONSL_T_SPECIAL) { 156 gd->credential.interval = atoi(buf); 157 gd->state = psRoot; 158 } 159 break; 160 case psVerificationUrl: 161 if (state->type == JSONSL_T_STRING) { 162 strlcpy(gd->credential.verification_url, buf, sizeof(gd->credential.verification_url)); 163 gd->state = psRoot; 164 } 165 break; 166 case psError: 167 if (state->type == JSONSL_T_STRING) { 168 strlcpy(gd->error.error, buf, sizeof(gd->error.error)); 169 gd->state = psRoot; 170 } 171 break; 172 case psErrorDescription: 173 if (state->type == JSONSL_T_STRING) { 174 strlcpy(gd->error.error_description, buf, sizeof(gd->error.error_description)); 175 gd->state = psRoot; 176 } 177 break; 178 } 179 } 180 181 void get_device_id_state_end(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 182 { 183 } 184 185 int get_device_id(google_drive_t *gd, const char *scope) 186 { 187 client_info_t *client_info = &gd->client_info; 188 credential_t *credential = &gd->credential; 189 CURLcode ret; 190 CURL *curl; 191 struct curl_slist *slist1; 192 size_t len; 193 char *postdata; 194 jsonsl_t jsn = gd->jsn; 195 196 gd->jsn_buf_pos = -1; 197 198 jsonsl_reset(jsn); 199 gd->start = get_device_id_state_start; 200 gd->end = get_device_id_state_end; 201 202 slist1 = NULL; 203 slist1 = curl_slist_append(slist1, "Content-Type: application/x-www-form-urlencoded"); 204 205 curl = curl_easy_init(); 206 207 char *client_id = curl_easy_escape(curl, client_info->client_id, strnlen(client_info->client_id, sizeof(client_info->client_id))); 208 char *esc_scope = curl_easy_escape(curl, scope, strlen(scope)); 209 210 len = sizeof("client_id=") + strlen(client_id) + sizeof("scope=") + strlen(esc_scope); 211 postdata = malloc(len); 212 snprintf(postdata, len, "client_id=%s&scope=%s", client_id, esc_scope); 213 214 curl_free(client_id); 215 curl_free(esc_scope); 216 217 curl_easy_setopt(curl, CURLOPT_URL, "https://accounts.google.com/o/oauth2/device/code"); 218 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata); 219 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)strnlen(postdata, len)); 220 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1); 221 curl_setopt_common(curl); 222 223 curl_easy_setopt(curl, CURLOPT_WRITEDATA, gd); 224 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); 225 226 ret = curl_easy_perform(curl); 227 228 free(postdata); 229 230 curl_easy_cleanup(curl); 231 curl = NULL; 232 curl_slist_free_all(slist1); 233 slist1 = NULL; 234 235 return (int)ret; 236 } 237 238 void get_access_token_state_start(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 239 { 240 switch (gd->state) { 241 case psRoot: 242 if (state->level != 2) { 243 break; 244 } 245 else if (strcmp(buf, "access_token") == 0) { 246 gd->state = psAccessToken; 247 } 248 else if (strcmp(buf, "expires_in") == 0) { 249 gd->state = psExpiresIn; 250 } 251 else if (strcmp(buf, "refresh_token") == 0) { 252 gd->state = psRefreshToken; 253 } 254 else if (strcmp(buf, "scope") == 0) { 255 gd->state = psScope; 256 } 257 else if (strcmp(buf, "token_type") == 0) { 258 gd->state = psTokenType; 259 } 260 else if (strcmp(buf, "error") == 0) { 261 gd->state = psError; 262 } 263 else if (strcmp(buf, "error_description") == 0) { 264 gd->state = psErrorDescription; 265 } 266 break; 267 case psAccessToken: 268 if (state->type == JSONSL_T_STRING) { 269 strlcpy(gd->credential.access_token, buf, sizeof(gd->credential.access_token)); 270 gd->state = psRoot; 271 } 272 break; 273 case psExpiresIn: 274 if (state->type == JSONSL_T_SPECIAL) { 275 gd->credential.expires_in = atoi(buf); 276 gd->state = psRoot; 277 } 278 break; 279 case psRefreshToken: 280 if (state->type == JSONSL_T_STRING) { 281 strlcpy(gd->credential.refresh_token, buf, sizeof(gd->credential.refresh_token)); 282 gd->state = psRoot; 283 } 284 break; 285 case psScope: 286 if (state->type == JSONSL_T_STRING) { 287 strlcpy(gd->credential.scope, buf, sizeof(gd->credential.scope)); 288 gd->state = psRoot; 289 } 290 break; 291 case psTokenType: 292 if (state->type == JSONSL_T_STRING) { 293 strlcpy(gd->credential.token_type, buf, sizeof(gd->credential.token_type)); 294 gd->state = psRoot; 295 } 296 break; 297 case psError: 298 if (state->type == JSONSL_T_STRING) { 299 strlcpy(gd->error.error, buf, sizeof(gd->error.error)); 300 gd->state = psRoot; 301 } 302 break; 303 case psErrorDescription: 304 if (state->type == JSONSL_T_STRING) { 305 strlcpy(gd->error.error_description, buf, sizeof(gd->error.error_description)); 306 gd->state = psRoot; 307 } 308 break; 309 } 310 } 311 312 void get_access_token_state_end(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 313 { 314 } 315 316 int get_access_token(google_drive_t *gd) 317 { 318 client_info_t *client_info = &gd->client_info; 319 credential_t *credential = &gd->credential; 320 CURLcode ret; 321 CURL *curl; 322 struct curl_slist *slist1; 323 size_t len; 324 char *postdata; 325 jsonsl_t jsn = gd->jsn; 326 327 gd->jsn_buf_pos = -1; 328 329 jsonsl_reset(jsn); 330 gd->start = get_access_token_state_start; 331 gd->end = get_access_token_state_end; 332 333 slist1 = NULL; 334 slist1 = curl_slist_append(slist1, "Content-Type: application/x-www-form-urlencoded"); 335 336 curl = curl_easy_init(); 337 338 char *client_id = curl_easy_escape(curl, client_info->client_id, strnlen(client_info->client_id, sizeof(client_info->client_id))); 339 char *client_secret = curl_easy_escape(curl, client_info->client_secret, strnlen(client_info->client_secret, sizeof(client_info->client_secret))); 340 char *grant_type = curl_easy_escape(curl, GRANT_TYPE_DEVICE, strnlen(GRANT_TYPE_DEVICE, sizeof(GRANT_TYPE_DEVICE))); 341 342 len = sizeof("client_id=") + strlen(client_id) + sizeof("client_secret=") + strlen(client_secret) 343 + sizeof("code=") + strlen(credential->device_code) + sizeof("grant_type=") + strlen(grant_type); 344 postdata = malloc(len); 345 snprintf(postdata, len, "client_id=%s&client_secret=%s&code=%s&grant_type=%s", 346 client_id, client_secret, credential->device_code, grant_type); 347 348 curl_free(client_id); 349 curl_free(client_secret); 350 curl_free(grant_type); 351 352 curl_easy_setopt(curl, CURLOPT_URL, "https://www.googleapis.com/oauth2/v4/token"); 353 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata); 354 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)strnlen(postdata, len)); 355 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1); 356 curl_setopt_common(curl); 357 358 curl_easy_setopt(curl, CURLOPT_WRITEDATA, gd); 359 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); 360 361 ret = curl_easy_perform(curl); 362 363 free(postdata); 364 365 curl_easy_cleanup(curl); 366 curl = NULL; 367 curl_slist_free_all(slist1); 368 slist1 = NULL; 369 370 return (int)ret; 371 } 372 373 void update_access_token_state_start(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 374 { 375 switch (gd->state) { 376 case psRoot: 377 if (state->level != 2) { 378 break; 379 } 380 else if (strcmp(buf, "access_token") == 0) { 381 gd->state = psAccessToken; 382 } 383 else if (strcmp(buf, "expires_in") == 0) { 384 gd->state = psExpiresIn; 385 } 386 else if (strcmp(buf, "scope") == 0) { 387 gd->state = psScope; 388 } 389 else if (strcmp(buf, "token_type") == 0) { 390 gd->state = psTokenType; 391 } 392 else if (strcmp(buf, "error") == 0) { 393 gd->state = psError; 394 } 395 else if (strcmp(buf, "error_description") == 0) { 396 gd->state = psErrorDescription; 397 } 398 break; 399 case psAccessToken: 400 if (state->type == JSONSL_T_STRING) { 401 strlcpy(gd->credential.access_token, buf, sizeof(gd->credential.access_token)); 402 gd->state = psRoot; 403 } 404 break; 405 case psExpiresIn: 406 if (state->type == JSONSL_T_SPECIAL) { 407 gd->credential.expires_in = atoi(buf); 408 gd->state = psRoot; 409 } 410 break; 411 case psScope: 412 if (state->type == JSONSL_T_STRING) { 413 strlcpy(gd->credential.scope, buf, sizeof(gd->credential.scope)); 414 gd->state = psRoot; 415 } 416 break; 417 case psTokenType: 418 if (state->type == JSONSL_T_STRING) { 419 strlcpy(gd->credential.token_type, buf, sizeof(gd->credential.token_type)); 420 gd->state = psRoot; 421 } 422 break; 423 case psError: 424 if (state->type == JSONSL_T_STRING) { 425 strlcpy(gd->error.error, buf, sizeof(gd->error.error)); 426 gd->state = psRoot; 427 } 428 break; 429 case psErrorDescription: 430 if (state->type == JSONSL_T_STRING) { 431 strlcpy(gd->error.error_description, buf, sizeof(gd->error.error_description)); 432 gd->state = psRoot; 433 } 434 break; 435 } 436 } 437 438 void update_access_token_state_end(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 439 { 440 } 441 442 int update_access_token(google_drive_t *gd) 443 { 444 client_info_t *client_info = &gd->client_info; 445 credential_t *credential = &gd->credential; 446 CURLcode ret; 447 CURL *curl; 448 struct curl_slist *slist1; 449 size_t len; 450 char *postdata; 451 jsonsl_t jsn = gd->jsn; 452 453 gd->jsn_buf_pos = -1; 454 455 jsonsl_reset(jsn); 456 gd->start = update_access_token_state_start; 457 gd->end = update_access_token_state_end; 458 459 slist1 = NULL; 460 slist1 = curl_slist_append(slist1, "Content-Type: application/x-www-form-urlencoded"); 461 462 curl = curl_easy_init(); 463 464 char *client_id = curl_easy_escape(curl, client_info->client_id, strnlen(client_info->client_id, sizeof(client_info->client_id))); 465 char *client_secret = curl_easy_escape(curl, client_info->client_secret, strnlen(client_info->client_secret, sizeof(client_info->client_secret))); 466 467 len = sizeof("client_id=") + strlen(client_id) + sizeof("client_secret=") + strlen(client_secret) 468 + sizeof("refresh_token=") + strlen(credential->refresh_token); 469 postdata = malloc(len); 470 snprintf(postdata, len, "client_id=%s&client_secret=%s&code=%s&grant_type=refresh_token", 471 client_id, client_secret, credential->refresh_token); 472 473 curl_free(client_id); 474 curl_free(client_secret); 475 476 curl_easy_setopt(curl, CURLOPT_URL, "https://www.googleapis.com/oauth2/v4/token"); 477 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata); 478 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)strnlen(postdata, len)); 479 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1); 480 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); 481 curl_setopt_common(curl); 482 483 curl_easy_setopt(curl, CURLOPT_WRITEDATA, gd); 484 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); 485 486 ret = curl_easy_perform(curl); 487 488 free(postdata); 489 490 curl_easy_cleanup(curl); 491 curl = NULL; 492 curl_slist_free_all(slist1); 493 slist1 = NULL; 494 495 return (int)ret; 496 } 497 498 void revoke_device_state_start(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 499 { 500 } 501 502 void revoke_device_state_end(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 503 { 504 } 505 506 int revoke_device(google_drive_t *gd) 507 { 508 client_info_t *client_info = &gd->client_info; 509 credential_t *credential = &gd->credential; 510 CURLcode ret; 511 CURL *curl; 512 size_t len; 513 struct curl_slist *slist1; 514 char *postdata; 515 jsonsl_t jsn = gd->jsn; 516 517 gd->jsn_buf_pos = -1; 518 519 jsonsl_reset(jsn); 520 gd->start = revoke_device_state_start; 521 gd->end = revoke_device_state_end; 522 523 slist1 = NULL; 524 slist1 = curl_slist_append(slist1, "Content-Type: application/x-www-form-urlencoded"); 525 526 curl = curl_easy_init(); 527 528 len = sizeof("token=") + strlen(credential->access_token); 529 postdata = malloc(len); 530 snprintf(postdata, len, "token=%s", credential->access_token); 531 532 curl_easy_setopt(curl, CURLOPT_URL, "https://accounts.google.com/o/oauth2/revoke"); 533 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata); 534 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)strnlen(postdata, len)); 535 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1); 536 curl_setopt_common(curl); 537 538 curl_easy_setopt(curl, CURLOPT_WRITEDATA, gd); 539 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); 540 541 ret = curl_easy_perform(curl); 542 543 free(postdata); 544 545 curl_easy_cleanup(curl); 546 curl = NULL; 547 curl_slist_free_all(slist1); 548 slist1 = NULL; 549 550 return (int)ret; 551 } 552 553 void upload_file_state_start(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 554 { 555 switch (gd->state) { 556 case psRoot: 557 if (state->level != 2) { 558 break; 559 } 560 else if (strcmp(buf, "kind") == 0) { 561 gd->state = psKind; 562 } 563 else if (strcmp(buf, "id") == 0) { 564 gd->state = psId; 565 } 566 else if (strcmp(buf, "name") == 0) { 567 gd->state = psName; 568 } 569 else if (strcmp(buf, "mimeType") == 0) { 570 gd->state = psMimeType; 571 } 572 else if (strcmp(buf, "error") == 0) { 573 gd->state = psError; 574 } 575 else if (strcmp(buf, "error_description") == 0) { 576 gd->state = psErrorDescription; 577 } 578 break; 579 case psKind: 580 if (state->type == JSONSL_T_STRING) { 581 strlcpy(gd->file.kind, buf, sizeof(gd->file.kind)); 582 gd->state = psRoot; 583 } 584 break; 585 case psId: 586 if (state->type == JSONSL_T_STRING) { 587 strlcpy(gd->file.id, buf, sizeof(gd->file.id)); 588 gd->state = psRoot; 589 } 590 break; 591 case psName: 592 if (state->type == JSONSL_T_STRING) { 593 strlcpy(gd->file.name, buf, sizeof(gd->file.name)); 594 gd->state = psRoot; 595 } 596 break; 597 case psMimeType: 598 if (state->type == JSONSL_T_STRING) { 599 strlcpy(gd->file.mimeType, buf, sizeof(gd->file.mimeType)); 600 gd->state = psRoot; 601 } 602 break; 603 case psError: 604 if (state->type == JSONSL_T_STRING) { 605 strlcpy(gd->error.error, buf, sizeof(gd->error.error)); 606 gd->state = psRoot; 607 } 608 break; 609 case psErrorDescription: 610 if (state->type == JSONSL_T_STRING) { 611 strlcpy(gd->error.error_description, buf, sizeof(gd->error.error_description)); 612 gd->state = psRoot; 613 } 614 break; 615 } 616 } 617 618 void upload_file_state_end(google_drive_t *gd, struct jsonsl_state_st *state, const char *buf) 619 { 620 } 621 622 size_t read_callback(char *buffer, size_t size, size_t nitems, void *arg) 623 { 624 FIL *file = (FIL *)arg; 625 UINT ret = 0; 626 FRESULT res; 627 628 res = f_read(file, buffer, size * nitems, &ret); 629 if (res != FR_OK) 630 return 0; 631 632 int rest = ret; 66 633 int len; 67 634 … … 76 643 response[len] = '\0'; 77 644 78 ntstdio_printf(&ntstdio,response);79 80 dly_tsk(100 * 1000);645 printf(response); 646 647 dly_tsk(100); 81 648 82 649 rest -= len; … … 84 651 } 85 652 86 return size * nmemb;87 }88 89 size_t read_data(char *buffer, size_t size, size_t nitems, void *instream)90 {91 FIL *file = (FIL *)instream;92 UINT ret = 0;93 FRESULT res;94 95 res = f_read(file, buffer, size * nitems, &ret);96 if (res != FR_OK)97 return 0;98 99 int rest = ret;100 int len;101 102 while (rest > 0) {103 len = rest;104 if (len > (sizeof(response) - 1)) {105 len = sizeof(response) - 1;106 }107 108 memcpy(response, buffer, len);109 110 response[len] = '\0';111 112 ntstdio_printf(&ntstdio, response);113 114 dly_tsk(100);115 116 rest -= len;117 buffer = (char *)buffer + len;118 }119 120 653 return ret; 121 654 } 122 655 123 char errbuf[CURL_ERROR_SIZE]; 656 int seek_callback(void *arg, curl_off_t offset, int origin) 657 { 658 FIL *file = (FIL *)arg; 659 BYTE mode; 660 FRESULT ret; 661 662 switch (origin) { 663 case SEEK_SET: 664 mode = F_SEEK_SET; 665 break; 666 case SEEK_CUR: 667 mode = F_SEEK_CUR; 668 break; 669 case SEEK_END: 670 mode = F_SEEK_END; 671 break; 672 default: 673 return CURL_SEEKFUNC_FAIL; 674 } 675 676 ret = f_seek(file, offset, mode); 677 if (ret != F_OK) 678 return CURL_SEEKFUNC_FAIL; 679 680 return CURL_SEEKFUNC_OK; 681 } 682 683 int upload_file(google_drive_t *gd, const char *filename, const char *localfilepath) 684 { 685 CURLcode ret; 686 CURL *curl; 687 curl_mime *mime; 688 curl_mimepart *part; 689 struct curl_slist *slist1; 690 size_t len; 691 char *postdata, *authorization; 692 static const char buf[] = "Expect:"; 693 jsonsl_t jsn = gd->jsn; 694 FIL file; 695 FRESULT fret; 696 697 gd->jsn_buf_pos = -1; 698 699 jsonsl_reset(jsn); 700 gd->start = upload_file_state_start; 701 gd->end = upload_file_state_end; 702 703 fret = f_open(&file, localfilepath, FA_READ); 704 if (fret != FR_OK) { 705 printf("log file open error %d\n", fret); 706 return -1; 707 } 708 709 len = sizeof("{\"name\":\"\"}") + strlen(filename); 710 postdata = malloc(len); 711 snprintf(postdata, len, "{\"name\":\"%s\"}", filename); 712 713 curl = curl_easy_init(); 714 715 mime = curl_mime_init(curl); 716 part = curl_mime_addpart(mime); 717 curl_mime_name(part, "metadata"); 718 curl_mime_type(part, "application/json;charset=utf-8"); 719 curl_mime_data(part, postdata, CURL_ZERO_TERMINATED); 720 free(postdata); 721 722 part = curl_mime_addpart(mime); 723 curl_mime_name(part, "file"); 724 curl_mime_type(part, "application/json"); 725 curl_mime_data_cb(part, file.fsize, read_callback, seek_callback, NULL, &file); 726 727 len = sizeof("Authorization: Bearer ") + strnlen(gd->credential.access_token, sizeof(gd->credential.access_token)); 728 authorization = malloc(len); 729 snprintf(authorization, len, "Authorization: Bearer %s", gd->credential.access_token); 730 slist1 = NULL; 731 slist1 = curl_slist_append(slist1, authorization); 732 free(authorization); 733 734 slist1 = curl_slist_append(slist1, buf); 735 736 curl_easy_setopt(curl, CURLOPT_URL, "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"); 737 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 738 curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); 739 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1); 740 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); 741 curl_setopt_common(curl); 742 743 curl_easy_setopt(curl, CURLOPT_WRITEDATA, gd); 744 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); 745 746 ret = curl_easy_perform(curl); 747 748 curl_easy_cleanup(curl); 749 curl = NULL; 750 curl_mime_free(mime); 751 mime = NULL; 752 curl_slist_free_all(slist1); 753 slist1 = NULL; 754 755 f_close(&file); 756 757 return (int)ret; 758 } 759 760 int google_drive_error_callback(jsonsl_t jsn, jsonsl_error_t err, 761 struct jsonsl_state_st *state, char *errat) 762 { 763 return 0; 764 } 765 766 void google_drive_state_callback(jsonsl_t jsn, jsonsl_action_t action, 767 struct jsonsl_state_st *state, const char *buf) 768 { 769 google_drive_t *gd = (google_drive_t *)jsn->data; 770 771 switch (action) { 772 case JSONSL_ACTION_PUSH: 773 switch (state->type) { 774 case JSONSL_T_SPECIAL: 775 gd->jsn_buf[0] = *buf; 776 gd->jsn_buf_pos = 1; 777 break; 778 case JSONSL_T_STRING: 779 case JSONSL_T_HKEY: 780 gd->jsn_buf_pos = 0; 781 break; 782 default: 783 gd->jsn_buf_pos = -1; 784 } 785 break; 786 case JSONSL_ACTION_POP: 787 switch (state->type) { 788 case JSONSL_T_SPECIAL: 789 case JSONSL_T_STRING: 790 case JSONSL_T_HKEY: 791 gd->jsn_buf_pos--; 792 if (gd->jsn_buf_pos < sizeof(gd->jsn_buf)) { 793 gd->jsn_buf[gd->jsn_buf_pos] = '\0'; 794 } 795 gd->start(gd, state, gd->jsn_buf); 796 break; 797 default: 798 gd->jsn_buf[0] = '\0'; 799 break; 800 } 801 gd->jsn_buf_pos = -1; 802 break; 803 default: 804 gd->jsn_buf_pos = -1; 805 break; 806 } 807 } 124 808 125 809 static void get_logfname(char *fname) … … 185 869 ret = f_open(&file, fname, FA_CREATE_ALWAYS | FA_WRITE); 186 870 if (ret != FR_OK) { 187 ntstdio_printf(&ntstdio,"not open a upload file %d\n", ret);871 printf("not open a upload file %d\n", ret); 188 872 return ret; 189 873 } … … 232 916 f_putc('}', &file); 233 917 234 file_close:235 918 f_close(&file); 236 919 … … 238 921 } 239 922 240 void client_task(intptr_t exinf) 241 { 242 CURL *curl; 923 void curl_setopt_common(CURL *curl) 924 { 243 925 CURLcode res; 244 int error = 0;245 //const char *data = "{\"value\":\"data post\"}";246 struct curl_slist *list = NULL;247 FIL file;248 FRESULT ret;249 char fname[] = {"1:/log/20160101000000.log"};250 251 get_logfname(fname);252 253 ret = write_log(fname);254 if (ret != FR_OK) {255 ntstdio_printf(&ntstdio, "log file write error %d\n", ret);256 return;257 }258 259 ret = f_open(&file, fname, FA_READ);260 if (ret != FR_OK) {261 ntstdio_printf(&ntstdio, "log file open error %d\n", ret);262 return;263 }264 265 ntstdio_printf(&ntstdio, "cURL start\n");266 267 curl = curl_easy_init();268 if (curl == NULL) {269 ntstdio_printf(&ntstdio, "curl_easy_init() failed\n");270 goto file_close;271 }272 926 273 927 /* ask libcurl to show us the verbose output */ 274 curl_easy_setopt(curl, CURLOPT_VERBOSE, true); 275 276 res = curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/"); 928 res = curl_easy_setopt(curl, CURLOPT_VERBOSE, true); 277 929 if (res != CURLE_OK) 278 ntstdio_printf(&ntstdio, "CURLOPT_URLfailed: %s\n",930 printf("CURLOPT_VERBOSE failed: %s\n", 279 931 curl_easy_strerror(res)); 280 932 … … 283 935 284 936 /* provide a buffer to store errors in */ 285 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); 937 res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); 938 if (res != CURLE_OK) 939 printf("CURLOPT_ERRORBUFFER failed: %s\n", 940 curl_easy_strerror(res)); 286 941 287 942 #ifdef SKIP_PEER_VERIFICATION … … 298 953 res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); 299 954 if (res != CURLE_OK) 300 ntstdio_printf(&ntstdio,"CURLOPT_SSL_VERIFYPEER failed: %s\n",955 printf("CURLOPT_SSL_VERIFYPEER failed: %s\n", 301 956 curl_easy_strerror(res)); 302 957 #else 303 958 res = curl_easy_setopt(curl, CURLOPT_CAINFO, "0:/certs/ca-cert.pem"); 304 959 if (res != CURLE_OK) 305 ntstdio_printf(&ntstdio,"CURLOPT_CAINFO failed: %s\n",960 printf("CURLOPT_CAINFO failed: %s\n", 306 961 curl_easy_strerror(res)); 307 962 308 963 res = curl_easy_setopt(curl, CURLOPT_SSLCERT, "0:/certs/client-cert.pem"); 309 964 if (res != CURLE_OK) 310 ntstdio_printf(&ntstdio,"CURLOPT_SSLCERT failed: %s\n",965 printf("CURLOPT_SSLCERT failed: %s\n", 311 966 curl_easy_strerror(res)); 312 967 313 968 res = curl_easy_setopt(curl, CURLOPT_SSLKEY, "0:/certs/client-key.pem"); 314 969 if (res != CURLE_OK) 315 ntstdio_printf(&ntstdio,"CURLOPT_SSLKEY failed: %s\n",970 printf("CURLOPT_SSLKEY failed: %s\n", 316 971 curl_easy_strerror(res)); 317 972 #endif … … 326 981 res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); 327 982 if (res != CURLE_OK) 328 ntstdio_printf(&ntstdio,"CURLOPT_SSL_VERIFYHOST failed: %s\n",983 printf("CURLOPT_SSL_VERIFYHOST failed: %s\n", 329 984 curl_easy_strerror(res)); 330 985 #endif … … 332 987 /*res = curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy.example.com:8080"); 333 988 if (res != CURLE_OK) 334 ntstdio_printf(&ntstdio,"CURLOPT_PROXY failed: %s\n",989 printf("CURLOPT_PROXY failed: %s\n", 335 990 curl_easy_strerror(res));*/ 336 991 337 curl_easy_setopt(curl, CURLOPT_POST, 1); 338 339 /* size of the POST data */ 340 //curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(data)); 341 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, file.fsize); 342 343 /* pass in a pointer to the data - libcurl will not copy */ 344 //curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); 345 346 list = curl_slist_append(list, "Content-Type: application/json"); 347 348 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); 349 350 curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&error); 351 352 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); 353 354 /* now specify which file to upload */ 355 curl_easy_setopt(curl, CURLOPT_READDATA, &file); 356 357 /* we want to use our own read function */ 358 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data); 359 360 ntstdio_printf(&ntstdio, "cURL perform the request\n"); 361 tslp_tsk(100 * 1000); 362 363 /* Perform the request, res will get the return code */ 364 res = curl_easy_perform(curl); 365 /* Check for errors */ 366 if (res != CURLE_OK) { 367 ntstdio_printf(&ntstdio, "curl_easy_perform() failed: %s\n", 992 res = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); 993 if (res != CURLE_OK) 994 printf("CURLOPT_NOPROGRESS failed: %s\n", 368 995 curl_easy_strerror(res)); 369 ntstdio_printf(&ntstdio, errbuf); 370 } 371 372 /* always cleanup */ 373 curl_easy_cleanup(curl); 374 375 ntstdio_printf(&ntstdio, "cURL end\n"); 376 377 file_close: 378 f_close(&file); 379 } 380 381 void client_fin(void) 382 { 996 997 res = curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); 998 if (res != CURLE_OK) 999 printf("CURLOPT_MAXREDIRS failed: %s\n", 1000 curl_easy_strerror(res)); 1001 1002 res = curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); 1003 if (res != CURLE_OK) 1004 printf("CURLOPT_TCP_KEEPALIVE failed: %s\n", 1005 curl_easy_strerror(res)); 1006 } 1007 1008 void client_set_client_id(const char *client_id) 1009 { 1010 google_drive_t *gd = &google_drive; 1011 1012 strlcpy(gd->client_info.client_id, client_id, sizeof(gd->client_info.client_id)); 1013 } 1014 1015 void client_set_client_secret(const char *client_secret) 1016 { 1017 google_drive_t *gd = &google_drive; 1018 1019 strlcpy(gd->client_info.client_secret, client_secret, sizeof(gd->client_info.client_secret)); 1020 } 1021 1022 int client_get_device_id(int argc, char **argv) 1023 { 1024 google_drive_t *gd = &google_drive; 1025 int ret; 1026 1027 ret = get_device_id(gd, SCOPE_DRIVE_FILE); 1028 if (ret == 0) { 1029 printf("Device was registered. Enter the code at the following URL\n"); 1030 printf("url: %s\n", gd->credential.verification_url); 1031 printf("code: %s\n", gd->credential.user_code); 1032 } 1033 else { 1034 printf("Device register failed! %d\n", ret); 1035 } 1036 1037 return ret; 1038 } 1039 1040 int client_get_access_token(int argc, char **argv) 1041 { 1042 google_drive_t *gd = &google_drive; 1043 int ret; 1044 1045 ret = get_access_token(gd); 1046 if (ret == 0) { 1047 printf("Access token was give\n"); 1048 printf("Refresh token: %s\n", gd->credential.refresh_token); 1049 printf("Access token: %s\n", gd->credential.access_token); 1050 } 1051 else { 1052 printf("Access token gain failed. %d\n", ret); 1053 } 1054 1055 return ret; 1056 } 1057 1058 int client_update_access_token(int argc, char **argv) 1059 { 1060 google_drive_t *gd = &google_drive; 1061 int ret; 1062 1063 ret = update_access_token(gd); 1064 if (ret == 0) { 1065 printf("Access token was update\n"); 1066 printf("Access token: %s\n", gd->credential.access_token); 1067 } 1068 else { 1069 printf("Access token update failed. %d\n", ret); 1070 } 1071 1072 return ret; 1073 } 1074 1075 int client_revoke(int argc, char **argv) 1076 { 1077 google_drive_t *gd = &google_drive; 1078 int ret; 1079 1080 ret = revoke_device(gd); 1081 if (ret == 0) { 1082 printf("Device was revoked.\n"); 1083 } 1084 else { 1085 printf("Device revoke failed. %d\n", ret); 1086 } 1087 1088 return ret; 1089 } 1090 1091 int client_upload_file(int argc, char **argv) 1092 { 1093 google_drive_t *gd = &google_drive; 1094 int ret; 1095 FRESULT fret; 1096 char fname[] = { "1:/log/20160101000000.log" }; 1097 1098 get_logfname(fname); 1099 1100 fret = write_log(fname); 1101 if (fret != FR_OK) { 1102 printf("log file write error %d\n", fret); 1103 return (int)fret; 1104 } 1105 1106 ret = upload_file(gd, &fname[7], fname); 1107 if (ret == 0) { 1108 printf("%s was uploaded.\n", &fname[7]); 1109 } 1110 else { 1111 printf("%s upload failed. %d\n", &fname[7], ret); 1112 } 1113 1114 return ret; 1115 } 1116 1117 void client_final(void) 1118 { 1119 google_drive_t *gd = &google_drive; 1120 jsonsl_t jsn = gd->jsn; 1121 383 1122 curl_global_cleanup(); 384 } 1123 jsonsl_destroy(jsn); 1124 } -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/src/client.h
r337 r364 39 39 #define _CLIENT_H_ 40 40 41 #include <kernel.h> 42 #include "target_kernel_impl.h" 41 typedef struct client_info_t { 42 char client_id[80]; 43 char client_secret[32]; 44 } client_info_t; 43 45 44 #define CLIENT_PRIORITY 4 /* クライアントタスクの優先度 */ 46 typedef struct credential_t { 47 char device_code[100]; 48 char user_code[12]; 49 int expires_in; 50 int interval; 51 char verification_url[32]; 52 char access_token[132]; 53 char refresh_token[64]; 54 char scope[64]; 55 char token_type[16]; 56 } credential_t; 45 57 46 #define CLIENT_STACK_SIZE 6144 /* スタック領域のサイズ */ 58 typedef struct error_response_t { 59 char error[64]; 60 char error_description[64]; 61 } error_response_t; 47 62 48 extern void client_init(void); 49 extern void client_task(intptr_t exinf); 50 extern void client_fin(void); 63 typedef struct drive_file_t { 64 char kind[32]; 65 char id[36]; 66 char name[256]; 67 char mimeType[40]; 68 } drive_file_t; 69 70 typedef enum google_drive_parse_state_t { 71 psRoot, 72 psDeviceCode, 73 psUserCode, 74 psExpiresIn, 75 psInterval, 76 psVerificationUrl, 77 psAccessToken, 78 psRefreshToken, 79 psScope, 80 psTokenType, 81 psKind, 82 psId, 83 psName, 84 psMimeType, 85 psError, 86 psErrorDescription, 87 } google_drive_parse_state_t; 88 89 struct jsonsl_st; 90 typedef struct jsonsl_st *jsonsl_t; 91 92 typedef void (*parser_callback_t)(struct google_drive_t *gd, struct jsonsl_state_st *state, const char *buf); 93 94 typedef struct google_drive_t { 95 client_info_t client_info; 96 credential_t credential; 97 drive_file_t file; 98 error_response_t error; 99 jsonsl_t jsn; 100 google_drive_parse_state_t state; 101 char fname[sizeof("1:/log/20160101000000.log")]; 102 char jsn_buf[256]; 103 int jsn_buf_pos; 104 parser_callback_t start; 105 parser_callback_t end; 106 } google_drive_t; 107 108 extern google_drive_t google_drive; 109 110 void client_init(void); 111 void client_final(void); 112 113 void client_set_client_id(const char *client_id); 114 void client_set_client_secret(const char *client_secret); 115 int client_get_device_id(int argc, char **argv); 116 int client_get_access_token(int argc, char **argv); 117 int client_update_access_token(int argc, char **argv); 118 int client_revoke(int argc, char **argv); 119 int client_upload_file(int argc, char **argv); 51 120 52 121 #endif /* _CLIENT_H_ */ -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/src/echonet_main.c
r351 r364 1 1 /* 2 2 * TOPPERS ECHONET Lite Communication Middleware 3 * 3 * 4 4 * Copyright (C) 2016-2018 Cores Co., Ltd. Japan 5 * 5 * 6 6 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ 7 7 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 … … 26 26 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを 27 27 * 免責すること. 28 * 28 * 29 29 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お 30 30 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 … … 32 32 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ 33 33 * の責任を負わない. 34 * 34 * 35 35 * @(#) $Id$ 36 36 */ 37 37 38 /* 38 /* 39 39 * サンプルプログラム(1)の本体 40 40 */ … … 152 152 { 153 153 /* サイズが1以外は受け付けない */ 154 if (size != 1)154 if (size != 1) 155 155 return 0; 156 156 157 157 *anno = *((uint8_t*)item->exinf) != *((uint8_t*)src); 158 158 159 switch (*(uint8_t *)src){159 switch (*(uint8_t *)src) { 160 160 /* ONの場合 */ 161 161 case 0x30: … … 184 184 { 185 185 /* サイズが1以外は受け付けない */ 186 if (size != 1)186 if (size != 1) 187 187 return 0; 188 188 189 189 *anno = *((uint8_t *)item->exinf) != *((uint8_t *)src); 190 190 191 switch (*(uint8_t *)src){191 switch (*(uint8_t *)src) { 192 192 /* 異常発生ありの場合 */ 193 193 case 0x41: … … 288 288 289 289 /* サイズが4以外は受け付けない */ 290 if (size != 4)290 if (size != 4) 291 291 return 0; 292 292 … … 308 308 309 309 len = 48 - meter->current_pos; 310 if (len > 0)310 if (len > 0) 311 311 memcpy(dst, &meter->integral_electric_energy_measurement_log[meter->current_pos], sizeof(uint32_t) * len); 312 312 dst = &((uint8_t *)dst)[len]; … … 367 367 368 368 ret2 = get_tim(&now); 369 if (ret2 != E_OK) {369 if (ret2 != E_OK) { 370 370 syslog(LOG_ERROR, "get_tim"); 371 371 return; 372 372 } 373 373 374 for (;;){374 for (;;) { 375 375 prev = now; 376 376 … … 380 380 /* 応答電文待ち */ 381 381 ret = ecn_trcv_esv(&esv, timer); 382 if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)) {382 if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)) { 383 383 syslog(LOG_ERROR, "ecn_trcv_esv"); 384 384 break; … … 386 386 387 387 ret2 = get_tim(&now); 388 if (ret2 != E_OK) {388 if (ret2 != E_OK) { 389 389 syslog(LOG_ERROR, "get_tim"); 390 390 break; … … 401 401 /* 領域解放 */ 402 402 ret = ecn_rel_esv(esv); 403 if (ret != E_OK) {403 if (ret != E_OK) { 404 404 syslog(LOG_ERROR, "ecn_rel_esv"); 405 405 break; … … 410 410 /* 応答電文待ちの割り込みデータ取得 */ 411 411 ret = ecn_get_brk_dat(esv, brkdat, sizeof(brkdat), &len); 412 if (ret != E_OK) {412 if (ret != E_OK) { 413 413 syslog(LOG_ERROR, "ecn_get_brk_dat"); 414 414 break; … … 420 420 /* 領域解放 */ 421 421 ret = ecn_rel_esv(esv); 422 if (ret != E_OK) {422 if (ret != E_OK) { 423 423 syslog(LOG_ERROR, "ecn_rel_esv"); 424 424 break; … … 431 431 } 432 432 433 bool_t started = false;434 435 433 void echonet_change_netif_link(uint8_t link_up, uint8_t up) 436 434 { … … 440 438 return; 441 439 442 if (up && !started) { 443 started = true; 444 445 /* ECHONETミドルウェアを起動 */ 446 ret = ecn_sta_svc(); 447 if (ret != E_OK) 448 return; 449 450 /* ECHONETミドルウェアを起動するのを待つ */ 451 dly_tsk(100); 440 if (up) { 441 /* インスタンスリスト通知の送信 */ 442 ret = ecn_ntf_inl(); 443 if (ret != E_OK) { 444 syslog(LOG_ERROR, "ecn_ntf_inl"); 445 } 452 446 } 453 447 … … 463 457 } 464 458 465 enum main_state_t{ 459 enum main_state_t { 460 main_state_start, 466 461 main_state_idle, 467 462 }; 468 463 469 464 int main_timer = TMO_FEVR; 470 enum main_state_t main_state = main_state_ idle;471 int main_l ed_timer = TMO_FEVR;465 enum main_state_t main_state = main_state_start; 466 int main_lcd_timer = TMO_FEVR; 472 467 int main_adv_timer = TMO_FEVR; 473 468 int main_whm_counter; … … 508 503 509 504 /* 3ms後に7SEG表示を更新 */ 510 main_led_timer = 3 * 1000; 511 512 /* 10ms後にボタン状態を確認 */ 513 main_timer = 10 * 1000; 505 main_lcd_timer = 3 * 1000; 506 507 /* ECHONETミドルウェアを起動するのを待つ */ 508 main_state = main_state_start; 509 main_timer = 1000 * 1000; 514 510 515 511 /* 12bitADC初期化 */ … … 526 522 main_adv_timer = 1000 * 1000; 527 523 524 /* メインタスクを起動 */ 528 525 ER ret = act_tsk(MAIN_TASK); 529 526 if (ret != E_OK) { … … 539 536 int result = main_timer; 540 537 541 if ((result == TMO_FEVR)542 || ((main_l ed_timer != TMO_FEVR) && (main_led_timer < result))){543 result = main_l ed_timer;538 if ((result == TMO_FEVR) 539 || ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))) { 540 result = main_lcd_timer; 544 541 } 545 542 … … 557 554 static void main_progress(int interval) 558 555 { 559 if (main_timer != TMO_FEVR){556 if (main_timer != TMO_FEVR) { 560 557 main_timer -= interval; 561 if (main_timer < 0){558 if (main_timer < 0) { 562 559 main_timer = 0; 563 560 } 564 561 } 565 562 566 if (main_led_timer != TMO_FEVR){567 main_l ed_timer -= interval;568 if (main_led_timer < 0){569 main_l ed_timer = 0;563 if (main_lcd_timer != TMO_FEVR) { 564 main_lcd_timer -= interval; 565 if (main_lcd_timer < 0) { 566 main_lcd_timer = 0; 570 567 } 571 568 } … … 591 588 592 589 ret = ecn_itr_ini(&enm, esv); 593 if (ret != E_OK){590 if (ret != E_OK) { 594 591 syslog(LOG_ERROR, "ecn_itr_ini"); 595 592 return; 596 593 } 597 594 598 for (;;) {599 while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {595 for (;;) { 596 while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) { 600 597 switch (epc) { 601 598 case 0x80: … … 605 602 } 606 603 } 607 if (ret != E_BOVR){604 if (ret != E_BOVR) { 608 605 syslog(LOG_ERROR, "ecn_itr_nxt"); 609 606 break; 610 607 } 611 if (enm.is_eof)608 if (enm.is_eof) 612 609 break; 613 610 } … … 619 616 static void main_break_wait(uint8_t *brkdat, int32_t len) 620 617 { 621 switch (main_state){618 switch (main_state) { 622 619 case main_state_idle: 623 620 if (len == 0) … … 638 635 639 636 static void main_ontimer(); 640 static void main_l ed_ontimer();637 static void main_lcd_ontimer(); 641 638 static void main_adv_ontimer(); 642 639 … … 646 643 static void main_timeout() 647 644 { 648 if (main_timer == 0){645 if (main_timer == 0) { 649 646 main_ontimer(); 650 647 } 651 648 652 if (main_led_timer == 0){653 main_l ed_ontimer();649 if (main_lcd_timer == 0) { 650 main_lcd_ontimer(); 654 651 } 655 652 … … 664 661 const uint8_t led_disp[] = { 0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE4, 0xFE, 0xF6, 0xEE, 0x3E, 0x1A, 0x7A, 0x9E, 0x8E }; 665 662 666 static void main_l ed_ontimer()663 static void main_lcd_ontimer() 667 664 { 668 665 /* 7Seg表示 */ … … 697 694 698 695 /* 3ms後に7SEG表示を更新 */ 699 main_l ed_timer = 3 * 1000;696 main_lcd_timer = 3 * 1000; 700 697 } 701 698 … … 727 724 static void main_ontimer() 728 725 { 726 ER ret; 729 727 uint8_t btn; 730 728 uint16_t ad_value; 731 729 732 switch(main_state){ 730 switch (main_state) { 731 case main_state_start: 732 /* ECHONETミドルウェアを起動 */ 733 ret = ecn_sta_svc(); 734 if (ret != E_OK) { 735 syslog(LOG_ERROR, "ecn_sta_svc"); 736 } 737 738 /* 10ms後にボタン状態を確認 */ 739 main_state = main_state_idle; 740 main_timer = 10 * 1000; 741 break; 733 742 case main_state_idle: 734 743 /* 10ms後にボタン状態を確認 */ … … 736 745 737 746 /* ADCの変換結果取得 */ 738 if ((sil_reb_mem((uint8_t *)S12AD_ADCSR_ADDR) & S12AD_ADCSR_ADST_BIT) == 0){747 if ((sil_reb_mem((uint8_t *)S12AD_ADCSR_ADDR) & S12AD_ADCSR_ADST_BIT) == 0) { 739 748 for (int i = 0; i < main_ad_count; i++) { 740 749 main_ad_avelage[i] -= main_ad_table[i][main_ad_pos]; … … 776 785 777 786 /* ボタン1の処理 */ 778 if (((btn & 0x20) != 0) && !main_btn1_state){787 if (((btn & 0x20) != 0) && !main_btn1_state) { 779 788 main_btn1_count++; 780 if (main_btn1_count > 10){789 if (main_btn1_count > 10) { 781 790 main_btn1_count = 0; 782 791 main_btn1_state = true; … … 785 794 } 786 795 } 787 else if (((btn & 0x20) == 0) && main_btn1_state){796 else if (((btn & 0x20) == 0) && main_btn1_state) { 788 797 main_btn1_count++; 789 if (main_btn1_count > 10){798 if (main_btn1_count > 10) { 790 799 main_btn1_count = 0; 791 800 main_btn1_state = false; … … 796 805 797 806 /* ボタン2の処理 */ 798 if (((btn & 0x80) != 0) && !main_btn2_state){807 if (((btn & 0x80) != 0) && !main_btn2_state) { 799 808 main_btn2_count++; 800 if (main_btn2_count > 10){809 if (main_btn2_count > 10) { 801 810 main_btn2_count = 0; 802 811 main_btn2_state = true; … … 805 814 } 806 815 } 807 else if (((btn & 0x80) == 0) && main_btn2_state){816 else if (((btn & 0x80) == 0) && main_btn2_state) { 808 817 main_btn2_count++; 809 if (main_btn2_count > 10){818 if (main_btn2_count > 10) { 810 819 main_btn2_count = 0; 811 820 main_btn2_state = false; … … 829 838 { 830 839 /* 押されて戻った時に処理する */ 831 if (push)840 if (push) 832 841 return; 833 842 834 843 /* 表示ポート番号 */ 835 if (!main_rev){844 if (!main_rev) { 836 845 main_port_no--; 837 if (main_port_no < 1){846 if (main_port_no < 1) { 838 847 main_port_no = 1; 839 848 main_rev = true; … … 841 850 } 842 851 } 843 else {852 else { 844 853 main_port_no++; 845 if (main_port_no > main_ad_count){854 if (main_port_no > main_ad_count) { 846 855 main_port_no = main_ad_count; 847 856 main_rev = false; … … 857 866 { 858 867 /* 押されて戻った時に処理する */ 859 if (push)868 if (push) 860 869 return; 861 870 … … 866 875 867 876 /* 表示ポート番号 */ 868 if (!main_rev){877 if (!main_rev) { 869 878 main_port_no++; 870 if (main_port_no > main_ad_count){879 if (main_port_no > main_ad_count) { 871 880 main_port_no = main_ad_count; 872 881 main_rev = false; … … 874 883 } 875 884 } 876 else {885 else { 877 886 main_port_no--; 878 if (main_port_no < 1){887 if (main_port_no < 1) { 879 888 main_port_no = 1; 880 889 main_rev = true; … … 893 902 894 903 main_port_no++; 895 if (main_port_no > main_ad_count)904 if (main_port_no > main_ad_count) 896 905 main_port_no = 1; 897 906 -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/src/main.c
r359 r364 45 45 #include <sil.h> 46 46 #include <setjmp.h> 47 #include <stdlib.h> 47 48 #include <string.h> 48 49 #include "syssvc/serial.h" … … 80 81 81 82 ID ws_api_mailboxid = MAIN_DATAQUEUE; 83 #ifndef NOUSE_MPF_NET_BUF 82 84 ID ws_mempoolid = MPF_NET_BUF_256; 83 85 #endif 84 86 #ifdef IF_ETHER_BTUSB 85 87 extern int bt_bnep_mode; 86 88 /* PANU向けリモートアドレス */ 87 89 bd_addr_t remote_addr = {0x00,0x1B,0xDC,0x09,0x27,0x26}; 90 bool_t dhcp_enable = false; 91 #else 92 bool_t dhcp_enable = true; 88 93 #endif 89 94 90 95 uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0x01}; 91 bool_t dhcp_enable = true;92 96 PRI main_task_priority = MAIN_PRIORITY + 1; 93 97 … … 112 116 static void main_timeout(); 113 117 118 extern int ntshell_exit; 119 114 120 int uart_read(char *buf, int cnt, void *extobj) 115 121 { 116 return serial_rea_dat(SIO_PORTID, (char *)buf, cnt); 122 struct main_t *obj = (struct main_t *)extobj; 123 int result; 124 ER ret; 125 int timer; 126 127 obj->prev = obj->now; 128 129 /* タイマー取得 */ 130 timer = main_get_timer(); 131 132 /* 待ち */ 133 ret = serial_trea_dat(SIO_PORTID, buf, cnt, timer); 134 if ((ret < 0) && (ret != E_OK) && (ret != E_TMOUT)) { 135 syslog(LOG_NOTICE, "tslp_tsk ret: %s %d", itron_strerror(ret), timer); 136 ntshell_exit = 1; 137 return -1; 138 } 139 result = (int)ret; 140 141 ret = get_tim(&obj->now); 142 if (ret != E_OK) { 143 syslog(LOG_NOTICE, "get_tim ret: %s", itron_strerror(ret)); 144 ntshell_exit = 1; 145 return -1; 146 } 147 148 /* 時間経過 */ 149 int elapse = obj->now - obj->prev; 150 main_progress(elapse); 151 152 /* タイムアウト処理 */ 153 main_timeout(); 154 155 return result; 117 156 } 118 157 … … 120 159 { 121 160 return serial_wri_dat(SIO_PORTID, buf, cnt); 122 }123 124 unsigned char ntstdio_xi(struct ntstdio_t *handle)125 {126 char buf[1];127 if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)128 return -EIO;129 return buf[0];130 }131 132 void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)133 {134 char buf[1];135 buf[0] = c;136 serial_wri_dat(SIO_PORTID, buf, 1);137 161 } 138 162 … … 151 175 main_initialize(); 152 176 153 ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);177 ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, &main_obj); 154 178 ntshell_set_prompt(&ntshell, "NTShell>"); 155 179 ntshell_execute(&ntshell); … … 171 195 ER ret; 172 196 197 #ifdef TOPPERS_OMIT_TECS 198 serial_opn_por(SIO_PORTID); 199 #endif 200 serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV); 201 173 202 //wolfSSL_Debugging_ON(); 174 203 175 ntshell_task_init( );204 ntshell_task_init(uart_read, uart_write, &main_obj); 176 205 177 206 main_obj.timer = TMO_FEVR; … … 308 337 } 309 338 339 int cmd_creid(int argc, char **argv) 340 { 341 if (argc != 2) { 342 printf("creid {client_id}\n"); 343 return 0; 344 } 345 346 client_set_client_id(argv[1]); 347 348 return 0; 349 } 350 351 int cmd_secret(int argc, char **argv) 352 { 353 if (argc != 2) { 354 printf("secret {client_secret}\n"); 355 return 0; 356 } 357 358 client_set_client_secret(argv[1]); 359 360 return 0; 361 } 362 310 363 int cmd_logupload(int argc, char **argv) 311 364 { 312 client_task(0); 313 return 0; 365 return client_upload_file(argc, argv); 314 366 } 315 367 … … 330 382 {"dnsc", "DNS client", usrcmd_dnsc }, 331 383 {"ntpc", "NTP client", usrcmd_ntpc }, 384 {"creid", "Regster device", cmd_creid}, 385 {"secret", "Regster device", cmd_secret}, 386 {"gdi", "get_device_id", client_get_device_id}, 387 {"gat", "get_access_token", client_get_access_token}, 388 {"uat", "update_access_token", client_update_access_token}, 389 {"rd", "revoke device", client_revoke}, 390 {"uf", "upload_file", client_upload_file}, 332 391 {"logupload", "Upload log to server", cmd_logupload}, 333 392 {"info", "This is a description text string for info command.", usrcmd_info}, -
asp3_tinet_ecnl_rx/trunk/app1_usb_watt_meter/src/main.cfg
r342 r364 54 54 INCLUDE("tinet/tinet_asp.cfg"); 55 55 INCLUDE("tinet_main.cfg"); 56 INCLUDE("netinet/ip_igmp.cfg");57 56 58 57 /* DHCP クライアント */ … … 77 76 INCLUDE("ffarch.cfg"); 78 77 78 /* mbed */ 79 INCLUDE("mbed_api.cfg"); 80 79 81 #ifdef IF_ETHER_BTUSB 80 82 INCLUDE("usb_hbth.cfg");
Note:
See TracChangeset
for help on using the changeset viewer.