Skip to content

Commit

Permalink
Directory reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
zicog committed Sep 17, 2013
1 parent a9159c7 commit 9c65372
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 44 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.dcu
*.~*~
*.local
*.identcache
__history
*.drc
*.map
*.exe
*.dll
bin/*
*.o
*.ppu

19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
3 changes: 0 additions & 3 deletions MQTTReadThread.pas → TMQTTClient/MQTTReadThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -143,7 +142,6 @@ procedure TMQTTReadThread.Execute;
{ Check errors }
if FPSocket^.LastError <> 0 then
begin
writeln ('Error: 2:');
rxState := 3;
end;
Synchronize(@HandleData);
Expand All @@ -155,7 +153,6 @@ procedure TMQTTReadThread.Execute;
end;
end;
end;
writeln ('TERMINATED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
end;

procedure TMQTTReadThread.HandleData;
Expand Down
10 changes: 0 additions & 10 deletions build_debian_amd64.sh

This file was deleted.

17 changes: 17 additions & 0 deletions examples/embeddedApp/README.md
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions examples/embeddedApp/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Build the embeddedApp MQTT client example.

fpc embeddedApp.pas -Fu../../TMQTTClient/ -Fu../../synapse



11 changes: 11 additions & 0 deletions examples/embeddedApp/build_debian_amd64.sh
Original file line number Diff line number Diff line change
@@ -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




91 changes: 60 additions & 31 deletions simple.pas → examples/embeddedApp/embeddedApp.pas
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -115,7 +144,7 @@ procedure TSimple.run();

end;
FAILING : begin
writeln('State: FAILING');
writeln('FAILING...');
MQTTClient.ForceDisconnect;
state := STARTING;
end;
Expand All @@ -131,11 +160,11 @@ procedure TSimple.run();


var
s : TSimple;
app : TembeddedApp;

(*MAIN*)
// main
begin
s.run;
app.run;
end.


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9c65372

Please sign in to comment.