From 9c653728646d0963c953919f9cc2c9b3e950d644 Mon Sep 17 00:00:00 2001 From: zicog Date: Tue, 17 Sep 2013 14:54:21 +0300 Subject: [PATCH] Directory reorganization --- .gitignore | 13 +++ LICENSE.md | 19 ++++ MQTT.pas => TMQTTClient/MQTT.pas | 0 .../MQTTReadThread.pas | 3 - build_debian_amd64.sh | 10 -- examples/embeddedApp/README.md | 17 ++++ examples/embeddedApp/build.sh | 8 ++ examples/embeddedApp/build_debian_amd64.sh | 11 +++ .../embeddedApp/embeddedApp.pas | 91 ++++++++++++------- blcksock.pas => synapse/blcksock.pas | 0 jedi.inc => synapse/jedi.inc | 0 ssfpc.inc => synapse/ssfpc.inc | 0 synacode.pas => synapse/synacode.pas | 0 synafpc.pas => synapse/synafpc.pas | 0 synaip.pas => synapse/synaip.pas | 0 synautil.pas => synapse/synautil.pas | 0 synsock.pas => synapse/synsock.pas | 0 17 files changed, 128 insertions(+), 44 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE.md rename MQTT.pas => TMQTTClient/MQTT.pas (100%) rename MQTTReadThread.pas => TMQTTClient/MQTTReadThread.pas (95%) delete mode 100755 build_debian_amd64.sh create mode 100644 examples/embeddedApp/README.md create mode 100755 examples/embeddedApp/build.sh create mode 100755 examples/embeddedApp/build_debian_amd64.sh rename simple.pas => examples/embeddedApp/embeddedApp.pas (51%) rename blcksock.pas => synapse/blcksock.pas (100%) rename jedi.inc => synapse/jedi.inc (100%) rename ssfpc.inc => synapse/ssfpc.inc (100%) rename synacode.pas => synapse/synacode.pas (100%) rename synafpc.pas => synapse/synafpc.pas (100%) rename synaip.pas => synapse/synaip.pas (100%) rename synautil.pas => synapse/synautil.pas (100%) rename synsock.pas => synapse/synsock.pas (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a800cbf --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.dcu +*.~*~ +*.local +*.identcache +__history +*.drc +*.map +*.exe +*.dll +bin/* +*.o +*.ppu + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..6d7c3a7 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) 2009 Jamie Ingilby + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/MQTT.pas b/TMQTTClient/MQTT.pas similarity index 100% rename from MQTT.pas rename to TMQTTClient/MQTT.pas diff --git a/MQTTReadThread.pas b/TMQTTClient/MQTTReadThread.pas similarity index 95% rename from MQTTReadThread.pas rename to TMQTTClient/MQTTReadThread.pas index 514aa06..410e129 100644 --- a/MQTTReadThread.pas +++ b/TMQTTClient/MQTTReadThread.pas @@ -122,7 +122,6 @@ procedure TMQTTReadThread.Execute; { Check errors } if FPSocket^.LastError <> 0 then begin - writeln ('Error: 1:'); rxState := 3; end; remainingLength := (digit and 127) * multiplier; @@ -143,7 +142,6 @@ procedure TMQTTReadThread.Execute; { Check errors } if FPSocket^.LastError <> 0 then begin - writeln ('Error: 2:'); rxState := 3; end; Synchronize(@HandleData); @@ -155,7 +153,6 @@ procedure TMQTTReadThread.Execute; end; end; end; - writeln ('TERMINATED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); end; procedure TMQTTReadThread.HandleData; diff --git a/build_debian_amd64.sh b/build_debian_amd64.sh deleted file mode 100755 index 7f344b4..0000000 --- a/build_debian_amd64.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# Build simple.pas on Debian Wheezy amd64 - -# For some reason the linker needs to know where to find crti.o -# on Debian amd64 -fpc simple.pas -Fl/usr/lib/x86_64-linux-gnu/ - - - diff --git a/examples/embeddedApp/README.md b/examples/embeddedApp/README.md new file mode 100644 index 0000000..42740c8 --- /dev/null +++ b/examples/embeddedApp/README.md @@ -0,0 +1,17 @@ +embeddedApp.pas is an example of using MQTT from a command line program as might be +used in an embedded system. + +Out of the box it requires access to the MQTT server at test.mosquitto.org on port 1883 + +Build with: + + $ ./build + +Or or Debian Wheezy for amd64: + + $ build_debian_amd64.sh + +and run as: + + $ ./embeddedApp + diff --git a/examples/embeddedApp/build.sh b/examples/embeddedApp/build.sh new file mode 100755 index 0000000..7d54835 --- /dev/null +++ b/examples/embeddedApp/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Build the embeddedApp MQTT client example. + +fpc embeddedApp.pas -Fu../../TMQTTClient/ -Fu../../synapse + + + diff --git a/examples/embeddedApp/build_debian_amd64.sh b/examples/embeddedApp/build_debian_amd64.sh new file mode 100755 index 0000000..5f813d2 --- /dev/null +++ b/examples/embeddedApp/build_debian_amd64.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Build the embeddedApp MQTT client exapmple on Debian Wheezy amd64 + +# For some reason the linker needs to know where to find crti.o +# on Debian amd64 +fpc embeddedApp.pas -Fl/usr/lib/x86_64-linux-gnu/ -Fu../../TMQTTClient/ -Fu../../synapse + + + + diff --git a/simple.pas b/examples/embeddedApp/embeddedApp.pas similarity index 51% rename from simple.pas rename to examples/embeddedApp/embeddedApp.pas index 4bbf698..bd41029 100644 --- a/simple.pas +++ b/examples/embeddedApp/embeddedApp.pas @@ -1,20 +1,53 @@ - -program simple; - -uses cthreads, Classes, SysUtils, MQTT, MQTTReadThread; - -type TSimpleStates = ( +{ + ------------------------------------------------- + embeddedApp.pas - An example of using the MQTT Client from a command line program + as might be used in an embedded system. + + MQTT - http://mqtt.org/ + Spec - http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/topic/com.ibm.etools.mft.doc/ac10840_.htm + + MIT License - http://www.opensource.org/licenses/mit-license.php + Copyright (c) 2009 RSM Ltd. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ------------------------------------------------- +} + +program embeddedApp; + +// cthreads is required to get the MQTTReadThread working. +uses cthreads, Classes, MQTT, sysutils; + +// The major states of the application. +type TembeddedAppStates = ( STARTING, RUNNING, FAILING ); type - { Define a simple class } - TSimple = object + // Define class for the embedded application + // The MQTT callbacks must be methods of an object not stanalone procedures. + TembeddedApp = object MQTTClient: TMQTTClient; pingCounter : integer; pingTimer : integer; - state : TSimpleStates; + state : TembeddedAppStates; procedure run (); procedure OnConnAck(Sender: TObject; ReturnCode: longint); procedure OnPingResp(Sender: TObject); @@ -23,44 +56,41 @@ procedure OnPublish(Sender: TObject; topic, payload: string); end; -procedure TSimple.OnConnAck(Sender: TObject; ReturnCode: longint); +procedure TembeddedApp.OnConnAck(Sender: TObject; ReturnCode: longint); begin writeln ('Connection Acknowledged, Return Code: ' + IntToStr(Ord(ReturnCode))); end; -procedure TSimple.OnPublish(Sender: TObject; topic, payload: string); +procedure TembeddedApp.OnPublish(Sender: TObject; topic, payload: string); begin writeln ('Publish Received. Topic: '+ topic + ' Payload: ' + payload); end; -procedure TSimple.OnSubAck(Sender: TObject; MessageID : longint; GrantedQoS : longint); +procedure TembeddedApp.OnSubAck(Sender: TObject; MessageID : longint; GrantedQoS : longint); begin writeln ('Sub Ack Received'); end; -procedure TSimple.OnUnSubAck(Sender: TObject); +procedure TembeddedApp.OnUnSubAck(Sender: TObject); begin writeln ('Unsubscribe Ack Received'); end; -procedure TSimple.OnPingResp(Sender: TObject); +procedure TembeddedApp.OnPingResp(Sender: TObject); begin writeln ('PING! PONG!'); + // Reset ping counter to indicate all is OK. pingCounter := 0; - write('Ping counter : '); - writeln (pingCounter); end; -procedure TSimple.run(); +procedure TembeddedApp.run(); begin - writeln ('Simple MQTT Client test.'); + writeln ('embeddedApp MQTT Client.'); state := STARTING; - // MQTTClient := TMQTTClient.Create('test.mosquitto.org', 1883); - MQTTClient := TMQTTClient.Create('192.168.0.12', 1883); - writeln ('mqtt created.'); + MQTTClient := TMQTTClient.Create('test.mosquitto.org', 1883); - { Setup callback handlers } + // Setup callback handlers MQTTClient.OnConnAck := @OnConnAck; MQTTClient.OnPingResp := @OnPingResp; MQTTClient.OnPublish := @OnPublish; @@ -70,13 +100,13 @@ procedure TSimple.run(); begin case state of STARTING : begin - { Connect to MQTT server } - writeln('State: STARTING'); + // Connect to MQTT server + writeln('STARTING...'); pingCounter := 0; pingTimer := 0; if MQTTClient.Connect then begin - { Make subscriptions } + // Make subscriptions MQTTClient.Subscribe('/rsm.ie/#'); state := RUNNING; end @@ -86,8 +116,7 @@ procedure TSimple.run(); end; end; RUNNING : begin - { Publish stuff } - writeln('State: RUNNING'); + // Publish stuff if not MQTTClient.Publish('/rsm.ie/fits/detectors', '0101000101000111') then begin state := FAILING; @@ -115,7 +144,7 @@ procedure TSimple.run(); end; FAILING : begin - writeln('State: FAILING'); + writeln('FAILING...'); MQTTClient.ForceDisconnect; state := STARTING; end; @@ -131,11 +160,11 @@ procedure TSimple.run(); var - s : TSimple; + app : TembeddedApp; -(*MAIN*) +// main begin - s.run; + app.run; end. diff --git a/blcksock.pas b/synapse/blcksock.pas similarity index 100% rename from blcksock.pas rename to synapse/blcksock.pas diff --git a/jedi.inc b/synapse/jedi.inc similarity index 100% rename from jedi.inc rename to synapse/jedi.inc diff --git a/ssfpc.inc b/synapse/ssfpc.inc similarity index 100% rename from ssfpc.inc rename to synapse/ssfpc.inc diff --git a/synacode.pas b/synapse/synacode.pas similarity index 100% rename from synacode.pas rename to synapse/synacode.pas diff --git a/synafpc.pas b/synapse/synafpc.pas similarity index 100% rename from synafpc.pas rename to synapse/synafpc.pas diff --git a/synaip.pas b/synapse/synaip.pas similarity index 100% rename from synaip.pas rename to synapse/synaip.pas diff --git a/synautil.pas b/synapse/synautil.pas similarity index 100% rename from synautil.pas rename to synapse/synautil.pas diff --git a/synsock.pas b/synapse/synsock.pas similarity index 100% rename from synsock.pas rename to synapse/synsock.pas