diff --git a/Symfony/app/AppKernel.php b/Symfony/app/AppKernel.php
index d14d7fe9..e0351afa 100644
--- a/Symfony/app/AppKernel.php
+++ b/Symfony/app/AppKernel.php
@@ -17,7 +17,8 @@ public function registerBundles()
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Codebender\LibraryBundle\CodebenderLibraryBundle(),
- new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle()
+ new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
+ new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
diff --git a/Symfony/app/DoctrineMigrations/Version20160203104457.php b/Symfony/app/DoctrineMigrations/Version20160203104457.php
new file mode 100644
index 00000000..b6423365
--- /dev/null
+++ b/Symfony/app/DoctrineMigrations/Version20160203104457.php
@@ -0,0 +1,55 @@
+abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('CREATE TABLE Architecture (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX name_idx (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE Library (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, default_header VARCHAR(255) NOT NULL, folder_name VARCHAR(255) NOT NULL, description VARCHAR(2048) NOT NULL, owner VARCHAR(255) DEFAULT NULL, repo VARCHAR(255) DEFAULT NULL, branch VARCHAR(255) DEFAULT NULL, in_repo_path VARCHAR(255) DEFAULT NULL, notes LONGTEXT DEFAULT NULL, verified TINYINT(1) NOT NULL, active TINYINT(1) NOT NULL, last_commit VARCHAR(255) DEFAULT NULL, url VARCHAR(512) DEFAULT NULL, UNIQUE INDEX header_idx (default_header, folder_name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE LibraryExample (id INT AUTO_INCREMENT NOT NULL, version_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, boards VARCHAR(2048) DEFAULT NULL, INDEX IDX_3EE4A5D34BBC2705 (version_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE Partner (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, auth_key VARCHAR(255) NOT NULL, UNIQUE INDEX auth_key_idx (auth_key), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE Preference (id INT AUTO_INCREMENT NOT NULL, library_id INT DEFAULT NULL, partner_id INT DEFAULT NULL, version_id INT DEFAULT NULL, INDEX IDX_1234B383FE2541D7 (library_id), INDEX IDX_1234B3839393F8FE (partner_id), INDEX IDX_1234B3834BBC2705 (version_id), UNIQUE INDEX search_idx (library_id, partner_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE Version (id INT AUTO_INCREMENT NOT NULL, library_id INT DEFAULT NULL, version VARCHAR(255) NOT NULL, description VARCHAR(2048) DEFAULT NULL, notes LONGTEXT DEFAULT NULL, source_url VARCHAR(512) DEFAULT NULL, release_commit VARCHAR(255) DEFAULT NULL, folder_name VARCHAR(255) NOT NULL, INDEX IDX_70A1EA5FFE2541D7 (library_id), UNIQUE INDEX folders_idx (library_id, folder_name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE ArchitectureVersion (version_id INT NOT NULL, architecture_id INT NOT NULL, INDEX IDX_98E4E2F14BBC2705 (version_id), INDEX IDX_98E4E2F173F96878 (architecture_id), PRIMARY KEY(version_id, architecture_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('ALTER TABLE LibraryExample ADD CONSTRAINT FK_3EE4A5D34BBC2705 FOREIGN KEY (version_id) REFERENCES Version (id)');
+ $this->addSql('ALTER TABLE Preference ADD CONSTRAINT FK_1234B383FE2541D7 FOREIGN KEY (library_id) REFERENCES Library (id)');
+ $this->addSql('ALTER TABLE Preference ADD CONSTRAINT FK_1234B3839393F8FE FOREIGN KEY (partner_id) REFERENCES Partner (id)');
+ $this->addSql('ALTER TABLE Preference ADD CONSTRAINT FK_1234B3834BBC2705 FOREIGN KEY (version_id) REFERENCES Version (id)');
+ $this->addSql('ALTER TABLE Version ADD CONSTRAINT FK_70A1EA5FFE2541D7 FOREIGN KEY (library_id) REFERENCES Library (id)');
+ $this->addSql('ALTER TABLE ArchitectureVersion ADD CONSTRAINT FK_98E4E2F14BBC2705 FOREIGN KEY (version_id) REFERENCES Version (id)');
+ $this->addSql('ALTER TABLE ArchitectureVersion ADD CONSTRAINT FK_98E4E2F173F96878 FOREIGN KEY (architecture_id) REFERENCES Architecture (id)');
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function down(Schema $schema)
+ {
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('ALTER TABLE ArchitectureVersion DROP FOREIGN KEY FK_98E4E2F173F96878');
+ $this->addSql('ALTER TABLE Preference DROP FOREIGN KEY FK_1234B383FE2541D7');
+ $this->addSql('ALTER TABLE Version DROP FOREIGN KEY FK_70A1EA5FFE2541D7');
+ $this->addSql('ALTER TABLE Preference DROP FOREIGN KEY FK_1234B3839393F8FE');
+ $this->addSql('ALTER TABLE LibraryExample DROP FOREIGN KEY FK_3EE4A5D34BBC2705');
+ $this->addSql('ALTER TABLE Preference DROP FOREIGN KEY FK_1234B3834BBC2705');
+ $this->addSql('ALTER TABLE ArchitectureVersion DROP FOREIGN KEY FK_98E4E2F14BBC2705');
+ $this->addSql('DROP TABLE Architecture');
+ $this->addSql('DROP TABLE Library');
+ $this->addSql('DROP TABLE LibraryExample');
+ $this->addSql('DROP TABLE Partner');
+ $this->addSql('DROP TABLE Preference');
+ $this->addSql('DROP TABLE Version');
+ $this->addSql('DROP TABLE ArchitectureVersion');
+ }
+}
diff --git a/Symfony/app/DoctrineMigrations/Version20160315080428.php b/Symfony/app/DoctrineMigrations/Version20160315080428.php
new file mode 100644
index 00000000..651571e9
--- /dev/null
+++ b/Symfony/app/DoctrineMigrations/Version20160315080428.php
@@ -0,0 +1,38 @@
+abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('ALTER TABLE Library ADD latest_version_id INT');
+ $this->addSql('ALTER TABLE Library ADD CONSTRAINT FK_6E3DA1205F67402F FOREIGN KEY (latest_version_id) REFERENCES Version (id)');
+ $this->addSql('CREATE UNIQUE INDEX UNIQ_6E3DA1205F67402F ON Library (latest_version_id)');
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function down(Schema $schema)
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('ALTER TABLE Library DROP FOREIGN KEY FK_6E3DA1205F67402F');
+ $this->addSql('DROP INDEX UNIQ_6E3DA1205F67402F ON Library');
+ $this->addSql('ALTER TABLE Library DROP latest_version_id');
+ }
+}
diff --git a/Symfony/app/DoctrineMigrations/Version20160315081844.php b/Symfony/app/DoctrineMigrations/Version20160315081844.php
new file mode 100644
index 00000000..7b81efab
--- /dev/null
+++ b/Symfony/app/DoctrineMigrations/Version20160315081844.php
@@ -0,0 +1,270 @@
+container = $container;
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function up(Schema $schema)
+ {
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('ALTER TABLE Library ADD is_built_in TINYINT(1) NOT NULL');
+ }
+
+ public function postUp(Schema $schema)
+ {
+ /* @var EntityManager $entityManager */
+ $entityManager = $this->container->get('doctrine.orm.entity_manager');
+
+ /*
+ * 1. Create the various Arduino architectures
+ */
+ $avrArchitecture = new Architecture();
+ $avrArchitecture->setName('AVR');
+
+ $esp8266Architecture = new Architecture();
+ $esp8266Architecture->setName('ESP8266');
+
+ $edisonArchitecture = new Architecture();
+ $edisonArchitecture->setName('Intel Edison');
+
+ $teensyArchitecture = new Architecture();
+ $teensyArchitecture->setName('Teensy');
+
+ $architectures = [$avrArchitecture, $esp8266Architecture, $edisonArchitecture, $teensyArchitecture];
+ foreach ($architectures as $architecture) {
+ $entityManager->persist($architecture);
+ }
+ $entityManager->flush();
+
+ /*
+ * 2. Migrate existing external libraries and add AVR architecture to them
+ */
+ $externalLibraries = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')
+ ->findAll();
+ $externalLibraryVersion = 'CB-1';
+ /* @var ExternalLibrary $externalLibrary */
+ foreach ($externalLibraries as $externalLibrary) {
+ $defaultHeader = $externalLibrary->getMachineName();
+ print("Migrating external lib: $defaultHeader\n");
+
+ // Do not migrate the SD external library
+ if ($defaultHeader === 'SD') continue;
+
+ /*
+ * Migrate all the existing attributes
+ */
+ $library = new Library();
+ $library->setName($externalLibrary->getHumanName());
+ $library->setDefaultHeader($externalLibrary->getMachineName());
+ $library->setFolderName($externalLibrary->getMachineName());
+ $library->setDescription($externalLibrary->getDescription());
+ $library->setOwner($externalLibrary->getOwner());
+ $library->setRepo($externalLibrary->getRepo());
+ $library->setBranch($externalLibrary->getBranch());
+ $library->setInRepoPath($externalLibrary->getInRepoPath());
+ $library->setNotes($externalLibrary->getNotes());
+ $library->setVerified($externalLibrary->getVerified());
+ $library->setActive($externalLibrary->getActive());
+ $library->setLastCommit($externalLibrary->getLastCommit());
+ $library->setUrl($externalLibrary->getUrl());
+ $library->setIsBuiltIn(False);
+
+ $version = new Version();
+ $version->setLibrary($library);
+ $version->setVersion($externalLibraryVersion);
+ $version->setDescription($externalLibrary->getDescription());
+ $version->setNotes($externalLibrary->getNotes());
+ $version->setSourceUrl($externalLibrary->getSourceUrl());
+ $version->setFolderName($externalLibraryVersion);
+ $version->addArchitecture($avrArchitecture);
+
+ $examples = $entityManager->getRepository('CodebenderLibraryBundle:Example')
+ ->findBy(['library' => $externalLibrary]);
+ /* @var Example $example */
+ foreach ($examples as $example) {
+ $position = strpos($example->getPath(), '/');
+ $newExamplePath = substr($example->getPath(), $position + 1);
+
+ $libraryExample = new LibraryExample();
+ $libraryExample->setName($example->getName());
+ $libraryExample->setVersion($version);
+ $libraryExample->setBoards($example->getBoards());
+ $libraryExample->setPath($newExamplePath);
+
+ $entityManager->persist($libraryExample);
+ }
+
+ $library->addVersion($version);
+ $library->setLatestVersion($version);
+
+ /*
+ * Persist and move library files
+ */
+ $entityManager->persist($library);
+ $entityManager->persist($version);
+ $this->moveExternalLibraryFiles($defaultHeader, $externalLibraryVersion);
+ }
+ $entityManager->flush();
+
+ /*
+ * 3. Migrate existing built-in libraries as external libraries and add AVR architecture to them
+ */
+ $builtInVersion = '1.0.5';
+ $builtInLibrariesPath = $this->container->getParameter('builtin_libraries') . '/libraries';
+ $finder = new Finder();
+ $finder->depth(0);
+ /* @var SplFileInfo $builtInLibrary */
+ foreach ($finder->in($builtInLibrariesPath) as $builtInLibrary) {
+ /*
+ * Migrate any existing attributes
+ */
+ $defaultHeader = $builtInLibrary->getFilename();
+ print("Migrating built-in lib: $defaultHeader\n");
+
+ $library = new Library();
+ $library->setName($defaultHeader);
+ $library->setDefaultHeader($defaultHeader);
+ $library->setFolderName($defaultHeader);
+ $library->setDescription($defaultHeader . ' v' . $builtInVersion);
+ $library->setVerified(True);
+ $library->setActive(True);
+ $library->setIsBuiltIn(True);
+
+ $version = new Version();
+ $version->setLibrary($library);
+ $version->setVersion($builtInVersion);
+ $version->setFolderName($builtInVersion);
+ $version->addArchitecture($avrArchitecture);
+
+ /* @var ApiHandler $handler */
+ $handler = $this->container->get('codebender_library.apiHandler');
+ $examples = $handler->fetchLibraryExamples(new Finder(), $builtInLibrary->getPathname());
+ foreach ($examples as $example) {
+ $libraryExample = new LibraryExample();
+ $libraryExample->setVersion($version);
+ $libraryExample->setName(pathinfo($example['filename'])['filename']);
+ $libraryExample->setPath($example['filename']);
+ $libraryExample->setBoards(null);
+
+ $entityManager->persist($libraryExample);
+ }
+
+ $library->addVersion($version);
+ $library->setLatestVersion($version);
+
+ /*
+ * Persist and move library files
+ */
+ $entityManager->persist($library);
+ $entityManager->persist($version);
+ $this->moveBuiltInLibraryFiles($builtInLibrary, $builtInVersion);
+ }
+ $entityManager->flush();
+
+ /*
+ * 4. Migrate existing authorization key
+ */
+ $authorizationKey = $this->container->getParameter('authorizationKey');
+ $codebender = new Partner();
+ $codebender->setName('Codebender');
+ $codebender->setAuthKey($authorizationKey);
+ $entityManager->persist($codebender);
+ $entityManager->flush();
+
+ /*
+ * 5. Set all existing versions as the preferred version for Codebender
+ */
+ $libraries = $entityManager->getRepository('CodebenderLibraryBundle:Library')->findAll();
+ /* @var Library $library */
+ foreach ($libraries as $library) {
+ $preference = new Preference();
+ $preference->setLibrary($library);
+ $preference->setVersion($library->getLatestVersion());
+ $codebender->addPreference($preference);
+
+ $entityManager->persist($preference);
+ $entityManager->persist($codebender);
+ }
+ $entityManager->flush();
+ }
+
+ /**
+ * This method moves an existing built-in library folder from the given sourceFolder to its
+ * new location. The old directory is removed after this operation.
+ *
+ * @param SplFileInfo $sourceFolder
+ * @param $version
+ */
+ private function moveBuiltInLibraryFiles(SplFileInfo $sourceFolder, $version)
+ {
+ $defaultHeader = $sourceFolder->getFilename();
+
+ /* @var Filesystem $filesystem */
+ $filesystem = new Filesystem();
+ $sourcePath = $sourceFolder->getPathname();
+ $destinationRootDirectory = $this->container->getParameter('external_libraries_v2');
+ $destinationPath = $destinationRootDirectory . '/' . $defaultHeader . '/' . $version;
+ $filesystem->mirror($sourcePath, $destinationPath);
+ }
+
+ /**
+ * This method moves an existing external library folder from the existing location to its
+ * new location. The old directory is removed after this operation.
+ *
+ * @param $defaultHeader
+ * @param $version
+ */
+ private function moveExternalLibraryFiles($defaultHeader, $version)
+ {
+ /* @var Filesystem $filesystem */
+ $filesystem = new Filesystem();
+ $sourceRootDirectory = $this->container->getParameter('external_libraries');
+ $destinationRootDirectory = $this->container->getParameter('external_libraries_v2');
+ $sourcePath = $sourceRootDirectory . '/' . $defaultHeader;
+ $destinationPath = $destinationRootDirectory . '/' . $defaultHeader . '/' . $version;
+ $filesystem->mirror($sourcePath, $destinationPath);
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function down(Schema $schema)
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('ALTER TABLE Library DROP is_built_in');
+ }
+}
diff --git a/Symfony/app/DoctrineMigrations/Version20160331141711.php b/Symfony/app/DoctrineMigrations/Version20160331141711.php
new file mode 100644
index 00000000..47b90b2c
--- /dev/null
+++ b/Symfony/app/DoctrineMigrations/Version20160331141711.php
@@ -0,0 +1,38 @@
+abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('ALTER TABLE Example DROP FOREIGN KEY FK_A151A203FE2541D7');
+ $this->addSql('DROP TABLE Example');
+ $this->addSql('DROP TABLE ExternalLibrary');
+ }
+
+ /**
+ * @param Schema $schema
+ */
+ public function down(Schema $schema)
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
+
+ $this->addSql('CREATE TABLE Example (id INT AUTO_INCREMENT NOT NULL, library_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, boards VARCHAR(2048) DEFAULT NULL, INDEX IDX_A151A203FE2541D7 (library_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('CREATE TABLE ExternalLibrary (id INT AUTO_INCREMENT NOT NULL, humanName VARCHAR(255) NOT NULL, machineName VARCHAR(255) NOT NULL, description VARCHAR(2048) NOT NULL, owner VARCHAR(255) DEFAULT NULL, repo VARCHAR(255) DEFAULT NULL, verified TINYINT(1) NOT NULL, active TINYINT(1) NOT NULL, lastCommit VARCHAR(255) DEFAULT NULL, url VARCHAR(512) DEFAULT NULL, branch VARCHAR(255) DEFAULT NULL, in_repo_path VARCHAR(255) DEFAULT NULL, notes LONGTEXT DEFAULT NULL, source_url VARCHAR(512) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+ $this->addSql('ALTER TABLE Example ADD CONSTRAINT FK_A151A203FE2541D7 FOREIGN KEY (library_id) REFERENCES ExternalLibrary (id)');
+ }
+}
diff --git a/Symfony/app/config/config.yml b/Symfony/app/config/config.yml
index 033d6682..53737ee3 100644
--- a/Symfony/app/config/config.yml
+++ b/Symfony/app/config/config.yml
@@ -25,7 +25,7 @@ services:
class: Codebender\LibraryBundle\EventListener\AuthenticationListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
- arguments: [ %authorizationKey% ]
+ arguments: [ %authorizationKey%, @service_container ]
# Twig Configuration
twig:
@@ -65,6 +65,12 @@ doctrine:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
+doctrine_migrations:
+ dir_name: "%kernel.root_dir%/DoctrineMigrations"
+ namespace: Application\Migrations
+ table_name: migration_versions
+ name: Application Migrations
+
# Swiftmailer Configuration
# swiftmailer:
# transport: %mailer_transport%
diff --git a/Symfony/app/config/parameters.yml.dist b/Symfony/app/config/parameters.yml.dist
index 3766c865..51125048 100644
--- a/Symfony/app/config/parameters.yml.dist
+++ b/Symfony/app/config/parameters.yml.dist
@@ -13,6 +13,7 @@ parameters:
# Paths to libraries.
builtin_libraries: /opt/codebender/codebender-arduino-library-files
external_libraries: /opt/codebender/codebender-external-library-files
+ external_libraries_v2: /opt/codebender/codebender-external-library-files-v2
authorizationKey: "youMustChangeThis"
diff --git a/Symfony/composer.json b/Symfony/composer.json
index 81abc1b0..9909cfd4 100644
--- a/Symfony/composer.json
+++ b/Symfony/composer.json
@@ -9,7 +9,7 @@
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
- "doctrine/orm": ">=2.2.3,<2.4-dev",
+ "doctrine/orm": "2.4.*",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
@@ -19,7 +19,8 @@
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
- "doctrine/doctrine-fixtures-bundle": "^2.2"
+ "doctrine/doctrine-fixtures-bundle": "^2.2",
+ "doctrine/doctrine-migrations-bundle": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
diff --git a/Symfony/composer.lock b/Symfony/composer.lock
index e421278a..ec7f32b5 100644
--- a/Symfony/composer.lock
+++ b/Symfony/composer.lock
@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "1ea0627142f4ec2d8e41b3f81b63416f",
- "content-hash": "40237162eb9019bb37b9009aa56285e9",
+ "hash": "ea9ee384757a3d9531247eed6dcfba0a",
+ "content-hash": "32ca2c32de351e8c373a140364d97488",
"packages": [
{
"name": "doctrine/annotations",
@@ -77,38 +77,38 @@
},
{
"name": "doctrine/cache",
- "version": "v1.4.2",
+ "version": "v1.6.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
- "reference": "8c434000f420ade76a07c64cbe08ca47e5c101ca"
+ "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/cache/zipball/8c434000f420ade76a07c64cbe08ca47e5c101ca",
- "reference": "8c434000f420ade76a07c64cbe08ca47e5c101ca",
+ "url": "https://api.github.com/repos/doctrine/cache/zipball/f8af318d14bdb0eff0336795b428b547bd39ccb6",
+ "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6",
"shasum": ""
},
"require": {
- "php": ">=5.3.2"
+ "php": "~5.5|~7.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
- "phpunit/phpunit": ">=3.7",
+ "phpunit/phpunit": "~4.8|~5.0",
"predis/predis": "~1.0",
"satooshi/php-coveralls": "~0.6"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.5.x-dev"
+ "dev-master": "1.6.x-dev"
}
},
"autoload": {
- "psr-0": {
- "Doctrine\\Common\\Cache\\": "lib/"
+ "psr-4": {
+ "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -143,7 +143,7 @@
"cache",
"caching"
],
- "time": "2015-08-31 12:36:41"
+ "time": "2015-12-31 16:37:02"
},
{
"name": "doctrine/collections",
@@ -213,16 +213,16 @@
},
{
"name": "doctrine/common",
- "version": "v2.4.3",
+ "version": "v2.6.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/common.git",
- "reference": "4824569127daa9784bf35219a1cd49306c795389"
+ "reference": "a579557bc689580c19fee4e27487a67fe60defc0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/common/zipball/4824569127daa9784bf35219a1cd49306c795389",
- "reference": "4824569127daa9784bf35219a1cd49306c795389",
+ "url": "https://api.github.com/repos/doctrine/common/zipball/a579557bc689580c19fee4e27487a67fe60defc0",
+ "reference": "a579557bc689580c19fee4e27487a67fe60defc0",
"shasum": ""
},
"require": {
@@ -231,20 +231,20 @@
"doctrine/collections": "1.*",
"doctrine/inflector": "1.*",
"doctrine/lexer": "1.*",
- "php": ">=5.3.2"
+ "php": "~5.5|~7.0"
},
"require-dev": {
- "phpunit/phpunit": "~3.7"
+ "phpunit/phpunit": "~4.8|~5.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.4.x-dev"
+ "dev-master": "2.7.x-dev"
}
},
"autoload": {
- "psr-0": {
- "Doctrine\\Common\\": "lib/"
+ "psr-4": {
+ "Doctrine\\Common\\": "lib/Doctrine/Common"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -282,28 +282,31 @@
"persistence",
"spl"
],
- "time": "2015-08-31 14:38:45"
+ "time": "2015-12-25 13:18:31"
},
{
"name": "doctrine/data-fixtures",
- "version": "v1.0.2",
+ "version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/data-fixtures.git",
- "reference": "422952ccf7151c02bb5c01fadb305dce266a3b5f"
+ "reference": "bd44f6b6e40247b6530bc8abe802e4e4d914976a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/422952ccf7151c02bb5c01fadb305dce266a3b5f",
- "reference": "422952ccf7151c02bb5c01fadb305dce266a3b5f",
+ "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/bd44f6b6e40247b6530bc8abe802e4e4d914976a",
+ "reference": "bd44f6b6e40247b6530bc8abe802e4e4d914976a",
"shasum": ""
},
"require": {
"doctrine/common": "~2.2",
"php": ">=5.3.2"
},
+ "conflict": {
+ "doctrine/orm": "< 2.4"
+ },
"require-dev": {
- "doctrine/orm": "~2.2"
+ "doctrine/orm": "~2.4"
},
"suggest": {
"doctrine/mongodb-odm": "For loading MongoDB ODM fixtures",
@@ -313,7 +316,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "1.1.x-dev"
}
},
"autoload": {
@@ -336,35 +339,37 @@
"keywords": [
"database"
],
- "time": "2015-03-27 21:01:43"
+ "time": "2015-03-30 12:14:13"
},
{
"name": "doctrine/dbal",
- "version": "2.3.5",
+ "version": "v2.4.5",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
- "reference": "d5067b0b7e5ef59ba165dcc116c539400bf957ff"
+ "reference": "5a1f4bf34d61d997ccd9f0539fbc14c7a772aa16"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/dbal/zipball/d5067b0b7e5ef59ba165dcc116c539400bf957ff",
- "reference": "d5067b0b7e5ef59ba165dcc116c539400bf957ff",
+ "url": "https://api.github.com/repos/doctrine/dbal/zipball/5a1f4bf34d61d997ccd9f0539fbc14c7a772aa16",
+ "reference": "5a1f4bf34d61d997ccd9f0539fbc14c7a772aa16",
"shasum": ""
},
"require": {
- "doctrine/common": ">=2.3.0,<2.5-dev",
+ "doctrine/common": "~2.4",
"php": ">=5.3.2"
},
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.3.x-dev"
- }
+ "require-dev": {
+ "phpunit/phpunit": "3.7.*",
+ "symfony/console": "~2.0"
+ },
+ "suggest": {
+ "symfony/console": "For helpful console commands such as SQL execution and import of files."
},
+ "type": "library",
"autoload": {
"psr-0": {
- "Doctrine\\DBAL": "lib/"
+ "Doctrine\\DBAL\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -397,7 +402,7 @@
"persistence",
"queryobject"
],
- "time": "2014-09-15 11:44:29"
+ "time": "2016-01-05 22:18:20"
},
{
"name": "doctrine/doctrine-bundle",
@@ -471,23 +476,23 @@
},
{
"name": "doctrine/doctrine-fixtures-bundle",
- "version": "v2.2.1",
+ "version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/DoctrineFixturesBundle.git",
- "reference": "817c2d233fde0fe85cb7e4d25d43fbfcd028aef8"
+ "reference": "0f1a2f91b349e10f5c343f75ab71d23aace5b029"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/817c2d233fde0fe85cb7e4d25d43fbfcd028aef8",
- "reference": "817c2d233fde0fe85cb7e4d25d43fbfcd028aef8",
+ "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/0f1a2f91b349e10f5c343f75ab71d23aace5b029",
+ "reference": "0f1a2f91b349e10f5c343f75ab71d23aace5b029",
"shasum": ""
},
"require": {
"doctrine/data-fixtures": "~1.0",
"doctrine/doctrine-bundle": "~1.0",
"php": ">=5.3.2",
- "symfony/doctrine-bridge": "~2.1"
+ "symfony/doctrine-bridge": "~2.3|~3.0"
},
"type": "symfony-bundle",
"extra": {
@@ -524,20 +529,78 @@
"Fixture",
"persistence"
],
- "time": "2015-08-04 22:43:14"
+ "time": "2015-11-04 21:23:23"
+ },
+ {
+ "name": "doctrine/doctrine-migrations-bundle",
+ "version": "1.1.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/DoctrineMigrationsBundle.git",
+ "reference": "303a576e2124efb07ec215e34ea2480b841cf5e4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/303a576e2124efb07ec215e34ea2480b841cf5e4",
+ "reference": "303a576e2124efb07ec215e34ea2480b841cf5e4",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/doctrine-bundle": "~1.0",
+ "doctrine/migrations": "~1.0",
+ "php": ">=5.3.2",
+ "symfony/framework-bundle": "~2.3|~3.0"
+ },
+ "type": "symfony-bundle",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.1-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\Bundle\\MigrationsBundle\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ },
+ {
+ "name": "Doctrine Project",
+ "homepage": "http://www.doctrine-project.org"
+ },
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ }
+ ],
+ "description": "Symfony DoctrineMigrationsBundle",
+ "homepage": "http://www.doctrine-project.org",
+ "keywords": [
+ "dbal",
+ "migrations",
+ "schema"
+ ],
+ "time": "2015-11-04 13:45:30"
},
{
"name": "doctrine/inflector",
- "version": "v1.0.1",
+ "version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/inflector.git",
- "reference": "0bcb2e79d8571787f18b7eb036ed3d004908e604"
+ "reference": "90b2128806bfde671b6952ab8bea493942c1fdae"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/inflector/zipball/0bcb2e79d8571787f18b7eb036ed3d004908e604",
- "reference": "0bcb2e79d8571787f18b7eb036ed3d004908e604",
+ "url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae",
+ "reference": "90b2128806bfde671b6952ab8bea493942c1fdae",
"shasum": ""
},
"require": {
@@ -549,7 +612,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "1.1.x-dev"
}
},
"autoload": {
@@ -591,7 +654,7 @@
"singularize",
"string"
],
- "time": "2014-12-20 21:24:13"
+ "time": "2015-11-06 14:35:42"
},
{
"name": "doctrine/lexer",
@@ -647,25 +710,99 @@
],
"time": "2014-09-09 13:34:57"
},
+ {
+ "name": "doctrine/migrations",
+ "version": "v1.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/migrations.git",
+ "reference": "2ce8d87d4247e4b87cc5905ea5f8446b12bd9b5b"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/migrations/zipball/2ce8d87d4247e4b87cc5905ea5f8446b12bd9b5b",
+ "reference": "2ce8d87d4247e4b87cc5905ea5f8446b12bd9b5b",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/dbal": "~2.2",
+ "ocramius/proxy-manager": "^1.0",
+ "php": "^5.5|^7.0",
+ "symfony/console": "~2.3|~3.0",
+ "symfony/yaml": "~2.3|~3.0"
+ },
+ "require-dev": {
+ "doctrine/coding-standard": "dev-master",
+ "doctrine/orm": "2.*",
+ "johnkary/phpunit-speedtrap": "~1.0@dev",
+ "mockery/mockery": "^0.9.4",
+ "phpunit/phpunit": "~4.7",
+ "satooshi/php-coveralls": "0.6.*"
+ },
+ "bin": [
+ "bin/doctrine-migrations"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "v1.4.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\DBAL\\Migrations\\": "lib/Doctrine/DBAL/Migrations"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "LGPL-2.1"
+ ],
+ "authors": [
+ {
+ "name": "Benjamin Eberlei",
+ "email": "kontakt@beberlei.de"
+ },
+ {
+ "name": "Jonathan Wage",
+ "email": "jonwage@gmail.com"
+ },
+ {
+ "name": "Michael Simonson",
+ "email": "contact@mikesimonson.com"
+ }
+ ],
+ "description": "Database Schema migrations using Doctrine DBAL",
+ "homepage": "http://www.doctrine-project.org",
+ "keywords": [
+ "database",
+ "migrations"
+ ],
+ "time": "2016-01-23 09:49:17"
+ },
{
"name": "doctrine/orm",
- "version": "v2.3.6",
+ "version": "v2.4.8",
"source": {
"type": "git",
"url": "https://github.com/doctrine/doctrine2.git",
- "reference": "c2135b38216c6c8a410e764792aa368e946f2ae5"
+ "reference": "5aedac1e5c5caaeac14798822c70325dc242d467"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/c2135b38216c6c8a410e764792aa368e946f2ae5",
- "reference": "c2135b38216c6c8a410e764792aa368e946f2ae5",
+ "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/5aedac1e5c5caaeac14798822c70325dc242d467",
+ "reference": "5aedac1e5c5caaeac14798822c70325dc242d467",
"shasum": ""
},
"require": {
- "doctrine/dbal": "2.3.*",
+ "doctrine/collections": "~1.1",
+ "doctrine/dbal": "~2.4",
"ext-pdo": "*",
"php": ">=5.3.2",
- "symfony/console": "2.*"
+ "symfony/console": "~2.0"
+ },
+ "require-dev": {
+ "satooshi/php-coveralls": "dev-master",
+ "symfony/yaml": "~2.1"
},
"suggest": {
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
@@ -677,12 +814,12 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.3.x-dev"
+ "dev-master": "2.4.x-dev"
}
},
"autoload": {
"psr-0": {
- "Doctrine\\ORM": "lib/"
+ "Doctrine\\ORM\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -690,17 +827,6 @@
"MIT"
],
"authors": [
- {
- "name": "Jonathan Wage",
- "email": "jonwage@gmail.com",
- "homepage": "http://www.jwage.com/",
- "role": "Creator"
- },
- {
- "name": "Guilherme Blanco",
- "email": "guilhermeblanco@gmail.com",
- "homepage": "http://www.instaclick.com"
- },
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
@@ -708,6 +834,14 @@
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
+ },
+ {
+ "name": "Guilherme Blanco",
+ "email": "guilhermeblanco@gmail.com"
+ },
+ {
+ "name": "Jonathan Wage",
+ "email": "jonwage@gmail.com"
}
],
"description": "Object-Relational-Mapper for PHP",
@@ -716,25 +850,25 @@
"database",
"orm"
],
- "time": "2014-06-03 19:53:45"
+ "time": "2015-08-31 13:19:01"
},
{
"name": "incenteev/composer-parameter-handler",
- "version": "v2.1.1",
+ "version": "v2.1.2",
"source": {
"type": "git",
"url": "https://github.com/Incenteev/ParameterHandler.git",
- "reference": "84a205fe80a46101607bafbc423019527893ddd0"
+ "reference": "d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Incenteev/ParameterHandler/zipball/84a205fe80a46101607bafbc423019527893ddd0",
- "reference": "84a205fe80a46101607bafbc423019527893ddd0",
+ "url": "https://api.github.com/repos/Incenteev/ParameterHandler/zipball/d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc",
+ "reference": "d7ce7f06136109e81d1cb9d57066c4d4a99cf1cc",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
- "symfony/yaml": "~2.0"
+ "symfony/yaml": "~2.3|~3.0"
},
"require-dev": {
"composer/composer": "1.0.*@dev",
@@ -767,7 +901,7 @@
"keywords": [
"parameters management"
],
- "time": "2015-06-03 08:27:03"
+ "time": "2015-11-10 17:04:01"
},
{
"name": "jdorn/sql-formatter",
@@ -967,6 +1101,117 @@
],
"time": "2015-10-14 12:51:02"
},
+ {
+ "name": "ocramius/proxy-manager",
+ "version": "1.0.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/Ocramius/ProxyManager.git",
+ "reference": "57e9272ec0e8deccf09421596e0e2252df440e11"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/Ocramius/ProxyManager/zipball/57e9272ec0e8deccf09421596e0e2252df440e11",
+ "reference": "57e9272ec0e8deccf09421596e0e2252df440e11",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "zendframework/zend-code": ">2.2.5,<3.0"
+ },
+ "require-dev": {
+ "ext-phar": "*",
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "1.5.*"
+ },
+ "suggest": {
+ "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects",
+ "zendframework/zend-json": "To have the JsonRpc adapter (Remote Object feature)",
+ "zendframework/zend-soap": "To have the Soap adapter (Remote Object feature)",
+ "zendframework/zend-stdlib": "To use the hydrator proxy",
+ "zendframework/zend-xmlrpc": "To have the XmlRpc adapter (Remote Object feature)"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "ProxyManager\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Marco Pivetta",
+ "email": "ocramius@gmail.com",
+ "homepage": "http://ocramius.github.com/"
+ }
+ ],
+ "description": "A library providing utilities to generate, instantiate and generally operate with Object Proxies",
+ "homepage": "https://github.com/Ocramius/ProxyManager",
+ "keywords": [
+ "aop",
+ "lazy loading",
+ "proxy",
+ "proxy pattern",
+ "service proxies"
+ ],
+ "time": "2015-08-09 04:28:19"
+ },
+ {
+ "name": "paragonie/random_compat",
+ "version": "1.1.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/paragonie/random_compat.git",
+ "reference": "e6f80ab77885151908d0ec743689ca700886e8b0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/paragonie/random_compat/zipball/e6f80ab77885151908d0ec743689ca700886e8b0",
+ "reference": "e6f80ab77885151908d0ec743689ca700886e8b0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.2.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "4.*|5.*"
+ },
+ "suggest": {
+ "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
+ },
+ "type": "library",
+ "autoload": {
+ "files": [
+ "lib/random.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Paragon Initiative Enterprises",
+ "email": "security@paragonie.com",
+ "homepage": "https://paragonie.com"
+ }
+ ],
+ "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
+ "keywords": [
+ "csprng",
+ "pseudorandom",
+ "random"
+ ],
+ "time": "2016-01-29 16:19:52"
+ },
{
"name": "psr/log",
"version": "1.0.0",
@@ -1326,28 +1571,28 @@
},
{
"name": "symfony/swiftmailer-bundle",
- "version": "v2.3.8",
+ "version": "v2.3.11",
"source": {
"type": "git",
"url": "https://github.com/symfony/swiftmailer-bundle.git",
- "reference": "970b13d01871207e81d17b17ddda025e7e21e797"
+ "reference": "5e1a90f28213231ceee19c953bbebc5b5b95c690"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/swiftmailer-bundle/zipball/970b13d01871207e81d17b17ddda025e7e21e797",
- "reference": "970b13d01871207e81d17b17ddda025e7e21e797",
+ "url": "https://api.github.com/repos/symfony/swiftmailer-bundle/zipball/5e1a90f28213231ceee19c953bbebc5b5b95c690",
+ "reference": "5e1a90f28213231ceee19c953bbebc5b5b95c690",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"swiftmailer/swiftmailer": ">=4.2.0,~5.0",
- "symfony/swiftmailer-bridge": "~2.1"
+ "symfony/config": "~2.3|~3.0",
+ "symfony/dependency-injection": "~2.3|~3.0",
+ "symfony/http-kernel": "~2.3|~3.0",
+ "symfony/yaml": "~2.3|~3.0"
},
"require-dev": {
- "symfony/config": "~2.1",
- "symfony/dependency-injection": "~2.1",
- "symfony/http-kernel": "~2.1",
- "symfony/yaml": "~2.1"
+ "symfony/phpunit-bridge": "~2.7|~3.0"
},
"suggest": {
"psr/log": "Allows logging"
@@ -1379,27 +1624,28 @@
],
"description": "Symfony SwiftmailerBundle",
"homepage": "http://symfony.com",
- "time": "2014-12-01 17:44:50"
+ "time": "2016-01-15 16:41:20"
},
{
"name": "symfony/symfony",
- "version": "v2.3.33",
+ "version": "v2.3.37",
"source": {
"type": "git",
"url": "https://github.com/symfony/symfony.git",
- "reference": "3b8a8ee48e8ad81cb5d9d85b909bbd28011423a1"
+ "reference": "8fe60fae1d35406762149faa3cf097725ffba9e2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/symfony/zipball/3b8a8ee48e8ad81cb5d9d85b909bbd28011423a1",
- "reference": "3b8a8ee48e8ad81cb5d9d85b909bbd28011423a1",
+ "url": "https://api.github.com/repos/symfony/symfony/zipball/8fe60fae1d35406762149faa3cf097725ffba9e2",
+ "reference": "8fe60fae1d35406762149faa3cf097725ffba9e2",
"shasum": ""
},
"require": {
"doctrine/common": "~2.4",
+ "paragonie/random_compat": "~1.0",
"php": ">=5.3.3",
"psr/log": "~1.0",
- "twig/twig": "~1.20|~2.0"
+ "twig/twig": "~1.23|~2.0"
},
"replace": {
"symfony/browser-kit": "self.version",
@@ -1428,7 +1674,10 @@
"symfony/proxy-manager-bridge": "self.version",
"symfony/routing": "self.version",
"symfony/security": "self.version",
+ "symfony/security-acl": "self.version",
"symfony/security-bundle": "self.version",
+ "symfony/security-core": "self.version",
+ "symfony/security-http": "self.version",
"symfony/serializer": "self.version",
"symfony/stopwatch": "self.version",
"symfony/swiftmailer-bridge": "self.version",
@@ -1447,8 +1696,7 @@
"ircmaxell/password-compat": "~1.0",
"monolog/monolog": "~1.3",
"ocramius/proxy-manager": "~0.3.1",
- "propel/propel1": "~1.6",
- "symfony/phpunit-bridge": "~2.7"
+ "propel/propel1": "~1.6"
},
"type": "library",
"extra": {
@@ -1466,6 +1714,9 @@
],
"files": [
"src/Symfony/Component/Intl/Resources/stubs/functions.php"
+ ],
+ "exclude-from-classmap": [
+ "**/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
@@ -1487,7 +1738,7 @@
"keywords": [
"framework"
],
- "time": "2015-09-25 09:08:49"
+ "time": "2016-01-14 09:15:03"
},
{
"name": "twig/extensions",
@@ -1538,16 +1789,16 @@
},
{
"name": "twig/twig",
- "version": "v1.22.3",
+ "version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
- "reference": "ebfc36b7e77b0c1175afe30459cf943010245540"
+ "reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/twigphp/Twig/zipball/ebfc36b7e77b0c1175afe30459cf943010245540",
- "reference": "ebfc36b7e77b0c1175afe30459cf943010245540",
+ "url": "https://api.github.com/repos/twigphp/Twig/zipball/3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8",
+ "reference": "3e5aa30ebfbafd5951fb1b01e338e1800ce7e0e8",
"shasum": ""
},
"require": {
@@ -1560,7 +1811,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.22-dev"
+ "dev-master": "1.24-dev"
}
},
"autoload": {
@@ -1595,7 +1846,113 @@
"keywords": [
"templating"
],
- "time": "2015-10-13 07:07:02"
+ "time": "2016-01-25 21:22:18"
+ },
+ {
+ "name": "zendframework/zend-code",
+ "version": "2.6.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/zendframework/zend-code.git",
+ "reference": "c4e8f976a772cfb14b47dabd69b5245a423082b4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/zendframework/zend-code/zipball/c4e8f976a772cfb14b47dabd69b5245a423082b4",
+ "reference": "c4e8f976a772cfb14b47dabd69b5245a423082b4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5",
+ "zendframework/zend-eventmanager": "^2.6|^3.0"
+ },
+ "require-dev": {
+ "doctrine/annotations": "~1.0",
+ "fabpot/php-cs-fixer": "1.7.*",
+ "phpunit/phpunit": "~4.0",
+ "zendframework/zend-stdlib": "~2.7"
+ },
+ "suggest": {
+ "doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features",
+ "zendframework/zend-stdlib": "Zend\\Stdlib component"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev",
+ "dev-develop": "2.7-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Zend\\Code\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "description": "provides facilities to generate arbitrary code using an object oriented interface",
+ "homepage": "https://github.com/zendframework/zend-code",
+ "keywords": [
+ "code",
+ "zf2"
+ ],
+ "time": "2016-01-05 05:58:37"
+ },
+ {
+ "name": "zendframework/zend-eventmanager",
+ "version": "3.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/zendframework/zend-eventmanager.git",
+ "reference": "8c9917f1595ff260f289439bdeb1f46500c65d62"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/zendframework/zend-eventmanager/zipball/8c9917f1595ff260f289439bdeb1f46500c65d62",
+ "reference": "8c9917f1595ff260f289439bdeb1f46500c65d62",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.5 || ^7.0"
+ },
+ "require-dev": {
+ "athletic/athletic": "^0.1",
+ "container-interop/container-interop": "^1.1.0",
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "^2.0",
+ "zendframework/zend-stdlib": "^2.7.3"
+ },
+ "suggest": {
+ "container-interop/container-interop": "^1.1.0, to use the lazy listeners feature",
+ "zendframework/zend-stdlib": "^2.7.3, to use the FilterChain feature"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0-dev",
+ "dev-develop": "3.1-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Zend\\EventManager\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "description": "Trigger and listen to events within a PHP application",
+ "homepage": "https://github.com/zendframework/zend-eventmanager",
+ "keywords": [
+ "event",
+ "eventmanager",
+ "events",
+ "zf2"
+ ],
+ "time": "2016-01-12 23:27:48"
}
],
"packages-dev": [
@@ -1654,70 +2011,41 @@
"time": "2015-06-14 21:17:01"
},
{
- "name": "guzzle/guzzle",
- "version": "v3.9.3",
+ "name": "guzzlehttp/guzzle",
+ "version": "6.1.1",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/guzzle3.git",
- "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
+ "url": "https://github.com/guzzle/guzzle.git",
+ "reference": "c6851d6e48f63b69357cbfa55bca116448140e0c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
- "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/c6851d6e48f63b69357cbfa55bca116448140e0c",
+ "reference": "c6851d6e48f63b69357cbfa55bca116448140e0c",
"shasum": ""
},
"require": {
- "ext-curl": "*",
- "php": ">=5.3.3",
- "symfony/event-dispatcher": "~2.1"
- },
- "replace": {
- "guzzle/batch": "self.version",
- "guzzle/cache": "self.version",
- "guzzle/common": "self.version",
- "guzzle/http": "self.version",
- "guzzle/inflection": "self.version",
- "guzzle/iterator": "self.version",
- "guzzle/log": "self.version",
- "guzzle/parser": "self.version",
- "guzzle/plugin": "self.version",
- "guzzle/plugin-async": "self.version",
- "guzzle/plugin-backoff": "self.version",
- "guzzle/plugin-cache": "self.version",
- "guzzle/plugin-cookie": "self.version",
- "guzzle/plugin-curlauth": "self.version",
- "guzzle/plugin-error-response": "self.version",
- "guzzle/plugin-history": "self.version",
- "guzzle/plugin-log": "self.version",
- "guzzle/plugin-md5": "self.version",
- "guzzle/plugin-mock": "self.version",
- "guzzle/plugin-oauth": "self.version",
- "guzzle/service": "self.version",
- "guzzle/stream": "self.version"
+ "guzzlehttp/promises": "~1.0",
+ "guzzlehttp/psr7": "~1.1",
+ "php": ">=5.5.0"
},
"require-dev": {
- "doctrine/cache": "~1.3",
- "monolog/monolog": "~1.0",
- "phpunit/phpunit": "3.7.*",
- "psr/log": "~1.0",
- "symfony/class-loader": "~2.1",
- "zendframework/zend-cache": "2.*,<2.3",
- "zendframework/zend-log": "2.*,<2.3"
- },
- "suggest": {
- "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
+ "ext-curl": "*",
+ "phpunit/phpunit": "~4.0",
+ "psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.9-dev"
+ "dev-master": "6.1-dev"
}
},
"autoload": {
- "psr-0": {
- "Guzzle": "src/",
- "Guzzle\\Tests": "tests/"
+ "files": [
+ "src/functions_include.php"
+ ],
+ "psr-4": {
+ "GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -1729,13 +2057,9 @@
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
- },
- {
- "name": "Guzzle Community",
- "homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
- "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
+ "description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
@@ -1746,7 +2070,116 @@
"rest",
"web service"
],
- "time": "2015-03-18 18:23:50"
+ "time": "2015-11-23 00:47:50"
+ },
+ {
+ "name": "guzzlehttp/promises",
+ "version": "1.0.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/promises.git",
+ "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea",
+ "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "GuzzleHttp\\Promise\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "Guzzle promises library",
+ "keywords": [
+ "promise"
+ ],
+ "time": "2015-10-15 22:28:00"
+ },
+ {
+ "name": "guzzlehttp/psr7",
+ "version": "1.2.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/psr7.git",
+ "reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5d04bdd2881ac89abde1fb78cc234bce24327bb",
+ "reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0",
+ "psr/http-message": "~1.0"
+ },
+ "provide": {
+ "psr/http-message-implementation": "1.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "GuzzleHttp\\Psr7\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "PSR-7 message implementation",
+ "keywords": [
+ "http",
+ "message",
+ "stream",
+ "uri"
+ ],
+ "time": "2016-01-23 01:23:02"
},
{
"name": "pdepend/pdepend",
@@ -2180,16 +2613,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "4.8.14",
+ "version": "4.8.22",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "b4900675926860bef091644849305399b986efa2"
+ "reference": "dfb11aa5236376b4fc63853cf746af39fe780e72"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b4900675926860bef091644849305399b986efa2",
- "reference": "b4900675926860bef091644849305399b986efa2",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/dfb11aa5236376b4fc63853cf746af39fe780e72",
+ "reference": "dfb11aa5236376b4fc63853cf746af39fe780e72",
"shasum": ""
},
"require": {
@@ -2248,7 +2681,7 @@
"testing",
"xunit"
],
- "time": "2015-10-17 15:03:30"
+ "time": "2016-02-02 09:01:21"
},
{
"name": "phpunit/phpunit-mock-objects",
@@ -2306,58 +2739,95 @@
],
"time": "2015-10-02 06:51:40"
},
+ {
+ "name": "psr/http-message",
+ "version": "1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/http-message.git",
+ "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
+ "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Http\\Message\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for HTTP messages",
+ "keywords": [
+ "http",
+ "http-message",
+ "psr",
+ "psr-7",
+ "request",
+ "response"
+ ],
+ "time": "2015-05-04 20:22:00"
+ },
{
"name": "satooshi/php-coveralls",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/satooshi/php-coveralls.git",
- "reference": "2fbf803803d179ab1082807308a67bbd5a760c70"
+ "reference": "50c60bb64054974f8ed7540ae6e75fd7981a5fd3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/2fbf803803d179ab1082807308a67bbd5a760c70",
- "reference": "2fbf803803d179ab1082807308a67bbd5a760c70",
+ "url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/50c60bb64054974f8ed7540ae6e75fd7981a5fd3",
+ "reference": "50c60bb64054974f8ed7540ae6e75fd7981a5fd3",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-simplexml": "*",
- "guzzle/guzzle": ">=2.7",
- "php": ">=5.3",
- "psr/log": "1.0.0",
- "symfony/config": ">=2.0",
- "symfony/console": ">=2.0",
- "symfony/stopwatch": ">=2.2",
- "symfony/yaml": ">=2.0"
- },
- "require-dev": {
- "apigen/apigen": "2.8.*@stable",
- "pdepend/pdepend": "dev-master as 2.0.0",
- "phpmd/phpmd": "dev-master",
- "phpunit/php-invoker": ">=1.1.0,<1.2.0",
- "phpunit/phpunit": "3.7.*@stable",
- "sebastian/finder-facade": "dev-master",
- "sebastian/phpcpd": "1.4.*@stable",
- "squizlabs/php_codesniffer": "1.4.*@stable",
- "theseer/fdomdocument": "dev-master"
+ "guzzlehttp/guzzle": "^6.0",
+ "php": ">=5.5",
+ "psr/log": "^1.0",
+ "symfony/config": "^2.1|^3.0",
+ "symfony/console": "^2.1|^3.0",
+ "symfony/stopwatch": "^2.0|^3.0",
+ "symfony/yaml": "^2.0|^3.0"
},
"suggest": {
"symfony/http-kernel": "Allows Symfony integration"
},
"bin": [
- "composer/bin/coveralls"
+ "bin/coveralls"
],
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "0.7-dev"
+ "dev-master": "2.0-dev"
}
},
"autoload": {
- "psr-0": {
- "Satooshi\\Component": "src/",
- "Satooshi\\Bundle": "src/"
+ "psr-4": {
+ "Satooshi\\": "src/Satooshi/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -2379,7 +2849,7 @@
"github",
"test"
],
- "time": "2014-11-11 15:35:34"
+ "time": "2016-01-20 17:44:41"
},
{
"name": "sebastian/comparator",
@@ -2447,28 +2917,28 @@
},
{
"name": "sebastian/diff",
- "version": "1.3.0",
+ "version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
- "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3"
+ "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3",
- "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e",
+ "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
- "phpunit/phpunit": "~4.2"
+ "phpunit/phpunit": "~4.8"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.3-dev"
+ "dev-master": "1.4-dev"
}
},
"autoload": {
@@ -2491,24 +2961,24 @@
}
],
"description": "Diff implementation",
- "homepage": "http://www.github.com/sebastianbergmann/diff",
+ "homepage": "https://github.com/sebastianbergmann/diff",
"keywords": [
"diff"
],
- "time": "2015-02-22 15:13:53"
+ "time": "2015-12-08 07:14:41"
},
{
"name": "sebastian/environment",
- "version": "1.3.2",
+ "version": "1.3.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44"
+ "reference": "6e7133793a8e5a5714a551a8324337374be209df"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44",
- "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e7133793a8e5a5714a551a8324337374be209df",
+ "reference": "6e7133793a8e5a5714a551a8324337374be209df",
"shasum": ""
},
"require": {
@@ -2545,7 +3015,7 @@
"environment",
"hhvm"
],
- "time": "2015-08-03 06:14:51"
+ "time": "2015-12-02 08:37:27"
},
{
"name": "sebastian/exporter",
@@ -2756,16 +3226,16 @@
},
{
"name": "sebastian/recursion-context",
- "version": "1.0.1",
+ "version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "994d4a811bafe801fb06dccbee797863ba2792ba"
+ "reference": "913401df809e99e4f47b27cdd781f4a258d58791"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba",
- "reference": "994d4a811bafe801fb06dccbee797863ba2792ba",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791",
+ "reference": "913401df809e99e4f47b27cdd781f4a258d58791",
"shasum": ""
},
"require": {
@@ -2805,7 +3275,7 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
- "time": "2015-06-21 08:04:50"
+ "time": "2015-11-11 19:50:13"
},
{
"name": "sebastian/version",
diff --git a/Symfony/src/Codebender/LibraryBundle/Command/LoadExternalLibraryFilesCommand.php b/Symfony/src/Codebender/LibraryBundle/Command/LoadExternalLibraryFilesCommand.php
index 8b454c99..02a3f6e3 100644
--- a/Symfony/src/Codebender/LibraryBundle/Command/LoadExternalLibraryFilesCommand.php
+++ b/Symfony/src/Codebender/LibraryBundle/Command/LoadExternalLibraryFilesCommand.php
@@ -46,18 +46,20 @@ public function execute(InputInterface $input, OutputInterface $output)
{
/* @var ContainerInterface $container */
$container = $this->getContainer();
- $externalLibrariesPath = $container->getParameter('external_libraries');
- if ($externalLibrariesPath === null || $externalLibrariesPath == '') {
- throw new InvalidConfigurationException('Parameter `external_libraries` is not properly set. Please double check your configuration files.');
+ $path = 'external_libraries_v2';
+ $source = 'library_files_new';
+ $externalLibrariesPath = $container->getParameter($path);
+ if ($externalLibrariesPath === null || $externalLibrariesPath === '') {
+ throw new InvalidConfigurationException('Parameter `' . $path . '` is not properly set. Please double check your configuration files.');
}
- $copyResult = $this->copyExternalLibraryFiles($externalLibrariesPath);
+ $copyResult = $this->copyExternalLibraryFiles($externalLibrariesPath, $source);
if ($copyResult['success'] != true) {
$output->writeln('' . $copyResult['error'] . '');
return;
}
- $output->writeln('Fixture libraries data moved successfully to the `external_libraries` directory.');
+ $output->writeln('Fixture libraries data moved successfully to the `' . $path . '` directory.');
return;
}
@@ -69,10 +71,10 @@ public function execute(InputInterface $input, OutputInterface $output)
* @param $externalLibrariesPath
* @return array
*/
- protected function copyExternalLibraryFiles($externalLibrariesPath)
+ protected function copyExternalLibraryFiles($externalLibrariesPath, $externalLibrariesSource)
{
$fixturesPath = $this->getApplication()->getKernel()
- ->locateResource('@CodebenderLibraryBundle/Resources/library_files');
+ ->locateResource('@CodebenderLibraryBundle/Resources/' . $externalLibrariesSource);
$filesystem = new Filesystem();
diff --git a/Symfony/src/Codebender/LibraryBundle/Controller/ApiController.php b/Symfony/src/Codebender/LibraryBundle/Controller/ApiController.php
new file mode 100644
index 00000000..ea67da1f
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Controller/ApiController.php
@@ -0,0 +1,36 @@
+getRequest();
+ $content = $request->getContent();
+
+ $content = json_decode($content, true);
+ $content['v1'] = false;
+ if ($content === null || !array_key_exists("type", $content)) {
+ return new JsonResponse(['success' => false, 'message' => 'Wrong data']);
+ }
+
+ $commandHandler = $this->get('codebender_library.apiCommandHandler');
+ $service = $commandHandler->getService($content);
+ $output = $service->execute($content);
+
+ return new JsonResponse($output);
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Controller/ApiViewsController.php b/Symfony/src/Codebender/LibraryBundle/Controller/ApiViewsController.php
new file mode 100644
index 00000000..753f335d
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Controller/ApiViewsController.php
@@ -0,0 +1,303 @@
+container->getParameter('authorizationKey');
+ $form = $this->createForm(new NewLibraryFormV2());
+
+ $form->handleRequest($this->getRequest());
+
+ if (!$form->isValid()) {
+ return $this->render('CodebenderLibraryBundle:V2:newLibForm.html.twig', array(
+ 'authorizationKey' => $authorizationKey,
+ 'form' => $form->createView()
+ ));
+ }
+
+ $formData = $form->getData();
+ $newLibraryHandler = $this->get('codebender_library.newLibraryHandler');
+ $libraryAdded = $newLibraryHandler->addLibrary($formData);
+ if ($libraryAdded['success'] !== true) {
+ $flashBag = $this->get('session')->getFlashBag();
+ $flashBag->add('error', 'Error: ' . $libraryAdded['message']);
+ $form = $this->createForm(new NewLibraryFormV2());
+
+ return $this->render('CodebenderLibraryBundle:V2:newLibForm.html.twig', [
+ 'authorizationKey' => $authorizationKey,
+ 'form' => $form->createView()
+ ]);
+ }
+
+ return $this->redirect(
+ $this->generateUrl(
+ 'codebender_library_view_library_v2',
+ ['authorizationKey' => $authorizationKey, 'library' => $formData['DefaultHeader'], 'disabled' => 1]
+ )
+ );
+ }
+
+ public function viewLibraryAction()
+ {
+ $request = $this->getRequest();
+ $library = $request->get('library');
+ $version = $request->get('version');
+ $disabled = $request->get('disabled') === "1";
+
+ $apiFetchCommand = $this->get('codebender_api.fetch');
+ $requestData = [
+ 'type'=>'fetch',
+ 'library' => $library,
+ 'disabled' => $disabled,
+ 'version' => $version,
+ 'renderView' => 'true'
+ ];
+ $response = $apiFetchCommand->execute($requestData);
+
+ if ($response['success'] !== true) {
+ return new JsonResponse($response);
+ }
+
+ $inSync = false;
+ if (!empty($response['meta'])) {
+ $apiHandler = $this->get('codebender_library.apiHandler');
+ $inSync = $apiHandler->isLibraryInSyncWithGit(
+ $response['meta']['gitOwner'],
+ $response['meta']['gitRepo'],
+ $response['meta']['gitBranch'],
+ $response['meta']['gitInRepoPath'],
+ $response['meta']['gitLastCommit']
+ );
+ }
+
+ return $this->render('CodebenderLibraryBundle:V2:libraryView.html.twig', array(
+ 'library' => $response['library'],
+ 'versions' => $response['versions'],
+ 'files' => $response['files'],
+ 'examples' => $response['examples'],
+ 'meta' => $response['meta'],
+ 'inSyncWithGit' => $inSync
+ ));
+ }
+
+ public function gitUpdatesAction()
+ {
+ $checkGithubUpdatesCommand = $this->get('codebender_api.checkGithubUpdates');
+
+ $handlerResponse = $checkGithubUpdatesCommand->execute();
+
+ if ($handlerResponse['success'] !== true) {
+ return new JsonResponse(['success' => false, 'message' => 'Invalid authorization key.']);
+ }
+
+ //TODO: create the twig and render it on return
+ return new JsonResponse($handlerResponse);
+ }
+
+ public function searchAction()
+ {
+ $request = $this->getRequest();
+ $query = $request->query->get('q');
+ $json = $request->query->get('json');
+ $names = array();
+
+ if ($query !== null && $query != "") {
+ $em = $this->getDoctrine()->getManager();
+ $repository = $em->getRepository('CodebenderLibraryBundle:Library');
+ $libraries = $repository->createQueryBuilder('p')->where('p.default_header LIKE :token')
+ ->setParameter('token', "%" . $query . "%")->getQuery()->getResult();
+
+
+ foreach ($libraries as $lib) {
+ if ($lib->getActive()) {
+ $names[] = $lib->getDefaultHeader();
+ }
+ }
+ }
+ if ($json !== null && $json === "true") {
+ return new JsonResponse(['success' => true, 'libs' => $names]);
+ }
+ return $this->render(
+ 'CodebenderLibraryBundle:V2:search.html.twig',
+ ['authorizationKey' => $this->container->getParameter('authorizationKey'), 'libs' => $names]
+ );
+ }
+
+ public function changeLibraryStatusAction($library)
+ {
+ if ($this->getRequest()->getMethod() != 'POST') {
+ return new JsonResponse(['success' => false, 'message' => 'POST method required']);
+ }
+
+ $apiHandler = $this->get('codebender_library.apiHandler');
+ $exists = $apiHandler->isExternalLibrary($library, true);
+
+ if (!$exists) {
+ return new JsonResponse(['success' => false, 'message' => 'Library not found.']);
+ }
+
+ $apiHandler->toggleLibraryStatus($library);
+
+ return new JsonResponse(['success' => true]);
+ }
+
+ /**
+ * Try get the library meta from the system
+ *
+ * @param $library
+ * @return JsonResponse
+ */
+ public function getLibraryMetaAction($library) {
+ if ($this->getRequest()->getMethod() != 'POST') {
+ return new JsonResponse(['success' => false, 'message' => 'POST method required']);
+ }
+
+ $apiHandler = $this->get('codebender_library.apiHandler');
+ $exists = $apiHandler->isExternalLibrary($library, true);
+
+ if (!$exists) {
+ return new JsonResponse(['success' => false, 'message' => 'Library not found.']);
+ }
+
+ $lib = $apiHandler->getLibraryFromDefaultHeader($library);
+
+ return new JsonResponse(['success' => true, 'meta' => $lib->getLibraryMeta()]);
+ }
+
+ public function getLibraryGitInfoAction()
+ {
+ if ($this->getRequest()->getMethod() != 'POST') {
+ return new JsonResponse(['success' => false, 'message' => 'POST method required']);
+ }
+
+ $handler = $this->get('codebender_library.apiHandler');
+
+ $githubUrl = $this->getRequest()->request->get('githubUrl');
+ $processedGitUrl = $handler->processGithubUrl($githubUrl);
+
+ if ($processedGitUrl['success'] !== true) {
+ return new JsonResponse(['success' => false, 'message' => 'Could not process provided url']);
+ }
+
+ $repoBranches = $handler->fetchRepoRefsFromGit($processedGitUrl['owner'], $processedGitUrl['repo']);
+ $repoReleases = $handler->fetchRepoReleasesFromGit($processedGitUrl['owner'], $processedGitUrl['repo']);
+
+ if ($repoBranches['success'] !== true || $repoReleases['success'] !== true) {
+ return new JsonResponse([
+ 'success' => false,
+ 'message' => 'Something went wrong while fetching the library. Please double check the Url you provided.'
+ ]);
+ }
+
+ return new JsonResponse(['success' => true, 'branches' => $repoBranches['headRefs'], 'releases' => $repoReleases['releases']]);
+ }
+
+ public function getRepoGitTreeAndMetaAction()
+ {
+ $handler = $this->get('codebender_library.apiHandler');
+
+ $githubUrl = $this->getRequest()->request->get('githubUrl');
+ $processedGitUrl = $handler->processGithubUrl($githubUrl);
+ $gitRef = $this->getRequest()->request->get('gitRef');
+
+ if ($processedGitUrl['success'] !== true) {
+ return new JsonResponse(['success' => false, 'message' => 'Could not process provided url']);
+ }
+
+ $githubLibrary = json_decode(
+ $handler->getRepoTreeStructure(
+ $processedGitUrl['owner'],
+ $processedGitUrl['repo'],
+ $gitRef,
+ $processedGitUrl['folder']
+ ),
+ true
+ );
+
+ if (!$githubLibrary['success']) {
+ return new JsonResponse($githubLibrary);
+ }
+
+ $description = $handler->getRepoDefaultDescription($processedGitUrl['owner'], $processedGitUrl['repo']);
+
+ return new JsonResponse([
+ 'success' => true,
+ 'files' => $githubLibrary['files'],
+ 'owner' => $processedGitUrl['owner'],
+ 'repo' => $processedGitUrl['repo'],
+ 'ref' => $gitRef,
+ 'description' => $description
+ ]);
+ }
+
+ public function downloadAction($defaultHeaderFile, $version)
+ {
+ $htmlcode = 200;
+ $finder = new Finder();
+ $exampleFinder = new Finder();
+
+ $apiHandler = $this->get('codebender_library.apiHandler');
+ $isValidLibrary = $apiHandler->libraryVersionExists($defaultHeaderFile, $version, true);
+
+ if (!$isValidLibrary) {
+ $value = "";
+ $htmlcode = 404;
+ return new Response($value, $htmlcode);
+ }
+
+ $path = $apiHandler->getExternalLibraryPath($defaultHeaderFile, $version);
+
+ $files = $apiHandler->fetchLibraryFiles($finder, $path, false);
+ $examples = $apiHandler->fetchLibraryExamples($exampleFinder, $path);
+
+ $zipname = "/tmp/asd.zip";
+
+ $zip = new ZipArchive();
+
+ if ($zip->open($zipname, ZIPARCHIVE::CREATE) === false) {
+ $value = "";
+ $htmlcode = 404;
+ } else {
+ if ($zip->addEmptyDir($defaultHeaderFile) !== true) {
+ $value = "";
+ $htmlcode = 404;
+ } else {
+ foreach ($files as $file) {
+ // No special handling needed for binary files, since addFromString method is binary safe.
+ $zip->addFromString($defaultHeaderFile . '/' . $file['filename'], file_get_contents($path . '/' . $file['filename']));
+ }
+ foreach ($examples as $file) {
+ $zip->addFromString($defaultHeaderFile . "/" . $file["filename"], $file["content"]);
+ }
+ $zip->close();
+ $value = file_get_contents($zipname);
+ }
+ unlink($zipname);
+ }
+
+ $headers = array('Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment;filename="' . $defaultHeaderFile . '.zip"');
+
+ return new Response($value, $htmlcode, $headers);
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Controller/DefaultController.php b/Symfony/src/Codebender/LibraryBundle/Controller/DefaultController.php
index b57f85dc..04ab763a 100644
--- a/Symfony/src/Codebender/LibraryBundle/Controller/DefaultController.php
+++ b/Symfony/src/Codebender/LibraryBundle/Controller/DefaultController.php
@@ -2,13 +2,9 @@
namespace Codebender\LibraryBundle\Controller;
-use Codebender\LibraryBundle\Entity\Example;
-use Codebender\LibraryBundle\Entity\ExternalLibrary;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
-use Doctrine\ORM\EntityManager;
class DefaultController extends Controller
{
@@ -27,7 +23,6 @@ public function statusAction()
* Checks the autorization credentials and the validity of the request.
* Can handle several types of requests, like code fetching, examples fetching, etc.
*
- * TODO: need to refactor how this work, JsonResponse objects are returned from all over the place inconsistently
* @param $version
* @return JsonResponse
*/
@@ -45,564 +40,12 @@ public function apiHandlerAction($version)
return new JsonResponse(['success' => false, 'message' => 'Wrong data']);
}
- if ($this->isValid($content) === false) {
- return new JsonResponse(['success' => false, 'message' => 'Incorrect request fields']);
- }
-
- return new JsonResponse($this->selectAction($content));
- }
-
- /**
- * Decides which operation should be excuted based on the `type` parameter of
- * the request. Returns an array with the results.
- *
- * @param $content
- * @return array
- */
- private function selectAction($content)
- {
- switch ($content["type"]) {
- case "list":
- return $this->listAll();
- case "getExampleCode":
- return $this->getExampleCode($content["library"], $content["example"]);
- case "getExamples":
- return $this->getLibraryExamples($content["library"]);
- case "fetch":
- $handler = $this->get('codebender_library.handler');
- return $handler->getLibraryCode($content["library"], 0);
- case "checkGithubUpdates":
- $handler = $this->get('codebender_library.handler');
- return $handler->checkGithubUpdates();
- case "getKeywords":
- return $this->getKeywords($content["library"]);
- case 'deleteLibrary':
- return $this->deleteLibrary($content['library']);
- default:
- return ['success' => false, 'message' => 'No valid action requested'];
- }
- }
-
- private function isValid($requestContent)
- {
- if (!array_key_exists('type', $requestContent)) {
- return false;
- }
-
- if (in_array($requestContent['type'], ['getExampleCode', 'getExamples', 'fetch', 'getKeywords', 'deleteLibrary'])
- && !array_key_exists('library', $requestContent)) {
- return false;
- }
-
- if ($requestContent['type'] == 'getExampleCode' && !array_key_exists('example', $requestContent)) {
- return false;
- }
-
- return true;
- }
-
- private function listAll()
- {
-
- $arduinoLibraryFiles = $this->container->getParameter('builtin_libraries') . "/";
-
- $builtinExamples = $this->getLibariesListFromDir($arduinoLibraryFiles . "examples");
- $includedLibraries = $this->getLibariesListFromDir($arduinoLibraryFiles . "libraries");
- /*
- * External libraries list is fetched from the database, because we need to list
- * active libraries only
- */
- $externalLibraries = $this->getExternalLibrariesList();
-
- ksort($builtinExamples);
- ksort($includedLibraries);
- ksort($externalLibraries);
-
- return [
- 'success' => true,
- 'text' => 'Successful Request!',
- 'categories' => [
- 'Examples' => $builtinExamples,
- 'Builtin Libraries' => $includedLibraries,
- 'External Libraries' => $externalLibraries
- ]
- ];
- }
-
- /**
- * @param $library
- * @param $example
- * @return mixed|string
- */
- private function getExampleCode($library, $example)
- {
-
- $type = $this->getLibraryType($library);
- if ($type['success'] !== true) {
- return $type;
- }
-
- switch ($type['type']) {
- case 'builtin':
- $dir = $this->container->getParameter('builtin_libraries') . "/libraries/";
- $example = $this->getExampleCodeFromDir($dir, $library, $example);
- break;
- case 'external':
- $example = $this->getExternalExampleCode($library, $example);
- break;
- case 'example':
- $dir = $this->container->getParameter('builtin_libraries') . "/examples/";
- $example = $this->getExampleCodeFromDir($dir, $library, $example);
- break;
- }
-
- return $example;
- }
-
- public function getLibraryGitBranchesAction()
- {
- $handler = $this->get('codebender_library.handler');
-
- $githubUrl = $this->getRequest()->request->get('githubUrl');
- $processedGitUrl = $handler->processGithubUrl($githubUrl);
-
- if ($processedGitUrl['success'] !== true) {
- return new JsonResponse(['success' => false, 'message' => 'Could not process provided url']);
- }
-
- $repoBranches = $handler->fetchRepoRefsFromGit($processedGitUrl['owner'], $processedGitUrl['repo']);
-
- if ($repoBranches['success'] !== true) {
- return new JsonResponse([
- 'success' => false,
- 'message' => 'Something went wrong while fetching the library. Please double check the Url you provided.'
- ]);
- }
-
- return new JsonResponse(['success' => true, 'branches' => $repoBranches['headRefs']]);
- }
-
- public function getRepoGitTreeAndMetaAction()
- {
- $handler = $this->get('codebender_library.handler');
-
- $githubUrl = $this->getRequest()->request->get('githubUrl');
- $processedGitUrl = $handler->processGithubUrl($githubUrl);
- $gitBranch = $this->getRequest()->request->get('githubBranch');
-
- if ($processedGitUrl['success'] !== true) {
- return new JsonResponse(['success' => false, 'message' => 'Could not process provided url']);
- }
-
- $githubLibrary = json_decode(
- $handler->getRepoTreeStructure(
- $processedGitUrl['owner'],
- $processedGitUrl['repo'],
- $gitBranch,
- $processedGitUrl['folder']
- )
- , true
- );
-
- if (!$githubLibrary['success']) {
- return new JsonResponse($githubLibrary);
- }
-
- $description = $handler->getRepoDefaultDescription($processedGitUrl['owner'], $processedGitUrl['repo']);
-
- return new JsonResponse([
- 'success' => true,
- 'files' => $githubLibrary['files'],
- 'owner' => $processedGitUrl['owner'],
- 'repo' => $processedGitUrl['repo'],
- 'branch' => $gitBranch,
- 'description' => $description
- ]);
- }
-
- /**
- * Deletes a library based on the provided.
- *
- * @param string $machineName
- * @return array
- */
- public function deleteLibrary($machineName)
- {
- $exists = $this->getLibraryType($machineName, true);
- if ($exists['success'] !== true) {
- return ['success' => false, 'error' => $exists['message']];
- }
- if ($exists['type'] != 'external') {
- return ['success' => false, 'error' => 'Library ' . $machineName . ' is not an external library.'];
- }
- $storagePath = $this->container->getParameter('external_libraries') . '/' . $machineName;
- if (!file_exists($storagePath)) {
- return ['success' => false, 'error' => 'Library ' . $machineName . ' does not exist in filesystem.'];
- }
-
- $this->removeLibraryExamplesEntities($machineName);
- $this->removeLibraryEntity($machineName);
-
- /* @var \Codebender\LibraryBundle\Handler\DefaultHandler $handler */
- $handler = $this->get('codebender_library.handler');
-
- $handler->removeDirectory($storagePath);
-
- return ['success' => true, 'message' => 'Library ' . $machineName . ' deleted successfully.'];
- }
-
- private function removeLibraryEntity($machineName)
- {
- /* @var EntityManager $entityManager */
- $entityManager = $this->container->get('doctrine')->getManager();
-
- /* @var ExternalLibrary $libraryEntity */
- $libraryEntity = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')
- ->findOneBy(['machineName' => $machineName]);
-
- $entityManager->remove($libraryEntity);
- $entityManager->flush();
- }
-
- private function removeLibraryExamplesEntities($machineName)
- {
- /* @var EntityManager $entityManager */
- $entityManager = $this->container->get('doctrine')->getManager();
-
- /* @var ExternalLibrary $libraryEntity */
- $libraryEntity = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')
- ->findOneBy(['machineName' => $machineName]);
-
- $libraryExamples = $entityManager->getRepository('CodebenderLibraryBundle:Example')
- ->findBy(['library' => $libraryEntity->getId()]);
- foreach ($libraryExamples as $example) {
- /* @var Example $example */
- $entityManager->remove($example);
- }
- $entityManager->flush();
- }
-
- private function getLibraryExamples($library)
- {
- $exists = $this->getLibraryType($library);
- if ($exists['success'] !== true) {
- return $exists;
- }
- $examples = array();
- $path = "";
- /*
- * Assume the requested library is an example
- */
- $path = $this->container->getParameter('builtin_libraries') . "/examples/" . $library;
- if ($exists['type'] == 'external') {
- $path = $this->container->getParameter('external_libraries') . '/' . $library;
- }
- if ($exists['type'] == 'builtin') {
- $path = $this->container->getParameter('builtin_libraries') . "/libraries/" . $library;
- }
- $inoFinder = new Finder();
- $inoFinder->in($path);
- $inoFinder->name('*.ino')->name('*.pde');
-
- foreach ($inoFinder as $example) {
- $files = array();
-
- $content = (!mb_check_encoding($example->getContents(), 'UTF-8')) ? mb_convert_encoding($example->getContents(), "UTF-8") : $example->getContents();
- $pathInfo = pathinfo($example->getBaseName());
- $files[] = array("filename" => $pathInfo['filename'] . '.ino', "content" => (!mb_check_encoding($content, 'UTF-8')) ? mb_convert_encoding($content, "UTF-8") : $content);
-
- // TODO: Not only .h and .cpp files in Arduino examples
- $notInoFilesFinder = new Finder();
- $notInoFilesFinder->files()->name('*.h')->name('*.cpp');
- $notInoFilesFinder->in($path . "/" . $example->getRelativePath());
-
- foreach ($notInoFilesFinder as $nonInoFile) {
- $files[] = array(
- "filename" => $nonInoFile->getBaseName(),
- "content" =>
- (!mb_check_encoding($nonInoFile->getContents(), 'UTF-8')) ? mb_convert_encoding($nonInoFile->getContents(), "UTF-8") : $nonInoFile->getContents()
- );
- }
-
- $dir = preg_replace('/[E|e]xamples\//', '', $example->getRelativePath());
- $dir = str_replace($pathInfo['filename'], '', $dir);
- $dir = str_replace('/', ':', $dir);
- if ($dir != '' && substr($dir, -1) != ':') {
- $dir .= ':';
- }
+ $content['v1'] = true;
+ $commandHandler = $this->get('codebender_library.apiCommandHandler');
+ $service = $commandHandler->getService($content);
+ $output = $service->execute($content);
- $examples[$dir . $pathInfo['filename']] = $files;
- }
- return ['success' => true, 'examples' => $examples];
- }
-
- private function getLibraryType($library, $checkDisabledToo = false)
- {
- $handler = $this->get('codebender_library.handler');
-
- /*
- * Each library's type can be either external () ..
- */
- $isExternal = json_decode($handler->checkIfExternalExists($library, $checkDisabledToo), true);
- if ($isExternal['success']) {
- return ['success' => true, 'type' => 'external'];
- }
-
- /*
- * .. or builtin (SD, Ethernet, etc) ...
- */
- $isBuiltIn = json_decode($handler->checkIfBuiltInExists($library), true);
- if ($isBuiltIn['success']) {
- return ['success' => true, 'type' => 'builtin'];
- }
-
- /*
- * .. or example (01.Basics, etc)
- */
- $isExample = json_decode($this->checkIfBuiltInExampleFolderExists($library), true);
- if ($isExample['success']) {
- return ['success' => true, 'type' => 'example'];
- }
-
- // Library was not found, return proper message
- return ['success' => false, 'message' => 'Library named ' . $library . ' not found.'];
- }
-
- private function getExternalExampleCode($library, $example)
- {
- $entityManager = $this->getDoctrine()->getManager();
- $libMeta = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findBy(array('machineName' => $library));
-
- $exampleMeta = $entityManager->getRepository('CodebenderLibraryBundle:Example')->findBy(array('library' => $libMeta[0], 'name' => $example));
- if (count($exampleMeta) == 0) {
- $example = str_replace(":", "/", $example);
- $filename = pathinfo($example, PATHINFO_FILENAME);
- $exampleMeta = $entityManager->getRepository('CodebenderLibraryBundle:Example')->findBy(array('library' => $libMeta[0], 'name' => $filename));
- if (count($exampleMeta) > 1) {
- $meta = null;
- foreach ($exampleMeta as $e) {
- $path = $e->getPath();
- if (!(strpos($path, $example) === false)) {
- $meta = $e;
- break;
- }
- }
- if (!$meta) {
- return ['success' => false];
- }
- } else if (count($exampleMeta) == 0) {
- return ['success' => false];
- } else {
- $meta = $exampleMeta[0];
- }
- } else {
- $meta = $exampleMeta[0];
- }
- $fullPath = $this->container->getParameter('external_libraries') . '/' . $meta->getPath();
-
- $path = pathinfo($fullPath, PATHINFO_DIRNAME);
- $files = $this->getExampleFilesFromDir($path);
- return $files;
-
- }
-
- private function getExampleCodeFromDir($dir, $library, $example)
- {
- $finder = new Finder();
- $finder->in($dir . $library);
- $finder->name($example . ".ino", $example . ".pde");
-
- if (iterator_count($finder) == 0) {
- $example = str_replace(":", "/", $example);
- $filename = pathinfo($example, PATHINFO_FILENAME);
- $finder->name($filename . ".ino", $filename . ".pde");
- if (iterator_count($finder) > 1) {
- $filesPath = null;
- foreach ($finder as $e) {
- $path = $e->getPath();
- if (!(strpos($path, $example) === false)) {
- $filesPath = $e;
- break;
- }
- }
- if (!$filesPath) {
- return ['success' => false];
- }
- } else if (iterator_count($finder) == 0) {
- return ['success' => false];
- } else {
- $filesPathIterator = iterator_to_array($finder, false);
- $filesPath = $filesPathIterator[0]->getPath();
- }
- } else {
-
- $filesPathIterator = iterator_to_array($finder, false);
- $filesPath = $filesPathIterator[0]->getPath();
- }
- $files = $this->getExampleFilesFromDir($filesPath);
- return $files;
- }
-
- private function getExampleFilesFromDir($dir)
- {
- $filesFinder = new Finder();
- $filesFinder->in($dir);
- $filesFinder->name('*.cpp')->name('*.h')->name('*.c')->name('*.S')->name('*.pde')->name('*.ino');
-
- $files = array();
- foreach ($filesFinder as $file) {
- if ($file->getExtension() == "pde")
- $name = $file->getBasename("pde") . "ino";
- else
- $name = $file->getFilename();
-
- $files[] = array("filename" => $name, "code" => (!mb_check_encoding($file->getContents(), 'UTF-8')) ? mb_convert_encoding($file->getContents(), "UTF-8") : $file->getContents());
-
- }
-
- return ['success' => true, "files" => $files];
+ return new JsonResponse($output);
}
-
- private function checkIfBuiltInExampleFolderExists($library)
- {
- $arduinoLibraryFiles = $this->container->getParameter('builtin_libraries') . "/";
- if (is_dir($arduinoLibraryFiles . "/examples/" . $library)) {
- return json_encode(array("success" => true, "message" => "Library found"));
- }
-
- return json_encode(array("success" => false, "message" => "No Library named " . $library . " found."));
- }
-
- private function getExternalLibrariesList()
- {
- $entityManager = $this->getDoctrine()->getManager();
- $externalMeta = $entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findBy(array('active' => true));
-
- $libraries = array();
- foreach ($externalMeta as $library) {
- $libraryMachineName = $library->getMachineName();
- if (!isset($libraries[$libraryMachineName])) {
- $libraries[$libraryMachineName] = array("description" => $library->getDescription(), "humanName" => $library->getHumanName(), "examples" => array());
-
- if ($library->getOwner() !== null && $library->getRepo() !== null) {
- $libraries[$libraryMachineName] = array("description" => $library->getDescription(), "humanName" => $library->getHumanName(), "url" => "http://github.com/" . $library->getOwner() . "/" . $library->getRepo(), "examples" => array());
- }
- }
-
- $examples = $entityManager->getRepository('CodebenderLibraryBundle:Example')->findBy(array('library' => $library));
-
- foreach ($examples as $example) {
- $names = $this->getExampleAndLibNameFromRelativePath(pathinfo($example->getPath(), PATHINFO_DIRNAME), $example->getName());
-
- $libraries[$libraryMachineName]['examples'][] = array('name' => $names['example_name']);
- }
-
-
- }
-
- return $libraries;
- }
-
- private function getLibariesListFromDir($path)
- {
-
- $finder = new Finder();
- $finder->files()->name('*.ino')->name('*.pde');
- $finder->in($path);
-
- $libraries = array();
-
- foreach ($finder as $file) {
- $names = $this->getExampleAndLibNameFromRelativePath($file->getRelativePath(), $file->getBasename("." . $file->getExtension()));
-
- if (!isset($libraries[$names['library_name']])) {
- $libraries[$names['library_name']] = array("description" => "", "examples" => array());
- }
- $libraries[$names['library_name']]['examples'][] = array('name' => $names['example_name']);
- }
- return $libraries;
- }
-
- private function getExampleAndLibNameFromRelativePath($path, $filename)
- {
- $type = "";
- $libraryName = strtok($path, "/");
-
- $tmp = strtok("/");
-
- while ($tmp != "" && !($tmp === false)) {
- if ($tmp != 'examples' && $tmp != 'Examples' && $tmp != $filename) {
- if ($type == "")
- $type = $tmp;
- else
- $type = $type . ":" . $tmp;
- }
- $tmp = strtok("/");
-
-
- }
- $exampleName = ($type == "" ? $filename : $type . ":" . $filename);
- return (array('library_name' => $libraryName, 'example_name' => $exampleName));
- }
-
- private function getKeywords($library)
- {
- if ($library === null) {
- return ['success' => false];
- }
-
- $exists = $this->getLibraryType($library);
-
- if ($exists['success'] !== true) {
- return $exists;
- }
-
- if ($exists['type'] == 'external') {
- $path = $this->container->getParameter('external_libraries') . '/' . $library;
- } else if ($exists['type'] = 'builtin') {
- $path = $this->container->getParameter('builtin_libraries') . "/libraries/" . $library;
- } else {
- return ['success' => false];
- }
-
- $keywords = array();
-
- $finder = new Finder();
- $finder->in($path);
- $finder->name('/keywords\.txt/i');
-
- foreach ($finder as $file) {
- $content = (!mb_check_encoding($file->getContents(), 'UTF-8')) ? mb_convert_encoding($file->getContents(), "UTF-8") : $file->getContents();
-
- $lines = preg_split('/\r\n|\r|\n/', $content);
-
- foreach ($lines as $rawline) {
-
- $line = trim($rawline);
- $parts = preg_split('/\s+/', $line);
-
- $totalParts = count($parts);
-
- if (($totalParts == 2) || ($totalParts == 3)) {
-
- if ((substr($parts[1], 0, 7) == "KEYWORD")) {
- $keywords[$parts[1]][] = $parts[0];
- }
-
- if ((substr($parts[1], 0, 7) == "LITERAL")) {
- $keywords["KEYWORD3"][] = $parts[0];
- }
-
- }
-
- }
-
- break;
- }
-
- return ['success' => true, 'keywords' => $keywords];
-
- }
-
}
diff --git a/Symfony/src/Codebender/LibraryBundle/Controller/ViewsController.php b/Symfony/src/Codebender/LibraryBundle/Controller/ViewsController.php
deleted file mode 100644
index 1af77ac3..00000000
--- a/Symfony/src/Codebender/LibraryBundle/Controller/ViewsController.php
+++ /dev/null
@@ -1,529 +0,0 @@
-container->getParameter('authorizationKey');
- $form = $this->createForm(new NewLibraryForm());
-
- $form->handleRequest($this->getRequest());
-
- if (!$form->isValid()) {
- return $this->render('CodebenderLibraryBundle:Default:newLibForm.html.twig', array(
- 'authorizationKey' => $authorizationKey,
- 'form' => $form->createView()
- ));
- }
- $formData = $form->getData();
-
- $libraryAdded = $this->addLibrary($formData);
- if ($libraryAdded['success'] !== true){
- $flashBag = $this->get('session')->getFlashBag();
- $flashBag->add('error', 'Error: ' . $libraryAdded['message']);
- $form = $this->createForm(new NewLibraryForm());
-
- return $this->render('CodebenderLibraryBundle:Default:newLibForm.html.twig', [
- 'authorizationKey' => $authorizationKey,
- 'form' => $form->createView()
- ]);
- }
-
- return $this->redirect($this->generateUrl('codebender_library_view_library',
- ['authorizationKey' => $authorizationKey, 'library' => $formData['MachineName'], 'disabled' => 1]));
- }
-
- /**
- * Performs the actual addition of an external library, as well as
- * input validation of the provided form data.
- *
- * @param array $data The data of the received form
- * @return array
- */
- private function addLibrary($data)
- {
- /*
- * Check whether the right combination of data was provided,
- * and figure out the type of library addition, that is a zip archive (zip)
- * or a Github repository (git)
- */
- $uploadType = $this->validateFormData($data);
- if ($uploadType['success'] != true) {
- return array('success' => false, 'message' => 'Invalid form. Please try again.');
- }
-
- /*
- * Then get the files of the library (either from extracting the zip,
- * or fetching them from Githib) and proceed
- */
- $handler = $this->get('codebender_library.handler');
- $path = '';
- $lastCommit = null;
- switch ($uploadType['type']) {
- case 'git':
- $path = $this->getInRepoPath($data["GitRepo"], $data['GitPath']);
- $libraryStructure = $handler->getGithubRepoCode($data["GitOwner"], $data["GitRepo"], $data['GitBranch'], $path);
- $lastCommit = $handler->getLastCommitFromGithub($data['GitOwner'], $data['GitRepo'], $data['GitBranch'], $path);
- break;
- case 'zip':
- $libraryStructure = $this->getLibFromZipFile($data["Zip"]);
- break;
- }
-
- if ($libraryStructure['success'] !== true) {
- return array('success' => false, 'message' => $libraryStructure['message']);
- }
-
- /*
- * In both ways of fething, the code of the library is found
- * under the 'library' key of the response, upon success.
- */
- $libraryStructure = $libraryStructure['library'];
-
- if ($uploadType['type'] == 'git') {
- $libraryStructure = $this->fixGitPaths($libraryStructure, $libraryStructure['name'], '');
- }
-
- /*
- * Save the library, that is write the files to the disk and
- * create the new ExternalLibrary Entity that represents the uploaded library.
- * Remember onnly external libraries are uploaded through this process
- */
- $creationResponse = json_decode(
- $this->saveNewLibrary($data['HumanName'], $data['MachineName'],
- $data['GitOwner'], $data['GitRepo'], $data['Description'],
- $lastCommit, $data['Url'], $data['GitBranch'], $data['SourceUrl'], $data['Notes'], $path, $libraryStructure)
- , true);
- if ($creationResponse['success'] != true) {
- return array('success' => false, 'message' => $creationResponse['message']);
- }
-
- return array('success' => true);
- }
-
- /**
- * Makes sure the received form does not contain Github data and
- * a zip archive at once. In such a case, the form is considered invalid.
- *
- * @param array $data The form data array
- * @return array
- */
- private function validateFormData($data)
- {
- if (($data['GitOwner'] === null && $data['GitRepo'] === null && $data['GitBranch'] === null && $data['GitPath'] === null) && is_object($data['Zip'])) {
- return array('success' => true, 'type' => 'zip');
- }
- if (($data['GitOwner'] !== null && $data['GitRepo'] !== null && $data['GitBranch'] !== null && $data['GitPath'] !== null) && $data['Zip'] === null) {
- return array('success' => true, 'type' => 'git');
- }
-
- return array('success' => false);
- }
-
- /**
- * Determines whether the basepath is exactly the same or is the
- * root directory of a provided path. Returns an empty string if the
- * two paths are equal or strips the basepath from the path, if
- * the first is a substring of the latter.
- *
- * @param string $basePath The name of the repo
- * @param string $path The provided path
- * @return string
- */
- private function getInRepoPath($basePath, $path)
- {
- if ($path == $basePath) {
- return '';
- }
-
- if (preg_match("/^$basePath\//", $path)) {
- return preg_replace("/^$basePath\//", '', $path);
- }
-
- return $path;
- }
-
- /**
- * The zip upload implementation, creates an assoc array in which the filenames of each file
- * include the absolute path to the file under the library root directory. This option is not available
- * when fetching libraries from Git, since filenames contain no paths. This function is called
- * recursively, and figures out the absolute path for each of the files of the provided file structure,
- * making the git assoc array compatible to the zip assoc array.
- *
- * @param $files
- * @param $root
- * @param $parentPath
- * @return mixed
- */
- private function fixGitPaths($files, $root, $parentPath)
- {
- if ($parentPath != '' && $parentPath != $root) {
- $files['name'] = $parentPath . '/' . $files['name'];
- }
- $parentPath = $files['name'];
- foreach ($files['contents'] as &$element) {
- if ($element['type'] == 'dir') {
- $element = $this->fixGitPaths($element, $root, $parentPath);
- }
- }
- return $files;
- }
-
- public function viewLibraryAction()
- {
- $handler = $this->get('codebender_library.handler');
-
- $request = $this->getRequest();
- $library = $request->get('library');
- $disabled = $request->get('disabled');
- if ($disabled != 1)
- $disabled = 0;
- else
- $disabled = 1;
-
- $response = $handler->getLibraryCode($library, $disabled, true);
-
- if ($response['success'] !== true) {
- return new JsonResponse($response);
- }
-
- $inSync = false;
- if (!empty($response['meta'])) {
- $inSync = $handler->isLibraryInSyncWithGit(
- $response['meta']['gitOwner'],
- $response['meta']['gitRepo'],
- $response['meta']['gitBranch'],
- $response['meta']['gitInRepoPath'],
- $response['meta']['gitLastCommit']
- );
- }
-
- return $this->render('CodebenderLibraryBundle:Default:libraryView.html.twig', array(
- 'library' => $response['library'],
- 'files' => $response['files'],
- 'examples' => $response['examples'],
- 'meta' => $response['meta'],
- 'inSyncWithGit' => $inSync
- ));
- }
-
- public function gitUpdatesAction()
- {
- $handler = $this->get('codebender_library.handler');
-
- $handlerResponse = $handler->checkGithubUpdates();
-
- if ($handlerResponse['success'] !== true) {
- return new JsonResponse(['success' => false, 'message' => 'Invalid authorization key.']);
- }
-
- //TODO: create the twig and render it on return
- return new JsonResponse($handlerResponse);
- }
-
- public function searchAction()
- {
- $request = $this->getRequest();
- $query = $request->query->get('q');
- $json = $request->query->get('json');
- $names = array();
-
- if ($query !== null && $query != "") {
- $em = $this->getDoctrine()->getManager();
- $repository = $em->getRepository('CodebenderLibraryBundle:ExternalLibrary');
- $libraries = $repository->createQueryBuilder('p')->where('p.machineName LIKE :token')
- ->setParameter('token', "%" . $query . "%")->getQuery()->getResult();
-
-
- foreach ($libraries as $lib) {
- if ($lib->getActive())
- $names[] = $lib->getMachineName();
- }
- }
- if ($json !== null && $json = true) {
- return new JsonResponse(['success' => true, 'libs' => $names]);
- }
- return $this->render('CodebenderLibraryBundle:Default:search.html.twig',
- ['authorizationKey' => $this->container->getParameter('authorizationKey'), 'libs' => $names]);
- }
-
- public function changeLibraryStatusAction($library)
- {
- if ($this->getRequest()->getMethod() != 'POST') {
- return new JsonResponse(['success' => false, 'message' => 'POST method required']);
- }
-
- $handler = $this->get('codebender_library.handler');
- $exists = json_decode($handler->checkIfExternalExists($library, true), true);
-
- if ($exists['success'] === false) {
- return new JsonResponse(['success' => false, 'message' => 'Library not found.']);
- }
-
- $em = $this->getDoctrine()->getManager();
- $lib = $em->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findBy(array('machineName' => $library));
- if ($lib[0]->getActive())
- $lib[0]->setActive(0);
- else
- $lib[0]->setActive(1);
- $em->persist($lib[0]);
- $em->flush();
-
- return new JsonResponse(['success' => true]);
- }
-
- public function downloadAction($library)
- {
- $htmlcode = 200;
- $builtinLibraryFilesPath = $this->container->getParameter('builtin_libraries') . "/";
- $externalLibraryFilesPath = $this->container->getParameter('external_libraries') . "/";
- $finder = new Finder();
- $exampleFinder = new Finder();
-
- $filename = $library;
-
- $last_slash = strrpos($library, "/");
- if ($last_slash !== false) {
- $filename = substr($library, $last_slash + 1);
- $vendor = substr($library, 0, $last_slash);
- }
-
- $handler = $this->get('codebender_library.handler');
- $isBuiltIn = json_decode($handler->checkIfBuiltInExists($filename), true);
- if ($isBuiltIn["success"])
- $path = $builtinLibraryFilesPath . "/libraries/" . $filename;
- else {
- $isExternal = json_decode($handler->checkIfExternalExists($filename), true);
- if ($isExternal["success"]) {
- $path = $externalLibraryFilesPath . '/' . $filename;
- } else {
- $value = "";
- $htmlcode = 404;
- return new Response($value, $htmlcode);
- }
- }
-
- $files = $handler->fetchLibraryFiles($finder, $path, false);
- $examples = $handler->fetchLibraryExamples($exampleFinder, $path);
-
- $zipname = "/tmp/asd.zip";
-
- $zip = new ZipArchive();
-
- if ($zip->open($zipname, ZIPARCHIVE::CREATE) === false) {
- $value = "";
- $htmlcode = 404;
- } else {
- if ($zip->addEmptyDir($filename) !== true) {
- $value = "";
- $htmlcode = 404;
- } else {
- foreach ($files as $file) {
- // No special handling needed for binary files, since addFromString method is binary safe.
- $zip->addFromString($library . '/' . $file['filename'], file_get_contents($path . '/' . $file['filename']));
- }
- foreach ($examples as $file) {
- $zip->addFromString($library . "/" . $file["filename"], $file["content"]);
- }
- $zip->close();
- $value = file_get_contents($zipname);
- }
- unlink($zipname);
- }
-
- $headers = array('Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment;filename="' . $filename . '.zip"');
-
- return new Response($value, $htmlcode, $headers);
- }
-
- private function saveNewLibrary($humanName, $machineName, $gitOwner, $gitRepo, $description, $lastCommit, $url, $branch, $sourceUrl, $notes, $inRepoPath, $libfiles)
- {
- $handler = $this->get('codebender_library.handler');
- $exists = json_decode($handler->checkIfExternalExists($machineName), true);
- if ($exists['success'])
- return json_encode(array("success" => false, "message" => "Library named " . $machineName . " already exists."));
-
- $create = json_decode($this->createLibFiles($machineName, $libfiles), true);
- if (!$create['success'])
- return json_encode($create);
-
- $lib = new ExternalLibrary();
- $lib->setHumanName($humanName);
- $lib->setMachineName($machineName);
- $lib->setDescription($description);
- $lib->setOwner($gitOwner);
- $lib->setRepo($gitRepo);
- $lib->setBranch($branch);
- $lib->setInRepoPath($inRepoPath);
- $lib->setSourceUrl($sourceUrl);
- $lib->setNotes($notes);
- $lib->setVerified(false);
- $lib->setActive(false);
- $lib->setLastCommit($lastCommit);
- $lib->setUrl($url);
-
- $em = $this->getDoctrine()->getManager();
- $em->persist($lib);
- $em->flush();
-
- $externalLibrariesPath = $this->container->getParameter('external_libraries');
- $examples = $handler->fetchLibraryExamples(new Finder(), $externalLibrariesPath . '/' . $machineName);
-
- foreach ($examples as $example) {
-
- $path_parts = pathinfo($example['filename']);
- $this->saveExampleMeta($path_parts['filename'], $lib, $machineName . "/" . $example['filename'], null);
- }
-
-
- return json_encode(array("success" => true));
-
- }
-
- private function createLibFiles($machineName, $lib)
- {
- $libBaseDir = $this->container->getParameter('external_libraries') . '/' . $machineName . "/";
- return ($this->createLibDirectory($libBaseDir, $libBaseDir, $lib['contents']));
- }
-
- private function createLibDirectory($base, $path, $files)
- {
-
- if (is_dir($path))
- return json_encode(array("success" => false, "message" => "Library directory already exists"));
- if (!mkdir($path))
- return json_encode(array("success" => false, "message" => "Cannot Save Library"));
-
- foreach ($files as $file) {
- if ($file['type'] == 'dir') {
- $create = json_decode($this->createLibDirectory($base, $base . $file['name'] . "/", $file['contents']), true);
- if (!$create['success'])
- return (json_encode($create));
- } else {
- file_put_contents($path . $file['name'], $file['contents']);
- }
- }
-
- return json_encode(array('success' => true));
- }
-
- private function saveExampleMeta($name, $lib, $path, $boards)
- {
- //TODO make it better. You know, return things and shit
- $example = new Example();
- $example->setName($name);
- $example->setLibrary($lib);
- $example->setPath($path);
- $example->setBoards($boards);
- $em = $this->getDoctrine()->getManager();
- $em->persist($example);
- $em->flush();
- }
-
-
- private function getLibFromZipFile($file)
- {
- if (is_dir('/tmp/lib'))
- $this->destroy_dir('/tmp/lib');
- $zip = new \ZipArchive;
- $opened = $zip->open($file);
-
- if ($opened === true) {
- $handler = $this->get('codebender_library.handler');
- $zip->extractTo('/tmp/lib/');
- $zip->close();
- $dir = $this->processZipDir('/tmp/lib');
-
- if (!$dir['success']) {
- return json_encode($dir);
- }
-
- $dir = $dir['directory'];
- $baseDir = $handler->findBaseDir($dir);
- if ($baseDir['success'] !== true) {
- return $baseDir;
- }
-
- $baseDir = $baseDir['directory'];
-
- return ['success' => true, 'library' => $baseDir];
- } else {
- return ['success' => false, 'message' => 'Could not unzip Archive. Code: ' . $opened];
- }
- }
-
- private function processZipDir($path)
- {
- $files = [];
- $dir = preg_grep('/^([^.])/', scandir($path));
- foreach ($dir as $file) {
- if ($file == "__MACOSX") {
- continue;
- }
-
- if (is_dir($path . '/' . $file)) {
- $subdir = $this->processZipDir($path . '/' . $file);
- if ($subdir['success'] !== true) {
- return $subdir;
- }
- array_push($files, $subdir['directory']);
- } else {
- $file = $this->processZipFile($path . '/' . $file);
- if ($file['success'] === true) {
- array_push($files, $file['file']);
- } else if ($file['message'] != "Bad Encoding") {
- return $file;
- }
- }
- }
- return ['success' => true, 'directory' => ['name' => substr($path, 9), 'type' => 'dir', 'contents' => $files]];
- }
-
- private function processZipFile($path)
- {
- $contents = file_get_contents($path);
-
- if ($contents === null) {
- return ['success' => false, 'message' => 'Could not read file ' . basename($path)];
- }
-
- return ['success' => true, 'file' => ['name' => basename($path), 'type' => 'file', 'contents' => $contents]];
- }
-
- private function destroy_dir($dir)
- {
- if (!is_dir($dir) || is_link($dir)) {
- return unlink($dir);
- }
- foreach (scandir($dir) as $file) {
- if ($file != '.' && $file != '..' && !$this->destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) {
- chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
- if (!$this->destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) return false;
- }
- }
- return rmdir($dir);
- }
-
-}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadArchitectureData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadArchitectureData.php
new file mode 100644
index 00000000..e5dfff69
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadArchitectureData.php
@@ -0,0 +1,87 @@
+setName('AVR');
+
+ /*
+ * Set a reference for each architecture and add it to the database using
+ * the object manager interface
+ */
+ $this->setReference('AvrArchitecture', $avrArchitecture);
+
+ $objectManager->persist($avrArchitecture);
+
+ $esp8266Architecture = new Architecture();
+ $esp8266Architecture->setName('ESP8266');
+
+ /*
+ * Set a reference for each architecture and add it to the database using
+ * the object manager interface
+ */
+ $this->setReference('ESP8266Architecture', $esp8266Architecture);
+
+ $objectManager->persist($esp8266Architecture);
+
+ $edisonArchitecture = new Architecture();
+ $edisonArchitecture->setName('Intel Edison');
+
+ /*
+ * Set a reference for each architecture and add it to the database using
+ * the object manager interface
+ */
+ $this->setReference('EdisonArchitecture', $edisonArchitecture);
+
+ $objectManager->persist($edisonArchitecture);
+
+ $teensyArchitecture = new Architecture();
+ $teensyArchitecture->setName('Teensy');
+
+ /*
+ * Set a reference for each architecture and add it to the database using
+ * the object manager interface
+ */
+ $this->setReference('TeensyArchitecture', $teensyArchitecture);
+
+ $objectManager->persist($teensyArchitecture);
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+ }
+
+ /**
+ * Returns the order in which the current fixture will be loaded,
+ * compared to other fixture classes.
+ *
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 3;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadArchitectureVersionData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadArchitectureVersionData.php
new file mode 100644
index 00000000..da917840
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadArchitectureVersionData.php
@@ -0,0 +1,142 @@
+getReference('AvrArchitecture');
+
+ /* @var \Codebender\LibraryBundle\Entity\Architecture $esp8266Architecture */
+ $esp8266Architecture = $this->getReference('ESP8266Architecture');
+
+ /* @var \Codebender\LibraryBundle\Entity\Architecture $edisonArchitecture */
+ $edisonArchitecture = $this->getReference('EdisonArchitecture');
+
+ /* @var \Codebender\LibraryBundle\Entity\Architecture $teensyArchitecture */
+ $teensyArchitecture = $this->getReference('TeensyArchitecture');
+
+ /**
+ * Get reference for our mock version data
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $defaultLibraryVersion1 */
+ $defaultLibraryVersion1 = $this->getReference('defaultLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $defaultLibraryVersion2 */
+ $defaultLibraryVersion2 = $this->getReference('defaultLibraryVersion2');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $dahLibraryVersion1 */
+ $dahLibraryVersion1 = $this->getReference('dynamicArrayHelperLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $multiInoLibraryVersion1 */
+ $multiInoLibraryVersion1 = $this->getReference('MultiInoLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $multiInoLibraryVersion2 */
+ $multiInoLibraryVersion2 = $this->getReference('MultiInoLibraryVersion2');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $subcategLibraryVersion1 */
+ $subcategLibraryVersion1 = $this->getReference('SubCategLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $subcategLibraryVersion2 */
+ $subcategLibraryVersion2 = $this->getReference('SubCategLibraryVersion2');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $hiddenFilesLibraryVersion1 */
+ $hiddenFilesLibraryVersion1 = $this->getReference('HiddenLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion1 */
+ $encodeLibraryVersion1 = $this->getReference('EncodeLibraryVersion1');
+
+ /*
+ * Add mock architectures for each versions
+ */
+ $defaultLibraryVersion1->addArchitecture($avrArchitecture);
+ $defaultLibraryVersion1->addArchitecture($esp8266Architecture);
+ $objectManager->persist($defaultLibraryVersion1);
+
+ $defaultLibraryVersion2->addArchitecture($avrArchitecture);
+ $defaultLibraryVersion2->addArchitecture($esp8266Architecture);
+ $defaultLibraryVersion2->addArchitecture($edisonArchitecture);
+ $defaultLibraryVersion2->addArchitecture($teensyArchitecture);
+ $objectManager->persist($defaultLibraryVersion2);
+
+ $dahLibraryVersion1->addArchitecture($avrArchitecture);
+ $dahLibraryVersion1->addArchitecture($esp8266Architecture);
+ $dahLibraryVersion1->addArchitecture($edisonArchitecture);
+ $dahLibraryVersion1->addArchitecture($teensyArchitecture);
+ $objectManager->persist($dahLibraryVersion1);
+
+ $multiInoLibraryVersion1->addArchitecture($avrArchitecture);
+ $multiInoLibraryVersion1->addArchitecture($esp8266Architecture);
+ $objectManager->persist($multiInoLibraryVersion1);
+
+ $multiInoLibraryVersion2->addArchitecture($avrArchitecture);
+ $multiInoLibraryVersion2->addArchitecture($esp8266Architecture);
+ $multiInoLibraryVersion2->addArchitecture($edisonArchitecture);
+ $multiInoLibraryVersion2->addArchitecture($teensyArchitecture);
+ $objectManager->persist($multiInoLibraryVersion2);
+
+ $subcategLibraryVersion1->addArchitecture($avrArchitecture);
+ $subcategLibraryVersion1->addArchitecture($esp8266Architecture);
+ $subcategLibraryVersion1->addArchitecture($edisonArchitecture);
+ $subcategLibraryVersion1->addArchitecture($teensyArchitecture);
+ $objectManager->persist($subcategLibraryVersion1);
+
+ $subcategLibraryVersion2->addArchitecture($avrArchitecture);
+ $subcategLibraryVersion2->addArchitecture($esp8266Architecture);
+ $subcategLibraryVersion2->addArchitecture($edisonArchitecture);
+ $subcategLibraryVersion2->addArchitecture($teensyArchitecture);
+ $objectManager->persist($subcategLibraryVersion2);
+
+ $hiddenFilesLibraryVersion1->addArchitecture($avrArchitecture);
+ $hiddenFilesLibraryVersion1->addArchitecture($esp8266Architecture);
+ $hiddenFilesLibraryVersion1->addArchitecture($edisonArchitecture);
+ $hiddenFilesLibraryVersion1->addArchitecture($teensyArchitecture);
+ $objectManager->persist($hiddenFilesLibraryVersion1);
+
+ $encodeLibraryVersion1->addArchitecture($avrArchitecture);
+ $encodeLibraryVersion1->addArchitecture($esp8266Architecture);
+ $encodeLibraryVersion1->addArchitecture($edisonArchitecture);
+ $encodeLibraryVersion1->addArchitecture($teensyArchitecture);
+ $objectManager->persist($encodeLibraryVersion1);
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+ }
+
+ /**
+ * Returns the order in which the current fixture will be loaded,
+ * compared to other fixture classes.
+ *
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 8;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadExternalLibraryData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadExternalLibraryData.php
deleted file mode 100644
index 60b2594f..00000000
--- a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadExternalLibraryData.php
+++ /dev/null
@@ -1,159 +0,0 @@
-setHumanName('Default Arduino Library');
- $defaultLibrary->setMachineName('default');
- $defaultLibrary->setActive(true);
- $defaultLibrary->setVerified(false);
- $defaultLibrary->setDescription('The default Arduino library (in fact it\'s Adafruit\'s GPS library)');
- $defaultLibrary->setNotes('No notes provided for this library');
- $defaultLibrary->setUrl('http://localhost/library/url');
-
- /*
- * Set a reference for the library and add it to the database using
- * the object manager interface
- */
- $this->setReference('defaultLibrary', $defaultLibrary);
- $objectManager->persist($defaultLibrary);
-
- // Dynamic Array Helper library hosted on codebender's Github organistion
- $dahLibrary = new ExternalLibrary();
- $dahLibrary->setHumanName('Dynamic Array Helper Arduino Library');
- $dahLibrary->setMachineName('DynamicArrayHelper');
- $dahLibrary->setActive(true);
- $dahLibrary->setVerified(false);
- $dahLibrary->setDescription('DynamicArrayHelper Arduino Library from the Arduino Playground');
- $dahLibrary->setUrl('https://github.com/codebendercc/DynamicArrayHelper-Arduino-Library');
- $dahLibrary->setSourceUrl('https://github.com/codebendercc/DynamicArrayHelper-Arduino-Library/archive/1.0.x.zip');
- $dahLibrary->setBranch('1.0.x');
- $dahLibrary->setOwner('codebendercc');
- $dahLibrary->setRepo('DynamicArrayHelper-Arduino-Library');
- $dahLibrary->setLastCommit('72b8865ee53b3edf159f22f5ff6f9a6dafa7ee1b'); // This is not the last commit of the branch
-
- // Reference to DynamicArrayHelper library
- $this->setReference('dynamicArrayHelperLibrary', $dahLibrary);
- $objectManager->persist($dahLibrary);
-
- // A fake library with multi-ino examples
- $multiIno = new ExternalLibrary();
- $multiIno->setHumanName('MultiIno Arduino Library');
- $multiIno->setMachineName('MultiIno');
- $multiIno->setActive(true);
- $multiIno->setVerified(false);
- $multiIno->setDescription('A library containing multi-ino examples which should be correctly fetched');
- $multiIno->setSourceUrl('https://some/source/url.com');
-
- // Reference to MultiIno library
- $this->setReference('MultiInoLibrary', $multiIno);
- $objectManager->persist($multiIno);
-
- // A fake library with examples contained in subcategories
- $subcategLibrary = new ExternalLibrary();
- $subcategLibrary->setHumanName('SubCategories Arduino Library');
- $subcategLibrary->setMachineName('SubCateg');
- $subcategLibrary->setActive(true);
- $subcategLibrary->setVerified(false);
- $subcategLibrary->setDescription('A library containing examples sorted in categories');
- $subcategLibrary->setUrl('https://some/url.com');
- $subcategLibrary->setSourceUrl('https://some/source/url.com');
-
- // Reference to SubCateg library
- $this->setReference('SubCategLibrary', $subcategLibrary);
- $objectManager->persist($subcategLibrary);
-
- // A fake library containing hidden files
- $hiddenFilesLibrary = new ExternalLibrary();
- $hiddenFilesLibrary->setHumanName('Hidden');
- $hiddenFilesLibrary->setMachineName('Hidden');
- $hiddenFilesLibrary->setActive(true);
- $hiddenFilesLibrary->setVerified(false);
- $hiddenFilesLibrary->setDescription('A library containing hidden files and directories in its code & examples');
- $hiddenFilesLibrary->setUrl('https://some/url.com');
- $hiddenFilesLibrary->setSourceUrl('https://some/source/url.com');
-
- // Reference to Hidden library
- $this->setReference('HiddenLibrary', $hiddenFilesLibrary);
- $objectManager->persist($hiddenFilesLibrary);
-
- // A fake library with non UTF-8 encoded content.
- $invalidEncodingLibrary = new ExternalLibrary();
- $invalidEncodingLibrary->setHumanName('Invalid Encoding Library');
- $invalidEncodingLibrary->setMachineName('Encode');
- $invalidEncodingLibrary->setActive(true);
- $invalidEncodingLibrary->setVerified(false);
- $invalidEncodingLibrary->setDescription('A library containing characters with invalid encoding in it code & examples');
- $invalidEncodingLibrary->setUrl('https://some/url.com');
- $invalidEncodingLibrary->setSourceUrl('https://some/source/url.com');
-
- // Reference to Encode library
- $this->setReference('EncodeLibrary', $invalidEncodingLibrary);
- $objectManager->persist($invalidEncodingLibrary);
-
- // A fake library with HTML doc files.
- $htmlLibrary = new ExternalLibrary();
- $htmlLibrary->setHumanName('HTML content Library');
- $htmlLibrary->setMachineName('HtmlLib');
- $htmlLibrary->setActive(true);
- $htmlLibrary->setVerified(false);
- $htmlLibrary->setDescription('A library containing HTML in its files');
- $htmlLibrary->setUrl('https://some/url.com');
- $htmlLibrary->setSourceUrl('https://some/source/url.com');
-
- $objectManager->persist($htmlLibrary);
-
- // A fake library with non-text contents.
- $binaryLbrary = new ExternalLibrary();
- $binaryLbrary->setHumanName('Binary content Library');
- $binaryLbrary->setMachineName('Binary');
- $binaryLbrary->setActive(true);
- $binaryLbrary->setVerified(false);
- $binaryLbrary->setDescription('A library containing non-text files');
- $binaryLbrary->setUrl('https://some/url.com');
- $binaryLbrary->setSourceUrl('https://some/source/url.com');
-
- // Persist the new library
- $objectManager->persist($binaryLbrary);
-
- /*
- * After all fixture objects have been added to the ObjectManager (`persist` operation),
- * it's time to flush the contents of the ObjectManager
- */
- $objectManager->flush();
- }
-
- /**
- * Returns the order in which the current fixture will be loaded,
- * compared to other fixture classes.
- *
- * @return int
- */
- public function getOrder()
- {
- return 1;
- }
-}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadExternalLibraryExamplesData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadExternalLibraryExamplesData.php
deleted file mode 100644
index 29164ff8..00000000
--- a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadExternalLibraryExamplesData.php
+++ /dev/null
@@ -1,128 +0,0 @@
-getReference('defaultLibrary');
-
- $defaultExample = new Example();
- $defaultExample->setName('example_one');
- $defaultExample->setLibrary($defaultLibrary);
- $defaultExample->setPath('default/examples/example_one/example_one.ino');
- $defaultExample->setBoards(null);
-
- /*
- * Set a reference for each example and add it to the database using
- * the object manager interface
- */
- $this->setReference('defaultLibraryExample', $defaultExample);
- $objectManager->persist($defaultExample);
-
- /* @var \Codebender\LibraryBundle\Entity\ExternalLibrary $multiInoLibrary */
- $multiInoLibrary = $this->getReference('MultiInoLibrary');
-
- $example = new Example();
- $example->setName('example_one');
- $example->setLibrary($multiInoLibrary);
- $example->setPath('MultiIno/examples/multi_ino_example/multi_ino_example.ino');
- $example->setBoards(null);
-
- // Persist the new example
- $objectManager->persist($example);
-
- /* @var \Codebender\LibraryBundle\Entity\ExternalLibrary $subcategLibrary */
- $subcategLibrary = $this->getReference('SubCategLibrary');
-
- $exampleDefaultCateg = new Example();
- $exampleDefaultCateg->setName('subcateg_example_one');
- $exampleDefaultCateg->setLibrary($subcategLibrary);
- $exampleDefaultCateg->setPath('SubCateg/Examples/subcateg_example_one/subcateg_example_one.ino');
- $exampleDefaultCateg->setBoards(null);
-
- // Persist the new example
- $objectManager->persist($exampleDefaultCateg);
-
- $exampleBeginnerCateg = new Example();
- $exampleBeginnerCateg->setName('subcateg_example_two');
- $exampleBeginnerCateg->setLibrary($subcategLibrary);
- $exampleBeginnerCateg->setPath('SubCateg/Examples/experienceBased/Beginners/subcateg_example_two/subcateg_example_two.ino');
- $exampleBeginnerCateg->setBoards(null);
-
- // Persist the new example
- $objectManager->persist($exampleBeginnerCateg);
-
- $exampleExperiencedCateg = new Example();
- $exampleExperiencedCateg->setName('subcateg_example_three');
- $exampleExperiencedCateg->setLibrary($subcategLibrary);
- $exampleExperiencedCateg->setPath('SubCateg/Examples/experienceBased/Advanced/Experts/subcateg_example_three/subcateg_example_three.ino');
- $exampleExperiencedCateg->setBoards(null);
-
- // Persist the new example
- $objectManager->persist($exampleExperiencedCateg);
-
- /* @var \Codebender\LibraryBundle\Entity\ExternalLibrary $hiddenFilesLibrary */
- $hiddenFilesLibrary = $this->getReference('HiddenLibrary');
-
- $hiddenFilesExample = new Example();
- $hiddenFilesExample->setName('hidden_files_example');
- $hiddenFilesExample->setLibrary($hiddenFilesLibrary);
- $hiddenFilesExample->setPath('Hidden/examples/hidden_files_example/hidden_files_example.ino');
- $hiddenFilesExample->setBoards(null);
-
- // Persist the new example
- $objectManager->persist($hiddenFilesExample);
-
- /* @var \Codebender\LibraryBundle\Entity\ExternalLibrary $encodeLibrary */
- $encodeLibrary = $this->getReference('EncodeLibrary');
-
- $encodeLibraryExample = new Example();
- $encodeLibraryExample->setName('encoded_example');
- $encodeLibraryExample->setLibrary($encodeLibrary);
- $encodeLibraryExample->setPath('Encode/examples/encoded_example/encoded_example.ino');
- $encodeLibraryExample->setBoards(null);
-
- // Persist the new example
- $objectManager->persist($encodeLibraryExample);
-
- /*
- * After all fixture objects have been added to the ObjectManager (`persist` operation),
- * it's time to flush the contents of the ObjectManager
- */
- $objectManager->flush();
- }
-
- /**
- * Returns the order in which the current fixture will be loaded,
- * compared to other fixture classes.
- * Examples database data should be provided after the library data,
- * because there is a foreign key constraint between them which should
- * be satisfied.
- *
- * @return int
- */
- public function getOrder()
- {
- return 2;
- }
-}
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadLibraryAndVersionData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadLibraryAndVersionData.php
new file mode 100644
index 00000000..a37ef279
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadLibraryAndVersionData.php
@@ -0,0 +1,471 @@
+setName('Default Arduino Library');
+ $defaultLibrary->setDefaultHeader('default');
+ $defaultLibrary->setActive(true);
+ $defaultLibrary->setVerified(false);
+ $defaultLibrary->setDescription('The default Arduino library (in fact it\'s Adafruit\'s GPS library)');
+ $defaultLibrary->setNotes('No notes provided for this library');
+ $defaultLibrary->setUrl('http://localhost/library/url');
+ $defaultLibrary->setFolderName('default');
+
+ /*
+ * Create mock version 1.0.0 for default library
+ */
+ $defaultLibraryVersion1 = new Version();
+ $defaultLibraryVersion1->setVersion('1.0.0');
+ $defaultLibraryVersion1->setLibrary($defaultLibrary);
+ $defaultLibraryVersion1->setDescription('Version 1.0.0');
+ $defaultLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Create mock version 1.1.0 for default library
+ */
+ $defaultLibraryVersion2 = new Version();
+ $defaultLibraryVersion2->setVersion('1.1.0');
+ $defaultLibraryVersion2->setLibrary($defaultLibrary);
+ $defaultLibraryVersion2->setDescription('Version 1.1.0');
+ $defaultLibraryVersion2->setFolderName('1.1.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $defaultLibrary->setLatestVersion($defaultLibraryVersion2);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('defaultLibrary', $defaultLibrary);
+ $this->setReference('defaultLibraryVersion1', $defaultLibraryVersion1);
+ $this->setReference('defaultLibraryVersion2', $defaultLibraryVersion2);
+ $objectManager->persist($defaultLibraryVersion1);
+ $objectManager->persist($defaultLibraryVersion2);
+ $objectManager->persist($defaultLibrary);
+
+
+ // Dynamic Array Helper library hosted on codebender's Github organistion
+ $dahLibrary = new Library();
+ $dahLibrary->setName('Dynamic Array Helper Arduino Library');
+ $dahLibrary->setDefaultHeader('DynamicArrayHelper');
+ $dahLibrary->setActive(true);
+ $dahLibrary->setVerified(false);
+ $dahLibrary->setDescription('DynamicArrayHelper Arduino Library from the Arduino Playground');
+ $dahLibrary->setUrl('https://github.com/codebendercc/DynamicArrayHelper-Arduino-Library');
+ $dahLibrary->setOwner('codebendercc');
+ $dahLibrary->setRepo('DynamicArrayHelper-Arduino-Library');
+ $dahLibrary->setBranch('1.0.x');
+ $dahLibrary->setInRepoPath('');
+ $dahLibrary->setLastCommit('72b8865ee53b3edf159f22f5ff6f9a6dafa7ee1b'); // This is not the last commit of the branch
+ $dahLibrary->setFolderName('DynamicArrayHelper');
+
+ /*
+ * Create mock version 1.0.0 for Dynamic Array Helper library
+ */
+ $dahLibraryVersion1 = new Version();
+ $dahLibraryVersion1->setVersion('1.0.0');
+ $dahLibraryVersion1->setLibrary($dahLibrary);
+ $dahLibraryVersion1->setDescription('Version 1.0.0');
+ $dahLibraryVersion1->setFolderName('1.0.0');
+ $dahLibraryVersion1->setReleaseCommit('1751ccb9f8a1c5d9161fe18d97a03415e3517235');
+ $dahLibraryVersion1->setSourceUrl('https://github.com/codebendercc/DynamicArrayHelper-Arduino-Library/archive/1.0.x.zip');
+
+ /*
+ * Set the latest version for the library
+ */
+ $dahLibrary->setLatestVersion($dahLibraryVersion1);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('dynamicArrayHelperLibrary', $dahLibrary);
+ $this->setReference('dynamicArrayHelperLibraryVersion1', $dahLibraryVersion1);
+ $objectManager->persist($dahLibrary);
+ $objectManager->persist($dahLibraryVersion1);
+
+
+ // A fake library with multi-ino examples
+ $multiIno = new Library();
+ $multiIno->setName('MultiIno Arduino Library');
+ $multiIno->setDefaultHeader('MultiIno');
+ $multiIno->setActive(true);
+ $multiIno->setVerified(false);
+ $multiIno->setDescription('A library containing multi-ino examples which should be correctly fetched');
+ $multiIno->setUrl('https://some/url.com');
+ $multiIno->setFolderName('MultiIno');
+
+ /*
+ * Create mock version 1.0.0 for Multi Ino library
+ */
+ $multiInoLibraryVersion1 = new Version();
+ $multiInoLibraryVersion1->setVersion('1.0.0');
+ $multiInoLibraryVersion1->setLibrary($multiIno);
+ $multiInoLibraryVersion1->setDescription('Version 1.0.0');
+ $multiInoLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Create mock version 2.0.0 for Multi Ino library
+ */
+ $multiInoLibraryVersion2 = new Version();
+ $multiInoLibraryVersion2->setVersion('2.0.0');
+ $multiInoLibraryVersion2->setLibrary($multiIno);
+ $multiInoLibraryVersion2->setDescription('Version 2.0.0');
+ $multiInoLibraryVersion2->setFolderName('2.0.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $multiIno->setLatestVersion($multiInoLibraryVersion2);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('MultiInoLibrary', $multiIno);
+ $this->setReference('MultiInoLibraryVersion1', $multiInoLibraryVersion1);
+ $this->setReference('MultiInoLibraryVersion2', $multiInoLibraryVersion2);
+ $objectManager->persist($multiIno);
+ $objectManager->persist($multiInoLibraryVersion1);
+ $objectManager->persist($multiInoLibraryVersion2);
+
+
+ // A fake library with examples contained in subcategories
+ $subcategLibrary = new Library();
+ $subcategLibrary->setName('SubCategories Arduino Library');
+ $subcategLibrary->setDefaultHeader('SubCateg');
+ $subcategLibrary->setActive(true);
+ $subcategLibrary->setVerified(false);
+ $subcategLibrary->setDescription('A library containing examples sorted in categories');
+ $subcategLibrary->setUrl('https://some/url.com');
+ $subcategLibrary->setFolderName('SubCateg');
+
+ /*
+ * Create mock version 1.0.0 for Sub Category library
+ */
+ $subcategLibraryVersion1 = new Version();
+ $subcategLibraryVersion1->setVersion('1.0.0');
+ $subcategLibraryVersion1->setLibrary($subcategLibrary);
+ $subcategLibraryVersion1->setDescription('Version 1.0.0');
+ $subcategLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Create mock version 1.5.2 for Sub Category library
+ */
+ $subcategLibraryVersion2 = new Version();
+ $subcategLibraryVersion2->setVersion('1.5.2');
+ $subcategLibraryVersion2->setLibrary($subcategLibrary);
+ $subcategLibraryVersion2->setDescription('Version 1.5.2');
+ $subcategLibraryVersion2->setFolderName('1.5.2');
+
+ /*
+ * Set the latest version for the library
+ */
+ $subcategLibrary->setLatestVersion($subcategLibraryVersion2);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('SubCategLibrary', $subcategLibrary);
+ $this->setReference('SubCategLibraryVersion1', $subcategLibraryVersion1);
+ $this->setReference('SubCategLibraryVersion2', $subcategLibraryVersion2);
+ $objectManager->persist($subcategLibrary);
+ $objectManager->persist($subcategLibraryVersion1);
+ $objectManager->persist($subcategLibraryVersion2);
+
+
+ // A fake library containing hidden files
+ $hiddenFilesLibrary = new Library();
+ $hiddenFilesLibrary->setName('Hidden');
+ $hiddenFilesLibrary->setDefaultHeader('Hidden');
+ $hiddenFilesLibrary->setActive(true);
+ $hiddenFilesLibrary->setVerified(false);
+ $hiddenFilesLibrary->setDescription('A library containing hidden files and directories in its code & examples');
+ $hiddenFilesLibrary->setUrl('https://some/url.com');
+ $hiddenFilesLibrary->setFolderName('Hidden');
+
+ /*
+ * Create mock version 1.0.0 for Hidden library
+ */
+ $hiddenFilesLibraryVersion1 = new Version();
+ $hiddenFilesLibraryVersion1->setVersion('1.0.0');
+ $hiddenFilesLibraryVersion1->setLibrary($hiddenFilesLibrary);
+ $hiddenFilesLibraryVersion1->setDescription('Version 1.0.0');
+ $hiddenFilesLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $hiddenFilesLibrary->setLatestVersion($hiddenFilesLibraryVersion1);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('HiddenLibrary', $hiddenFilesLibrary);
+ $this->setReference('HiddenLibraryVersion1', $hiddenFilesLibraryVersion1);
+ $objectManager->persist($hiddenFilesLibrary);
+ $objectManager->persist($hiddenFilesLibraryVersion1);
+
+
+ // A fake library with non UTF-8 encoded content.
+ $invalidEncodingLibrary = new Library();
+ $invalidEncodingLibrary->setName('Invalid Encoding Library');
+ $invalidEncodingLibrary->setDefaultHeader('Encode');
+ $invalidEncodingLibrary->setActive(true);
+ $invalidEncodingLibrary->setVerified(false);
+ $invalidEncodingLibrary->setDescription('A library containing characters with invalid encoding in it code & examples');
+ $invalidEncodingLibrary->setUrl('https://some/url.com');
+ $invalidEncodingLibrary->setFolderName('Encode');
+
+ /*
+ * Create mock version 1.0.0 for Encode library
+ */
+ $encodeLibraryVersion1 = new Version();
+ $encodeLibraryVersion1->setVersion('1.0.0');
+ $encodeLibraryVersion1->setLibrary($invalidEncodingLibrary);
+ $encodeLibraryVersion1->setDescription('Version 1.0.0');
+ $encodeLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $invalidEncodingLibrary->setLatestVersion($encodeLibraryVersion1);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('EncodeLibrary', $invalidEncodingLibrary);
+ $this->setReference('EncodeLibraryVersion1', $encodeLibraryVersion1);
+ $objectManager->persist($invalidEncodingLibrary);
+ $objectManager->persist($encodeLibraryVersion1);
+
+ /*
+ * Set references and persist
+ */
+ $htmlLibrary = new Library();
+ $htmlLibrary->setName('HTML content Library');
+ $htmlLibrary->setDefaultHeader('HtmlLib');
+ $htmlLibrary->setActive(true);
+ $htmlLibrary->setVerified(false);
+ $htmlLibrary->setDescription('A library containing HTML in its files');
+ $htmlLibrary->setUrl('https://some/url.com');
+ $htmlLibrary->setFolderName('HtmlLib');
+
+ /*
+ * Create mock version 1.0.0 for Binary library
+ */
+ $htmlLbraryVersion1 = new Version();
+ $htmlLbraryVersion1->setVersion('1.0.0');
+ $htmlLbraryVersion1->setLibrary($htmlLibrary);
+ $htmlLbraryVersion1->setDescription('Version 1.0.0');
+ $htmlLbraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $htmlLibrary->setLatestVersion($htmlLbraryVersion1);
+
+ $this->setReference('HtmlLibrary', $htmlLibrary);
+ $this->setReference('HtmlLibraryVersion1', $htmlLbraryVersion1);
+ $objectManager->persist($htmlLibrary);
+ $objectManager->persist($htmlLbraryVersion1);
+
+
+ // A fake library with non-text contents.
+ $binaryLbrary = new Library();
+ $binaryLbrary->setName('Binary content Library');
+ $binaryLbrary->setDefaultHeader('Binary');
+ $binaryLbrary->setActive(true);
+ $binaryLbrary->setVerified(false);
+ $binaryLbrary->setDescription('A library containing non-text files');
+ $binaryLbrary->setUrl('https://some/url.com');
+ $binaryLbrary->setFolderName('Binary');
+
+ /*
+ * Create mock version 1.0.0 for Binary library
+ */
+ $binaryLbraryVersion1 = new Version();
+ $binaryLbraryVersion1->setVersion('1.0.0');
+ $binaryLbraryVersion1->setLibrary($binaryLbrary);
+ $binaryLbraryVersion1->setDescription('Version 1.0.0');
+ $binaryLbraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $binaryLbrary->setLatestVersion($binaryLbraryVersion1);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('BinaryLibrary', $binaryLbrary);
+ $this->setReference('BinaryLibraryVersion1', $binaryLbraryVersion1);
+ $objectManager->persist($binaryLbrary);
+ $objectManager->persist($binaryLbraryVersion1);
+
+
+ // Fake libraries to be used for testing delete API
+ $deleteMeLibrary = new Library();
+ $deleteMeLibrary->setName('deleteMeLibrary');
+ $deleteMeLibrary->setDefaultHeader('deleteMe');
+ $deleteMeLibrary->setActive(true);
+ $deleteMeLibrary->setVerified(false);
+ $deleteMeLibrary->setDescription('Fake library for delete test');
+ $deleteMeLibrary->setNotes('No one shall read this note.');
+ $deleteMeLibrary->setUrl('http://localhost/library/url');
+ $deleteMeLibrary->setFolderName('delete');
+
+ /*
+ * Create mock version 1.0.0 for delete library
+ */
+ $deleteMeLibraryVersion1 = new Version();
+ $deleteMeLibraryVersion1->setVersion('1.0.0');
+ $deleteMeLibraryVersion1->setLibrary($deleteMeLibrary);
+ $deleteMeLibraryVersion1->setDescription('Version 1.0.0');
+ $deleteMeLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Create mock version 1.1.0 for delete library
+ */
+ $deleteMeLibraryVersion2 = new Version();
+ $deleteMeLibraryVersion2->setVersion('1.1.0');
+ $deleteMeLibraryVersion2->setLibrary($deleteMeLibrary);
+ $deleteMeLibraryVersion2->setDescription('Version 1.1.0');
+ $deleteMeLibraryVersion2->setFolderName('1.1.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $deleteMeLibrary->setLatestVersion($deleteMeLibraryVersion2);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('deleteMeLibrary', $deleteMeLibrary);
+ $this->setReference('deleteMeLibraryVersion1', $deleteMeLibraryVersion1);
+ $this->setReference('deleteMeLibraryVersion2', $deleteMeLibraryVersion2);
+ $objectManager->persist($deleteMeLibraryVersion1);
+ $objectManager->persist($deleteMeLibraryVersion2);
+ $objectManager->persist($deleteMeLibrary);
+
+ // Fake libraries to be used for testing delete API
+ $deleteLatestMeLibrary = new Library();
+ $deleteLatestMeLibrary->setName('deleteLatestMeLibrary');
+ $deleteLatestMeLibrary->setDefaultHeader('deleteLatestMe');
+ $deleteLatestMeLibrary->setActive(true);
+ $deleteLatestMeLibrary->setVerified(false);
+ $deleteLatestMeLibrary->setDescription('Fake library for delete test');
+ $deleteLatestMeLibrary->setNotes('No one shall read this note.');
+ $deleteLatestMeLibrary->setUrl('http://localhost/library/url');
+ $deleteLatestMeLibrary->setFolderName('deleteLatest');
+
+ /*
+ * Create mock version 1.0.0 for delete library
+ */
+ $deleteLatestMeLibraryVersion1 = new Version();
+ $deleteLatestMeLibraryVersion1->setVersion('1.0.0');
+ $deleteLatestMeLibraryVersion1->setLibrary($deleteLatestMeLibrary);
+ $deleteLatestMeLibraryVersion1->setDescription('Version 1.0.0');
+ $deleteLatestMeLibraryVersion1->setFolderName('1.0.0');
+
+ /*
+ * Create mock version 1.1.0 for delete library
+ */
+ $deleteLatestMeLibraryVersion2 = new Version();
+ $deleteLatestMeLibraryVersion2->setVersion('1.1.0');
+ $deleteLatestMeLibraryVersion2->setLibrary($deleteLatestMeLibrary);
+ $deleteLatestMeLibraryVersion2->setDescription('Version 1.1.0');
+ $deleteLatestMeLibraryVersion2->setFolderName('1.1.0');
+
+ /*
+ * Set the latest version for the library
+ */
+ $deleteLatestMeLibrary->setLatestVersion($deleteLatestMeLibraryVersion2);
+
+ /*
+ * Set references and persist
+ */
+ $this->setReference('deleteLatestMeLibrary', $deleteLatestMeLibrary);
+ $this->setReference('deleteLatestMeLibraryVersion1', $deleteLatestMeLibraryVersion1);
+ $this->setReference('deleteLatestMeLibraryVersion2', $deleteLatestMeLibraryVersion2);
+ $objectManager->persist($deleteLatestMeLibraryVersion1);
+ $objectManager->persist($deleteLatestMeLibraryVersion2);
+ $objectManager->persist($deleteLatestMeLibrary);
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+
+
+ // From here on add all the internal libraries
+ $builtInLibs = ["EEPROM", "Ethernet", "GSM", "Robot_Control", "SD", "SoftwareSerial", "Stepper", "WiFi",
+ "Esplora", "Firmata", "LiquidCrystal", "Robot_Motor", "Servo", "SPI", "TFT", "Wire"];
+ $builtInDefaultVersion = 'default';
+ foreach ($builtInLibs as $name) {
+ $builtInLib = new Library();
+ $builtInLib->setName($name);
+ $builtInLib->setDefaultHeader($name);
+ $builtInLib->setActive(true);
+ $builtInLib->setVerified(true);
+ $builtInLib->setDescription("Built-in library " . $name);
+ $builtInLib->setFolderName($name);
+ $builtInLib->setIsBuiltIn(true);
+
+ $builtInLibVersion = new Version();
+ $builtInLibVersion->setVersion($builtInDefaultVersion);
+ $builtInLibVersion->setLibrary($builtInLib);
+ $builtInLibVersion->setDescription("Built-in library " . $name . " default version.");
+ $builtInLibVersion->setFolderName($builtInDefaultVersion);
+
+ $builtInLib->setLatestVersion($builtInLibVersion);
+
+ $this->setReference($name . 'Library', $builtInLib);
+ $this->setReference($name . ucfirst($builtInDefaultVersion) . 'Version', $builtInLibVersion);
+ $objectManager->persist($builtInLib);
+ $objectManager->persist($builtInLibVersion);
+ }
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+ }
+
+ /**
+ * Returns the order in which the current fixture will be loaded,
+ * compared to other fixture classes.
+ *
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 5;
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadLibraryExampleData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadLibraryExampleData.php
new file mode 100644
index 00000000..df63962e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadLibraryExampleData.php
@@ -0,0 +1,362 @@
+getReference('defaultLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $defaultExample1 = new LibraryExample();
+ $defaultExample1->setName('example_one');
+ $defaultExample1->setVersion($defaultVersion1);
+ $defaultExample1->setPath('examples/example_one/example_one.ino');
+ $defaultExample1->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($defaultExample1);
+
+ /*
+ * Get mock version 1.1.0 of default Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $defaultVersion2 */
+ $defaultVersion2 = $this->getReference('defaultLibraryVersion2');
+
+ $defaultExample2 = new LibraryExample();
+ $defaultExample2->setName('example_one');
+ $defaultExample2->setVersion($defaultVersion2);
+ $defaultExample2->setPath('examples/example_one/example_one.ino');
+ $defaultExample2->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($defaultExample2);
+
+ /*
+ * Get mock version 1.0.0 of Multi Ino Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $multiInoLibraryVersion1 */
+ $multiInoLibraryVersion1 = $this->getReference('MultiInoLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $multiInoLibraryExample1 = new LibraryExample();
+ $multiInoLibraryExample1->setName('multi_ino_example');
+ $multiInoLibraryExample1->setVersion($multiInoLibraryVersion1);
+ $multiInoLibraryExample1->setPath('examples/multi_ino_example/multi_ino_example.ino');
+ $multiInoLibraryExample1->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($multiInoLibraryExample1);
+
+ /*
+ * Get mock version 2.0.0 of Multi Ino Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $multiInoLibraryVersion2 */
+ $multiInoLibraryVersion2 = $this->getReference('MultiInoLibraryVersion2');
+
+ /*
+ * Mock a new library example
+ */
+ $multiInoLibraryExample2 = new LibraryExample();
+ $multiInoLibraryExample2->setName('multi_ino_example');
+ $multiInoLibraryExample2->setVersion($multiInoLibraryVersion2);
+ $multiInoLibraryExample2->setPath('examples/multi_ino_example/multi_ino_example.ino');
+ $multiInoLibraryExample2->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($multiInoLibraryExample2);
+
+ /*
+ * Get mock version 1 of Sub Category Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $subcategLibraryVersion1 */
+ $subcategLibraryVersion1 = $this->getReference('SubCategLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $subcategLibraryExample1 = new LibraryExample();
+ $subcategLibraryExample1->setName('subcateg_example_one');
+ $subcategLibraryExample1->setVersion($subcategLibraryVersion1);
+ $subcategLibraryExample1->setPath('Examples/subcateg_example_one/subcateg_example_one.ino');
+ $subcategLibraryExample1->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($subcategLibraryExample1);
+
+ /*
+ * Mock a new library example
+ */
+ $subcategLibraryExample2 = new LibraryExample();
+ $subcategLibraryExample2->setName('subcateg_example_two');
+ $subcategLibraryExample2->setVersion($subcategLibraryVersion1);
+ $subcategLibraryExample2->setPath('Examples/experienceBased/Beginners/subcateg_example_two/subcateg_example_two.ino');
+ $subcategLibraryExample2->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($subcategLibraryExample2);
+
+ /*
+ * Mock a new library example
+ */
+ $subcategLibraryExample3 = new LibraryExample();
+ $subcategLibraryExample3->setName('subcateg_example_three');
+ $subcategLibraryExample3->setVersion($subcategLibraryVersion1);
+ $subcategLibraryExample3->setPath('Examples/experienceBased/Advanced/Experts/subcateg_example_three/subcateg_example_three.ino');
+ $subcategLibraryExample3->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($subcategLibraryExample3);
+
+ /*
+ * Get mock version 1.5.2 of Sub Category Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $subcategLibraryVersion2 */
+ $subcategLibraryVersion2 = $this->getReference('SubCategLibraryVersion2');
+
+ /*
+ * Mock a new library example
+ */
+ $subcategLibraryExample4 = new LibraryExample();
+ $subcategLibraryExample4->setName('subcateg_example_one');
+ $subcategLibraryExample4->setVersion($subcategLibraryVersion2);
+ $subcategLibraryExample4->setPath('Examples/subcateg_example_one/subcateg_example_one.ino');
+ $subcategLibraryExample4->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($subcategLibraryExample4);
+
+ /*
+ * Mock a new library example
+ */
+ $subcategLibraryExample5 = new LibraryExample();
+ $subcategLibraryExample5->setName('subcateg_example_two');
+ $subcategLibraryExample5->setVersion($subcategLibraryVersion2);
+ $subcategLibraryExample5->setPath('Examples/experienceBased/Beginners/subcateg_example_two/subcateg_example_two.ino');
+ $subcategLibraryExample5->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($subcategLibraryExample5);
+
+ /*
+ * Mock a new library example
+ */
+ $subcategLibraryExample6 = new LibraryExample();
+ $subcategLibraryExample6->setName('subcateg_example_three');
+ $subcategLibraryExample6->setVersion($subcategLibraryVersion2);
+ $subcategLibraryExample6->setPath('Examples/experienceBased/Advanced/Experts/subcateg_example_three/subcateg_example_three.ino');
+ $subcategLibraryExample6->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($subcategLibraryExample6);
+
+ /*
+ * Get Version 1.0.0 of Hidden Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $hiddenFilesLibraryVersion1 */
+ $hiddenFilesLibraryVersion1 = $this->getReference('HiddenLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $hiddenFilesLibraryExample = new LibraryExample();
+ $hiddenFilesLibraryExample->setName('hidden_files_example');
+ $hiddenFilesLibraryExample->setVersion($hiddenFilesLibraryVersion1);
+ $hiddenFilesLibraryExample->setPath('examples/hidden_files_example/hidden_files_example.ino');
+ $hiddenFilesLibraryExample->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($hiddenFilesLibraryExample);
+
+ /*
+ * Get Version 1.0.0 of Encode Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion1 */
+ $encodeLibraryVersion1 = $this->getReference('EncodeLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $encodeLibraryExample = new LibraryExample();
+ $encodeLibraryExample->setName('encoded_example');
+ $encodeLibraryExample->setVersion($encodeLibraryVersion1);
+ $encodeLibraryExample->setPath('examples/encoded_example/encoded_example.ino');
+ $encodeLibraryExample->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($encodeLibraryExample);
+
+ /*
+ * Get Version 1.0.0 of deleteMe Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion1 */
+ $deleteMeLibraryVersion1 = $this->getReference('deleteMeLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $deleteMeLibraryExample1 = new LibraryExample();
+ $deleteMeLibraryExample1->setName('deleteMe_example');
+ $deleteMeLibraryExample1->setVersion($deleteMeLibraryVersion1);
+ $deleteMeLibraryExample1->setPath('examples/deleteMe_example/deleteMe_example.ino');
+ $deleteMeLibraryExample1->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($deleteMeLibraryExample1);
+
+ /*
+ * Get Version 1.1.0 of deleteMe Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion2 */
+ $deleteMeLibraryVersion2 = $this->getReference('deleteMeLibraryVersion2');
+
+ /*
+ * Mock a new library example
+ */
+ $deleteMeLibraryExample2 = new LibraryExample();
+ $deleteMeLibraryExample2->setName('deleteMe_example');
+ $deleteMeLibraryExample2->setVersion($deleteMeLibraryVersion2);
+ $deleteMeLibraryExample2->setPath('examples/deleteMe_example/deleteMe_example.ino');
+ $deleteMeLibraryExample2->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($deleteMeLibraryExample2);
+
+ /*
+ * Get Version 1.0.0 of deleteLatestMe Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion1 */
+ $deleteLatestMeLibraryVersion1 = $this->getReference('deleteLatestMeLibraryVersion1');
+
+ /*
+ * Mock a new library example
+ */
+ $deleteLatestMeLibraryExample1 = new LibraryExample();
+ $deleteLatestMeLibraryExample1->setName('deleteLatestMe_example');
+ $deleteLatestMeLibraryExample1->setVersion($deleteLatestMeLibraryVersion1);
+ $deleteLatestMeLibraryExample1->setPath('examples/deleteLatestMe_example/deleteLatestMe_example.ino');
+ $deleteLatestMeLibraryExample1->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($deleteLatestMeLibraryExample1);
+
+ /*
+ * Get Version 1.1.0 of deleteLatestMe Library
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion2 */
+ $deleteLatestMeLibraryVersion2 = $this->getReference('deleteLatestMeLibraryVersion2');
+
+ /*
+ * Mock a new library example
+ */
+ $deleteLatestMeLibraryExample2 = new LibraryExample();
+ $deleteLatestMeLibraryExample2->setName('deleteLatestMe_example');
+ $deleteLatestMeLibraryExample2->setVersion($deleteLatestMeLibraryVersion2);
+ $deleteLatestMeLibraryExample2->setPath('examples/deleteLatestMe_example/deleteLatestMe_example.ino');
+ $deleteLatestMeLibraryExample2->setBoards(null);
+
+ /*
+ * Add newly created example to the database using the object manager interface
+ */
+ $objectManager->persist($deleteLatestMeLibraryExample2);
+
+ // From here on add the internal library examples. Only few are added.
+ $builtInLibs = [
+ "EEPROM" => ["eeprom_clear", "eeprom_read", "eeprom_write"],
+ "Robot_Control" => ["explore", "learn"],
+ "WiFi" => ["ConnectNoEncryption", "ScanNetworks", "WiFiPachubeClient", "WiFiUdpNtpClient", "WiFiWebClientRepeating",
+ "ConnectWithWEP", "SimpleWebServerWiFi", "WiFiPachubeClientString", "WiFiUdpSendReceiveString", "WiFiWebServer",
+ "ConnectWithWPA", "WiFiChatServer", "WiFiTwitterClient", "WiFiWebClient"]
+ ];
+ $builtInDefaultVersion = 'default';
+ foreach ($builtInLibs as $name => $examples) {
+ $builtInLibVersion = $this->getReference($name . ucfirst($builtInDefaultVersion) . 'Version');
+
+ foreach ($examples as $example) {
+ $builtInLibExample = new LibraryExample();
+ $builtInLibExample->setName($example);
+ $builtInLibExample->setVersion($builtInLibVersion);
+ $builtInLibExample->setPath('examples/' . $example . '/' . $example . '.ino');
+ $builtInLibExample->setBoards(null);
+
+ $objectManager->persist($builtInLibExample);
+ }
+ }
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+ }
+
+ /**
+ * Returns the order in which the current fixture will be loaded,
+ * compared to other fixture classes.
+ * Examples database data should be provided after the library data,
+ * because there is a foreign key constraint between them which should
+ * be satisfied.
+ *
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 7;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadPartnerData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadPartnerData.php
new file mode 100644
index 00000000..9ede584a
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadPartnerData.php
@@ -0,0 +1,57 @@
+setName('codebender');
+ $codebender->setAuthKey('youMustChangeThis');
+ $this->setReference('PartnerCodebender', $codebender);
+ $objectManager->persist($codebender);
+
+ // partner 2 : arduino.cc
+ $arduinoCc = new Partner();
+ $arduinoCc->setName('arduino.cc');
+ $arduinoCc->setAuthKey('authKey');
+ $this->setReference('PartnerArduinoCc', $arduinoCc);
+ $objectManager->persist($arduinoCc);
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+ }
+
+ /**
+ * Returns the order in which the current fixture will be loaded,
+ * compared to other fixture classes.
+ *
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 4;
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadPreferenceData.php b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadPreferenceData.php
new file mode 100644
index 00000000..3d52b246
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/DataFixtures/ORM/LoadPreferenceData.php
@@ -0,0 +1,169 @@
+getReference('PartnerCodebender');
+ $arduinoCc = $this->getReference('PartnerArduinoCc');
+
+ /**
+ * Get reference for our mock version data
+ */
+ /* @var \Codebender\LibraryBundle\Entity\Version $defaultLibraryVersion2 */
+ $defaultLibraryVersion = $this->getReference('defaultLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $dahLibraryVersion1 */
+ $dahLibraryVersion1 = $this->getReference('dynamicArrayHelperLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $multiInoLibraryVersion2 */
+ $multiInoLibraryVersion2 = $this->getReference('MultiInoLibraryVersion2');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $subcategLibraryVersion2 */
+ $subcategLibraryVersion2 = $this->getReference('SubCategLibraryVersion2');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $hiddenFilesLibraryVersion1 */
+ $hiddenFilesLibraryVersion1 = $this->getReference('HiddenLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $encodeLibraryVersion1 */
+ $encodeLibraryVersion1 = $this->getReference('EncodeLibraryVersion1');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $deleteMeLibraryVersion2 */
+ $deleteMeLibraryVersion2 = $this->getReference('deleteMeLibraryVersion2');
+
+ /* @var \Codebender\LibraryBundle\Entity\Version $deleteLatestMeLibraryVersion2 */
+ $deleteLatestMeLibraryVersion2 = $this->getReference('deleteLatestMeLibraryVersion2');
+
+ /*
+ * Add mock preference for partner: codebender
+ */
+ $preference1 = new Preference();
+ $preference1->setLibrary($defaultLibraryVersion->getLibrary());
+ $preference1->setVersion($defaultLibraryVersion);
+ $preference1->setPartner($codebender);
+ $objectManager->persist($preference1);
+
+ $preference2 = new Preference();
+ $preference2->setLibrary($dahLibraryVersion1->getLibrary());
+ $preference2->setVersion($dahLibraryVersion1);
+ $preference2->setPartner($codebender);
+ $objectManager->persist($preference2);
+
+ $preference3 = new Preference();
+ $preference3->setLibrary($multiInoLibraryVersion2->getLibrary());
+ $preference3->setVersion($multiInoLibraryVersion2);
+ $preference3->setPartner($codebender);
+ $objectManager->persist($preference3);
+
+ $preference4 = new Preference();
+ $preference4->setLibrary($subcategLibraryVersion2->getLibrary());
+ $preference4->setVersion($subcategLibraryVersion2);
+ $preference4->setPartner($codebender);
+ $objectManager->persist($preference4);
+
+ $preference5 = new Preference();
+ $preference5->setLibrary($hiddenFilesLibraryVersion1->getLibrary());
+ $preference5->setVersion($hiddenFilesLibraryVersion1);
+ $preference5->setPartner($codebender);
+ $objectManager->persist($preference5);
+
+ $preference6 = new Preference();
+ $preference6->setLibrary($encodeLibraryVersion1->getLibrary());
+ $preference6->setVersion($encodeLibraryVersion1);
+ $preference6->setPartner($codebender);
+ $objectManager->persist($preference6);
+
+ /*
+ * Add mock preference for partner: arduino.cc
+ */
+ $preference7 = new Preference();
+ $preference7->setLibrary($defaultLibraryVersion->getLibrary());
+ $preference7->setVersion($defaultLibraryVersion);
+ $preference7->setPartner($arduinoCc);
+ $objectManager->persist($preference7);
+
+ $preference8 = new Preference();
+ $preference8->setLibrary($dahLibraryVersion1->getLibrary());
+ $preference8->setVersion($dahLibraryVersion1);
+ $preference8->setPartner($arduinoCc);
+ $objectManager->persist($preference8);
+
+ $preference9 = new Preference();
+ $preference9->setLibrary($multiInoLibraryVersion2->getLibrary());
+ $preference9->setVersion($multiInoLibraryVersion2);
+ $preference9->setPartner($arduinoCc);
+ $objectManager->persist($preference9);
+
+ $preference10 = new Preference();
+ $preference10->setLibrary($subcategLibraryVersion2->getLibrary());
+ $preference10->setVersion($subcategLibraryVersion2);
+ $preference10->setPartner($arduinoCc);
+ $objectManager->persist($preference10);
+
+ $preference11 = new Preference();
+ $preference11->setLibrary($hiddenFilesLibraryVersion1->getLibrary());
+ $preference11->setVersion($hiddenFilesLibraryVersion1);
+ $preference11->setPartner($arduinoCc);
+ $objectManager->persist($preference11);
+
+ $preference12 = new Preference();
+ $preference12->setLibrary($encodeLibraryVersion1->getLibrary());
+ $preference12->setVersion($encodeLibraryVersion1);
+ $preference12->setPartner($arduinoCc);
+ $objectManager->persist($preference12);
+
+ $preference13 = new Preference();
+ $preference13->setLibrary($deleteMeLibraryVersion2->getLibrary());
+ $preference13->setVersion($deleteMeLibraryVersion2);
+ $preference13->setPartner($arduinoCc);
+ $objectManager->persist($preference13);
+
+ $preference14 = new Preference();
+ $preference14->setLibrary($deleteLatestMeLibraryVersion2->getLibrary());
+ $preference14->setVersion($deleteLatestMeLibraryVersion2);
+ $preference14->setPartner($arduinoCc);
+ $objectManager->persist($preference14);
+
+ /*
+ * After all fixture objects have been added to the ObjectManager (`persist` operation),
+ * it's time to flush the contents of the ObjectManager
+ */
+ $objectManager->flush();
+ }
+
+ /**
+ * Returns the order in which the current fixture will be loaded,
+ * compared to other fixture classes.
+ *
+ * @return int
+ */
+ public function getOrder()
+ {
+ return 9;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Entity/Architecture.php b/Symfony/src/Codebender/LibraryBundle/Entity/Architecture.php
new file mode 100644
index 00000000..85db4587
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Entity/Architecture.php
@@ -0,0 +1,70 @@
+id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ * @return Architecture
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function __toString()
+ {
+ return $this->getName();
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Entity/ExternalLibrary.php b/Symfony/src/Codebender/LibraryBundle/Entity/Library.php
similarity index 57%
rename from Symfony/src/Codebender/LibraryBundle/Entity/ExternalLibrary.php
rename to Symfony/src/Codebender/LibraryBundle/Entity/Library.php
index a2222ca3..8eb9511c 100644
--- a/Symfony/src/Codebender/LibraryBundle/Entity/ExternalLibrary.php
+++ b/Symfony/src/Codebender/LibraryBundle/Entity/Library.php
@@ -5,12 +5,16 @@
use Doctrine\ORM\Mapping as ORM;
/**
- * ExternalLibrary
+ * Library
*
- * @ORM\Table()
+ * @ORM\Table(
+ * uniqueConstraints={
+ * @ORM\UniqueConstraint(name="header_idx", columns={"default_header", "folder_name"})
+ * }
+ * )
* @ORM\Entity
*/
-class ExternalLibrary
+class Library
{
/**
* @var integer
@@ -24,16 +28,23 @@ class ExternalLibrary
/**
* @var string
*
- * @ORM\Column(name="humanName", type="string", length=255)
+ * @ORM\Column(name="name", type="string", length=255)
*/
- private $humanName;
+ private $name;
/**
* @var string
*
- * @ORM\Column(name="machineName", type="string", length=255)
+ * @ORM\Column(name="default_header", type="string", length=255)
*/
- private $machineName;
+ private $default_header;
+
+ /**
+ * @var string
+ *
+ * @ORM\Column(name="folder_name", type="string", length=255)
+ */
+ private $folder_name;
/**
* @var string
@@ -94,9 +105,9 @@ class ExternalLibrary
/**
* @var string
*
- * @ORM\Column(name="lastCommit", type="string", length=255, nullable = true)
+ * @ORM\Column(name="last_commit", type="string", length=255, nullable = true)
*/
- private $lastCommit;
+ private $last_commit;
/**
* @var string
@@ -106,11 +117,22 @@ class ExternalLibrary
private $url;
/**
- * @var string
+ * @ORM\OneToMany(targetEntity="Version", mappedBy="library")
+ */
+ private $versions;
+
+ /**
+ * @ORM\Column(name="is_built_in", type="boolean")
+ */
+ private $is_built_in = false;
+
+ /**
+ * @var integer
*
- * @ORM\Column(name="source_url", type="string", length=512, nullable = true)
+ * @ORM\OneToOne(targetEntity="Version")
+ * @ORM\JoinColumn(name="latest_version_id", referencedColumnName="id", nullable = false)
*/
- private $sourceUrl;
+ private $latest_version;
/**
* Get id
@@ -123,68 +145,91 @@ public function getId()
}
/**
- * Set humanName
+ * Set name
+ *
+ * @param string $name
+ * @return Library
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Get name
*
- * @param string $humanName
- * @return ExternalLibrary
+ * @return string
*/
- public function setHumanName($humanName)
+ public function getName()
{
- $this->humanName = $humanName;
-
+ return $this->name;
+ }
+
+ /**
+ * Set default_header
+ *
+ * @param string $defaultHeader
+ * @return Library
+ */
+ public function setDefaultHeader($defaultHeader)
+ {
+ $this->default_header = $defaultHeader;
+
return $this;
}
/**
- * Get humanName
+ * Get default_header
*
- * @return string
+ * @return string
*/
- public function getHumanName()
+ public function getDefaultHeader()
{
- return $this->humanName;
+ return $this->default_header;
}
/**
- * Set machineName
+ * Set folder_name
*
- * @param string $machineName
- * @return ExternalLibrary
+ * @param string $folderName
+ * @return Library
*/
- public function setMachineName($machineName)
+ public function setFolderName($folderName)
{
- $this->machineName = $machineName;
-
+ $this->folder_name = $folderName;
+
return $this;
}
/**
- * Get machineName
+ * Get folder_name
*
- * @return string
+ * @return string
*/
- public function getMachineName()
+ public function getFolderName()
{
- return $this->machineName;
+ return $this->folder_name;
}
/**
* Set description
*
* @param string $description
- * @return ExternalLibrary
+ * @return Library
*/
public function setDescription($description)
{
$this->description = $description;
-
+
return $this;
}
/**
* Get description
*
- * @return string
+ * @return string
*/
public function getDescription()
{
@@ -195,19 +240,19 @@ public function getDescription()
* Set owner
*
* @param string $owner
- * @return ExternalLibrary
+ * @return Library
*/
public function setOwner($owner)
{
$this->owner = $owner;
-
+
return $this;
}
/**
* Get owner
*
- * @return string
+ * @return string
*/
public function getOwner()
{
@@ -218,19 +263,19 @@ public function getOwner()
* Set repo
*
* @param string $repo
- * @return ExternalLibrary
+ * @return Library
*/
public function setRepo($repo)
{
$this->repo = $repo;
-
+
return $this;
}
/**
* Get repo
*
- * @return string
+ * @return string
*/
public function getRepo()
{
@@ -241,11 +286,12 @@ public function getRepo()
* Set branch
*
* @param string $branch
- * @return ExternalLibrary
+ * @return Version
*/
public function setBranch($branch)
{
$this->branch = $branch;
+
return $this;
}
@@ -263,11 +309,12 @@ public function getBranch()
* Set inRepoPath
*
* @param string $inRepoPath
- * @return ExternalLibrary
+ * @return Version
*/
public function setInRepoPath($inRepoPath)
{
$this->inRepoPath = $inRepoPath;
+
return $this;
}
@@ -285,11 +332,12 @@ public function getInRepoPath()
* Set notes
*
* @param string $notes
- * @return ExternalLibrary
+ * @return Library
*/
public function setNotes($notes)
{
$this->notes = $notes;
+
return $this;
}
@@ -307,19 +355,19 @@ public function getNotes()
* Set verified
*
* @param boolean $verified
- * @return ExternalLibrary
+ * @return Library
*/
public function setVerified($verified)
{
$this->verified = $verified;
-
+
return $this;
}
/**
* Get verified
*
- * @return boolean
+ * @return boolean
*/
public function getVerified()
{
@@ -330,7 +378,7 @@ public function getVerified()
* Set active
*
* @param boolean $active
- * @return ExternalLibrary
+ * @return Library
*/
public function setActive($active)
{
@@ -350,33 +398,33 @@ public function getActive()
}
/**
- * Set lastCommit
+ * Set last_commit
*
* @param string $lastCommit
- * @return ExternalLibrary
+ * @return Library
*/
public function setLastCommit($lastCommit)
{
- $this->lastCommit = $lastCommit;
+ $this->last_commit = $lastCommit;
return $this;
}
/**
- * Get verified
+ * Get last_commit
*
* @return string
*/
public function getLastCommit()
{
- return $this->lastCommit;
+ return $this->last_commit;
}
/**
* Set url
*
* @param string $url
- * @return ExternalLibrary
+ * @return Library
*/
public function setUrl($url)
{
@@ -394,28 +442,90 @@ public function getUrl()
{
return $this->url;
}
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->versions = new \Doctrine\Common\Collections\ArrayCollection();
+ }
/**
- * Set sourceUrl
+ * Add version
*
- * @param string $sourceUrl
- * @return ExternalLibrary
+ * @param \Codebender\LibraryBundle\Entity\Version $version
+ * @return Library
*/
- public function setSourceUrl($sourceUrl)
+ public function addVersion(\Codebender\LibraryBundle\Entity\Version $version)
{
- $this->sourceUrl = $sourceUrl;
+ $this->versions[] = $version;
return $this;
}
/**
- * Get sourceUrl
+ * Remove version
*
- * @return string
+ * @param \Codebender\LibraryBundle\Entity\Version $version
+ */
+ public function removeVersion(\Codebender\LibraryBundle\Entity\Version $version)
+ {
+ $this->versions->removeElement($version);
+ }
+
+ /**
+ * Get versions
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getVersions()
+ {
+ return $this->versions;
+ }
+
+ /**
+ * Return latest version
+ *
+ * @return Version
+ */
+ public function getLatestVersion()
+ {
+ return $this->latest_version;
+ }
+
+ /**
+ * Set latest version
+ *
+ * @param \Codebender\LibraryBundle\Entity\Version $latest_version
+ * @return Library
*/
- public function getSourceUrl()
+ public function setLatestVersion(\Codebender\LibraryBundle\Entity\Version $latest_version)
{
- return $this->sourceUrl;
+ $this->latest_version = $latest_version;
+
+ return $this;
+ }
+
+ /**
+ * Check whether it is built in
+ *
+ * @return boolean
+ */
+ public function isBuiltIn()
+ {
+ return $this->is_built_in;
+ }
+
+ /**
+ * Set whether it is built in
+ *
+ * @return Library
+ */
+ public function setIsBuiltIn($is_built_in)
+ {
+ $this->is_built_in = $is_built_in;
+
+ return $this;
}
/**
@@ -423,21 +533,22 @@ public function getSourceUrl()
*
* @return array
*/
- public function getLiraryMeta()
+ public function getLibraryMeta()
{
return array(
- 'humanName' => $this->getHumanName(),
+ 'name' => $this->getName(),
'description' => $this->getDescription(),
'verified' => $this->getVerified(),
'gitOwner' => $this->getOwner(),
'gitRepo' => $this->getRepo(),
'url' => $this->getUrl(),
'active' => $this->getActive(),
- 'sourceUrl' => $this->getSourceUrl(),
'gitBranch' => $this->getBranch(),
'gitLastCommit' => $this->getLastCommit(),
'gitInRepoPath' => $this->getInRepoPath(),
- 'libraryNotes' => $this->getNotes()
+ 'libraryNotes' => $this->getNotes(),
+ 'isBuiltIn' => $this->isBuiltIn(),
+ 'latestVersionName' => $this->getLatestVersion()->getVersion()
);
}
}
diff --git a/Symfony/src/Codebender/LibraryBundle/Entity/Example.php b/Symfony/src/Codebender/LibraryBundle/Entity/LibraryExample.php
similarity index 69%
rename from Symfony/src/Codebender/LibraryBundle/Entity/Example.php
rename to Symfony/src/Codebender/LibraryBundle/Entity/LibraryExample.php
index 480dcce2..ceea7170 100644
--- a/Symfony/src/Codebender/LibraryBundle/Entity/Example.php
+++ b/Symfony/src/Codebender/LibraryBundle/Entity/LibraryExample.php
@@ -5,12 +5,14 @@
use Doctrine\ORM\Mapping as ORM;
/**
- * Example
+ * LibraryExample
*
- * @ORM\Table()
* @ORM\Entity
+ * @ORM\Table(
+ * indexes={@ORM\Index(name="version_idx", columns={"version_id"})}
+ * )
*/
-class Example
+class LibraryExample
{
/**
* @var integer
@@ -21,6 +23,14 @@ class Example
*/
private $id;
+ /**
+ * @var Version
+ *
+ * @ORM\ManyToOne(targetEntity="Version", inversedBy="libraryExamples")
+ * @ORM\JoinColumn(name="version_id", referencedColumnName="id")
+ */
+ private $version;
+
/**
* @var string
*
@@ -28,11 +38,6 @@ class Example
*/
private $name;
- /**
- * @ORM\ManyToOne(targetEntity="Codebender\LibraryBundle\Entity\ExternalLibrary")
- **/
- private $library;
-
/**
* @var string
*
@@ -47,6 +52,7 @@ class Example
*/
private $boards;
+
/**
* Get id
*
@@ -61,12 +67,12 @@ public function getId()
* Set name
*
* @param string $name
- * @return Example
+ * @return LibraryExample
*/
public function setName($name)
{
$this->name = $name;
-
+
return $this;
}
@@ -80,39 +86,16 @@ public function getName()
return $this->name;
}
- /**
- * Set library
- *
- * @param ExternalLibrary $library
- * @return Example
- */
- public function setLibrary($library)
- {
- $this->library = $library;
-
- return $this;
- }
-
- /**
- * Get library
- *
- * @return ExternalLibrary
- */
- public function getLibrary()
- {
- return $this->library;
- }
-
/**
* Set path
*
* @param string $path
- * @return Example
+ * @return LibraryExample
*/
public function setPath($path)
{
$this->path = $path;
-
+
return $this;
}
@@ -130,12 +113,12 @@ public function getPath()
* Set boards
*
* @param string $boards
- * @return Example
+ * @return LibraryExample
*/
public function setBoards($boards)
{
$this->boards = $boards;
-
+
return $this;
}
@@ -149,4 +132,26 @@ public function getBoards()
return $this->boards;
}
+ /**
+ * Set version
+ *
+ * @param \Codebender\LibraryBundle\Entity\Version $version
+ * @return LibraryExample
+ */
+ public function setVersion(\Codebender\LibraryBundle\Entity\Version $version = null)
+ {
+ $this->version = $version;
+
+ return $this;
+ }
+
+ /**
+ * Get version
+ *
+ * @return \Codebender\LibraryBundle\Entity\Version
+ */
+ public function getVersion()
+ {
+ return $this->version;
+ }
}
diff --git a/Symfony/src/Codebender/LibraryBundle/Entity/Partner.php b/Symfony/src/Codebender/LibraryBundle/Entity/Partner.php
new file mode 100644
index 00000000..b0829949
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Entity/Partner.php
@@ -0,0 +1,141 @@
+id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ * @return Partner
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set auth_key
+ *
+ * @param string $authKey
+ * @return Partner
+ */
+ public function setAuthKey($authKey)
+ {
+ $this->auth_key = $authKey;
+
+ return $this;
+ }
+
+ /**
+ * Get auth_key
+ *
+ * @return string
+ */
+ public function getAuthKey()
+ {
+ return $this->auth_key;
+ }
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->preferences = new \Doctrine\Common\Collections\ArrayCollection();
+ }
+
+ /**
+ * Add preference
+ *
+ * @param \Codebender\LibraryBundle\Entity\Preference $preference
+ * @return Partner
+ */
+ public function addPreference(\Codebender\LibraryBundle\Entity\Preference $preference)
+ {
+ $this->preferences[] = $preference;
+
+ return $this;
+ }
+
+ /**
+ * Remove preference
+ *
+ * @param \Codebender\LibraryBundle\Entity\Preference $preference
+ */
+ public function removePreference(\Codebender\LibraryBundle\Entity\Preference $preference)
+ {
+ $this->preferences->removeElement($preference);
+ }
+
+ /**
+ * Get preferences
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getPreferences()
+ {
+ return $this->preferences;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Entity/Preference.php b/Symfony/src/Codebender/LibraryBundle/Entity/Preference.php
new file mode 100644
index 00000000..a6c36ca4
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Entity/Preference.php
@@ -0,0 +1,128 @@
+id;
+ }
+
+ /**
+ * Set library
+ *
+ * @param \Codebender\LibraryBundle\Entity\Library $library
+ * @return Preference
+ */
+ public function setLibrary(\Codebender\LibraryBundle\Entity\Library $library = null)
+ {
+ $this->library = $library;
+
+ return $this;
+ }
+
+ /**
+ * Get library
+ *
+ * @return \Codebender\LibraryBundle\Entity\Library
+ */
+ public function getLibrary()
+ {
+ return $this->library;
+ }
+
+ /**
+ * Set partner
+ *
+ * @param \Codebender\LibraryBundle\Entity\Partner $partner
+ * @return Preference
+ */
+ public function setPartner(\Codebender\LibraryBundle\Entity\Partner $partner = null)
+ {
+ $this->partner = $partner;
+
+ return $this;
+ }
+
+ /**
+ * Get partner
+ *
+ * @return \Codebender\LibraryBundle\Entity\Partner
+ */
+ public function getPartner()
+ {
+ return $this->partner;
+ }
+
+ /**
+ * Set version
+ *
+ * @param \Codebender\LibraryBundle\Entity\Version $version
+ * @return Preference
+ */
+ public function setVersion(\Codebender\LibraryBundle\Entity\Version $version = null)
+ {
+ $this->version = $version;
+
+ return $this;
+ }
+
+ /**
+ * Get version
+ *
+ * @return \Codebender\LibraryBundle\Entity\Version
+ */
+ public function getVersion()
+ {
+ return $this->version;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Entity/Version.php b/Symfony/src/Codebender/LibraryBundle/Entity/Version.php
new file mode 100644
index 00000000..e28540b4
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Entity/Version.php
@@ -0,0 +1,352 @@
+libraryExamples = new \Doctrine\Common\Collections\ArrayCollection();
+ $this->architectures = new \Doctrine\Common\Collections\ArrayCollection();
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set version
+ *
+ * @param string $version
+ * @return Version
+ */
+ public function setVersion($version)
+ {
+ $this->version = $version;
+
+ return $this;
+ }
+
+ /**
+ * Get version
+ *
+ * @return string
+ */
+ public function getVersion()
+ {
+ return $this->version;
+ }
+
+ /**
+ * Set description
+ *
+ * @param string $description
+ * @return Version
+ */
+ public function setDescription($description)
+ {
+ $this->description = $description;
+
+ return $this;
+ }
+
+ /**
+ * Get description
+ *
+ * @return string
+ */
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ /**
+ * Set notes
+ *
+ * @param string $notes
+ * @return Version
+ */
+ public function setNotes($notes)
+ {
+ $this->notes = $notes;
+
+ return $this;
+ }
+
+ /**
+ * Get notes
+ *
+ * @return string
+ */
+ public function getNotes()
+ {
+ return $this->notes;
+ }
+
+ /**
+ * Set sourceUrl
+ *
+ * @param string $sourceUrl
+ * @return Version
+ */
+ public function setSourceUrl($sourceUrl)
+ {
+ $this->sourceUrl = $sourceUrl;
+
+ return $this;
+ }
+
+ /**
+ * Get sourceUrl
+ *
+ * @return string
+ */
+ public function getSourceUrl()
+ {
+ return $this->sourceUrl;
+ }
+
+ /**
+ * Set releaseCommit
+ *
+ * @param string $releaseCommit
+ * @return Version
+ */
+ public function setReleaseCommit($releaseCommit)
+ {
+ $this->releaseCommit = $releaseCommit;
+
+ return $this;
+ }
+
+ /**
+ * Get releaseCommit
+ *
+ * @return string
+ */
+ public function getReleaseCommit()
+ {
+ return $this->releaseCommit;
+ }
+
+ /**
+ * Set folderName
+ *
+ * @param string $folderName
+ * @return Version
+ */
+ public function setFolderName($folderName)
+ {
+ $this->folderName = $folderName;
+
+ return $this;
+ }
+
+ /**
+ * Get folderName
+ *
+ * @return string
+ */
+ public function getFolderName()
+ {
+ return $this->folderName;
+ }
+
+ /**
+ * Set library
+ *
+ * @param \Codebender\LibraryBundle\Entity\Library $library
+ * @return Version
+ */
+ public function setLibrary(\Codebender\LibraryBundle\Entity\Library $library = null)
+ {
+ $this->library = $library;
+
+ return $this;
+ }
+
+ /**
+ * Get library
+ *
+ * @return \Codebender\LibraryBundle\Entity\Library
+ */
+ public function getLibrary()
+ {
+ return $this->library;
+ }
+
+ /**
+ * Add libraryExample
+ *
+ * @param \Codebender\LibraryBundle\Entity\LibraryExample $libraryExample
+ * @return Version
+ */
+ public function addLibraryExample(\Codebender\LibraryBundle\Entity\LibraryExample $libraryExample)
+ {
+ $this->libraryExamples[] = $libraryExample;
+
+ return $this;
+ }
+
+ /**
+ * Remove libraryExample
+ *
+ * @param \Codebender\LibraryBundle\Entity\LibraryExample $libraryExample
+ */
+ public function removeLibraryExample(\Codebender\LibraryBundle\Entity\LibraryExample $libraryExample)
+ {
+ $this->libraryExamples->removeElement($libraryExample);
+ }
+
+ /**
+ * Get libraryExamples
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getLibraryExamples()
+ {
+ return $this->libraryExamples;
+ }
+
+ /**
+ * Add architecture
+ *
+ * @param \Codebender\LibraryBundle\Entity\Architecture $architecture
+ * @return Version
+ */
+ public function addArchitecture(\Codebender\LibraryBundle\Entity\Architecture $architecture)
+ {
+ $this->architectures[] = $architecture;
+
+ return $this;
+ }
+
+ /**
+ * Remove architecture
+ *
+ * @param \Codebender\LibraryBundle\Entity\Architecture $architecture
+ */
+ public function removeArchitecture(\Codebender\LibraryBundle\Entity\Architecture $architecture)
+ {
+ $this->architectures->removeElement($architecture);
+ }
+
+ /**
+ * Get architectures
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getArchitectures()
+ {
+ return $this->architectures;
+ }
+
+ /**
+ * Get the metadata of the version
+ *
+ * @return array
+ */
+ public function getVersionMeta()
+ {
+ return array(
+ 'version' => $this->getVersion(),
+ 'description' => $this->getDescription(),
+ 'notes' => $this->getNotes(),
+ 'sourceUrl' => $this->getSourceUrl(),
+ 'architectures' => $this->getArchitectures()->toArray()
+ );
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/EventListener/AuthenticationListener.php b/Symfony/src/Codebender/LibraryBundle/EventListener/AuthenticationListener.php
index 66a8f729..84942e6f 100644
--- a/Symfony/src/Codebender/LibraryBundle/EventListener/AuthenticationListener.php
+++ b/Symfony/src/Codebender/LibraryBundle/EventListener/AuthenticationListener.php
@@ -4,19 +4,23 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\DependencyInjection\ContainerInterface;
class AuthenticationListener
{
- private $authorizationKey;
+ private $v1AuthorizationKey;
+ private $container;
/**
* AuthenticationListener constructor.
*
* @param string $authorizationKey
+ * @param ContainerInterface $container
*/
- public function __construct($authorizationKey)
+ public function __construct($authorizationKey, ContainerInterface $container)
{
- $this->authorizationKey = $authorizationKey;
+ $this->v1AuthorizationKey = $authorizationKey;
+ $this->container = $container;
}
/**
@@ -28,12 +32,16 @@ public function __construct($authorizationKey)
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
+ /* @var \Codebender\LibraryBundle\Handler\ApiHandler $apiHandler */
+ $apiHandler = $this->container->get('codebender_library.apiHandler');
$routeParameters = $request->attributes->get('_route_params');
if (!empty($routeParameters)
&& array_key_exists('authorizationKey', $routeParameters)
- && $routeParameters['authorizationKey'] != $this->authorizationKey
+ // Support both v1 and v2 authentication methods
+ && $routeParameters['authorizationKey'] != $this->v1AuthorizationKey
+ && !$apiHandler->isAuthenticatedPartner($routeParameters['authorizationKey'])
) {
$event->setResponse(new Response(
json_encode(['success' => false, 'message' => '[eratosthenes] Invalid authorization key.'])
diff --git a/Symfony/src/Codebender/LibraryBundle/Form/NewLibraryForm.php b/Symfony/src/Codebender/LibraryBundle/Form/NewLibraryFormV2.php
similarity index 51%
rename from Symfony/src/Codebender/LibraryBundle/Form/NewLibraryForm.php
rename to Symfony/src/Codebender/LibraryBundle/Form/NewLibraryFormV2.php
index 0a4fd5c7..ccb2b83f 100644
--- a/Symfony/src/Codebender/LibraryBundle/Form/NewLibraryForm.php
+++ b/Symfony/src/Codebender/LibraryBundle/Form/NewLibraryFormV2.php
@@ -4,7 +4,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
-class NewLibraryForm extends AbstractType{
+class NewLibraryFormV2 extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{
@@ -14,13 +14,25 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('GitRepo', 'hidden')
->add('GitBranch', 'hidden')
->add('GitPath', 'hidden')
+ ->add('GitRelease', 'hidden')
->add('Zip', 'file')
- ->add('HumanName', 'text', array('label' => 'Human Name: '))
- ->add('MachineName', 'hidden')
- ->add('Description', 'text', array('label' => 'Description: '))
+ ->add('Name', 'text', array('label' => 'Human Name: '))
+ ->add('DefaultHeader', 'hidden')
+ ->add('Notes', 'textarea', array('label' => 'Notes for the library: ', 'required' => false, 'attr' => array('placeholder' => 'Notes about the library')))
+ ->add('Version', 'text', array('label' => 'Version: '))
+ ->add('Description', 'text', array('label' => 'Library Description: '))
+ ->add('VersionDescription', 'text', array('label' => 'Version Description: '))
+ ->add('VersionNotes', 'textarea', array('label' => 'Notes for the version: ', 'required' => false, 'attr' => array('placeholder' => 'Notes about the version')))
+ ->add('Architectures', 'entity',
+ array(
+ 'class' => 'CodebenderLibraryBundle:Architecture',
+ 'expanded' => true,
+ 'multiple' => true
+ )
+ )
+ ->add('IsLatestVersion', 'checkbox', array('label' => 'Latest Version?', 'required' => false))
->add('Url', 'text', array('label' => 'Info Url: ', 'required' => false, 'attr' => array('placeholder' => 'The url where you can find info about the library')))
->add('SourceUrl', 'text', array('label' => 'Source Url: ', 'required' => false, 'attr' => array('placeholder' => 'A link to the actual code of the library (i.e. zip, etc)')))
- ->add('Notes', 'textarea', array('label' => 'Notes for the library: ', 'required' => false, 'attr' => array('placeholder' => 'Notes for the people of codebender')))
->add('Go', 'submit', array('attr' => array('class' => 'btn')));
}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/AbstractApiCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/AbstractApiCommand.php
new file mode 100644
index 00000000..5337da52
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/AbstractApiCommand.php
@@ -0,0 +1,27 @@
+entityManager = $entityManager;
+ $this->container = $containerInterface;
+ }
+
+ /**
+ * This is the main execution of the API that returns the API response.
+ *
+ * @param $content
+ * @return mixed
+ */
+ abstract function execute($content);
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/CheckGithubUpdatesCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/CheckGithubUpdatesCommand.php
new file mode 100644
index 00000000..d6b0178f
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/CheckGithubUpdatesCommand.php
@@ -0,0 +1,223 @@
+entityManager->getRepository('CodebenderLibraryBundle:Library')->findAll();
+
+ foreach ($libraries as $lib) {
+ if (!$this->isActive($lib) || !$this->hasGit($lib)) {
+ continue;
+ }
+
+ if (!$this->isUpdated($lib)) {
+ $needToUpdate[] = $this->getLibrarySummary($lib);
+ }
+ }
+
+ if (empty($needToUpdate)) {
+ return ['success' => true, 'message' => 'No external libraries need to be updated'];
+ }
+
+ return [
+ 'success' => true,
+ 'message' => count($needToUpdate) . " external libraries need to be updated",
+ 'libraries' => $needToUpdate
+ ];
+ }
+
+ /**
+ * This method toggles the active status of a library.
+ *
+ * @param $defaultHeader
+ */
+ public function toggleLibraryStatus($defaultHeader)
+ {
+ $entityManager = $this->entityManager;
+ $library = $entityManager
+ ->getRepository('CodebenderLibraryBundle:Library')
+ ->findBy(array('default_header' => $defaultHeader));
+
+ // Do nothing if the library does not exist
+ if (count($library) < 1) {
+ return;
+ }
+
+ $library = $library[0];
+ $currentStatus = $library->getActive();
+ $library->setActive(!$currentStatus);
+ $entityManager->persist($library);
+ $entityManager->flush();
+ }
+
+ /**
+ * This method checks if a given library is updated or not.
+ *
+ * @param $library
+ * @return bool
+ */
+ private function isUpdated($library)
+ {
+ $gitOwner = $library->getOwner();
+ $gitRepo = $library->getRepo();
+ $branch = (string)$library->getBranch(); // not providing any branch will make git return the commits of the default branch
+ $directoryInRepo = (string)$library->getInRepoPath();
+
+ $lastCommitFromGithub = $this->getLastCommitFromGithub($gitOwner, $gitRepo, $branch, $directoryInRepo);
+ return $lastCommitFromGithub === $library->getLastCommit();
+ }
+
+ /**
+ * This method returns a summary of the given library.
+ *
+ * @param $library
+ * @return array
+ */
+ private function getLibrarySummary($library)
+ {
+ return [
+ 'Machine Name' => $library->getDefaultHeader(),
+ 'Human Name' => $library->getName(),
+ 'Git Owner' => $library->getOwner(),
+ 'Git Repo' => $library->getRepo(),
+ 'Git Branch' => $library->getBranch(),
+ 'Path in Git Repo' => $library->getInRepoPath()
+ ];
+ }
+
+ /**
+ * This method checks if a given library is active.
+ *
+ * @param $library
+ * @return bool
+ */
+ private function isActive($library)
+ {
+ return $library->getActive();
+ }
+
+ /**
+ * This method checks if a given library has a git repo.
+ *
+ * @param $library
+ * @return bool
+ */
+ private function hasGit($library)
+ {
+ $gitOwner = $library->getOwner();
+ $gitRepo = $library->getRepo();
+ return ($gitOwner !== null && $gitRepo !== null);
+ }
+
+ /**
+ * Fetches the last commit sha of a repo. `sha` parameter can either be the name of a branch, or a commit
+ * sha. In the first case, the commit sha's of the branch are returned. In the second case, the commit sha's
+ * of the default branch are returned, as long as the have been written after the provided commit.
+ * Not providing any sha/branch will make Git API return the list of commits for the default branch.
+ * The API can also use a path parameter, in which case only commits that affect a specific directory are returned.
+ *
+ * @param $gitOwner
+ * @param $gitRepo
+ * @param string $sha
+ * @param string $path
+ * @return mixed
+ */
+ private function getLastCommitFromGithub($gitOwner, $gitRepo, $sha = '', $path = '')
+ {
+ /*
+ * See the docs here https://developer.github.com/v3/repos/commits/
+ * for more info on the json returned.
+ */
+ $url = "https://api.github.com/repos/" . $gitOwner . "/" . $gitRepo . "/commits";
+ $queryParams = '';
+ if ($sha != '') {
+ $queryParams = "?sha=" . $sha;
+ }
+ if ($path != '') {
+ $queryParams .= "&path=$path";
+ }
+
+ $lastCommitResponse = $this->curlGitRequest($url, $queryParams);
+
+ return $lastCommitResponse[0]['sha'];
+ }
+
+ private function curlRequest($url, $post_request_data = null, $http_header = null)
+ {
+ $curl_req = curl_init();
+ curl_setopt_array($curl_req, array(
+ CURLOPT_URL => $url,
+ CURLOPT_HEADER => 0,
+ CURLOPT_RETURNTRANSFER => 1,
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_SSL_VERIFYHOST => 0,
+ ));
+ if ($post_request_data !== null) {
+ curl_setopt($curl_req, CURLOPT_POSTFIELDS, $post_request_data);
+ }
+
+ if ($http_header !== null) {
+ curl_setopt($curl_req, CURLOPT_HTTPHEADER, $http_header);
+ }
+
+ $contents = curl_exec($curl_req);
+
+ curl_close($curl_req);
+ return $contents;
+ }
+
+ /**
+ * A wrapper for the curlRequest function which adds Github authentication
+ * to the Github API request
+ * Returns the json decoded Github response.
+ *
+ * @param string $url The requested url
+ * @param string $queryParams Additional query parameters to be added to the request url
+ * @return mixed
+ */
+ private function curlGitRequest($url, $queryParams = '')
+ {
+ $clientId = $this->container->getParameter('github_app_client_id');
+ $clientSecret = $this->container->getParameter('github_app_client_secret');
+ $githubAppName = $this->container->getParameter('github_app_name');
+
+ $requestUrl = $url . "?client_id=" . $clientId . "&client_secret=" . $clientSecret;
+ if ($queryParams != '') {
+ $requestUrl = $url . $queryParams . "&client_id=" . $clientId . "&client_secret=" . $clientSecret;
+ }
+ /*
+ * Note: The user-agent MUST be set to a valid value, otherwise the request will be rejected. One of the
+ * suggested values is the application name.
+ * One more thing that must be set on the headers, is the version of the API, which will offer stability
+ * to the application, in case of future Github API updates.
+ */
+ $jsonDecodedContent = json_decode(
+ $this->curlRequest(
+ $requestUrl,
+ null,
+ ['User-Agent: ' . $githubAppName, 'Accept: application/vnd.github.v3.json']
+ ),
+ true
+ );
+
+ return $jsonDecodedContent;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/DeleteLibraryApiCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/DeleteLibraryApiCommand.php
new file mode 100644
index 00000000..d861971e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/DeleteLibraryApiCommand.php
@@ -0,0 +1,143 @@
+ false, "message" => "You need to specify which library version to delete."];
+ }
+
+ $libraryName = $content['library'];
+ $versionName = $content['version'];
+
+ $this->apiHandler = $this->container->get('codebender_library.apiHandler');
+ $this->fileSystem = new Filesystem();
+
+ /* @var \Codebender\LibraryBundle\Entity\Library $library */
+ $library = $this->apiHandler->getLibraryFromDefaultHeader($libraryName);
+ if (is_null($library)) {
+ return ["success" => false, "message" => "There is no library called $libraryName to delete."];
+ }
+
+ $version = $this->apiHandler->getVersionFromDefaultHeader($libraryName, $versionName);
+ if (is_null($version)) {
+ return ["success" => false, "message" => "There is no version $versionName for library called $libraryName to delete."];
+ }
+
+ // If the user is deleting the latest version of the library and we need to re-assign the latest version
+ if ($version === $library->getLatestVersion() && sizeof($library->getVersions()) > 1) {
+
+ // The user did not specify the next latest version
+ if (!array_key_exists('nextLatestVersion', $content)) {
+ return ["success" => false, "message" => "You need to specify the next latest version of the library $libraryName."];
+ }
+
+ $nextLatestVersionName = $content['nextLatestVersion'];
+ $nextLatestVersion = $this->apiHandler->getVersionFromDefaultHeader($libraryName, $nextLatestVersionName);
+
+ // The user specified the next latest version but the specified version does not exist
+ if (is_null($nextLatestVersion)) {
+ return ["success" => false, "message" => "The next latest version $nextLatestVersionName does not exist."];
+ }
+
+ $this->setNewLatestLibrary($library, $nextLatestVersion);
+ }
+
+ $libraryFolderName = $library->getFolderName();
+ $versionFolderName = $version->getFolderName();
+
+ $this->setNullToVersionLibrary($version);
+
+ $this->removeVersionExamples($version);
+ $this->removeRelatedPreference($version);
+ if (sizeof($library->getVersions()) === 1) {
+ $this->removeLibrary($library);
+ $dir = $libraryFolderName;
+ } else {
+ $dir = "$libraryFolderName/$versionFolderName";
+ }
+ $this->removeVersion($version);
+
+ try {
+ $this->entityManager->flush();
+ $this->removeLibraryDirectory($dir);
+ } catch (Exception $e) {
+ return ["success" => false, "message" => $e->getMessage()];
+ }
+
+ return ["success" => true, "message" => "Version $versionName of the library $libraryName has been deleted successfully."];
+ }
+
+ private function removeVersionExamples($version)
+ {
+ $examples = $version->getLibraryExamples();
+ foreach ($examples as $example) {
+ $this->entityManager->remove($example);
+ }
+ }
+
+ private function removeVersion($version)
+ {
+ $this->entityManager->remove($version);
+ }
+
+ private function removeLibrary($library)
+ {
+ $this->entityManager->remove($library);
+ }
+
+ private function setNullToVersionLibrary($version)
+ {
+ // This is to escape foreign key constraint.
+ $version->setLibrary(null);
+ $this->entityManager->persist($version);
+ $this->entityManager->flush();
+ }
+
+ private function setNewLatestLibrary(Library $library, Version $nextLatestVersion)
+ {
+ $library->setLatestVersion($nextLatestVersion);
+ $library->setLastCommit($nextLatestVersion->getReleaseCommit());
+ $this->entityManager->persist($library);
+ }
+
+ private function removeRelatedPreference($version)
+ {
+ $preferences = $this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Preference')
+ ->createQueryBuilder('p')
+ ->where('p.version = :version')
+ ->setParameters([':version' => $version->getId()])
+ ->getQuery()
+ ->getResult();
+
+ foreach ($preferences as $preference) {
+ $this->entityManager->remove($preference);
+ }
+ }
+
+ private function removeLibraryDirectory($dir)
+ {
+ $baseDir = $this->container->getParameter('external_libraries_v2');
+ $targetDir = "$baseDir/$dir";
+ if (!is_dir($targetDir)) {
+ throw new InvalidArgumentException("$targetDir does not exist.");
+ }
+ $this->fileSystem->remove($targetDir);
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchApiCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchApiCommand.php
new file mode 100644
index 00000000..cd33106a
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchApiCommand.php
@@ -0,0 +1,178 @@
+ false, "message" => "You need to specify which library to fetch."];
+ }
+
+ $content = $this->setDefault($content);
+ $filename = $content['library'];
+
+ $last_slash = strrpos($filename, "/");
+ if ($last_slash !== false) {
+ $filename = substr($filename, $last_slash + 1);
+ }
+
+ $this->apiHandler = $this->container->get('codebender_library.apiHandler');
+
+ $externalLibrariesPath = $this->container->getParameter('external_libraries_v2');
+
+ $finder = new Finder();
+ $exampleFinder = new Finder();
+
+ //TODO handle the case of different .h filenames and folder names
+ $reservedNames = ["ArduinoRobot" => "Robot_Control", "ArduinoRobotMotorBoard" => "Robot_Motor",
+ "BlynkSimpleSerial" => "BlynkSimpleEthernet", "BlynkSimpleCC3000" => "BlynkSimpleEthernet"];
+
+ if (array_key_exists($filename, $reservedNames)) {
+ $filename = $reservedNames[$filename];
+ }
+
+ if (!$this->apiHandler->isLibrary($filename, $content['disabled'])) {
+ return ["success" => false, "message" => "No Library named " . $filename . " found."];
+ }
+
+ // check if requested (if any) version is valid
+ if ($content['version'] !== null && !$this->apiHandler->libraryVersionExists($filename, $content['version'])) {
+ return [
+ 'success' => false,
+ 'message' => 'No files for Library named `' . $filename . '` with version `' . $content['version'] . '` found.'
+ ];
+ }
+
+ $versionObjects = $this->apiHandler->getAllVersionsFromDefaultHeader($filename);
+
+ // fetch default version
+ // if rendering view, fetch all versions
+ // if specifically asked for a certain version, fetch that version
+ // else if specifically asked for latest version, fetch latest version
+ $versions = [$this->apiHandler->fetchPartnerDefaultVersion($this->getRequest()->get('authorizationKey'), $filename)];
+ if ($content['renderView'] && $content['version'] === null) {
+ $versions = $versionObjects->toArray();
+ }
+ if ($content['version'] !== null) {
+ $versionsCollection = $versionObjects->filter(function ($version) use ($content) {
+ return $version->getVersion() === $content['version'];
+ });
+ $versions = $versionsCollection->toArray();
+ }
+ if ($content['latest']) {
+ $lib = $this->apiHandler->getLibraryFromDefaultHeader($filename);
+ $versions = [$lib->getLatestVersion()];
+ }
+
+ if (array_key_exists('v1', $content) && $content['v1']) {
+ // fetch library files for each version
+ $response = [];
+ $examples = [];
+
+ $version = $this->apiHandler->fetchPartnerDefaultVersion($this->getRequest()->get('authorizationKey'), $filename);
+
+ /* @var Version $version */
+ $libraryPath = $externalLibrariesPath . "/" . $filename . "/" . $version->getFolderName();
+
+ // fetch library files for this version
+ $fetchResponse = $this->apiHandler->fetchLibraryFiles($finder->create(), $libraryPath);
+ if (!empty($fetchResponse)) {
+ $response = $fetchResponse;
+ }
+
+ if ($content['renderView']) {
+ // fetch example files for this version if it's rendering view
+ $exampleResponse = $this->apiHandler->fetchLibraryExamples($exampleFinder->create(), $libraryPath);
+ if (!empty($exampleResponse)) {
+ $examples[$version->getVersion()] = $exampleResponse;
+ }
+ }
+
+ if ($content['renderView']) {
+ $externalLibrary = $this->entityManager->getRepository('CodebenderLibraryBundle:Library')
+ ->findOneBy(array('default_header' => $filename));
+ $filename = $externalLibrary->getDefaultHeader();
+ $meta = $externalLibrary->getLibraryMeta();
+
+ $result = [
+ 'success' => true,
+ 'library' => $filename,
+ 'files' => $response,
+ 'examples' => $examples,
+ 'meta' => $meta
+ ];
+ } else {
+ $result = ['success' => true, 'message' => 'Library found', 'files' => $response];
+ }
+ } else {
+ // fetch library files for each version
+ $response = [];
+ $examples = [];
+ foreach ($versions as $version) {
+ /* @var Version $version */
+ $libraryPath = $externalLibrariesPath . "/" . $filename . "/" . $version->getFolderName();
+ // fetch library files for this version
+ $fetchResponse = $this->apiHandler->fetchLibraryFiles($finder->create(), $libraryPath);
+ if (!empty($fetchResponse)) {
+ $response[$version->getVersion()] = $fetchResponse;
+ }
+ if ($content['renderView']) {
+ // fetch example files for this version if it's rendering view
+ $exampleResponse = $this->apiHandler->fetchLibraryExamples($exampleFinder->create(), $libraryPath);
+ if (!empty($exampleResponse)) {
+ $examples[$version->getVersion()] = $exampleResponse;
+ }
+ }
+ }
+ if ($content['renderView']) {
+ $externalLibrary = $this->entityManager->getRepository('CodebenderLibraryBundle:Library')
+ ->findOneBy(array('default_header' => $filename));
+ $filename = $externalLibrary->getDefaultHeader();
+ $meta = $externalLibrary->getLibraryMeta();
+ $versions = array_map(
+ function ($version) {
+ return $version->getVersionMeta();
+ },
+ $versions
+ );
+ $result = [
+ 'success' => true,
+ 'library' => $filename,
+ 'versions' => $versions,
+ 'files' => $response,
+ 'examples' => $examples,
+ 'meta' => $meta
+ ];
+ } else {
+ $result = ['success' => true, 'message' => 'Library found', 'files' => $response];
+ }
+ }
+
+ return $result;
+ }
+
+ private function setDefault($content)
+ {
+ $content['disabled'] = (array_key_exists('disabled', $content) ? $content['disabled'] : false);
+ $content['version'] = (array_key_exists('version', $content) ? $content['version'] : null);
+ $content['latest'] = (array_key_exists('latest', $content) ? $content['latest'] : false);
+ $content['renderView'] = (array_key_exists('renderView', $content) ? $content['renderView'] : false);
+ if (!array_key_exists('disabled', $content)) {
+ $content['disabled'] = false;
+ }
+ if (!array_key_exists('version', $content)) {
+ $content['version'] = null;
+ }
+ if (!array_key_exists('renderView', $content)) {
+ $content['renderView'] = false;
+ }
+ return $content;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchLatestApiCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchLatestApiCommand.php
new file mode 100644
index 00000000..88708729
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/FetchLatestApiCommand.php
@@ -0,0 +1,21 @@
+ false, 'message' => 'Wrong data'];
+ }
+
+ $content['latest'] = true;
+ $content['version'] = null;
+ $fetchApiCommand = new FetchApiCommand($this->entityManager, $this->container);
+ return $fetchApiCommand->execute($content);
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetDefaultVersionCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetDefaultVersionCommand.php
new file mode 100644
index 00000000..47a06d29
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetDefaultVersionCommand.php
@@ -0,0 +1,27 @@
+ false, 'message' => 'Wrong data'];
+ }
+ $defaultHeader = $content['library'];
+
+ /* @var ApiHandler $handler */
+ $handler = $this->get('codebender_library.apiHandler');
+ // check library exists
+ if (!$handler->isExternalLibrary($defaultHeader, true)) {
+ return ['success' => false, 'message' => "No library named $defaultHeader was found."];
+ }
+ $version = $handler->fetchPartnerDefaultVersion($this->getRequest()->get('authorizationKey'), $defaultHeader);
+
+ return ['success' => true, 'version' => $version->getVersion()];
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetExampleCodeCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetExampleCodeCommand.php
new file mode 100644
index 00000000..29caa12e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetExampleCodeCommand.php
@@ -0,0 +1,193 @@
+ false, 'message' => 'Incorrect request fields'];
+ }
+ $library = $content['library'];
+ $example = $content['example'];
+
+ /* @var ApiHandler $handler */
+ $handler = $this->get('codebender_library.apiHandler');
+
+ $type = $handler->getLibraryType($library);
+ if ($type === 'unknown') {
+ return ['success' => false, 'message' => "Library named $library not found."];
+ }
+
+ $version = '';
+ // for external library, fetch default version for partner
+ if ($type !== 'example') {
+ $version = $handler->fetchPartnerDefaultVersion($this->getRequest()->get('authorizationKey'), $library)->getVersion();
+ }
+
+ // use specific requested version if any
+ if (array_key_exists('version', $content)) {
+ $version = $content['version']; // use specific requested version if any
+ }
+
+ if ($type === 'external' && !$handler->libraryVersionExists($library, $version)) {
+ return ['success' => false, 'message' => 'Requested library (version) does not exist'];
+ }
+
+ switch ($type) {
+ case 'builtin':
+ $example = $this->getExternalExampleCode($library, $version, $example);
+ break;
+ case 'external':
+ $example = $this->getExternalExampleCode($library, $version, $example);
+ break;
+ case 'example':
+ $dir = $handler->getBuiltInLibraryExamplePath($library);
+ $example = $this->getExampleCodeFromDir($dir, $example);
+ break;
+ }
+ return $example;
+ }
+
+ /**
+ * Retrieve example files data for the requested external library example
+ *
+ * @param $library
+ * @param $version
+ * @param $example
+ * @return array
+ */
+ private function getExternalExampleCode($library, $version, $example)
+ {
+ /* @var ApiHandler $handler */
+ $handler = $this->get('codebender_library.apiHandler');
+
+ $exampleMeta = $handler->getExampleForExternalLibrary($library, $version, $example);
+
+ if (count($exampleMeta) === 0) {
+ $example = str_replace(':', '/', $example);
+ $filename = pathinfo($example, PATHINFO_FILENAME);
+ $exampleMeta = $handler->getExampleForExternalLibrary($library, $version, $filename);
+
+ if (count($exampleMeta) > 1) {
+ $meta = null;
+ foreach ($exampleMeta as $e) {
+ $path = $e->getPath();
+ if (!(strpos($path, $example) === false)) {
+ $meta = $e;
+ break;
+ }
+ }
+ if (!$meta) {
+ return ['success' => false, 'message' => 'Could not retrieve the requested example'];
+ }
+ } elseif (count($exampleMeta) === 0) {
+ return ['success' => false, 'message' => 'Could not retrieve the requested example'];
+ } else {
+ $meta = $exampleMeta[0];
+ }
+ } else {
+ $meta = $exampleMeta[0];
+ }
+
+ $fullPath = $this->getPathForExternalExample($meta);
+ $path = pathinfo($fullPath, PATHINFO_DIRNAME);
+ $files = $this->getExampleFilesFromDir($path);
+ return $files;
+ }
+
+ /**
+ * Try retrieve example codes for given example name from
+ * a specified directory
+ *
+ * @param $dir
+ * @param $example
+ * @return array
+ */
+ private function getExampleCodeFromDir($dir, $example)
+ {
+ $finder = new Finder();
+ $finder->in($dir);
+ $finder->name($example . '.ino', $example . '.pde');
+
+ if (iterator_count($finder) === 0) {
+ $example = str_replace(':', '/', $example);
+ $filename = pathinfo($example, PATHINFO_FILENAME);
+ $finder->name($filename . '.ino', $filename . '.pde');
+ if (iterator_count($finder) > 1) {
+ $filesPath = null;
+ foreach ($finder as $e) {
+ $path = $e->getPath();
+ if (!(strpos($path, $example) === false)) {
+ $filesPath = $e;
+ break;
+ }
+ }
+ if (!$filesPath) {
+ return ['success' => false, 'message' => 'Could not retrieve the requested example'];
+ }
+ } elseif (iterator_count($finder) === 0) {
+ return ['success' => false, 'message' => 'Could not retrieve the requested example'];
+ } else {
+ $filesPathIterator = iterator_to_array($finder, false);
+ $filesPath = $filesPathIterator[0]->getPath();
+ }
+ } else {
+ $filesPathIterator = iterator_to_array($finder, false);
+ $filesPath = $filesPathIterator[0]->getPath();
+ }
+ $files = $this->getExampleFilesFromDir($filesPath);
+ return $files;
+ }
+
+ /**
+ * Retrieve example files data from the given directory
+ *
+ * @param $dir
+ * @return array
+ */
+ private function getExampleFilesFromDir($dir)
+ {
+ $filesFinder = new Finder();
+ $filesFinder->in($dir);
+ $filesFinder->name('*.cpp')->name('*.h')->name('*.c')->name('*.S')->name('*.pde')->name('*.ino');
+
+ $files = array();
+ foreach ($filesFinder as $file) {
+ if ($file->getExtension() === 'pde') {
+ $name = $file->getBasename('pde') . 'ino';
+ } else {
+ $name = $file->getFilename();
+ }
+
+ $files[] = array(
+ 'filename' => $name,
+ 'code' => (!mb_check_encoding($file->getContents(), 'UTF-8')) ? mb_convert_encoding($file->getContents(), 'UTF-8') : $file->getContents()
+ );
+
+ }
+
+ return ['success' => true, 'files' => $files];
+ }
+
+ /**
+ * Construct the full path for a given example entity
+ *
+ * @param $example
+ * @return string
+ */
+ private function getPathForExternalExample($example)
+ {
+ $externalLibraryPath = $this->container->getParameter('external_libraries_v2');
+ $libraryFolder = $example->getVersion()->getLibrary()->getFolderName();
+ $versionFolder = $example->getVersion()->getFolderName();
+ $examplePath = $example->getPath();
+
+ return "$externalLibraryPath/$libraryFolder/$versionFolder/$examplePath";
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetExamplesCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetExamplesCommand.php
new file mode 100644
index 00000000..be64a8ba
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetExamplesCommand.php
@@ -0,0 +1,100 @@
+ false, 'message' => 'Incorrect request fields'];
+ }
+ $library = $content['library'];
+
+ /* @var ApiHandler $handler */
+ $handler = $this->get('codebender_library.apiHandler');
+
+ $libraryType = $handler->getLibraryType($library);
+ if ($libraryType === 'unknown') {
+ return ['success' => false, 'message' => "Library named $library not found."];
+ }
+
+ $version = '';
+ // for built-in and external library, fetch default version for partner
+ if ($libraryType !== 'example') {
+ $version = $handler->fetchPartnerDefaultVersion($this->getRequest()->get('authorizationKey'), $library)->getVersion();
+ }
+
+ // use specific requested version if any
+ if (array_key_exists('version', $content)) {
+ $version = $content['version']; // use specific requested version if any
+ }
+
+ if (!$handler->libraryVersionExists($library, $version)) {
+ return ['success' => false, 'message' => "Requested version for library $library not found"];
+ }
+
+ $path = $handler->getBuiltInLibraryExamplePath($library);
+ if ($libraryType !== 'example') {
+ $path = $handler->getExternalLibraryPath($library, $version);
+ }
+
+ $examples = $this->getExampleFilesFromPath($path);
+
+ return ['success' => true, 'examples' => $examples];
+ }
+
+ /**
+ * Collect information of all example files from the given path
+ *
+ * @param $path
+ * @return array
+ */
+ private function getExampleFilesFromPath($path)
+ {
+
+ $inoFinder = new Finder();
+ $inoFinder->in($path);
+ $inoFinder->name('*.ino')->name('*.pde');
+
+ // TODO: Not only .h and .cpp files in Arduino examples
+ $notInoFilesFinder = new Finder();
+ $notInoFilesFinder->files()->name('*.h')->name('*.cpp');
+
+ $examples = array();
+
+ foreach ($inoFinder as $example) {
+ $files = array();
+ $content = (!mb_check_encoding($example->getContents(), 'UTF-8')) ? mb_convert_encoding($example->getContents(), 'UTF-8') : $example->getContents();
+ $pathInfo = pathinfo($example->getBaseName());
+ $files[] = array(
+ 'filename' => $pathInfo['filename'] . '.ino',
+ 'content' => (!mb_check_encoding($content, 'UTF-8')) ? mb_convert_encoding($content, 'UTF-8') : $content
+ );
+
+ // get non-ino files
+ $notInoFilesFinder->in($path . '/' . $example->getRelativePath());
+
+ foreach ($notInoFilesFinder as $nonInoFile) {
+ $files[] = array(
+ 'filename' => $nonInoFile->getBaseName(),
+ 'content' => (!mb_check_encoding($nonInoFile->getContents(), 'UTF-8')) ? mb_convert_encoding($nonInoFile->getContents(), 'UTF-8') : $nonInoFile->getContents()
+ );
+ }
+
+ $dir = preg_replace('/[E|e]xamples\//', '', $example->getRelativePath());
+ $dir = str_replace($pathInfo['filename'], '', $dir);
+ $dir = str_replace('/', ':', $dir);
+ if ($dir !== '' && substr($dir, -1) !== ':') {
+ $dir .= ':';
+ }
+
+ $examples[$dir . $pathInfo['filename']] = $files;
+ }
+
+ return $examples;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetKeywordsCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetKeywordsCommand.php
new file mode 100644
index 00000000..b287d442
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetKeywordsCommand.php
@@ -0,0 +1,137 @@
+apiHandler = $this->container->get('codebender_library.apiHandler');
+ }
+
+ /**
+ * This is the main execution of the getKeywords API.
+ * This method returns a response containing all the keywords of a library version.
+ *
+ * @param $content
+ * @return array
+ */
+ public function execute($content)
+ {
+ if (!$this->isValidContent($content)) {
+ return ['success' => false, 'message' => 'Incorrect request fields'];
+ }
+
+ $defaultHeader = $content['library'];
+
+ $libraryType = $this->apiHandler->getLibraryType($defaultHeader);
+ if ($libraryType === 'external' || $libraryType === 'builtin') {
+ $version = $this->getRequestedVersions($content);
+
+ if (!$this->apiHandler->libraryVersionExists($defaultHeader, $version)) {
+ return ['success' => false, 'message' => 'Could not find keywords for requested library version.'];
+ }
+
+ $keywords = $this->getExternalLibraryKeywords($defaultHeader, $version);
+ } else {
+ return ['success' => false, 'message' => "Library named $defaultHeader not found."];
+ }
+
+ return ['success' => true, 'keywords' => $keywords];
+ }
+
+ /**
+ * This method checks if the given $content is valid.
+ *
+ * @param $content
+ * @return bool
+ */
+ private function isValidContent($content)
+ {
+ return array_key_exists('library', $content);
+ }
+
+ /**
+ * This method get partner default version for the requested external library
+ * @param $content
+ * @return mixed
+ */
+ private function getRequestedVersions($content)
+ {
+ if (!array_key_exists("version", $content)) {
+ return $this->apiHandler->fetchPartnerDefaultVersion(
+ $this->getRequest()->get('authorizationKey'),
+ $content['library']
+ )->getVersion();
+ }
+
+ return $content['version'];
+ }
+
+ /**
+ * This method returns an array of keywords from a given library version
+ * specified by its $defaultHeader and $version.
+ *
+ * @param $defaultHeader
+ * @param $version
+ * @return array
+ */
+ private function getExternalLibraryKeywords($defaultHeader, $version)
+ {
+ $path = $this->apiHandler->getExternalLibraryPath($defaultHeader, $version);
+ $keywords = $this->getKeywordsFromFile($path);
+ return $keywords;
+ }
+
+ /**
+ * This method returns an array of keywords found in $path.
+ *
+ * @param $path
+ * @return array
+ */
+ private function getKeywordsFromFile($path)
+ {
+ $keywords = array();
+
+ $finder = new Finder();
+ $finder->in($path);
+ $finder->name('/^keywords\.txt$/i');
+
+ foreach ($finder as $file) {
+ $content = (!mb_check_encoding($file->getContents(), 'UTF-8')) ? mb_convert_encoding($file->getContents(), "UTF-8") : $file->getContents();
+
+ $lines = preg_split('/\r\n|\r|\n/', $content);
+
+ foreach ($lines as $rawline) {
+
+ $line = trim($rawline);
+ $parts = preg_split('/\s+/', $line);
+
+ $totalParts = count($parts);
+
+ if (($totalParts == 2) || ($totalParts == 3)) {
+
+ if ((substr($parts[1], 0, 7) == "KEYWORD")) {
+ $keywords[$parts[1]][] = $parts[0];
+ }
+
+ if ((substr($parts[1], 0, 7) == "LITERAL")) {
+ $keywords["KEYWORD3"][] = $parts[0];
+ }
+
+ }
+
+ }
+
+ break;
+ }
+ return $keywords;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetVersionsCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetVersionsCommand.php
new file mode 100644
index 00000000..7470fce0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/GetVersionsCommand.php
@@ -0,0 +1,68 @@
+apiHandler = $this->container->get('codebender_library.apiHandler');
+ }
+
+ /**
+ * This is the main execution of the getVersions API. It
+ * returns a response that includes an array of versions
+ * belonging to the given library name if the library exists.
+ *
+ * @param $content
+ * @return array
+ */
+ public function execute($content)
+ {
+ if (!$this->isValidContent($content)) {
+ return ['success' => false, 'message' => 'Incorrect request fields'];
+ }
+
+ $defaultHeader = $content['library'];
+ if (!$this->apiHandler->isExternalLibrary($defaultHeader)) {
+ return ['success' => false, 'message' => 'Invalid library name ' . $defaultHeader];
+ }
+
+ $versions = $this->getVersionStringsFromDefaultHeader($defaultHeader);
+ return ['success' => true, 'versions' => $versions];
+ }
+
+ /**
+ * This method checks if the given $content is valid.
+ *
+ * @param $content
+ * @return bool
+ */
+ private function isValidContent($content)
+ {
+ return array_key_exists("library", $content);
+ }
+
+ /**
+ * This method returns an array of versions belonging to a library
+ * with the given default header.
+ *
+ * @param $defaultHeader
+ * @return array
+ */
+ private function getVersionStringsFromDefaultHeader($defaultHeader)
+ {
+ $versionObjects = $this->apiHandler->getAllVersionsFromDefaultHeader($defaultHeader);
+ $versionsCollection = $versionObjects->map(function ($version) {
+ return $version->getVersion();
+ });
+ $versions = $versionsCollection->toArray();
+ return $versions;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/InvalidApiCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/InvalidApiCommand.php
new file mode 100644
index 00000000..58c77670
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/InvalidApiCommand.php
@@ -0,0 +1,14 @@
+ false, 'message' => 'No valid action requested'];
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/ListApiCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/ListApiCommand.php
new file mode 100644
index 00000000..8809803a
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/ListApiCommand.php
@@ -0,0 +1,171 @@
+getLibraryList($content);
+
+ $arduinoLibraryFiles = $this->container->getParameter('builtin_libraries') . "/";
+ $builtinExamples = $this->getLibariesListFromDir($arduinoLibraryFiles . "examples");
+
+ ksort($builtinExamples);
+ ksort($externalLibraries['Builtin Libraries']);
+ ksort($externalLibraries['External Libraries']);
+
+ return [
+ 'success' => true,
+ 'text' => 'Successful Request!',
+ 'categories' => [
+ 'Examples' => $builtinExamples,
+ 'Builtin Libraries' => $externalLibraries['Builtin Libraries'],
+ 'External Libraries' => $externalLibraries['External Libraries']
+ ]
+ ];
+ }
+
+ private function getLibariesListFromDir($path)
+ {
+ $finder = new Finder();
+ $finder->files()->name('*.ino')->name('*.pde');
+ $finder->in($path);
+ $libraries = array();
+ foreach ($finder as $file) {
+ $exampleInfo = $this
+ ->getExampleAndLibNameFromRelativePath(
+ $file->getRelativePath(),
+ $file->getBasename("." . $file->getExtension()),
+ true
+ );
+ if (!isset($libraries[$exampleInfo['library_name']])) {
+ $libraries[$exampleInfo['library_name']] = array("description" => "", "examples" => array());
+ }
+ $libraries[$exampleInfo['library_name']]['examples'][] = array('name' => $exampleInfo['example_name']);
+ }
+ return $libraries;
+ }
+
+ private function getLibraryList($content)
+ {
+ $entityManager = $this->getDoctrine()->getManager();
+ $externalMeta = $entityManager
+ ->getRepository('CodebenderLibraryBundle:Library')
+ ->findBy(array('active' => true));
+
+ $libraries = ['Builtin Libraries' => [], 'External Libraries' => []];
+ foreach ($externalMeta as $library) {
+ if ($library->isBuiltIn()) {
+ $category = 'Builtin Libraries';
+ } else {
+ $category = 'External Libraries';
+ }
+
+ $defaultHeader = $library->getDefaultHeader();
+
+ $libraries[$category][$defaultHeader] = array();
+
+ if (array_key_exists('v1', $content) && $content['v1']) {
+ $handler = $this->get('codebender_library.apiHandler');
+ $version = $handler->fetchPartnerDefaultVersion($this->getRequest()->get('authorizationKey'), $defaultHeader);
+ if (is_null($version)) {
+ continue;
+ }
+
+ $libraries[$category][$defaultHeader] = array(
+ 'description' => ''
+ );
+
+ if ($category === 'External Libraries') {
+ $libraries[$category][$defaultHeader]['description'] = $library->getDescription();
+ $libraries[$category][$defaultHeader]['humanName'] = $library->getName();
+ if ($library->getOwner() !== null && $library->getRepo() !== null) {
+ $libraries[$category][$defaultHeader]['url'] = "http://github.com/" . $library->getOwner() . "/" . $library->getRepo();
+ }
+ }
+
+ $libraries[$category][$defaultHeader]['examples'] = array();
+
+ $examples = $entityManager
+ ->getRepository('CodebenderLibraryBundle:LibraryExample')
+ ->findBy(array('version' => $version->getId()));
+
+ foreach ($examples as $example) {
+ $exampleInfo = $this
+ ->getExampleAndLibNameFromRelativePath(
+ pathinfo($example->getPath(), PATHINFO_DIRNAME),
+ $example->getName()
+ );
+
+ $libraries[$category][$defaultHeader]['examples'][] = array('name' => $exampleInfo['example_name']);
+ }
+ } else {
+ $versions = $library->getVersions();
+ foreach ($versions as $version) {
+ $libraries[$category][$defaultHeader][$version->getVersion()] = array(
+ "description" => $library->getDescription(),
+ "name" => $library->getName(),
+ "url" => "http://github.com/" . $library->getOwner() . "/" . $library->getRepo(),
+ "examples" => array()
+ );
+
+ $examples = $entityManager
+ ->getRepository('CodebenderLibraryBundle:LibraryExample')
+ ->findBy(array('version' => $version->getId()));
+
+ foreach ($examples as $example) {
+ $exampleInfo = $this
+ ->getExampleAndLibNameFromRelativePath(
+ pathinfo($example->getPath(), PATHINFO_DIRNAME),
+ $example->getName()
+ );
+
+ $libraries[$category][$defaultHeader][$version->getVersion()]['examples'][] = $exampleInfo['example_name'];
+ }
+ }
+ }
+ }
+
+ return $libraries;
+ }
+
+ /*
+ * Copied from DefaultController.php
+ */
+ private function getExampleAndLibNameFromRelativePath($path, $filename, $isBasicExamples = false)
+ {
+ $type = "";
+ $tmp = strtok($path, "/");
+
+ $result = [];
+ if ($isBasicExamples) {
+ $result['library_name'] = $tmp;
+ $tmp = strtok("/");
+ }
+
+ while ($tmp !== "" && !($tmp === false)) {
+ if ($tmp !== '.' && $tmp !== 'examples' && $tmp !== 'Examples' && $tmp !== $filename) {
+ if ($type === "") {
+ $type = $tmp;
+ } else {
+ $type = $type . ":" . $tmp;
+ }
+ }
+ $tmp = strtok("/");
+ }
+
+ $result['example_name'] = $filename;
+ if ($type !== "") {
+ $result['example_name'] = $type . ":" . $filename;
+ }
+
+ return $result;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/StatusCommand.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/StatusCommand.php
new file mode 100644
index 00000000..aed6f357
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommand/StatusCommand.php
@@ -0,0 +1,14 @@
+ true, 'status' => 'OK'];
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommandHandler.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommandHandler.php
new file mode 100644
index 00000000..cc53c5df
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiCommandHandler.php
@@ -0,0 +1,60 @@
+entityManager = $entityManager;
+ $this->container = $containerInterface;
+ }
+
+ /**
+ * This method attempts to match the given API name with
+ * the service name of an API. If the API is found, the service
+ * is returned. Otherwise, the InvalidApi service is returned.
+ *
+ * Security Implications: The prefix codebender_api is used for
+ * publicly accessible services only. Do NOT prefix an internal/private
+ * service with codebender_api as it will then be accessible to the
+ * public.
+ *
+ * @param $content
+ * @return AbstractApiCommand
+ */
+ public function getService($content)
+ {
+ $apiPrefix = 'codebender_api.';
+ $apiName = $this->removeNonAlphabetic($content['type']);
+ $serviceName = $apiPrefix . $apiName;
+
+ if ($this->container->has($serviceName)) {
+ $service = $this->container->get($serviceName);
+ } else {
+ $service = $this->container->get($apiPrefix . 'invalidApi');
+ }
+
+ return $service;
+ }
+
+ /**
+ * This method removes all non-alphabetic characters from $string
+ * and returns the new string after processing.
+ *
+ * @param $string
+ * @return mixed
+ */
+ private function removeNonAlphabetic($string)
+ {
+ return preg_replace("/[^A-Za-z]/", '', $string);
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/DefaultHandler.php b/Symfony/src/Codebender/LibraryBundle/Handler/ApiHandler.php
similarity index 53%
rename from Symfony/src/Codebender/LibraryBundle/Handler/DefaultHandler.php
rename to Symfony/src/Codebender/LibraryBundle/Handler/ApiHandler.php
index f6da0c22..0ebd8a5e 100644
--- a/Symfony/src/Codebender/LibraryBundle/Handler/DefaultHandler.php
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/ApiHandler.php
@@ -1,23 +1,18 @@
container = $containerInterface;
}
- public function getLibraryCode($library, $disabled, $renderView = false)
+ /**
+ * This method returns the type of the library (e.g. external/builtin) as a string.
+ *
+ * @param $defaultHeader
+ * @return string
+ */
+ public function getLibraryType($defaultHeader)
{
- $builtinLibrariesPath = $this->container->getParameter('builtin_libraries') . "/";
- $externalLibrariesPath = $this->container->getParameter('external_libraries') . "/";
+ if ($this->isExternalLibrary($defaultHeader)) {
+ return 'external';
+ } elseif ($this->isBuiltInLibrary($defaultHeader)) {
+ return 'builtin';
+ } elseif ($this->isBuiltInLibraryExample($defaultHeader)) {
+ return 'example';
+ }
- $finder = new Finder();
- $exampleFinder = new Finder();
+ return 'unknown';
+ }
- if ($disabled != 1) {
- $getDisabled = false;
- } else {
- $getDisabled = true;
- }
+ /**
+ * Constrct the path for the given library and version
+ * @param $defaultHeader
+ * @param $version
+ * @return string
+ * TODO: consider changing name into getLibraryPath
+ */
+ public function getExternalLibraryPath($defaultHeader, $version)
+ {
+ $externalLibraryRoot = $this->container->getParameter('external_libraries_v2') . "/";
- $filename = $library;
- $directory = "";
+ $library = $this->getLibraryFromDefaultHeader($defaultHeader);
+ $libraryFolderName = $library->getFolderName();
- $last_slash = strrpos($library, "/");
- if ($last_slash !== false) {
- $filename = substr($library, $last_slash + 1);
- $vendor = substr($library, 0, $last_slash);
- }
+ $versions = $library->getVersions();
+ $version = $versions->filter(
+ function (Version $ver) use ($version) {
+ return $ver->getVersion() === $version;
+ },
+ $versions
+ )->first();
+ $versionFolderName = $version->getFolderName();
- //TODO handle the case of different .h filenames and folder names
- if ($filename == "ArduinoRobot")
- $filename = "Robot_Control";
- else if ($filename == "ArduinoRobotMotorBoard")
- $filename = "Robot_Motor";
- if ($filename == 'BlynkSimpleSerial' || $filename == 'BlynkSimpleCC3000') {
- $filename = 'BlynkSimpleEthernet';
+ $path = $externalLibraryRoot . '/' . $libraryFolderName . '/' . $versionFolderName;
+ return $path;
+ }
+
+ // TODO: rearrange filesystem to completely remove builtin_libraries parameter
+ // TODO: consider changing name into getArduinoExamplePath
+ public function getBuiltInLibraryExamplePath($exmapleName)
+ {
+ $builtInLibraryRoot = $this->container->getParameter('builtin_libraries');
+ $path = $builtInLibraryRoot . '/examples/' . $exmapleName;
+ return $path;
+ }
+
+ /**
+ * This method checks if a given library (version) exists
+ *
+ * @param $defaultHeader
+ * @param $version
+ * @param bool $checkDisabled
+ * @return bool
+ */
+ public function libraryVersionExists($defaultHeader, $version, $checkDisabled = false)
+ {
+ if ($this->isValidLibraryVersion($defaultHeader, $version, $checkDisabled)) {
+ return true;
+ } elseif ($this->isBuiltInLibraryExample($defaultHeader)) {
+ return true;
}
- $exists = json_decode($this->checkIfBuiltInExists($filename), true);
+ return false;
+ }
- if ($exists["success"]) {
- $response = $this->fetchLibraryFiles($finder, $builtinLibrariesPath . "/libraries/" . $filename);
+ public function isLibrary($defaultHeader, $getDisabled = false)
+ {
+ $library = $this->getLibraryFromDefaultHeader($defaultHeader);
- if ($renderView) {
- $examples = $this->fetchLibraryExamples($exampleFinder, $builtinLibrariesPath . "/libraries/" . $filename);
- $meta = [];
- }
- } else {
- $response = json_decode($this->checkIfExternalExists($filename, $getDisabled), true);
- if (!$response['success']) {
- return $response;
- } else {
- $response = $this->fetchLibraryFiles($finder, $externalLibrariesPath . "/" . $filename);
- if (empty($response)) {
- return ['success' => false, 'message' => 'No files for Library named ' . $library . ' found.'];
- }
+ return $getDisabled ? $library !== null : $library !== null && $library->getActive();
+ }
- if ($renderView) {
- $examples = $this->fetchLibraryExamples($exampleFinder, $externalLibrariesPath . "/" . $filename);
- $externalLibrary = $this->entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')
- ->findOneBy(array('machineName' => $filename));
- $filename = $externalLibrary->getMachineName();
- $meta = $externalLibrary->getLiraryMeta();
- }
- }
+ /**
+ * This method checks if the given built-in library exists (specified by
+ * its $defaultHeader)
+ *
+ * @param $defaultHeader
+ * @return bool
+ */
+ public function isBuiltInLibrary($defaultHeader)
+ {
+ $library = $this->getLibraryFromDefaultHeader($defaultHeader);
+
+ if ($library === null) {
+ return false;
}
- if (!$renderView) {
- return ['success' => true, 'message' => 'Library found', 'files' => $response];
+ return $library->isBuiltIn();
+ }
+
+ /**
+ * This method checks if the given built-in library example exists (specified by
+ * its $defaultHeader)
+ *
+ * @param $defaultHeader
+ * @return bool
+ * TODO: consider changing name into isArduinoExample
+ */
+ public function isBuiltInLibraryExample($defaultHeader)
+ {
+ if (!is_dir($this->getBuiltInLibraryExamplePath($defaultHeader))) {
+ return false;
}
- return [
- 'success' => true,
- 'library' => $filename,
- 'files' => $response,
- 'examples' => $examples,
- 'meta' => $meta
- ];
+ return true;
}
/**
- * Checks all external libraries that are uploaded from Github, making sure the commit
- * hash stored in our database is the same as the last commit on the repo origin.
- * If no branch is stored in the database for a specific library, the default (master) is
- * used. In case no in-repo path is stored in the database, an empty path is used during the
- * last commit fetching, that is, the last commit for the root directory of the repo is fethced.
- * TODO: Enchance the method, making it able to auto-update any outdated libraries.
+ * This method checks if a given external library exists in the database.
*
- * @return array
+ * @param $defaultHeader
+ * @param bool $getDisabled
+ * @return bool
*/
- public function checkGithubUpdates()
+ public function isExternalLibrary($defaultHeader, $getDisabled = false)
{
- $needToUpdate = array();
- $libraries = $this->entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findAll();
+ $library = $this->getLibraryFromDefaultHeader($defaultHeader);
- foreach ($libraries as $lib) {
- $gitOwner = $lib->getOwner();
- $gitRepo = $lib->getRepo();
+ if ($library === null || $library->isBuiltIn()) {
+ return false;
+ }
- if ($lib->getActive() === false || $gitOwner === null || $gitRepo === null) {
- continue;
- }
+ if ($getDisabled) {
+ return true;
+ }
- $branch = $lib->getBranch();
- if ($branch === null){
- $branch = ''; // not providing any branch will make git return the commits of the default branch
- }
+ return $library->getActive();
+ }
- $directoryInRepo = $lib->getInRepoPath();
- if ($directoryInRepo === null){
- $directoryInRepo = '';
- }
+ /**
+ * Converts a given default header into its Library entity
+ *
+ * @param $defaultHeader
+ * @return Library
+ */
+ public function getLibraryFromDefaultHeader($defaultHeader)
+ {
+ $lib = $this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Library')
+ ->findOneBy(array('default_header' => $defaultHeader));
- $lastCommitFromGithub = $this->getLastCommitFromGithub($gitOwner, $gitRepo, $branch, $directoryInRepo);
- if ($lastCommitFromGithub !== $lib->getLastCommit()) {
- $needToUpdate[] = [
- 'Machine Name' => $lib->getMachineName(),
- 'Human Name' => $lib->getHumanName(),
- 'Git Owner' => $lib->getOwner(),
- 'Git Repo' => $lib->getRepo(),
- 'Git Branch' => $lib->getBranch(),
- 'Path in Git Repo' => $lib->getInRepoPath()
- ];
- }
+ return $lib;
+ }
+
+ /**
+ * @param $defaultHeader
+ * @return ArrayCollection
+ */
+ public function getAllVersionsFromDefaultHeader($defaultHeader)
+ {
+ $library = $this->getLibraryFromDefaultHeader($defaultHeader);
+ if ($library === null) {
+ return new ArrayCollection();
}
- if (empty($needToUpdate)) {
- return ['success' => true, 'message' => 'No external libraries need to be updated'];
+ return $library->getVersions();
+ }
+
+ /**
+ * Get the Version entity for the given library and specific version
+ * @param $library
+ * @param $version
+ * @return Version
+ */
+ public function getVersionFromDefaultHeader($library, $version)
+ {
+ /* @var ArrayCollection $versionCollection */
+ $versionCollection = $this->getAllVersionsFromDefaultHeader($library);
+
+ // check if this library contains requested version
+ $result = $versionCollection->filter(
+ function (Version $versionObject) use ($version) {
+ return $versionObject->getVersion() === $version;
+ }
+ );
+
+ if ($result->isEmpty()) {
+ return null;
}
- return [
- 'success' => true,
- 'message' => count($needToUpdate) . " external libraries need to be updated",
- 'libraries' => $needToUpdate
- ];
+ return $result->first();
}
/**
- * Fetches the last commit sha of a repo. `sha` parameter can either be the name of a branch, or a commit
- * sha. In the first case, the commit sha's of the branch are returned. In the second case, the commit sha's
- * of the default branch are returned, as long as the have been written after the provided commit.
- * Not providing any sha/branch will make Git API return the list of commits for the default branch.
- * The API can also use a path parameter, in which case only commits that affect a specific directory are returned.
- *
- * @param $gitOwner
- * @param $gitRepo
- * @param string $sha
- * @param string $path
- * @return mixed
+ * Get LibraryExample entity for the requested library example
+ * @param $library
+ * @param $version
+ * @param $example
+ * @return array
+ * TODO: consider changing name into getExampleForLibrary
*/
- public function getLastCommitFromGithub($gitOwner, $gitRepo, $sha = '', $path = '')
+ public function getExampleForExternalLibrary($library, $version, $example)
{
- /*
- * See the docs here https://developer.github.com/v3/repos/commits/
- * for more info on the json returned.
- */
- $url = "https://api.github.com/repos/" . $gitOwner . "/" . $gitRepo . "/commits";
- $queryParams = '';
- if ($sha != '') {
- $queryParams = "?sha=" . $sha;
- }
- if ($path != '') {
- $queryParams .= "&path=$path";
+ /* @var Version $versionMeta */
+ $versionMeta = $this->getVersionFromDefaultHeader($library, $version);
+
+ if ($versionMeta === null) {
+ return [];
}
- $lastCommitResponse = $this->curlGitRequest($url, $queryParams);
+ $examplenMeta = array_values(
+ array_filter(
+ $versionMeta->getLibraryExamples()->toArray(),
+ function (LibraryExample $exampleObject) use ($example) {
+ return $exampleObject->getName() === $example;
+ }
+ )
+ );
- return $lastCommitResponse[0]['sha'];
+ return $examplenMeta;
}
- public function checkIfBuiltInExists($library)
+ /**
+ * This method toggles the active status of a library.
+ *
+ * @param $defaultHeader
+ */
+ public function toggleLibraryStatus($defaultHeader)
{
- $arduino_library_files = $this->container->getParameter('builtin_libraries') . "/";
- if (is_dir($arduino_library_files . "/libraries/" . $library))
- return json_encode(array("success" => true, "message" => "Library found"));
- else
- return json_encode(array("success" => false, "message" => "No Library named " . $library . " found."));
+ $entityManager = $this->entityManager;
+ $library = $entityManager
+ ->getRepository('CodebenderLibraryBundle:Library')
+ ->findBy(array('default_header' => $defaultHeader));
+
+ // Do nothing if the library does not exist
+ if (count($library) < 1) {
+ return;
+ }
+
+ $library = $library[0];
+ $currentStatus = $library->getActive();
+ $library->setActive(!$currentStatus);
+ $entityManager->persist($library);
+ $entityManager->flush();
}
- public function checkIfExternalExists($library, $getDisabled = false)
+ /**
+ * This method checks if a library is in sync with its Github repository given its Github metadata.
+ *
+ * @param $gitOwner
+ * @param $gitRepo
+ * @param $gitBranch
+ * @param $gitInRepoPath
+ * @param $gitLastCommit
+ * @return bool
+ */
+ public function isLibraryInSyncWithGit($gitOwner, $gitRepo, $gitBranch, $gitInRepoPath, $gitLastCommit)
{
- $lib = $this->entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')->findBy(array('machineName' => $library));
- if (empty($lib) || (!$getDisabled && !$lib[0]->getActive())) {
- return json_encode(array("success" => false, "message" => "No Library named " . $library . " found."));
- } else {
- return json_encode(array("success" => true, "message" => "Library found"));
+ /*
+ * The values below are fetched from the database of the application. If any of them is not set
+ * in the database, the default (null) value will be returned.
+ */
+ if ($gitOwner === null || $gitRepo === null || $gitBranch === null || $gitLastCommit === null) {
+ return false;
}
+ $gitBranch = $this->convertNullToEmptyString($gitBranch); // not providing any branch will make git return the commits of the default branch
+ $gitInRepoPath = $this->convertNullToEmptyString($gitInRepoPath);
+
+ $lastCommitFromGithub = $this->getLastCommitFromGithub($gitOwner, $gitRepo, $gitBranch, $gitInRepoPath);
+ return $lastCommitFromGithub === $gitLastCommit;
}
public function fetchLibraryFiles($finder, $directory, $getContent = true)
@@ -217,11 +300,9 @@ public function fetchLibraryFiles($finder, $directory, $getContent = true)
if (!is_dir($directory)) {
return array();
}
-
$finder->in($directory)->exclude('examples')->exclude('Examples');
- // Left this here, just in case we need it again.
- // $finder->name('*.cpp')->name('*.h')->name('*.c')->name('*.S')->name('*.inc')->name('*.txt');
$finder->name('*.*');
+ $finder->files(); // fetch only files
$finfo = finfo_open(FILEINFO_MIME_TYPE);
@@ -229,13 +310,15 @@ public function fetchLibraryFiles($finder, $directory, $getContent = true)
foreach ($finder as $file) {
if ($getContent) {
$mimeType = finfo_file($finfo, $file);
- if (strpos($mimeType, "text/") === false)
+ if (strpos($mimeType, "text/") === false) {
$content = "/*\n *\n * We detected that this is not a text file.\n * Such files are currently not supported by our editor.\n * We're sorry for the inconvenience.\n * \n */";
- else
+ } else {
$content = (!mb_check_encoding($file->getContents(), 'UTF-8')) ? mb_convert_encoding($file->getContents(), "UTF-8") : $file->getContents();
+ }
$response[] = array("filename" => $file->getRelativePathname(), "content" => $content);
- } else
+ } else {
$response[] = array("filename" => $file->getRelativePathname());
+ }
}
return $response;
}
@@ -257,70 +340,157 @@ public function fetchLibraryExamples($finder, $directory)
}
/**
- * Determines whether an ExternalLibrary is in sync with its Github origin repo, if any.
+ * This method compares the commit time of two commits. The method returns an integer less than 0 if commit1
+ * is before commit2, 0 if commit 1 was committed at the same time as commit 2, and greater than 0 if commit1
+ * is later than commit2.
*
- * @param $owner
- * @param $repo
- * @param $branch
- * @param $inRepoPath
- * @param $lastCommit
- * @return bool
+ * @param $gitOwner
+ * @param $gitRepo
+ * @param $commit1
+ * @param $commit2
+ * @return int
*/
- public function isLibraryInSyncWithGit($owner, $repo, $branch, $inRepoPath, $lastCommit)
+ public function compareCommitTime($gitOwner, $gitRepo, $commit1, $commit2)
{
- /*
- * The values below are fetched fromt the database of the application. If any of them is not set
- * in the database, the default (null) value will be returned.
- */
- if ($owner === null || $repo === null || $branch === null || $lastCommit === null) {
- return false;
- }
+ $commit1Timestamp = $this->getCommitTimestamp($gitOwner, $gitRepo, $commit1);
+ $commit2Timestamp = $this->getCommitTimestamp($gitOwner, $gitRepo, $commit2);
+ return $commit1Timestamp - $commit2Timestamp;
+ }
+
+ /**
+ * This method returns the UNIX timestamp of a commit.
+ *
+ * @param $gitOwner
+ * @param $gitRepo
+ * @param $commit
+ * @return int
+ */
+ public function getCommitTimestamp($gitOwner, $gitRepo, $commit)
+ {
+ $url = "https://api.github.com/repos/" . $gitOwner . "/" . $gitRepo . "/git/commits/" . $commit;
+ $reponse = $this->curlGitRequest($url);
+ $dateString = $reponse['committer']['date'];
+ return strtotime($dateString);
+ }
+
+ public function isAuthenticatedPartner($auth_key)
+ {
+ /* @var Partner $partner */
+ $partner = $this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Partner')
+ ->findOneBy(array('auth_key' => $auth_key));
+ return $partner !== null;
+ }
- if ($inRepoPath === null) {
- $inRepoPath = '';
+ /**
+ * Create a new default version Preference for the partner
+ * Assume no Preference has been created for this library
+ * @param $partnerKey
+ * @param $defaultHeader
+ * @param $versionName
+ */
+ public function createPartnerDefaultVersion($partnerKey, $defaultHeader, $versionName)
+ {
+ $partner = $this->getPartnerFromAuthKey($partnerKey);
+ $version = $this->getVersionFromDefaultHeader($defaultHeader, $versionName);
+ $this->createNewPreferences($partner, $version);
+ }
+
+ /**
+ * Update a preference for the user
+ * @param $partnerKey
+ * @param $defaultHeader
+ * @param $versionName
+ */
+ public function updatePartnerDefaultVersion($partnerKey, $defaultHeader, $versionName)
+ {
+ $partner = $this->getPartnerFromAuthKey($partnerKey);
+ $version = $this->getVersionFromDefaultHeader($defaultHeader, $versionName);
+ $library = $version->getLibrary();
+ $preference = $this->getPartnerPreferenceForLibrary($partner, $library);
+
+ if ($preference !== null) {
+ $preference->setVersion($version);
+ $this->entityManager->persist($preference);
}
+ }
- $originLastCommit = $this->getLastCommitFromGithub($owner, $repo, $branch, $inRepoPath);
+ /**
+ * @param $partnerKey
+ * @param $defaultHeader
+ * @return Version
+ */
+ public function fetchPartnerDefaultVersion($partnerKey, $defaultHeader)
+ {
+ $partner = $this->getPartnerFromAuthKey($partnerKey);
+ $library = $this->getLibraryFromDefaultHeader($defaultHeader);
+ $preference = $this->getPartnerPreferenceForLibrary($partner, $library);
- if ($originLastCommit != $lastCommit) {
- return false;
+ // if no explicit default version set for this library
+ if ($preference === null) {
+ return $library->getLatestVersion();
}
- return true;
+ return $preference->getVersion();
}
- public function getRepoTreeStructure($owner, $repo, $branch, $requestedFolder)
+ /**
+ * Get the Partner entity from the authorization key
+ * @param $authKey
+ * @return Partner|null the partner entity
+ */
+ public function getPartnerFromAuthKey($authKey)
{
- $currentUrl = "https://api.github.com/repos/$owner/$repo/git/trees/$branch";
+ $partner = $this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Partner')
+ ->findOneBy(array('auth_key' => $authKey));
- $queryParams = "?recursive=1";
-
- /*
- * See the docs here https://developer.github.com/v3/git/trees/
- * for more info on the json returned.
- */
- $gitResponse = $this->curlGitRequest($currentUrl, $queryParams);
+ return $partner;
+ }
- if (array_key_exists('message', $gitResponse)) {
- return json_encode(array('success' => false, 'message' => $gitResponse['message']));
- }
- // TODO: Could try some recursive call to all tree nodes of the response, instead of just quitting
- if ($gitResponse['truncated'] != false) {
- return json_encode(array('success' => false, 'message' => 'Truncated data. Try using a subtree of the repo'));
+ public function findBaseDir($dir)
+ {
+ $baseDir = $this->getDir($dir);
+ if ($baseDir) {
+ return ['success' => true, 'directory' => $baseDir];
}
- $fileStructure = $this->createJsTreeStructure($gitResponse['tree'], $repo, '.', array('sha' => $gitResponse['sha'], 'type' => 'tree'));
+ foreach ($dir['contents'] as $file) {
+ if ($file['type'] == 'dir') {
+ $baseDir = $this->getDir($file);
+ if ($baseDir) {
+ $baseDir = $this->fixDirName($file);
+ return ['success' => true, 'directory' => $baseDir];
+ }
+ }
+ }
- $fileStructure = $this->findSelectedNode($repo . '/' . $requestedFolder, $fileStructure);
+ return ['success' => false, 'message' => 'Failed to find base dir'];
+ }
- return json_encode(array('success' => true, 'files' => $fileStructure));
+ private function getDir($dir)
+ {
+ foreach ($dir['contents'] as $file) {
+ if ($file['type'] == 'file' && strpos($file['name'], ".h") !== false) {
+ return $dir;
+ }
+ }
+ return false;
}
- public function getGithubRepoCode($owner, $repo, $branch, $path)
+ /**
+ * Get contents from the name of the commit/branch/tag
+ * @param $owner String
+ * @param $repo String
+ * @param $ref String The name of the commit/branch/tag
+ * @param $path String
+ * @return array
+ */
+ public function getGithubRepoCode($owner, $repo, $ref, $path)
{
$urlEncodedPath = implode('/', array_map('rawurlencode', explode('/', $path)));
$url = "https://api.github.com/repos/$owner/$repo/contents/$urlEncodedPath";
- $queryParams = "?ref=$branch";
+ $queryParams = "?ref=$ref";
/*
* See the docs here https://developer.github.com/v3/repos/contents/
@@ -337,7 +507,11 @@ public function getGithubRepoCode($owner, $repo, $branch, $path)
if ($path == '') {
$path = $repo;
}
- $libraryContents = array('name' => pathinfo($path, PATHINFO_BASENAME), 'type' => 'dir', 'contents' => array());
+ $libraryContents = array(
+ 'name' => pathinfo($path, PATHINFO_BASENAME),
+ 'type' => 'dir',
+ 'contents' => array()
+ );
foreach ($contents as $element) {
if ($element['type'] == 'file') {
$code = $this->getGithubFileCode($owner, $repo, $element['path'], $element['sha']);
@@ -346,7 +520,7 @@ public function getGithubRepoCode($owner, $repo, $branch, $path)
}
$libraryContents['contents'][] = $code['file'];
} elseif ($element['type'] == 'dir') {
- $directoryContents = $this->getGithubRepoCode($owner, $repo, $branch, $element['path']);
+ $directoryContents = $this->getGithubRepoCode($owner, $repo, $ref, $element['path']);
if ($directoryContents['success'] !== true) {
return $directoryContents;
}
@@ -357,7 +531,6 @@ public function getGithubRepoCode($owner, $repo, $branch, $path)
return array('success' => true, 'library' => $libraryContents);
}
-
private function getGithubFileCode($owner, $repo, $path, $blobSha)
{
$url = "https://api.github.com/repos/$owner/$repo/git/blobs/$blobSha";
@@ -369,7 +542,7 @@ private function getGithubFileCode($owner, $repo, $path, $blobSha)
$jsonDecodedContent = $this->curlGitRequest($url);
if (json_last_error() != JSON_ERROR_NONE) {
- return ['success' => false, 'message' => 'Invalid Git API response (cannot decode)'];
+ return array('success' => false, 'message' => 'Invalid Git API response (cannot decode)');
}
if (array_key_exists('message', $jsonDecodedContent)) {
@@ -383,26 +556,6 @@ private function getGithubFileCode($owner, $repo, $path, $blobSha)
return array('success' => true, 'file' => array('name' => pathinfo($path, PATHINFO_BASENAME), 'type' => 'file', 'contents' => base64_decode($jsonDecodedContent['content'])));
}
- public function findBaseDir($dir)
- {
- foreach ($dir['contents'] as $file) {
- if ($file['type'] == 'file' && strpos($file['name'], ".h") !== false)
- return ['success' => true, 'directory' => $dir];
-
- }
-
- foreach ($dir['contents'] as $file) {
- if ($file['type'] == 'dir') {
- foreach ($file['contents'] as $f) {
- if ($f['type'] == 'file' && strpos($f['name'], ".h") !== false) {
- $file = $this->fixDirName($file);
- return ['success' => true, 'directory' => $file];
- }
- }
- }
- }
- }
-
private function fixDirName($dir)
{
foreach ($dir['contents'] as &$f) {
@@ -415,62 +568,116 @@ private function fixDirName($dir)
return $dir;
}
+ /**
+ * Create a new Preference entity and save it in the database
+ * @param $partner Partner
+ * @param $version Version
+ */
+ private function createNewPreferences($partner, $version)
+ {
+ $preference = new Preference();
+ $preference->setLibrary($version->getLibrary());
+ $preference->setVersion($version);
+ $preference->setPartner($partner);
+ $this->entityManager->persist($preference);
+ }
- public function curlRequest($url, $post_request_data = null, $http_header = null)
+ /**
+ * Get a partner's Preference entity for a specific library
+ * @param $partner Partner
+ * @param $library Library
+ * @return Preference|null
+ */
+ private function getPartnerPreferenceForLibrary($partner, $library)
{
- $curl_req = curl_init();
- curl_setopt_array($curl_req, array(
- CURLOPT_URL => $url,
- CURLOPT_HEADER => 0,
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYHOST => 0,
- ));
- if ($post_request_data !== null)
- curl_setopt($curl_req, CURLOPT_POSTFIELDS, $post_request_data);
+ $result = $partner->getPreferences()
+ ->filter(
+ function ($preference) use ($library) {
+ return $preference->getLibrary()->getId() === $library->getId();
+ }
+ );
- if ($http_header !== null)
- curl_setopt($curl_req, CURLOPT_HTTPHEADER, $http_header);
+ if ($result->isEmpty()) {
+ return null;
+ }
- $contents = curl_exec($curl_req);
+ return $result->first();
+ }
- curl_close($curl_req);
- return $contents;
+ /**
+ * This method takes in an object and returns and empty
+ * string if the object is null. Otherwise, the original
+ * object is returned.
+ *
+ * @param $object
+ * @return string an empty string if $object is null, otherwise
+ * $object is returned
+ */
+ private function convertNullToEmptyString($object)
+ {
+ if ($object === null) {
+ return '';
+ }
+
+ return $object;
}
/**
- * A wrapper for the curlRequest function which adds Github authentication
- * to the Github API request
- * Returns the json decoded Github response.
+ * This method checks if the given version exists in the given library
+ * specified by the $defaultHeader.
*
- * @param string $url The requested url
- * @param string $queryParams Additional query parameters to be added to the request url
- * @return mixed
+ * @param $defaultHeader
+ * @param $version
+ * @param bool $checkDisabled
+ * @return bool
*/
- private function curlGitRequest($url, $queryParams = '')
+ private function isValidLibraryVersion($defaultHeader, $version, $checkDisabled = false)
{
- $clientId = $this->container->getParameter('github_app_client_id');
- $clientSecret = $this->container->getParameter('github_app_client_secret');
- $githubAppName = $this->container->getParameter('github_app_name');
+ if (!$this->isLibrary($defaultHeader, $checkDisabled)) {
+ return false;
+ }
- $requestUrl = $url . "?client_id=" . $clientId . "&client_secret=" . $clientSecret;
- if ($queryParams != '') {
- $requestUrl = $url . $queryParams . "&client_id=" . $clientId . "&client_secret=" . $clientSecret;
+ $versionsCollection = $this->getAllVersionsFromDefaultHeader($defaultHeader)
+ ->filter(
+ function ($versionObject) use ($version) {
+ return $versionObject->getVersion() === $version;
+ }
+ );
+
+ return !$versionsCollection->isEmpty();
+ }
+
+ /**
+ * Fetches the last commit sha of a repo. `sha` parameter can either be the name of a branch, or a commit
+ * sha. In the first case, the commit sha's of the branch are returned. In the second case, the commit sha's
+ * of the default branch are returned, as long as the have been written after the provided commit.
+ * Not providing any sha/branch will make Git API return the list of commits for the default branch.
+ * The API can also use a path parameter, in which case only commits that affect a specific directory are returned.
+ *
+ * @param $gitOwner
+ * @param $gitRepo
+ * @param string $sha
+ * @param string $path
+ * @return mixed
+ */
+ public function getLastCommitFromGithub($gitOwner, $gitRepo, $sha = '', $path = '')
+ {
+ /*
+ * See the docs here https://developer.github.com/v3/repos/commits/
+ * for more info on the json returned.
+ */
+ $url = "https://api.github.com/repos/" . $gitOwner . "/" . $gitRepo . "/commits";
+ $queryParams = '';
+ if ($sha != '') {
+ $queryParams = "?sha=" . $sha;
+ }
+ if ($path != '') {
+ $queryParams .= "&path=$path";
}
- /*
- * Note: The user-agent MUST be set to a valid value, otherwise the request will be rejected. One of the
- * suggested values is the application name.
- * One more thing that must be set on the headers, is the version of the API, which will offer stability
- * to the application, in case of future Github API updates.
- */
- $jsonDecodedContent = json_decode(
- $this->curlRequest(
- $requestUrl,
- null,
- ['User-Agent: ' . $githubAppName, 'Accept: application/vnd.github.v3.json']
- ), true);
- return $jsonDecodedContent;
+ $lastCommitResponse = $this->curlGitRequest($url, $queryParams);
+
+ return $lastCommitResponse[0]['sha'];
}
public function processGithubUrl($url)
@@ -517,6 +724,96 @@ public function cleanPrependingSlash($path)
return $path;
}
+ public function fetchRepoRefsFromGit($owner, $repo)
+ {
+ $url = "https://api.github.com/repos/$owner/$repo/git/refs/heads";
+
+ /*
+ * See the docs here https://developer.github.com/v3/git/refs/
+ * for more info on the json returned.
+ */
+ $gitResponse = $this->curlGitRequest($url);
+
+ if (array_key_exists('message', $gitResponse)) {
+ return array('success' => false, 'message' => $gitResponse['message']);
+ }
+
+ $headRefs = array();
+ foreach ($gitResponse as $ref) {
+ $headRefs[] = str_replace('refs/heads/', '', $ref['ref']);
+ }
+
+ return array('success' => true, 'headRefs' => $headRefs);
+ }
+
+ /**
+ * Fetch all releases from the Github repo
+ * @param $owner String
+ * @param $repo String
+ * @return array
+ */
+ public function fetchRepoReleasesFromGit($owner, $repo)
+ {
+ $url = "https://api.github.com/repos/$owner/$repo/releases";
+
+ /*
+ * See the docs here https://developer.github.com/v3/repos/releases/
+ * for more info on the json returned.
+ */
+ $gitResponse = $this->curlGitRequest($url);
+
+ if (array_key_exists('message', $gitResponse)) {
+ return array('success' => false, 'message' => $gitResponse['message']);
+ }
+
+ $releases = array();
+ foreach ($gitResponse as $release) {
+ $releases[] = [
+ 'name' => $release['name'],
+ 'tag' => $release['tag_name'],
+ 'branch' => $release['target_commitish'],
+ 'source' => $release['zipball_url']
+ ];
+ }
+
+ return array('success' => true, 'releases' => $releases);
+ }
+
+ /**
+ * Get a Github repo's tree structure
+ * @param $owner
+ * @param $repo
+ * @param $ref String could be a commit sha, a branch, or a tag
+ * @param $requestedFolder
+ * @return string
+ */
+ public function getRepoTreeStructure($owner, $repo, $ref, $requestedFolder)
+ {
+ $currentUrl = "https://api.github.com/repos/$owner/$repo/git/trees/$ref";
+
+ $queryParams = "?recursive=1";
+
+ /*
+ * See the docs here https://developer.github.com/v3/git/trees/
+ * for more info on the json returned.
+ */
+ $gitResponse = $this->curlGitRequest($currentUrl, $queryParams);
+
+ if (array_key_exists('message', $gitResponse)) {
+ return json_encode(array('success' => false, 'message' => $gitResponse['message']));
+ }
+ // TODO: Could try some recursive call to all tree nodes of the response, instead of just quitting
+ if ($gitResponse['truncated'] != false) {
+ return json_encode(array('success' => false, 'message' => 'Truncated data. Try using a subtree of the repo'));
+ }
+
+ $fileStructure = $this->createJsTreeStructure($gitResponse['tree'], $repo, '.', array('sha' => $gitResponse['sha'], 'type' => 'tree'));
+
+ $fileStructure = $this->findSelectedNode($repo . '/' . $requestedFolder, $fileStructure);
+
+ return json_encode(array('success' => true, 'files' => $fileStructure));
+ }
+
/**
* @param array $repoTree The tree of blobs and sub-trees returned from Github's API
* @param string $nodeName The name of the file tree node processed in the current iteration of the function
@@ -535,23 +832,28 @@ public function createJsTreeStructure($repoTree, $nodeName, $path, $gitMeta)
* Remember that files are listed as `blobs` and directories are listed as `trees`
* array_values is used to re-index the two arrays
*/
- $subtreeNodes = array_values(array_filter(
- $repoTree,
- function($element) {
- if ($element['type'] == 'tree') {
- return true;
+ $subtreeNodes = array_values(
+ array_filter(
+ $repoTree,
+ function ($element) {
+ if ($element['type'] == 'tree') {
+ return true;
+ }
+ return false;
}
- return false;
- })
+ )
);
- $files = array_values(array_filter(
- $repoTree,
- function($element) {
- if ($element['type'] == 'blob') {
- return true;
+
+ $files = array_values(
+ array_filter(
+ $repoTree,
+ function ($element) {
+ if ($element['type'] == 'blob') {
+ return true;
+ }
+ return false;
}
- return false;
- })
+ )
);
foreach ($files as $file) {
@@ -560,7 +862,8 @@ function($element) {
}
$fileStructure['children'][] = array_merge(
array('text' => pathinfo($file['path'], PATHINFO_BASENAME), 'icon' => 'fa fa-file', 'state' => array('disabled' => true)),
- $file);
+ $file
+ );
}
foreach ($subtreeNodes as $directory) {
@@ -582,6 +885,100 @@ function($element) {
return $fileStructure;
}
+ /**
+ * Returns the description of a Github repository
+ *
+ * @param string $owner The owner of the repository
+ * @param string $repo The repository name
+ * @return string The description of the repo, if any
+ */
+ public function getRepoDefaultDescription($owner, $repo)
+ {
+ $url = "https://api.github.com/repos/$owner/$repo";
+
+ /*
+ * See the docs here https://developer.github.com/v3/repos/
+ * for more info on the json returned.
+ */
+ $gitResponse = $this->curlGitRequest($url);
+
+ if (!array_key_exists('description', $gitResponse)) {
+ return '';
+ }
+
+ return $gitResponse['description'];
+ }
+
+ public function getLibraryCode($library, $disabled, $renderView = false)
+ {
+ $builtinLibrariesPath = $this->container->getParameter('builtin_libraries') . "/";
+ $externalLibrariesPath = $this->container->getParameter('external_libraries') . "/";
+
+ $finder = new Finder();
+ $exampleFinder = new Finder();
+
+ $getDisabled = true;
+ if ($disabled !== 1) {
+ $getDisabled = false;
+ }
+
+ $filename = $library;
+
+ $last_slash = strrpos($library, "/");
+ if ($last_slash !== false) {
+ $filename = substr($library, $last_slash + 1);
+ }
+
+ //TODO handle the case of different .h filenames and folder names
+ if ($filename == "ArduinoRobot") {
+ $filename = "Robot_Control";
+ }
+ if ($filename == "ArduinoRobotMotorBoard") {
+ $filename = "Robot_Motor";
+ }
+ if ($filename == 'BlynkSimpleSerial' || $filename == 'BlynkSimpleCC3000') {
+ $filename = 'BlynkSimpleEthernet';
+ }
+
+ if ($this->isBuiltInLibrary($filename)) {
+ $response = $this->fetchLibraryFiles($finder, $builtinLibrariesPath . "/libraries/" . $filename);
+
+ if ($renderView) {
+ $examples = $this->fetchLibraryExamples($exampleFinder, $builtinLibrariesPath . "/libraries/" . $filename);
+ $meta = [];
+ }
+ } else {
+ if (!$this->isExternalLibrary($filename, $getDisabled)) {
+ return ["success" => false, "message" => "No Library named " . $filename . " found."];
+ } else {
+ $response = $this->fetchLibraryFiles($finder, $externalLibrariesPath . "/" . $filename);
+ if (empty($response)) {
+ return ['success' => false, 'message' => 'No files for Library named ' . $library . ' found.'];
+ }
+
+ if ($renderView) {
+ $examples = $this->fetchLibraryExamples($exampleFinder, $externalLibrariesPath . "/" . $filename);
+
+ $externalLibrary = $this->entityManager->getRepository('CodebenderLibraryBundle:ExternalLibrary')
+ ->findOneBy(array('machineName' => $filename));
+ $filename = $externalLibrary->getMachineName();
+ $meta = $externalLibrary->getLiraryMeta();
+ }
+ }
+ }
+ if (!$renderView) {
+ return ['success' => true, 'message' => 'Library found', 'files' => $response];
+ }
+
+ return [
+ 'success' => true,
+ 'library' => $filename,
+ 'files' => $response,
+ 'examples' => $examples,
+ 'meta' => $meta
+ ];
+ }
+
/**
* Returns the blobs and trees of a provided tree that belong to
* a specific directory.
@@ -639,7 +1036,7 @@ private function getMachineNamesFromChildren($children)
*/
private function findSelectedNode($path, $files)
{
- // Remove trailing slashes
+ // Remove trailing slashes
$path = rtrim($path, '/');
// Then split the provided path in slashes
$path = explode('/', $path);
@@ -671,82 +1068,65 @@ private function findSelectedNode($path, $files)
return $files;
}
- public function fetchRepoRefsFromGit($owner, $repo)
+ private function curlRequest($url, $post_request_data = null, $http_header = null)
{
- $url = "https://api.github.com/repos/$owner/$repo/git/refs/heads";
-
- /*
- * See the docs here https://developer.github.com/v3/git/refs/
- * for more info on the json returned.
- */
- $gitResponse = $this->curlGitRequest($url);
-
- if (array_key_exists('message', $gitResponse)) {
- return array('success' => false, 'message' => $gitResponse['message']);
+ $curl_req = curl_init();
+ curl_setopt_array($curl_req, array(
+ CURLOPT_URL => $url,
+ CURLOPT_HEADER => 0,
+ CURLOPT_RETURNTRANSFER => 1,
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_SSL_VERIFYHOST => 0,
+ ));
+ if ($post_request_data !== null) {
+ curl_setopt($curl_req, CURLOPT_POSTFIELDS, $post_request_data);
}
- $headRefs = array();
- foreach ($gitResponse as $ref) {
- $headRefs[] = str_replace('refs/heads/', '', $ref['ref']);
+ if ($http_header !== null) {
+ curl_setopt($curl_req, CURLOPT_HTTPHEADER, $http_header);
}
- return array('success' => true, 'headRefs' => $headRefs);
+ $contents = curl_exec($curl_req);
+
+ curl_close($curl_req);
+ return $contents;
}
/**
- * Returns the description of a Github repository
+ * A wrapper for the curlRequest function which adds Github authentication
+ * to the Github API request
+ * Returns the json decoded Github response.
*
- * @param string $owner The owner of the repository
- * @param string $repo The repository name
- * @return string The description of the repo, if any
+ * @param string $url The requested url
+ * @param string $queryParams Additional query parameters to be added to the request url
+ * @return mixed
*/
- public function getRepoDefaultDescription($owner, $repo)
+ private function curlGitRequest($url, $queryParams = '')
{
- $url = "https://api.github.com/repos/$owner/$repo";
+ $clientId = $this->container->getParameter('github_app_client_id');
+ $clientSecret = $this->container->getParameter('github_app_client_secret');
+ $githubAppName = $this->container->getParameter('github_app_name');
+ $requestUrl = $url . "?client_id=" . $clientId . "&client_secret=" . $clientSecret;
+ if ($queryParams != '') {
+ $requestUrl = $url . $queryParams . "&client_id=" . $clientId . "&client_secret=" . $clientSecret;
+ }
/*
- * See the docs here https://developer.github.com/v3/repos/
- * for more info on the json returned.
+ * Note: The user-agent MUST be set to a valid value, otherwise the request will be rejected. One of the
+ * suggested values is the application name.
+ * One more thing that must be set on the headers, is the version of the API, which will offer stability
+ * to the application, in case of future Github API updates.
*/
- $gitResponse = $this->curlGitRequest($url);
-
- if (!array_key_exists('description', $gitResponse)) {
- return '';
- }
-
- return $gitResponse['description'];
- }
+ $jsonDecodedContent = json_decode(
+ $this->curlRequest(
+ $requestUrl,
+ null,
+ ['User-Agent: ' . $githubAppName, 'Accept: application/vnd.github.v3.json']
+ ),
+ true
+ );
- /**
- * Recursively removes a directory and its contents.
- *
- * @param string $directory
- * @throws \Exception
- */
- public function removeDirectory($directory)
- {
- $directory = realpath($directory);
- if (!file_exists($directory)) {
- return;
- }
- $directoryIterator = new DirectoryIterator($directory);
- foreach ($directoryIterator as $directoryElement) {
- if ($directoryElement->isDot()) {
- continue;
- }
- if ($directoryElement->isDir()) {
- $this->removeDirectory($directoryElement->getRealPath());
- continue;
- }
- if (unlink($directoryElement->getRealPath()) !== true) {
- throw new \Exception(
- 'Cannot delete file: ' . $directoryElement->getRealPath()
- );
- }
- }
- if (rmdir($directory) !== true) {
- throw new \Exception('Cannot delete directory: ' . $directory);
- }
+ return $jsonDecodedContent;
}
+}
-}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Handler/NewLibraryHandler.php b/Symfony/src/Codebender/LibraryBundle/Handler/NewLibraryHandler.php
new file mode 100644
index 00000000..913e1d55
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Handler/NewLibraryHandler.php
@@ -0,0 +1,520 @@
+entityManager = $entityManager;
+ $this->container = $containerInterface;
+ }
+
+ /**
+ * Performs the actual addition of a library, as well as
+ * input validation of the provided form data.
+ *
+ * @param array $data The data of the received form
+ * @return array
+ */
+ public function addLibrary($data)
+ {
+ /*
+ * Check whether the right combination of data was provided,
+ * and figure out the type of library addition, that is a zip archive (zip)
+ * or a Github repository (git)
+ */
+ $uploadType = $this->validateFormData($data);
+ if ($uploadType['success'] != true) {
+ return array('success' => false, 'message' => 'Invalid form. Please try again.');
+ }
+
+ /*
+ * Then get the files of the library (either from extracting the zip,
+ * or fetching them from Githib) and proceed
+ */
+ $handler = $this->container->get('codebender_library.apiHandler');
+ $path = '';
+ $lastCommit = null;
+
+ // check if data are taken from releases
+ // if from releases, then use the tag specified
+ // otherwise, use the branch info
+ $gitRef = $data["GitRelease"] !== null ? $data["GitRelease"] : $data["GitBranch"];
+ switch ($uploadType['type']) {
+ case 'git':
+ $path = $this->getInRepoPath($data["GitRepo"], $data['GitPath']);
+ $libraryStructure = $handler->getGithubRepoCode($data["GitOwner"], $data["GitRepo"], $gitRef, $path);
+ $lastCommit = $handler->getLastCommitFromGithub($data['GitOwner'], $data['GitRepo'], $gitRef, $path);
+ break;
+ case 'zip':
+ $libraryStructure = $this->getLibFromZipFile($data["Zip"]);
+ break;
+ default:
+ return array('success' => false, 'message' => 'Unknown upload type.');
+ }
+
+ if ($libraryStructure['success'] !== true) {
+ return array('success' => false, 'message' => $libraryStructure['message']);
+ }
+
+ /*
+ * In both ways of fething, the code of the library is found
+ * under the 'library' key of the response, upon success.
+ */
+ $libraryStructure = $libraryStructure['library'];
+
+ if ($uploadType['type'] == 'git') {
+ $libraryStructure = $this->fixGitPaths($libraryStructure, $libraryStructure['name'], '');
+ }
+
+ $data['LastCommit'] = $lastCommit;
+ $data['GitPath'] = $path;
+ $data['LibraryStructure'] = $libraryStructure;
+
+ /*
+ * It write the files to the disk and create the new Library and/or Version Entity
+ * that represents what's uploaded.
+ */
+ $lib = $this->getLibrary($data['DefaultHeader']);
+ // if same header name exists, add as a new version
+ // otherwise, create the library first then add new version
+ if ($lib === null) {
+ $data['IsLatestVersion'] = true;
+ $data['FolderName'] = $this->getLibraryFolderName($data['DefaultHeader']);
+
+ $creationResponse = $this->makeNewLibrary($data);
+ if ($creationResponse['success'] != true) {
+ return array('success' => false, 'message' => $creationResponse['message']);
+ }
+
+ $lib = $creationResponse["lib"];
+ } else {
+ $data['FolderName'] = $lib->getFolderName();
+ }
+
+ $handler = $this->container->get('codebender_library.apiHandler');
+ $version = $handler->getVersionFromDefaultHeader($data['DefaultHeader'], $data['Version']);
+ if ($version !== null) {
+ return array("success" => false, "message" => "Library '" . $data['DefaultHeader'] . "' already has version '" . $data['Version'] . "'");
+ }
+
+ $creationResponse = $this->makeNewVersionAndExamples($data, $lib);
+ if (!$creationResponse['success']) {
+ return array('success' => false, 'message' => $creationResponse['message']);
+ }
+
+ return array('success' => true);
+ }
+
+
+ /**
+ * Makes sure the received form does not contain Github data and
+ * a zip archive at once. In such a case, the form is considered invalid.
+ *
+ * @param array $data The form data array
+ * @return array
+ */
+ private function validateFormData($data)
+ {
+ if (($data['GitOwner'] === null && $data['GitRepo'] === null && $data['GitBranch'] === null && $data['GitPath'] === null) && is_object($data['Zip'])) {
+ return array('success' => true, 'type' => 'zip');
+ }
+ if (($data['GitOwner'] !== null && $data['GitRepo'] !== null && $data['GitBranch'] !== null && $data['GitPath'] !== null) && $data['Zip'] === null) {
+ return array('success' => true, 'type' => 'git');
+ }
+
+ return array('success' => false);
+ }
+
+ /**
+ * Determines whether the basepath is exactly the same or is the
+ * root directory of a provided path. Returns an empty string if the
+ * two paths are equal or strips the basepath from the path, if
+ * the first is a substring of the latter.
+ *
+ * @param string $basePath The name of the repo
+ * @param string $path The provided path
+ * @return string
+ */
+ private function getInRepoPath($basePath, $path)
+ {
+ if ($path == $basePath) {
+ return '';
+ }
+
+ if (preg_match("/^$basePath\//", $path)) {
+ return preg_replace("/^$basePath\//", '', $path);
+ }
+
+ return $path;
+ }
+
+ /**
+ * The zip upload implementation, creates an assoc array in which the filenames of each file
+ * include the absolute path to the file under the library root directory. This option is not available
+ * when fetching libraries from Git, since filenames contain no paths. This function is called
+ * recursively, and figures out the absolute path for each of the files of the provided file structure,
+ * making the git assoc array compatible to the zip assoc array.
+ *
+ * @param $files
+ * @param $root
+ * @param $parentPath
+ * @return mixed
+ */
+ private function fixGitPaths($files, $root, $parentPath)
+ {
+ if ($parentPath != '' && $parentPath != $root) {
+ $files['name'] = $parentPath . '/' . $files['name'];
+ }
+ $parentPath = $files['name'];
+ foreach ($files['contents'] as &$element) {
+ if ($element['type'] == 'dir') {
+ $element = $this->fixGitPaths($element, $root, $parentPath);
+ }
+ }
+ return $files;
+ }
+
+ private function makeNewLibrary($data)
+ {
+ $lib = new Library();
+ $lib->setName($data['Name']);
+ $lib->setDefaultHeader($data['DefaultHeader']);
+ $lib->setDescription($data['Description']);
+ $lib->setOwner($data['GitOwner']);
+ $lib->setRepo($data['GitRepo']);
+ $lib->setBranch($data['GitBranch']);
+ $lib->setInRepoPath($data['GitPath']);
+ $lib->setNotes($data['Notes']);
+ $lib->setVerified(false);
+ $lib->setActive(false);
+ $lib->setLastCommit($data['LastCommit']);
+ $lib->setUrl($data['Url']);
+ $lib->setFolderName($data['FolderName']);
+
+ $create = json_decode($this->createLibraryDirectory($data['FolderName'], $data['LibraryStructure']), true);
+
+ if (!$create['success']) {
+ return $create;
+ }
+
+ return ["success" => true, "lib" => $lib];
+ }
+
+ private function makeNewVersionAndExamples($data, Library $lib)
+ {
+ if ($lib === null) {
+ return json_encode(['success' => false]);
+ }
+
+ $version = new Version();
+ $version->setLibrary($lib);
+ $version->setFolderName($this->getVersionFolderName($lib, $data['Version']));
+ $version->setDescription($data['VersionDescription']);
+ $version->setReleaseCommit($data['LastCommit']);
+ $version->setSourceUrl($data['SourceUrl']);
+ $version->setNotes($data['VersionNotes']);
+ $version->setVersion($data['Version']);
+ $lib->addVersion($version);
+
+ /*
+ * If the version belongs to a Git repo, we update the lastCommit of the library accordingly
+ */
+ /* @var ApiHandler $handler */
+ $handler = $this->container->get('codebender_library.apiHandler');
+ $libraryLastCommit = $lib->getLastCommit();
+ if ((!empty($data['LastCommit']) && !empty($libraryLastCommit)) &&
+ $handler->compareCommitTime($data['GitOwner'], $data['GitRepo'], $data['LastCommit'], $libraryLastCommit) > 0) {
+ $lib->setLastCommit($data['LastCommit']);
+ }
+
+ $create = json_decode($this->createVersionDirectory($data['FolderName'], $version->getFolderName(), $data['LibraryStructure']), true);
+ if (!$create['success']) {
+ return json_encode($create);
+ }
+
+ if ($data['IsLatestVersion']) {
+ $lib->setLatestVersion($version);
+ }
+
+ $version = $this->saveArchitecturesForVersion($version, $data['Architectures']);
+ $examples = $this->makeExamples($data, $lib, $version);
+
+ $this->saveEntities([$version, $lib]);
+ $this->saveEntities($examples);
+
+ $this->entityManager->flush();
+
+ return ["success" => true, "lib" => $lib, "version" => $version];
+ }
+
+ /**
+ * @param $data
+ * @param $lib
+ * @param $version
+ * @return array
+ */
+ private function makeExamples($data, $lib, $version)
+ {
+ $handler = $this->container->get('codebender_library.apiHandler');
+
+ $externalLibrariesPath = $this->container->getParameter('external_libraries_v2');
+ $versionPath = $externalLibrariesPath . '/' . $lib->getFolderName() . '/' . $version->getFolderName();
+ $examples = $handler->fetchLibraryExamples(new Finder(), $versionPath);
+
+ $exampleMetas = [];
+ foreach ($examples as $example) {
+ $path_parts = pathinfo($example['filename']);
+ $exampleMetas[] = $this->makeExampleMeta($path_parts['filename'], $version, $example['filename'], null);
+ }
+
+ return $exampleMetas;
+ }
+
+ private function createLibraryDirectory($folderName, $libraryStructure)
+ {
+ $path = $this->container->getParameter('external_libraries_v2') . '/' . $folderName . '/';
+ if (is_dir($path)) {
+ return json_encode(array("success" => false, "message" => "Library directory already exists"));
+ }
+ if (!mkdir($path)) {
+ return json_encode(array("success" => false, "message" => "Cannot Save Library"));
+ }
+ return json_encode(array("success" => true));
+ }
+
+ private function createVersionDirectory($libraryFolderName, $versionFolderName, $libraryStructure)
+ {
+ $base = $path = $this->container->getParameter('external_libraries_v2') . '/' . $libraryFolderName . '/' . $versionFolderName . '/';
+ return ($this->createVersionDirectoryRecur($base, $path, $libraryStructure['contents']));
+ }
+
+ private function createVersionDirectoryRecur($base, $path, $files)
+ {
+ if (is_dir($path)) {
+ return json_encode(array("success" => false, "message" => "Library directory already exists"));
+ }
+ if (!mkdir($path)) {
+ return json_encode(array("success" => false, "message" => "Cannot Save Library"));
+ }
+
+ foreach ($files as $file) {
+ if ($file['type'] == 'dir') {
+ $create = json_decode($this->createVersionDirectoryRecur($base, $base . $file['name'] . "/", $file['contents']), true);
+ if (!$create['success']) {
+ return (json_encode($create));
+ }
+ } else {
+ file_put_contents($path . $file['name'], $file['contents']);
+ }
+ }
+
+ return json_encode(array('success' => true));
+ }
+
+ private function makeExampleMeta($name, $version, $path, $boards)
+ {
+ //TODO make it better. You know, return things and shit
+ $example = new LibraryExample();
+ $example->setName($name);
+ $example->setVersion($version);
+ $example->setPath($path);
+ $example->setBoards($boards);
+
+ return $example;
+ }
+
+
+ private function getLibFromZipFile($file)
+ {
+ if (is_dir('/tmp/lib')) {
+ $this->destroyDir('/tmp/lib');
+ }
+ $zip = new \ZipArchive;
+ $opened = $zip->open($file);
+
+ if ($opened === true) {
+ $handler = $this->container->get('codebender_library.apiHandler');
+ $zip->extractTo('/tmp/lib/');
+ $zip->close();
+ $dir = $this->processZipDir('/tmp/lib');
+
+ if (!$dir['success']) {
+ return json_encode($dir);
+ }
+
+ $dir = $dir['directory'];
+ $baseDir = $handler->findBaseDir($dir);
+ if ($baseDir['success'] !== true) {
+ return $baseDir;
+ }
+
+ $baseDir = $baseDir['directory'];
+
+ return ['success' => true, 'library' => $baseDir];
+ } else {
+ return ['success' => false, 'message' => 'Could not unzip Archive. Code: ' . $opened];
+ }
+ }
+
+ private function processZipDir($path)
+ {
+ $files = [];
+ $dir = preg_grep('/^([^.])/', scandir($path));
+ foreach ($dir as $file) {
+ if ($file == "__MACOSX") {
+ continue;
+ }
+
+ if (is_dir($path . '/' . $file)) {
+ $subdir = $this->processZipDir($path . '/' . $file);
+ if ($subdir['success'] !== true) {
+ return $subdir;
+ }
+ array_push($files, $subdir['directory']);
+ } else {
+ $file = $this->processZipFile($path . '/' . $file);
+ if ($file['success'] === true) {
+ array_push($files, $file['file']);
+ } elseif ($file['message'] != "Bad Encoding") {
+ return $file;
+ }
+ }
+ }
+ return ['success' => true, 'directory' => ['name' => substr($path, 9), 'type' => 'dir', 'contents' => $files]];
+ }
+
+ private function processZipFile($path)
+ {
+ $contents = file_get_contents($path);
+
+ if ($contents === null) {
+ return ['success' => false, 'message' => 'Could not read file ' . basename($path)];
+ }
+
+ return ['success' => true, 'file' => ['name' => basename($path), 'type' => 'file', 'contents' => $contents]];
+ }
+
+ private function destroyDir($dir)
+ {
+ if (!is_dir($dir) || is_link($dir)) {
+ return unlink($dir);
+ }
+ foreach (scandir($dir) as $file) {
+ if ($file != '.' && $file != '..' && !$this->destroyDir($dir . DIRECTORY_SEPARATOR . $file)) {
+ chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
+ if (!$this->destroyDir($dir . DIRECTORY_SEPARATOR . $file)) {
+ return false;
+ }
+ }
+ }
+ return rmdir($dir);
+ }
+
+ /**
+ * @param $defaultHeader
+ * @return Library entity or Null
+ */
+ private function getLibrary($defaultHeader)
+ {
+ return $this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Library')
+ ->findOneBy(['default_header' => $defaultHeader]);
+ }
+
+ private function saveEntities($entities)
+ {
+ foreach ($entities as $entity) {
+ $this->entityManager->persist($entity);
+ }
+ }
+
+ /**
+ * Save each supported architecture to the given version
+ * @param Version $version
+ * @param $architectures
+ * @return Version
+ */
+ private function saveArchitecturesForVersion(Version $version, $architectures)
+ {
+ if (!$architectures->isEmpty()) {
+ foreach ($architectures as $architecture) {
+ $version->addArchitecture($architecture);
+ }
+ }
+ return $version;
+ }
+
+ /**
+ * Make folder name based on the number of libraries with the same name.
+ * @param $name header name
+ * @return string
+ */
+ // TODO: better way of finding existing folder name. somehow could not use findBy multiple parameters
+ private function getLibraryFolderName($name)
+ {
+ $name = $this->normalizeString($name);
+ $folderName = $name;
+ $libraries = sizeof($this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Library')
+ ->findBy(array('default_header' => $name)));
+
+ if ($libraries === 0) {
+ return $folderName;
+ }
+
+ $count = 0;
+ while (!$this->hasFolderName($libraries, $folderName)) {
+ $count++;
+ $folderName = $name . '_' . $count;
+ }
+
+ return $folderName;
+ }
+
+ // TODO: better way of finding existing folder name. somehow could not use findBy multiple parameters
+ private function getVersionFolderName($lib, $version)
+ {
+ $name = $this->normalizeString($version);
+ $folderName = $name;
+ $versions = $this->entityManager
+ ->getRepository('CodebenderLibraryBundle:Version')
+ ->findBy(array('library' => $lib));
+
+ $count = 0;
+ while (!$this->hasFolderName($versions, $folderName)) {
+ $count++;
+ $folderName = $name . '_' . $count;
+ }
+
+ return $folderName;
+ }
+
+ private function hasFolderName($versions, $folderName)
+ {
+ foreach ($versions as $version) {
+ if ($version->getFolderName() === $folderName) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private function normalizeString($str)
+ {
+ $str = preg_replace('/[^a-z0-9]/i', '_', $str);
+ return $str;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/config/routing.yml b/Symfony/src/Codebender/LibraryBundle/Resources/config/routing.yml
index 4c5feb31..370672ed 100644
--- a/Symfony/src/Codebender/LibraryBundle/Resources/config/routing.yml
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/config/routing.yml
@@ -6,9 +6,46 @@ codebender_unit_test:
pattern: /{authorizationKey}/test
defaults: { _controller: CodebenderLibraryBundle:Test:test }
-codebender_library_view_library:
- pattern: /{authorizationKey}/view
- defaults: { _controller: CodebenderLibraryBundle:Views:viewLibrary }
+codebender_library_view_library_v2:
+ pattern: /{authorizationKey}/v2/view
+ defaults: { _controller: CodebenderLibraryBundle:ApiViews:viewLibrary }
+
+codebender_library_download_v2:
+ pattern: /{authorizationKey}/v2/download/{defaultHeaderFile}/{version}
+ defaults: { _controller: CodebenderLibraryBundle:ApiViews:download }
+
+codebender_library_new_external_v2:
+ pattern: /{authorizationKey}/v2/new
+ defaults: {_controller:CodebenderLibraryBundle:ApiViews:newLibrary}
+ methods: [GET, POST]
+
+codebender_library_check_github_updates_v2:
+ pattern: /{authorizationKey}/v2/gitUpdates
+ defaults: {_controller:CodebenderLibraryBundle:ApiViews:gitUpdates}
+
+codebender_library_search_v2:
+ pattern: /{authorizationKey}/v2/search
+ defaults: { _controller: CodebenderLibraryBundle:ApiViews:search }
+
+codebender_library_status_change_v2:
+ pattern: /{authorizationKey}/v2/toggleStatus/{library}
+ defaults: {_controller:CodebenderLibraryBundle:ApiViews:changeLibraryStatus}
+ methods: [POST]
+
+codebender_library_get_library_git_info:
+ pattern: /{authorizationKey}/v2/getLibGitInfo
+ defaults: {_controller:CodebenderLibraryBundle:ApiViews:getLibraryGitInfo}
+ methods: [POST]
+
+codebender_library_get_repo_tree_meta_v2:
+ pattern: /{authorizationKey}/v2/get_repo_tree_meta
+ defaults: {_controller:CodebenderLibraryBundle:ApiViews:getRepoGitTreeAndMeta}
+ methods: [POST]
+
+codebender_library_get_library_meta:
+ pattern: /{authorizationKey}/v2/getLibMeta/{library}
+ defaults: {_controller:CodebenderLibraryBundle:ApiViews:getLibraryMeta}
+ methods: [POST]
codebender_library_get_repo_tree_meta:
pattern: /{authorizationKey}/get_repo_tree_meta
@@ -20,32 +57,15 @@ codebender_library_get_library_git_branches:
defaults: {_controller:CodebenderLibraryBundle:Default:getLibraryGitBranches}
methods: [POST]
-codebender_library_download:
- pattern: /{authorizationKey}/download/{library}
- defaults: { _controller: CodebenderLibraryBundle:Views:download }
-
-codebender_library_new_external:
- pattern: /{authorizationKey}/new
- defaults: {_controller:CodebenderLibraryBundle:Views:newLibrary}
- methods: [GET, POST]
-
-codebender_library_check_github_updates:
- pattern: /{authorizationKey}/gitUpdates
- defaults: {_controller:CodebenderLibraryBundle:Views:gitUpdates}
-
-codebender_library_search:
- pattern: /{authorizationKey}/search
- defaults: { _controller: CodebenderLibraryBundle:Views:search }
-
-codebender_library_status_change:
- pattern: /{authorizationKey}/toggleStatus/{library}
- defaults: {_controller:CodebenderLibraryBundle:Views:changeLibraryStatus}
- methods: [POST]
-
codebender_library_get_keywords:
pattern: /{authorizationKey}/{version}/getKeywords
defaults: { _controller: CodebenderLibraryBundle:Default:getKeywords}
+codebender_api_handler_v2:
+ pattern: /{authorizationKey}/v2
+ defaults: { _controller: CodebenderLibraryBundle:Api:apiHandler }
+ methods: [POST]
+
codebender_api_handler:
pattern: /{authorizationKey}/{version}
defaults: { _controller: CodebenderLibraryBundle:Default:apiHandler }
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/config/services.yml b/Symfony/src/Codebender/LibraryBundle/Resources/config/services.yml
index 291d288b..8841b4a4 100644
--- a/Symfony/src/Codebender/LibraryBundle/Resources/config/services.yml
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/config/services.yml
@@ -1,6 +1,23 @@
parameters:
# codebender_library.example.class: Codebender\LibraryBundle\Example
codebender_library.handler.class: Codebender\LibraryBundle\Handler\DefaultHandler
+ codebender_library.apiHandler.class: Codebender\LibraryBundle\Handler\ApiHandler
+ codebender_library.apiCommandHandler.class: Codebender\LibraryBundle\Handler\ApiCommandHandler
+ codebender_library.newLibraryHandler.class: Codebender\LibraryBundle\Handler\NewLibraryHandler
+
+# Publicly accessible APIs
+ codebender_api.status.class: Codebender\LibraryBundle\Handler\ApiCommand\StatusCommand
+ codebender_api.invalidApi.class: Codebender\LibraryBundle\Handler\ApiCommand\InvalidApiCommand
+ codebender_api.getVersions.class: Codebender\LibraryBundle\Handler\ApiCommand\GetVersionsCommand
+ codebender_api.getKeywords.class: Codebender\LibraryBundle\Handler\ApiCommand\GetKeywordsCommand
+ codebender_api.getExamples.class: Codebender\LibraryBundle\Handler\ApiCommand\GetExamplesCommand
+ codebender_api.getExampleCode.class: Codebender\LibraryBundle\Handler\ApiCommand\GetExampleCodeCommand
+ codebender_api.list.class: Codebender\LibraryBundle\Handler\ApiCommand\ListApiCommand
+ codebender_api.fetch.class: Codebender\LibraryBundle\Handler\ApiCommand\FetchApiCommand
+ codebender_api.fetchLatest.class: Codebender\LibraryBundle\Handler\ApiCommand\FetchLatestApiCommand
+ codebender_api.checkGithubUpdates.class: Codebender\LibraryBundle\Handler\ApiCommand\CheckGithubUpdatesCommand
+ codebender_api.getDefaultVersion.class: Codebender\LibraryBundle\Handler\ApiCommand\GetDefaultVersionCommand
+ codebender_api.deleteLibrary.class: Codebender\LibraryBundle\Handler\ApiCommand\DeleteLibraryApiCommand
services:
# codebender_library.example:
@@ -11,4 +28,95 @@ services:
class: %codebender_library.handler.class%
arguments:
entityManager: "@doctrine.orm.entity_manager"
- containerInterface: "@service_container"
\ No newline at end of file
+ containerInterface: "@service_container"
+
+ codebender_library.apiHandler:
+ class: %codebender_library.apiHandler.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_library.apiCommandHandler:
+ class: %codebender_library.apiCommandHandler.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_library.newLibraryHandler:
+ class: %codebender_library.newLibraryHandler.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+# Publicly accessible services
+ codebender_api.status:
+ class: %codebender_api.status.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.invalidApi:
+ class: %codebender_api.invalidApi.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.getVersions:
+ class: %codebender_api.getVersions.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.fetch:
+ class: %codebender_api.fetch.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.fetchLatest:
+ class: %codebender_api.fetchLatest.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.getKeywords:
+ class: %codebender_api.getKeywords.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.getExamples:
+ class: %codebender_api.getExamples.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.getExampleCode:
+ class: %codebender_api.getExampleCode.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.list:
+ class: %codebender_api.list.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.checkGithubUpdates:
+ class: %codebender_api.checkGithubUpdates.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.getDefaultVersion:
+ class: %codebender_api.getDefaultVersion.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
+
+ codebender_api.deleteLibrary:
+ class: %codebender_api.deleteLibrary.class%
+ arguments:
+ entityManager: "@doctrine.orm.entity_manager"
+ containerInterface: "@service_container"
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/Binary.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/Binary.h
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/Binary.h
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/Binary.h
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/command.bat b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/command.bat
old mode 100755
new mode 100644
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/command.bat
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/command.bat
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/file.zip b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/file.zip
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/file.zip
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/file.zip
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/icon48.png b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/icon48.png
old mode 100755
new mode 100644
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/icon48.png
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/icon48.png
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/windows_executable.exe b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/windows_executable.exe
old mode 100755
new mode 100644
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Binary/windows_executable.exe
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Binary/1.0.0/windows_executable.exe
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/EEPROM.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/EEPROM.cpp
new file mode 100644
index 00000000..dfa1deb5
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/EEPROM.cpp
@@ -0,0 +1,50 @@
+/*
+ EEPROM.cpp - EEPROM library
+ Copyright (c) 2006 David A. Mellis. All right reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+/******************************************************************************
+ * Includes
+ ******************************************************************************/
+
+#include
+#include "Arduino.h"
+#include "EEPROM.h"
+
+/******************************************************************************
+ * Definitions
+ ******************************************************************************/
+
+/******************************************************************************
+ * Constructors
+ ******************************************************************************/
+
+/******************************************************************************
+ * User API
+ ******************************************************************************/
+
+uint8_t EEPROMClass::read(int address)
+{
+ return eeprom_read_byte((unsigned char *) address);
+}
+
+void EEPROMClass::write(int address, uint8_t value)
+{
+ eeprom_write_byte((unsigned char *) address, value);
+}
+
+EEPROMClass EEPROM;
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/EEPROM.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/EEPROM.h
new file mode 100644
index 00000000..aa2b5772
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/EEPROM.h
@@ -0,0 +1,35 @@
+/*
+ EEPROM.h - EEPROM library
+ Copyright (c) 2006 David A. Mellis. All right reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef EEPROM_h
+#define EEPROM_h
+
+#include
+
+class EEPROMClass
+{
+ public:
+ uint8_t read(int);
+ void write(int, uint8_t);
+};
+
+extern EEPROMClass EEPROM;
+
+#endif
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_clear/eeprom_clear.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_clear/eeprom_clear.ino
new file mode 100644
index 00000000..d1e29bdb
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_clear/eeprom_clear.ino
@@ -0,0 +1,23 @@
+/*
+ * EEPROM Clear
+ *
+ * Sets all of the bytes of the EEPROM to 0.
+ * This example code is in the public domain.
+
+ */
+
+#include
+
+void setup()
+{
+ // write a 0 to all 512 bytes of the EEPROM
+ for (int i = 0; i < 512; i++)
+ EEPROM.write(i, 0);
+
+ // turn the LED on when we're done
+ digitalWrite(13, HIGH);
+}
+
+void loop()
+{
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_read/eeprom_read.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_read/eeprom_read.ino
new file mode 100644
index 00000000..0709b2d4
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_read/eeprom_read.ino
@@ -0,0 +1,43 @@
+/*
+ * EEPROM Read
+ *
+ * Reads the value of each byte of the EEPROM and prints it
+ * to the computer.
+ * This example code is in the public domain.
+ */
+
+#include
+
+// start reading from the first byte (address 0) of the EEPROM
+int address = 0;
+byte value;
+
+void setup()
+{
+ // initialize serial and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+}
+
+void loop()
+{
+ // read a byte from the current address of the EEPROM
+ value = EEPROM.read(address);
+
+ Serial.print(address);
+ Serial.print("\t");
+ Serial.print(value, DEC);
+ Serial.println();
+
+ // advance to the next address of the EEPROM
+ address = address + 1;
+
+ // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
+ // on address 512, wrap around to address 0
+ if (address == 512)
+ address = 0;
+
+ delay(500);
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_write/eeprom_write.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_write/eeprom_write.ino
new file mode 100644
index 00000000..ae7c57eb
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/examples/eeprom_write/eeprom_write.ino
@@ -0,0 +1,38 @@
+/*
+ * EEPROM Write
+ *
+ * Stores values read from analog input 0 into the EEPROM.
+ * These values will stay in the EEPROM when the board is
+ * turned off and may be retrieved later by another sketch.
+ */
+
+#include
+
+// the current address in the EEPROM (i.e. which byte
+// we're going to write to next)
+int addr = 0;
+
+void setup()
+{
+}
+
+void loop()
+{
+ // need to divide by 4 because analog inputs range from
+ // 0 to 1023 and each byte of the EEPROM can only hold a
+ // value from 0 to 255.
+ int val = analogRead(0) / 4;
+
+ // write the value to the appropriate byte of the EEPROM.
+ // these values will remain there when the board is
+ // turned off.
+ EEPROM.write(addr, val);
+
+ // advance to the next address. there are 512 bytes in
+ // the EEPROM, so go back to 0 when we hit 512.
+ addr = addr + 1;
+ if (addr == 512)
+ addr = 0;
+
+ delay(100);
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/keywords.txt b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/keywords.txt
new file mode 100644
index 00000000..d3218fe2
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/EEPROM/default/keywords.txt
@@ -0,0 +1,18 @@
+#######################################
+# Syntax Coloring Map For Ultrasound
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+EEPROM KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Encode/Encode.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Encode/1.0.0/Encode.h
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Encode/Encode.h
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Encode/1.0.0/Encode.h
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files/Encode/examples/encoded_example/encoded_example.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Encode/1.0.0/examples/encoded_example/encoded_example.ino
similarity index 100%
rename from Symfony/src/Codebender/LibraryBundle/Resources/library_files/Encode/examples/encoded_example/encoded_example.ino
rename to Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Encode/1.0.0/examples/encoded_example/encoded_example.ino
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/Esplora.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/Esplora.cpp
new file mode 100644
index 00000000..29c9e191
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/Esplora.cpp
@@ -0,0 +1,184 @@
+/*
+ Esplora.cpp - Arduino Esplora board library
+ Written by Enrico Gueli
+ Copyright (c) 2012 Arduino(TM) All right reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include "Esplora.h"
+
+_Esplora Esplora;
+
+/*
+ * The following constants tell, for each accelerometer
+ * axis, which values are returned when the axis measures
+ * zero acceleration.
+ */
+const int ACCEL_ZERO_X = 320;
+const int ACCEL_ZERO_Y = 330;
+const int ACCEL_ZERO_Z = 310;
+
+const byte MUX_ADDR_PINS[] = { A0, A1, A2, A3 };
+const byte MUX_COM_PIN = A4;
+
+const int JOYSTICK_DEAD_ZONE = 100;
+
+const byte RED_PIN = 5;
+const byte BLUE_PIN = 9;
+const byte GREEN_PIN = 10;
+
+const byte BUZZER_PIN = 6;
+
+// non-multiplexer Esplora pins:
+// Accelerometer: x-A5, y-A7, z-A6
+// External outputs: D3, D11
+// Buzzer: A8
+// RGB Led: red-D5, green-D10/A11, blue-D9/A10
+// Led 13: D13
+
+const byte ACCEL_X_PIN = A5;
+const byte ACCEL_Y_PIN = A11;
+const byte ACCEL_Z_PIN = A6;
+
+const byte LED_PIN = 13;
+
+_Esplora::_Esplora() {
+ for (byte p=0; p<4; p++) {
+ pinMode(MUX_ADDR_PINS[p], OUTPUT);
+ }
+ pinMode(RED_PIN, OUTPUT);
+ pinMode(GREEN_PIN, OUTPUT);
+ pinMode(BLUE_PIN, OUTPUT);
+}
+
+unsigned int _Esplora::readChannel(byte channel) {
+ digitalWrite(MUX_ADDR_PINS[0], (channel & 1) ? HIGH : LOW);
+ digitalWrite(MUX_ADDR_PINS[1], (channel & 2) ? HIGH : LOW);
+ digitalWrite(MUX_ADDR_PINS[2], (channel & 4) ? HIGH : LOW);
+ digitalWrite(MUX_ADDR_PINS[3], (channel & 8) ? HIGH : LOW);
+ // workaround to cope with lack of pullup resistor on joystick switch
+ if (channel == CH_JOYSTICK_SW) {
+ pinMode(MUX_COM_PIN, INPUT_PULLUP);
+ unsigned int joystickSwitchState = (digitalRead(MUX_COM_PIN) == HIGH) ? 1023 : 0;
+ digitalWrite(MUX_COM_PIN, LOW);
+ return joystickSwitchState;
+ }
+ else
+ return analogRead(MUX_COM_PIN);
+}
+
+boolean _Esplora::joyLowHalf(byte joyCh) {
+ return (readChannel(joyCh) < 512 - JOYSTICK_DEAD_ZONE)
+ ? LOW : HIGH;
+}
+
+boolean _Esplora::joyHighHalf(byte joyCh) {
+ return (readChannel(joyCh) > 512 + JOYSTICK_DEAD_ZONE)
+ ? LOW : HIGH;
+}
+
+boolean _Esplora::readButton(byte ch) {
+ if (ch >= SWITCH_1 && ch <= SWITCH_4) {
+ ch--;
+ }
+
+ switch(ch) {
+ case JOYSTICK_RIGHT:
+ return joyLowHalf(CH_JOYSTICK_X);
+ case JOYSTICK_LEFT:
+ return joyHighHalf(CH_JOYSTICK_X);
+ case JOYSTICK_UP:
+ return joyLowHalf(CH_JOYSTICK_Y);
+ case JOYSTICK_DOWN:
+ return joyHighHalf(CH_JOYSTICK_Y);
+ }
+
+ unsigned int val = readChannel(ch);
+ return (val > 512) ? HIGH : LOW;
+}
+
+boolean _Esplora::readJoystickButton() {
+ if (readChannel(CH_JOYSTICK_SW) == 1023) {
+ return HIGH;
+ } else if (readChannel(CH_JOYSTICK_SW) == 0) {
+ return LOW;
+ }
+}
+
+
+void _Esplora::writeRGB(byte r, byte g, byte b) {
+ writeRed(r);
+ writeGreen(g);
+ writeBlue(b);
+}
+
+#define RGB_FUNC(name, pin, lastVar) \
+void _Esplora::write##name(byte val) { \
+ if (val == lastVar) \
+ return; \
+ analogWrite(pin, val); \
+ lastVar = val; \
+ delay(5); \
+} \
+\
+byte _Esplora::read##name() { \
+ return lastVar; \
+}
+
+RGB_FUNC(Red, RED_PIN, lastRed)
+RGB_FUNC(Green, GREEN_PIN, lastGreen)
+RGB_FUNC(Blue, BLUE_PIN, lastBlue)
+
+void _Esplora::tone(unsigned int freq) {
+ if (freq > 0)
+ ::tone(BUZZER_PIN, freq);
+ else
+ ::noTone(BUZZER_PIN);
+}
+
+void _Esplora::tone(unsigned int freq, unsigned long duration) {
+ if (freq > 0)
+ ::tone(BUZZER_PIN, freq, duration);
+ else
+ ::noTone(BUZZER_PIN);
+}
+
+void _Esplora::noTone() {
+ ::noTone(BUZZER_PIN);
+}
+
+int _Esplora::readTemperature(const byte scale) {
+ long rawT = readChannel(CH_TEMPERATURE);
+ if (scale == DEGREES_C) {
+ return (int)((rawT * 500 / 1024) - 50);
+ }
+ else if (scale == DEGREES_F) {
+ return (int)((rawT * 450 / 512 ) - 58);
+ }
+ else {
+ return readTemperature(DEGREES_C);
+ }
+}
+
+int _Esplora::readAccelerometer(const byte axis) {
+ switch (axis) {
+ case X_AXIS: return analogRead(ACCEL_X_PIN) - ACCEL_ZERO_X;
+ case Y_AXIS: return analogRead(ACCEL_Y_PIN) - ACCEL_ZERO_Y;
+ case Z_AXIS: return analogRead(ACCEL_Z_PIN) - ACCEL_ZERO_Z;
+ default: return 0;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/Esplora.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/Esplora.h
new file mode 100644
index 00000000..4f553455
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/Esplora.h
@@ -0,0 +1,165 @@
+/*
+ Esplora.h - Arduino Esplora board library
+ Written by Enrico Gueli
+ Copyright (c) 2012 Arduino(TM) All right reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef ESPLORA_H_
+#define ESPLORA_H_
+
+#include
+
+/*
+ * The following constants are used internally by the Esplora
+ * library code.
+ */
+
+const byte JOYSTICK_BASE = 16; // it's a "virtual" channel: its ID won't conflict with real ones
+
+const byte MAX_CHANNELS = 13;
+
+const byte CH_SWITCH_1 = 0;
+const byte CH_SWITCH_2 = 1;
+const byte CH_SWITCH_3 = 2;
+const byte CH_SWITCH_4 = 3;
+const byte CH_SLIDER = 4;
+const byte CH_LIGHT = 5;
+const byte CH_TEMPERATURE = 6;
+const byte CH_MIC = 7;
+const byte CH_JOYSTICK_SW = 10;
+const byte CH_JOYSTICK_X = 11;
+const byte CH_JOYSTICK_Y = 12;
+
+/*
+ * The following constants can be used with the readButton()
+ * method.
+ */
+
+const byte SWITCH_1 = 1;
+const byte SWITCH_2 = 2;
+const byte SWITCH_3 = 3;
+const byte SWITCH_4 = 4;
+
+const byte SWITCH_DOWN = SWITCH_1;
+const byte SWITCH_LEFT = SWITCH_2;
+const byte SWITCH_UP = SWITCH_3;
+const byte SWITCH_RIGHT = SWITCH_4;
+
+const byte JOYSTICK_DOWN = JOYSTICK_BASE;
+const byte JOYSTICK_LEFT = JOYSTICK_BASE+1;
+const byte JOYSTICK_UP = JOYSTICK_BASE+2;
+const byte JOYSTICK_RIGHT = JOYSTICK_BASE+3;
+
+/*
+ * These constants can be use for comparison with the value returned
+ * by the readButton() method.
+ */
+const boolean PRESSED = LOW;
+const boolean RELEASED = HIGH;
+
+/*
+ * The following constants can be used with the readTemperature()
+ * method to specify the desired scale.
+ */
+const byte DEGREES_C = 0;
+const byte DEGREES_F = 1;
+
+/*
+ * The following constants can be used with the readAccelerometer()
+ * method to specify the desired axis to return.
+ */
+const byte X_AXIS = 0;
+const byte Y_AXIS = 1;
+const byte Z_AXIS = 2;
+
+
+class _Esplora {
+private:
+ byte lastRed;
+ byte lastGreen;
+ byte lastBlue;
+
+ unsigned int readChannel(byte channel);
+
+ boolean joyLowHalf(byte joyCh);
+ boolean joyHighHalf(byte joyCh);
+
+public:
+ _Esplora();
+
+ /*
+ * Returns a number corresponding to the position of the
+ * linear potentiometer. 0 means full right, 1023 means
+ * full left.
+ */
+ inline unsigned int readSlider() { return readChannel(CH_SLIDER); }
+
+ /*
+ * Returns a number corresponding to the amount of ambient
+ * light sensed by the light sensor.
+ */
+ inline unsigned int readLightSensor() { return readChannel(CH_LIGHT); }
+
+ /*
+ * Returns the current ambient temperature, expressed either in Celsius
+ * or Fahreneit scale.
+ */
+ int readTemperature(const byte scale);
+
+ /*
+ * Returns a number corresponding to the amount of ambient noise.
+ */
+ inline unsigned int readMicrophone() { return readChannel(CH_MIC); }
+
+ inline unsigned int readJoystickSwitch() { return readChannel(CH_JOYSTICK_SW); }
+
+ inline int readJoystickX() {
+ return readChannel(CH_JOYSTICK_X) - 512;
+ }
+ inline int readJoystickY() {
+ return readChannel(CH_JOYSTICK_Y) - 512;
+ }
+
+ int readAccelerometer(const byte axis);
+
+ /*
+ * Reads the current state of a button. It will return
+ * LOW if the button is pressed, and HIGH otherwise.
+ */
+ boolean readButton(byte channel);
+
+ boolean readJoystickButton();
+
+ void writeRGB(byte red, byte green, byte blue);
+ void writeRed(byte red);
+ void writeGreen(byte green);
+ void writeBlue(byte blue);
+
+ byte readRed();
+ byte readGreen();
+ byte readBlue();
+
+ void tone(unsigned int freq);
+ void tone(unsigned int freq, unsigned long duration);
+ void noTone();
+};
+
+
+
+extern _Esplora Esplora;
+
+#endif // ESPLORA_H_
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino
new file mode 100644
index 00000000..db5cc93e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino
@@ -0,0 +1,38 @@
+/*
+ Esplora Accelerometer
+
+ This sketch shows you how to read the values from the accelerometer.
+ To see it in action, open the serial monitor and tilt the board. You'll see
+ the accelerometer values for each axis change when you tilt the board
+ on that axis.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include
+
+void setup()
+{
+ Serial.begin(9600); // initialize serial communications with your computer
+}
+
+void loop()
+{
+ int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis
+ int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
+ int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis
+
+ Serial.print("x: "); // print the label for X
+ Serial.print(xAxis); // print the value for the X axis
+ Serial.print("\ty: "); // print a tab character, then the label for Y
+ Serial.print(yAxis); // print the value for the Y axis
+ Serial.print("\tz: "); // print a tab character, then the label for Z
+ Serial.println(zAxis); // print the value for the Z axis
+
+ delay(500); // wait half a second (500 milliseconds)
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraBlink/EsploraBlink.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraBlink/EsploraBlink.ino
new file mode 100644
index 00000000..e198551a
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraBlink/EsploraBlink.ino
@@ -0,0 +1,42 @@
+
+/*
+ Esplora Blink
+
+ This sketch blinks the Esplora's RGB LED. It goes through
+ all three primary colors (red, green, blue), then it
+ combines them for secondary colors(yellow, cyan, magenta), then
+ it turns on all the colors for white.
+ For best results cover the LED with a piece of white paper to see the colors.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include
+
+
+void setup() {
+ // There's nothing to set up for this sketch
+}
+
+void loop() {
+ Esplora.writeRGB(255,0,0); // make the LED red
+ delay(1000); // wait 1 second
+ Esplora.writeRGB(0,255,0); // make the LED green
+ delay(1000); // wait 1 second
+ Esplora.writeRGB(0,0,255); // make the LED blue
+ delay(1000); // wait 1 second
+ Esplora.writeRGB(255,255,0); // make the LED yellow
+ delay(1000); // wait 1 second
+ Esplora.writeRGB(0,255,255); // make the LED cyan
+ delay(1000); // wait 1 second
+ Esplora.writeRGB(255,0,255); // make the LED magenta
+ delay(1000); // wait 1 second
+ Esplora.writeRGB(255,255,255);// make the LED white
+ delay(1000); // wait 1 second
+
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino
new file mode 100644
index 00000000..8d9260e3
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino
@@ -0,0 +1,50 @@
+/*
+ Esplora Joystick Mouse
+
+ This sketch shows you how to read the joystick and use it to control the movement
+ of the cursor on your computer. You're making your Esplora into a mouse!
+
+ WARNING: this sketch will take over your mouse movement. If you lose control
+ of your mouse do the following:
+ 1) unplug the Esplora.
+ 2) open the EsploraBlink sketch
+ 3) hold the reset button down while plugging your Esplora back in
+ 4) while holding reset, click "Upload"
+ 5) when you see the message "Done compiling", release the reset button.
+
+ This will stop your Esplora from controlling your mouse while you upload a sketch
+ that doesn't take control of the mouse.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include
+
+void setup()
+{
+ Serial.begin(9600); // initialize serial communication with your computer
+ Mouse.begin(); // take control of the mouse
+}
+
+void loop()
+{
+ int xValue = Esplora.readJoystickX(); // read the joystick's X position
+ int yValue = Esplora.readJoystickY(); // read the joystick's Y position
+ int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton
+ Serial.print("Joystick X: "); // print a label for the X value
+ Serial.print(xValue); // print the X value
+ Serial.print("\tY: "); // print a tab character and a label for the Y value
+ Serial.print(yValue); // print the Y value
+ Serial.print("\tButton: "); // print a tab character and a label for the button
+ Serial.print(button); // print the button value
+
+ int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X
+ int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
+ Mouse.move(mouseX, mouseY, 0); // move the mouse
+
+ delay(10); // a short delay before moving again
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLedShow/EsploraLedShow.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLedShow/EsploraLedShow.ino
new file mode 100644
index 00000000..3c617dcc
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLedShow/EsploraLedShow.ino
@@ -0,0 +1,42 @@
+/*
+ Esplora LED Show
+
+ Makes the RGB LED bright and glow as the joystick or the
+ slider are moved.
+
+ Created on 22 november 2012
+ By Enrico Gueli
+ Modified 22 Dec 2012
+ by Tom Igoe
+*/
+#include
+
+void setup() {
+ // initialize the serial communication:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // read the sensors into variables:
+ int xAxis = Esplora.readJoystickX();
+ int yAxis = Esplora.readJoystickY();
+ int slider = Esplora.readSlider();
+
+ // convert the sensor readings to light levels:
+ byte red = map(xAxis, -512, 512, 0, 255);
+ byte green = map(yAxis, -512, 512, 0, 255);
+ byte blue = slider/4;
+
+ // print the light levels:
+ Serial.print(red);
+ Serial.print(' ');
+ Serial.print(green);
+ Serial.print(' ');
+ Serial.println(blue);
+
+ // write the light levels to the LED.
+ Esplora.writeRGB(red, green, blue);
+
+ // add a delay to keep the LED from flickering:
+ delay(10);
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino
new file mode 100644
index 00000000..8f9f8a2b
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino
@@ -0,0 +1,55 @@
+/*
+ Esplora Led/Microphone
+
+ This simple sketch reads the microphone, light sensor, and slider.
+ Then it uses those readings to set the brightness of red, green and blue
+ channels of the RGB LED. The red channel will change with the loudness
+ "heared" by the microphone, the green channel changes as the
+ amount of light in the room and the blue channel will change
+ with the position of the slider.
+
+ Created on 22 november 2012
+ By Enrico Gueli
+ Modified 24 Nov 2012
+ by Tom Igoe
+*/
+
+#include
+
+void setup() {
+ // initialize the serial communication:
+ Serial.begin(9600);
+}
+
+int lowLight = 400; // the light sensor reading when it's covered
+int highLight = 1023; // the maximum light sensor reading
+int minGreen = 0; // minimum brightness of the green LED
+int maxGreen = 100; // maximum brightness of the green LED
+
+void loop() {
+ // read the sensors into variables:
+ int mic = Esplora.readMicrophone();
+ int light = Esplora.readLightSensor();
+ int slider = Esplora.readSlider();
+
+ // convert the sensor readings to light levels:
+ byte red = constrain(mic, 0, 255);
+ byte green = constrain(
+ map(light, lowLight, highLight, minGreen, maxGreen),
+ 0, 255);
+ byte blue = slider/4;
+
+ // print the light levels (to see what's going on):
+ Serial.print(red);
+ Serial.print(' ');
+ Serial.print(green);
+ Serial.print(' ');
+ Serial.println(blue);
+
+ // write the light levels to the LED.
+ // note that the green value is always 0:
+ Esplora.writeRGB(red, green, blue);
+
+ // add a delay to keep the LED from flickering:
+ delay(10);
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino
new file mode 100644
index 00000000..c3eaff42
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino
@@ -0,0 +1,91 @@
+/*
+ Esplora Led calibration
+
+ This sketch shows you how to read and calibrate the light sensor.
+ Because light levels vary from one location to another, you need to calibrate the
+ sensor for each location. To do this, you read the sensor for a few seconds,
+ and save the highest and lowest readings as maximum and minimum.
+ Then, when you're using the sensor's reading (for example, to set the brightness
+ of the LED), you map the sensor's reading to a range between the minimum
+ and the maximum.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include
+
+// variables:
+int lightMin = 1023; // minimum sensor value
+int lightMax = 0; // maximum sensor value
+boolean calibrated = false; // whether the sensor's been calibrated yet
+
+void setup() {
+ // initialize the serial communication:
+ Serial.begin(9600);
+
+ // print an intial message
+ Serial.println("To calibrate the light sensor, press and hold Switch 1");
+}
+
+void loop() {
+ // if switch 1 is pressed, go to the calibration function again:
+ if (Esplora.readButton(1) == LOW) {
+ calibrate();
+ }
+ // read the sensor into a variable:
+ int light = Esplora.readLightSensor();
+
+ // map the light level to a brightness level for the LED
+ // using the calibration min and max:
+ int brightness = map(light, lightMin, lightMax, 0, 255);
+ // limit the brightness to a range from 0 to 255:
+ brightness = constrain(brightness, 0, 255);
+ // write the brightness to the blue LED.
+ Esplora.writeBlue(brightness);
+
+ // if the calibration's been done, show the sensor and brightness
+ // levels in the serial monitor:
+ if (calibrated == true) {
+ // print the light sensor levels and the LED levels (to see what's going on):
+ Serial.print("light sensor level: ");
+ Serial.print(light);
+ Serial.print(" blue brightness: ");
+ Serial.println(brightness);
+ }
+ // add a delay to keep the LED from flickering:
+ delay(10);
+}
+
+void calibrate() {
+ // tell the user what do to using the serial monitor:
+ Serial.println("While holding switch 1, shine a light on the light sensor, then cover it.");
+
+ // calibrate while switch 1 is pressed:
+ while(Esplora.readButton(1) == LOW) {
+ // read the sensor value:
+ int light = Esplora.readLightSensor();
+
+ // record the maximum sensor value:
+ if (light > lightMax) {
+ lightMax = light;
+ }
+
+ // record the minimum sensor value:
+ if (light < lightMin) {
+ lightMin = light;
+ }
+ // note that you're calibrated, for future reference:
+ calibrated = true;
+ }
+}
+
+
+
+
+
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraMusic/EsploraMusic.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraMusic/EsploraMusic.ino
new file mode 100644
index 00000000..7a950fb1
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraMusic/EsploraMusic.ino
@@ -0,0 +1,53 @@
+/*
+ Esplora Music
+
+ This sketch turns the Esplora in a simple musical instrument.
+ Press the Switch 1 and move the slider to see how it works.
+
+ Created on 22 november 2012
+ By Enrico Gueli
+ modified 22 Dec 2012
+ by Tom Igoe
+*/
+
+
+#include
+
+// these are the frequencies for the notes from middle C
+// to one octave above middle C:
+const int note[] = {
+262, // C
+277, // C#
+294, // D
+311, // D#
+330, // E
+349, // F
+370, // F#
+392, // G
+415, // G#
+440, // A
+466, // A#
+494, // B
+523 // C next octave
+};
+
+void setup() {
+}
+
+void loop() {
+ // read the button labeled SWITCH_DOWN. If it's low,
+ // then play a note:
+ if (Esplora.readButton(SWITCH_DOWN) == LOW) {
+ int slider = Esplora.readSlider();
+
+ // use map() to map the slider's range to the
+ // range of notes you have:
+ byte thisNote = map(slider, 0, 1023, 0, 13);
+ // play the note corresponding to the slider's position:
+ Esplora.tone(note[thisNote]);
+ }
+ else {
+ // if the button isn't pressed, turn the note off:
+ Esplora.noTone();
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino
new file mode 100644
index 00000000..3bf454fe
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino
@@ -0,0 +1,41 @@
+/*
+ Esplora Sound Sensor
+
+ This sketch shows you how to read the microphone sensor. The microphone
+will range from 0 (total silence) to 1023 (really loud).
+ When you're using the sensor's reading (for example, to set the brightness
+ of the LED), you map the sensor's reading to a range between the minimum
+ and the maximum.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include
+
+void setup() {
+ // initialize the serial communication:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // read the sensor into a variable:
+ int loudness = Esplora.readMicrophone();
+
+ // map the sound level to a brightness level for the LED:
+ int brightness = map(loudness, 0, 1023, 0, 255);
+ // write the brightness to the green LED:
+ Esplora.writeGreen(brightness);
+
+
+ // print the microphone levels and the LED levels (to see what's going on):
+ Serial.print("sound level: ");
+ Serial.print(loudness);
+ Serial.print(" Green brightness: ");
+ Serial.println(brightness);
+ // add a delay to keep the LED from flickering:
+ delay(10);
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino
new file mode 100644
index 00000000..72bbf04e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino
@@ -0,0 +1,37 @@
+/*
+ Esplora Temperature Sensor
+
+ This sketch shows you how to read the Esplora's temperature sensor
+ You can read the temperature sensor in Farhenheit or Celsius.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+#include
+
+void setup()
+{
+ Serial.begin(9600); // initialize serial communications with your computer
+}
+
+void loop()
+{
+ // read the temperature sensor in Celsius, then Fahrenheit:
+ int celsius = Esplora.readTemperature(DEGREES_C);
+ int fahrenheit = Esplora.readTemperature(DEGREES_F);
+
+ // print the results:
+ Serial.print("Temperature is: ");
+ Serial.print(celsius);
+ Serial.print(" degrees Celsius, or ");
+ Serial.print(fahrenheit);
+ Serial.println(" degrees Fahrenheit.");
+ Serial.println(" Fahrenheit = (9/5 * Celsius) + 32");
+
+ // wait a second before reading again:
+ delay(1000);
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraKart/EsploraKart.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraKart/EsploraKart.ino
new file mode 100644
index 00000000..4c1621c1
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraKart/EsploraKart.ino
@@ -0,0 +1,125 @@
+/*
+ Esplora Kart
+
+ This sketch turns the Esplora into a PC game pad.
+
+ It uses the both the analog joystick and the four switches.
+ By moving the joystick in a direction or by pressing a switch,
+ the PC will "see" that a key is pressed. If the PC is running
+ a game that has keyboard input, the Esplora can control it.
+
+ The default configuration is suitable for SuperTuxKart, an
+ open-source racing game. It can be downloaded from
+ http://supertuxkart.sourceforge.net/ .
+
+ Created on 22 november 2012
+ By Enrico Gueli
+*/
+
+
+#include
+
+/*
+ You're going to handle eight different buttons. You'll use arrays,
+ which are ordered lists of variables with a fixed size. Each array
+ has an index (counting from 0) to keep track of the position
+ you're reading in the array, and each position can contain a number.
+
+ This code uses three different arrays: one for the buttons you'll read;
+ a second to hold the current states of those buttons; and a third to hold
+ the keystrokes associated with each button.
+ */
+
+/*
+ This array holds the last sensed state of each of the buttons
+ you're reading.
+ Later in the code, you'll read the button states, and compare them
+ to the previous states that are stored in this array. If the two
+ states are different, it means that the button was either
+ pressed or released.
+ */
+boolean buttonStates[8];
+
+/*
+ This array holds the names of the buttons being read.
+ Later in the sketch, you'll use these names with
+ the method Esplora.readButton(x), where x
+ is one of these buttons.
+ */
+const byte buttons[] = {
+ JOYSTICK_DOWN,
+ JOYSTICK_LEFT,
+ JOYSTICK_UP,
+ JOYSTICK_RIGHT,
+ SWITCH_RIGHT, // fire
+ SWITCH_LEFT, // bend
+ SWITCH_UP, // nitro
+ SWITCH_DOWN, // look back
+};
+
+/*
+ This array tells what keystroke to send to the PC when a
+ button is pressed.
+ If you look at this array and the above one, you can see that
+ the "cursor down" keystroke is sent when the joystick is moved
+ down, the "cursor up" keystroke when the joystick is moved up
+ and so on.
+*/
+const char keystrokes[] = {
+ KEY_DOWN_ARROW,
+ KEY_LEFT_ARROW,
+ KEY_UP_ARROW,
+ KEY_RIGHT_ARROW,
+ ' ',
+ 'V',
+ 'N',
+ 'B'
+};
+
+/*
+ This is code is run only at startup, to initialize the
+ virtual USB keyboard.
+*/
+void setup() {
+ Keyboard.begin();
+}
+
+/*
+ After setup() is finished, this code is run continuously.
+ Here we continuously check if something happened with the
+ buttons.
+*/
+void loop() {
+
+ // Iterate through all the buttons:
+ for (byte thisButton=0; thisButton<8; thisButton++) {
+ boolean lastState = buttonStates[thisButton];
+ boolean newState = Esplora.readButton(buttons[thisButton]);
+ if (lastState != newState) { // Something changed!
+ /*
+ The Keyboard library allows you to "press" and "release" the
+ keys as two distinct actions. These actions can be
+ linked to the buttons we're handling.
+ */
+ if (newState == PRESSED) {
+ Keyboard.press(keystrokes[thisButton]);
+ }
+ else if (newState == RELEASED) {
+ Keyboard.release(keystrokes[thisButton]);
+ }
+ }
+
+ // Store the new button state, so you can sense a difference later:
+ buttonStates[thisButton] = newState;
+ }
+
+ /*
+ Wait a little bit (50ms) between a check and another.
+ When a mechanical switch is pressed or released, the
+ contacts may bounce very rapidly. If the check is done too
+ fast, these bounces may be confused as multiple presses and
+ may lead to unexpected behaviour.
+ */
+ delay(50);
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraPong/EsploraPong.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraPong/EsploraPong.ino
new file mode 100644
index 00000000..725a109f
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraPong/EsploraPong.ino
@@ -0,0 +1,44 @@
+/*
+ Esplora Pong
+
+ This sketch connects serially to a Processing sketch to control a Pong game.
+ It sends the position of the slider and the states of three pushbuttons to the
+ Processing sketch serially, separated by commas. The Processing sketch uses that
+ data to control the graphics in the sketch.
+
+ The slider sets a paddle's height
+ Switch 1 is resets the game
+ Switch 2 resets the ball to the center
+ Switch 3 reverses the players
+
+ You can play this game with one or two Esploras.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include
+
+void setup() {
+ Serial.begin(9600); // initialize serial communication
+}
+
+void loop() {
+ // read the slider and three of the buttons
+ int slider = Esplora.readSlider();
+ int resetButton = Esplora.readButton(SWITCH_1);
+ int serveButton = Esplora.readButton(SWITCH_3);
+ int switchPlayerButton = Esplora.readButton(SWITCH_4);
+
+ Serial.print(slider); // print the slider value
+ Serial.print(","); // add a comma
+ Serial.print(resetButton); // print the reset button value
+ Serial.print(","); // add another comma
+ Serial.print(serveButton); // print the serve button value
+ Serial.print(","); // add another comma
+ Serial.println(switchPlayerButton); // print the last button with a newline
+ delay(10); // delay before sending the next set
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraRemote/EsploraRemote.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraRemote/EsploraRemote.ino
new file mode 100644
index 00000000..27010897
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraRemote/EsploraRemote.ino
@@ -0,0 +1,116 @@
+/*
+ Esplora Remote
+
+ This sketch allows to test all the Esplora's peripherals.
+ It is also used with the ProcessingStart sketch (for Processing).
+
+ When uploaded, you can open the Serial monitor and write one of
+ the following commands (without quotes) to get an answer:
+
+ "D": prints the current value of all sensors, separated by a comma.
+ See the dumpInputs() function below to get the meaning of
+ each value.
+
+ "Rxxx"
+ "Gxxx"
+ "Bxxx": set the color of the RGB led. For example, write "R255"
+ to turn on the red to full brightness, "G128" to turn
+ the green to half brightness, or "G0" to turn off
+ the green channel.
+
+ "Txxxx": play a tone with the buzzer. The number is the
+ frequency, e.g. "T440" plays the central A note.
+ Write "T0" to turn off the buzzer.
+
+
+ Created on 22 november 2012
+ By Enrico Gueli
+ Modified 23 Dec 2012
+ by Tom Igoe
+ */
+
+#include
+
+void setup() {
+ while(!Serial); // needed for Leonardo-based board like Esplora
+ Serial.begin(9600);
+}
+
+void loop() {
+ if (Serial.available())
+ parseCommand();
+}
+
+/*
+ * This function reads a character from the serial line and
+ * decide what to do next. The "what to do" part is given by
+ * function it calls (e.g. dumpInputs(), setRed() and so on).
+ */
+void parseCommand() {
+ char cmd = Serial.read();
+ switch(cmd) {
+ case 'D':
+ dumpInputs();
+ break;
+ case 'R':
+ setRed();
+ break;
+ case 'G':
+ setGreen();
+ break;
+ case 'B':
+ setBlue();
+ break;
+ case 'T':
+ setTone();
+ break;
+ }
+}
+
+void dumpInputs() {
+ Serial.print(Esplora.readButton(SWITCH_1));
+ Serial.print(',');
+ Serial.print(Esplora.readButton(SWITCH_2));
+ Serial.print(',');
+ Serial.print(Esplora.readButton(SWITCH_3));
+ Serial.print(',');
+ Serial.print(Esplora.readButton(SWITCH_4));
+ Serial.print(',');
+ Serial.print(Esplora.readSlider());
+ Serial.print(',');
+ Serial.print(Esplora.readLightSensor());
+ Serial.print(',');
+ Serial.print(Esplora.readTemperature(DEGREES_C));
+ Serial.print(',');
+ Serial.print(Esplora.readMicrophone());
+ Serial.print(',');
+ Serial.print(Esplora.readJoystickSwitch());
+ Serial.print(',');
+ Serial.print(Esplora.readJoystickX());
+ Serial.print(',');
+ Serial.print(Esplora.readJoystickY());
+ Serial.print(',');
+ Serial.print(Esplora.readAccelerometer(X_AXIS));
+ Serial.print(',');
+ Serial.print(Esplora.readAccelerometer(Y_AXIS));
+ Serial.print(',');
+ Serial.print(Esplora.readAccelerometer(Z_AXIS));
+ Serial.println();
+}
+
+void setRed() {
+ Esplora.writeRed(Serial.parseInt());
+}
+
+void setGreen() {
+ Esplora.writeGreen(Serial.parseInt());
+}
+
+void setBlue() {
+ Esplora.writeBlue(Serial.parseInt());
+}
+
+void setTone() {
+ Esplora.tone(Serial.parseInt());
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraTable/EsploraTable.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraTable/EsploraTable.ino
new file mode 100644
index 00000000..712dffa7
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/examples/Experts/EsploraTable/EsploraTable.ino
@@ -0,0 +1,213 @@
+/*
+ Esplora Table
+
+ Acts like a keyboard that prints sensor
+ data in a table-like text, row by row.
+
+ At startup, it does nothing. It waits for you to open a
+ spreadsheet (e.g. Google Drive spreadsheet) so it can write
+ data. By pressing Switch 1, it starts printing the table
+ headers and the first row of data. It waits a bit, then it
+ will print another row, and so on.
+
+ The amount of time between each row is determined by the slider.
+ If put to full left, the sketch will wait 10 seconds; at
+ full right position, it will wait 5 minutes. An intermediate
+ position will make the sketch wait for some time in-between.
+
+ Clicking the Switch 1 at any time will stop the logging.
+
+ The color LED shows what the sketch is doing:
+ blue = idle, waiting for you to press Switch 1 to start logging
+ green = active; will print soon
+ red = printing data to the PC
+
+ Created on 22 november 2012
+ By Enrico Gueli
+ modified 24 Nov 2012
+ by Tom Igoe
+*/
+
+#include
+
+/*
+ * this variable tells if the data-logging is currently active.
+ */
+boolean active = false;
+
+/*
+ * this variable holds the time in the future when the sketch
+ * will "sample" the data (sampling is the act of reading some
+ * input at a known time). This variable is checked continuously
+ * against millis() to know when it's time to sample.
+ */
+unsigned long nextSampleAt = 0;
+
+/*
+ * This variable just holds the millis() value at the time the
+ * logging was activated. This is needed to enter the correct
+ * value in the "Time" column in the printed table.
+ */
+unsigned long startedAt = 0;
+
+
+/*
+ * when the "active" variable is set to true, the same is done
+ * with this variable. This is needed because the code that does
+ * the "just-after-activation" stuff is run some time later than
+ * the code that says "be active now".
+ */
+boolean justActivated = false;
+
+
+/*
+ * this variable holds the last sensed status of the switch press
+ * button. If the code sees a difference between the value of
+ * this variable and the current status of the switch, it means
+ * that the button was either pressed or released.
+ */
+boolean lastStartBtn = HIGH;
+
+/*
+ * Initialization code. The virtual USB keyboard must be
+ * initialized; the Serial class is needed just for debugging.
+ */
+void setup() {
+ Keyboard.begin();
+ Serial.begin(9600);
+}
+
+/*
+ * This code is run continuously.
+ */
+void loop() {
+ /*
+ * note: we don't use Arduino's delay() here, because we can't
+ * normally do anything while delaying. Our own version lets us
+ * check for button presses often enough to not miss any event.
+ */
+ activeDelay(50);
+
+ /*
+ * the justActivated variable may be set to true in the
+ * checkSwitchPress() function. Here we check its status to
+ * print the table headers and configure what's needed to.
+ */
+ if (justActivated == true) {
+ justActivated = false; // do this just once
+ printHeaders();
+ // do next sampling ASAP
+ nextSampleAt = startedAt = millis();
+ }
+
+ if (active == true) {
+ if (nextSampleAt < millis()) {
+ // it's time to sample!
+ int slider = Esplora.readSlider();
+ // the row below maps the slider position to a range between
+ // 10 and 290 seconds.
+ int sampleInterval = map(slider, 0, 1023, 10, 290);
+ nextSampleAt = millis() + sampleInterval * 1000;
+
+ logAndPrint();
+ }
+
+ // let the RGB led blink green once per second, for 200ms.
+ unsigned int ms = millis() % 1000;
+ if (ms < 200)
+ Esplora.writeGreen(50);
+ else
+ Esplora.writeGreen(0);
+
+ Esplora.writeBlue(0);
+ }
+ else
+ // while not active, keep a reassuring blue color coming
+ // from the Esplora...
+ Esplora.writeBlue(20);
+
+}
+
+/*
+ * Print the table headers.
+ */
+void printHeaders() {
+ Keyboard.print("Time");
+ Keyboard.write(KEY_TAB);
+ activeDelay(300); // Some spreadsheets are slow, e.g. Google
+ // Drive that wants to save every edit.
+ Keyboard.print("Accel X");
+ Keyboard.write(KEY_TAB);
+ activeDelay(300);
+ Keyboard.print("Accel Y");
+ Keyboard.write(KEY_TAB);
+ activeDelay(300);
+ Keyboard.print("Accel Z");
+ Keyboard.println();
+ activeDelay(300);
+}
+
+void logAndPrint() {
+ // do all the samplings at once, because keystrokes have delays
+ unsigned long timeSecs = (millis() - startedAt) /1000;
+ int xAxis = Esplora.readAccelerometer(X_AXIS);
+ int yAxis = Esplora.readAccelerometer(Y_AXIS);
+ int zAxis = Esplora.readAccelerometer(Z_AXIS);
+
+ Esplora.writeRed(100);
+
+ Keyboard.print(timeSecs);
+ Keyboard.write(KEY_TAB);
+ activeDelay(300);
+ Keyboard.print(xAxis);
+ Keyboard.write(KEY_TAB);
+ activeDelay(300);
+ Keyboard.print(yAxis);
+ Keyboard.write(KEY_TAB);
+ activeDelay(300);
+ Keyboard.print(zAxis);
+ Keyboard.println();
+ activeDelay(300);
+ Keyboard.write(KEY_HOME);
+
+ Esplora.writeRed(0);
+}
+
+/**
+ * Similar to delay(), but allows the program to do something else
+ * in the meanwhile. In particular, it calls checkSwitchPress().
+ * Note 1: it may wait longer than the specified amount, not less;
+ * Note 2: beware of data synchronization issues, e.g. if the
+ * activeDelay() function alters some variables used by the
+ * caller of this function.
+ */
+void activeDelay(unsigned long amount) {
+ unsigned long at = millis() + amount;
+ while (millis() < at) {
+ checkSwitchPress();
+ }
+}
+
+/*
+ * This function reads the status of the switch; if it sees that
+ * it was pressed, toggles the status of the "active" variable.
+ * If it's set to true, also the justActivated variable is set to
+ * true, so the loop() function above can do the right things.
+ * This function should be called as often as possible and do as
+ * little as possible, because it can be called while another
+ * function is running.
+ */
+void checkSwitchPress() {
+ boolean startBtn = Esplora.readButton(SWITCH_DOWN);
+
+ if (startBtn != lastStartBtn) {
+ if (startBtn == HIGH) { // button released
+ active = !active;
+ if (active)
+ justActivated = true;
+ }
+
+ lastStartBtn = startBtn;
+ }
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/keywords.txt b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/keywords.txt
new file mode 100644
index 00000000..b225991f
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Esplora/default/keywords.txt
@@ -0,0 +1,69 @@
+#######################################
+# Syntax Coloring Map For Esplora
+#######################################
+# Class
+#######################################
+
+Esplora KEYWORD3
+
+#######################################
+# Methods and Functions
+#######################################
+
+begin KEYWORD2
+readSlider KEYWORD2
+readLightSensor KEYWORD2
+readTemperature KEYWORD2
+readMicrophone KEYWORD2
+readJoystickSwitch KEYWORD2
+readJoystickButton KEYWORD2
+readJoystickX KEYWORD2
+readJoystickY KEYWORD2
+readAccelerometer KEYWORD2
+readButton KEYWORD2
+writeRGB KEYWORD2
+writeRed KEYWORD2
+writeGreen KEYWORD2
+writeBlue KEYWORD2
+readRed KEYWORD2
+readGreen KEYWORD2
+readBlue KEYWORD2
+tone KEYWORD2
+noTone KEYWORD2
+
+
+#######################################
+# Constants
+#######################################
+
+JOYSTICK_BASE LITERAL1
+MAX_CHANNELS LITERAL1
+CH_SWITCH_1 LITERAL1
+CH_SWITCH_2 LITERAL1
+CH_SWITCH_3 LITERAL1
+CH_SWITCH_4 LITERAL1
+CH_SLIDER LITERAL1
+CH_LIGHT LITERAL1
+CH_TEMPERATURE LITERAL1
+CH_MIC LITERAL1
+CH_JOYSTICK_SW LITERAL1
+CH_JOYSTICK_X LITERAL1
+CH_JOYSTICK_Y LITERAL1
+SWITCH_1 LITERAL1
+SWITCH_2 LITERAL1
+SWITCH_3 LITERAL1
+SWITCH_4 LITERAL1
+SWITCH_DOWN LITERAL1
+SWITCH_LEFT LITERAL1
+SWITCH_UP LITERAL1
+SWITCH_RIGHT LITERAL1
+JOYSTICK_DOWN LITERAL1
+JOYSTICK_LEFT LITERAL1
+JOYSTICK_UP LITERAL1
+PRESSED LITERAL1
+RELEASED LITERAL1
+DEGREES_C LITERAL1
+DEGREES_F LITERAL1
+X_AXIS LITERAL1
+Y_AXIS LITERAL1
+Z_AXIS LITERAL1
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dhcp.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dhcp.cpp
new file mode 100644
index 00000000..9e5262c3
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dhcp.cpp
@@ -0,0 +1,480 @@
+// DHCP Library v0.3 - April 25, 2009
+// Author: Jordan Terrell - blog.jordanterrell.com
+
+#include "w5100.h"
+
+#include
+#include
+#include "Dhcp.h"
+#include "Arduino.h"
+#include "util.h"
+
+int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
+{
+ _dhcpLeaseTime=0;
+ _dhcpT1=0;
+ _dhcpT2=0;
+ _lastCheck=0;
+ _timeout = timeout;
+ _responseTimeout = responseTimeout;
+
+ // zero out _dhcpMacAddr
+ memset(_dhcpMacAddr, 0, 6);
+ reset_DHCP_lease();
+
+ memcpy((void*)_dhcpMacAddr, (void*)mac, 6);
+ _dhcp_state = STATE_DHCP_START;
+ return request_DHCP_lease();
+}
+
+void DhcpClass::reset_DHCP_lease(){
+ // zero out _dhcpSubnetMask, _dhcpGatewayIp, _dhcpLocalIp, _dhcpDhcpServerIp, _dhcpDnsServerIp
+ memset(_dhcpLocalIp, 0, 20);
+}
+
+//return:0 on error, 1 if request is sent and response is received
+int DhcpClass::request_DHCP_lease(){
+
+ uint8_t messageType = 0;
+
+
+
+ // Pick an initial transaction ID
+ _dhcpTransactionId = random(1UL, 2000UL);
+ _dhcpInitialTransactionId = _dhcpTransactionId;
+
+ _dhcpUdpSocket.stop();
+ if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
+ {
+ // Couldn't get a socket
+ return 0;
+ }
+
+ presend_DHCP();
+
+ int result = 0;
+
+ unsigned long startTime = millis();
+
+ while(_dhcp_state != STATE_DHCP_LEASED)
+ {
+ if(_dhcp_state == STATE_DHCP_START)
+ {
+ _dhcpTransactionId++;
+
+ send_DHCP_MESSAGE(DHCP_DISCOVER, ((millis() - startTime) / 1000));
+ _dhcp_state = STATE_DHCP_DISCOVER;
+ }
+ else if(_dhcp_state == STATE_DHCP_REREQUEST){
+ _dhcpTransactionId++;
+ send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime)/1000));
+ _dhcp_state = STATE_DHCP_REQUEST;
+ }
+ else if(_dhcp_state == STATE_DHCP_DISCOVER)
+ {
+ uint32_t respId;
+ messageType = parseDHCPResponse(_responseTimeout, respId);
+ if(messageType == DHCP_OFFER)
+ {
+ // We'll use the transaction ID that the offer came with,
+ // rather than the one we were up to
+ _dhcpTransactionId = respId;
+ send_DHCP_MESSAGE(DHCP_REQUEST, ((millis() - startTime) / 1000));
+ _dhcp_state = STATE_DHCP_REQUEST;
+ }
+ }
+ else if(_dhcp_state == STATE_DHCP_REQUEST)
+ {
+ uint32_t respId;
+ messageType = parseDHCPResponse(_responseTimeout, respId);
+ if(messageType == DHCP_ACK)
+ {
+ _dhcp_state = STATE_DHCP_LEASED;
+ result = 1;
+ //use default lease time if we didn't get it
+ if(_dhcpLeaseTime == 0){
+ _dhcpLeaseTime = DEFAULT_LEASE;
+ }
+ //calculate T1 & T2 if we didn't get it
+ if(_dhcpT1 == 0){
+ //T1 should be 50% of _dhcpLeaseTime
+ _dhcpT1 = _dhcpLeaseTime >> 1;
+ }
+ if(_dhcpT2 == 0){
+ //T2 should be 87.5% (7/8ths) of _dhcpLeaseTime
+ _dhcpT2 = _dhcpT1 << 1;
+ }
+ _renewInSec = _dhcpT1;
+ _rebindInSec = _dhcpT2;
+ }
+ else if(messageType == DHCP_NAK)
+ _dhcp_state = STATE_DHCP_START;
+ }
+
+ if(messageType == 255)
+ {
+ messageType = 0;
+ _dhcp_state = STATE_DHCP_START;
+ }
+
+ if(result != 1 && ((millis() - startTime) > _timeout))
+ break;
+ }
+
+ // We're done with the socket now
+ _dhcpUdpSocket.stop();
+ _dhcpTransactionId++;
+
+ return result;
+}
+
+void DhcpClass::presend_DHCP()
+{
+}
+
+void DhcpClass::send_DHCP_MESSAGE(uint8_t messageType, uint16_t secondsElapsed)
+{
+ uint8_t buffer[32];
+ memset(buffer, 0, 32);
+ IPAddress dest_addr( 255, 255, 255, 255 ); // Broadcast address
+
+ if (-1 == _dhcpUdpSocket.beginPacket(dest_addr, DHCP_SERVER_PORT))
+ {
+ // FIXME Need to return errors
+ return;
+ }
+
+ buffer[0] = DHCP_BOOTREQUEST; // op
+ buffer[1] = DHCP_HTYPE10MB; // htype
+ buffer[2] = DHCP_HLENETHERNET; // hlen
+ buffer[3] = DHCP_HOPS; // hops
+
+ // xid
+ unsigned long xid = htonl(_dhcpTransactionId);
+ memcpy(buffer + 4, &(xid), 4);
+
+ // 8, 9 - seconds elapsed
+ buffer[8] = ((secondsElapsed & 0xff00) >> 8);
+ buffer[9] = (secondsElapsed & 0x00ff);
+
+ // flags
+ unsigned short flags = htons(DHCP_FLAGSBROADCAST);
+ memcpy(buffer + 10, &(flags), 2);
+
+ // ciaddr: already zeroed
+ // yiaddr: already zeroed
+ // siaddr: already zeroed
+ // giaddr: already zeroed
+
+ //put data in W5100 transmit buffer
+ _dhcpUdpSocket.write(buffer, 28);
+
+ memset(buffer, 0, 32); // clear local buffer
+
+ memcpy(buffer, _dhcpMacAddr, 6); // chaddr
+
+ //put data in W5100 transmit buffer
+ _dhcpUdpSocket.write(buffer, 16);
+
+ memset(buffer, 0, 32); // clear local buffer
+
+ // leave zeroed out for sname && file
+ // put in W5100 transmit buffer x 6 (192 bytes)
+
+ for(int i = 0; i < 6; i++) {
+ _dhcpUdpSocket.write(buffer, 32);
+ }
+
+ // OPT - Magic Cookie
+ buffer[0] = (uint8_t)((MAGIC_COOKIE >> 24)& 0xFF);
+ buffer[1] = (uint8_t)((MAGIC_COOKIE >> 16)& 0xFF);
+ buffer[2] = (uint8_t)((MAGIC_COOKIE >> 8)& 0xFF);
+ buffer[3] = (uint8_t)(MAGIC_COOKIE& 0xFF);
+
+ // OPT - message type
+ buffer[4] = dhcpMessageType;
+ buffer[5] = 0x01;
+ buffer[6] = messageType; //DHCP_REQUEST;
+
+ // OPT - client identifier
+ buffer[7] = dhcpClientIdentifier;
+ buffer[8] = 0x07;
+ buffer[9] = 0x01;
+ memcpy(buffer + 10, _dhcpMacAddr, 6);
+
+ // OPT - host name
+ buffer[16] = hostName;
+ buffer[17] = strlen(HOST_NAME) + 6; // length of hostname + last 3 bytes of mac address
+ strcpy((char*)&(buffer[18]), HOST_NAME);
+
+ printByte((char*)&(buffer[24]), _dhcpMacAddr[3]);
+ printByte((char*)&(buffer[26]), _dhcpMacAddr[4]);
+ printByte((char*)&(buffer[28]), _dhcpMacAddr[5]);
+
+ //put data in W5100 transmit buffer
+ _dhcpUdpSocket.write(buffer, 30);
+
+ if(messageType == DHCP_REQUEST)
+ {
+ buffer[0] = dhcpRequestedIPaddr;
+ buffer[1] = 0x04;
+ buffer[2] = _dhcpLocalIp[0];
+ buffer[3] = _dhcpLocalIp[1];
+ buffer[4] = _dhcpLocalIp[2];
+ buffer[5] = _dhcpLocalIp[3];
+
+ buffer[6] = dhcpServerIdentifier;
+ buffer[7] = 0x04;
+ buffer[8] = _dhcpDhcpServerIp[0];
+ buffer[9] = _dhcpDhcpServerIp[1];
+ buffer[10] = _dhcpDhcpServerIp[2];
+ buffer[11] = _dhcpDhcpServerIp[3];
+
+ //put data in W5100 transmit buffer
+ _dhcpUdpSocket.write(buffer, 12);
+ }
+
+ buffer[0] = dhcpParamRequest;
+ buffer[1] = 0x06;
+ buffer[2] = subnetMask;
+ buffer[3] = routersOnSubnet;
+ buffer[4] = dns;
+ buffer[5] = domainName;
+ buffer[6] = dhcpT1value;
+ buffer[7] = dhcpT2value;
+ buffer[8] = endOption;
+
+ //put data in W5100 transmit buffer
+ _dhcpUdpSocket.write(buffer, 9);
+
+ _dhcpUdpSocket.endPacket();
+}
+
+uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId)
+{
+ uint8_t type = 0;
+ uint8_t opt_len = 0;
+
+ unsigned long startTime = millis();
+
+ while(_dhcpUdpSocket.parsePacket() <= 0)
+ {
+ if((millis() - startTime) > responseTimeout)
+ {
+ return 255;
+ }
+ delay(50);
+ }
+ // start reading in the packet
+ RIP_MSG_FIXED fixedMsg;
+ _dhcpUdpSocket.read((uint8_t*)&fixedMsg, sizeof(RIP_MSG_FIXED));
+
+ if(fixedMsg.op == DHCP_BOOTREPLY && _dhcpUdpSocket.remotePort() == DHCP_SERVER_PORT)
+ {
+ transactionId = ntohl(fixedMsg.xid);
+ if(memcmp(fixedMsg.chaddr, _dhcpMacAddr, 6) != 0 || (transactionId < _dhcpInitialTransactionId) || (transactionId > _dhcpTransactionId))
+ {
+ // Need to read the rest of the packet here regardless
+ _dhcpUdpSocket.flush();
+ return 0;
+ }
+
+ memcpy(_dhcpLocalIp, fixedMsg.yiaddr, 4);
+
+ // Skip to the option part
+ // Doing this a byte at a time so we don't have to put a big buffer
+ // on the stack (as we don't have lots of memory lying around)
+ for (int i =0; i < (240 - (int)sizeof(RIP_MSG_FIXED)); i++)
+ {
+ _dhcpUdpSocket.read(); // we don't care about the returned byte
+ }
+
+ while (_dhcpUdpSocket.available() > 0)
+ {
+ switch (_dhcpUdpSocket.read())
+ {
+ case endOption :
+ break;
+
+ case padOption :
+ break;
+
+ case dhcpMessageType :
+ opt_len = _dhcpUdpSocket.read();
+ type = _dhcpUdpSocket.read();
+ break;
+
+ case subnetMask :
+ opt_len = _dhcpUdpSocket.read();
+ _dhcpUdpSocket.read(_dhcpSubnetMask, 4);
+ break;
+
+ case routersOnSubnet :
+ opt_len = _dhcpUdpSocket.read();
+ _dhcpUdpSocket.read(_dhcpGatewayIp, 4);
+ for (int i = 0; i < opt_len-4; i++)
+ {
+ _dhcpUdpSocket.read();
+ }
+ break;
+
+ case dns :
+ opt_len = _dhcpUdpSocket.read();
+ _dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
+ for (int i = 0; i < opt_len-4; i++)
+ {
+ _dhcpUdpSocket.read();
+ }
+ break;
+
+ case dhcpServerIdentifier :
+ opt_len = _dhcpUdpSocket.read();
+ if( *((uint32_t*)_dhcpDhcpServerIp) == 0 ||
+ IPAddress(_dhcpDhcpServerIp) == _dhcpUdpSocket.remoteIP() )
+ {
+ _dhcpUdpSocket.read(_dhcpDhcpServerIp, sizeof(_dhcpDhcpServerIp));
+ }
+ else
+ {
+ // Skip over the rest of this option
+ while (opt_len--)
+ {
+ _dhcpUdpSocket.read();
+ }
+ }
+ break;
+
+ case dhcpT1value :
+ opt_len = _dhcpUdpSocket.read();
+ _dhcpUdpSocket.read((uint8_t*)&_dhcpT1, sizeof(_dhcpT1));
+ _dhcpT1 = ntohl(_dhcpT1);
+ break;
+
+ case dhcpT2value :
+ opt_len = _dhcpUdpSocket.read();
+ _dhcpUdpSocket.read((uint8_t*)&_dhcpT2, sizeof(_dhcpT2));
+ _dhcpT2 = ntohl(_dhcpT2);
+ break;
+
+ case dhcpIPaddrLeaseTime :
+ opt_len = _dhcpUdpSocket.read();
+ _dhcpUdpSocket.read((uint8_t*)&_dhcpLeaseTime, sizeof(_dhcpLeaseTime));
+ _dhcpLeaseTime = ntohl(_dhcpLeaseTime);
+ _renewInSec = _dhcpLeaseTime;
+ break;
+
+ default :
+ opt_len = _dhcpUdpSocket.read();
+ // Skip over the rest of this option
+ while (opt_len--)
+ {
+ _dhcpUdpSocket.read();
+ }
+ break;
+ }
+ }
+ }
+
+ // Need to skip to end of the packet regardless here
+ _dhcpUdpSocket.flush();
+
+ return type;
+}
+
+
+/*
+ returns:
+ 0/DHCP_CHECK_NONE: nothing happened
+ 1/DHCP_CHECK_RENEW_FAIL: renew failed
+ 2/DHCP_CHECK_RENEW_OK: renew success
+ 3/DHCP_CHECK_REBIND_FAIL: rebind fail
+ 4/DHCP_CHECK_REBIND_OK: rebind success
+*/
+int DhcpClass::checkLease(){
+ //this uses a signed / unsigned trick to deal with millis overflow
+ unsigned long now = millis();
+ signed long snow = (long)now;
+ int rc=DHCP_CHECK_NONE;
+ if (_lastCheck != 0){
+ signed long factor;
+ //calc how many ms past the timeout we are
+ factor = snow - (long)_secTimeout;
+ //if on or passed the timeout, reduce the counters
+ if ( factor >= 0 ){
+ //next timeout should be now plus 1000 ms minus parts of second in factor
+ _secTimeout = snow + 1000 - factor % 1000;
+ //how many seconds late are we, minimum 1
+ factor = factor / 1000 +1;
+
+ //reduce the counters by that mouch
+ //if we can assume that the cycle time (factor) is fairly constant
+ //and if the remainder is less than cycle time * 2
+ //do it early instead of late
+ if(_renewInSec < factor*2 )
+ _renewInSec = 0;
+ else
+ _renewInSec -= factor;
+
+ if(_rebindInSec < factor*2 )
+ _rebindInSec = 0;
+ else
+ _rebindInSec -= factor;
+ }
+
+ //if we have a lease but should renew, do it
+ if (_dhcp_state == STATE_DHCP_LEASED && _renewInSec <=0){
+ _dhcp_state = STATE_DHCP_REREQUEST;
+ rc = 1 + request_DHCP_lease();
+ }
+
+ //if we have a lease or is renewing but should bind, do it
+ if( (_dhcp_state == STATE_DHCP_LEASED || _dhcp_state == STATE_DHCP_START) && _rebindInSec <=0){
+ //this should basically restart completely
+ _dhcp_state = STATE_DHCP_START;
+ reset_DHCP_lease();
+ rc = 3 + request_DHCP_lease();
+ }
+ }
+ else{
+ _secTimeout = snow + 1000;
+ }
+
+ _lastCheck = now;
+ return rc;
+}
+
+IPAddress DhcpClass::getLocalIp()
+{
+ return IPAddress(_dhcpLocalIp);
+}
+
+IPAddress DhcpClass::getSubnetMask()
+{
+ return IPAddress(_dhcpSubnetMask);
+}
+
+IPAddress DhcpClass::getGatewayIp()
+{
+ return IPAddress(_dhcpGatewayIp);
+}
+
+IPAddress DhcpClass::getDhcpServerIp()
+{
+ return IPAddress(_dhcpDhcpServerIp);
+}
+
+IPAddress DhcpClass::getDnsServerIp()
+{
+ return IPAddress(_dhcpDnsServerIp);
+}
+
+void DhcpClass::printByte(char * buf, uint8_t n ) {
+ char *str = &buf[1];
+ buf[0]='0';
+ do {
+ unsigned long m = n;
+ n /= 16;
+ char c = m - 16 * n;
+ *str-- = c < 10 ? c + '0' : c + 'A' - 10;
+ } while(n);
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dhcp.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dhcp.h
new file mode 100644
index 00000000..6f9c632c
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dhcp.h
@@ -0,0 +1,178 @@
+// DHCP Library v0.3 - April 25, 2009
+// Author: Jordan Terrell - blog.jordanterrell.com
+
+#ifndef Dhcp_h
+#define Dhcp_h
+
+#include "EthernetUdp.h"
+
+/* DHCP state machine. */
+#define STATE_DHCP_START 0
+#define STATE_DHCP_DISCOVER 1
+#define STATE_DHCP_REQUEST 2
+#define STATE_DHCP_LEASED 3
+#define STATE_DHCP_REREQUEST 4
+#define STATE_DHCP_RELEASE 5
+
+#define DHCP_FLAGSBROADCAST 0x8000
+
+/* UDP port numbers for DHCP */
+#define DHCP_SERVER_PORT 67 /* from server to client */
+#define DHCP_CLIENT_PORT 68 /* from client to server */
+
+/* DHCP message OP code */
+#define DHCP_BOOTREQUEST 1
+#define DHCP_BOOTREPLY 2
+
+/* DHCP message type */
+#define DHCP_DISCOVER 1
+#define DHCP_OFFER 2
+#define DHCP_REQUEST 3
+#define DHCP_DECLINE 4
+#define DHCP_ACK 5
+#define DHCP_NAK 6
+#define DHCP_RELEASE 7
+#define DHCP_INFORM 8
+
+#define DHCP_HTYPE10MB 1
+#define DHCP_HTYPE100MB 2
+
+#define DHCP_HLENETHERNET 6
+#define DHCP_HOPS 0
+#define DHCP_SECS 0
+
+#define MAGIC_COOKIE 0x63825363
+#define MAX_DHCP_OPT 16
+
+#define HOST_NAME "WIZnet"
+#define DEFAULT_LEASE (900) //default lease time in seconds
+
+#define DHCP_CHECK_NONE (0)
+#define DHCP_CHECK_RENEW_FAIL (1)
+#define DHCP_CHECK_RENEW_OK (2)
+#define DHCP_CHECK_REBIND_FAIL (3)
+#define DHCP_CHECK_REBIND_OK (4)
+
+enum
+{
+ padOption = 0,
+ subnetMask = 1,
+ timerOffset = 2,
+ routersOnSubnet = 3,
+ /* timeServer = 4,
+ nameServer = 5,*/
+ dns = 6,
+ /*logServer = 7,
+ cookieServer = 8,
+ lprServer = 9,
+ impressServer = 10,
+ resourceLocationServer = 11,*/
+ hostName = 12,
+ /*bootFileSize = 13,
+ meritDumpFile = 14,*/
+ domainName = 15,
+ /*swapServer = 16,
+ rootPath = 17,
+ extentionsPath = 18,
+ IPforwarding = 19,
+ nonLocalSourceRouting = 20,
+ policyFilter = 21,
+ maxDgramReasmSize = 22,
+ defaultIPTTL = 23,
+ pathMTUagingTimeout = 24,
+ pathMTUplateauTable = 25,
+ ifMTU = 26,
+ allSubnetsLocal = 27,
+ broadcastAddr = 28,
+ performMaskDiscovery = 29,
+ maskSupplier = 30,
+ performRouterDiscovery = 31,
+ routerSolicitationAddr = 32,
+ staticRoute = 33,
+ trailerEncapsulation = 34,
+ arpCacheTimeout = 35,
+ ethernetEncapsulation = 36,
+ tcpDefaultTTL = 37,
+ tcpKeepaliveInterval = 38,
+ tcpKeepaliveGarbage = 39,
+ nisDomainName = 40,
+ nisServers = 41,
+ ntpServers = 42,
+ vendorSpecificInfo = 43,
+ netBIOSnameServer = 44,
+ netBIOSdgramDistServer = 45,
+ netBIOSnodeType = 46,
+ netBIOSscope = 47,
+ xFontServer = 48,
+ xDisplayManager = 49,*/
+ dhcpRequestedIPaddr = 50,
+ dhcpIPaddrLeaseTime = 51,
+ /*dhcpOptionOverload = 52,*/
+ dhcpMessageType = 53,
+ dhcpServerIdentifier = 54,
+ dhcpParamRequest = 55,
+ /*dhcpMsg = 56,
+ dhcpMaxMsgSize = 57,*/
+ dhcpT1value = 58,
+ dhcpT2value = 59,
+ /*dhcpClassIdentifier = 60,*/
+ dhcpClientIdentifier = 61,
+ endOption = 255
+};
+
+typedef struct _RIP_MSG_FIXED
+{
+ uint8_t op;
+ uint8_t htype;
+ uint8_t hlen;
+ uint8_t hops;
+ uint32_t xid;
+ uint16_t secs;
+ uint16_t flags;
+ uint8_t ciaddr[4];
+ uint8_t yiaddr[4];
+ uint8_t siaddr[4];
+ uint8_t giaddr[4];
+ uint8_t chaddr[6];
+}RIP_MSG_FIXED;
+
+class DhcpClass {
+private:
+ uint32_t _dhcpInitialTransactionId;
+ uint32_t _dhcpTransactionId;
+ uint8_t _dhcpMacAddr[6];
+ uint8_t _dhcpLocalIp[4];
+ uint8_t _dhcpSubnetMask[4];
+ uint8_t _dhcpGatewayIp[4];
+ uint8_t _dhcpDhcpServerIp[4];
+ uint8_t _dhcpDnsServerIp[4];
+ uint32_t _dhcpLeaseTime;
+ uint32_t _dhcpT1, _dhcpT2;
+ signed long _renewInSec;
+ signed long _rebindInSec;
+ signed long _lastCheck;
+ unsigned long _timeout;
+ unsigned long _responseTimeout;
+ unsigned long _secTimeout;
+ uint8_t _dhcp_state;
+ EthernetUDP _dhcpUdpSocket;
+
+ int request_DHCP_lease();
+ void reset_DHCP_lease();
+ void presend_DHCP();
+ void send_DHCP_MESSAGE(uint8_t, uint16_t);
+ void printByte(char *, uint8_t);
+
+ uint8_t parseDHCPResponse(unsigned long responseTimeout, uint32_t& transactionId);
+public:
+ IPAddress getLocalIp();
+ IPAddress getSubnetMask();
+ IPAddress getGatewayIp();
+ IPAddress getDhcpServerIp();
+ IPAddress getDnsServerIp();
+
+ int beginWithDHCP(uint8_t *, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
+ int checkLease();
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dns.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dns.cpp
new file mode 100644
index 00000000..b3c1a9dc
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dns.cpp
@@ -0,0 +1,423 @@
+// Arduino DNS client for WizNet5100-based Ethernet shield
+// (c) Copyright 2009-2010 MCQN Ltd.
+// Released under Apache License, version 2.0
+
+#include "w5100.h"
+#include "EthernetUdp.h"
+#include "util.h"
+
+#include "Dns.h"
+#include
+//#include
+#include "Arduino.h"
+
+
+#define SOCKET_NONE 255
+// Various flags and header field values for a DNS message
+#define UDP_HEADER_SIZE 8
+#define DNS_HEADER_SIZE 12
+#define TTL_SIZE 4
+#define QUERY_FLAG (0)
+#define RESPONSE_FLAG (1<<15)
+#define QUERY_RESPONSE_MASK (1<<15)
+#define OPCODE_STANDARD_QUERY (0)
+#define OPCODE_INVERSE_QUERY (1<<11)
+#define OPCODE_STATUS_REQUEST (2<<11)
+#define OPCODE_MASK (15<<11)
+#define AUTHORITATIVE_FLAG (1<<10)
+#define TRUNCATION_FLAG (1<<9)
+#define RECURSION_DESIRED_FLAG (1<<8)
+#define RECURSION_AVAILABLE_FLAG (1<<7)
+#define RESP_NO_ERROR (0)
+#define RESP_FORMAT_ERROR (1)
+#define RESP_SERVER_FAILURE (2)
+#define RESP_NAME_ERROR (3)
+#define RESP_NOT_IMPLEMENTED (4)
+#define RESP_REFUSED (5)
+#define RESP_MASK (15)
+#define TYPE_A (0x0001)
+#define CLASS_IN (0x0001)
+#define LABEL_COMPRESSION_MASK (0xC0)
+// Port number that DNS servers listen on
+#define DNS_PORT 53
+
+// Possible return codes from ProcessResponse
+#define SUCCESS 1
+#define TIMED_OUT -1
+#define INVALID_SERVER -2
+#define TRUNCATED -3
+#define INVALID_RESPONSE -4
+
+void DNSClient::begin(const IPAddress& aDNSServer)
+{
+ iDNSServer = aDNSServer;
+ iRequestId = 0;
+}
+
+
+int DNSClient::inet_aton(const char* aIPAddrString, IPAddress& aResult)
+{
+ // See if we've been given a valid IP address
+ const char* p =aIPAddrString;
+ while (*p &&
+ ( (*p == '.') || (*p >= '0') || (*p <= '9') ))
+ {
+ p++;
+ }
+
+ if (*p == '\0')
+ {
+ // It's looking promising, we haven't found any invalid characters
+ p = aIPAddrString;
+ int segment =0;
+ int segmentValue =0;
+ while (*p && (segment < 4))
+ {
+ if (*p == '.')
+ {
+ // We've reached the end of a segment
+ if (segmentValue > 255)
+ {
+ // You can't have IP address segments that don't fit in a byte
+ return 0;
+ }
+ else
+ {
+ aResult[segment] = (byte)segmentValue;
+ segment++;
+ segmentValue = 0;
+ }
+ }
+ else
+ {
+ // Next digit
+ segmentValue = (segmentValue*10)+(*p - '0');
+ }
+ p++;
+ }
+ // We've reached the end of address, but there'll still be the last
+ // segment to deal with
+ if ((segmentValue > 255) || (segment > 3))
+ {
+ // You can't have IP address segments that don't fit in a byte,
+ // or more than four segments
+ return 0;
+ }
+ else
+ {
+ aResult[segment] = (byte)segmentValue;
+ return 1;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult)
+{
+ int ret =0;
+
+ // See if it's a numeric IP address
+ if (inet_aton(aHostname, aResult))
+ {
+ // It is, our work here is done
+ return 1;
+ }
+
+ // Check we've got a valid DNS server to use
+ if (iDNSServer == INADDR_NONE)
+ {
+ return INVALID_SERVER;
+ }
+
+ // Find a socket to use
+ if (iUdp.begin(1024+(millis() & 0xF)) == 1)
+ {
+ // Try up to three times
+ int retries = 0;
+// while ((retries < 3) && (ret <= 0))
+ {
+ // Send DNS request
+ ret = iUdp.beginPacket(iDNSServer, DNS_PORT);
+ if (ret != 0)
+ {
+ // Now output the request data
+ ret = BuildRequest(aHostname);
+ if (ret != 0)
+ {
+ // And finally send the request
+ ret = iUdp.endPacket();
+ if (ret != 0)
+ {
+ // Now wait for a response
+ int wait_retries = 0;
+ ret = TIMED_OUT;
+ while ((wait_retries < 3) && (ret == TIMED_OUT))
+ {
+ ret = ProcessResponse(5000, aResult);
+ wait_retries++;
+ }
+ }
+ }
+ }
+ retries++;
+ }
+
+ // We're done with the socket now
+ iUdp.stop();
+ }
+
+ return ret;
+}
+
+uint16_t DNSClient::BuildRequest(const char* aName)
+{
+ // Build header
+ // 1 1 1 1 1 1
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // | ID |
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // | QDCOUNT |
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // | ANCOUNT |
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // | NSCOUNT |
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // | ARCOUNT |
+ // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
+ // As we only support one request at a time at present, we can simplify
+ // some of this header
+ iRequestId = millis(); // generate a random ID
+ uint16_t twoByteBuffer;
+
+ // FIXME We should also check that there's enough space available to write to, rather
+ // FIXME than assume there's enough space (as the code does at present)
+ iUdp.write((uint8_t*)&iRequestId, sizeof(iRequestId));
+
+ twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+
+ twoByteBuffer = htons(1); // One question record
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+
+ twoByteBuffer = 0; // Zero answer records
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+ // and zero additional records
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+
+ // Build question
+ const char* start =aName;
+ const char* end =start;
+ uint8_t len;
+ // Run through the name being requested
+ while (*end)
+ {
+ // Find out how long this section of the name is
+ end = start;
+ while (*end && (*end != '.') )
+ {
+ end++;
+ }
+
+ if (end-start > 0)
+ {
+ // Write out the size of this section
+ len = end-start;
+ iUdp.write(&len, sizeof(len));
+ // And then write out the section
+ iUdp.write((uint8_t*)start, end-start);
+ }
+ start = end+1;
+ }
+
+ // We've got to the end of the question name, so
+ // terminate it with a zero-length section
+ len = 0;
+ iUdp.write(&len, sizeof(len));
+ // Finally the type and class of question
+ twoByteBuffer = htons(TYPE_A);
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+
+ twoByteBuffer = htons(CLASS_IN); // Internet class of question
+ iUdp.write((uint8_t*)&twoByteBuffer, sizeof(twoByteBuffer));
+ // Success! Everything buffered okay
+ return 1;
+}
+
+
+uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress)
+{
+ uint32_t startTime = millis();
+
+ // Wait for a response packet
+ while(iUdp.parsePacket() <= 0)
+ {
+ if((millis() - startTime) > aTimeout)
+ return TIMED_OUT;
+ delay(50);
+ }
+
+ // We've had a reply!
+ // Read the UDP header
+ uint8_t header[DNS_HEADER_SIZE]; // Enough space to reuse for the DNS header
+ // Check that it's a response from the right server and the right port
+ if ( (iDNSServer != iUdp.remoteIP()) ||
+ (iUdp.remotePort() != DNS_PORT) )
+ {
+ // It's not from who we expected
+ return INVALID_SERVER;
+ }
+
+ // Read through the rest of the response
+ if (iUdp.available() < DNS_HEADER_SIZE)
+ {
+ return TRUNCATED;
+ }
+ iUdp.read(header, DNS_HEADER_SIZE);
+
+ uint16_t header_flags = htons(*((uint16_t*)&header[2]));
+ // Check that it's a response to this request
+ if ( ( iRequestId != (*((uint16_t*)&header[0])) ) ||
+ ((header_flags & QUERY_RESPONSE_MASK) != (uint16_t)RESPONSE_FLAG) )
+ {
+ // Mark the entire packet as read
+ iUdp.flush();
+ return INVALID_RESPONSE;
+ }
+ // Check for any errors in the response (or in our request)
+ // although we don't do anything to get round these
+ if ( (header_flags & TRUNCATION_FLAG) || (header_flags & RESP_MASK) )
+ {
+ // Mark the entire packet as read
+ iUdp.flush();
+ return -5; //INVALID_RESPONSE;
+ }
+
+ // And make sure we've got (at least) one answer
+ uint16_t answerCount = htons(*((uint16_t*)&header[6]));
+ if (answerCount == 0 )
+ {
+ // Mark the entire packet as read
+ iUdp.flush();
+ return -6; //INVALID_RESPONSE;
+ }
+
+ // Skip over any questions
+ for (uint16_t i =0; i < htons(*((uint16_t*)&header[4])); i++)
+ {
+ // Skip over the name
+ uint8_t len;
+ do
+ {
+ iUdp.read(&len, sizeof(len));
+ if (len > 0)
+ {
+ // Don't need to actually read the data out for the string, just
+ // advance ptr to beyond it
+ while(len--)
+ {
+ iUdp.read(); // we don't care about the returned byte
+ }
+ }
+ } while (len != 0);
+
+ // Now jump over the type and class
+ for (int i =0; i < 4; i++)
+ {
+ iUdp.read(); // we don't care about the returned byte
+ }
+ }
+
+ // Now we're up to the bit we're interested in, the answer
+ // There might be more than one answer (although we'll just use the first
+ // type A answer) and some authority and additional resource records but
+ // we're going to ignore all of them.
+
+ for (uint16_t i =0; i < answerCount; i++)
+ {
+ // Skip the name
+ uint8_t len;
+ do
+ {
+ iUdp.read(&len, sizeof(len));
+ if ((len & LABEL_COMPRESSION_MASK) == 0)
+ {
+ // It's just a normal label
+ if (len > 0)
+ {
+ // And it's got a length
+ // Don't need to actually read the data out for the string,
+ // just advance ptr to beyond it
+ while(len--)
+ {
+ iUdp.read(); // we don't care about the returned byte
+ }
+ }
+ }
+ else
+ {
+ // This is a pointer to a somewhere else in the message for the
+ // rest of the name. We don't care about the name, and RFC1035
+ // says that a name is either a sequence of labels ended with a
+ // 0 length octet or a pointer or a sequence of labels ending in
+ // a pointer. Either way, when we get here we're at the end of
+ // the name
+ // Skip over the pointer
+ iUdp.read(); // we don't care about the returned byte
+ // And set len so that we drop out of the name loop
+ len = 0;
+ }
+ } while (len != 0);
+
+ // Check the type and class
+ uint16_t answerType;
+ uint16_t answerClass;
+ iUdp.read((uint8_t*)&answerType, sizeof(answerType));
+ iUdp.read((uint8_t*)&answerClass, sizeof(answerClass));
+
+ // Ignore the Time-To-Live as we don't do any caching
+ for (int i =0; i < TTL_SIZE; i++)
+ {
+ iUdp.read(); // we don't care about the returned byte
+ }
+
+ // And read out the length of this answer
+ // Don't need header_flags anymore, so we can reuse it here
+ iUdp.read((uint8_t*)&header_flags, sizeof(header_flags));
+
+ if ( (htons(answerType) == TYPE_A) && (htons(answerClass) == CLASS_IN) )
+ {
+ if (htons(header_flags) != 4)
+ {
+ // It's a weird size
+ // Mark the entire packet as read
+ iUdp.flush();
+ return -9;//INVALID_RESPONSE;
+ }
+ iUdp.read(aAddress.raw_address(), 4);
+ return SUCCESS;
+ }
+ else
+ {
+ // This isn't an answer type we're after, move onto the next one
+ for (uint16_t i =0; i < htons(header_flags); i++)
+ {
+ iUdp.read(); // we don't care about the returned byte
+ }
+ }
+ }
+
+ // Mark the entire packet as read
+ iUdp.flush();
+
+ // If we get here then we haven't found an answer
+ return -10;//INVALID_RESPONSE;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dns.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dns.h
new file mode 100644
index 00000000..c99f5c37
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Dns.h
@@ -0,0 +1,41 @@
+// Arduino DNS client for WizNet5100-based Ethernet shield
+// (c) Copyright 2009-2010 MCQN Ltd.
+// Released under Apache License, version 2.0
+
+#ifndef DNSClient_h
+#define DNSClient_h
+
+#include
+
+class DNSClient
+{
+public:
+ // ctor
+ void begin(const IPAddress& aDNSServer);
+
+ /** Convert a numeric IP address string into a four-byte IP address.
+ @param aIPAddrString IP address to convert
+ @param aResult IPAddress structure to store the returned IP address
+ @result 1 if aIPAddrString was successfully converted to an IP address,
+ else error code
+ */
+ int inet_aton(const char *aIPAddrString, IPAddress& aResult);
+
+ /** Resolve the given hostname to an IP address.
+ @param aHostname Name to be resolved
+ @param aResult IPAddress structure to store the returned IP address
+ @result 1 if aIPAddrString was successfully converted to an IP address,
+ else error code
+ */
+ int getHostByName(const char* aHostname, IPAddress& aResult);
+
+protected:
+ uint16_t BuildRequest(const char* aName);
+ uint16_t ProcessResponse(uint16_t aTimeout, IPAddress& aAddress);
+
+ IPAddress iDNSServer;
+ uint16_t iRequestId;
+ EthernetUDP iUdp;
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Ethernet.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Ethernet.cpp
new file mode 100644
index 00000000..c31a85f0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Ethernet.cpp
@@ -0,0 +1,122 @@
+#include "w5100.h"
+#include "Ethernet.h"
+#include "Dhcp.h"
+
+// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
+uint8_t EthernetClass::_state[MAX_SOCK_NUM] = {
+ 0, 0, 0, 0 };
+uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
+ 0, 0, 0, 0 };
+
+int EthernetClass::begin(uint8_t *mac_address)
+{
+ static DhcpClass s_dhcp;
+ _dhcp = &s_dhcp;
+
+
+ // Initialise the basic info
+ W5100.init();
+ W5100.setMACAddress(mac_address);
+ W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
+
+ // Now try to get our config info from a DHCP server
+ int ret = _dhcp->beginWithDHCP(mac_address);
+ if(ret == 1)
+ {
+ // We've successfully found a DHCP server and got our configuration info, so set things
+ // accordingly
+ W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
+ W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
+ W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
+ _dnsServerAddress = _dhcp->getDnsServerIp();
+ }
+
+ return ret;
+}
+
+void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
+{
+ // Assume the DNS server will be the machine on the same network as the local IP
+ // but with last octet being '1'
+ IPAddress dns_server = local_ip;
+ dns_server[3] = 1;
+ begin(mac_address, local_ip, dns_server);
+}
+
+void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
+{
+ // Assume the gateway will be the machine on the same network as the local IP
+ // but with last octet being '1'
+ IPAddress gateway = local_ip;
+ gateway[3] = 1;
+ begin(mac_address, local_ip, dns_server, gateway);
+}
+
+void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
+{
+ IPAddress subnet(255, 255, 255, 0);
+ begin(mac_address, local_ip, dns_server, gateway, subnet);
+}
+
+void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
+{
+ W5100.init();
+ W5100.setMACAddress(mac);
+ W5100.setIPAddress(local_ip._address);
+ W5100.setGatewayIp(gateway._address);
+ W5100.setSubnetMask(subnet._address);
+ _dnsServerAddress = dns_server;
+}
+
+int EthernetClass::maintain(){
+ int rc = DHCP_CHECK_NONE;
+ if(_dhcp != NULL){
+ //we have a pointer to dhcp, use it
+ rc = _dhcp->checkLease();
+ switch ( rc ){
+ case DHCP_CHECK_NONE:
+ //nothing done
+ break;
+ case DHCP_CHECK_RENEW_OK:
+ case DHCP_CHECK_REBIND_OK:
+ //we might have got a new IP.
+ W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
+ W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
+ W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
+ _dnsServerAddress = _dhcp->getDnsServerIp();
+ break;
+ default:
+ //this is actually a error, it will retry though
+ break;
+ }
+ }
+ return rc;
+}
+
+IPAddress EthernetClass::localIP()
+{
+ IPAddress ret;
+ W5100.getIPAddress(ret.raw_address());
+ return ret;
+}
+
+IPAddress EthernetClass::subnetMask()
+{
+ IPAddress ret;
+ W5100.getSubnetMask(ret.raw_address());
+ return ret;
+}
+
+IPAddress EthernetClass::gatewayIP()
+{
+ IPAddress ret;
+ W5100.getGatewayIp(ret.raw_address());
+ return ret;
+}
+
+IPAddress EthernetClass::dnsServerIP()
+{
+ return _dnsServerAddress;
+}
+
+EthernetClass Ethernet;
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Ethernet.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Ethernet.h
new file mode 100644
index 00000000..2a07ff35
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/Ethernet.h
@@ -0,0 +1,41 @@
+#ifndef ethernet_h
+#define ethernet_h
+
+#include
+//#include "w5100.h"
+#include "IPAddress.h"
+#include "EthernetClient.h"
+#include "EthernetServer.h"
+#include "Dhcp.h"
+
+#define MAX_SOCK_NUM 4
+
+class EthernetClass {
+private:
+ IPAddress _dnsServerAddress;
+ DhcpClass* _dhcp;
+public:
+ static uint8_t _state[MAX_SOCK_NUM];
+ static uint16_t _server_port[MAX_SOCK_NUM];
+ // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
+ // configuration through DHCP.
+ // Returns 0 if the DHCP configuration failed, and 1 if it succeeded
+ int begin(uint8_t *mac_address);
+ void begin(uint8_t *mac_address, IPAddress local_ip);
+ void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
+ void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
+ void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
+ int maintain();
+
+ IPAddress localIP();
+ IPAddress subnetMask();
+ IPAddress gatewayIP();
+ IPAddress dnsServerIP();
+
+ friend class EthernetClient;
+ friend class EthernetServer;
+};
+
+extern EthernetClass Ethernet;
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetClient.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetClient.cpp
new file mode 100644
index 00000000..9885efb7
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetClient.cpp
@@ -0,0 +1,165 @@
+#include "w5100.h"
+#include "socket.h"
+
+extern "C" {
+ #include "string.h"
+}
+
+#include "Arduino.h"
+
+#include "Ethernet.h"
+#include "EthernetClient.h"
+#include "EthernetServer.h"
+#include "Dns.h"
+
+uint16_t EthernetClient::_srcport = 1024;
+
+EthernetClient::EthernetClient() : _sock(MAX_SOCK_NUM) {
+}
+
+EthernetClient::EthernetClient(uint8_t sock) : _sock(sock) {
+}
+
+int EthernetClient::connect(const char* host, uint16_t port) {
+ // Look up the host first
+ int ret = 0;
+ DNSClient dns;
+ IPAddress remote_addr;
+
+ dns.begin(Ethernet.dnsServerIP());
+ ret = dns.getHostByName(host, remote_addr);
+ if (ret == 1) {
+ return connect(remote_addr, port);
+ } else {
+ return ret;
+ }
+}
+
+int EthernetClient::connect(IPAddress ip, uint16_t port) {
+ if (_sock != MAX_SOCK_NUM)
+ return 0;
+
+ for (int i = 0; i < MAX_SOCK_NUM; i++) {
+ uint8_t s = W5100.readSnSR(i);
+ if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
+ _sock = i;
+ break;
+ }
+ }
+
+ if (_sock == MAX_SOCK_NUM)
+ return 0;
+
+ _srcport++;
+ if (_srcport == 0) _srcport = 1024;
+ socket(_sock, SnMR::TCP, _srcport, 0);
+
+ if (!::connect(_sock, rawIPAddress(ip), port)) {
+ _sock = MAX_SOCK_NUM;
+ return 0;
+ }
+
+ while (status() != SnSR::ESTABLISHED) {
+ delay(1);
+ if (status() == SnSR::CLOSED) {
+ _sock = MAX_SOCK_NUM;
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+size_t EthernetClient::write(uint8_t b) {
+ return write(&b, 1);
+}
+
+size_t EthernetClient::write(const uint8_t *buf, size_t size) {
+ if (_sock == MAX_SOCK_NUM) {
+ setWriteError();
+ return 0;
+ }
+ if (!send(_sock, buf, size)) {
+ setWriteError();
+ return 0;
+ }
+ return size;
+}
+
+int EthernetClient::available() {
+ if (_sock != MAX_SOCK_NUM)
+ return W5100.getRXReceivedSize(_sock);
+ return 0;
+}
+
+int EthernetClient::read() {
+ uint8_t b;
+ if ( recv(_sock, &b, 1) > 0 )
+ {
+ // recv worked
+ return b;
+ }
+ else
+ {
+ // No data available
+ return -1;
+ }
+}
+
+int EthernetClient::read(uint8_t *buf, size_t size) {
+ return recv(_sock, buf, size);
+}
+
+int EthernetClient::peek() {
+ uint8_t b;
+ // Unlike recv, peek doesn't check to see if there's any data available, so we must
+ if (!available())
+ return -1;
+ ::peek(_sock, &b);
+ return b;
+}
+
+void EthernetClient::flush() {
+ while (available())
+ read();
+}
+
+void EthernetClient::stop() {
+ if (_sock == MAX_SOCK_NUM)
+ return;
+
+ // attempt to close the connection gracefully (send a FIN to other side)
+ disconnect(_sock);
+ unsigned long start = millis();
+
+ // wait a second for the connection to close
+ while (status() != SnSR::CLOSED && millis() - start < 1000)
+ delay(1);
+
+ // if it hasn't closed, close it forcefully
+ if (status() != SnSR::CLOSED)
+ close(_sock);
+
+ EthernetClass::_server_port[_sock] = 0;
+ _sock = MAX_SOCK_NUM;
+}
+
+uint8_t EthernetClient::connected() {
+ if (_sock == MAX_SOCK_NUM) return 0;
+
+ uint8_t s = status();
+ return !(s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::FIN_WAIT ||
+ (s == SnSR::CLOSE_WAIT && !available()));
+}
+
+uint8_t EthernetClient::status() {
+ if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
+ return W5100.readSnSR(_sock);
+}
+
+// the next function allows us to use the client returned by
+// EthernetServer::available() as the condition in an if-statement.
+
+EthernetClient::operator bool() {
+ return _sock != MAX_SOCK_NUM;
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetClient.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetClient.h
new file mode 100644
index 00000000..44740fea
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetClient.h
@@ -0,0 +1,37 @@
+#ifndef ethernetclient_h
+#define ethernetclient_h
+#include "Arduino.h"
+#include "Print.h"
+#include "Client.h"
+#include "IPAddress.h"
+
+class EthernetClient : public Client {
+
+public:
+ EthernetClient();
+ EthernetClient(uint8_t sock);
+
+ uint8_t status();
+ virtual int connect(IPAddress ip, uint16_t port);
+ virtual int connect(const char *host, uint16_t port);
+ virtual size_t write(uint8_t);
+ virtual size_t write(const uint8_t *buf, size_t size);
+ virtual int available();
+ virtual int read();
+ virtual int read(uint8_t *buf, size_t size);
+ virtual int peek();
+ virtual void flush();
+ virtual void stop();
+ virtual uint8_t connected();
+ virtual operator bool();
+
+ friend class EthernetServer;
+
+ using Print::write;
+
+private:
+ static uint16_t _srcport;
+ uint8_t _sock;
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetServer.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetServer.cpp
new file mode 100644
index 00000000..0308b926
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetServer.cpp
@@ -0,0 +1,91 @@
+#include "w5100.h"
+#include "socket.h"
+extern "C" {
+#include "string.h"
+}
+
+#include "Ethernet.h"
+#include "EthernetClient.h"
+#include "EthernetServer.h"
+
+EthernetServer::EthernetServer(uint16_t port)
+{
+ _port = port;
+}
+
+void EthernetServer::begin()
+{
+ for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
+ EthernetClient client(sock);
+ if (client.status() == SnSR::CLOSED) {
+ socket(sock, SnMR::TCP, _port, 0);
+ listen(sock);
+ EthernetClass::_server_port[sock] = _port;
+ break;
+ }
+ }
+}
+
+void EthernetServer::accept()
+{
+ int listening = 0;
+
+ for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
+ EthernetClient client(sock);
+
+ if (EthernetClass::_server_port[sock] == _port) {
+ if (client.status() == SnSR::LISTEN) {
+ listening = 1;
+ }
+ else if (client.status() == SnSR::CLOSE_WAIT && !client.available()) {
+ client.stop();
+ }
+ }
+ }
+
+ if (!listening) {
+ begin();
+ }
+}
+
+EthernetClient EthernetServer::available()
+{
+ accept();
+
+ for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
+ EthernetClient client(sock);
+ if (EthernetClass::_server_port[sock] == _port &&
+ (client.status() == SnSR::ESTABLISHED ||
+ client.status() == SnSR::CLOSE_WAIT)) {
+ if (client.available()) {
+ // XXX: don't always pick the lowest numbered socket.
+ return client;
+ }
+ }
+ }
+
+ return EthernetClient(MAX_SOCK_NUM);
+}
+
+size_t EthernetServer::write(uint8_t b)
+{
+ return write(&b, 1);
+}
+
+size_t EthernetServer::write(const uint8_t *buffer, size_t size)
+{
+ size_t n = 0;
+
+ accept();
+
+ for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
+ EthernetClient client(sock);
+
+ if (EthernetClass::_server_port[sock] == _port &&
+ client.status() == SnSR::ESTABLISHED) {
+ n += client.write(buffer, size);
+ }
+ }
+
+ return n;
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetServer.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetServer.h
new file mode 100644
index 00000000..86ccafe9
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetServer.h
@@ -0,0 +1,22 @@
+#ifndef ethernetserver_h
+#define ethernetserver_h
+
+#include "Server.h"
+
+class EthernetClient;
+
+class EthernetServer :
+public Server {
+private:
+ uint16_t _port;
+ void accept();
+public:
+ EthernetServer(uint16_t);
+ EthernetClient available();
+ virtual void begin();
+ virtual size_t write(uint8_t);
+ virtual size_t write(const uint8_t *buf, size_t size);
+ using Print::write;
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetUdp.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetUdp.cpp
new file mode 100644
index 00000000..37600529
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetUdp.cpp
@@ -0,0 +1,218 @@
+/*
+ * Udp.cpp: Library to send/receive UDP packets with the Arduino ethernet shield.
+ * This version only offers minimal wrapping of socket.c/socket.h
+ * Drop Udp.h/.cpp into the Ethernet library directory at hardware/libraries/Ethernet/
+ *
+ * MIT License:
+ * Copyright (c) 2008 Bjoern Hartmann
+ * 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.
+ *
+ * bjoern@cs.stanford.edu 12/30/2008
+ */
+
+#include "w5100.h"
+#include "socket.h"
+#include "Ethernet.h"
+#include "Udp.h"
+#include "Dns.h"
+
+/* Constructor */
+EthernetUDP::EthernetUDP() : _sock(MAX_SOCK_NUM) {}
+
+/* Start EthernetUDP socket, listening at local port PORT */
+uint8_t EthernetUDP::begin(uint16_t port) {
+ if (_sock != MAX_SOCK_NUM)
+ return 0;
+
+ for (int i = 0; i < MAX_SOCK_NUM; i++) {
+ uint8_t s = W5100.readSnSR(i);
+ if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
+ _sock = i;
+ break;
+ }
+ }
+
+ if (_sock == MAX_SOCK_NUM)
+ return 0;
+
+ _port = port;
+ _remaining = 0;
+ socket(_sock, SnMR::UDP, _port, 0);
+
+ return 1;
+}
+
+/* return number of bytes available in the current packet,
+ will return zero if parsePacket hasn't been called yet */
+int EthernetUDP::available() {
+ return _remaining;
+}
+
+/* Release any resources being used by this EthernetUDP instance */
+void EthernetUDP::stop()
+{
+ if (_sock == MAX_SOCK_NUM)
+ return;
+
+ close(_sock);
+
+ EthernetClass::_server_port[_sock] = 0;
+ _sock = MAX_SOCK_NUM;
+}
+
+int EthernetUDP::beginPacket(const char *host, uint16_t port)
+{
+ // Look up the host first
+ int ret = 0;
+ DNSClient dns;
+ IPAddress remote_addr;
+
+ dns.begin(Ethernet.dnsServerIP());
+ ret = dns.getHostByName(host, remote_addr);
+ if (ret == 1) {
+ return beginPacket(remote_addr, port);
+ } else {
+ return ret;
+ }
+}
+
+int EthernetUDP::beginPacket(IPAddress ip, uint16_t port)
+{
+ _offset = 0;
+ return startUDP(_sock, rawIPAddress(ip), port);
+}
+
+int EthernetUDP::endPacket()
+{
+ return sendUDP(_sock);
+}
+
+size_t EthernetUDP::write(uint8_t byte)
+{
+ return write(&byte, 1);
+}
+
+size_t EthernetUDP::write(const uint8_t *buffer, size_t size)
+{
+ uint16_t bytes_written = bufferData(_sock, _offset, buffer, size);
+ _offset += bytes_written;
+ return bytes_written;
+}
+
+int EthernetUDP::parsePacket()
+{
+ // discard any remaining bytes in the last packet
+ flush();
+
+ if (W5100.getRXReceivedSize(_sock) > 0)
+ {
+ //HACK - hand-parse the UDP packet using TCP recv method
+ uint8_t tmpBuf[8];
+ int ret =0;
+ //read 8 header bytes and get IP and port from it
+ ret = recv(_sock,tmpBuf,8);
+ if (ret > 0)
+ {
+ _remoteIP = tmpBuf;
+ _remotePort = tmpBuf[4];
+ _remotePort = (_remotePort << 8) + tmpBuf[5];
+ _remaining = tmpBuf[6];
+ _remaining = (_remaining << 8) + tmpBuf[7];
+
+ // When we get here, any remaining bytes are the data
+ ret = _remaining;
+ }
+ return ret;
+ }
+ // There aren't any packets available
+ return 0;
+}
+
+int EthernetUDP::read()
+{
+ uint8_t byte;
+
+ if ((_remaining > 0) && (recv(_sock, &byte, 1) > 0))
+ {
+ // We read things without any problems
+ _remaining--;
+ return byte;
+ }
+
+ // If we get here, there's no data available
+ return -1;
+}
+
+int EthernetUDP::read(unsigned char* buffer, size_t len)
+{
+
+ if (_remaining > 0)
+ {
+
+ int got;
+
+ if (_remaining <= len)
+ {
+ // data should fit in the buffer
+ got = recv(_sock, buffer, _remaining);
+ }
+ else
+ {
+ // too much data for the buffer,
+ // grab as much as will fit
+ got = recv(_sock, buffer, len);
+ }
+
+ if (got > 0)
+ {
+ _remaining -= got;
+ return got;
+ }
+
+ }
+
+ // If we get here, there's no data available or recv failed
+ return -1;
+
+}
+
+int EthernetUDP::peek()
+{
+ uint8_t b;
+ // Unlike recv, peek doesn't check to see if there's any data available, so we must.
+ // If the user hasn't called parsePacket yet then return nothing otherwise they
+ // may get the UDP header
+ if (!_remaining)
+ return -1;
+ ::peek(_sock, &b);
+ return b;
+}
+
+void EthernetUDP::flush()
+{
+ // could this fail (loop endlessly) if _remaining > 0 and recv in read fails?
+ // should only occur if recv fails after telling us the data is there, lets
+ // hope the w5100 always behaves :)
+
+ while (_remaining)
+ {
+ read();
+ }
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetUdp.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetUdp.h
new file mode 100644
index 00000000..8a6b7ab5
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/EthernetUdp.h
@@ -0,0 +1,99 @@
+/*
+ * Udp.cpp: Library to send/receive UDP packets with the Arduino ethernet shield.
+ * This version only offers minimal wrapping of socket.c/socket.h
+ * Drop Udp.h/.cpp into the Ethernet library directory at hardware/libraries/Ethernet/
+ *
+ * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
+ * 1) UDP does not guarantee the order in which assembled UDP packets are received. This
+ * might not happen often in practice, but in larger network topologies, a UDP
+ * packet can be received out of sequence.
+ * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
+ * aware of it. Again, this may not be a concern in practice on small local networks.
+ * For more information, see http://www.cafeaulait.org/course/week12/35.html
+ *
+ * MIT License:
+ * Copyright (c) 2008 Bjoern Hartmann
+ * 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.
+ *
+ * bjoern@cs.stanford.edu 12/30/2008
+ */
+
+#ifndef ethernetudp_h
+#define ethernetudp_h
+
+#include
+
+#define UDP_TX_PACKET_MAX_SIZE 24
+
+class EthernetUDP : public UDP {
+private:
+ uint8_t _sock; // socket ID for Wiz5100
+ uint16_t _port; // local port to listen on
+ IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed
+ uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed
+ uint16_t _offset; // offset into the packet being sent
+ uint16_t _remaining; // remaining bytes of incoming packet yet to be processed
+
+public:
+ EthernetUDP(); // Constructor
+ virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
+ virtual void stop(); // Finish with the UDP socket
+
+ // Sending UDP packets
+
+ // Start building up a packet to send to the remote host specific in ip and port
+ // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
+ virtual int beginPacket(IPAddress ip, uint16_t port);
+ // Start building up a packet to send to the remote host specific in host and port
+ // Returns 1 if successful, 0 if there was a problem resolving the hostname or port
+ virtual int beginPacket(const char *host, uint16_t port);
+ // Finish off this packet and send it
+ // Returns 1 if the packet was sent successfully, 0 if there was an error
+ virtual int endPacket();
+ // Write a single byte into the packet
+ virtual size_t write(uint8_t);
+ // Write size bytes from buffer into the packet
+ virtual size_t write(const uint8_t *buffer, size_t size);
+
+ using Print::write;
+
+ // Start processing the next available incoming packet
+ // Returns the size of the packet in bytes, or 0 if no packets are available
+ virtual int parsePacket();
+ // Number of bytes remaining in the current packet
+ virtual int available();
+ // Read a single byte from the current packet
+ virtual int read();
+ // Read up to len bytes from the current packet and place them into buffer
+ // Returns the number of bytes read, or 0 if none are available
+ virtual int read(unsigned char* buffer, size_t len);
+ // Read up to len characters from the current packet and place them into buffer
+ // Returns the number of characters read, or 0 if none are available
+ virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
+ // Return the next byte from the current packet without moving on to the next byte
+ virtual int peek();
+ virtual void flush(); // Finish reading the current packet
+
+ // Return the IP address of the host who sent the current incoming packet
+ virtual IPAddress remoteIP() { return _remoteIP; };
+ // Return the port of the host who sent the current incoming packet
+ virtual uint16_t remotePort() { return _remotePort; };
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
new file mode 100644
index 00000000..bfbcb6d4
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino
@@ -0,0 +1,222 @@
+/*
+ SCP1000 Barometric Pressure Sensor Display
+
+ Serves the output of a Barometric Pressure Sensor as a web page.
+ Uses the SPI library. For details on the sensor, see:
+ http://www.sparkfun.com/commerce/product_info.php?products_id=8161
+ http://www.vti.fi/en/support/obsolete_products/pressure_sensors/
+
+ This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
+ http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip
+
+ Circuit:
+ SCP1000 sensor attached to pins 6,7, and 11 - 13:
+ DRDY: pin 6
+ CSB: pin 7
+ MOSI: pin 11
+ MISO: pin 12
+ SCK: pin 13
+
+ created 31 July 2010
+ by Tom Igoe
+ */
+
+#include
+// the sensor communicates using SPI, so include the library:
+#include
+
+
+// assign a MAC address for the ethernet controller.
+// fill in your address here:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+// assign an IP address for the controller:
+IPAddress ip(192,168,1,20);
+IPAddress gateway(192,168,1,1);
+IPAddress subnet(255, 255, 255, 0);
+
+
+// Initialize the Ethernet server library
+// with the IP address and port you want to use
+// (port 80 is default for HTTP):
+EthernetServer server(80);
+
+
+//Sensor's memory register addresses:
+const int PRESSURE = 0x1F; //3 most significant bits of pressure
+const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
+const int TEMPERATURE = 0x21; //16 bit temperature reading
+
+// pins used for the connection with the sensor
+// the others you need are controlled by the SPI library):
+const int dataReadyPin = 6;
+const int chipSelectPin = 7;
+
+float temperature = 0.0;
+long pressure = 0;
+long lastReadingTime = 0;
+
+void setup() {
+ // start the SPI library:
+ SPI.begin();
+
+ // start the Ethernet connection and the server:
+ Ethernet.begin(mac, ip);
+ server.begin();
+
+ // initalize the data ready and chip select pins:
+ pinMode(dataReadyPin, INPUT);
+ pinMode(chipSelectPin, OUTPUT);
+
+ Serial.begin(9600);
+
+ //Configure SCP1000 for low noise configuration:
+ writeRegister(0x02, 0x2D);
+ writeRegister(0x01, 0x03);
+ writeRegister(0x03, 0x02);
+
+ // give the sensor and Ethernet shield time to set up:
+ delay(1000);
+
+ //Set the sensor to high resolution mode tp start readings:
+ writeRegister(0x03, 0x0A);
+
+}
+
+void loop() {
+ // check for a reading no more than once a second.
+ if (millis() - lastReadingTime > 1000){
+ // if there's a reading ready, read it:
+ // don't do anything until the data ready pin is high:
+ if (digitalRead(dataReadyPin) == HIGH) {
+ getData();
+ // timestamp the last time you got a reading:
+ lastReadingTime = millis();
+ }
+ }
+
+ // listen for incoming Ethernet connections:
+ listenForEthernetClients();
+}
+
+
+void getData() {
+ Serial.println("Getting reading");
+ //Read the temperature data
+ int tempData = readRegister(0x21, 2);
+
+ // convert the temperature to celsius and display it:
+ temperature = (float)tempData / 20.0;
+
+ //Read the pressure data highest 3 bits:
+ byte pressureDataHigh = readRegister(0x1F, 1);
+ pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
+
+ //Read the pressure data lower 16 bits:
+ unsigned int pressureDataLow = readRegister(0x20, 2);
+ //combine the two parts into one 19-bit number:
+ pressure = ((pressureDataHigh << 16) | pressureDataLow)/4;
+
+ Serial.print("Temperature: ");
+ Serial.print(temperature);
+ Serial.println(" degrees C");
+ Serial.print("Pressure: " + String(pressure));
+ Serial.println(" Pa");
+}
+
+void listenForEthernetClients() {
+ // listen for incoming clients
+ EthernetClient client = server.available();
+ if (client) {
+ Serial.println("Got a client");
+ // an http request ends with a blank line
+ boolean currentLineIsBlank = true;
+ while (client.connected()) {
+ if (client.available()) {
+ char c = client.read();
+ // if you've gotten to the end of the line (received a newline
+ // character) and the line is blank, the http request has ended,
+ // so you can send a reply
+ if (c == '\n' && currentLineIsBlank) {
+ // send a standard http response header
+ client.println("HTTP/1.1 200 OK");
+ client.println("Content-Type: text/html");
+ client.println();
+ // print the current readings, in HTML format:
+ client.print("Temperature: ");
+ client.print(temperature);
+ client.print(" degrees C");
+ client.println("
");
+ client.print("Pressure: " + String(pressure));
+ client.print(" Pa");
+ client.println("
");
+ break;
+ }
+ if (c == '\n') {
+ // you're starting a new line
+ currentLineIsBlank = true;
+ }
+ else if (c != '\r') {
+ // you've gotten a character on the current line
+ currentLineIsBlank = false;
+ }
+ }
+ }
+ // give the web browser time to receive the data
+ delay(1);
+ // close the connection:
+ client.stop();
+ }
+}
+
+
+//Send a write command to SCP1000
+void writeRegister(byte registerName, byte registerValue) {
+ // SCP1000 expects the register name in the upper 6 bits
+ // of the byte:
+ registerName <<= 2;
+ // command (read or write) goes in the lower two bits:
+ registerName |= 0b00000010; //Write command
+
+ // take the chip select low to select the device:
+ digitalWrite(chipSelectPin, LOW);
+
+ SPI.transfer(registerName); //Send register location
+ SPI.transfer(registerValue); //Send value to record into register
+
+ // take the chip select high to de-select:
+ digitalWrite(chipSelectPin, HIGH);
+}
+
+
+//Read register from the SCP1000:
+unsigned int readRegister(byte registerName, int numBytes) {
+ byte inByte = 0; // incoming from the SPI read
+ unsigned int result = 0; // result to return
+
+ // SCP1000 expects the register name in the upper 6 bits
+ // of the byte:
+ registerName <<= 2;
+ // command (read or write) goes in the lower two bits:
+ registerName &= 0b11111100; //Read command
+
+ // take the chip select low to select the device:
+ digitalWrite(chipSelectPin, LOW);
+ // send the device the register you want to read:
+ int command = SPI.transfer(registerName);
+ // send a value of 0 to read the first byte returned:
+ inByte = SPI.transfer(0x00);
+
+ result = inByte;
+ // if there's more than one byte returned,
+ // shift the first byte then get the second byte:
+ if (numBytes > 1){
+ result = inByte << 8;
+ inByte = SPI.transfer(0x00);
+ result = result |inByte;
+ }
+ // take the chip select high to de-select:
+ digitalWrite(chipSelectPin, HIGH);
+ // return the result:
+ return(result);
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/ChatServer/ChatServer.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/ChatServer/ChatServer.ino
new file mode 100644
index 00000000..d50e5a65
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/ChatServer/ChatServer.ino
@@ -0,0 +1,79 @@
+/*
+ Chat Server
+
+ A simple server that distributes any incoming messages to all
+ connected clients. To use telnet to your device's IP address and type.
+ You can see the client's input in the serial monitor as well.
+ Using an Arduino Wiznet Ethernet shield.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ * Analog inputs attached to pins A0 through A5 (optional)
+
+ created 18 Dec 2009
+ by David A. Mellis
+ modified 9 Apr 2012
+ by Tom Igoe
+
+ */
+
+#include
+#include
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network.
+// gateway and subnet are optional:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+IPAddress ip(192,168,1, 177);
+IPAddress gateway(192,168,1, 1);
+IPAddress subnet(255, 255, 0, 0);
+
+
+// telnet defaults to port 23
+EthernetServer server(23);
+boolean alreadyConnected = false; // whether or not the client was connected previously
+
+void setup() {
+ // initialize the ethernet device
+ Ethernet.begin(mac, ip, gateway, subnet);
+ // start listening for clients
+ server.begin();
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ Serial.print("Chat server address:");
+ Serial.println(Ethernet.localIP());
+}
+
+void loop() {
+ // wait for a new client:
+ EthernetClient client = server.available();
+
+ // when the client sends the first byte, say hello:
+ if (client) {
+ if (!alreadyConnected) {
+ // clead out the input buffer:
+ client.flush();
+ Serial.println("We have a new client");
+ client.println("Hello, client!");
+ alreadyConnected = true;
+ }
+
+ if (client.available() > 0) {
+ // read the bytes incoming from the client:
+ char thisChar = client.read();
+ // echo the bytes back to the client:
+ server.write(thisChar);
+ // echo the bytes to the server as well:
+ Serial.write(thisChar);
+ }
+ }
+}
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
new file mode 100644
index 00000000..5eaaf24d
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
@@ -0,0 +1,59 @@
+/*
+ DHCP-based IP printer
+
+ This sketch uses the DHCP extensions to the Ethernet library
+ to get an IP address via DHCP and print the address obtained.
+ using an Arduino Wiznet Ethernet shield.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 12 April 2011
+ modified 9 Apr 2012
+ by Tom Igoe
+
+ */
+
+#include
+#include
+
+// Enter a MAC address for your controller below.
+// Newer Ethernet shields have a MAC address printed on a sticker on the shield
+byte mac[] = {
+ 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
+
+// Initialize the Ethernet client library
+// with the IP address and port of the server
+// that you want to connect to (port 80 is default for HTTP):
+EthernetClient client;
+
+void setup() {
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ // this check is only needed on the Leonardo:
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+ // start the Ethernet connection:
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // no point in carrying on, so do nothing forevermore:
+ for(;;)
+ ;
+ }
+ // print your local IP address:
+ Serial.print("My IP address: ");
+ for (byte thisByte = 0; thisByte < 4; thisByte++) {
+ // print the value of each byte of the IP address:
+ Serial.print(Ethernet.localIP()[thisByte], DEC);
+ Serial.print(".");
+ }
+ Serial.println();
+}
+
+void loop() {
+
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/DhcpChatServer/DhcpChatServer.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/DhcpChatServer/DhcpChatServer.ino
new file mode 100644
index 00000000..09cbd435
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/DhcpChatServer/DhcpChatServer.ino
@@ -0,0 +1,87 @@
+/*
+ DHCP Chat Server
+
+ A simple server that distributes any incoming messages to all
+ connected clients. To use telnet to your device's IP address and type.
+ You can see the client's input in the serial monitor as well.
+ Using an Arduino Wiznet Ethernet shield.
+
+ THis version attempts to get an IP address using DHCP
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 21 May 2011
+ modified 9 Apr 2012
+ by Tom Igoe
+ Based on ChatServer example by David A. Mellis
+
+ */
+
+#include
+#include
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network.
+// gateway and subnet are optional:
+byte mac[] = {
+ 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
+IPAddress ip(192,168,1, 177);
+IPAddress gateway(192,168,1, 1);
+IPAddress subnet(255, 255, 0, 0);
+
+// telnet defaults to port 23
+EthernetServer server(23);
+boolean gotAMessage = false; // whether or not you got a message from the client yet
+
+void setup() {
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ // this check is only needed on the Leonardo:
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // start the Ethernet connection:
+ Serial.println("Trying to get an IP address using DHCP");
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // initialize the ethernet device not using DHCP:
+ Ethernet.begin(mac, ip, gateway, subnet);
+ }
+ // print your local IP address:
+ Serial.print("My IP address: ");
+ ip = Ethernet.localIP();
+ for (byte thisByte = 0; thisByte < 4; thisByte++) {
+ // print the value of each byte of the IP address:
+ Serial.print(ip[thisByte], DEC);
+ Serial.print(".");
+ }
+ Serial.println();
+ // start listening for clients
+ server.begin();
+
+}
+
+void loop() {
+ // wait for a new client:
+ EthernetClient client = server.available();
+
+ // when the client sends the first byte, say hello:
+ if (client) {
+ if (!gotAMessage) {
+ Serial.println("We have a new client");
+ client.println("Hello, client!");
+ gotAMessage = true;
+ }
+
+ // read the bytes incoming from the client:
+ char thisChar = client.read();
+ // echo the bytes back to the client:
+ server.write(thisChar);
+ // echo the bytes to the server as well:
+ Serial.print(thisChar);
+ }
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/PachubeClient/PachubeClient.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/PachubeClient/PachubeClient.ino
new file mode 100644
index 00000000..dfd2d401
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/PachubeClient/PachubeClient.ino
@@ -0,0 +1,163 @@
+/*
+ Pachube sensor client
+
+ This sketch connects an analog sensor to Pachube (http://www.pachube.com)
+ using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
+ the Adafruit Ethernet shield, either one will work, as long as it's got
+ a Wiznet Ethernet module on board.
+
+ This example has been updated to use version 2.0 of the Pachube.com API.
+ To make it work, create a feed with a datastream, and give it the ID
+ sensor1. Or change the code below to match your feed.
+
+
+ Circuit:
+ * Analog sensor attached to analog in 0
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 15 March 2010
+ modified 9 Apr 2012
+ by Tom Igoe with input from Usman Haque and Joe Saavedra
+
+http://arduino.cc/en/Tutorial/PachubeClient
+ This code is in the public domain.
+
+ */
+
+#include
+#include
+
+#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
+#define FEEDID 00000 // replace your feed ID
+#define USERAGENT "My Project" // user agent is the project name
+
+// assign a MAC address for the ethernet controller.
+// Newer Ethernet shields have a MAC address printed on a sticker on the shield
+// fill in your address here:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,1,20);
+// initialize the library instance:
+EthernetClient client;
+
+// if you don't want to use DNS (and reduce your sketch size)
+// use the numeric IP instead of the name for the server:
+IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
+//char server[] = "api.pachube.com"; // name address for pachube API
+
+unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
+boolean lastConnected = false; // state of the connection last time through the main loop
+const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
+
+void setup() {
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // start the Ethernet connection:
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // DHCP failed, so use a fixed IP address:
+ Ethernet.begin(mac, ip);
+ }
+}
+
+void loop() {
+ // read the analog sensor:
+ int sensorReading = analogRead(A0);
+
+ // if there's incoming data from the net connection.
+ // send it out the serial port. This is for debugging
+ // purposes only:
+ if (client.available()) {
+ char c = client.read();
+ Serial.print(c);
+ }
+
+ // if there's no net connection, but there was one last time
+ // through the loop, then stop the client:
+ if (!client.connected() && lastConnected) {
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+ }
+
+ // if you're not connected, and ten seconds have passed since
+ // your last connection, then connect again and send data:
+ if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+ sendData(sensorReading);
+ }
+ // store the state of the connection for next time through
+ // the loop:
+ lastConnected = client.connected();
+}
+
+// this method makes a HTTP connection to the server:
+void sendData(int thisData) {
+ // if there's a successful connection:
+ if (client.connect(server, 80)) {
+ Serial.println("connecting...");
+ // send the HTTP PUT request:
+ client.print("PUT /v2/feeds/");
+ client.print(FEEDID);
+ client.println(".csv HTTP/1.1");
+ client.println("Host: api.pachube.com");
+ client.print("X-PachubeApiKey: ");
+ client.println(APIKEY);
+ client.print("User-Agent: ");
+ client.println(USERAGENT);
+ client.print("Content-Length: ");
+
+ // calculate the length of the sensor reading in bytes:
+ // 8 bytes for "sensor1," + number of digits of the data:
+ int thisLength = 8 + getLength(thisData);
+ client.println(thisLength);
+
+ // last pieces of the HTTP PUT request:
+ client.println("Content-Type: text/csv");
+ client.println("Connection: close");
+ client.println();
+
+ // here's the actual content of the PUT request:
+ client.print("sensor1,");
+ client.println(thisData);
+
+ }
+ else {
+ // if you couldn't make a connection:
+ Serial.println("connection failed");
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+ }
+ // note the time that the connection was made or attempted:
+ lastConnectionTime = millis();
+}
+
+
+// This method calculates the number of digits in the
+// sensor reading. Since each digit of the ASCII decimal
+// representation is a byte, the number of digits equals
+// the number of bytes:
+
+int getLength(int someValue) {
+ // there's at least one byte:
+ int digits = 1;
+ // continually divide the value by ten,
+ // adding one to the digit count for each
+ // time you divide, until you're at 0:
+ int dividend = someValue /10;
+ while (dividend > 0) {
+ dividend = dividend /10;
+ digits++;
+ }
+ // return the number of digits:
+ return digits;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/PachubeClientString/PachubeClientString.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/PachubeClientString/PachubeClientString.ino
new file mode 100644
index 00000000..26472d12
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/PachubeClientString/PachubeClientString.ino
@@ -0,0 +1,154 @@
+/*
+ Pachube sensor client with Strings
+
+ This sketch connects an analog sensor to Pachube (http://www.pachube.com)
+ using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
+ the Adafruit Ethernet shield, either one will work, as long as it's got
+ a Wiznet Ethernet module on board.
+
+ This example has been updated to use version 2.0 of the pachube.com API.
+ To make it work, create a feed with two datastreams, and give them the IDs
+ sensor1 and sensor2. Or change the code below to match your feed.
+
+ This example uses the String library, which is part of the Arduino core from
+ version 0019.
+
+ Circuit:
+ * Analog sensor attached to analog in 0
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 15 March 2010
+ modified 9 Apr 2012
+ by Tom Igoe with input from Usman Haque and Joe Saavedra
+ modified 8 September 2012
+ by Scott Fitzgerald
+
+ http://arduino.cc/en/Tutorial/PachubeClientString
+ This code is in the public domain.
+
+ */
+
+#include
+#include
+
+
+#define APIKEY "YOUR API KEY GOES HERE" // replace your Pachube api key here
+#define FEEDID 00000 // replace your feed ID
+#define USERAGENT "My Project" // user agent is the project name
+
+
+// assign a MAC address for the ethernet controller.
+// fill in your address here:
+ byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,1,20);
+
+// initialize the library instance:
+EthernetClient client;
+
+// if you don't want to use DNS (and reduce your sketch size)
+// use the numeric IP instead of the name for the server:
+IPAddress server(216,52,233,121); // numeric IP for api.pachube.com
+//char server[] = "api.pachube.com"; // name address for pachube API
+
+unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
+boolean lastConnected = false; // state of the connection last time through the main loop
+const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com
+
+void setup() {
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // give the ethernet module time to boot up:
+ delay(1000);
+ // start the Ethernet connection:
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // DHCP failed, so use a fixed IP address:
+ Ethernet.begin(mac, ip);
+ }
+}
+
+void loop() {
+ // read the analog sensor:
+ int sensorReading = analogRead(A0);
+ // convert the data to a String to send it:
+
+ String dataString = "sensor1,";
+ dataString += sensorReading;
+
+ // you can append multiple readings to this String if your
+ // pachube feed is set up to handle multiple values:
+ int otherSensorReading = analogRead(A1);
+ dataString += "\nsensor2,";
+ dataString += otherSensorReading;
+
+ // if there's incoming data from the net connection.
+ // send it out the serial port. This is for debugging
+ // purposes only:
+ if (client.available()) {
+ char c = client.read();
+ Serial.print(c);
+ }
+
+ // if there's no net connection, but there was one last time
+ // through the loop, then stop the client:
+ if (!client.connected() && lastConnected) {
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+ }
+
+ // if you're not connected, and ten seconds have passed since
+ // your last connection, then connect again and send data:
+ if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+ sendData(dataString);
+ }
+ // store the state of the connection for next time through
+ // the loop:
+ lastConnected = client.connected();
+}
+
+// this method makes a HTTP connection to the server:
+void sendData(String thisData) {
+ // if there's a successful connection:
+ if (client.connect(server, 80)) {
+ Serial.println("connecting...");
+ // send the HTTP PUT request:
+ client.print("PUT /v2/feeds/");
+ client.print(FEEDID);
+ client.println(".csv HTTP/1.1");
+ client.println("Host: api.pachube.com");
+ client.print("X-pachubeApiKey: ");
+ client.println(APIKEY);
+ client.print("User-Agent: ");
+ client.println(USERAGENT);
+ client.print("Content-Length: ");
+ client.println(thisData.length());
+
+ // last pieces of the HTTP PUT request:
+ client.println("Content-Type: text/csv");
+ client.println("Connection: close");
+ client.println();
+
+ // here's the actual content of the PUT request:
+ client.println(thisData);
+ }
+ else {
+ // if you couldn't make a connection:
+ Serial.println("connection failed");
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+ }
+ // note the time that the connection was made or attempted:
+ lastConnectionTime = millis();
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/TelnetClient/TelnetClient.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/TelnetClient/TelnetClient.ino
new file mode 100644
index 00000000..34571256
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/TelnetClient/TelnetClient.ino
@@ -0,0 +1,93 @@
+/*
+ Telnet client
+
+ This sketch connects to a a telnet server (http://www.google.com)
+ using an Arduino Wiznet Ethernet shield. You'll need a telnet server
+ to test this with.
+ Processing's ChatServer example (part of the network library) works well,
+ running on port 10002. It can be found as part of the examples
+ in the Processing application, available at
+ http://processing.org/
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 14 Sep 2010
+ modified 9 Apr 2012
+ by Tom Igoe
+
+ */
+
+#include
+#include
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+IPAddress ip(192,168,1,177);
+
+// Enter the IP address of the server you're connecting to:
+IPAddress server(1,1,1,1);
+
+// Initialize the Ethernet client library
+// with the IP address and port of the server
+// that you want to connect to (port 23 is default for telnet;
+// if you're using Processing's ChatServer, use port 10002):
+EthernetClient client;
+
+void setup() {
+ // start the Ethernet connection:
+ Ethernet.begin(mac, ip);
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // give the Ethernet shield a second to initialize:
+ delay(1000);
+ Serial.println("connecting...");
+
+ // if you get a connection, report back via serial:
+ if (client.connect(server, 10002)) {
+ Serial.println("connected");
+ }
+ else {
+ // if you didn't get a connection to the server:
+ Serial.println("connection failed");
+ }
+}
+
+void loop()
+{
+ // if there are incoming bytes available
+ // from the server, read them and print them:
+ if (client.available()) {
+ char c = client.read();
+ Serial.print(c);
+ }
+
+ // as long as there are bytes in the serial queue,
+ // read them and send them out the socket if it's open:
+ while (Serial.available() > 0) {
+ char inChar = Serial.read();
+ if (client.connected()) {
+ client.print(inChar);
+ }
+ }
+
+ // if the server's disconnected, stop the client:
+ if (!client.connected()) {
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+ // do nothing:
+ while(true);
+ }
+}
+
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/TwitterClient/TwitterClient.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/TwitterClient/TwitterClient.ino
new file mode 100644
index 00000000..9fee1fea
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/TwitterClient/TwitterClient.ino
@@ -0,0 +1,136 @@
+/*
+ Twitter Client with Strings
+
+ This sketch connects to Twitter using an Ethernet shield. It parses the XML
+ returned, and looks for this is a tweet
+
+ You can use the Arduino Ethernet shield, or the Adafruit Ethernet shield,
+ either one will work, as long as it's got a Wiznet Ethernet module on board.
+
+ This example uses the DHCP routines in the Ethernet library which is part of the
+ Arduino core from version 1.0 beta 1
+
+ This example uses the String library, which is part of the Arduino core from
+ version 0019.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 21 May 2011
+ modified 9 Apr 2012
+ by Tom Igoe
+
+ This code is in the public domain.
+
+ */
+#include
+#include
+
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network:
+byte mac[] = {
+ 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
+IPAddress ip(192,168,1,20);
+
+// initialize the library instance:
+EthernetClient client;
+
+const unsigned long requestInterval = 60000; // delay between requests
+
+char serverName[] = "api.twitter.com"; // twitter URL
+
+boolean requested; // whether you've made a request since connecting
+unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
+
+String currentLine = ""; // string to hold the text from server
+String tweet = ""; // string to hold the tweet
+boolean readingTweet = false; // if you're currently reading the tweet
+
+void setup() {
+ // reserve space for the strings:
+ currentLine.reserve(256);
+ tweet.reserve(150);
+
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // attempt a DHCP connection:
+ Serial.println("Attempting to get an IP address using DHCP:");
+ if (!Ethernet.begin(mac)) {
+ // if DHCP fails, start with a hard-coded address:
+ Serial.println("failed to get an IP address using DHCP, trying manually");
+ Ethernet.begin(mac, ip);
+ }
+ Serial.print("My address:");
+ Serial.println(Ethernet.localIP());
+ // connect to Twitter:
+ connectToServer();
+}
+
+
+
+void loop()
+{
+ if (client.connected()) {
+ if (client.available()) {
+ // read incoming bytes:
+ char inChar = client.read();
+
+ // add incoming byte to end of line:
+ currentLine += inChar;
+
+ // if you get a newline, clear the line:
+ if (inChar == '\n') {
+ currentLine = "";
+ }
+ // if the current line ends with , it will
+ // be followed by the tweet:
+ if ( currentLine.endsWith("")) {
+ // tweet is beginning. Clear the tweet string:
+ readingTweet = true;
+ tweet = "";
+ }
+ // if you're currently reading the bytes of a tweet,
+ // add them to the tweet String:
+ if (readingTweet) {
+ if (inChar != '<') {
+ tweet += inChar;
+ }
+ else {
+ // if you got a "<" character,
+ // you've reached the end of the tweet:
+ readingTweet = false;
+ Serial.println(tweet);
+ // close the connection to the server:
+ client.stop();
+ }
+ }
+ }
+ }
+ else if (millis() - lastAttemptTime > requestInterval) {
+ // if you're not connected, and two minutes have passed since
+ // your last connection, then attempt to connect again:
+ connectToServer();
+ }
+}
+
+void connectToServer() {
+ // attempt to connect, and wait a millisecond:
+ Serial.println("connecting to server...");
+ if (client.connect(serverName, 80)) {
+ Serial.println("making HTTP request...");
+ // make HTTP GET request to twitter:
+ client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino&count=1 HTTP/1.1");
+ client.println("HOST: api.twitter.com");
+ client.println("Connection: close");
+ client.println();
+ }
+ // note the time of this connect attempt:
+ lastAttemptTime = millis();
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/UDPSendReceiveString/UDPSendReceiveString.ino
new file mode 100644
index 00000000..4d4045ca
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/UDPSendReceiveString/UDPSendReceiveString.ino
@@ -0,0 +1,118 @@
+/*
+ UDPSendReceive.pde:
+ This sketch receives UDP message strings, prints them to the serial port
+ and sends an "acknowledge" string back to the sender
+
+ A Processing sketch is included at the end of file that can be used to send
+ and received messages for testing with a computer.
+
+ created 21 Aug 2010
+ by Michael Margolis
+
+ This code is in the public domain.
+ */
+
+
+#include // needed for Arduino versions later than 0018
+#include
+#include // UDP library from: bjoern@cs.stanford.edu 12/30/2008
+
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+IPAddress ip(192, 168, 1, 177);
+
+unsigned int localPort = 8888; // local port to listen on
+
+// buffers for receiving and sending data
+char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
+char ReplyBuffer[] = "acknowledged"; // a string to send back
+
+// An EthernetUDP instance to let us send and receive packets over UDP
+EthernetUDP Udp;
+
+void setup() {
+ // start the Ethernet and UDP:
+ Ethernet.begin(mac,ip);
+ Udp.begin(localPort);
+
+ Serial.begin(9600);
+}
+
+void loop() {
+ // if there's data available, read a packet
+ int packetSize = Udp.parsePacket();
+ if(packetSize)
+ {
+ Serial.print("Received packet of size ");
+ Serial.println(packetSize);
+ Serial.print("From ");
+ IPAddress remote = Udp.remoteIP();
+ for (int i =0; i < 4; i++)
+ {
+ Serial.print(remote[i], DEC);
+ if (i < 3)
+ {
+ Serial.print(".");
+ }
+ }
+ Serial.print(", port ");
+ Serial.println(Udp.remotePort());
+
+ // read the packet into packetBufffer
+ Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
+ Serial.println("Contents:");
+ Serial.println(packetBuffer);
+
+ // send a reply, to the IP address and port that sent us the packet we received
+ Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
+ Udp.write(ReplyBuffer);
+ Udp.endPacket();
+ }
+ delay(10);
+}
+
+
+/*
+ Processing sketch to run with this example
+ =====================================================
+
+ // Processing UDP example to send and receive string data from Arduino
+ // press any key to send the "Hello Arduino" message
+
+
+ import hypermedia.net.*;
+
+ UDP udp; // define the UDP object
+
+
+ void setup() {
+ udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
+ //udp.log( true ); // <-- printout the connection activity
+ udp.listen( true ); // and wait for incoming message
+ }
+
+ void draw()
+ {
+ }
+
+ void keyPressed() {
+ String ip = "192.168.1.177"; // the remote IP address
+ int port = 8888; // the destination port
+
+ udp.send("Hello World", ip, port ); // the message to send
+
+ }
+
+ void receive( byte[] data ) { // <-- default handler
+ //void receive( byte[] data, String ip, int port ) { // <-- extended handler
+
+ for(int i=0; i < data.length; i++)
+ print(char(data[i]));
+ println();
+ }
+ */
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/UdpNtpClient/UdpNtpClient.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/UdpNtpClient/UdpNtpClient.ino
new file mode 100644
index 00000000..6b3b53d1
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/UdpNtpClient/UdpNtpClient.ino
@@ -0,0 +1,150 @@
+/*
+
+ Udp NTP Client
+
+ Get the time from a Network Time Protocol (NTP) time server
+ Demonstrates use of UDP sendPacket and ReceivePacket
+ For more on NTP time servers and the messages needed to communicate with them,
+ see http://en.wikipedia.org/wiki/Network_Time_Protocol
+
+ Warning: NTP Servers are subject to temporary failure or IP address change.
+ Plese check
+
+ http://tf.nist.gov/tf-cgi/servers.cgi
+
+ if the time server used in the example didn't work.
+
+ created 4 Sep 2010
+ by Michael Margolis
+ modified 9 Apr 2012
+ by Tom Igoe
+
+ This code is in the public domain.
+
+ */
+
+#include
+#include
+#include
+
+// Enter a MAC address for your controller below.
+// Newer Ethernet shields have a MAC address printed on a sticker on the shield
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+
+unsigned int localPort = 8888; // local port to listen for UDP packets
+
+IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server
+// IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov NTP server
+// IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov NTP server
+
+const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
+
+byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
+
+// A UDP instance to let us send and receive packets over UDP
+EthernetUDP Udp;
+
+void setup()
+{
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // start Ethernet and UDP
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // no point in carrying on, so do nothing forevermore:
+ for(;;)
+ ;
+ }
+ Udp.begin(localPort);
+}
+
+void loop()
+{
+ sendNTPpacket(timeServer); // send an NTP packet to a time server
+
+ // wait to see if a reply is available
+ delay(1000);
+ if ( Udp.parsePacket() ) {
+ // We've received a packet, read the data from it
+ Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
+
+ //the timestamp starts at byte 40 of the received packet and is four bytes,
+ // or two words, long. First, esxtract the two words:
+
+ unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
+ unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
+ // combine the four bytes (two words) into a long integer
+ // this is NTP time (seconds since Jan 1 1900):
+ unsigned long secsSince1900 = highWord << 16 | lowWord;
+ Serial.print("Seconds since Jan 1 1900 = " );
+ Serial.println(secsSince1900);
+
+ // now convert NTP time into everyday time:
+ Serial.print("Unix time = ");
+ // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
+ const unsigned long seventyYears = 2208988800UL;
+ // subtract seventy years:
+ unsigned long epoch = secsSince1900 - seventyYears;
+ // print Unix time:
+ Serial.println(epoch);
+
+
+ // print the hour, minute and second:
+ Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
+ Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
+ Serial.print(':');
+ if ( ((epoch % 3600) / 60) < 10 ) {
+ // In the first 10 minutes of each hour, we'll want a leading '0'
+ Serial.print('0');
+ }
+ Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
+ Serial.print(':');
+ if ( (epoch % 60) < 10 ) {
+ // In the first 10 seconds of each minute, we'll want a leading '0'
+ Serial.print('0');
+ }
+ Serial.println(epoch %60); // print the second
+ }
+ // wait ten seconds before asking for the time again
+ delay(10000);
+}
+
+// send an NTP request to the time server at the given address
+unsigned long sendNTPpacket(IPAddress& address)
+{
+ // set all bytes in the buffer to 0
+ memset(packetBuffer, 0, NTP_PACKET_SIZE);
+ // Initialize values needed to form NTP request
+ // (see URL above for details on the packets)
+ packetBuffer[0] = 0b11100011; // LI, Version, Mode
+ packetBuffer[1] = 0; // Stratum, or type of clock
+ packetBuffer[2] = 6; // Polling Interval
+ packetBuffer[3] = 0xEC; // Peer Clock Precision
+ // 8 bytes of zero for Root Delay & Root Dispersion
+ packetBuffer[12] = 49;
+ packetBuffer[13] = 0x4E;
+ packetBuffer[14] = 49;
+ packetBuffer[15] = 52;
+
+ // all NTP fields have been given values, now
+ // you can send a packet requesting a timestamp:
+ Udp.beginPacket(address, 123); //NTP requests are to port 123
+ Udp.write(packetBuffer,NTP_PACKET_SIZE);
+ Udp.endPacket();
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebClient/WebClient.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebClient/WebClient.ino
new file mode 100644
index 00000000..40523a4d
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebClient/WebClient.ino
@@ -0,0 +1,88 @@
+/*
+ Web client
+
+ This sketch connects to a website (http://www.google.com)
+ using an Arduino Wiznet Ethernet shield.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 18 Dec 2009
+ by David A. Mellis
+ modified 9 Apr 2012
+ by Tom Igoe, based on work by Adrian McEwen
+
+ */
+
+#include
+#include
+
+// Enter a MAC address for your controller below.
+// Newer Ethernet shields have a MAC address printed on a sticker on the shield
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+// if you don't want to use DNS (and reduce your sketch size)
+// use the numeric IP instead of the name for the server:
+//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
+char server[] = "www.google.com"; // name address for Google (using DNS)
+
+// Set the static IP address to use if the DHCP fails to assign
+IPAddress ip(192,168,0,177);
+
+// Initialize the Ethernet client library
+// with the IP address and port of the server
+// that you want to connect to (port 80 is default for HTTP):
+EthernetClient client;
+
+void setup() {
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+ // start the Ethernet connection:
+ if (Ethernet.begin(mac) == 0) {
+ Serial.println("Failed to configure Ethernet using DHCP");
+ // no point in carrying on, so do nothing forevermore:
+ // try to congifure using IP address instead of DHCP:
+ Ethernet.begin(mac, ip);
+ }
+ // give the Ethernet shield a second to initialize:
+ delay(1000);
+ Serial.println("connecting...");
+
+ // if you get a connection, report back via serial:
+ if (client.connect(server, 80)) {
+ Serial.println("connected");
+ // Make a HTTP request:
+ client.println("GET /search?q=arduino HTTP/1.1");
+ client.println("Host: www.google.com");
+ client.println("Connection: close");
+ client.println();
+ }
+ else {
+ // kf you didn't get a connection to the server:
+ Serial.println("connection failed");
+ }
+}
+
+void loop()
+{
+ // if there are incoming bytes available
+ // from the server, read them and print them:
+ if (client.available()) {
+ char c = client.read();
+ Serial.print(c);
+ }
+
+ // if the server's disconnected, stop the client:
+ if (!client.connected()) {
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+
+ // do nothing forevermore:
+ while(true);
+ }
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebClientRepeating/WebClientRepeating.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebClientRepeating/WebClientRepeating.ino
new file mode 100644
index 00000000..e0f06c43
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebClientRepeating/WebClientRepeating.ino
@@ -0,0 +1,110 @@
+/*
+ Repeating Web client
+
+ This sketch connects to a a web server and makes a request
+ using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
+ the Adafruit Ethernet shield, either one will work, as long as it's got
+ a Wiznet Ethernet module on board.
+
+ This example uses DNS, by assigning the Ethernet client with a MAC address,
+ IP address, and DNS address.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+
+ created 19 Apr 2012
+ by Tom Igoe
+
+ http://arduino.cc/en/Tutorial/WebClientRepeating
+ This code is in the public domain.
+
+ */
+
+#include
+#include
+
+// assign a MAC address for the ethernet controller.
+// fill in your address here:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+// fill in an available IP address on your network here,
+// for manual configuration:
+IPAddress ip(10,0,0,20);
+
+// fill in your Domain Name Server address here:
+IPAddress myDns(1,1,1,1);
+
+// initialize the library instance:
+EthernetClient client;
+
+char server[] = "www.arduino.cc";
+
+unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
+boolean lastConnected = false; // state of the connection last time through the main loop
+const unsigned long postingInterval = 60*1000; // delay between updates, in milliseconds
+
+void setup() {
+ // start serial port:
+ Serial.begin(9600);
+ // give the ethernet module time to boot up:
+ delay(1000);
+ // start the Ethernet connection using a fixed IP address and DNS server:
+ Ethernet.begin(mac, ip, myDns);
+ // print the Ethernet board/shield's IP address:
+ Serial.print("My IP address: ");
+ Serial.println(Ethernet.localIP());
+}
+
+void loop() {
+ // if there's incoming data from the net connection.
+ // send it out the serial port. This is for debugging
+ // purposes only:
+ if (client.available()) {
+ char c = client.read();
+ Serial.print(c);
+ }
+
+ // if there's no net connection, but there was one last time
+ // through the loop, then stop the client:
+ if (!client.connected() && lastConnected) {
+ Serial.println();
+ Serial.println("disconnecting.");
+ client.stop();
+ }
+
+ // if you're not connected, and ten seconds have passed since
+ // your last connection, then connect again and send data:
+ if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
+ httpRequest();
+ }
+ // store the state of the connection for next time through
+ // the loop:
+ lastConnected = client.connected();
+}
+
+// this method makes a HTTP connection to the server:
+void httpRequest() {
+ // if there's a successful connection:
+ if (client.connect(server, 80)) {
+ Serial.println("connecting...");
+ // send the HTTP PUT request:
+ client.println("GET /latest.txt HTTP/1.1");
+ client.println("Host: www.arduino.cc");
+ client.println("User-Agent: arduino-ethernet");
+ client.println("Connection: close");
+ client.println();
+
+ // note the time that the connection was made:
+ lastConnectionTime = millis();
+ }
+ else {
+ // if you couldn't make a connection:
+ Serial.println("connection failed");
+ Serial.println("disconnecting.");
+ client.stop();
+ }
+}
+
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebServer/WebServer.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebServer/WebServer.ino
new file mode 100644
index 00000000..5e5d67af
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/examples/WebServer/WebServer.ino
@@ -0,0 +1,100 @@
+/*
+ Web Server
+
+ A simple web server that shows the value of the analog input pins.
+ using an Arduino Wiznet Ethernet shield.
+
+ Circuit:
+ * Ethernet shield attached to pins 10, 11, 12, 13
+ * Analog inputs attached to pins A0 through A5 (optional)
+
+ created 18 Dec 2009
+ by David A. Mellis
+ modified 9 Apr 2012
+ by Tom Igoe
+
+ */
+
+#include
+#include
+
+// Enter a MAC address and IP address for your controller below.
+// The IP address will be dependent on your local network:
+byte mac[] = {
+ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+IPAddress ip(192,168,1,177);
+
+// Initialize the Ethernet server library
+// with the IP address and port you want to use
+// (port 80 is default for HTTP):
+EthernetServer server(80);
+
+void setup() {
+ // Open serial communications and wait for port to open:
+ Serial.begin(9600);
+ while (!Serial) {
+ ; // wait for serial port to connect. Needed for Leonardo only
+ }
+
+
+ // start the Ethernet connection and the server:
+ Ethernet.begin(mac, ip);
+ server.begin();
+ Serial.print("server is at ");
+ Serial.println(Ethernet.localIP());
+}
+
+
+void loop() {
+ // listen for incoming clients
+ EthernetClient client = server.available();
+ if (client) {
+ Serial.println("new client");
+ // an http request ends with a blank line
+ boolean currentLineIsBlank = true;
+ while (client.connected()) {
+ if (client.available()) {
+ char c = client.read();
+ Serial.write(c);
+ // if you've gotten to the end of the line (received a newline
+ // character) and the line is blank, the http request has ended,
+ // so you can send a reply
+ if (c == '\n' && currentLineIsBlank) {
+ // send a standard http response header
+ client.println("HTTP/1.1 200 OK");
+ client.println("Content-Type: text/html");
+ client.println("Connection: close"); // the connection will be closed after completion of the response
+ client.println("Refresh: 5"); // refresh the page automatically every 5 sec
+ client.println();
+ client.println("");
+ client.println("");
+ // output the value of each analog input pin
+ for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
+ int sensorReading = analogRead(analogChannel);
+ client.print("analog input ");
+ client.print(analogChannel);
+ client.print(" is ");
+ client.print(sensorReading);
+ client.println("
");
+ }
+ client.println("");
+ break;
+ }
+ if (c == '\n') {
+ // you're starting a new line
+ currentLineIsBlank = true;
+ }
+ else if (c != '\r') {
+ // you've gotten a character on the current line
+ currentLineIsBlank = false;
+ }
+ }
+ }
+ // give the web browser time to receive the data
+ delay(1);
+ // close the connection:
+ client.stop();
+ Serial.println("client disonnected");
+ }
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/keywords.txt b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/keywords.txt
new file mode 100644
index 00000000..6b37cbe0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/keywords.txt
@@ -0,0 +1,37 @@
+#######################################
+# Syntax Coloring Map For Ethernet
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+Ethernet KEYWORD1
+EthernetClient KEYWORD1
+EthernetServer KEYWORD1
+IPAddress KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+status KEYWORD2
+connect KEYWORD2
+write KEYWORD2
+available KEYWORD2
+read KEYWORD2
+peek KEYWORD2
+flush KEYWORD2
+stop KEYWORD2
+connected KEYWORD2
+begin KEYWORD2
+beginPacket KEYWORD2
+endPacket KEYWORD2
+parsePacket KEYWORD2
+remoteIP KEYWORD2
+remotePort KEYWORD2
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/util.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/util.h
new file mode 100644
index 00000000..5042e82e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/util.h
@@ -0,0 +1,13 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#define htons(x) ( ((x)<<8) | (((x)>>8)&0xFF) )
+#define ntohs(x) htons(x)
+
+#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
+ ((x)<< 8 & 0x00FF0000UL) | \
+ ((x)>> 8 & 0x0000FF00UL) | \
+ ((x)>>24 & 0x000000FFUL) )
+#define ntohl(x) htonl(x)
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/socket.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/socket.cpp
new file mode 100644
index 00000000..fd3e4426
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/socket.cpp
@@ -0,0 +1,400 @@
+#include "w5100.h"
+#include "socket.h"
+
+static uint16_t local_port;
+
+/**
+ * @brief This Socket function initialize the channel in perticular mode, and set the port and wait for W5100 done it.
+ * @return 1 for success else 0.
+ */
+uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
+{
+ if ((protocol == SnMR::TCP) || (protocol == SnMR::UDP) || (protocol == SnMR::IPRAW) || (protocol == SnMR::MACRAW) || (protocol == SnMR::PPPOE))
+ {
+ close(s);
+ W5100.writeSnMR(s, protocol | flag);
+ if (port != 0) {
+ W5100.writeSnPORT(s, port);
+ }
+ else {
+ local_port++; // if don't set the source port, set local_port number.
+ W5100.writeSnPORT(s, local_port);
+ }
+
+ W5100.execCmdSn(s, Sock_OPEN);
+
+ return 1;
+ }
+
+ return 0;
+}
+
+
+/**
+ * @brief This function close the socket and parameter is "s" which represent the socket number
+ */
+void close(SOCKET s)
+{
+ W5100.execCmdSn(s, Sock_CLOSE);
+ W5100.writeSnIR(s, 0xFF);
+}
+
+
+/**
+ * @brief This function established the connection for the channel in passive (server) mode. This function waits for the request from the peer.
+ * @return 1 for success else 0.
+ */
+uint8_t listen(SOCKET s)
+{
+ if (W5100.readSnSR(s) != SnSR::INIT)
+ return 0;
+ W5100.execCmdSn(s, Sock_LISTEN);
+ return 1;
+}
+
+
+/**
+ * @brief This function established the connection for the channel in Active (client) mode.
+ * This function waits for the untill the connection is established.
+ *
+ * @return 1 for success else 0.
+ */
+uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port)
+{
+ if
+ (
+ ((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) ||
+ ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
+ (port == 0x00)
+ )
+ return 0;
+
+ // set destination IP
+ W5100.writeSnDIPR(s, addr);
+ W5100.writeSnDPORT(s, port);
+ W5100.execCmdSn(s, Sock_CONNECT);
+
+ return 1;
+}
+
+
+
+/**
+ * @brief This function used for disconnect the socket and parameter is "s" which represent the socket number
+ * @return 1 for success else 0.
+ */
+void disconnect(SOCKET s)
+{
+ W5100.execCmdSn(s, Sock_DISCON);
+}
+
+
+/**
+ * @brief This function used to send the data in TCP mode
+ * @return 1 for success else 0.
+ */
+uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len)
+{
+ uint8_t status=0;
+ uint16_t ret=0;
+ uint16_t freesize=0;
+
+ if (len > W5100.SSIZE)
+ ret = W5100.SSIZE; // check size not to exceed MAX size.
+ else
+ ret = len;
+
+ // if freebuf is available, start.
+ do
+ {
+ freesize = W5100.getTXFreeSize(s);
+ status = W5100.readSnSR(s);
+ if ((status != SnSR::ESTABLISHED) && (status != SnSR::CLOSE_WAIT))
+ {
+ ret = 0;
+ break;
+ }
+ }
+ while (freesize < ret);
+
+ // copy data
+ W5100.send_data_processing(s, (uint8_t *)buf, ret);
+ W5100.execCmdSn(s, Sock_SEND);
+
+ /* +2008.01 bj */
+ while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
+ {
+ /* m2008.01 [bj] : reduce code */
+ if ( W5100.readSnSR(s) == SnSR::CLOSED )
+ {
+ close(s);
+ return 0;
+ }
+ }
+ /* +2008.01 bj */
+ W5100.writeSnIR(s, SnIR::SEND_OK);
+ return ret;
+}
+
+
+/**
+ * @brief This function is an application I/F function which is used to receive the data in TCP mode.
+ * It continues to wait for data as much as the application wants to receive.
+ *
+ * @return received data size for success else -1.
+ */
+int16_t recv(SOCKET s, uint8_t *buf, int16_t len)
+{
+ // Check how much data is available
+ int16_t ret = W5100.getRXReceivedSize(s);
+ if ( ret == 0 )
+ {
+ // No data available.
+ uint8_t status = W5100.readSnSR(s);
+ if ( status == SnSR::LISTEN || status == SnSR::CLOSED || status == SnSR::CLOSE_WAIT )
+ {
+ // The remote end has closed its side of the connection, so this is the eof state
+ ret = 0;
+ }
+ else
+ {
+ // The connection is still up, but there's no data waiting to be read
+ ret = -1;
+ }
+ }
+ else if (ret > len)
+ {
+ ret = len;
+ }
+
+ if ( ret > 0 )
+ {
+ W5100.recv_data_processing(s, buf, ret);
+ W5100.execCmdSn(s, Sock_RECV);
+ }
+ return ret;
+}
+
+
+/**
+ * @brief Returns the first byte in the receive queue (no checking)
+ *
+ * @return
+ */
+uint16_t peek(SOCKET s, uint8_t *buf)
+{
+ W5100.recv_data_processing(s, buf, 1, 1);
+
+ return 1;
+}
+
+
+/**
+ * @brief This function is an application I/F function which is used to send the data for other then TCP mode.
+ * Unlike TCP transmission, The peer's destination address and the port is needed.
+ *
+ * @return This function return send data size for success else -1.
+ */
+uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
+{
+ uint16_t ret=0;
+
+ if (len > W5100.SSIZE) ret = W5100.SSIZE; // check size not to exceed MAX size.
+ else ret = len;
+
+ if
+ (
+ ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
+ ((port == 0x00)) ||(ret == 0)
+ )
+ {
+ /* +2008.01 [bj] : added return value */
+ ret = 0;
+ }
+ else
+ {
+ W5100.writeSnDIPR(s, addr);
+ W5100.writeSnDPORT(s, port);
+
+ // copy data
+ W5100.send_data_processing(s, (uint8_t *)buf, ret);
+ W5100.execCmdSn(s, Sock_SEND);
+
+ /* +2008.01 bj */
+ while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
+ {
+ if (W5100.readSnIR(s) & SnIR::TIMEOUT)
+ {
+ /* +2008.01 [bj]: clear interrupt */
+ W5100.writeSnIR(s, (SnIR::SEND_OK | SnIR::TIMEOUT)); /* clear SEND_OK & TIMEOUT */
+ return 0;
+ }
+ }
+
+ /* +2008.01 bj */
+ W5100.writeSnIR(s, SnIR::SEND_OK);
+ }
+ return ret;
+}
+
+
+/**
+ * @brief This function is an application I/F function which is used to receive the data in other then
+ * TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well.
+ *
+ * @return This function return received data size for success else -1.
+ */
+uint16_t recvfrom(SOCKET s, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
+{
+ uint8_t head[8];
+ uint16_t data_len=0;
+ uint16_t ptr=0;
+
+ if ( len > 0 )
+ {
+ ptr = W5100.readSnRX_RD(s);
+ switch (W5100.readSnMR(s) & 0x07)
+ {
+ case SnMR::UDP :
+ W5100.read_data(s, (uint8_t *)ptr, head, 0x08);
+ ptr += 8;
+ // read peer's IP address, port number.
+ addr[0] = head[0];
+ addr[1] = head[1];
+ addr[2] = head[2];
+ addr[3] = head[3];
+ *port = head[4];
+ *port = (*port << 8) + head[5];
+ data_len = head[6];
+ data_len = (data_len << 8) + head[7];
+
+ W5100.read_data(s, (uint8_t *)ptr, buf, data_len); // data copy.
+ ptr += data_len;
+
+ W5100.writeSnRX_RD(s, ptr);
+ break;
+
+ case SnMR::IPRAW :
+ W5100.read_data(s, (uint8_t *)ptr, head, 0x06);
+ ptr += 6;
+
+ addr[0] = head[0];
+ addr[1] = head[1];
+ addr[2] = head[2];
+ addr[3] = head[3];
+ data_len = head[4];
+ data_len = (data_len << 8) + head[5];
+
+ W5100.read_data(s, (uint8_t *)ptr, buf, data_len); // data copy.
+ ptr += data_len;
+
+ W5100.writeSnRX_RD(s, ptr);
+ break;
+
+ case SnMR::MACRAW:
+ W5100.read_data(s,(uint8_t*)ptr,head,2);
+ ptr+=2;
+ data_len = head[0];
+ data_len = (data_len<<8) + head[1] - 2;
+
+ W5100.read_data(s,(uint8_t*) ptr,buf,data_len);
+ ptr += data_len;
+ W5100.writeSnRX_RD(s, ptr);
+ break;
+
+ default :
+ break;
+ }
+ W5100.execCmdSn(s, Sock_RECV);
+ }
+ return data_len;
+}
+
+
+uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len)
+{
+ uint8_t status=0;
+ uint16_t ret=0;
+
+ if (len > W5100.SSIZE)
+ ret = W5100.SSIZE; // check size not to exceed MAX size.
+ else
+ ret = len;
+
+ if (ret == 0)
+ return 0;
+
+ W5100.send_data_processing(s, (uint8_t *)buf, ret);
+ W5100.execCmdSn(s, Sock_SEND);
+
+ while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
+ {
+ status = W5100.readSnSR(s);
+ if (W5100.readSnIR(s) & SnIR::TIMEOUT)
+ {
+ /* in case of igmp, if send fails, then socket closed */
+ /* if you want change, remove this code. */
+ close(s);
+ return 0;
+ }
+ }
+
+ W5100.writeSnIR(s, SnIR::SEND_OK);
+ return ret;
+}
+
+uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len)
+{
+ uint16_t ret =0;
+ if (len > W5100.getTXFreeSize(s))
+ {
+ ret = W5100.getTXFreeSize(s); // check size not to exceed MAX size.
+ }
+ else
+ {
+ ret = len;
+ }
+ W5100.send_data_processing_offset(s, offset, buf, ret);
+ return ret;
+}
+
+int startUDP(SOCKET s, uint8_t* addr, uint16_t port)
+{
+ if
+ (
+ ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
+ ((port == 0x00))
+ )
+ {
+ return 0;
+ }
+ else
+ {
+ W5100.writeSnDIPR(s, addr);
+ W5100.writeSnDPORT(s, port);
+ return 1;
+ }
+}
+
+int sendUDP(SOCKET s)
+{
+ W5100.execCmdSn(s, Sock_SEND);
+
+ /* +2008.01 bj */
+ while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
+ {
+ if (W5100.readSnIR(s) & SnIR::TIMEOUT)
+ {
+ /* +2008.01 [bj]: clear interrupt */
+ W5100.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
+ return 0;
+ }
+ }
+
+ /* +2008.01 bj */
+ W5100.writeSnIR(s, SnIR::SEND_OK);
+
+ /* Sent ok */
+ return 1;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/socket.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/socket.h
new file mode 100644
index 00000000..45e0fb3e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/socket.h
@@ -0,0 +1,41 @@
+#ifndef _SOCKET_H_
+#define _SOCKET_H_
+
+#include "w5100.h"
+
+extern uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag); // Opens a socket(TCP or UDP or IP_RAW mode)
+extern void close(SOCKET s); // Close socket
+extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TCP connection (Active connection)
+extern void disconnect(SOCKET s); // disconnect the connection
+extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection)
+extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP)
+extern int16_t recv(SOCKET s, uint8_t * buf, int16_t len); // Receive data (TCP)
+extern uint16_t peek(SOCKET s, uint8_t *buf);
+extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW)
+extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW)
+
+extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len);
+
+// Functions to allow buffered UDP send (i.e. where the UDP datagram is built up over a
+// number of calls before being sent
+/*
+ @brief This function sets up a UDP datagram, the data for which will be provided by one
+ or more calls to bufferData and then finally sent with sendUDP.
+ @return 1 if the datagram was successfully set up, or 0 if there was an error
+*/
+extern int startUDP(SOCKET s, uint8_t* addr, uint16_t port);
+/*
+ @brief This function copies up to len bytes of data from buf into a UDP datagram to be
+ sent later by sendUDP. Allows datagrams to be built up from a series of bufferData calls.
+ @return Number of bytes successfully buffered
+*/
+uint16_t bufferData(SOCKET s, uint16_t offset, const uint8_t* buf, uint16_t len);
+/*
+ @brief Send a UDP datagram built up from a sequence of startUDP followed by one or more
+ calls to bufferData.
+ @return 1 if the datagram was successfully sent, or 0 if there was an error
+*/
+int sendUDP(SOCKET s);
+
+#endif
+/* _SOCKET_H_ */
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/w5100.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/w5100.cpp
new file mode 100644
index 00000000..9c748fd2
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/w5100.cpp
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2010 by Cristian Maglie
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of either the GNU General Public License version 2
+ * or the GNU Lesser General Public License version 2.1, both as
+ * published by the Free Software Foundation.
+ */
+
+#include
+#include
+#include
+
+#include "w5100.h"
+
+// W5100 controller instance
+W5100Class W5100;
+
+#define TX_RX_MAX_BUF_SIZE 2048
+#define TX_BUF 0x1100
+#define RX_BUF (TX_BUF + TX_RX_MAX_BUF_SIZE)
+
+#define TXBUF_BASE 0x4000
+#define RXBUF_BASE 0x6000
+
+void W5100Class::init(void)
+{
+ delay(300);
+
+ SPI.begin();
+ initSS();
+
+ writeMR(1< SSIZE)
+ {
+ // Wrap around circular buffer
+ uint16_t size = SSIZE - offset;
+ write(dstAddr, data, size);
+ write(SBASE[s], data + size, len - size);
+ }
+ else {
+ write(dstAddr, data, len);
+ }
+
+ ptr += len;
+ writeSnTX_WR(s, ptr);
+}
+
+
+void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek)
+{
+ uint16_t ptr;
+ ptr = readSnRX_RD(s);
+ read_data(s, (uint8_t *)ptr, data, len);
+ if (!peek)
+ {
+ ptr += len;
+ writeSnRX_RD(s, ptr);
+ }
+}
+
+void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len)
+{
+ uint16_t size;
+ uint16_t src_mask;
+ uint16_t src_ptr;
+
+ src_mask = (uint16_t)src & RMASK;
+ src_ptr = RBASE[s] + src_mask;
+
+ if( (src_mask + len) > RSIZE )
+ {
+ size = RSIZE - src_mask;
+ read(src_ptr, (uint8_t *)dst, size);
+ dst += size;
+ read(RBASE[s], (uint8_t *) dst, len - size);
+ }
+ else
+ read(src_ptr, (uint8_t *) dst, len);
+}
+
+
+uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
+{
+ setSS();
+ SPI.transfer(0xF0);
+ SPI.transfer(_addr >> 8);
+ SPI.transfer(_addr & 0xFF);
+ SPI.transfer(_data);
+ resetSS();
+ return 1;
+}
+
+uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
+{
+ for (uint16_t i=0; i<_len; i++)
+ {
+ setSS();
+ SPI.transfer(0xF0);
+ SPI.transfer(_addr >> 8);
+ SPI.transfer(_addr & 0xFF);
+ _addr++;
+ SPI.transfer(_buf[i]);
+ resetSS();
+ }
+ return _len;
+}
+
+uint8_t W5100Class::read(uint16_t _addr)
+{
+ setSS();
+ SPI.transfer(0x0F);
+ SPI.transfer(_addr >> 8);
+ SPI.transfer(_addr & 0xFF);
+ uint8_t _data = SPI.transfer(0);
+ resetSS();
+ return _data;
+}
+
+uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
+{
+ for (uint16_t i=0; i<_len; i++)
+ {
+ setSS();
+ SPI.transfer(0x0F);
+ SPI.transfer(_addr >> 8);
+ SPI.transfer(_addr & 0xFF);
+ _addr++;
+ _buf[i] = SPI.transfer(0);
+ resetSS();
+ }
+ return _len;
+}
+
+void W5100Class::execCmdSn(SOCKET s, SockCMD _cmd) {
+ // Send command to socket
+ writeSnCR(s, _cmd);
+ // Wait for command to complete
+ while (readSnCR(s))
+ ;
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/w5100.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/w5100.h
new file mode 100644
index 00000000..8dccd9f2
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Ethernet/default/utility/w5100.h
@@ -0,0 +1,404 @@
+/*
+ * Copyright (c) 2010 by Cristian Maglie
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of either the GNU General Public License version 2
+ * or the GNU Lesser General Public License version 2.1, both as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef W5100_H_INCLUDED
+#define W5100_H_INCLUDED
+
+#include
+#include
+
+#define MAX_SOCK_NUM 4
+
+typedef uint8_t SOCKET;
+
+#define IDM_OR 0x8000
+#define IDM_AR0 0x8001
+#define IDM_AR1 0x8002
+#define IDM_DR 0x8003
+/*
+class MR {
+public:
+ static const uint8_t RST = 0x80;
+ static const uint8_t PB = 0x10;
+ static const uint8_t PPPOE = 0x08;
+ static const uint8_t LB = 0x04;
+ static const uint8_t AI = 0x02;
+ static const uint8_t IND = 0x01;
+};
+*/
+/*
+class IR {
+public:
+ static const uint8_t CONFLICT = 0x80;
+ static const uint8_t UNREACH = 0x40;
+ static const uint8_t PPPoE = 0x20;
+ static const uint8_t SOCK0 = 0x01;
+ static const uint8_t SOCK1 = 0x02;
+ static const uint8_t SOCK2 = 0x04;
+ static const uint8_t SOCK3 = 0x08;
+ static inline uint8_t SOCK(SOCKET ch) { return (0x01 << ch); };
+};
+*/
+
+class SnMR {
+public:
+ static const uint8_t CLOSE = 0x00;
+ static const uint8_t TCP = 0x01;
+ static const uint8_t UDP = 0x02;
+ static const uint8_t IPRAW = 0x03;
+ static const uint8_t MACRAW = 0x04;
+ static const uint8_t PPPOE = 0x05;
+ static const uint8_t ND = 0x20;
+ static const uint8_t MULTI = 0x80;
+};
+
+enum SockCMD {
+ Sock_OPEN = 0x01,
+ Sock_LISTEN = 0x02,
+ Sock_CONNECT = 0x04,
+ Sock_DISCON = 0x08,
+ Sock_CLOSE = 0x10,
+ Sock_SEND = 0x20,
+ Sock_SEND_MAC = 0x21,
+ Sock_SEND_KEEP = 0x22,
+ Sock_RECV = 0x40
+};
+
+/*class SnCmd {
+public:
+ static const uint8_t OPEN = 0x01;
+ static const uint8_t LISTEN = 0x02;
+ static const uint8_t CONNECT = 0x04;
+ static const uint8_t DISCON = 0x08;
+ static const uint8_t CLOSE = 0x10;
+ static const uint8_t SEND = 0x20;
+ static const uint8_t SEND_MAC = 0x21;
+ static const uint8_t SEND_KEEP = 0x22;
+ static const uint8_t RECV = 0x40;
+};
+*/
+
+class SnIR {
+public:
+ static const uint8_t SEND_OK = 0x10;
+ static const uint8_t TIMEOUT = 0x08;
+ static const uint8_t RECV = 0x04;
+ static const uint8_t DISCON = 0x02;
+ static const uint8_t CON = 0x01;
+};
+
+class SnSR {
+public:
+ static const uint8_t CLOSED = 0x00;
+ static const uint8_t INIT = 0x13;
+ static const uint8_t LISTEN = 0x14;
+ static const uint8_t SYNSENT = 0x15;
+ static const uint8_t SYNRECV = 0x16;
+ static const uint8_t ESTABLISHED = 0x17;
+ static const uint8_t FIN_WAIT = 0x18;
+ static const uint8_t CLOSING = 0x1A;
+ static const uint8_t TIME_WAIT = 0x1B;
+ static const uint8_t CLOSE_WAIT = 0x1C;
+ static const uint8_t LAST_ACK = 0x1D;
+ static const uint8_t UDP = 0x22;
+ static const uint8_t IPRAW = 0x32;
+ static const uint8_t MACRAW = 0x42;
+ static const uint8_t PPPOE = 0x5F;
+};
+
+class IPPROTO {
+public:
+ static const uint8_t IP = 0;
+ static const uint8_t ICMP = 1;
+ static const uint8_t IGMP = 2;
+ static const uint8_t GGP = 3;
+ static const uint8_t TCP = 6;
+ static const uint8_t PUP = 12;
+ static const uint8_t UDP = 17;
+ static const uint8_t IDP = 22;
+ static const uint8_t ND = 77;
+ static const uint8_t RAW = 255;
+};
+
+class W5100Class {
+
+public:
+ void init();
+
+ /**
+ * @brief This function is being used for copy the data form Receive buffer of the chip to application buffer.
+ *
+ * It calculate the actual physical address where one has to read
+ * the data from Receive buffer. Here also take care of the condition while it exceed
+ * the Rx memory uper-bound of socket.
+ */
+ void read_data(SOCKET s, volatile uint8_t * src, volatile uint8_t * dst, uint16_t len);
+
+ /**
+ * @brief This function is being called by send() and sendto() function also.
+ *
+ * This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer
+ * register. User should read upper byte first and lower byte later to get proper value.
+ */
+ void send_data_processing(SOCKET s, const uint8_t *data, uint16_t len);
+ /**
+ * @brief A copy of send_data_processing that uses the provided ptr for the
+ * write offset. Only needed for the "streaming" UDP API, where
+ * a single UDP packet is built up over a number of calls to
+ * send_data_processing_ptr, because TX_WR doesn't seem to get updated
+ * correctly in those scenarios
+ * @param ptr value to use in place of TX_WR. If 0, then the value is read
+ * in from TX_WR
+ * @return New value for ptr, to be used in the next call
+ */
+// FIXME Update documentation
+ void send_data_processing_offset(SOCKET s, uint16_t data_offset, const uint8_t *data, uint16_t len);
+
+ /**
+ * @brief This function is being called by recv() also.
+ *
+ * This function read the Rx read pointer register
+ * and after copy the data from receive buffer update the Rx write pointer register.
+ * User should read upper byte first and lower byte later to get proper value.
+ */
+ void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek = 0);
+
+ inline void setGatewayIp(uint8_t *_addr);
+ inline void getGatewayIp(uint8_t *_addr);
+
+ inline void setSubnetMask(uint8_t *_addr);
+ inline void getSubnetMask(uint8_t *_addr);
+
+ inline void setMACAddress(uint8_t * addr);
+ inline void getMACAddress(uint8_t * addr);
+
+ inline void setIPAddress(uint8_t * addr);
+ inline void getIPAddress(uint8_t * addr);
+
+ inline void setRetransmissionTime(uint16_t timeout);
+ inline void setRetransmissionCount(uint8_t _retry);
+
+ void execCmdSn(SOCKET s, SockCMD _cmd);
+
+ uint16_t getTXFreeSize(SOCKET s);
+ uint16_t getRXReceivedSize(SOCKET s);
+
+
+ // W5100 Registers
+ // ---------------
+private:
+ static uint8_t write(uint16_t _addr, uint8_t _data);
+ static uint16_t write(uint16_t addr, const uint8_t *buf, uint16_t len);
+ static uint8_t read(uint16_t addr);
+ static uint16_t read(uint16_t addr, uint8_t *buf, uint16_t len);
+
+#define __GP_REGISTER8(name, address) \
+ static inline void write##name(uint8_t _data) { \
+ write(address, _data); \
+ } \
+ static inline uint8_t read##name() { \
+ return read(address); \
+ }
+#define __GP_REGISTER16(name, address) \
+ static void write##name(uint16_t _data) { \
+ write(address, _data >> 8); \
+ write(address+1, _data & 0xFF); \
+ } \
+ static uint16_t read##name() { \
+ uint16_t res = read(address); \
+ res = (res << 8) + read(address + 1); \
+ return res; \
+ }
+#define __GP_REGISTER_N(name, address, size) \
+ static uint16_t write##name(uint8_t *_buff) { \
+ return write(address, _buff, size); \
+ } \
+ static uint16_t read##name(uint8_t *_buff) { \
+ return read(address, _buff, size); \
+ }
+
+public:
+ __GP_REGISTER8 (MR, 0x0000); // Mode
+ __GP_REGISTER_N(GAR, 0x0001, 4); // Gateway IP address
+ __GP_REGISTER_N(SUBR, 0x0005, 4); // Subnet mask address
+ __GP_REGISTER_N(SHAR, 0x0009, 6); // Source MAC address
+ __GP_REGISTER_N(SIPR, 0x000F, 4); // Source IP address
+ __GP_REGISTER8 (IR, 0x0015); // Interrupt
+ __GP_REGISTER8 (IMR, 0x0016); // Interrupt Mask
+ __GP_REGISTER16(RTR, 0x0017); // Timeout address
+ __GP_REGISTER8 (RCR, 0x0019); // Retry count
+ __GP_REGISTER8 (RMSR, 0x001A); // Receive memory size
+ __GP_REGISTER8 (TMSR, 0x001B); // Transmit memory size
+ __GP_REGISTER8 (PATR, 0x001C); // Authentication type address in PPPoE mode
+ __GP_REGISTER8 (PTIMER, 0x0028); // PPP LCP Request Timer
+ __GP_REGISTER8 (PMAGIC, 0x0029); // PPP LCP Magic Number
+ __GP_REGISTER_N(UIPR, 0x002A, 4); // Unreachable IP address in UDP mode
+ __GP_REGISTER16(UPORT, 0x002E); // Unreachable Port address in UDP mode
+
+#undef __GP_REGISTER8
+#undef __GP_REGISTER16
+#undef __GP_REGISTER_N
+
+ // W5100 Socket registers
+ // ----------------------
+private:
+ static inline uint8_t readSn(SOCKET _s, uint16_t _addr);
+ static inline uint8_t writeSn(SOCKET _s, uint16_t _addr, uint8_t _data);
+ static inline uint16_t readSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t len);
+ static inline uint16_t writeSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t len);
+
+ static const uint16_t CH_BASE = 0x0400;
+ static const uint16_t CH_SIZE = 0x0100;
+
+#define __SOCKET_REGISTER8(name, address) \
+ static inline void write##name(SOCKET _s, uint8_t _data) { \
+ writeSn(_s, address, _data); \
+ } \
+ static inline uint8_t read##name(SOCKET _s) { \
+ return readSn(_s, address); \
+ }
+#define __SOCKET_REGISTER16(name, address) \
+ static void write##name(SOCKET _s, uint16_t _data) { \
+ writeSn(_s, address, _data >> 8); \
+ writeSn(_s, address+1, _data & 0xFF); \
+ } \
+ static uint16_t read##name(SOCKET _s) { \
+ uint16_t res = readSn(_s, address); \
+ uint16_t res2 = readSn(_s,address + 1); \
+ res = res << 8; \
+ res2 = res2 & 0xFF; \
+ res = res | res2; \
+ return res; \
+ }
+#define __SOCKET_REGISTER_N(name, address, size) \
+ static uint16_t write##name(SOCKET _s, uint8_t *_buff) { \
+ return writeSn(_s, address, _buff, size); \
+ } \
+ static uint16_t read##name(SOCKET _s, uint8_t *_buff) { \
+ return readSn(_s, address, _buff, size); \
+ }
+
+public:
+ __SOCKET_REGISTER8(SnMR, 0x0000) // Mode
+ __SOCKET_REGISTER8(SnCR, 0x0001) // Command
+ __SOCKET_REGISTER8(SnIR, 0x0002) // Interrupt
+ __SOCKET_REGISTER8(SnSR, 0x0003) // Status
+ __SOCKET_REGISTER16(SnPORT, 0x0004) // Source Port
+ __SOCKET_REGISTER_N(SnDHAR, 0x0006, 6) // Destination Hardw Addr
+ __SOCKET_REGISTER_N(SnDIPR, 0x000C, 4) // Destination IP Addr
+ __SOCKET_REGISTER16(SnDPORT, 0x0010) // Destination Port
+ __SOCKET_REGISTER16(SnMSSR, 0x0012) // Max Segment Size
+ __SOCKET_REGISTER8(SnPROTO, 0x0014) // Protocol in IP RAW Mode
+ __SOCKET_REGISTER8(SnTOS, 0x0015) // IP TOS
+ __SOCKET_REGISTER8(SnTTL, 0x0016) // IP TTL
+ __SOCKET_REGISTER16(SnTX_FSR, 0x0020) // TX Free Size
+ __SOCKET_REGISTER16(SnTX_RD, 0x0022) // TX Read Pointer
+ __SOCKET_REGISTER16(SnTX_WR, 0x0024) // TX Write Pointer
+ __SOCKET_REGISTER16(SnRX_RSR, 0x0026) // RX Free Size
+ __SOCKET_REGISTER16(SnRX_RD, 0x0028) // RX Read Pointer
+ __SOCKET_REGISTER16(SnRX_WR, 0x002A) // RX Write Pointer (supported?)
+
+#undef __SOCKET_REGISTER8
+#undef __SOCKET_REGISTER16
+#undef __SOCKET_REGISTER_N
+
+
+private:
+ static const uint8_t RST = 7; // Reset BIT
+
+ static const int SOCKETS = 4;
+ static const uint16_t SMASK = 0x07FF; // Tx buffer MASK
+ static const uint16_t RMASK = 0x07FF; // Rx buffer MASK
+public:
+ static const uint16_t SSIZE = 2048; // Max Tx buffer size
+private:
+ static const uint16_t RSIZE = 2048; // Max Rx buffer size
+ uint16_t SBASE[SOCKETS]; // Tx buffer base address
+ uint16_t RBASE[SOCKETS]; // Rx buffer base address
+
+private:
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
+ inline static void initSS() { DDRB |= _BV(4); };
+ inline static void setSS() { PORTB &= ~_BV(4); };
+ inline static void resetSS() { PORTB |= _BV(4); };
+#elif defined(__AVR_ATmega32U4__)
+ inline static void initSS() { DDRB |= _BV(6); };
+ inline static void setSS() { PORTB &= ~_BV(6); };
+ inline static void resetSS() { PORTB |= _BV(6); };
+#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
+ inline static void initSS() { DDRB |= _BV(0); };
+ inline static void setSS() { PORTB &= ~_BV(0); };
+ inline static void resetSS() { PORTB |= _BV(0); };
+#else
+ inline static void initSS() { DDRB |= _BV(2); };
+ inline static void setSS() { PORTB &= ~_BV(2); };
+ inline static void resetSS() { PORTB |= _BV(2); };
+#endif
+
+};
+
+extern W5100Class W5100;
+
+uint8_t W5100Class::readSn(SOCKET _s, uint16_t _addr) {
+ return read(CH_BASE + _s * CH_SIZE + _addr);
+}
+
+uint8_t W5100Class::writeSn(SOCKET _s, uint16_t _addr, uint8_t _data) {
+ return write(CH_BASE + _s * CH_SIZE + _addr, _data);
+}
+
+uint16_t W5100Class::readSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t _len) {
+ return read(CH_BASE + _s * CH_SIZE + _addr, _buf, _len);
+}
+
+uint16_t W5100Class::writeSn(SOCKET _s, uint16_t _addr, uint8_t *_buf, uint16_t _len) {
+ return write(CH_BASE + _s * CH_SIZE + _addr, _buf, _len);
+}
+
+void W5100Class::getGatewayIp(uint8_t *_addr) {
+ readGAR(_addr);
+}
+
+void W5100Class::setGatewayIp(uint8_t *_addr) {
+ writeGAR(_addr);
+}
+
+void W5100Class::getSubnetMask(uint8_t *_addr) {
+ readSUBR(_addr);
+}
+
+void W5100Class::setSubnetMask(uint8_t *_addr) {
+ writeSUBR(_addr);
+}
+
+void W5100Class::getMACAddress(uint8_t *_addr) {
+ readSHAR(_addr);
+}
+
+void W5100Class::setMACAddress(uint8_t *_addr) {
+ writeSHAR(_addr);
+}
+
+void W5100Class::getIPAddress(uint8_t *_addr) {
+ readSIPR(_addr);
+}
+
+void W5100Class::setIPAddress(uint8_t *_addr) {
+ writeSIPR(_addr);
+}
+
+void W5100Class::setRetransmissionTime(uint16_t _timeout) {
+ writeRTR(_timeout);
+}
+
+void W5100Class::setRetransmissionCount(uint8_t _retry) {
+ writeRCR(_retry);
+}
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/Boards.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/Boards.h
new file mode 100644
index 00000000..06f69c62
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/Boards.h
@@ -0,0 +1,366 @@
+/* Boards.h - Hardware Abstraction Layer for Firmata library */
+
+#ifndef Firmata_Boards_h
+#define Firmata_Boards_h
+
+#include
+
+#if defined(ARDUINO) && ARDUINO >= 100
+#include "Arduino.h" // for digitalRead, digitalWrite, etc
+#else
+#include "WProgram.h"
+#endif
+
+// Normally Servo.h must be included before Firmata.h (which then includes
+// this file). If Servo.h wasn't included, this allows the code to still
+// compile, but without support for any Servos. Hopefully that's what the
+// user intended by not including Servo.h
+#ifndef MAX_SERVOS
+#define MAX_SERVOS 0
+#endif
+
+/*
+ Firmata Hardware Abstraction Layer
+
+Firmata is built on top of the hardware abstraction functions of Arduino,
+specifically digitalWrite, digitalRead, analogWrite, analogRead, and
+pinMode. While these functions offer simple integer pin numbers, Firmata
+needs more information than is provided by Arduino. This file provides
+all other hardware specific details. To make Firmata support a new board,
+only this file should require editing.
+
+The key concept is every "pin" implemented by Firmata may be mapped to
+any pin as implemented by Arduino. Usually a simple 1-to-1 mapping is
+best, but such mapping should not be assumed. This hardware abstraction
+layer allows Firmata to implement any number of pins which map onto the
+Arduino implemented pins in almost any arbitrary way.
+
+
+General Constants:
+
+These constants provide basic information Firmata requires.
+
+TOTAL_PINS: The total number of pins Firmata implemented by Firmata.
+ Usually this will match the number of pins the Arduino functions
+ implement, including any pins pins capable of analog or digital.
+ However, Firmata may implement any number of pins. For example,
+ on Arduino Mini with 8 analog inputs, 6 of these may be used
+ for digital functions, and 2 are analog only. On such boards,
+ Firmata can implement more pins than Arduino's pinMode()
+ function, in order to accommodate those special pins. The
+ Firmata protocol supports a maximum of 128 pins, so this
+ constant must not exceed 128.
+
+TOTAL_ANALOG_PINS: The total number of analog input pins implemented.
+ The Firmata protocol allows up to 16 analog inputs, accessed
+ using offsets 0 to 15. Because Firmata presents the analog
+ inputs using different offsets than the actual pin numbers
+ (a legacy of Arduino's analogRead function, and the way the
+ analog input capable pins are physically labeled on all
+ Arduino boards), the total number of analog input signals
+ must be specified. 16 is the maximum.
+
+VERSION_BLINK_PIN: When Firmata starts up, it will blink the version
+ number. This constant is the Arduino pin number where a
+ LED is connected.
+
+
+Pin Mapping Macros:
+
+These macros provide the mapping between pins as implemented by
+Firmata protocol and the actual pin numbers used by the Arduino
+functions. Even though such mappings are often simple, pin
+numbers received by Firmata protocol should always be used as
+input to these macros, and the result of the macro should be
+used with with any Arduino function.
+
+When Firmata is extended to support a new pin mode or feature,
+a pair of macros should be added and used for all hardware
+access. For simple 1:1 mapping, these macros add no actual
+overhead, yet their consistent use allows source code which
+uses them consistently to be easily adapted to all other boards
+with different requirements.
+
+IS_PIN_XXXX(pin): The IS_PIN macros resolve to true or non-zero
+ if a pin as implemented by Firmata corresponds to a pin
+ that actually implements the named feature.
+
+PIN_TO_XXXX(pin): The PIN_TO macros translate pin numbers as
+ implemented by Firmata to the pin numbers needed as inputs
+ to the Arduino functions. The corresponding IS_PIN macro
+ should always be tested before using a PIN_TO macro, so
+ these macros only need to handle valid Firmata pin
+ numbers for the named feature.
+
+
+Port Access Inline Funtions:
+
+For efficiency, Firmata protocol provides access to digital
+input and output pins grouped by 8 bit ports. When these
+groups of 8 correspond to actual 8 bit ports as implemented
+by the hardware, these inline functions can provide high
+speed direct port access. Otherwise, a default implementation
+using 8 calls to digitalWrite or digitalRead is used.
+
+When porting Firmata to a new board, it is recommended to
+use the default functions first and focus only on the constants
+and macros above. When those are working, if optimized port
+access is desired, these inline functions may be extended.
+The recommended approach defines a symbol indicating which
+optimization to use, and then conditional complication is
+used within these functions.
+
+readPort(port, bitmask): Read an 8 bit port, returning the value.
+ port: The port number, Firmata pins port*8 to port*8+7
+ bitmask: The actual pins to read, indicated by 1 bits.
+
+writePort(port, value, bitmask): Write an 8 bit port.
+ port: The port number, Firmata pins port*8 to port*8+7
+ value: The 8 bit value to write
+ bitmask: The actual pins to write, indicated by 1 bits.
+*/
+
+/*==============================================================================
+ * Board Specific Configuration
+ *============================================================================*/
+
+#ifndef digitalPinHasPWM
+#define digitalPinHasPWM(p) IS_PIN_DIGITAL(p)
+#endif
+
+// Arduino Duemilanove, Diecimila, and NG
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
+#if defined(NUM_ANALOG_INPUTS) && NUM_ANALOG_INPUTS == 6
+#define TOTAL_ANALOG_PINS 6
+#define TOTAL_PINS 20 // 14 digital + 6 analog
+#else
+#define TOTAL_ANALOG_PINS 8
+#define TOTAL_PINS 22 // 14 digital + 8 analog
+#endif
+#define VERSION_BLINK_PIN 13
+#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 19)
+#define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - 14)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) ((p) - 2)
+#define ARDUINO_PINOUT_OPTIMIZE 1
+
+
+// Wiring (and board)
+#elif defined(WIRING)
+#define VERSION_BLINK_PIN WLED
+#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) ((p) >= FIRST_ANALOG_PIN && (p) < (FIRST_ANALOG_PIN+TOTAL_ANALOG_PINS))
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - FIRST_ANALOG_PIN)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) (p)
+
+
+// old Arduinos
+#elif defined(__AVR_ATmega8__)
+#define TOTAL_ANALOG_PINS 6
+#define TOTAL_PINS 20 // 14 digital + 6 analog
+#define VERSION_BLINK_PIN 13
+#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 19)
+#define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 19)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - 14)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) ((p) - 2)
+#define ARDUINO_PINOUT_OPTIMIZE 1
+
+
+// Arduino Mega
+#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
+#define TOTAL_ANALOG_PINS 16
+#define TOTAL_PINS 70 // 54 digital + 16 analog
+#define VERSION_BLINK_PIN 13
+#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) ((p) >= 54 && (p) < TOTAL_PINS)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 20 || (p) == 21)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - 54)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) ((p) - 2)
+
+
+// Teensy 1.0
+#elif defined(__AVR_AT90USB162__)
+#define TOTAL_ANALOG_PINS 0
+#define TOTAL_PINS 21 // 21 digital + no analog
+#define VERSION_BLINK_PIN 6
+#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) (0)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
+#define IS_PIN_I2C(p) (0)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) (0)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) (p)
+
+
+// Teensy 2.0
+#elif defined(__AVR_ATmega32U4__)
+#define TOTAL_ANALOG_PINS 12
+#define TOTAL_PINS 25 // 11 digital + 12 analog
+#define VERSION_BLINK_PIN 11
+#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) ((p) >= 11 && (p) <= 22)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 5 || (p) == 6)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) (((p)<22)?21-(p):11)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) (p)
+
+
+// Teensy++ 1.0 and 2.0
+#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
+#define TOTAL_ANALOG_PINS 8
+#define TOTAL_PINS 46 // 38 digital + 8 analog
+#define VERSION_BLINK_PIN 6
+#define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) ((p) >= 38 && (p) < TOTAL_PINS)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 0 || (p) == 1)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - 38)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) (p)
+
+
+// Sanguino
+#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
+#define TOTAL_ANALOG_PINS 8
+#define TOTAL_PINS 32 // 24 digital + 8 analog
+#define VERSION_BLINK_PIN 0
+#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) ((p) >= 24 && (p) < TOTAL_PINS)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 16 || (p) == 17)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - 24)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) ((p) - 2)
+
+
+// Illuminato
+#elif defined(__AVR_ATmega645__)
+#define TOTAL_ANALOG_PINS 6
+#define TOTAL_PINS 42 // 36 digital + 6 analog
+#define VERSION_BLINK_PIN 13
+#define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
+#define IS_PIN_ANALOG(p) ((p) >= 36 && (p) < TOTAL_PINS)
+#define IS_PIN_PWM(p) digitalPinHasPWM(p)
+#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
+#define IS_PIN_I2C(p) ((p) == 4 || (p) == 5)
+#define PIN_TO_DIGITAL(p) (p)
+#define PIN_TO_ANALOG(p) ((p) - 36)
+#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
+#define PIN_TO_SERVO(p) ((p) - 2)
+
+
+// anything else
+#else
+#error "Please edit Boards.h with a hardware abstraction for this board"
+#endif
+
+
+/*==============================================================================
+ * readPort() - Read an 8 bit port
+ *============================================================================*/
+
+static inline unsigned char readPort(byte, byte) __attribute__((always_inline, unused));
+static inline unsigned char readPort(byte port, byte bitmask)
+{
+#if defined(ARDUINO_PINOUT_OPTIMIZE)
+ if (port == 0) return (PIND & 0xFC) & bitmask; // ignore Rx/Tx 0/1
+ if (port == 1) return ((PINB & 0x3F) | ((PINC & 0x03) << 6)) & bitmask;
+ if (port == 2) return ((PINC & 0x3C) >> 2) & bitmask;
+ return 0;
+#else
+ unsigned char out=0, pin=port*8;
+ if (IS_PIN_DIGITAL(pin+0) && (bitmask & 0x01) && digitalRead(PIN_TO_DIGITAL(pin+0))) out |= 0x01;
+ if (IS_PIN_DIGITAL(pin+1) && (bitmask & 0x02) && digitalRead(PIN_TO_DIGITAL(pin+1))) out |= 0x02;
+ if (IS_PIN_DIGITAL(pin+2) && (bitmask & 0x04) && digitalRead(PIN_TO_DIGITAL(pin+2))) out |= 0x04;
+ if (IS_PIN_DIGITAL(pin+3) && (bitmask & 0x08) && digitalRead(PIN_TO_DIGITAL(pin+3))) out |= 0x08;
+ if (IS_PIN_DIGITAL(pin+4) && (bitmask & 0x10) && digitalRead(PIN_TO_DIGITAL(pin+4))) out |= 0x10;
+ if (IS_PIN_DIGITAL(pin+5) && (bitmask & 0x20) && digitalRead(PIN_TO_DIGITAL(pin+5))) out |= 0x20;
+ if (IS_PIN_DIGITAL(pin+6) && (bitmask & 0x40) && digitalRead(PIN_TO_DIGITAL(pin+6))) out |= 0x40;
+ if (IS_PIN_DIGITAL(pin+7) && (bitmask & 0x80) && digitalRead(PIN_TO_DIGITAL(pin+7))) out |= 0x80;
+ return out;
+#endif
+}
+
+/*==============================================================================
+ * writePort() - Write an 8 bit port, only touch pins specified by a bitmask
+ *============================================================================*/
+
+static inline unsigned char writePort(byte, byte, byte) __attribute__((always_inline, unused));
+static inline unsigned char writePort(byte port, byte value, byte bitmask)
+{
+#if defined(ARDUINO_PINOUT_OPTIMIZE)
+ if (port == 0) {
+ bitmask = bitmask & 0xFC; // do not touch Tx & Rx pins
+ byte valD = value & bitmask;
+ byte maskD = ~bitmask;
+ cli();
+ PORTD = (PORTD & maskD) | valD;
+ sei();
+ } else if (port == 1) {
+ byte valB = (value & bitmask) & 0x3F;
+ byte valC = (value & bitmask) >> 6;
+ byte maskB = ~(bitmask & 0x3F);
+ byte maskC = ~((bitmask & 0xC0) >> 6);
+ cli();
+ PORTB = (PORTB & maskB) | valB;
+ PORTC = (PORTC & maskC) | valC;
+ sei();
+ } else if (port == 2) {
+ bitmask = bitmask & 0x0F;
+ byte valC = (value & bitmask) << 2;
+ byte maskC = ~(bitmask << 2);
+ cli();
+ PORTC = (PORTC & maskC) | valC;
+ sei();
+ }
+#else
+ byte pin=port*8;
+ if ((bitmask & 0x01)) digitalWrite(PIN_TO_DIGITAL(pin+0), (value & 0x01));
+ if ((bitmask & 0x02)) digitalWrite(PIN_TO_DIGITAL(pin+1), (value & 0x02));
+ if ((bitmask & 0x04)) digitalWrite(PIN_TO_DIGITAL(pin+2), (value & 0x04));
+ if ((bitmask & 0x08)) digitalWrite(PIN_TO_DIGITAL(pin+3), (value & 0x08));
+ if ((bitmask & 0x10)) digitalWrite(PIN_TO_DIGITAL(pin+4), (value & 0x10));
+ if ((bitmask & 0x20)) digitalWrite(PIN_TO_DIGITAL(pin+5), (value & 0x20));
+ if ((bitmask & 0x40)) digitalWrite(PIN_TO_DIGITAL(pin+6), (value & 0x40));
+ if ((bitmask & 0x80)) digitalWrite(PIN_TO_DIGITAL(pin+7), (value & 0x80));
+#endif
+}
+
+
+
+
+#ifndef TOTAL_PORTS
+#define TOTAL_PORTS ((TOTAL_PINS + 7) / 8)
+#endif
+
+
+#endif /* Firmata_Boards_h */
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/Firmata.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/Firmata.cpp
new file mode 100644
index 00000000..e81c10bb
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/Firmata.cpp
@@ -0,0 +1,444 @@
+/*
+ Firmata.cpp - Firmata library
+ Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See file LICENSE.txt for further informations on licensing terms.
+*/
+
+//******************************************************************************
+//* Includes
+//******************************************************************************
+
+#include "Firmata.h"
+#include "HardwareSerial.h"
+
+extern "C" {
+#include
+#include
+}
+
+//******************************************************************************
+//* Support Functions
+//******************************************************************************
+
+void FirmataClass::sendValueAsTwo7bitBytes(int value)
+{
+ FirmataSerial.write(value & B01111111); // LSB
+ FirmataSerial.write(value >> 7 & B01111111); // MSB
+}
+
+void FirmataClass::startSysex(void)
+{
+ FirmataSerial.write(START_SYSEX);
+}
+
+void FirmataClass::endSysex(void)
+{
+ FirmataSerial.write(END_SYSEX);
+}
+
+//******************************************************************************
+//* Constructors
+//******************************************************************************
+
+FirmataClass::FirmataClass(Stream &s) : FirmataSerial(s)
+{
+ firmwareVersionCount = 0;
+ systemReset();
+}
+
+//******************************************************************************
+//* Public Methods
+//******************************************************************************
+
+/* begin method for overriding default serial bitrate */
+void FirmataClass::begin(void)
+{
+ begin(57600);
+}
+
+/* begin method for overriding default serial bitrate */
+void FirmataClass::begin(long speed)
+{
+ Serial.begin(speed);
+ FirmataSerial = Serial;
+ blinkVersion();
+ printVersion();
+ printFirmwareVersion();
+}
+
+void FirmataClass::begin(Stream &s)
+{
+ FirmataSerial = s;
+ systemReset();
+ printVersion();
+ printFirmwareVersion();
+}
+
+// output the protocol version message to the serial port
+void FirmataClass::printVersion(void) {
+ FirmataSerial.write(REPORT_VERSION);
+ FirmataSerial.write(FIRMATA_MAJOR_VERSION);
+ FirmataSerial.write(FIRMATA_MINOR_VERSION);
+}
+
+void FirmataClass::blinkVersion(void)
+{
+ // flash the pin with the protocol version
+ pinMode(VERSION_BLINK_PIN,OUTPUT);
+ pin13strobe(FIRMATA_MAJOR_VERSION, 40, 210);
+ delay(250);
+ pin13strobe(FIRMATA_MINOR_VERSION, 40, 210);
+ delay(125);
+}
+
+void FirmataClass::printFirmwareVersion(void)
+{
+ byte i;
+
+ if(firmwareVersionCount) { // make sure that the name has been set before reporting
+ startSysex();
+ FirmataSerial.write(REPORT_FIRMWARE);
+ FirmataSerial.write(firmwareVersionVector[0]); // major version number
+ FirmataSerial.write(firmwareVersionVector[1]); // minor version number
+ for(i=2; i 0) && (inputData < 128) ) {
+ waitForData--;
+ storedInputData[waitForData] = inputData;
+ if( (waitForData==0) && executeMultiByteCommand ) { // got the whole message
+ switch(executeMultiByteCommand) {
+ case ANALOG_MESSAGE:
+ if(currentAnalogCallback) {
+ (*currentAnalogCallback)(multiByteChannel,
+ (storedInputData[0] << 7)
+ + storedInputData[1]);
+ }
+ break;
+ case DIGITAL_MESSAGE:
+ if(currentDigitalCallback) {
+ (*currentDigitalCallback)(multiByteChannel,
+ (storedInputData[0] << 7)
+ + storedInputData[1]);
+ }
+ break;
+ case SET_PIN_MODE:
+ if(currentPinModeCallback)
+ (*currentPinModeCallback)(storedInputData[1], storedInputData[0]);
+ break;
+ case REPORT_ANALOG:
+ if(currentReportAnalogCallback)
+ (*currentReportAnalogCallback)(multiByteChannel,storedInputData[0]);
+ break;
+ case REPORT_DIGITAL:
+ if(currentReportDigitalCallback)
+ (*currentReportDigitalCallback)(multiByteChannel,storedInputData[0]);
+ break;
+ }
+ executeMultiByteCommand = 0;
+ }
+ } else {
+ // remove channel info from command byte if less than 0xF0
+ if(inputData < 0xF0) {
+ command = inputData & 0xF0;
+ multiByteChannel = inputData & 0x0F;
+ } else {
+ command = inputData;
+ // commands in the 0xF* range don't use channel data
+ }
+ switch (command) {
+ case ANALOG_MESSAGE:
+ case DIGITAL_MESSAGE:
+ case SET_PIN_MODE:
+ waitForData = 2; // two data bytes needed
+ executeMultiByteCommand = command;
+ break;
+ case REPORT_ANALOG:
+ case REPORT_DIGITAL:
+ waitForData = 1; // two data bytes needed
+ executeMultiByteCommand = command;
+ break;
+ case START_SYSEX:
+ parsingSysex = true;
+ sysexBytesRead = 0;
+ break;
+ case SYSTEM_RESET:
+ systemReset();
+ break;
+ case REPORT_VERSION:
+ Firmata.printVersion();
+ break;
+ }
+ }
+}
+
+//------------------------------------------------------------------------------
+// Serial Send Handling
+
+// send an analog message
+void FirmataClass::sendAnalog(byte pin, int value)
+{
+ // pin can only be 0-15, so chop higher bits
+ FirmataSerial.write(ANALOG_MESSAGE | (pin & 0xF));
+ sendValueAsTwo7bitBytes(value);
+}
+
+// send a single digital pin in a digital message
+void FirmataClass::sendDigital(byte pin, int value)
+{
+ /* TODO add single pin digital messages to the protocol, this needs to
+ * track the last digital data sent so that it can be sure to change just
+ * one bit in the packet. This is complicated by the fact that the
+ * numbering of the pins will probably differ on Arduino, Wiring, and
+ * other boards. The DIGITAL_MESSAGE sends 14 bits at a time, but it is
+ * probably easier to send 8 bit ports for any board with more than 14
+ * digital pins.
+ */
+
+ // TODO: the digital message should not be sent on the serial port every
+ // time sendDigital() is called. Instead, it should add it to an int
+ // which will be sent on a schedule. If a pin changes more than once
+ // before the digital message is sent on the serial port, it should send a
+ // digital message for each change.
+
+ // if(value == 0)
+ // sendDigitalPortPair();
+}
+
+
+// send 14-bits in a single digital message (protocol v1)
+// send an 8-bit port in a single digital message (protocol v2)
+void FirmataClass::sendDigitalPort(byte portNumber, int portData)
+{
+ FirmataSerial.write(DIGITAL_MESSAGE | (portNumber & 0xF));
+ FirmataSerial.write((byte)portData % 128); // Tx bits 0-6
+ FirmataSerial.write(portData >> 7); // Tx bits 7-13
+}
+
+
+void FirmataClass::sendSysex(byte command, byte bytec, byte* bytev)
+{
+ byte i;
+ startSysex();
+ FirmataSerial.write(command);
+ for(i=0; i
+
+byte pin;
+
+int analogValue;
+int previousAnalogValues[TOTAL_ANALOG_PINS];
+
+byte portStatus[TOTAL_PORTS]; // each bit: 1=pin is digital input, 0=other/ignore
+byte previousPINs[TOTAL_PORTS];
+
+/* timer variables */
+unsigned long currentMillis; // store the current value from millis()
+unsigned long previousMillis; // for comparison with currentMillis
+/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
+ get long, random delays. So only read analogs every 20ms or so */
+int samplingInterval = 19; // how often to run the main loop (in ms)
+
+void sendPort(byte portNumber, byte portValue)
+{
+ portValue = portValue & portStatus[portNumber];
+ if(previousPINs[portNumber] != portValue) {
+ Firmata.sendDigitalPort(portNumber, portValue);
+ previousPINs[portNumber] = portValue;
+ }
+}
+
+void setup()
+{
+ byte i, port, status;
+
+ Firmata.setFirmwareVersion(0, 1);
+
+ for(pin = 0; pin < TOTAL_PINS; pin++) {
+ if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
+ }
+
+ for (port=0; port samplingInterval) {
+ previousMillis += samplingInterval;
+ while(Firmata.available()) {
+ Firmata.processInput();
+ }
+ for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
+ analogValue = analogRead(pin);
+ if(analogValue != previousAnalogValues[pin]) {
+ Firmata.sendAnalog(pin, analogValue);
+ previousAnalogValues[pin] = analogValue;
+ }
+ }
+ }
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/AnalogFirmata/AnalogFirmata.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/AnalogFirmata/AnalogFirmata.ino
new file mode 100644
index 00000000..ff1d664b
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/AnalogFirmata/AnalogFirmata.ino
@@ -0,0 +1,94 @@
+/*
+ * Firmata is a generic protocol for communicating with microcontrollers
+ * from software on a host computer. It is intended to work with
+ * any host computer software package.
+ *
+ * To download a host software package, please clink on the following link
+ * to open the download page in your default browser.
+ *
+ * http://firmata.org/wiki/Download
+ */
+
+/* This firmware supports as many analog ports as possible, all analog inputs,
+ * four PWM outputs, and two with servo support.
+ *
+ * This example code is in the public domain.
+ */
+#include
+#include
+
+/*==============================================================================
+ * GLOBAL VARIABLES
+ *============================================================================*/
+
+/* servos */
+Servo servo9, servo10; // one instance per pin
+/* analog inputs */
+int analogInputsToReport = 0; // bitwise array to store pin reporting
+int analogPin = 0; // counter for reading analog pins
+/* timer variables */
+unsigned long currentMillis; // store the current value from millis()
+unsigned long previousMillis; // for comparison with currentMillis
+
+
+/*==============================================================================
+ * FUNCTIONS
+ *============================================================================*/
+
+void analogWriteCallback(byte pin, int value)
+{
+ switch(pin) {
+ case 9: servo9.write(value); break;
+ case 10: servo10.write(value); break;
+ case 3:
+ case 5:
+ case 6:
+ case 11: // PWM pins
+ analogWrite(pin, value);
+ break;
+ }
+}
+// -----------------------------------------------------------------------------
+// sets bits in a bit array (int) to toggle the reporting of the analogIns
+void reportAnalogCallback(byte pin, int value)
+{
+ if(value == 0) {
+ analogInputsToReport = analogInputsToReport &~ (1 << pin);
+ }
+ else { // everything but 0 enables reporting of that pin
+ analogInputsToReport = analogInputsToReport | (1 << pin);
+ }
+ // TODO: save status to EEPROM here, if changed
+}
+
+/*==============================================================================
+ * SETUP()
+ *============================================================================*/
+void setup()
+{
+ Firmata.setFirmwareVersion(0, 2);
+ Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
+ Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
+
+ servo9.attach(9);
+ servo10.attach(10);
+ Firmata.begin(57600);
+}
+
+/*==============================================================================
+ * LOOP()
+ *============================================================================*/
+void loop()
+{
+ while(Firmata.available())
+ Firmata.processInput();
+ currentMillis = millis();
+ if(currentMillis - previousMillis > 20) {
+ previousMillis += 20; // run this every 20ms
+ for(analogPin=0;analogPin
+
+byte analogPin;
+
+void stringCallback(char *myString)
+{
+ Firmata.sendString(myString);
+}
+
+
+void sysexCallback(byte command, byte argc, byte*argv)
+{
+ Firmata.sendSysex(command, argc, argv);
+}
+
+void setup()
+{
+ Firmata.setFirmwareVersion(0, 1);
+ Firmata.attach(STRING_DATA, stringCallback);
+ Firmata.attach(START_SYSEX, sysexCallback);
+ Firmata.begin(57600);
+}
+
+void loop()
+{
+ while(Firmata.available()) {
+ Firmata.processInput();
+ }
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/I2CFirmata/I2CFirmata.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/I2CFirmata/I2CFirmata.ino
new file mode 100644
index 00000000..1da8963a
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/I2CFirmata/I2CFirmata.ino
@@ -0,0 +1,228 @@
+/*
+ * Firmata is a generic protocol for communicating with microcontrollers
+ * from software on a host computer. It is intended to work with
+ * any host computer software package.
+ *
+ * To download a host software package, please clink on the following link
+ * to open the download page in your default browser.
+ *
+ * http://firmata.org/wiki/Download
+ */
+
+/*
+ Copyright (C) 2009 Jeff Hoefs. All rights reserved.
+ Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See file LICENSE.txt for further informations on licensing terms.
+ */
+
+#include
+#include
+
+
+#define I2C_WRITE B00000000
+#define I2C_READ B00001000
+#define I2C_READ_CONTINUOUSLY B00010000
+#define I2C_STOP_READING B00011000
+#define I2C_READ_WRITE_MODE_MASK B00011000
+
+#define MAX_QUERIES 8
+
+unsigned long currentMillis; // store the current value from millis()
+unsigned long previousMillis; // for comparison with currentMillis
+unsigned int samplingInterval = 32; // default sampling interval is 33ms
+unsigned int i2cReadDelayTime = 0; // default delay time between i2c read request and Wire.requestFrom()
+unsigned int powerPinsEnabled = 0; // use as boolean to prevent enablePowerPins from being called more than once
+
+#define MINIMUM_SAMPLING_INTERVAL 10
+
+#define REGISTER_NOT_SPECIFIED -1
+
+struct i2c_device_info {
+ byte addr;
+ byte reg;
+ byte bytes;
+};
+
+i2c_device_info query[MAX_QUERIES];
+
+byte i2cRxData[32];
+boolean readingContinuously = false;
+byte queryIndex = 0;
+
+void readAndReportData(byte address, int theRegister, byte numBytes)
+{
+ if (theRegister != REGISTER_NOT_SPECIFIED) {
+ Wire.beginTransmission(address);
+ Wire.write((byte)theRegister);
+ Wire.endTransmission();
+ delayMicroseconds(i2cReadDelayTime); // delay is necessary for some devices such as WiiNunchuck
+ }
+ else {
+ theRegister = 0; // fill the register with a dummy value
+ }
+
+ Wire.requestFrom(address, numBytes);
+
+ // check to be sure correct number of bytes were returned by slave
+ if(numBytes == Wire.available()) {
+ i2cRxData[0] = address;
+ i2cRxData[1] = theRegister;
+ for (int i = 0; i < numBytes; i++) {
+ i2cRxData[2 + i] = Wire.read();
+ }
+ // send slave address, register and received bytes
+ Firmata.sendSysex(I2C_REPLY, numBytes + 2, i2cRxData);
+ }
+ else {
+ if(numBytes > Wire.available()) {
+ Firmata.sendString("I2C Read Error: Too many bytes received");
+ } else {
+ Firmata.sendString("I2C Read Error: Too few bytes received");
+ }
+ }
+
+}
+
+void sysexCallback(byte command, byte argc, byte *argv)
+{
+ byte mode;
+ byte slaveAddress;
+ byte slaveRegister;
+ byte data;
+ int delayTime;
+
+ if (command == I2C_REQUEST) {
+ mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
+ slaveAddress = argv[0];
+
+ switch(mode) {
+ case I2C_WRITE:
+ Wire.beginTransmission(slaveAddress);
+ for (byte i = 2; i < argc; i += 2) {
+ data = argv[i] + (argv[i + 1] << 7);
+ Wire.write(data);
+ }
+ Wire.endTransmission();
+ delayMicroseconds(70); // TODO is this needed?
+ break;
+ case I2C_READ:
+ if (argc == 6) {
+ // a slave register is specified
+ slaveRegister = argv[2] + (argv[3] << 7);
+ data = argv[4] + (argv[5] << 7); // bytes to read
+ readAndReportData(slaveAddress, (int)slaveRegister, data);
+ }
+ else {
+ // a slave register is NOT specified
+ data = argv[2] + (argv[3] << 7); // bytes to read
+ readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
+ }
+ break;
+ case I2C_READ_CONTINUOUSLY:
+ if ((queryIndex + 1) >= MAX_QUERIES) {
+ // too many queries, just ignore
+ Firmata.sendString("too many queries");
+ break;
+ }
+ query[queryIndex].addr = slaveAddress;
+ query[queryIndex].reg = argv[2] + (argv[3] << 7);
+ query[queryIndex].bytes = argv[4] + (argv[5] << 7);
+ readingContinuously = true;
+ queryIndex++;
+ break;
+ case I2C_STOP_READING:
+ readingContinuously = false;
+ queryIndex = 0;
+ break;
+ default:
+ break;
+ }
+ }
+ else if (command == SAMPLING_INTERVAL) {
+ samplingInterval = argv[0] + (argv[1] << 7);
+
+ if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) {
+ samplingInterval = MINIMUM_SAMPLING_INTERVAL;
+ }
+
+ samplingInterval -= 1;
+ Firmata.sendString("sampling interval");
+ }
+
+ else if (command == I2C_CONFIG) {
+ delayTime = (argv[4] + (argv[5] << 7)); // MSB
+ delayTime = (delayTime << 8) + (argv[2] + (argv[3] << 7)); // add LSB
+
+ if((argv[0] + (argv[1] << 7)) > 0) {
+ enablePowerPins(PORTC3, PORTC2);
+ }
+
+ if(delayTime > 0) {
+ i2cReadDelayTime = delayTime;
+ }
+
+ if(argc > 6) {
+ // If you extend I2C_Config, handle your data here
+ }
+
+ }
+}
+
+void systemResetCallback()
+{
+ readingContinuously = false;
+ queryIndex = 0;
+}
+
+/* reference: BlinkM_funcs.h by Tod E. Kurt, ThingM, http://thingm.com/ */
+// Enables Pins A2 and A3 to be used as GND and Power
+// so that I2C devices can be plugged directly
+// into Arduino header (pins A2 - A5)
+static void enablePowerPins(byte pwrpin, byte gndpin)
+{
+ if(powerPinsEnabled == 0) {
+ DDRC |= _BV(pwrpin) | _BV(gndpin);
+ PORTC &=~ _BV(gndpin);
+ PORTC |= _BV(pwrpin);
+ powerPinsEnabled = 1;
+ Firmata.sendString("Power pins enabled");
+ delay(100);
+ }
+}
+
+void setup()
+{
+ Firmata.setFirmwareVersion(2, 0);
+
+ Firmata.attach(START_SYSEX, sysexCallback);
+ Firmata.attach(SYSTEM_RESET, systemResetCallback);
+
+ for (int i = 0; i < TOTAL_PINS; ++i) {
+ pinMode(i, OUTPUT);
+ }
+
+ Firmata.begin(57600);
+ Wire.begin();
+}
+
+void loop()
+{
+ while (Firmata.available()) {
+ Firmata.processInput();
+ }
+
+ currentMillis = millis();
+ if (currentMillis - previousMillis > samplingInterval) {
+ previousMillis += samplingInterval;
+
+ for (byte i = 0; i < queryIndex; i++) {
+ readAndReportData(query[i].addr, query[i].reg, query[i].bytes);
+ }
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/OldStandardFirmata/LICENSE.txt b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/OldStandardFirmata/LICENSE.txt
new file mode 100644
index 00000000..77cec6dd
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/OldStandardFirmata/LICENSE.txt
@@ -0,0 +1,458 @@
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/OldStandardFirmata/OldStandardFirmata.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/OldStandardFirmata/OldStandardFirmata.ino
new file mode 100644
index 00000000..d306c70d
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/OldStandardFirmata/OldStandardFirmata.ino
@@ -0,0 +1,239 @@
+/*
+ * Firmata is a generic protocol for communicating with microcontrollers
+ * from software on a host computer. It is intended to work with
+ * any host computer software package.
+ *
+ * To download a host software package, please clink on the following link
+ * to open the download page in your default browser.
+ *
+ * http://firmata.org/wiki/Download
+ */
+
+/*
+ Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See file LICENSE.txt for further informations on licensing terms.
+ */
+
+/*
+ * This is an old version of StandardFirmata (v2.0). It is kept here because
+ * its the last version that works on an ATMEGA8 chip. Also, it can be used
+ * for host software that has not been updated to a newer version of the
+ * protocol. It also uses the old baud rate of 115200 rather than 57600.
+ */
+
+#include
+#include
+
+/*==============================================================================
+ * GLOBAL VARIABLES
+ *============================================================================*/
+
+/* analog inputs */
+int analogInputsToReport = 0; // bitwise array to store pin reporting
+int analogPin = 0; // counter for reading analog pins
+
+/* digital pins */
+byte reportPINs[TOTAL_PORTS]; // PIN == input port
+byte previousPINs[TOTAL_PORTS]; // PIN == input port
+byte pinStatus[TOTAL_PINS]; // store pin status, default OUTPUT
+byte portStatus[TOTAL_PORTS];
+
+/* timer variables */
+unsigned long currentMillis; // store the current value from millis()
+unsigned long previousMillis; // for comparison with currentMillis
+
+
+/*==============================================================================
+ * FUNCTIONS
+ *============================================================================*/
+
+void outputPort(byte portNumber, byte portValue)
+{
+ portValue = portValue &~ portStatus[portNumber];
+ if(previousPINs[portNumber] != portValue) {
+ Firmata.sendDigitalPort(portNumber, portValue);
+ previousPINs[portNumber] = portValue;
+ Firmata.sendDigitalPort(portNumber, portValue);
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * check all the active digital inputs for change of state, then add any events
+ * to the Serial output queue using Serial.print() */
+void checkDigitalInputs(void)
+{
+ byte i, tmp;
+ for(i=0; i < TOTAL_PORTS; i++) {
+ if(reportPINs[i]) {
+ switch(i) {
+ case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1
+ case 1: outputPort(1, PINB); break;
+ case 2: outputPort(2, PINC); break;
+ }
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+/* sets the pin mode to the correct state and sets the relevant bits in the
+ * two bit-arrays that track Digital I/O and PWM status
+ */
+void setPinModeCallback(byte pin, int mode) {
+ byte port = 0;
+ byte offset = 0;
+
+ if (pin < 8) {
+ port = 0;
+ offset = 0;
+ } else if (pin < 14) {
+ port = 1;
+ offset = 8;
+ } else if (pin < 22) {
+ port = 2;
+ offset = 14;
+ }
+
+ if(pin > 1) { // ignore RxTx (pins 0 and 1)
+ pinStatus[pin] = mode;
+ switch(mode) {
+ case INPUT:
+ pinMode(pin, INPUT);
+ portStatus[port] = portStatus[port] &~ (1 << (pin - offset));
+ break;
+ case OUTPUT:
+ digitalWrite(pin, LOW); // disable PWM
+ case PWM:
+ pinMode(pin, OUTPUT);
+ portStatus[port] = portStatus[port] | (1 << (pin - offset));
+ break;
+ //case ANALOG: // TODO figure this out
+ default:
+ Firmata.sendString("");
+ }
+ // TODO: save status to EEPROM here, if changed
+ }
+}
+
+void analogWriteCallback(byte pin, int value)
+{
+ setPinModeCallback(pin,PWM);
+ analogWrite(pin, value);
+}
+
+void digitalWriteCallback(byte port, int value)
+{
+ switch(port) {
+ case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1)
+ // 0xFF03 == B1111111100000011 0x03 == B00000011
+ PORTD = (value &~ 0xFF03) | (PORTD & 0x03);
+ break;
+ case 1: // pins 8-13 (14,15 are disabled for the crystal)
+ PORTB = (byte)value;
+ break;
+ case 2: // analog pins used as digital
+ PORTC = (byte)value;
+ break;
+ }
+}
+
+// -----------------------------------------------------------------------------
+/* sets bits in a bit array (int) to toggle the reporting of the analogIns
+ */
+//void FirmataClass::setAnalogPinReporting(byte pin, byte state) {
+//}
+void reportAnalogCallback(byte pin, int value)
+{
+ if(value == 0) {
+ analogInputsToReport = analogInputsToReport &~ (1 << pin);
+ }
+ else { // everything but 0 enables reporting of that pin
+ analogInputsToReport = analogInputsToReport | (1 << pin);
+ }
+ // TODO: save status to EEPROM here, if changed
+}
+
+void reportDigitalCallback(byte port, int value)
+{
+ reportPINs[port] = (byte)value;
+ if(port == 2) // turn off analog reporting when used as digital
+ analogInputsToReport = 0;
+}
+
+/*==============================================================================
+ * SETUP()
+ *============================================================================*/
+void setup()
+{
+ byte i;
+
+ Firmata.setFirmwareVersion(2, 0);
+
+ Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
+ Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
+ Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
+ Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
+ Firmata.attach(SET_PIN_MODE, setPinModeCallback);
+
+ portStatus[0] = B00000011; // ignore Tx/RX pins
+ portStatus[1] = B11000000; // ignore 14/15 pins
+ portStatus[2] = B00000000;
+
+// for(i=0; i 20) {
+ previousMillis += 20; // run this every 20ms
+ /* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
+ * all serialReads at once, i.e. empty the buffer */
+ while(Firmata.available())
+ Firmata.processInput();
+ /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
+ * 60 bytes. use a timer to sending an event character every 4 ms to
+ * trigger the buffer to dump. */
+
+ /* ANALOGREAD - right after the event character, do all of the
+ * analogReads(). These only need to be done every 4ms. */
+ for(analogPin=0;analogPin
+#include
+
+Servo servos[MAX_SERVOS];
+
+void analogWriteCallback(byte pin, int value)
+{
+ if (IS_PIN_SERVO(pin)) {
+ servos[PIN_TO_SERVO(pin)].write(value);
+ }
+}
+
+void setup()
+{
+ byte pin;
+
+ Firmata.setFirmwareVersion(0, 2);
+ Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
+
+ for (pin=0; pin < TOTAL_PINS; pin++) {
+ if (IS_PIN_SERVO(pin)) {
+ servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
+ }
+ }
+
+ Firmata.begin(57600);
+}
+
+void loop()
+{
+ while(Firmata.available())
+ Firmata.processInput();
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino
new file mode 100644
index 00000000..44ea91ee
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino
@@ -0,0 +1,46 @@
+/*
+ * Firmata is a generic protocol for communicating with microcontrollers
+ * from software on a host computer. It is intended to work with
+ * any host computer software package.
+ *
+ * To download a host software package, please clink on the following link
+ * to open the download page in your default browser.
+ *
+ * http://firmata.org/wiki/Download
+ */
+
+/* Supports as many analog inputs and analog PWM outputs as possible.
+ *
+ * This example code is in the public domain.
+ */
+#include
+
+byte analogPin = 0;
+
+void analogWriteCallback(byte pin, int value)
+{
+ if (IS_PIN_PWM(pin)) {
+ pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
+ analogWrite(PIN_TO_PWM(pin), value);
+ }
+}
+
+void setup()
+{
+ Firmata.setFirmwareVersion(0, 1);
+ Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
+ Firmata.begin(57600);
+}
+
+void loop()
+{
+ while(Firmata.available()) {
+ Firmata.processInput();
+ }
+ // do one analogRead per loop, so if PC is sending a lot of
+ // analog write messages, we will only delay 1 analogRead
+ Firmata.sendAnalog(analogPin, analogRead(analogPin));
+ analogPin = analogPin + 1;
+ if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino
new file mode 100644
index 00000000..a0d764f7
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino
@@ -0,0 +1,72 @@
+/*
+ * Firmata is a generic protocol for communicating with microcontrollers
+ * from software on a host computer. It is intended to work with
+ * any host computer software package.
+ *
+ * To download a host software package, please clink on the following link
+ * to open the download page in your default browser.
+ *
+ * http://firmata.org/wiki/Download
+ */
+
+/* Supports as many digital inputs and outputs as possible.
+ *
+ * This example code is in the public domain.
+ */
+#include
+
+byte previousPIN[TOTAL_PORTS]; // PIN means PORT for input
+byte previousPORT[TOTAL_PORTS];
+
+void outputPort(byte portNumber, byte portValue)
+{
+ // only send the data when it changes, otherwise you get too many messages!
+ if (previousPIN[portNumber] != portValue) {
+ Firmata.sendDigitalPort(portNumber, portValue);
+ previousPIN[portNumber] = portValue;
+ }
+}
+
+void setPinModeCallback(byte pin, int mode) {
+ if (IS_PIN_DIGITAL(pin)) {
+ pinMode(PIN_TO_DIGITAL(pin), mode);
+ }
+}
+
+void digitalWriteCallback(byte port, int value)
+{
+ byte i;
+ byte currentPinValue, previousPinValue;
+
+ if (port < TOTAL_PORTS && value != previousPORT[port]) {
+ for(i=0; i<8; i++) {
+ currentPinValue = (byte) value & (1 << i);
+ previousPinValue = previousPORT[port] & (1 << i);
+ if(currentPinValue != previousPinValue) {
+ digitalWrite(i + (port*8), currentPinValue);
+ }
+ }
+ previousPORT[port] = value;
+ }
+}
+
+void setup()
+{
+ Firmata.setFirmwareVersion(0, 1);
+ Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
+ Firmata.attach(SET_PIN_MODE, setPinModeCallback);
+ Firmata.begin(57600);
+}
+
+void loop()
+{
+ byte i;
+
+ for (i=0; i
+#include
+#include
+
+// move the following defines to Firmata.h?
+#define I2C_WRITE B00000000
+#define I2C_READ B00001000
+#define I2C_READ_CONTINUOUSLY B00010000
+#define I2C_STOP_READING B00011000
+#define I2C_READ_WRITE_MODE_MASK B00011000
+#define I2C_10BIT_ADDRESS_MODE_MASK B00100000
+
+#define MAX_QUERIES 8
+#define MINIMUM_SAMPLING_INTERVAL 10
+
+#define REGISTER_NOT_SPECIFIED -1
+
+/*==============================================================================
+ * GLOBAL VARIABLES
+ *============================================================================*/
+
+/* analog inputs */
+int analogInputsToReport = 0; // bitwise array to store pin reporting
+
+/* digital input ports */
+byte reportPINs[TOTAL_PORTS]; // 1 = report this port, 0 = silence
+byte previousPINs[TOTAL_PORTS]; // previous 8 bits sent
+
+/* pins configuration */
+byte pinConfig[TOTAL_PINS]; // configuration of every pin
+byte portConfigInputs[TOTAL_PORTS]; // each bit: 1 = pin in INPUT, 0 = anything else
+int pinState[TOTAL_PINS]; // any value that has been written
+
+/* timer variables */
+unsigned long currentMillis; // store the current value from millis()
+unsigned long previousMillis; // for comparison with currentMillis
+int samplingInterval = 19; // how often to run the main loop (in ms)
+
+/* i2c data */
+struct i2c_device_info {
+ byte addr;
+ byte reg;
+ byte bytes;
+};
+
+/* for i2c read continuous more */
+i2c_device_info query[MAX_QUERIES];
+
+byte i2cRxData[32];
+boolean isI2CEnabled = false;
+signed char queryIndex = -1;
+unsigned int i2cReadDelayTime = 0; // default delay time between i2c read request and Wire.requestFrom()
+
+Servo servos[MAX_SERVOS];
+/*==============================================================================
+ * FUNCTIONS
+ *============================================================================*/
+
+void readAndReportData(byte address, int theRegister, byte numBytes) {
+ // allow I2C requests that don't require a register read
+ // for example, some devices using an interrupt pin to signify new data available
+ // do not always require the register read so upon interrupt you call Wire.requestFrom()
+ if (theRegister != REGISTER_NOT_SPECIFIED) {
+ Wire.beginTransmission(address);
+ #if ARDUINO >= 100
+ Wire.write((byte)theRegister);
+ #else
+ Wire.send((byte)theRegister);
+ #endif
+ Wire.endTransmission();
+ delayMicroseconds(i2cReadDelayTime); // delay is necessary for some devices such as WiiNunchuck
+ } else {
+ theRegister = 0; // fill the register with a dummy value
+ }
+
+ Wire.requestFrom(address, numBytes); // all bytes are returned in requestFrom
+
+ // check to be sure correct number of bytes were returned by slave
+ if(numBytes == Wire.available()) {
+ i2cRxData[0] = address;
+ i2cRxData[1] = theRegister;
+ for (int i = 0; i < numBytes; i++) {
+ #if ARDUINO >= 100
+ i2cRxData[2 + i] = Wire.read();
+ #else
+ i2cRxData[2 + i] = Wire.receive();
+ #endif
+ }
+ }
+ else {
+ if(numBytes > Wire.available()) {
+ Firmata.sendString("I2C Read Error: Too many bytes received");
+ } else {
+ Firmata.sendString("I2C Read Error: Too few bytes received");
+ }
+ }
+
+ // send slave address, register and received bytes
+ Firmata.sendSysex(SYSEX_I2C_REPLY, numBytes + 2, i2cRxData);
+}
+
+void outputPort(byte portNumber, byte portValue, byte forceSend)
+{
+ // pins not configured as INPUT are cleared to zeros
+ portValue = portValue & portConfigInputs[portNumber];
+ // only send if the value is different than previously sent
+ if(forceSend || previousPINs[portNumber] != portValue) {
+ Firmata.sendDigitalPort(portNumber, portValue);
+ previousPINs[portNumber] = portValue;
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * check all the active digital inputs for change of state, then add any events
+ * to the Serial output queue using Serial.print() */
+void checkDigitalInputs(void)
+{
+ /* Using non-looping code allows constants to be given to readPort().
+ * The compiler will apply substantial optimizations if the inputs
+ * to readPort() are compile-time constants. */
+ if (TOTAL_PORTS > 0 && reportPINs[0]) outputPort(0, readPort(0, portConfigInputs[0]), false);
+ if (TOTAL_PORTS > 1 && reportPINs[1]) outputPort(1, readPort(1, portConfigInputs[1]), false);
+ if (TOTAL_PORTS > 2 && reportPINs[2]) outputPort(2, readPort(2, portConfigInputs[2]), false);
+ if (TOTAL_PORTS > 3 && reportPINs[3]) outputPort(3, readPort(3, portConfigInputs[3]), false);
+ if (TOTAL_PORTS > 4 && reportPINs[4]) outputPort(4, readPort(4, portConfigInputs[4]), false);
+ if (TOTAL_PORTS > 5 && reportPINs[5]) outputPort(5, readPort(5, portConfigInputs[5]), false);
+ if (TOTAL_PORTS > 6 && reportPINs[6]) outputPort(6, readPort(6, portConfigInputs[6]), false);
+ if (TOTAL_PORTS > 7 && reportPINs[7]) outputPort(7, readPort(7, portConfigInputs[7]), false);
+ if (TOTAL_PORTS > 8 && reportPINs[8]) outputPort(8, readPort(8, portConfigInputs[8]), false);
+ if (TOTAL_PORTS > 9 && reportPINs[9]) outputPort(9, readPort(9, portConfigInputs[9]), false);
+ if (TOTAL_PORTS > 10 && reportPINs[10]) outputPort(10, readPort(10, portConfigInputs[10]), false);
+ if (TOTAL_PORTS > 11 && reportPINs[11]) outputPort(11, readPort(11, portConfigInputs[11]), false);
+ if (TOTAL_PORTS > 12 && reportPINs[12]) outputPort(12, readPort(12, portConfigInputs[12]), false);
+ if (TOTAL_PORTS > 13 && reportPINs[13]) outputPort(13, readPort(13, portConfigInputs[13]), false);
+ if (TOTAL_PORTS > 14 && reportPINs[14]) outputPort(14, readPort(14, portConfigInputs[14]), false);
+ if (TOTAL_PORTS > 15 && reportPINs[15]) outputPort(15, readPort(15, portConfigInputs[15]), false);
+}
+
+// -----------------------------------------------------------------------------
+/* sets the pin mode to the correct state and sets the relevant bits in the
+ * two bit-arrays that track Digital I/O and PWM status
+ */
+void setPinModeCallback(byte pin, int mode)
+{
+ if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) {
+ // disable i2c so pins can be used for other functions
+ // the following if statements should reconfigure the pins properly
+ disableI2CPins();
+ }
+ if (IS_PIN_SERVO(pin) && mode != SERVO && servos[PIN_TO_SERVO(pin)].attached()) {
+ servos[PIN_TO_SERVO(pin)].detach();
+ }
+ if (IS_PIN_ANALOG(pin)) {
+ reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting
+ }
+ if (IS_PIN_DIGITAL(pin)) {
+ if (mode == INPUT) {
+ portConfigInputs[pin/8] |= (1 << (pin & 7));
+ } else {
+ portConfigInputs[pin/8] &= ~(1 << (pin & 7));
+ }
+ }
+ pinState[pin] = 0;
+ switch(mode) {
+ case ANALOG:
+ if (IS_PIN_ANALOG(pin)) {
+ if (IS_PIN_DIGITAL(pin)) {
+ pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
+ digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
+ }
+ pinConfig[pin] = ANALOG;
+ }
+ break;
+ case INPUT:
+ if (IS_PIN_DIGITAL(pin)) {
+ pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver
+ digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
+ pinConfig[pin] = INPUT;
+ }
+ break;
+ case OUTPUT:
+ if (IS_PIN_DIGITAL(pin)) {
+ digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable PWM
+ pinMode(PIN_TO_DIGITAL(pin), OUTPUT);
+ pinConfig[pin] = OUTPUT;
+ }
+ break;
+ case PWM:
+ if (IS_PIN_PWM(pin)) {
+ pinMode(PIN_TO_PWM(pin), OUTPUT);
+ analogWrite(PIN_TO_PWM(pin), 0);
+ pinConfig[pin] = PWM;
+ }
+ break;
+ case SERVO:
+ if (IS_PIN_SERVO(pin)) {
+ pinConfig[pin] = SERVO;
+ if (!servos[PIN_TO_SERVO(pin)].attached()) {
+ servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
+ }
+ }
+ break;
+ case I2C:
+ if (IS_PIN_I2C(pin)) {
+ // mark the pin as i2c
+ // the user must call I2C_CONFIG to enable I2C for a device
+ pinConfig[pin] = I2C;
+ }
+ break;
+ default:
+ Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM
+ }
+ // TODO: save status to EEPROM here, if changed
+}
+
+void analogWriteCallback(byte pin, int value)
+{
+ if (pin < TOTAL_PINS) {
+ switch(pinConfig[pin]) {
+ case SERVO:
+ if (IS_PIN_SERVO(pin))
+ servos[PIN_TO_SERVO(pin)].write(value);
+ pinState[pin] = value;
+ break;
+ case PWM:
+ if (IS_PIN_PWM(pin))
+ analogWrite(PIN_TO_PWM(pin), value);
+ pinState[pin] = value;
+ break;
+ }
+ }
+}
+
+void digitalWriteCallback(byte port, int value)
+{
+ byte pin, lastPin, mask=1, pinWriteMask=0;
+
+ if (port < TOTAL_PORTS) {
+ // create a mask of the pins on this port that are writable.
+ lastPin = port*8+8;
+ if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS;
+ for (pin=port*8; pin < lastPin; pin++) {
+ // do not disturb non-digital pins (eg, Rx & Tx)
+ if (IS_PIN_DIGITAL(pin)) {
+ // only write to OUTPUT and INPUT (enables pullup)
+ // do not touch pins in PWM, ANALOG, SERVO or other modes
+ if (pinConfig[pin] == OUTPUT || pinConfig[pin] == INPUT) {
+ pinWriteMask |= mask;
+ pinState[pin] = ((byte)value & mask) ? 1 : 0;
+ }
+ }
+ mask = mask << 1;
+ }
+ writePort(port, (byte)value, pinWriteMask);
+ }
+}
+
+
+// -----------------------------------------------------------------------------
+/* sets bits in a bit array (int) to toggle the reporting of the analogIns
+ */
+//void FirmataClass::setAnalogPinReporting(byte pin, byte state) {
+//}
+void reportAnalogCallback(byte analogPin, int value)
+{
+ if (analogPin < TOTAL_ANALOG_PINS) {
+ if(value == 0) {
+ analogInputsToReport = analogInputsToReport &~ (1 << analogPin);
+ } else {
+ analogInputsToReport = analogInputsToReport | (1 << analogPin);
+ }
+ }
+ // TODO: save status to EEPROM here, if changed
+}
+
+void reportDigitalCallback(byte port, int value)
+{
+ if (port < TOTAL_PORTS) {
+ reportPINs[port] = (byte)value;
+ }
+ // do not disable analog reporting on these 8 pins, to allow some
+ // pins used for digital, others analog. Instead, allow both types
+ // of reporting to be enabled, but check if the pin is configured
+ // as analog when sampling the analog inputs. Likewise, while
+ // scanning digital pins, portConfigInputs will mask off values from any
+ // pins configured as analog
+}
+
+/*==============================================================================
+ * SYSEX-BASED commands
+ *============================================================================*/
+
+void sysexCallback(byte command, byte argc, byte *argv)
+{
+ byte mode;
+ byte slaveAddress;
+ byte slaveRegister;
+ byte data;
+ unsigned int delayTime;
+
+ switch(command) {
+ case I2C_REQUEST:
+ mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
+ if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
+ Firmata.sendString("10-bit addressing mode is not yet supported");
+ return;
+ }
+ else {
+ slaveAddress = argv[0];
+ }
+
+ switch(mode) {
+ case I2C_WRITE:
+ Wire.beginTransmission(slaveAddress);
+ for (byte i = 2; i < argc; i += 2) {
+ data = argv[i] + (argv[i + 1] << 7);
+ #if ARDUINO >= 100
+ Wire.write(data);
+ #else
+ Wire.send(data);
+ #endif
+ }
+ Wire.endTransmission();
+ delayMicroseconds(70);
+ break;
+ case I2C_READ:
+ if (argc == 6) {
+ // a slave register is specified
+ slaveRegister = argv[2] + (argv[3] << 7);
+ data = argv[4] + (argv[5] << 7); // bytes to read
+ readAndReportData(slaveAddress, (int)slaveRegister, data);
+ }
+ else {
+ // a slave register is NOT specified
+ data = argv[2] + (argv[3] << 7); // bytes to read
+ readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
+ }
+ break;
+ case I2C_READ_CONTINUOUSLY:
+ if ((queryIndex + 1) >= MAX_QUERIES) {
+ // too many queries, just ignore
+ Firmata.sendString("too many queries");
+ break;
+ }
+ queryIndex++;
+ query[queryIndex].addr = slaveAddress;
+ query[queryIndex].reg = argv[2] + (argv[3] << 7);
+ query[queryIndex].bytes = argv[4] + (argv[5] << 7);
+ break;
+ case I2C_STOP_READING:
+ byte queryIndexToSkip;
+ // if read continuous mode is enabled for only 1 i2c device, disable
+ // read continuous reporting for that device
+ if (queryIndex <= 0) {
+ queryIndex = -1;
+ } else {
+ // if read continuous mode is enabled for multiple devices,
+ // determine which device to stop reading and remove it's data from
+ // the array, shifiting other array data to fill the space
+ for (byte i = 0; i < queryIndex + 1; i++) {
+ if (query[i].addr = slaveAddress) {
+ queryIndexToSkip = i;
+ break;
+ }
+ }
+
+ for (byte i = queryIndexToSkip; i 0) {
+ i2cReadDelayTime = delayTime;
+ }
+
+ if (!isI2CEnabled) {
+ enableI2CPins();
+ }
+
+ break;
+ case SERVO_CONFIG:
+ if(argc > 4) {
+ // these vars are here for clarity, they'll optimized away by the compiler
+ byte pin = argv[0];
+ int minPulse = argv[1] + (argv[2] << 7);
+ int maxPulse = argv[3] + (argv[4] << 7);
+
+ if (IS_PIN_SERVO(pin)) {
+ if (servos[PIN_TO_SERVO(pin)].attached())
+ servos[PIN_TO_SERVO(pin)].detach();
+ servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin), minPulse, maxPulse);
+ setPinModeCallback(pin, SERVO);
+ }
+ }
+ break;
+ case SAMPLING_INTERVAL:
+ if (argc > 1) {
+ samplingInterval = argv[0] + (argv[1] << 7);
+ if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) {
+ samplingInterval = MINIMUM_SAMPLING_INTERVAL;
+ }
+ } else {
+ //Firmata.sendString("Not enough data");
+ }
+ break;
+ case EXTENDED_ANALOG:
+ if (argc > 1) {
+ int val = argv[1];
+ if (argc > 2) val |= (argv[2] << 7);
+ if (argc > 3) val |= (argv[3] << 14);
+ analogWriteCallback(argv[0], val);
+ }
+ break;
+ case CAPABILITY_QUERY:
+ Serial.write(START_SYSEX);
+ Serial.write(CAPABILITY_RESPONSE);
+ for (byte pin=0; pin < TOTAL_PINS; pin++) {
+ if (IS_PIN_DIGITAL(pin)) {
+ Serial.write((byte)INPUT);
+ Serial.write(1);
+ Serial.write((byte)OUTPUT);
+ Serial.write(1);
+ }
+ if (IS_PIN_ANALOG(pin)) {
+ Serial.write(ANALOG);
+ Serial.write(10);
+ }
+ if (IS_PIN_PWM(pin)) {
+ Serial.write(PWM);
+ Serial.write(8);
+ }
+ if (IS_PIN_SERVO(pin)) {
+ Serial.write(SERVO);
+ Serial.write(14);
+ }
+ if (IS_PIN_I2C(pin)) {
+ Serial.write(I2C);
+ Serial.write(1); // to do: determine appropriate value
+ }
+ Serial.write(127);
+ }
+ Serial.write(END_SYSEX);
+ break;
+ case PIN_STATE_QUERY:
+ if (argc > 0) {
+ byte pin=argv[0];
+ Serial.write(START_SYSEX);
+ Serial.write(PIN_STATE_RESPONSE);
+ Serial.write(pin);
+ if (pin < TOTAL_PINS) {
+ Serial.write((byte)pinConfig[pin]);
+ Serial.write((byte)pinState[pin] & 0x7F);
+ if (pinState[pin] & 0xFF80) Serial.write((byte)(pinState[pin] >> 7) & 0x7F);
+ if (pinState[pin] & 0xC000) Serial.write((byte)(pinState[pin] >> 14) & 0x7F);
+ }
+ Serial.write(END_SYSEX);
+ }
+ break;
+ case ANALOG_MAPPING_QUERY:
+ Serial.write(START_SYSEX);
+ Serial.write(ANALOG_MAPPING_RESPONSE);
+ for (byte pin=0; pin < TOTAL_PINS; pin++) {
+ Serial.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127);
+ }
+ Serial.write(END_SYSEX);
+ break;
+ }
+}
+
+void enableI2CPins()
+{
+ byte i;
+ // is there a faster way to do this? would probaby require importing
+ // Arduino.h to get SCL and SDA pins
+ for (i=0; i < TOTAL_PINS; i++) {
+ if(IS_PIN_I2C(i)) {
+ // mark pins as i2c so they are ignore in non i2c data requests
+ setPinModeCallback(i, I2C);
+ }
+ }
+
+ isI2CEnabled = true;
+
+ // is there enough time before the first I2C request to call this here?
+ Wire.begin();
+}
+
+/* disable the i2c pins so they can be used for other functions */
+void disableI2CPins() {
+ isI2CEnabled = false;
+ // disable read continuous mode for all devices
+ queryIndex = -1;
+ // uncomment the following if or when the end() method is added to Wire library
+ // Wire.end();
+}
+
+/*==============================================================================
+ * SETUP()
+ *============================================================================*/
+
+void systemResetCallback()
+{
+ // initialize a defalt state
+ // TODO: option to load config from EEPROM instead of default
+ if (isI2CEnabled) {
+ disableI2CPins();
+ }
+ for (byte i=0; i < TOTAL_PORTS; i++) {
+ reportPINs[i] = false; // by default, reporting off
+ portConfigInputs[i] = 0; // until activated
+ previousPINs[i] = 0;
+ }
+ // pins with analog capability default to analog input
+ // otherwise, pins default to digital output
+ for (byte i=0; i < TOTAL_PINS; i++) {
+ if (IS_PIN_ANALOG(i)) {
+ // turns off pullup, configures everything
+ setPinModeCallback(i, ANALOG);
+ } else {
+ // sets the output to 0, configures portConfigInputs
+ setPinModeCallback(i, OUTPUT);
+ }
+ }
+ // by default, do not report any analog inputs
+ analogInputsToReport = 0;
+
+ /* send digital inputs to set the initial state on the host computer,
+ * since once in the loop(), this firmware will only send on change */
+ /*
+ TODO: this can never execute, since no pins default to digital input
+ but it will be needed when/if we support EEPROM stored config
+ for (byte i=0; i < TOTAL_PORTS; i++) {
+ outputPort(i, readPort(i, portConfigInputs[i]), true);
+ }
+ */
+}
+
+void setup()
+{
+ Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
+
+ Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
+ Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
+ Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
+ Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
+ Firmata.attach(SET_PIN_MODE, setPinModeCallback);
+ Firmata.attach(START_SYSEX, sysexCallback);
+ Firmata.attach(SYSTEM_RESET, systemResetCallback);
+
+ Firmata.begin(57600);
+ systemResetCallback(); // reset to default config
+}
+
+/*==============================================================================
+ * LOOP()
+ *============================================================================*/
+void loop()
+{
+ byte pin, analogPin;
+
+ /* DIGITALREAD - as fast as possible, check for changes and output them to the
+ * FTDI buffer using Serial.print() */
+ checkDigitalInputs();
+
+ /* SERIALREAD - processing incoming messagse as soon as possible, while still
+ * checking digital inputs. */
+ while(Firmata.available())
+ Firmata.processInput();
+
+ /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
+ * 60 bytes. use a timer to sending an event character every 4 ms to
+ * trigger the buffer to dump. */
+
+ currentMillis = millis();
+ if (currentMillis - previousMillis > samplingInterval) {
+ previousMillis += samplingInterval;
+ /* ANALOGREAD - do all analogReads() at the configured sampling interval */
+ for(pin=0; pin -1) {
+ for (byte i = 0; i < queryIndex + 1; i++) {
+ readAndReportData(query[i].addr, query[i].reg, query[i].bytes);
+ }
+ }
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/keywords.txt b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/keywords.txt
new file mode 100644
index 00000000..52e0a9c7
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/Firmata/default/keywords.txt
@@ -0,0 +1,62 @@
+#######################################
+# Syntax Coloring Map For Firmata
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+Firmata KEYWORD1
+callbackFunction KEYWORD1
+systemResetCallbackFunction KEYWORD1
+stringCallbackFunction KEYWORD1
+sysexCallbackFunction KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+begin KEYWORD2
+begin KEYWORD2
+printVersion KEYWORD2
+blinkVersion KEYWORD2
+printFirmwareVersion KEYWORD2
+setFirmwareVersion KEYWORD2
+setFirmwareNameAndVersion KEYWORD2
+available KEYWORD2
+processInput KEYWORD2
+sendAnalog KEYWORD2
+sendDigital KEYWORD2
+sendDigitalPortPair KEYWORD2
+sendDigitalPort KEYWORD2
+sendString KEYWORD2
+sendString KEYWORD2
+sendSysex KEYWORD2
+attach KEYWORD2
+detach KEYWORD2
+flush KEYWORD2
+
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+
+MAX_DATA_BYTES LITERAL1
+
+DIGITAL_MESSAGE LITERAL1
+ANALOG_MESSAGE LITERAL1
+REPORT_ANALOG LITERAL1
+REPORT_DIGITAL LITERAL1
+REPORT_VERSION LITERAL1
+SET_PIN_MODE LITERAL1
+SYSTEM_RESET LITERAL1
+
+START_SYSEX LITERAL1
+END_SYSEX LITERAL1
+
+PWM LITERAL1
+
+TOTAL_ANALOG_PINS LITERAL1
+TOTAL_DIGITAL_PINS LITERAL1
+TOTAL_PORTS LITERAL1
+ANALOG_PORT LITERAL1
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM.h
new file mode 100644
index 00000000..ec2bf6ae
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM.h
@@ -0,0 +1,68 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SIMPLIFIERFILE_
+#define _GSM3SIMPLIFIERFILE_
+
+// This file simplifies the use of the GSM3 library
+// First we include everything.
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define GSM GSM3ShieldV1AccessProvider
+#define GPRS GSM3ShieldV1DataNetworkProvider
+#define GSMClient GSM3MobileClientService
+#define GSMServer GSM3MobileServerService
+#define GSMVoiceCall GSM3VoiceCallService
+#define GSM_SMS GSM3SMSService
+
+#define GSMPIN GSM3ShieldV1PinManagement
+#define GSMModem GSM3ShieldV1ModemVerification
+#define GSMCell GSM3CellManagement
+#define GSMBand GSM3ShieldV1BandManagement
+#define GSMScanner GSM3ShieldV1ScanNetworks
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3CircularBuffer.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3CircularBuffer.cpp
new file mode 100644
index 00000000..ea6f7d86
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3CircularBuffer.cpp
@@ -0,0 +1,319 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include "GSM3CircularBuffer.h"
+#include
+
+GSM3CircularBuffer::GSM3CircularBuffer(GSM3CircularBufferManager* mgr)
+{
+ head=0;
+ tail=0;
+ cbm=mgr;
+}
+
+int GSM3CircularBuffer::write(char c)
+{
+ byte aux=(tail+1)& __BUFFERMASK__;
+ if(aux!=head)
+ {
+ theBuffer[tail]=c;
+ // Lets put an extra zero at the end, so we can
+ // read chains as we like.
+ // This is not exactly perfect, we are always 1+ behind the head
+ theBuffer[aux]=0;
+ tail=aux;
+ return 1;
+ }
+ return 0;
+}
+
+char GSM3CircularBuffer::read()
+{
+ char res;
+ if(head!=tail)
+ {
+ res=theBuffer[head];
+ head=(head+1)& __BUFFERMASK__;
+ //if(cbm)
+ // cbm->spaceAvailable();
+ return res;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+char GSM3CircularBuffer::peek(int increment)
+{
+ char res;
+ byte num_aux;
+
+ if (tail>head) num_aux = tail-head;
+ else num_aux = 128 - head + tail;
+
+ if(increment < num_aux)
+ {
+ res=theBuffer[head];
+ return res;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+void GSM3CircularBufferManager::spaceAvailable(){return;};
+
+void GSM3CircularBuffer::flush()
+{
+ head=tail;
+}
+
+char* GSM3CircularBuffer::nextString()
+{
+ while(head!=tail)
+ {
+ head=(head+1) & __BUFFERMASK__;
+ if(theBuffer[head]==0)
+ {
+ head=(head+1) & __BUFFERMASK__;
+ return (char*)theBuffer+head;
+ }
+ }
+ return 0;
+}
+
+
+bool GSM3CircularBuffer::locate(const char* reference)
+{
+
+ return locate(reference, head, tail, 0, 0);
+}
+
+bool GSM3CircularBuffer::chopUntil(const char* reference, bool movetotheend, bool usehead)
+{
+ byte from, to;
+
+ if(locate(reference, head, tail, &from, &to))
+ {
+ if(usehead)
+ {
+ if(movetotheend)
+ head=(to+1) & __BUFFERMASK__;
+ else
+ head=from;
+ }
+ else
+ {
+ if(movetotheend)
+ tail=(to+1) & __BUFFERMASK__;
+ else
+ tail=from;
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool GSM3CircularBuffer::locate(const char* reference, byte thishead, byte thistail, byte* from, byte* to)
+{
+ int refcursor=0;
+ bool into=false;
+ byte b2, binit;
+ bool possible=1;
+
+ if(reference[0]==0)
+ return true;
+
+ for(byte b1=thishead; b1!=thistail;b1=(b1+1)& __BUFFERMASK__)
+ {
+ possible = 1;
+ b2 = b1;
+ while (possible&&(b2!=thistail))
+ {
+ if(theBuffer[b2]==reference[refcursor])
+ {
+ if(!into)
+ binit=b2;
+ into=true;
+ refcursor++;
+ if(reference[refcursor]==0)
+ {
+ if(from)
+ *from=binit;
+ if(to)
+ *to=b2;
+ return true;
+ }
+ }
+ else if (into==true)
+ {
+ possible = 0;
+ into=false;
+ refcursor=0;
+ }
+ b2=(b2+1)& __BUFFERMASK__;
+ }
+ }
+ return false;
+}
+
+bool GSM3CircularBuffer::extractSubstring(const char* from, const char* to, char* buffer, int bufsize)
+{
+ byte t1;
+ byte h2;
+ byte b;
+ int i;
+
+//DEBUG
+//Serial.println("Beginning extractSubstring");
+//Serial.print("head,tail=");Serial.print(int(head));Serial.print(",");Serial.println(int(tail));
+
+ if(!locate(from, head, tail, 0, &t1))
+ return false;
+
+//DEBUG
+//Serial.println("Located chain from.");
+
+ t1++; //To point the next.
+ if(!locate(to, t1, tail, &h2, 0))
+ return false;
+
+//DEBUG
+//Serial.println("Located chain to.");
+/*Serial.print("t1=");Serial.println(int(t1));
+Serial.print("h2=");Serial.println(int(h2));*/
+
+
+ for(i=0,b=t1;i='0')&&(c<='9'))
+ {
+ anyfound=true;
+ res=(res*10)+(int)c-48;
+ }
+ else
+ {
+ if(negative)
+ res=(-1)*res;
+ return res;
+ }
+ }
+ if(negative)
+ res=(-1)*res;
+ return res;
+}
+
+void GSM3CircularBuffer::debugBuffer()
+{
+ byte h1=head;
+ byte t1=tail;
+ Serial.println();
+ Serial.print(h1);
+ Serial.print(" ");
+ Serial.print(t1);
+ Serial.print('>');
+ for(byte b=h1; b!=t1; b=(b+1)& __BUFFERMASK__)
+ printCharDebug(theBuffer[b]);
+ Serial.println();
+}
+
+void GSM3CircularBuffer::printCharDebug(uint8_t c)
+{
+ if((c>31)&&(c<127))
+ Serial.print((char)c);
+ else
+ {
+ Serial.print('%');
+ Serial.print(c);
+ Serial.print('%');
+ }
+}
+
+bool GSM3CircularBuffer::retrieveBuffer(char* buffer, int bufsize, int& SizeWritten)
+{
+ byte b;
+ int i;
+
+ /*for(i=0,b=head;i
+#include
+
+#ifndef byte
+#define byte uint8_t
+#endif
+
+// These values have to be interrelated
+// To-Do: may we have just one? (BUFFERMASK)
+#define __BUFFERSIZE__ 128
+#define __BUFFERMASK__ 0x7F
+
+class GSM3CircularBufferManager
+{
+ public:
+
+ /** If there is spaceAvailable in the buffer, lets send a XON
+ */
+ virtual void spaceAvailable();
+};
+
+class GSM3CircularBuffer
+{
+ private:
+ // Buffer pointers.
+ // head=tail means buffer empty
+ // tail=head-1 means buffer full
+ // tail=head+1 means just one char (pointed by head)
+ // REMEMBER. head can be moved only by the main program
+ // REMEMBER. tail can be moved only by the other thread (interrupts)
+ // REMEMBER. head and tail can move only FORWARD
+ volatile byte head; // First written one
+ volatile byte tail; // Last written one.
+
+ GSM3CircularBufferManager* cbm; // Circular buffer manager
+
+ // The buffer
+ volatile byte theBuffer[__BUFFERSIZE__];
+
+ /** Checks if a substring exists in the buffer
+ @param reference Substring
+ @param thishead Head
+ @param thistail Tail
+ @param from Initial byte position
+ @param to Final byte position
+ @return true if exists, in otherwise return false
+ */
+ bool locate(const char* reference, byte thishead, byte thistail, byte* from=0, byte* to=0);
+
+ public:
+
+ /** Constructor
+ @param mgr Circular buffer manager
+ */
+ GSM3CircularBuffer(GSM3CircularBufferManager* mgr=0);
+
+ // TO-DO.Check if this formule runs too at the buffer limit
+
+ /** Get available bytes in circular buffer
+ @return available bytes
+ */
+ inline byte availableBytes(){ return ((head-(tail+1))&__BUFFERMASK__);};
+
+ /** Stored bytes in circular buffer
+ @return stored bytes
+ */
+ inline byte storedBytes(){ return ((tail-head)&__BUFFERMASK__);};
+
+ /** Write a character in circular buffer
+ @param c Character
+ @return 1 if successful
+ */
+ int write(char c);
+
+ /** Returns a character and moves the pointer
+ @return character
+ */
+ char read();
+
+ /** Returns a character but does not move the pointer.
+ @param increment Increment
+ @return character
+ */
+ char peek(int increment);
+
+ /** Returns a pointer to the head of the buffer
+ @return buffer with pointer in head
+ */
+ inline char* firstString(){return (char*)theBuffer+head;};
+
+ /** Go forward one string
+ @return buffer with one string advance
+ */
+ char* nextString();
+
+ /** Flush circular buffer
+ */
+ void flush();
+
+ /** Get tail
+ @return tail
+ */
+ inline byte getTail(){return tail;};
+
+ /** Get head
+ @return head
+ */
+ inline byte getHead(){return head;};
+
+ // Only can be executed from the interrupt!
+ /** Delete circular buffer to the end
+ @param from Initial byte position
+ */
+ inline void deleteToTheEnd(byte from){tail=from;};
+
+ /** Checks if a substring exists in the buffer
+ move=0, dont move, =1,put head at the beginning of the string, =2, put head at the end
+ @param reference
+ @return true if exists, in otherwise return false
+ */
+ bool locate(const char* reference);
+
+ /** Locates reference. If found, moves head (or tail) to the beginning (or end)
+ @param reference
+ @param movetotheend
+ @param head
+ @return true if successful
+ */
+ bool chopUntil(const char* reference, bool movetotheend, bool head=true);
+
+ /** Reads an integer from the head. Stops with first non blank, non number character
+ @return integer from the head
+ */
+ int readInt();
+
+ // Caveat: copies the first bytes until buffer is full
+
+ /** Extract a substring from circular buffer
+ @param from Initial byte position
+ @param to Final byte position
+ @param buffer Buffer for copy substring
+ @param bufsize Buffer size
+ @return true if successful, false if substring does not exists
+ */
+ bool extractSubstring(const char* from, const char* to, char* buffer, int bufsize);
+
+ /** Retrieve all the contents of buffer from head to tail
+ @param buffer
+ @param bufsize
+ @param SizeWritten
+ @return true if successful
+ */
+ bool retrieveBuffer(char* buffer, int bufsize, int& SizeWritten);
+
+ /** Debug function to print the buffer after receiving data from the modem.
+ */
+ void debugBuffer();
+
+ /** Utility: dump character if printable, else, put in %x%
+ @param c Character
+ */
+ static void printCharDebug(uint8_t c);
+
+
+};
+
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileAccessProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileAccessProvider.cpp
new file mode 100644
index 00000000..02d10808
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileAccessProvider.cpp
@@ -0,0 +1,3 @@
+#include
+
+GSM3MobileAccessProvider* theGSM3MobileAccessProvider;
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileAccessProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileAccessProvider.h
new file mode 100644
index 00000000..21ecd1b0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileAccessProvider.h
@@ -0,0 +1,68 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILEACCESSPROVIDER_
+#define _GSM3MOBILEACCESSPROVIDER_
+
+enum GSM3_NetworkStatus_t { ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED};
+
+class GSM3MobileAccessProvider
+{
+ public:
+ // Access functions
+ //Configuration functions.
+ /** Establish GSM connection
+ @param pin PIN code
+ @param restart Determines if hardware restart
+ @param synchronous Determines sync mode
+ @return If synchronous, GSM3_NetworkStatus_t. If asynchronous, returns 0.
+ */
+ virtual inline GSM3_NetworkStatus_t begin(char* pin=0,bool restart=true, bool synchronous=true)=0;
+
+ /** Check network access status
+ @return 1 if Alive, 0 if down
+ */
+ virtual inline int isAccessAlive()=0;
+
+ /** Shutdown the modem (power off really)
+ @return true if successful
+ */
+ virtual inline bool shutdown()=0;
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileCellManagement.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileCellManagement.cpp
new file mode 100644
index 00000000..1db20b94
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileCellManagement.cpp
@@ -0,0 +1 @@
+#include
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileCellManagement.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileCellManagement.h
new file mode 100644
index 00000000..035dfee9
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileCellManagement.h
@@ -0,0 +1,53 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILECELLMANAGEMENT_
+#define _GSM3MOBILECELLMANAGEMENT_
+
+#include
+
+class GSM3MobileCellManagement
+{
+ public:
+
+ virtual inline int getLocation() {return 0;};
+
+ virtual inline int getICCID() {return 0;};
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientProvider.cpp
new file mode 100644
index 00000000..3636a75d
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientProvider.cpp
@@ -0,0 +1,3 @@
+#include
+
+GSM3MobileClientProvider* theGSM3MobileClientProvider;
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientProvider.h
new file mode 100644
index 00000000..a771ff46
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientProvider.h
@@ -0,0 +1,156 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_MOBILECLIENTPROVIDER__
+#define __GSM3_MOBILECLIENTPROVIDER__
+
+#include
+#include
+
+class GSM3MobileClientProvider
+{
+ protected:
+
+ uint8_t sockets;
+
+ public:
+
+ /** Constructor */
+ GSM3MobileClientProvider(){};
+
+ /** Minimum socket
+ @return socket
+ */
+ virtual inline int minSocket()=0;
+
+ /** Maximum socket
+ @return socket
+ */
+ virtual inline int maxSocket()=0;
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+
+ /** Get status socket client
+ @param socket Socket
+ @return 1 if connected
+ */
+ virtual bool getStatusSocketClient(uint8_t socket)=0;
+
+ // Socket management
+
+ /** Get socket
+ @param socket Socket
+ @return socket
+ */
+ virtual int getSocket(int socket=-1)=0;
+
+ /** Release socket
+ @param socket Socket
+ */
+ virtual void releaseSocket(int socket)=0;
+
+ // Client socket functions
+
+ /** Connect to a server via TCP connection
+ @param server Server name or IP address in a String
+ @param port Port
+ @param id_socket Socket
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ virtual int connectTCPClient(const char* server, int port, int id_socket)=0;
+
+ /** Connect to a server (by IP address) via TCP connection
+ @param add IP address in IPAddress format
+ @param port Port
+ @param id_socket Socket
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ virtual int connectTCPClient(IPAddress add, int port, int id_socket)=0;
+
+ /** Begin writing through a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ virtual void beginWriteSocket(bool client1Server0, int id_socket)=0;
+
+ /** Write through a socket. MUST go after beginWriteSocket()
+ @param c character to be written
+ */
+ virtual void writeSocket(uint8_t c)=0;
+
+ /** Write through a socket. MUST go after beginWriteSocket()
+ @param buf characters to be written (final 0 will not be written)
+ */
+ virtual void writeSocket(const char* buf)=0;
+
+ /** Finish current writing
+ */
+ virtual void endWriteSocket()=0;
+
+ /** Check if there are data to be read in socket.
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
+ */
+ virtual int availableSocket(bool client, int id_socket)=0;
+
+ /** Read data (get a character) available in socket
+ @return character
+ */
+ virtual int readSocket()=0;
+
+ /** Flush socket
+ */
+ virtual void flushSocket()=0;
+
+ /** Get a character but will not advance the buffer head
+ @return character
+ */
+ virtual int peekSocket()=0;
+
+ /** Close a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Socket
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ virtual int disconnectTCP(bool client1Server0, int idsocket)=0;
+
+};
+
+extern GSM3MobileClientProvider* theGSM3MobileClientProvider;
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientService.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientService.cpp
new file mode 100644
index 00000000..15874a13
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientService.cpp
@@ -0,0 +1,260 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+#include
+
+// While there is only a shield (ShieldV1) we will include it by default
+#include
+GSM3ShieldV1ClientProvider theShieldV1ClientProvider;
+
+
+#define GSM3MOBILECLIENTSERVICE_CLIENT 0x01 // 1: This side is Client. 0: This side is Server
+#define GSM3MOBILECLIENTSERVICE_WRITING 0x02 // 1: TRUE 0: FALSE
+#define GSM3MOBILECLIENTSERVICE_SYNCH 0x04 // 1: TRUE, compatible with other clients 0: FALSE
+
+#define __TOUTBEGINWRITE__ 10000
+
+
+GSM3MobileClientService::GSM3MobileClientService(bool synch)
+{
+ flags = GSM3MOBILECLIENTSERVICE_CLIENT;
+ if(synch)
+ flags |= GSM3MOBILECLIENTSERVICE_SYNCH;
+ mySocket=255;
+}
+
+GSM3MobileClientService::GSM3MobileClientService(int socket, bool synch)
+{
+ // We are creating a socket on an existing, occupied one.
+ flags=0;
+ if(synch)
+ flags |= GSM3MOBILECLIENTSERVICE_SYNCH;
+ mySocket=socket;
+ theGSM3MobileClientProvider->getSocket(socket);
+
+}
+
+// Returns 0 if last command is still executing
+// 1 if success
+// >1 if error
+int GSM3MobileClientService::ready()
+{
+ return theGSM3MobileClientProvider->ready();
+}
+
+int GSM3MobileClientService::connect(IPAddress add, uint16_t port)
+{
+ if(theGSM3MobileClientProvider==0)
+ return 2;
+
+ // TODO: ask for the socket id
+ mySocket=theGSM3MobileClientProvider->getSocket();
+
+ if(mySocket<0)
+ return 2;
+
+ int res=theGSM3MobileClientProvider->connectTCPClient(add, port, mySocket);
+ if(flags & GSM3MOBILECLIENTSERVICE_SYNCH)
+ res=waitForAnswer();
+
+ return res;
+};
+
+int GSM3MobileClientService::connect(const char *host, uint16_t port)
+{
+
+ if(theGSM3MobileClientProvider==0)
+ return 2;
+ // TODO: ask for the socket id
+ mySocket=theGSM3MobileClientProvider->getSocket();
+
+ if(mySocket<0)
+ return 2;
+
+ int res=theGSM3MobileClientProvider->connectTCPClient(host, port, mySocket);
+ if(flags & GSM3MOBILECLIENTSERVICE_SYNCH)
+ res=waitForAnswer();
+
+ return res;
+}
+
+int GSM3MobileClientService::waitForAnswer()
+{
+ unsigned long m;
+ m=millis();
+ int res;
+
+ while(((millis()-m)< __TOUTBEGINWRITE__ )&&(ready()==0))
+ delay(100);
+
+ res=ready();
+
+ // If we get something different from a 1, we are having a problem
+ if(res!=1)
+ res=0;
+
+ return res;
+}
+
+void GSM3MobileClientService::beginWrite(bool sync)
+{
+ flags |= GSM3MOBILECLIENTSERVICE_WRITING;
+ theGSM3MobileClientProvider->beginWriteSocket(flags & GSM3MOBILECLIENTSERVICE_CLIENT, mySocket);
+ if(sync)
+ waitForAnswer();
+}
+
+size_t GSM3MobileClientService::write(uint8_t c)
+{
+ if(!(flags & GSM3MOBILECLIENTSERVICE_WRITING))
+ beginWrite(true);
+ theGSM3MobileClientProvider->writeSocket(c);
+ return 1;
+}
+
+size_t GSM3MobileClientService::write(const uint8_t* buf)
+{
+ if(!(flags & GSM3MOBILECLIENTSERVICE_WRITING))
+ beginWrite(true);
+ theGSM3MobileClientProvider->writeSocket((const char*)(buf));
+ return strlen((const char*)buf);
+}
+
+size_t GSM3MobileClientService::write(const uint8_t* buf, size_t sz)
+{
+ if(!(flags & GSM3MOBILECLIENTSERVICE_WRITING))
+ beginWrite(true);
+ for(int i=0;iwriteSocket(buf[i]);
+ return sz;
+}
+
+void GSM3MobileClientService::endWrite(bool sync)
+{
+ flags ^= GSM3MOBILECLIENTSERVICE_WRITING;
+ theGSM3MobileClientProvider->endWriteSocket();
+ if(sync)
+ waitForAnswer();
+}
+
+uint8_t GSM3MobileClientService::connected()
+{
+ if(mySocket==255)
+ return 0;
+ return theGSM3MobileClientProvider->getStatusSocketClient(mySocket);
+}
+
+GSM3MobileClientService::operator bool()
+{
+ return connected()==1;
+};
+
+int GSM3MobileClientService::available()
+{
+ int res;
+
+ // Even if not connected, we are looking for available data
+
+ if(flags & GSM3MOBILECLIENTSERVICE_WRITING)
+ endWrite(true);
+
+ res=theGSM3MobileClientProvider->availableSocket(flags & GSM3MOBILECLIENTSERVICE_CLIENT,mySocket);
+ if(flags & GSM3MOBILECLIENTSERVICE_SYNCH)
+ res=waitForAnswer();
+
+ return res;
+}
+
+int GSM3MobileClientService::read(uint8_t *buf, size_t size)
+{
+ int i;
+ uint8_t c;
+
+ for(i=0;ireadSocket(flags & GSM3MOBILECLIENTSERVICE_CLIENT, (char *)(buf), size, mySocket);
+
+ return res;
+*/
+}
+
+int GSM3MobileClientService::read()
+{
+ if(flags & GSM3MOBILECLIENTSERVICE_WRITING)
+ endWrite(true);
+ int c=theGSM3MobileClientProvider->readSocket();
+ return c;
+}
+
+int GSM3MobileClientService::peek()
+{
+ if(flags & GSM3MOBILECLIENTSERVICE_WRITING)
+ endWrite(true);
+ return theGSM3MobileClientProvider->peekSocket(/*mySocket, false*/);
+}
+
+void GSM3MobileClientService::flush()
+{
+ if(flags & GSM3MOBILECLIENTSERVICE_WRITING)
+ endWrite(true);
+ theGSM3MobileClientProvider->flushSocket(/*mySocket*/);
+ if(flags & GSM3MOBILECLIENTSERVICE_SYNCH)
+ waitForAnswer();
+
+}
+
+void GSM3MobileClientService::stop()
+{
+ if(flags & GSM3MOBILECLIENTSERVICE_WRITING)
+ endWrite(true);
+ theGSM3MobileClientProvider->disconnectTCP(flags & GSM3MOBILECLIENTSERVICE_CLIENT, mySocket);
+ theGSM3MobileClientProvider->releaseSocket(mySocket);
+ mySocket = 0;
+ if(flags & GSM3MOBILECLIENTSERVICE_SYNCH)
+ waitForAnswer();
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientService.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientService.h
new file mode 100644
index 00000000..304a5196
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileClientService.h
@@ -0,0 +1,162 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILECLIENTSERVICE_
+#define _GSM3MOBILECLIENTSERVICE_
+
+#include
+#include
+
+
+class GSM3MobileClientService : public Client
+{
+ private:
+
+ uint8_t mySocket;
+ uint8_t flags;
+
+ /** Blocks waiting for an answer
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int waitForAnswer();
+
+ public:
+
+ /** Constructor
+ @param synch Sync mode
+ */
+ GSM3MobileClientService(bool synch=true);
+
+ /** Constructor
+ @param socket Socket
+ @param synch Sync mode
+ */
+ GSM3MobileClientService(int socket, bool synch);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready();
+
+ // we take this function out as IPAddress is complex to bring to
+ // version 1.
+ /** Connect to server by IP address
+ @param (IPAddress)
+ @param (uint16_t)
+ @return returns 0 if last command is still executing, 1 success, 2 if there are no resources
+ */
+ inline int connect(IPAddress, uint16_t);
+
+ /** Connect to server by hostname
+ @param host Hostname
+ @param port Port
+ @return returns 0 if last command is still executing, 1 success, 2 if there are no resources
+ */
+ int connect(const char *host, uint16_t port);
+
+ /** Initialize write in request
+ @param sync Sync mode
+ */
+ void beginWrite(bool sync=false);
+
+ /** Write a character in request
+ @param c Character
+ @return size
+ */
+ size_t write(uint8_t c);
+
+ /** Write a characters buffer in request
+ @param buf Buffer
+ @return buffer size
+ */
+ size_t write(const uint8_t *buf);
+
+ /** Write a characters buffer with size in request
+ @param (uint8_t*) Buffer
+ @param (size_t) Buffer size
+ @return buffer size
+ */
+ size_t write(const uint8_t*, size_t);
+
+ /** Finish write request
+ @param sync Sync mode
+ */
+ void endWrite(bool sync=false);
+
+ /** Check if connected to server
+ @return 1 if connected
+ */
+ uint8_t connected();
+
+ operator bool();
+
+ /** Read from response buffer and copy size specified to buffer
+ @param buf Buffer
+ @param size Buffer size
+ @return bytes read
+ */
+ int read(uint8_t *buf, size_t size);
+
+ /** Read a character from response buffer
+ @return character
+ */
+ int read();
+
+ /** Check if exists a response available
+ @return 1 if exists, 0 if not exists
+ */
+ int available();
+
+ /** Read a character from response buffer but does not move the pointer.
+ @return character
+ */
+ int peek();
+
+ /** Flush response buffer
+ */
+ void flush();
+
+ /** Stop client
+ */
+ void stop();
+
+ /** Get socket
+ @return socket
+ */
+ inline int getSocket(){return (int)mySocket;};
+
+
+};
+
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileDataNetworkProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileDataNetworkProvider.cpp
new file mode 100644
index 00000000..538f6d43
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileDataNetworkProvider.cpp
@@ -0,0 +1,3 @@
+#include
+
+// GSM3MobileDataNetworkProvider* theGSM3MobileDataNetworkProvider;
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileDataNetworkProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileDataNetworkProvider.h
new file mode 100644
index 00000000..bffd381f
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileDataNetworkProvider.h
@@ -0,0 +1,62 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILEDATANETWORKPROVIDER_
+#define _GSM3MOBILEDATANETWORKPROVIDER_
+
+#include
+
+// This class is not really useful, but serves as a guideline for programmers
+// We keep it but it should never be linked
+class GSM3MobileDataNetworkProvider
+{
+ public:
+
+ /** Attach to GPRS/GSM network
+ @param networkId APN GPRS
+ @param user Username
+ @param pass Password
+ @return connection status
+ */
+ virtual GSM3_NetworkStatus_t networkAttach(char* networId, char* user, char* pass)=0;
+
+ /** Detach GPRS/GSM network
+ @return connection status
+ */
+ virtual GSM3_NetworkStatus_t networkDetach()=0;
+
+};
+
+extern GSM3MobileDataNetworkProvider* theGSM3MobileDataNetworkProvider;
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileMockupProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileMockupProvider.cpp
new file mode 100644
index 00000000..673285b5
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileMockupProvider.cpp
@@ -0,0 +1,191 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+#include
+#include
+
+
+GSM3MobileMockupProvider::GSM3MobileMockupProvider()
+{
+ lineStatus=IDLE;
+ msgExample="Hello#World";
+ msgIndex=0;
+};
+
+int GSM3MobileMockupProvider::begin(char* pin)
+{
+ Serial.println("GSM3MobileMockupProvider::begin()");
+ return 0;
+};
+
+int GSM3MobileMockupProvider::ready()
+{
+ Serial.println("GSM3MobileMockupProvider::ready()");
+ return 1;
+};
+
+int GSM3MobileMockupProvider::beginSMS(const char* number)
+{
+ Serial.println("SM3MobileMockupProvider::beginSMS()");
+ return 0;
+};
+
+void GSM3MobileMockupProvider::writeSMS(char c)
+{
+ Serial.print(c);
+};
+
+int GSM3MobileMockupProvider::endSMS()
+{
+ Serial.println("GSM3MobileMockupProvider::endSMS()");
+};
+
+int GSM3MobileMockupProvider::availableSMS()
+{
+ Serial.println("GSM3MobileMockupProvider::availableSMS()");
+ return 120;
+};
+
+int GSM3MobileMockupProvider::peek()
+{
+ return (int)'H';
+};
+
+int GSM3MobileMockupProvider::remoteSMSNumber(char* number, int nlength)
+{
+ if(nlength>=13)
+ strcpy(number, "+34630538546");
+ return 12;
+};
+
+
+void GSM3MobileMockupProvider::flushSMS()
+{
+ Serial.println("GSM3MobileMockupProvider::flushSMS()");
+};
+
+int GSM3MobileMockupProvider::readSMS()
+{
+ if(msgExample[msgIndex]==0)
+ {
+ msgIndex=0;
+ return 0;
+ }
+ else
+ {
+ msgIndex++;
+ return msgExample[msgIndex-1];
+ };
+};
+
+int GSM3MobileMockupProvider::connectTCPClient(const char* server, int port, int id_socket)
+{
+ Serial.println("GSM3MobileMockupProvider::connectTCPClient()");
+ Serial.print(server);Serial.print(":");Serial.print(port);Serial.print("-");Serial.println(id_socket);
+}
+
+void GSM3MobileMockupProvider::writeSocket(const uint8_t *buf, size_t size, int id_socket)
+{
+ int i;
+ for(i=0;i=minSocket())&&(socket<=maxSocket()))
+ return 1;
+ else
+ return 0;
+};
+*/
+
+int GSM3MobileMockupProvider::readSocket(uint8_t *buf, size_t size, int idsocket)
+{
+ int i;
+ int l=strlen(msgExample);
+ for(i=0;(i12))
+ strcpy("192.168.1.1", localIP);
+ return 1;
+};
+
+bool GSM3MobileMockupProvider::getSocketModemStatus(uint8_t s)
+{
+ // Feeling lazy
+ return true;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileMockupProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileMockupProvider.h
new file mode 100644
index 00000000..fc786d00
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileMockupProvider.h
@@ -0,0 +1,255 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILEMOCKUPPROVIDER_
+#define _GSM3MOBILEMOCKUPPROVIDER_
+
+#include
+#include
+
+class GSM3MobileMockupProvider: public GSM3MobileNetworkProvider
+{
+ private:
+ // Introducing this status is quite "heavy". But something like this should
+ // be added to ShieldV1. Or not.
+ // Note, in ShieldV1 there is no "RECEIVINGSMS" status.
+ enum GSM3_modemlinest_e { IDLE, WAITINGANSWER, SENDINGSMS};
+ GSM3_modemlinest_e lineStatus;
+ char* msgExample;
+ int msgIndex;
+
+ public:
+
+ /** Minimum socket
+ @return 1
+ */
+ inline int minSocket(){return 1;};
+
+ /** Maximum socket
+ @return 8
+ */
+ inline int maxSocket(){return 8;};
+
+ /** Constructor */
+ GSM3MobileMockupProvider();
+
+ /** Get network status
+ @return network status
+ */
+ inline GSM3_NetworkStatus_t getStatus(){return ERROR;};
+
+ /** Get voice call status
+ @return call status
+ */
+ inline GSM3_voiceCall_st getvoiceCallStatus(){return IDLE_CALL;};
+
+ /** Get last command status
+ @return Returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready();
+ inline void closeCommand(int code){};
+
+ //Configuration functions.
+
+ /** Begin connection
+ @param pin PIN code
+ @return
+ */
+ int begin(char* pin=0);
+
+ /** Check if is modem alive
+ @return 0
+ */
+ inline int isModemAlive(){return 0;};
+
+ /** Shutdown the modem (power off really)
+ @return true if successful
+ */
+ inline bool shutdown(){return false;};
+
+ //Call functions
+
+ /** Launch a voice call
+ @param number Phone number to be called
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ inline int voiceCall(const char* number){return 0;};
+
+ /** Answer a voice call
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ inline int answerCall(){return 0;};
+
+ /** Hang a voice call
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ inline int hangCall(){return 0;};
+
+ /** Retrieve phone number of caller
+ @param buffer Buffer for copy phone number
+ @param bufsize Buffer size
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ inline int retrieveCallingNumber(char* buffer, int*& bufsize){return 0;};
+
+ // SMS functions
+
+ /** Begin a SMS to send it
+ @param number Destination
+ @return error command if it exists
+ */
+ int beginSMS(const char* number);
+
+ /** End SMS
+ @return error command if it exists
+ */
+ int endSMS();
+
+ /** Check if SMS available and prepare it to be read
+ @return error command if it exists
+ */
+ int availableSMS();
+
+ /** Read a byte but do not advance the buffer header (circular buffer)
+ @return character
+ */
+ int peek();
+
+ /** Delete the SMS from Modem memory and proccess answer
+ */
+ void flushSMS();
+
+ /** Read sender number phone
+ @param number Buffer for save number phone
+ @param nlength Buffer length
+ @return 1 success, >1 error
+ */
+ int remoteSMSNumber(char* number, int nlength);
+
+ /** Read one char for SMS buffer (advance circular buffer)
+ @return character
+ */
+ int readSMS();
+
+ /** Write a SMS character by character
+ @param c Character
+ */
+ void writeSMS(char c);
+
+ // Socket functions
+
+ /** Connect to a remote TCP server
+ @param server String with IP or server name
+ @param port Remote port number
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int connectTCPClient(const char* server, int port, int id_socket);
+
+ // Attention to parameter rewriting in ShieldV1
+ /** Write buffer information into a socket
+ @param buf Buffer
+ @param size Buffer size
+ @param idsocket Socket
+ */
+ void writeSocket(const uint8_t *buf, size_t size, int idsocket);
+
+ // ShieldV1 will have two reading mechanisms:
+ // Mechanism 1: Call AT+QIRD for size bytes. Put them in the circular buffer,
+ // fill buf. Take care to xon/xoff effect, as we may copy just a part of the
+ // incoming bytes.
+ /** Read socket and put information in a buffer
+ @param buf Buffer
+ @param size Buffer size
+ @param idsocket Socket
+ @return
+ */
+ int readSocket(uint8_t *buf, size_t size, int idsocket);
+
+ // Mechanism 2 in ShieldV1:
+ // When called "available()" or "read()" reuse readSocket code to execute
+ // QIRD SYNCHRONOUSLY. Ask the modem for 1500 bytes but do not copy them anywhere,
+ // leave data in the circular buffer. Put buffer head at the start of received data.
+ // Peek() will get a character but will not advance the buffer head.
+ // Read() will get one character. XON/XOFF will take care of buffer filling
+ // If Read() gets to the end of the QIRD response, execute again QIRD SYNCHRONOUSLY
+ // If the user executes flush(), execute read() until there is nothing more to read()
+ // (the modem gives no way to empty the socket of incoming data)
+
+ /** Check if there are data to be read in socket.
+ @param idsocket Local socket number
+ @return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
+ */
+ int availableSocket(int idsocket);
+
+ /** Read data (get a character) available in socket
+ @param idsocket Socket
+ @param advance Determines if advance the buffer head
+ @return character
+ */
+ int readSocket(int idsocket, bool advance=true);
+
+ /** Flush socket
+ @param idsocket Socket
+ */
+ void flushSocket(int idsocket);
+
+ // This is the same in ShieldV1
+ /** Close a socket
+ @param idsocket Socket
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int disconnectTCP(int idsocket);
+
+ // TCP Server. Attention. Changing the int*&. We'll receive a buffer for the IP
+ // If the pointer ins NULL just forget it
+ // I think that opening a server does not occupy a socket. Is that true?
+ /** Establish a TCP connection
+ @param port Port
+ @param localIP IP address
+ @param localIPlength IP address size in characters
+ @return command error if exists
+ */
+ int connectTCPServer(int port, char* localIP, int* localIPlength);
+
+ // Modem sockets status. Return TRUE if the modem thinks the socket is occupied.
+ // This should be detected through an unrequisited response
+ /** Get modem status
+ @param s Socket
+ @return modem status (true if connected)
+ */
+ bool getSocketModemStatus(uint8_t s);
+
+
+};
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkProvider.cpp
new file mode 100644
index 00000000..324213c1
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkProvider.cpp
@@ -0,0 +1,72 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+
+GSM3MobileNetworkProvider* theProvider;
+
+GSM3MobileNetworkProvider::GSM3MobileNetworkProvider()
+{
+ socketsAsServer=0x0000;
+};
+
+
+int GSM3MobileNetworkProvider::getNewOccupiedSocketAsServer()
+{
+ int i;
+ for(i=minSocketAsServer(); i<=maxSocketAsServer(); i++)
+ {
+ if ((!(socketsAsServer&(0x0001<
+#include
+#include
+#include
+
+class GSM3MobileNetworkProvider
+{
+ private:
+
+ /** Restart hardware
+ @return 1 if successful
+ */
+ int HWrestart();
+
+ uint16_t socketsAsServer; // Server socket
+
+ /** Get modem status
+ @param s Socket
+ @return modem status (true if connected)
+ */
+ virtual inline bool getSocketAsServerModemStatus(int s){return false;};
+
+ public:
+
+ /** minSocketAsServer
+ @return 0
+ */
+ virtual inline int minSocketAsServer(){return 0;};
+
+ /** maxSocketAsServer
+ @return 0
+ */
+ virtual inline int maxSocketAsServer(){return 0;};
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+
+ /** Constructor */
+ GSM3MobileNetworkProvider();
+
+ /** Get network status
+ @return network status
+ */
+ virtual inline GSM3_NetworkStatus_t getStatus(){return ERROR;};
+
+ /** Get socket client status
+ @param socket Socket
+ @return 1 if connected, 0 otherwise
+ */
+ bool getStatusSocketClient(uint8_t socket);
+
+ /** Close a AT command
+ @param code Close code
+ */
+ virtual inline void closeCommand(int code){};
+
+ /** Establish a TCP connection
+ @param port Port
+ @param localIP IP address
+ @param localIPlength IP address size in characters
+ @return command error if exists
+ */
+ virtual inline int connectTCPServer(int port, char* localIP, int localIPlength){return 0;};
+
+ /** Get local IP address
+ @param LocalIP Buffer for save IP address
+ @param LocalIPlength Buffer size
+ */
+ virtual inline int getIP(char* LocalIP, int LocalIPlength){return 0;};
+
+ /** Get new occupied socket
+ @return -1 if no new socket has been occupied
+ */
+ int getNewOccupiedSocketAsServer();
+
+ /** Get socket status as server
+ @param socket Socket to get status
+ @return socket status
+ */
+ bool getStatusSocketAsServer(uint8_t socket);
+
+ /** Close a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int disconnectTCP(bool client1Server0, int idsocket){return 1;};
+
+ /** Release socket
+ @param socket Socket
+ */
+ void releaseSocket(int socket){};
+
+};
+
+extern GSM3MobileNetworkProvider* theProvider;
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkRegistry.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkRegistry.cpp
new file mode 100644
index 00000000..1ef6d8a5
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkRegistry.cpp
@@ -0,0 +1,51 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+
+GSM3MobileNetworkRegistry::GSM3MobileNetworkRegistry()
+{
+ theProvider=0;
+};
+
+void GSM3MobileNetworkRegistry::registerMobileNetworkProvider(GSM3MobileNetworkProvider* provider)
+{
+ theProvider=provider;
+}
+
+GSM3MobileNetworkProvider* GSM3MobileNetworkRegistry::getMobileNetworkProvider()
+{
+ return theProvider;
+}
+
+GSM3MobileNetworkRegistry theMobileNetworkRegistry;
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkRegistry.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkRegistry.h
new file mode 100644
index 00000000..77a7563e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileNetworkRegistry.h
@@ -0,0 +1,63 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILENETWORKREGISTRY_
+#define _GSM3MOBILENETWORKREGISTRY_
+#include
+
+class GSM3MobileNetworkRegistry
+{
+ private:
+
+ GSM3MobileNetworkProvider* theProvider; // Network provider
+
+ public:
+
+ /** Constructor */
+ GSM3MobileNetworkRegistry();
+
+ /** Register in mobile network provider
+ @param provider Provider
+ */
+ void registerMobileNetworkProvider(GSM3MobileNetworkProvider* provider);
+
+ /** Returns network provider object pointer
+ @return mobile network provider
+ */
+ GSM3MobileNetworkProvider* getMobileNetworkProvider();
+
+};
+
+extern GSM3MobileNetworkRegistry theMobileNetworkRegistry;
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileSMSProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileSMSProvider.cpp
new file mode 100644
index 00000000..b5363308
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileSMSProvider.cpp
@@ -0,0 +1,3 @@
+#include
+
+GSM3MobileSMSProvider* theGSM3SMSProvider;
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileSMSProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileSMSProvider.h
new file mode 100644
index 00000000..aa727110
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileSMSProvider.h
@@ -0,0 +1,91 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILESMSPROVIDER_
+#define _GSM3MOBILESMSPROVIDER_
+
+class GSM3MobileSMSProvider
+{
+ public:
+
+ /** Begin a SMS to send it
+ @param to Destination
+ @return error command if it exists
+ */
+ virtual inline int beginSMS(const char* to){return 0;};
+
+ /** Write a SMS character by character
+ @param c Character
+ */
+ virtual inline void writeSMS(const char c){};
+
+ /** End SMS
+ @return error command if it exists
+ */
+ virtual inline int endSMS(){return 0;};
+
+ /** Check if SMS available and prepare it to be read
+ @return number of bytes in a received SMS
+ */
+ virtual inline int availableSMS(){return 0;};
+
+ /** Read a byte but do not advance the buffer header (circular buffer)
+ @return character
+ */
+ virtual inline int peekSMS(){return 0;};
+
+ /** Delete the SMS from Modem memory and proccess answer
+ */
+ virtual inline void flushSMS(){return;};
+
+ /** Read sender number phone
+ @param number Buffer for save number phone
+ @param nlength Buffer length
+ @return 1 success, >1 error
+ */
+ virtual inline int remoteSMSNumber(char* number, int nlength){return 0;};
+
+ /** Read one char for SMS buffer (advance circular buffer)
+ @return character
+ */
+ virtual inline int readSMS(){return 0;};
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+};
+
+extern GSM3MobileSMSProvider* theGSM3SMSProvider;
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerProvider.cpp
new file mode 100644
index 00000000..4739ac7e
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerProvider.cpp
@@ -0,0 +1,5 @@
+ #include
+
+ GSM3MobileServerProvider* theGSM3MobileServerProvider;
+
+
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerProvider.h
new file mode 100644
index 00000000..e4eb9c50
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerProvider.h
@@ -0,0 +1,95 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_MOBILESERVERPROVIDER__
+#define __GSM3_MOBILESERVERPROVIDER__
+
+
+#include
+#include
+#include
+
+
+class GSM3MobileServerProvider
+{
+ /** Get socket status
+ @param s Socket
+ @return modem status (true if connected)
+ */
+ virtual bool getSocketAsServerModemStatus(int s)=0;
+
+ public:
+
+ /** minSocketAsServer
+ @return socket
+ */
+ virtual int minSocketAsServer()=0;
+
+ /** maxSocketAsServer
+ @return socket
+ */
+ virtual int maxSocketAsServer()=0;
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+
+ /** Constructor */
+ GSM3MobileServerProvider(){};
+
+ /** Connect server to TCP port
+ @param port TCP port
+ @return command error if exists
+ */
+ virtual int connectTCPServer(int port)=0;
+ //virtual int getIP(char* LocalIP, int LocalIPlength)=0;
+
+ /** Get new occupied socket as server
+ @return return -1 if no new socket has been occupied
+ */
+ virtual int getNewOccupiedSocketAsServer()=0;
+
+ /** Get socket status
+ @param socket Socket
+ @return socket status (true if connected)
+ */
+ virtual bool getStatusSocketAsServer(uint8_t socket)=0;
+
+ // virtual int disconnectTCP(bool client1Server0, int idsocket)=0;
+
+};
+
+extern GSM3MobileServerProvider* theGSM3MobileServerProvider;
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerService.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerService.cpp
new file mode 100644
index 00000000..2baca209
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerService.cpp
@@ -0,0 +1,159 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+#include
+
+
+#define __TOUTSERVER__ 10000
+#define BUFFERSIZETWEET 100
+
+#define GSM3MOBILESERVERSERVICE_SYNCH 0x01 // 1: TRUE, compatible with other clients 0: FALSE
+
+// While there is only a shield (ShieldV1) we will include it by default
+#include
+GSM3ShieldV1ServerProvider theShieldV1ServerProvider;
+
+
+GSM3MobileServerService::GSM3MobileServerService(uint8_t port, bool synch)
+{
+ mySocket=0;
+ _port=port;
+ flags = 0;
+
+ // If synchronous
+ if(synch)
+ flags |= GSM3MOBILESERVERSERVICE_SYNCH;
+}
+
+// Returns 0 if last command is still executing
+// 1 if success
+// >1 if error
+int GSM3MobileServerService::ready()
+{
+ return theGSM3MobileServerProvider->ready();
+}
+
+void GSM3MobileServerService::begin()
+{
+ if(theGSM3MobileServerProvider==0)
+ return;
+ theGSM3MobileServerProvider->connectTCPServer(_port);
+
+ if(flags & GSM3MOBILESERVERSERVICE_SYNCH)
+ waitForAnswer();
+}
+
+GSM3MobileClientService GSM3MobileServerService::available(bool synch)
+{
+ int newSocket;
+ // In case we are debugging, we'll need to force a look at the buffer
+ ready();
+
+ newSocket=theGSM3MobileServerProvider->getNewOccupiedSocketAsServer();
+
+ // Instatiate new client. If we are synch, the client is synchronous/blocking
+ GSM3MobileClientService client((uint8_t)(newSocket), (flags & GSM3MOBILESERVERSERVICE_SYNCH));
+
+ return client;
+}
+
+size_t GSM3MobileServerService::write(uint8_t c)
+{
+// Adapt to the new, lean implementation
+// theGSM3MobileServerProvider->writeSocket(c);
+ return 1;
+}
+
+void GSM3MobileServerService::beginWrite()
+{
+// Adapt to the new, lean implementation
+// theGSM3MobileServerProvider->beginWriteSocket(local1Remote0, mySocket);
+}
+
+size_t GSM3MobileServerService::write(const uint8_t* buf)
+{
+// Adapt to the new, lean implementation
+// theGSM3MobileServerProvider->writeSocket((const char*)(buf));
+ return strlen((const char*)buf);
+}
+
+size_t GSM3MobileServerService::write(const uint8_t* buf, size_t sz)
+{
+// Adapt to the new, lean implementation
+// theGSM3MobileServerProvider->writeSocket((const char*)(buf));
+}
+
+void GSM3MobileServerService::endWrite()
+{
+// Adapt to the new, lean implementation
+// theGSM3MobileServerProvider->endWriteSocket();
+}
+
+void GSM3MobileServerService::stop()
+{
+
+ // Review, should be the server?
+ theGSM3MobileClientProvider->disconnectTCP(local1Remote0, mySocket);
+ if(flags & GSM3MOBILESERVERSERVICE_SYNCH)
+ waitForAnswer();
+ theGSM3MobileClientProvider->releaseSocket(mySocket);
+ mySocket = -1;
+}
+
+
+/*int GSM3MobileServerService::getIP(char* LocalIP, int LocalIPlength)
+{
+ return theGSM3MobileServerProvider->getIP(LocalIP, LocalIPlength);
+}*/
+
+int GSM3MobileServerService::waitForAnswer()
+{
+ unsigned long m;
+ m=millis();
+ int res;
+
+ while(((millis()-m)< __TOUTSERVER__ )&&(ready()==0))
+ delay(10);
+
+ res=ready();
+
+ // If we get something different from a 1, we are having a problem
+ if(res!=1)
+ res=0;
+
+ return res;
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerService.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerService.h
new file mode 100644
index 00000000..2d25e38c
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileServerService.h
@@ -0,0 +1,124 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILESERVERSERVICE_
+#define _GSM3MOBILESERVERSERVICE_
+
+#include
+#include
+#include
+
+class GSM3MobileServerService : public Server
+{
+ private:
+
+ uint8_t _port; // Port
+ uint8_t mySocket; // Actual socket
+ uint8_t flags;
+ bool local1Remote0;
+
+ /** Internal utility, used in synchronous calls
+ @return operation result, 1 if success, 0 otherwise
+ */
+ int waitForAnswer();
+
+ public:
+
+ /** Constructor
+ @param port Port
+ @param synch True if the server acts synchronously
+ */
+ GSM3MobileServerService(uint8_t port, bool synch=true);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready();
+
+ /** Initialize server
+ */
+ void begin();
+
+ /** Check if there is an incoming client request
+ @param synch If true, the returned client is synchronous or
+ blocking.
+ @return Client if successful, else error
+ */
+ GSM3MobileClientService available(bool synch=true);
+
+ // Just to keep in line with Ethernet.
+ // Write to every open socket...
+ //void write(uint8_t);
+ //void write(const uint8_t *buf, size_t size);
+
+ /** Begin write in socket
+ */
+ void beginWrite();
+
+ /** Write character in socket
+ @param c Character
+ @return size
+ */
+ size_t write(uint8_t c);
+
+ /** Write buffer in socket
+ @param buf Buffer
+ @return size
+ */
+ size_t write(const uint8_t *buf);
+
+ /** Write buffer in socket with size
+ @param buf Buffer
+ @param sz Buffer size
+ @return size
+ */
+ size_t write(const uint8_t *buf, size_t sz);
+
+ /** End write in socket
+ */
+ void endWrite();
+
+ /** Stop server
+ */
+ void stop();
+
+ // we take this function out as IPAddress is complex to bring to
+ // version 1.
+ // inline int connect(IPAddress ip, uint16_t port){return 0;};
+ // Returns 2 if there are no resources
+ //int getIP(char* LocalIP, int LocalIPlength);
+
+};
+
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileVoiceProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileVoiceProvider.cpp
new file mode 100644
index 00000000..7af4e8fc
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileVoiceProvider.cpp
@@ -0,0 +1,4 @@
+#include
+
+
+GSM3MobileVoiceProvider* theGSM3MobileVoiceProvider;
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileVoiceProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileVoiceProvider.h
new file mode 100644
index 00000000..2091a1ba
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3MobileVoiceProvider.h
@@ -0,0 +1,90 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3MOBILEVOICEPROVIDER_
+#define _GSM3MOBILEVOICEPROVIDER_
+
+enum GSM3_voiceCall_st { IDLE_CALL, CALLING, RECEIVINGCALL, TALKING};
+
+class GSM3MobileVoiceProvider
+{
+ public:
+
+ /** Initialize the object relating it to the general infrastructure
+ @param
+ @return void
+ */
+ virtual void initialize(){};
+
+ /** Launch a voice call
+ @param number Phone number to be called
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ virtual int voiceCall(const char* number)=0;
+
+ /** Answer a voice call
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ virtual int answerCall()=0;
+
+ /** Hang a voice call
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ virtual int hangCall()=0;
+
+ /** Retrieve phone number of caller
+ @param buffer Buffer for copy phone number
+ @param bufsize Buffer size
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ virtual int retrieveCallingNumber(char* buffer, int bufsize)=0;
+
+ /** Returns voice call status
+ @return voice call status
+ */
+ virtual GSM3_voiceCall_st getvoiceCallStatus()=0;
+
+ /** Set voice call status
+ @param status New status for voice call
+ */
+ virtual void setvoiceCallStatus(GSM3_voiceCall_st status)=0;
+
+ /** Get last command status
+ @return Returns 0 if last command is still executing, 1 success, >1 error
+ */
+ virtual int ready()=0;
+};
+
+extern GSM3MobileVoiceProvider* theGSM3MobileVoiceProvider;
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SMSService.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SMSService.cpp
new file mode 100644
index 00000000..96f53f87
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SMSService.cpp
@@ -0,0 +1,126 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+#include
+
+// While there is only a shield (ShieldV1) we will include it by default
+#include
+GSM3ShieldV1SMSProvider theShieldV1SMSProvider;
+
+#define GSM3SMSSERVICE_SYNCH 0x01 // 1: synchronous 0: asynchronous
+#define __TOUT__ 10000
+
+
+GSM3SMSService::GSM3SMSService(bool synch)
+{
+ if(synch)
+ flags |= GSM3SMSSERVICE_SYNCH;
+}
+
+// Returns 0 if last command is still executing
+// 1 if success
+// >1 if error
+int GSM3SMSService::ready()
+{
+ return theGSM3SMSProvider->ready();
+}
+
+int GSM3SMSService::beginSMS(const char *number)
+{
+ return waitForAnswerIfNeeded(theGSM3SMSProvider->beginSMS(number));
+};
+
+int GSM3SMSService::endSMS()
+{
+ return waitForAnswerIfNeeded(theGSM3SMSProvider->endSMS());
+};
+
+size_t GSM3SMSService::write(uint8_t c)
+{
+ theGSM3SMSProvider->writeSMS(c);
+ return 1;
+}
+
+void GSM3SMSService::flush()
+{
+ theGSM3SMSProvider->flushSMS();
+ waitForAnswerIfNeeded(1);
+};
+
+int GSM3SMSService::available()
+{
+ return waitForAnswerIfNeeded(theGSM3SMSProvider->availableSMS());
+};
+
+int GSM3SMSService::remoteNumber(char* number, int nlength)
+{
+ return theGSM3SMSProvider->remoteSMSNumber(number, nlength);
+
+}
+
+int GSM3SMSService::read()
+{
+ return theGSM3SMSProvider->readSMS();
+};
+int GSM3SMSService::peek()
+{
+ return theGSM3SMSProvider->peekSMS();
+};
+
+int GSM3SMSService::waitForAnswerIfNeeded(int returnvalue)
+{
+ // If synchronous
+ if(flags & GSM3SMSSERVICE_SYNCH )
+ {
+ unsigned long m;
+ m=millis();
+ // Wait for __TOUT__
+ while(((millis()-m)< __TOUT__ )&&(ready()==0))
+ delay(100);
+ // If everything was OK, return 1
+ // else (timeout or error codes) return 0;
+ if(ready()==1)
+ return 1;
+ else
+ return 0;
+ }
+ // If not synchronous just kick ahead the coming result
+ return ready();
+}
+
+
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SMSService.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SMSService.h
new file mode 100644
index 00000000..8cb61040
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SMSService.h
@@ -0,0 +1,110 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SMSSERVICE_
+#define _GSM3SMSSERVICE_
+
+#include
+#include
+
+class GSM3SMSService : public Stream
+{
+ private:
+
+ uint8_t flags;
+
+ /** Makes synchronous the functions, if needed
+ @param returnvalue Return value
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int waitForAnswerIfNeeded(int returnvalue);
+
+ public:
+
+ /** Constructor
+ @param synch Determines sync mode
+ */
+ GSM3SMSService(bool synch=true);
+
+ /** Write a character in SMS message
+ @param c Character
+ @return size
+ */
+ size_t write(uint8_t c);
+
+ /** Begin a SMS to send it
+ @param to Destination
+ @return error command if it exists
+ */
+ int beginSMS(const char* to);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready();
+
+ /** End SMS
+ @return error command if it exists
+ */
+ int endSMS();
+
+ /** Check if SMS available and prepare it to be read
+ @return number of bytes in a received SMS
+ */
+ int available();
+
+ /** Read sender number phone
+ @param number Buffer for save number phone
+ @param nlength Buffer length
+ @return 1 success, >1 error
+ */
+ int remoteNumber(char* number, int nlength);
+
+ /** Read one char for SMS buffer (advance circular buffer)
+ @return byte
+ */
+ int read();
+
+ /** Read a byte but do not advance the buffer header (circular buffer)
+ @return byte
+ */
+ int peek();
+
+ /** Delete the SMS from Modem memory and proccess answer
+ */
+ void flush();
+
+};
+
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1.cpp
new file mode 100644
index 00000000..a36cf1d9
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1.cpp
@@ -0,0 +1,96 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+#include
+
+#define __RESETPIN__ 7
+#define __TOUTLOCALCOMS__ 500
+#define __TOUTSHUTDOWN__ 5000
+#define __TOUTMODEMCONFIGURATION__ 5000//equivalent to 30000 because of time in interrupt routine.
+#define __TOUTAT__ 1000
+#define __TOUTSMS__ 7000
+#define __TOUTCALL__ 15000
+#define __TOUTGPRS__ 10000
+#define __NCLIENTS_MAX__ 3
+
+//Constructor.
+GSM3ShieldV1::GSM3ShieldV1(bool db)
+{
+ theGSM3ShieldV1ModemCore.setCommandCounter(1);
+ socketsAccepted=0;
+ theGSM3ShieldV1ModemCore.registerUMProvider(this);
+ theProvider=this;
+}
+
+//Response management.
+void GSM3ShieldV1::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+
+ }
+}
+
+//Function for 2 sec delay inside an interruption.
+void GSM3ShieldV1::delayInsideInterrupt2seg()
+{
+ for (int k=0;k<40;k++) theGSM3ShieldV1ModemCore.gss.tunedDelay(50000);
+}
+
+///////////////////////////////////////////////////////UNSOLICITED RESULT CODE (URC) FUNCTIONS///////////////////////////////////////////////////////////////////
+
+//URC recognize.
+bool GSM3ShieldV1::recognizeUnsolicitedEvent(byte oldTail)
+{
+
+int nlength;
+char auxLocate [15];
+ //POWER DOWN.
+ prepareAuxLocate(PSTR("POWER DOWN"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate))
+ {
+ theGSM3ShieldV1ModemCore.gss.cb.flush();
+ return true;
+ }
+
+
+ return false;
+}
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1.h
new file mode 100644
index 00000000..78617d07
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1.h
@@ -0,0 +1,137 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_SHIELDV1__
+#define __GSM3_SHIELDV1__
+
+#include
+#include
+#include
+#include
+
+
+class GSM3ShieldV1 : public GSM3MobileNetworkProvider, public GSM3ShieldV1BaseProvider
+{
+ // General code, for modem management
+ private:
+
+ /** Delay inside an interrupt (2 seconds)
+ */
+ void delayInsideInterrupt2seg();
+
+ // Code for SMS Service
+ private:
+
+
+ long commandMillis;
+ bool commandSent;
+
+ const char* pinConfig; //PIN.
+ char* accessPoint; //APN.
+ char* userName; //User.
+ char* passw; //Password.
+ const char* remoteID; //Server.
+
+ char* dataSocket; //Data socket.
+ int local_Port; //Local Port.
+ char* local_IP; //Local IP.
+ int local_IP_Length; //Local IP length.
+
+
+ int socketDataSize; //Size of socket data to be read.
+ int socketDataSizeWritten; //Number of socket data written in buffer not to overflow the buffer
+
+ int socketsAccepted; //Status for remote clients accepted of closed.
+
+ public:
+
+ /** Constructor **/
+ GSM3ShieldV1(bool debug=false);
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Parse modem response
+ @param rsp Returns true if expected response exists
+ @param string1 Substring expected in response
+ @param string2 Second substring expected in response
+ @return true if parsed successful
+ */
+ bool genericParse_rsp2(bool& rsp, char* string1, char* string2);
+
+ /** Recognize URC
+ @param oldTail
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte oldTail);
+
+ /** Receive answer
+ @return true if successful
+ */
+ bool answerReceived();
+
+ /** Receive socket
+ @param id_socket Socket ID
+ @return true if successful
+ */
+ bool socketReceived(int id_socket);
+
+ /** Update active ID sockets
+ @param active Active sockets
+ @param ID Id for update
+ */
+ void update_activeIDsockets (bool active, int ID);
+
+ /** Assign ID to socket
+ @param ID Id to assign to socket
+ @return true if successful
+ */
+ bool assignIDsocket (int& ID);
+
+ /** Close data socket
+ @return true if successful
+ */
+ bool closedDataSocket(); //Flag closed current data socket.
+
+ //bool writeIncomingCalls(char* bufferForCallerId) If isn't zero, doesn't wait calls
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1AccessProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1AccessProvider.cpp
new file mode 100644
index 00000000..67ae7555
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1AccessProvider.cpp
@@ -0,0 +1,296 @@
+#include
+#include
+
+#define __RESETPIN__ 7
+#define __TOUTSHUTDOWN__ 5000
+#define __TOUTMODEMCONFIGURATION__ 5000//equivalent to 30000 because of time in interrupt routine.
+#define __TOUTAT__ 1000
+
+char _command_AT[] PROGMEM = "AT";
+char _command_CGREG[] PROGMEM = "AT+CGREG?";
+
+
+GSM3ShieldV1AccessProvider::GSM3ShieldV1AccessProvider(bool debug)
+{
+ theGSM3ShieldV1ModemCore.setDebug(debug);
+
+}
+
+void GSM3ShieldV1AccessProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case MODEMCONFIG:
+ ModemConfigurationContinue();
+ break;
+ case ALIVETEST:
+ isModemAliveContinue();
+ break;
+ }
+}
+
+///////////////////////////////////////////////////////CONFIGURATION FUNCTIONS///////////////////////////////////////////////////////////////////
+
+// Begin
+// Restart or start the modem
+// May be synchronous
+GSM3_NetworkStatus_t GSM3ShieldV1AccessProvider::begin(char* pin, bool restart, bool synchronous)
+{
+ pinMode(__RESETPIN__, OUTPUT);
+
+ // If asked for modem restart, restart
+ if (restart)
+ HWrestart();
+ else
+ HWstart();
+
+ theGSM3ShieldV1ModemCore.gss.begin(9600);
+ // Launch modem configuration commands
+ ModemConfiguration(pin);
+ // If synchronous, wait till ModemConfiguration is over
+ if(synchronous)
+ {
+ // if we shorten this delay, the command fails
+ while(ready()==0)
+ delay(1000);
+ }
+ return getStatus();
+}
+
+//HWrestart.
+int GSM3ShieldV1AccessProvider::HWrestart()
+{
+
+ theGSM3ShieldV1ModemCore.setStatus(IDLE);
+ digitalWrite(__RESETPIN__, HIGH);
+ delay(12000);
+ digitalWrite(__RESETPIN__, LOW);
+ delay(1000);
+ return 1; //configandwait(pin);
+}
+
+//HWrestart.
+int GSM3ShieldV1AccessProvider::HWstart()
+{
+
+ theGSM3ShieldV1ModemCore.setStatus(IDLE);
+ digitalWrite(__RESETPIN__, HIGH);
+ delay(2000);
+ digitalWrite(__RESETPIN__, LOW);
+ //delay(1000);
+
+ return 1; //configandwait(pin);
+}
+
+//Initial configuration main function.
+int GSM3ShieldV1AccessProvider::ModemConfiguration(char* pin)
+{
+ theGSM3ShieldV1ModemCore.setPhoneNumber(pin);
+ theGSM3ShieldV1ModemCore.openCommand(this,MODEMCONFIG);
+ theGSM3ShieldV1ModemCore.setStatus(CONNECTING);
+ ModemConfigurationContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Initial configuration continue function.
+void GSM3ShieldV1AccessProvider::ModemConfigurationContinue()
+{
+ bool resp;
+
+ // 1: Send AT
+ // 2: Wait AT OK and SetPin or CGREG
+ // 3: Wait Pin OK and CGREG
+ // 4: Wait CGREG and Flow SW control or CGREG
+ // 5: Wait IFC OK and SMS Text Mode
+ // 6: Wait SMS text Mode OK and Calling line identification
+ // 7: Wait Calling Line Id OK and Echo off
+ // 8: Wait for OK and COLP command for connecting line identification.
+ // 9: Wait for OK.
+ int ct=theGSM3ShieldV1ModemCore.getCommandCounter();
+ if(ct==1)
+ {
+ // Launch AT
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT);
+ }
+ else if(ct==2)
+ {
+ // Wait for AT - OK.
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ // OK received
+ if(theGSM3ShieldV1ModemCore.getPhoneNumber() && (theGSM3ShieldV1ModemCore.getPhoneNumber()[0]!=0))
+ {
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CPIN="), false);
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ theGSM3ShieldV1ModemCore.genericCommand_rqc(theGSM3ShieldV1ModemCore.getPhoneNumber());
+ }
+ else
+ {
+ //DEBUG
+ //Serial.println("AT+CGREG?");
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ theGSM3ShieldV1ModemCore.takeMilliseconds();
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG);
+ }
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==3)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ theGSM3ShieldV1ModemCore.takeMilliseconds();
+ theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==4)
+ {
+ char auxLocate1 [12];
+ char auxLocate2 [12];
+ prepareAuxLocate(PSTR("+CGREG: 0,1"), auxLocate1);
+ prepareAuxLocate(PSTR("+CGREG: 0,5"), auxLocate2);
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate1, auxLocate2))
+ {
+ if(resp)
+ {
+ theGSM3ShieldV1ModemCore.setCommandCounter(5);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+IFC=1,1"));
+ }
+ else
+ {
+ // If not, launch command again
+ if(theGSM3ShieldV1ModemCore.takeMilliseconds() > __TOUTMODEMCONFIGURATION__)
+ {
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGREG);
+ }
+ }
+ }
+ }
+ else if(ct==5)
+ {
+ // 5: Wait IFC OK
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ //Delay for SW flow control being active.
+ theGSM3ShieldV1ModemCore.delayInsideInterrupt(2000);
+ // 9: SMS Text Mode
+ theGSM3ShieldV1ModemCore.setCommandCounter(6);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGF=1"));
+ }
+ }
+ else if(ct==6)
+ {
+ // 6: Wait SMS text Mode OK
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ //Calling line identification
+ theGSM3ShieldV1ModemCore.setCommandCounter(7);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLIP=1"));
+ }
+ }
+ else if(ct==7)
+ {
+ // 7: Wait Calling Line Id OK
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Echo off
+ theGSM3ShieldV1ModemCore.setCommandCounter(8);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATE0"));
+ }
+ }
+ else if(ct==8)
+ {
+ // 8: Wait ATEO OK, send COLP
+ // In Arduino Mega, attention, take away the COLP step
+ // It looks as we can only have 8 steps
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ theGSM3ShieldV1ModemCore.setCommandCounter(9);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+COLP=1"));
+ }
+ }
+ else if(ct==9)
+ {
+ // 9: Wait ATCOLP OK
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if (resp)
+ {
+ theGSM3ShieldV1ModemCore.setStatus(GSM_READY);
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+}
+
+//Alive Test main function.
+int GSM3ShieldV1AccessProvider::isAccessAlive()
+{
+ theGSM3ShieldV1ModemCore.setCommandError(0);
+ theGSM3ShieldV1ModemCore.setCommandCounter(1);
+ theGSM3ShieldV1ModemCore.openCommand(this,ALIVETEST);
+ isModemAliveContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Alive Test continue function.
+void GSM3ShieldV1AccessProvider::isModemAliveContinue()
+{
+bool rsp;
+switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_AT);
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(rsp))
+ {
+ if (rsp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Shutdown.
+bool GSM3ShieldV1AccessProvider::shutdown()
+{
+ unsigned long m;
+ bool resp;
+ char auxLocate [18];
+
+ // It makes no sense to have an asynchronous shutdown
+ pinMode(__RESETPIN__, OUTPUT);
+ digitalWrite(__RESETPIN__, HIGH);
+ delay(1500);
+ digitalWrite(__RESETPIN__, LOW);
+ theGSM3ShieldV1ModemCore.setStatus(IDLE);
+ theGSM3ShieldV1ModemCore.gss.close();
+
+ m=millis();
+ prepareAuxLocate(PSTR("POWER DOWN"), auxLocate);
+ while((millis()-m) < __TOUTSHUTDOWN__)
+ {
+ delay(1);
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, auxLocate))
+ return resp;
+ }
+ return false;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1AccessProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1AccessProvider.h
new file mode 100644
index 00000000..1ddcc8cc
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1AccessProvider.h
@@ -0,0 +1,116 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SHIELDV1ACCESSPROVIDER_
+#define _GSM3SHIELDV1ACCESSPROVIDER_
+
+#include
+#include
+#include
+
+class GSM3ShieldV1AccessProvider : public GSM3MobileAccessProvider, public GSM3ShieldV1BaseProvider
+{
+ private:
+
+ /** Initialize main modem configuration
+ @param pin PIN code
+ @return command error if exists
+ */
+ int ModemConfiguration(char* pin);
+
+ /** Continue to modem configuration function
+ */
+ void ModemConfigurationContinue();
+
+ /** Continue to check if modem alive function
+ */
+ void isModemAliveContinue();
+
+
+ public:
+
+ /** Constructor
+ @param debug Determines debug mode
+ */
+
+ GSM3ShieldV1AccessProvider(bool debug=false);
+
+ /** Start the GSM/GPRS modem, attaching to the GSM network
+ @param pin SIM PIN number (4 digits in a string, example: "1234"). If
+ NULL the SIM has no configured PIN.
+ @param restart Restart the modem. Default is TRUE. The modem receives
+ a signal through the Ctrl/D7 pin. If it is shut down, it will
+ start-up. If it is running, it will restart. Takes up to 10
+ seconds
+ @param synchronous If TRUE the call only returns after the Start is complete
+ or fails. If FALSE the call will return inmediately. You have
+ to call repeatedly ready() until you get a result. Default is TRUE.
+ @return If synchronous, GSM3_NetworkStatus_t. If asynchronous, returns 0.
+ */
+ GSM3_NetworkStatus_t begin(char* pin=0,bool restart=true, bool synchronous=true);
+
+ /** Check network access status
+ @return 1 if Alive, 0 if down
+ */
+ int isAccessAlive();
+
+ /** Shutdown the modem (power off really)
+ @return true if successful
+ */
+ bool shutdown();
+
+ /** Returns 0 if last command is still executing
+ @return 1 if success, >1 if error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Returns modem status
+ @return modem network status
+ */
+ inline GSM3_NetworkStatus_t getStatus(){return theGSM3ShieldV1ModemCore.getStatus();};
+
+ void manageResponse(byte from, byte to);
+
+ /** Restart the modem (will shut down if running)
+ @return 1 if success, >1 if error
+ */
+ int HWrestart();
+
+ /** Start the modem (will not shut down if running)
+ @return 1 if success, >1 if error
+ */
+ int HWstart();
+
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BandManagement.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BandManagement.cpp
new file mode 100644
index 00000000..94dec9ae
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BandManagement.cpp
@@ -0,0 +1,67 @@
+#include
+
+GSM3ShieldV1BandManagement::GSM3ShieldV1BandManagement(bool trace): modem(trace)
+{
+ quectelStrings[UNDEFINED]="";
+ quectelStrings[EGSM_MODE]="\"EGSM_MODE\"";
+ quectelStrings[DCS_MODE]="\"DCS_MODE\"";
+ quectelStrings[PCS_MODE]="\"PCS_MODE\"";
+ quectelStrings[EGSM_DCS_MODE]="\"EGSM_DCS_MODE\"";
+ quectelStrings[GSM850_PCS_MODE]="\"GSM850_PCS_MODE\"";
+ quectelStrings[GSM850_EGSM_DCS_PCS_MODE]="\"GSM850_EGSM_DCS_PCS_MODE\"";
+}
+
+GSM3_NetworkStatus_t GSM3ShieldV1BandManagement::begin()
+{
+ // check modem response
+ modem.begin();
+
+ // reset hardware
+ modem.restartModem();
+
+ return IDLE;
+}
+
+String GSM3ShieldV1BandManagement::getBand()
+{
+ String modemResponse=modem.writeModemCommand("AT+QBAND?", 2000);
+
+ for(GSM3GSMBand i=GSM850_EGSM_DCS_PCS_MODE;i>UNDEFINED;i=(GSM3GSMBand)((int)i-1))
+ {
+ if(modemResponse.indexOf(quectelStrings[i])>=0)
+ return quectelStrings[i];
+ }
+
+ Serial.print("Unrecognized modem answer:");
+ Serial.println(modemResponse);
+
+ return "";
+}
+
+bool GSM3ShieldV1BandManagement::setBand(String band)
+{
+ String command;
+ String modemResponse;
+ bool found=false;
+
+ command="AT+QBAND=";
+ for(GSM3GSMBand i=EGSM_MODE;((i<=GSM850_EGSM_DCS_PCS_MODE)&&(!found));i=(GSM3GSMBand)((int)i+1))
+ {
+ String aux=quectelStrings[i];
+ if(aux.indexOf(band)>=0)
+ {
+ command+=aux;
+ found=true;
+ }
+ }
+
+ if(!found)
+ return false;
+ // Quad-band takes an awful lot of time
+ modemResponse=modem.writeModemCommand(command, 15000);
+
+ if(modemResponse.indexOf("QBAND")>=0)
+ return true;
+ else
+ return false;
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BandManagement.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BandManagement.h
new file mode 100644
index 00000000..919d4ad2
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BandManagement.h
@@ -0,0 +1,96 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3SHIELDV1BANDMANAGEMENT__
+#define __GSM3SHIELDV1BANDMANAGEMENT__
+
+// This class executes band management functions for the ShieldV1
+#include
+
+#define NUMBEROFBANDS 7
+#define GSM_MODE_UNDEFINED "UNDEFINED"
+#define GSM_MODE_EGSM "EGSM_MODE"
+#define GSM_MODE_DCS "DCS_MODE"
+#define GSM_MODE_PCS "PCS_MODE"
+#define GSM_MODE_EGSM_DCS "EGSM_DCS_MODE"
+#define GSM_MODE_GSM850_PCS "GSM850_PCS_MODE"
+#define GSM_MODE_GSM850_EGSM_DCS_PCS "GSM850_EGSM_DCS_PCS_MODE"
+
+typedef enum GSM3GSMBand {UNDEFINED, EGSM_MODE, DCS_MODE, PCS_MODE, EGSM_DCS_MODE, GSM850_PCS_MODE, GSM850_EGSM_DCS_PCS_MODE};
+
+//
+// These are the bands and scopes:
+//
+// E-GSM(900)
+// DCS(1800)
+// PCS(1900)
+// E-GSM(900)+DCS(1800) ex: Europe
+// GSM(850)+PCS(1900) Ex: USA, South Am.
+// GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)
+
+class GSM3ShieldV1BandManagement
+{
+ private:
+
+ GSM3ShieldV1DirectModemProvider modem; // Direct access to modem
+
+ char* quectelStrings[NUMBEROFBANDS];// = {"\"EGSM_MODE\"", "\"DCS_MODE\"", "\"PCS_MODE\"",
+ //"\"EGSM_DCS_MODE\"", "\"GSM850_PCS_MODE\"",
+ //"\"GSM850_EGSM_DCS_PCS_MODE\""};
+
+
+ public:
+
+ /** Constructor
+ @param trace If true, dumps all AT dialogue to Serial
+ */
+ GSM3ShieldV1BandManagement(bool trace=false);
+
+ /** Forces modem hardware restart, so we begin from scratch
+ @return always returns IDLE status
+ */
+ GSM3_NetworkStatus_t begin();
+
+ /** Get current modem work band
+ @return current modem work band
+ */
+ String getBand();
+
+ /** Changes the modem operating band
+ @param band Desired new band
+ @return true if success, false otherwise
+ */
+ bool setBand(String band);
+
+};
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BaseProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BaseProvider.cpp
new file mode 100644
index 00000000..d63967be
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BaseProvider.cpp
@@ -0,0 +1,27 @@
+#include
+#include
+#include
+
+// Returns 0 if last command is still executing
+// 1 if success
+// >1 if error
+int GSM3ShieldV1BaseProvider::ready()
+{
+ theGSM3ShieldV1ModemCore.manageReceivedData();
+
+ return theGSM3ShieldV1ModemCore.getCommandError();
+};
+
+void GSM3ShieldV1BaseProvider::prepareAuxLocate(PROGMEM prog_char str[], char auxLocate[])
+{
+ int i=0;
+ char c;
+
+ do
+ {
+ c=pgm_read_byte_near(str + i);
+ auxLocate[i]=c;
+ i++;
+ } while (c!=0);
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BaseProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BaseProvider.h
new file mode 100644
index 00000000..802d46cb
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1BaseProvider.h
@@ -0,0 +1,73 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SHIELDV1BASEPROVIDER_
+#define _GSM3SHIELDV1BASEPROVIDER_
+
+#include
+
+enum GSM3_commandType_e { XON, NONE, MODEMCONFIG, ALIVETEST, BEGINSMS, ENDSMS, AVAILABLESMS, FLUSHSMS,
+ VOICECALL, ANSWERCALL, HANGCALL, RETRIEVECALLINGNUMBER,
+ ATTACHGPRS, DETACHGPRS, CONNECTTCPCLIENT, DISCONNECTTCP, BEGINWRITESOCKET, ENDWRITESOCKET,
+ AVAILABLESOCKET, FLUSHSOCKET, CONNECTSERVER, GETIP, GETCONNECTSTATUS, GETLOCATION, GETICCID};
+
+class GSM3ShieldV1BaseProvider
+{
+ public:
+
+ /** Get last command status
+ @return Returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready();
+
+ /** This function locates strings from PROGMEM in the buffer
+ @param str PROGMEN
+ @param auxLocate Buffer where to locate strings
+ */
+ void prepareAuxLocate(PROGMEM prog_char str[], char auxLocate[]);
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ virtual void manageResponse(byte from, byte to);
+
+ /** Recognize URC
+ @param from
+ @return true if successful (default: false)
+ */
+ virtual bool recognizeUnsolicitedEvent(byte from){return false;};
+
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1CellManagement.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1CellManagement.cpp
new file mode 100644
index 00000000..2af91abf
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1CellManagement.cpp
@@ -0,0 +1,168 @@
+#include
+
+GSM3ShieldV1CellManagement::GSM3ShieldV1CellManagement()
+{
+}
+
+bool GSM3ShieldV1CellManagement::parseQCCID_available(bool& rsp)
+{
+ char c;
+ bool iccidFound = false;
+ int i = 0;
+
+ while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 19))
+ {
+ if((c < 58) & (c > 47))
+ iccidFound = true;
+
+ if(iccidFound)
+ {
+ bufferICCID[i] = c;
+ i++;
+ }
+ }
+ bufferICCID[i]=0;
+
+ return true;
+}
+
+bool GSM3ShieldV1CellManagement::parseQENG_available(bool& rsp)
+{
+ char c;
+ char location[50] = "";
+ int i = 0;
+
+ if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG: ", true)))
+ rsp = false;
+ else
+ rsp = true;
+
+ if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG:", true)))
+ rsp = false;
+ else
+ rsp = true;
+
+ while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 50))
+ {
+ location[i] = c;
+ i++;
+ }
+ location[i]=0;
+
+ char* res_tok = strtok(location, ",");
+ res_tok=strtok(NULL, ",");
+ strcpy(countryCode, res_tok);
+ res_tok=strtok(NULL, ",");
+ strcpy(networkCode, res_tok);
+ res_tok=strtok(NULL, ",");
+ strcpy(locationArea, res_tok);
+ res_tok=strtok(NULL, ",");
+ strcpy(cellId, res_tok);
+
+ return true;
+}
+
+int GSM3ShieldV1CellManagement::getLocation(char *country, char *network, char *area, char *cell)
+{
+ if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY))
+ return 2;
+
+ countryCode=country;
+ networkCode=network;
+ locationArea=area;
+ cellId=cell;
+
+ theGSM3ShieldV1ModemCore.openCommand(this,GETLOCATION);
+ getLocationContinue();
+
+ unsigned long timeOut = millis();
+ while(((millis() - timeOut) < 5000) & (ready() == 0));
+
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+void GSM3ShieldV1CellManagement::getLocationContinue()
+{
+ bool resp;
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.gss.tunedDelay(3000);
+ delay(3000);
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG=1"), false);
+ theGSM3ShieldV1ModemCore.print("\r");
+ break;
+ case 2:
+ if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ theGSM3ShieldV1ModemCore.gss.tunedDelay(3000);
+ delay(3000);
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG?"), false);
+ theGSM3ShieldV1ModemCore.print("\r");
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(1);
+ break;
+ case 3:
+ if (resp)
+ {
+ parseQENG_available(resp);
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(2);
+ break;
+ }
+}
+
+int GSM3ShieldV1CellManagement::getICCID(char *iccid)
+{
+ if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY))
+ return 2;
+
+ bufferICCID=iccid;
+ theGSM3ShieldV1ModemCore.openCommand(this,GETICCID);
+ getICCIDContinue();
+
+ unsigned long timeOut = millis();
+ while(((millis() - timeOut) < 5000) & (ready() == 0));
+
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+void GSM3ShieldV1CellManagement::getICCIDContinue()
+{
+ bool resp;
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QCCID"), false);
+ theGSM3ShieldV1ModemCore.print("\r");
+ break;
+ case 2:
+ if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ parseQCCID_available(resp);
+ theGSM3ShieldV1ModemCore.closeCommand(2);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(1);
+ break;
+ }
+}
+
+void GSM3ShieldV1CellManagement::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+ case GETLOCATION:
+ getLocationContinue();
+ break;
+ case GETICCID:
+ getICCIDContinue();
+ break;
+ }
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1CellManagement.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1CellManagement.h
new file mode 100644
index 00000000..78307da3
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1CellManagement.h
@@ -0,0 +1,92 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_SHIELDV1CELLMANAGEMENT__
+#define __GSM3_SHIELDV1CELLMANAGEMENT__
+
+#include
+#include
+#include
+
+class GSM3ShieldV1CellManagement : public GSM3MobileCellManagement, public GSM3ShieldV1BaseProvider
+{
+ public:
+
+ /** Constructor
+ */
+ GSM3ShieldV1CellManagement();
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ /** getLocation
+ @return current cell location
+ */
+ int getLocation(char *country, char *network, char *area, char *cell);
+
+ /** getICCID
+ */
+ int getICCID(char *iccid);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ private:
+
+ char *countryCode;
+ char *networkCode;
+ char *locationArea;
+ char *cellId;
+
+ char *bufferICCID;
+
+ /** Continue to getLocation function
+ */
+ void getLocationContinue();
+
+ /** Continue to getICCID function
+ */
+ void getICCIDContinue();
+
+ bool parseQENG_available(bool& rsp);
+
+ bool parseQCCID_available(bool& rsp);
+
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ClientProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ClientProvider.cpp
new file mode 100644
index 00000000..92d3e857
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ClientProvider.cpp
@@ -0,0 +1,294 @@
+#include
+#include
+
+GSM3ShieldV1ClientProvider::GSM3ShieldV1ClientProvider()
+{
+ theGSM3MobileClientProvider=this;
+};
+
+//Response management.
+void GSM3ShieldV1ClientProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+ case CONNECTTCPCLIENT:
+ connectTCPClientContinue();
+ break;
+ case FLUSHSOCKET:
+ flushSocketContinue();
+ break;
+ }
+}
+
+//Connect TCP main function.
+int GSM3ShieldV1ClientProvider::connectTCPClient(const char* server, int port, int id_socket)
+{
+ theGSM3ShieldV1ModemCore.setPort(port);
+ idSocket = id_socket;
+
+ theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server);
+ theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT);
+ theGSM3ShieldV1ModemCore.registerUMProvider(this);
+ connectTCPClientContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+int GSM3ShieldV1ClientProvider::connectTCPClient(IPAddress add, int port, int id_socket)
+{
+ remoteIP=add;
+ theGSM3ShieldV1ModemCore.setPhoneNumber(0);
+ return connectTCPClient(0, port, id_socket);
+}
+
+//Connect TCP continue function.
+void GSM3ShieldV1ClientProvider::connectTCPClientContinue()
+{
+ bool resp;
+ // 0: Dot or DNS notation activation
+ // 1: Disable SW flow control
+ // 2: Waiting for IFC OK
+ // 3: Start-up TCP connection "AT+QIOPEN"
+ // 4: Wait for connection OK
+ // 5: Wait for CONNECT
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false);
+ if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&&
+ ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9'))))
+ {
+ theGSM3ShieldV1ModemCore.print('1');
+ theGSM3ShieldV1ModemCore.print('\r');
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.print('0');
+ theGSM3ShieldV1ModemCore.print('\r');
+ }
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ //Response received
+ if(resp)
+ {
+ // AT+QIOPEN
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false);
+ theGSM3ShieldV1ModemCore.print("\"TCP\",\"");
+ if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)
+ {
+ theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber());
+ }
+ else
+ {
+ remoteIP.printTo(theGSM3ShieldV1ModemCore);
+ }
+ theGSM3ShieldV1ModemCore.print('"');
+ theGSM3ShieldV1ModemCore.print(',');
+ theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort());
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+
+ case 3:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ if(resp)
+ {
+ // OK Received
+ // Great. Go for the next step
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 4:
+ char auxLocate [12];
+ prepareAuxLocate(PSTR("CONNECT\r\n"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate))
+ {
+ // Response received
+ if(resp)
+ {
+ // Received CONNECT OK
+ // Great. We're done
+ theGSM3ShieldV1ModemCore.setStatus(TRANSPARENT_CONNECTED);
+ theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, true);
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+
+ }
+}
+
+//Disconnect TCP main function.
+int GSM3ShieldV1ClientProvider::disconnectTCP(bool client1Server0, int id_socket)
+{
+ // id Socket does not really mean anything, in this case we have
+ // only one socket running
+ theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP);
+
+ // If we are not closed, launch the command
+//[ZZ] if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED)
+// {
+ delay(1000);
+ theGSM3ShieldV1ModemCore.print("+++");
+ delay(1000);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE"));
+ theGSM3ShieldV1ModemCore.setStatus(GPRS_READY);
+// }
+ // Looks like it runs everytime, so we simply flush to death and go on
+ do
+ {
+ // Empty the local buffer, and tell the modem to XON
+ // If meanwhile we receive a DISCONNECT we should detect it as URC.
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ // Give some time for the buffer to refill
+ delay(100);
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }while(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()>0);
+
+ theGSM3ShieldV1ModemCore.unRegisterUMProvider(this);
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+
+//Write socket first chain main function.
+void GSM3ShieldV1ClientProvider::beginWriteSocket(bool client1Server0, int id_socket)
+{
+}
+
+
+//Write socket next chain function.
+void GSM3ShieldV1ClientProvider::writeSocket(const char* buf)
+{
+ if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED)
+ theGSM3ShieldV1ModemCore.print(buf);
+}
+
+//Write socket character function.
+void GSM3ShieldV1ClientProvider::writeSocket(uint8_t c)
+{
+ if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED)
+ theGSM3ShieldV1ModemCore.print((char)c);
+}
+
+//Write socket last chain main function.
+void GSM3ShieldV1ClientProvider::endWriteSocket()
+{
+}
+
+
+//Available socket main function.
+int GSM3ShieldV1ClientProvider::availableSocket(bool client1Server0, int id_socket)
+{
+
+ if(!(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED))
+ theGSM3ShieldV1ModemCore.closeCommand(4);
+
+ if(theGSM3ShieldV1ModemCore.theBuffer().storedBytes())
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(4);
+
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+int GSM3ShieldV1ClientProvider::readSocket()
+{
+ char charSocket;
+
+ if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0)
+ {
+ return 0;
+ }
+
+ charSocket = theGSM3ShieldV1ModemCore.theBuffer().read();
+
+ if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==100)
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+
+ return charSocket;
+
+}
+
+//Read socket main function.
+int GSM3ShieldV1ClientProvider::peekSocket()
+{
+ return theGSM3ShieldV1ModemCore.theBuffer().peek(0);
+}
+
+
+//Flush SMS main function.
+void GSM3ShieldV1ClientProvider::flushSocket()
+{
+ theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET);
+
+ flushSocketContinue();
+}
+
+//Send SMS continue function.
+void GSM3ShieldV1ClientProvider::flushSocketContinue()
+{
+ // If we have incomed data
+ if(theGSM3ShieldV1ModemCore.theBuffer().storedBytes()>0)
+ {
+ // Empty the local buffer, and tell the modem to XON
+ // If meanwhile we receive a DISCONNECT we should detect it as URC.
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ }
+ else
+ {
+ //We're done
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+}
+
+// URC recognize.
+// Yes, we recognize "closes" in client mode
+bool GSM3ShieldV1ClientProvider::recognizeUnsolicitedEvent(byte oldTail)
+{
+ char auxLocate [12];
+ prepareAuxLocate(PSTR("CLOSED"), auxLocate);
+
+ if((theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED) & theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, false, false))
+ {
+ theGSM3ShieldV1ModemCore.setStatus(GPRS_READY);
+ theGSM3ShieldV1ModemCore.unRegisterUMProvider(this);
+ return true;
+ }
+
+ return false;
+}
+
+int GSM3ShieldV1ClientProvider::getSocket(int socket)
+{
+ return 0;
+}
+
+void GSM3ShieldV1ClientProvider::releaseSocket(int socket)
+{
+
+}
+
+bool GSM3ShieldV1ClientProvider::getStatusSocketClient(uint8_t socket)
+{
+ return (theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED);
+
+};
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ClientProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ClientProvider.h
new file mode 100644
index 00000000..fa2f8b58
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ClientProvider.h
@@ -0,0 +1,181 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_SHIELDV1CLIENTPROVIDER__
+#define __GSM3_SHIELDV1CLIENTPROVIDER__
+
+#include
+#include
+
+class GSM3ShieldV1ClientProvider : public GSM3MobileClientProvider, public GSM3ShieldV1BaseProvider
+{
+ private:
+
+ int remotePort; //Current operation remote port.
+ IPAddress remoteIP; // Remote IP address
+ int idSocket; // Remote ID socket.
+
+
+ /** Continue to connect TCP client function
+ */
+ void connectTCPClientContinue();
+
+ /** Continue to available socket function
+ */
+ void availableSocketContinue();
+
+ /** Continue to flush socket function
+ */
+ void flushSocketContinue();
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1ClientProvider();
+
+ /** minSocket
+ @return 0
+ */
+ int minSocket(){return 0;};
+
+ /** maxSocket
+ @return 0
+ */
+ int maxSocket(){return 0;};
+
+ /** Connect to a remote TCP server
+ @param server String with IP or server name
+ @param port Remote port number
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int connectTCPClient(const char* server, int port, int id_socket);
+
+ /** Connect to a remote TCP server
+ @param add Remote IP address
+ @param port Remote port number
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int connectTCPClient(IPAddress add, int port, int id_socket);
+
+ /** Begin writing through a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ void beginWriteSocket(bool client1Server0, int id_socket);
+
+ /** Write through a socket. MUST go after beginWriteSocket()
+ @param buf characters to be written (final 0 will not be written)
+ */
+ void writeSocket(const char* buf);
+
+ /** Write through a socket. MUST go after beginWriteSocket()
+ @param c character to be written
+ */
+ void writeSocket(uint8_t c);
+
+ /** Finish current writing
+ */
+ void endWriteSocket();
+
+ /** Check if there are data to be read in socket.
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
+ */
+ int availableSocket(bool client, int id_socket); // With "available" and "readSocket" ask the modem for 1500 bytes.
+
+ /** Read data (get a character) available in socket
+ @return character
+ */
+ int readSocket(); //If Read() gets to the end of the QIRD response, execute again QIRD SYNCHRONOUSLY
+
+ /** Flush socket
+ */
+ void flushSocket();
+
+ /** Get a character but will not advance the buffer head
+ @return character
+ */
+ int peekSocket();
+
+ /** Close a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Socket
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int disconnectTCP(bool client1Server0, int id_socket);
+
+ /** Recognize unsolicited event
+ @param oldTail
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte from);
+
+ /** Manages modem response
+ @param from Initial byte position
+ @param to Final byte position
+ */
+ void manageResponse(byte from, byte to);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ // Client socket management, just to be compatible
+ // with the Multi option
+
+ /** Get socket
+ @param socket Socket
+ @return socket
+ */
+ int getSocket(int socket=-1);
+
+ /** Release socket
+ @param socket Socket
+ */
+ void releaseSocket(int socket);
+
+ /** Get socket client status
+ @param socket Socket
+ @return 1 if connected, 0 otherwise
+ */
+ bool getStatusSocketClient(uint8_t socket);
+
+};
+
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DataNetworkProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DataNetworkProvider.cpp
new file mode 100644
index 00000000..aaffdba6
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DataNetworkProvider.cpp
@@ -0,0 +1,363 @@
+#include
+#include
+
+char _command_CGATT[] PROGMEM = "AT+CGATT=";
+char _command_SEPARATOR[] PROGMEM = "\",\"";
+
+//Attach GPRS main function.
+GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::attachGPRS(char* apn, char* user_name, char* password, bool synchronous)
+{
+ user = user_name;
+ passwd = password;
+ // A sad use of byte reuse
+ theGSM3ShieldV1ModemCore.setPhoneNumber(apn);
+
+ theGSM3ShieldV1ModemCore.openCommand(this,ATTACHGPRS);
+ theGSM3ShieldV1ModemCore.setStatus(CONNECTING);
+
+ attachGPRSContinue();
+
+ // If synchronous, wait till attach is over, or not.
+ if(synchronous)
+ {
+ // if we shorten this delay, the command fails
+ while(ready()==0)
+ delay(100);
+ }
+
+ return theGSM3ShieldV1ModemCore.getStatus();
+}
+
+//Atthach GPRS continue function.
+void GSM3ShieldV1DataNetworkProvider::attachGPRSContinue()
+{
+ bool resp;
+ // 1: Attach to GPRS service "AT+CGATT=1"
+ // 2: Wait attach OK and Set the context 0 as FGCNT "AT+QIFGCNT=0"
+ // 3: Wait context OK and Set bearer type as GPRS, APN, user name and pasword "AT+QICSGP=1..."
+ // 4: Wait bearer OK and Enable the function of MUXIP "AT+QIMUX=1"
+ // 5: Wait for disable MUXIP OK and Set the session mode as non transparent "AT+QIMODE=0"
+ // 6: Wait for session mode OK and Enable notification when data received "AT+QINDI=1"
+ // 8: Wait domain name OK and Register the TCP/IP stack "AT+QIREGAPP"
+ // 9: Wait for Register OK and Activate FGCNT "AT+QIACT"
+ // 10: Wait for activate OK
+
+ int ct=theGSM3ShieldV1ModemCore.getCommandCounter();
+ if(ct==1)
+ {
+ //AT+CGATT
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGATT,false);
+ theGSM3ShieldV1ModemCore.print(1);
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ }
+ else if(ct==2)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ //AT+QIFGCNT
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIFGCNT=0"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==3)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ // Great. Go for the next step
+ //DEBUG
+ //Serial.println("AT+QICSGP.");
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICSGP=1,\""),false);
+ theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber());
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_SEPARATOR,false);
+ theGSM3ShieldV1ModemCore.print(user);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_SEPARATOR,false);
+ theGSM3ShieldV1ModemCore.print(passwd);
+ theGSM3ShieldV1ModemCore.print("\"\r");
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==4)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ // AT+QIMUX=1 for multisocket
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIMUX=0"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(5);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==5)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ //AT+QIMODE=0 for multisocket
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIMODE=1"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(6);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==6)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ // AT+QINDI=1
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QINDI=1"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(8);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==8)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ // AT+QIREGAPP
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIREGAPP"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(9);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==9)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if(resp)
+ {
+ // AT+QIACT
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIACT"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(10);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ else if(ct==10)
+ {
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if (resp)
+ {
+ theGSM3ShieldV1ModemCore.setStatus(GPRS_READY);
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+}
+
+//Detach GPRS main function.
+GSM3_NetworkStatus_t GSM3ShieldV1DataNetworkProvider::detachGPRS(bool synchronous)
+{
+ theGSM3ShieldV1ModemCore.openCommand(this,DETACHGPRS);
+ theGSM3ShieldV1ModemCore.setStatus(CONNECTING);
+ detachGPRSContinue();
+
+ if(synchronous)
+ {
+ while(ready()==0)
+ delay(1);
+ }
+
+ return theGSM3ShieldV1ModemCore.getStatus();
+}
+
+void GSM3ShieldV1DataNetworkProvider::detachGPRSContinue()
+{
+ bool resp;
+ // 1: Detach to GPRS service "AT+CGATT=0"
+ // 2: Wait dettach +PDP DEACT
+ // 3: Wait for OK
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //AT+CGATT=0
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_CGATT,false);
+ theGSM3ShieldV1ModemCore.print(0);
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ char auxLocate[12];
+ prepareAuxLocate(PSTR("+PDP DEACT"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
+ {
+ if(resp)
+ {
+ // Received +PDP DEACT;
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 3:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // OK received
+ if (resp)
+ {
+ theGSM3ShieldV1ModemCore.setStatus(GSM_READY);
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//QILOCIP parse.
+bool GSM3ShieldV1DataNetworkProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp)
+{
+ if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength)))
+ rsp = false;
+ else
+ rsp = true;
+ return true;
+}
+
+//Get IP main function.
+int GSM3ShieldV1DataNetworkProvider::getIP(char* LocalIP, int LocalIPlength)
+{
+ theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP);
+ theGSM3ShieldV1ModemCore.setPort(LocalIPlength);
+ theGSM3ShieldV1ModemCore.openCommand(this,GETIP);
+ getIPContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+void GSM3ShieldV1DataNetworkProvider::getIPContinue()
+{
+
+ bool resp;
+ // 1: Read Local IP "AT+QILOCIP"
+ // 2: Waiting for IP.
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //AT+QILOCIP
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILOCIP"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp))
+ {
+ if (resp)
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ break;
+ }
+}
+
+//Get IP with IPAddress object
+IPAddress GSM3ShieldV1DataNetworkProvider::getIPAddress() {
+ char ip_temp[15]="";
+ getIP(ip_temp, 15);
+ unsigned long m=millis();
+
+ while((millis()-m)<10*1000 && (!ready())){
+ // wait for a response from the modem:
+ delay(100);
+ }
+ IPAddress ip;
+ inet_aton(ip_temp, ip);
+ return ip;
+}
+
+int GSM3ShieldV1DataNetworkProvider::inet_aton(const char* aIPAddrString, IPAddress& aResult)
+{
+ // See if we've been given a valid IP address
+ const char* p =aIPAddrString;
+ while (*p &&
+ ( (*p == '.') || (*p >= '0') || (*p <= '9') ))
+ {
+ p++;
+ }
+
+ if (*p == '\0')
+ {
+ // It's looking promising, we haven't found any invalid characters
+ p = aIPAddrString;
+ int segment =0;
+ int segmentValue =0;
+ while (*p && (segment < 4))
+ {
+ if (*p == '.')
+ {
+ // We've reached the end of a segment
+ if (segmentValue > 255)
+ {
+ // You can't have IP address segments that don't fit in a byte
+ return 0;
+ }
+ else
+ {
+ aResult[segment] = (byte)segmentValue;
+ segment++;
+ segmentValue = 0;
+ }
+ }
+ else
+ {
+ // Next digit
+ segmentValue = (segmentValue*10)+(*p - '0');
+ }
+ p++;
+ }
+ // We've reached the end of address, but there'll still be the last
+ // segment to deal with
+ if ((segmentValue > 255) || (segment > 3))
+ {
+ // You can't have IP address segments that don't fit in a byte,
+ // or more than four segments
+ return 0;
+ }
+ else
+ {
+ aResult[segment] = (byte)segmentValue;
+ return 1;
+ }
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+//Response management.
+void GSM3ShieldV1DataNetworkProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case ATTACHGPRS:
+ attachGPRSContinue();
+ break;
+ case DETACHGPRS:
+ detachGPRSContinue();
+ break;
+ case GETIP:
+ getIPContinue();
+ break;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DataNetworkProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DataNetworkProvider.h
new file mode 100644
index 00000000..012a0ca5
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DataNetworkProvider.h
@@ -0,0 +1,140 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SHIELDV1DATANETWORKPROVIDER_
+#define _GSM3SHIELDV1DATANETWORKPROVIDER_
+
+#include
+#include
+#include
+#include
+
+class GSM3ShieldV1DataNetworkProvider : public GSM3MobileDataNetworkProvider, public GSM3ShieldV1BaseProvider
+{
+ private:
+
+ char* user; // Username for GPRS
+ char* passwd; // Password for GPRS
+
+ /** Continue to attach GPRS function
+ */
+ void attachGPRSContinue();
+
+ /** Continue to detach GPRS function
+ */
+ void detachGPRSContinue();
+
+ /** Parse QILOCIP response
+ @param LocalIP Buffer for save local IP address
+ @param LocalIPlength Buffer size
+ @param rsp Returns true if expected response exists
+ @return true if command executed correctly
+ */
+ bool parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp);
+
+ /** Continue to get IP function
+ */
+ void getIPContinue();
+
+ /** Implementation of inet_aton standard function
+ @param aIPAddrString IP address in characters buffer
+ @param aResult IP address in IPAddress format
+ @return 1 if the address is successfully converted, or 0 if the conversion failed
+ */
+ int inet_aton(const char* aIPAddrString, IPAddress& aResult);
+
+ public:
+
+ /** Attach to GPRS/GSM network
+ @param networkId APN GPRS
+ @param user Username
+ @param pass Password
+ @return connection status
+ */
+ GSM3_NetworkStatus_t networkAttach(char* networkId, char* user, char* pass)
+ {
+ return attachGPRS(networkId, user, pass);
+ };
+
+ /** Detach GPRS/GSM network
+ @return connection status
+ */
+ GSM3_NetworkStatus_t networkDetach(){ return detachGPRS();};
+
+ /** Attach to GPRS service
+ @param apn APN GPRS
+ @param user_name Username
+ @param password Password
+ @param synchronous Sync mode
+ @return connection status
+ */
+ GSM3_NetworkStatus_t attachGPRS(char* apn, char* user_name, char* password, bool synchronous=true);
+
+ /** Detach GPRS service
+ @param synchronous Sync mode
+ @return connection status
+ */
+ GSM3_NetworkStatus_t detachGPRS(bool synchronous=true);
+
+ /** Returns 0 if last command is still executing
+ @return 1 if success, >1 if error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Get network status (connection)
+ @return status
+ */
+ inline GSM3_NetworkStatus_t getStatus(){return theGSM3ShieldV1ModemCore.getStatus();};
+
+ /** Get actual assigned IP address
+ @param LocalIP Buffer for copy IP address
+ @param LocalIPlength Buffer length
+ @return command error if exists
+ */
+ int getIP(char* LocalIP, int LocalIPlength);
+
+ /** Get actual assigned IP address in IPAddress format
+ @return IP address in IPAddress format
+ */
+ IPAddress getIPAddress();
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DirectModemProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DirectModemProvider.cpp
new file mode 100644
index 00000000..47aa52b0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DirectModemProvider.cpp
@@ -0,0 +1,143 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+#include
+#include
+
+#define __RESETPIN__ 7
+
+//Constructor
+GSM3ShieldV1DirectModemProvider::GSM3ShieldV1DirectModemProvider(bool t)
+{
+ trace=t;
+};
+
+void GSM3ShieldV1DirectModemProvider::begin()
+{
+ theGSM3ShieldV1ModemCore.gss.begin(9600);
+}
+
+void GSM3ShieldV1DirectModemProvider::restartModem()
+{
+ pinMode(__RESETPIN__, OUTPUT);
+ digitalWrite(__RESETPIN__, HIGH);
+ delay(12000);
+ digitalWrite(__RESETPIN__, LOW);
+ delay(1000);
+
+}
+
+//To enable the debug process
+void GSM3ShieldV1DirectModemProvider::connect()
+{
+ theGSM3ShieldV1ModemCore.registerActiveProvider(this);
+}
+
+//To disable the debug process
+void GSM3ShieldV1DirectModemProvider::disconnect()
+{
+ theGSM3ShieldV1ModemCore.registerActiveProvider(0);
+}
+
+//Write to the modem by means of SoftSerial
+size_t GSM3ShieldV1DirectModemProvider::write(uint8_t c)
+{
+ theGSM3ShieldV1ModemCore.write(c);
+}
+
+//Detect if data to be read
+int/*bool*/ GSM3ShieldV1DirectModemProvider::available()
+{
+ if (theGSM3ShieldV1ModemCore.gss.cb.peek(1)) return 1;
+ else return 0;
+}
+
+//Read data
+int/*char*/ GSM3ShieldV1DirectModemProvider::read()
+{
+ int dataRead;
+ dataRead = theGSM3ShieldV1ModemCore.gss.cb.read();
+ //In case last char in xof mode.
+ if (!(theGSM3ShieldV1ModemCore.gss.cb.peek(0))) {
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ delay(100);
+ }
+ return dataRead;
+}
+
+//Peek data
+int/*char*/ GSM3ShieldV1DirectModemProvider::peek()
+{
+ return theGSM3ShieldV1ModemCore.gss.cb.peek(0);
+}
+
+//Flush data
+void GSM3ShieldV1DirectModemProvider::flush()
+{
+ return theGSM3ShieldV1ModemCore.gss.cb.flush();
+}
+
+String GSM3ShieldV1DirectModemProvider::writeModemCommand(String ATcommand, int responseDelay)
+{
+
+ if(trace)
+ Serial.println(ATcommand);
+
+ // Flush other texts
+ flush();
+
+ //Enter debug mode.
+ connect();
+ //Send the AT command.
+ println(ATcommand);
+
+ delay(responseDelay);
+
+ //Get response data from modem.
+ String result = "";
+ if(trace)
+ theGSM3ShieldV1ModemCore.gss.cb.debugBuffer();
+
+ while (available())
+ {
+ char c = read();
+ result += c;
+ }
+ if(trace)
+ Serial.println(result);
+ //Leave the debug mode.
+ disconnect();
+ return result;
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DirectModemProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DirectModemProvider.h
new file mode 100644
index 00000000..2d20412b
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1DirectModemProvider.h
@@ -0,0 +1,118 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+
+#ifndef __GSM3DIRECTMODEMPROVIDER__
+#define __GSM3DIRECTMODEMPROVIDER__
+
+#include
+#include
+#include
+#include
+#include
+
+class GSM3ShieldV1DirectModemProvider : public GSM3ShieldV1BaseProvider, public Stream
+{
+ private:
+
+ bool trace;
+
+ public:
+
+ /** Constructor
+ @param trace if true, dumps all AT dialogue to Serial
+ */
+ GSM3ShieldV1DirectModemProvider(bool trace=false);
+
+ /**
+ */
+ void begin();
+
+ /**
+ */
+ void restartModem();
+
+ /** Enable the debug process.
+ */
+ void connect();
+
+ /** Disable the debug process.
+ */
+ void disconnect();
+
+ /** Debug write to modem by means of SoftSerial.
+ @param c Character
+ @return size
+ */
+ size_t write(uint8_t c);
+
+ /** Check for incoming bytes in buffer
+ @return
+ */
+ int available();
+
+ /** Read from circular buffer
+ @return character
+ */
+ int read();
+
+ /** Read from circular buffer, but do not delete it
+ @return character
+ */
+ int peek();
+
+ /** Empty circular buffer
+ */
+ void flush();
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to){};
+
+ /** Recognize unsolicited event
+ @param from
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte from){return false;};
+
+ /** Send AT command to modem
+ @param command AT command
+ @param delay Time to wait for response
+ @return response from modem
+ */
+ String writeModemCommand(String command, int delay);
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemCore.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemCore.cpp
new file mode 100644
index 00000000..c90ff4dd
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemCore.cpp
@@ -0,0 +1,198 @@
+#include
+#include
+
+GSM3ShieldV1ModemCore theGSM3ShieldV1ModemCore;
+
+char* __ok__="OK";
+
+GSM3ShieldV1ModemCore::GSM3ShieldV1ModemCore() : gss()
+{
+ gss.registerMgr(this);
+ _dataInBufferFrom=0;
+ _dataInBufferTo=0;
+ commandError=1;
+ commandCounter=0;
+ ongoingCommand=NONE;
+ takeMilliseconds();
+
+ for(int i=0;irecognizeUnsolicitedEvent(from);
+ }
+ if((!recognized)&&(activeProvider))
+ activeProvider->manageResponse(from, to);
+}
+
+
+void GSM3ShieldV1ModemCore::openCommand(GSM3ShieldV1BaseProvider* provider, GSM3_commandType_e c)
+{
+ activeProvider=provider;
+ commandError=0;
+ commandCounter=1;
+ ongoingCommand=c;
+ _dataInBufferFrom=0;
+ _dataInBufferTo=0;
+
+};
+
+size_t GSM3ShieldV1ModemCore::writePGM(PROGMEM prog_char str[], bool CR)
+{
+ int i=0;
+ char c;
+
+ do
+ {
+ c=pgm_read_byte_near(str + i);
+ if(c!=0)
+ write(c);
+ i++;
+ } while (c!=0);
+ if(CR)
+ print("\r");
+
+ return 1;
+}
+
+size_t GSM3ShieldV1ModemCore::write(uint8_t c)
+{
+ if(_debug)
+ GSM3CircularBuffer::printCharDebug(c);
+ return gss.write(c);
+}
+
+unsigned long GSM3ShieldV1ModemCore::takeMilliseconds()
+{
+ unsigned long now=millis();
+ unsigned long delta;
+ delta=now-milliseconds;
+ milliseconds=now;
+ return delta;
+}
+
+void GSM3ShieldV1ModemCore::delayInsideInterrupt(unsigned long milliseconds)
+{
+ for (unsigned long k=0;k
+#include
+#include
+#include
+
+#define UMPROVIDERS 3
+
+class GSM3ShieldV1ModemCore : public GSM3SoftSerialMgr, public Print
+{
+ private:
+
+ // Phone number, used when calling, sending SMS and reading calling numbers
+ // Also PIN in modem configuration
+ // Also APN
+ // Also remote server
+ char* phoneNumber;
+
+ // Working port. Port used in the ongoing command, while opening a server
+ // Also for IP address length
+ int port;
+
+ // 0 = ongoing
+ // 1 = OK
+ // 2 = Error. Incorrect state
+ // 3 = Unexpected modem message
+ // 4 = OK but not available data.
+ uint8_t commandError;
+
+ // Counts the steps by the command
+ uint8_t commandCounter;
+
+ // Presently ongoing command
+ GSM3_commandType_e ongoingCommand;
+
+ // Enable/disable debug
+ bool _debug;
+ byte _dataInBufferFrom;
+ byte _dataInBufferTo;
+
+ // This is the modem (known) status
+ GSM3_NetworkStatus_t _status;
+
+ GSM3ShieldV1BaseProvider* UMProvider[UMPROVIDERS];
+ GSM3ShieldV1BaseProvider* activeProvider;
+
+ // Private function for anage message
+ void manageMsgNow(byte from, byte to);
+
+ unsigned long milliseconds;
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1ModemCore();
+
+ GSM3SoftSerial gss; // Direct access to modem
+
+ /** Get phone number
+ @return phone number
+ */
+ char *getPhoneNumber(){return phoneNumber;};
+
+ /** Establish a new phone number
+ @param n Phone number
+ */
+ void setPhoneNumber(char *n){phoneNumber=n;};
+
+ /** Get port used
+ @return port
+ */
+ int getPort(){return port;};
+
+ /** Establish a new port for use
+ @param p Port
+ */
+ void setPort(int p){port=p;};
+
+ /** Get command error
+ @return command error
+ */
+ uint8_t getCommandError(){return commandError;};
+
+ /** Establish a command error
+ @param n Command error
+ */
+ void setCommandError(uint8_t n){commandError=n;};
+
+ /** Get command counter
+ @return command counter
+ */
+ uint8_t getCommandCounter(){return commandCounter;};
+
+ /** Set command counter
+ @param c Initial value
+ */
+ void setCommandCounter(uint8_t c){commandCounter=c;};
+
+ /** Get ongoing command
+ @return command
+ */
+ GSM3_commandType_e getOngoingCommand(){return ongoingCommand;};
+
+ /** Set ongoing command
+ @param c New ongoing command
+ */
+ void setOngoingCommand(GSM3_commandType_e c){ongoingCommand=c;};
+
+ /** Open command
+ @param activeProvider Active provider
+ @param c Command for open
+ */
+ void openCommand(GSM3ShieldV1BaseProvider* activeProvider, GSM3_commandType_e c);
+
+ /** Close command
+ @param code Close code
+ */
+ void closeCommand(int code);
+
+ // These functions allow writing to the SoftwareSerial
+ // If debug is set, dump to the console
+
+ /** Write a character in serial
+ @param c Character
+ @return size
+ */
+ size_t write(uint8_t c);
+
+ /** Write PGM
+ @param str Buffer for write
+ @param CR Carriadge return adding automatically
+ @return size
+ */
+ virtual size_t writePGM(PROGMEM prog_char str[], bool CR=true);
+
+ /** Establish debug mode
+ @param db Boolean that indicates debug on or off
+ */
+ void setDebug(bool db){_debug=db;};
+
+ /** Generic response parser
+ @param rsp Returns true if expected response exists
+ @param string Substring expected in response
+ @param string2 Second substring expected in response
+ @return true if parsed correctly
+ */
+ bool genericParse_rsp(bool& rsp, char* string=0, char* string2=0);
+
+ /** Generates a generic AT command request from PROGMEM prog_char buffer
+ @param str Buffer with AT command
+ @param addCR Carriadge return adding automatically
+ */
+ void genericCommand_rq(PROGMEM prog_char str[], bool addCR=true);
+
+ /** Generates a generic AT command request from a simple char buffer
+ @param str Buffer with AT command
+ @param addCR Carriadge return adding automatically
+ */
+ void genericCommand_rqc(const char* str, bool addCR=true);
+
+ /** Generates a generic AT command request from characters buffer
+ @param str Buffer with AT command
+ @param addCR Carriadge return adding automatically
+ */
+ void genericCommand_rq(const char* str, bool addCR=true);
+
+ /** Returns the circular buffer
+ @return circular buffer
+ */
+ inline GSM3CircularBuffer& theBuffer(){return gss.cb;};
+
+ /** Establish a new network status
+ @param status Network status
+ */
+ inline void setStatus(GSM3_NetworkStatus_t status) { _status = status; };
+
+ /** Returns actual network status
+ @return network status
+ */
+ inline GSM3_NetworkStatus_t getStatus() { return _status; };
+
+ /** Register provider as willing to receive unsolicited messages
+ @param provider Pointer to provider able to receive unsolicited messages
+ */
+ void registerUMProvider(GSM3ShieldV1BaseProvider* provider);
+
+ /** unegister provider as willing to receive unsolicited messages
+ @param provider Pointer to provider able to receive unsolicited messages
+ */
+ void unRegisterUMProvider(GSM3ShieldV1BaseProvider* provider);
+
+
+ /** Register a provider as "dialoguing" talking in facto with the modem
+ @param provider Pointer to provider receiving responses
+ */
+ void registerActiveProvider(GSM3ShieldV1BaseProvider* provider){activeProvider=provider;};
+
+ /** Needed to manage the SoftSerial. Receives the call when received data
+ If _debugging, no code is called
+ @param from Starting byte to read
+ @param to Last byte to read
+ */
+ void manageMsg(byte from, byte to);
+
+ /** If _debugging, this call is assumed to be made out of interrupts
+ Prints incoming info and calls manageMsgNow
+ */
+ void manageReceivedData();
+
+ /** Chronometer. Measure milliseconds from last call
+ @return milliseconds from las time function was called
+ */
+ unsigned long takeMilliseconds();
+
+ /** Delay for interrupts
+ @param milliseconds Delay time in milliseconds
+ */
+ void delayInsideInterrupt(unsigned long milliseconds);
+
+};
+
+extern GSM3ShieldV1ModemCore theGSM3ShieldV1ModemCore;
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemVerification.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemVerification.cpp
new file mode 100644
index 00000000..e5d190fb
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemVerification.cpp
@@ -0,0 +1,79 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+
+#include
+
+// constructor
+GSM3ShieldV1ModemVerification::GSM3ShieldV1ModemVerification()
+{
+};
+
+// reset the modem for direct access
+int GSM3ShieldV1ModemVerification::begin()
+{
+ int result=0;
+ String modemResponse;
+
+ // check modem response
+ modemAccess.begin();
+
+ // reset hardware
+ modemAccess.restartModem();
+
+ modemResponse=modemAccess.writeModemCommand("AT", 1000);
+ if(modemResponse.indexOf("OK")>=0)
+ result=1;
+ modemResponse=modemAccess.writeModemCommand("ATE0", 1000);
+ return result;
+}
+
+// get IMEI
+String GSM3ShieldV1ModemVerification::getIMEI()
+{
+ String number;
+ // AT command for obtain IMEI
+ String modemResponse = modemAccess.writeModemCommand("AT+GSN", 2000);
+ // Parse and check response
+ char res_to_compare[modemResponse.length()];
+ modemResponse.toCharArray(res_to_compare, modemResponse.length());
+ if(strstr(res_to_compare,"OK") == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ number = modemResponse.substring(1, 17);
+ return number;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemVerification.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemVerification.h
new file mode 100644
index 00000000..e03980e0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ModemVerification.h
@@ -0,0 +1,64 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SHIELDV1MODEMVERIFICATION_
+#define _GSM3SHIELDV1MODEMVERIFICATION_
+
+#include
+#include
+
+class GSM3ShieldV1ModemVerification
+{
+
+ private:
+
+ GSM3ShieldV1DirectModemProvider modemAccess;
+ GSM3ShieldV1AccessProvider gsm; // Access provider to GSM/GPRS network
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1ModemVerification();
+
+ /** Check modem response and restart it
+ */
+ int begin();
+
+ /** Obtain modem IMEI (command AT)
+ @return modem IMEI number
+ */
+ String getIMEI();
+
+};
+
+#endif;
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1MultiClientProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1MultiClientProvider.cpp
new file mode 100644
index 00000000..797424f0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1MultiClientProvider.cpp
@@ -0,0 +1,583 @@
+#include
+#include
+
+char _command_MultiQISRVC[] PROGMEM = "AT+QISRVC=";
+
+#define __TOUTFLUSH__ 10000
+
+GSM3ShieldV1MultiClientProvider::GSM3ShieldV1MultiClientProvider()
+{
+ theGSM3MobileClientProvider=this;
+ theGSM3ShieldV1ModemCore.registerUMProvider(this);
+};
+
+//Response management.
+void GSM3ShieldV1MultiClientProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case XON:
+ if (flagReadingSocket)
+ {
+// flagReadingSocket = 0;
+ fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
+ }
+ else theGSM3ShieldV1ModemCore.setOngoingCommand(NONE);
+ break;
+ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+ case CONNECTTCPCLIENT:
+ connectTCPClientContinue();
+ break;
+ case DISCONNECTTCP:
+ disconnectTCPContinue();
+ break;
+ case BEGINWRITESOCKET:
+ beginWriteSocketContinue();
+ break;
+ case ENDWRITESOCKET:
+ endWriteSocketContinue();
+ break;
+ case AVAILABLESOCKET:
+ availableSocketContinue();
+ break;
+ case FLUSHSOCKET:
+ fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
+ flushSocketContinue();
+ break;
+ }
+}
+
+//Connect TCP main function.
+int GSM3ShieldV1MultiClientProvider::connectTCPClient(const char* server, int port, int id_socket)
+{
+ theGSM3ShieldV1ModemCore.setPort(port);
+ idSocket = id_socket;
+
+ theGSM3ShieldV1ModemCore.setPhoneNumber((char*)server);
+ theGSM3ShieldV1ModemCore.openCommand(this,CONNECTTCPCLIENT);
+ connectTCPClientContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+int GSM3ShieldV1MultiClientProvider::connectTCPClient(IPAddress add, int port, int id_socket)
+{
+ remoteIP=add;
+ theGSM3ShieldV1ModemCore.setPhoneNumber(0);
+ return connectTCPClient(0, port, id_socket);
+}
+
+//Connect TCP continue function.
+void GSM3ShieldV1MultiClientProvider::connectTCPClientContinue()
+{
+ bool resp;
+ // 0: Dot or DNS notation activation
+ // 1: Disable SW flow control
+ // 2: Waiting for IFC OK
+ // 3: Start-up TCP connection "AT+QIOPEN"
+ // 4: Wait for connection OK
+ // 5: Wait for CONNECT
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIDNSIP="), false);
+ if ((theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)&&
+ ((*(theGSM3ShieldV1ModemCore.getPhoneNumber())<'0')||((*(theGSM3ShieldV1ModemCore.getPhoneNumber())>'9'))))
+ {
+ theGSM3ShieldV1ModemCore.print('1');
+ theGSM3ShieldV1ModemCore.print('\r');
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.print('0');
+ theGSM3ShieldV1ModemCore.print('\r');
+ }
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ //Response received
+ if(resp)
+ {
+ // AT+QIOPEN
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIOPEN="),false);
+ theGSM3ShieldV1ModemCore.print(idSocket);
+ theGSM3ShieldV1ModemCore.print(",\"TCP\",\"");
+ if(theGSM3ShieldV1ModemCore.getPhoneNumber()!=0)
+ {
+ theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber());
+ }
+ else
+ {
+ remoteIP.printTo(theGSM3ShieldV1ModemCore);
+ }
+ theGSM3ShieldV1ModemCore.print('"');
+ theGSM3ShieldV1ModemCore.print(',');
+ theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPort());
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+
+ case 3:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ if(resp)
+ {
+ // OK Received
+ // Great. Go for the next step
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 4:
+ char auxLocate [12];
+ prepareAuxLocate(PSTR("CONNECT OK"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp,auxLocate))
+ {
+ // Response received
+ if(resp)
+ {
+ // Received CONNECT OK
+ // Great. We're done
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+
+ }
+}
+
+//Disconnect TCP main function.
+int GSM3ShieldV1MultiClientProvider::disconnectTCP(bool client1Server0, int id_socket)
+{
+ idSocket = id_socket;
+
+ // First of all, we will flush the socket synchronously
+ unsigned long m;
+ m=millis();
+ flushSocket();
+ while(((millis()-m)< __TOUTFLUSH__ )&&(ready()==0))
+ delay(10);
+
+ // Could not flush the communications... strange
+ if(ready()==0)
+ {
+ theGSM3ShieldV1ModemCore.setCommandError(2);
+ return theGSM3ShieldV1ModemCore.getCommandError();
+ }
+
+ // Set up the command
+ client1_server0 = client1Server0;
+ flagReadingSocket=0;
+ theGSM3ShieldV1ModemCore.openCommand(this,DISCONNECTTCP);
+ disconnectTCPContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Disconnect TCP continue function
+void GSM3ShieldV1MultiClientProvider::disconnectTCPContinue()
+{
+ bool resp;
+ // 1: Send AT+QISRVC
+ // 2: "AT+QICLOSE"
+ // 3: Wait for OK
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false);
+ if (client1_server0) theGSM3ShieldV1ModemCore.print('1');
+ else theGSM3ShieldV1ModemCore.print('2');
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ // Parse response to QISRVC
+ theGSM3ShieldV1ModemCore.genericParse_rsp(resp);
+ if(resp)
+ {
+ // Send QICLOSE command
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QICLOSE="),false);
+ theGSM3ShieldV1ModemCore.print(idSocket);
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ break;
+ case 3:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ theGSM3ShieldV1ModemCore.setCommandCounter(0);
+ if (resp)
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Write socket first chain main function.
+void GSM3ShieldV1MultiClientProvider::beginWriteSocket(bool client1Server0, int id_socket)
+{
+ idSocket = id_socket;
+ client1_server0 = client1Server0;
+ theGSM3ShieldV1ModemCore.openCommand(this,BEGINWRITESOCKET);
+ beginWriteSocketContinue();
+}
+
+//Write socket first chain continue function.
+void GSM3ShieldV1MultiClientProvider::beginWriteSocketContinue()
+{
+ bool resp;
+ // 1: Send AT+QISRVC
+ // 2: Send AT+QISEND
+ // 3: wait for > and Write text
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ // AT+QISRVC
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MultiQISRVC, false);
+ if (client1_server0)
+ theGSM3ShieldV1ModemCore.print('1');
+ else
+ theGSM3ShieldV1ModemCore.print('2');
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ if(resp)
+ {
+ // AT+QISEND
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISEND="), false);
+ theGSM3ShieldV1ModemCore.print(idSocket);
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ break;
+ case 3:
+ char aux[2];
+ aux[0]='>';
+ aux[1]=0;
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux))
+ {
+ if(resp)
+ {
+ // Received ">"
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ }
+ break;
+ }
+}
+
+//Write socket next chain function.
+void GSM3ShieldV1MultiClientProvider::writeSocket(const char* buf)
+{
+ theGSM3ShieldV1ModemCore.print(buf);
+}
+
+//Write socket character function.
+void GSM3ShieldV1MultiClientProvider::writeSocket(char c)
+{
+ theGSM3ShieldV1ModemCore.print(c);
+}
+
+//Write socket last chain main function.
+void GSM3ShieldV1MultiClientProvider::endWriteSocket()
+{
+ theGSM3ShieldV1ModemCore.openCommand(this,ENDWRITESOCKET);
+ endWriteSocketContinue();
+}
+
+//Write socket last chain continue function.
+void GSM3ShieldV1MultiClientProvider::endWriteSocketContinue()
+{
+ bool resp;
+ // 1: Write text (ctrl-Z)
+ // 2: Wait for OK
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.write(26); // Ctrl-Z
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // OK received
+ if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Available socket main function.
+int GSM3ShieldV1MultiClientProvider::availableSocket(bool client1Server0, int id_socket)
+{
+ if(flagReadingSocket==1)
+ {
+ theGSM3ShieldV1ModemCore.setCommandError(1);
+ return 1;
+ }
+ client1_server0 = client1Server0;
+ idSocket = id_socket;
+ theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET);
+ availableSocketContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Available socket continue function.
+void GSM3ShieldV1MultiClientProvider::availableSocketContinue()
+{
+ bool resp;
+ // 1: AT+QIRD
+ // 2: Wait for OK and Next necessary AT+QIRD
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QIRD=0,"),false);
+ if (client1_server0)
+ theGSM3ShieldV1ModemCore.print('1');
+ else
+ theGSM3ShieldV1ModemCore.print('2');
+ theGSM3ShieldV1ModemCore.print(',');
+ theGSM3ShieldV1ModemCore.print(idSocket);
+ theGSM3ShieldV1ModemCore.print(",1500");
+ // theGSM3ShieldV1ModemCore.print(",120");
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(parseQIRD_head(resp))
+ {
+ if (!resp)
+ {
+ theGSM3ShieldV1ModemCore.closeCommand(4);
+ }
+ else
+ {
+ flagReadingSocket=1;
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Read Socket Parse head.
+bool GSM3ShieldV1MultiClientProvider::parseQIRD_head(bool& rsp)
+{
+ char _qird [8];
+ prepareAuxLocate(PSTR("+QIRD:"), _qird);
+ fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(_qird))
+ {
+ theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true);
+ // Saving more memory, reuse _qird
+ _qird[0]='\n';
+ _qird[1]=0;
+ theGSM3ShieldV1ModemCore.theBuffer().chopUntil(_qird, true);
+ rsp = true;
+ return true;
+ }
+ else if(theGSM3ShieldV1ModemCore.theBuffer().locate("OK"))
+ {
+ rsp = false;
+ return true;
+ }
+ else
+ {
+ rsp = false;
+ return false;
+ }
+}
+/*
+//Read socket main function.
+int GSM3ShieldV1MultiClientProvider::readSocket()
+{
+ char charSocket;
+ charSocket = theGSM3ShieldV1ModemCore.theBuffer().read();
+ //Case buffer not full
+ if (!fullBufferSocket)
+ {
+ //The last part of the buffer after data is CRLFOKCRLF
+ if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125)
+ {
+ //Start again availableSocket function.
+ flagReadingSocket=0;
+ theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET);
+ availableSocketContinue();
+ }
+ }
+ else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127)
+ {
+ // The buffer is full, no more action is possible until we have read()
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ flagReadingSocket = 1;
+ theGSM3ShieldV1ModemCore.openCommand(this,XON);
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ //A small delay to assure data received after xon.
+ delay(10);
+ }
+ //To distinguish the case no more available data in socket.
+ if (ready()==1)
+ return charSocket;
+ else
+ return 0;
+}
+*/
+int GSM3ShieldV1MultiClientProvider::readSocket()
+{
+ char charSocket;
+
+ if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==0)
+ {
+ Serial.println();Serial.println("*");
+ return 0;
+ }
+
+ charSocket = theGSM3ShieldV1ModemCore.theBuffer().read();
+ //Case buffer not full
+ if (!fullBufferSocket)
+ {
+ //The last part of the buffer after data is CRLFOKCRLF
+ if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==125)
+ {
+ //Start again availableSocket function.
+ flagReadingSocket=0;
+ theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESOCKET);
+ availableSocketContinue();
+ }
+ }
+ else if (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()>=100)
+ {
+ // The buffer was full, we have to let the data flow again
+ // theGSM3ShieldV1ModemCore.theBuffer().flush();
+ flagReadingSocket = 1;
+ theGSM3ShieldV1ModemCore.openCommand(this,XON);
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ //A small delay to assure data received after xon.
+ delay(100);
+ if(theGSM3ShieldV1ModemCore.theBuffer().availableBytes() >=6)
+ fullBufferSocket=false;
+ }
+
+ return charSocket;
+
+}
+
+//Read socket main function.
+int GSM3ShieldV1MultiClientProvider::peekSocket()
+{
+ return theGSM3ShieldV1ModemCore.theBuffer().peek(0);
+}
+
+
+//Flush SMS main function.
+void GSM3ShieldV1MultiClientProvider::flushSocket()
+{
+ flagReadingSocket=0;
+ theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSOCKET);
+ flushSocketContinue();
+}
+
+//Send SMS continue function.
+void GSM3ShieldV1MultiClientProvider::flushSocketContinue()
+{
+ bool resp;
+ // 1: Deleting SMS
+ // 2: wait for OK
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //DEBUG
+ //Serial.println("Flushing Socket.");
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ if (fullBufferSocket)
+ {
+ //Serial.println("Buffer flushed.");
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ }
+ else
+ {
+ //Serial.println("Socket flushed completely.");
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ break;
+ }
+}
+
+//URC recognize.
+// Momentarily, we will not recognize "closes" in client mode
+bool GSM3ShieldV1MultiClientProvider::recognizeUnsolicitedEvent(byte oldTail)
+{
+ return false;
+}
+
+int GSM3ShieldV1MultiClientProvider::getSocket(int socket)
+{
+ if(socket==-1)
+ {
+ int i;
+ for(i=minSocket(); i<=maxSocket(); i++)
+ {
+ if (!(sockets&(0x0001<8)
+ return 0;
+ if(sockets&(0x0001<
+#include
+
+class GSM3ShieldV1MultiClientProvider : public GSM3MobileClientProvider, public GSM3ShieldV1BaseProvider
+{
+ private:
+
+ int remotePort; // Current operation remote port
+ int idSocket; // Remote ID socket
+ IPAddress remoteIP; // Remote IP address
+
+ uint16_t sockets;
+
+ /** Continue to connect TCP client function
+ */
+ void connectTCPClientContinue();
+
+ /** Continue to disconnect TCP client function
+ */
+ void disconnectTCPContinue();
+
+ /** Continue to begin socket for write function
+ */
+ void beginWriteSocketContinue();
+
+ /** Continue to end write socket function
+ */
+ void endWriteSocketContinue();
+
+ /** Continue to available socket function
+ */
+ void availableSocketContinue();
+
+ /** Continue to flush socket function
+ */
+ void flushSocketContinue();
+
+ // GATHER!
+ bool flagReadingSocket; //In case socket data being read, update fullBufferSocket in the next buffer.
+ bool fullBufferSocket; //To detect if the socket data being read needs another buffer.
+ bool client1_server0; //1 Client, 0 Server.
+
+ /** Parse QIRD response
+ @param rsp Returns true if expected response exists
+ @return true if command executed correctly
+ */
+ bool parseQIRD_head(bool& rsp);
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1MultiClientProvider();
+
+ /** Minimum socket
+ @return 0
+ */
+ int minSocket(){return 0;};
+
+ /** Maximum socket
+ @return 5
+ */
+ int maxSocket(){return 5;};
+
+ /** Connect to a remote TCP server
+ @param server String with IP or server name
+ @param port Remote port number
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int connectTCPClient(const char* server, int port, int id_socket);
+
+ /** Connect to a remote TCP server
+ @param add Remote IP address
+ @param port Remote port number
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int connectTCPClient(IPAddress add, int port, int id_socket);
+
+ /** Begin writing through a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ void beginWriteSocket(bool client1Server0, int id_socket);
+
+ /** Write through a socket. MUST go after beginWriteSocket()
+ @param buf characters to be written (final 0 will not be written)
+ */
+ void writeSocket(const char* buf);
+
+ /** Write through a socket. MUST go after beginWriteSocket()
+ @param c character to be written
+ */
+ void writeSocket(char c);
+
+ /** Finish current writing
+ */
+ void endWriteSocket();
+
+ /** Check if there are data to be read in socket.
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if there are data available, 4 if no data, otherwise error
+ */
+ int availableSocket(bool client, int id_socket); // With "available" and "readSocket" ask the modem for 1500 bytes.
+
+ /** Read a character from socket
+ @return socket
+ */
+ int readSocket(); //If Read() gets to the end of the QIRD response, execute again QIRD SYNCHRONOUSLY
+
+ /** Flush socket
+ */
+ void flushSocket();
+
+ /** Get a character but will not advance the buffer head
+ @return character
+ */
+ int peekSocket();
+
+ /** Close a socket
+ @param client1Server0 1 if modem acts as client, 0 if acts as server
+ @param id_socket Local socket number
+ @return 0 if command running, 1 if success, otherwise error
+ */
+ int disconnectTCP(bool client1Server0, int id_socket);
+
+ /** Recognize unsolicited event
+ @param from
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte from);
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Get client socket
+ @param socket
+ @return socket
+ */
+ int getSocket(int socket=-1);
+
+ /** Release socket
+ @param socket Socket for release
+ */
+ void releaseSocket(int socket);
+
+ /** Get socket client status
+ @param socket Socket
+ @return socket client status
+ */
+ bool getStatusSocketClient(uint8_t socket);
+
+};
+
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1MultiServerProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1MultiServerProvider.cpp
new file mode 100644
index 00000000..6a915f29
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1MultiServerProvider.cpp
@@ -0,0 +1,357 @@
+#include
+#include
+#include
+
+#define __NCLIENTS_MAX__ 3
+
+char _command_QILOCIP[] PROGMEM = "AT+QILOCIP";
+
+GSM3ShieldV1MultiServerProvider::GSM3ShieldV1MultiServerProvider()
+{
+ theGSM3MobileServerProvider=this;
+ socketsAsServer=0;
+ socketsAccepted=0;
+ theGSM3ShieldV1ModemCore.registerUMProvider(this);
+};
+
+//Response management.
+void GSM3ShieldV1MultiServerProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+ case CONNECTSERVER:
+ connectTCPServerContinue();
+ break;
+ case GETIP:
+ getIPContinue();
+ break;
+ }
+}
+
+//Connect Server main function.
+int GSM3ShieldV1MultiServerProvider::connectTCPServer(int port)
+{
+ // We forget about LocalIP as it has no real use, the modem does whatever it likes
+ theGSM3ShieldV1ModemCore.setPort(port);
+ theGSM3ShieldV1ModemCore.openCommand(this,CONNECTSERVER);
+ connectTCPServerContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Connect Server continue function.
+void GSM3ShieldV1MultiServerProvider::connectTCPServerContinue()
+{
+
+ bool resp;
+ // 1: Read Local IP "AT+QILOCIP"
+ // 2: Waiting for IP and Set local port "AT+QILPORT"
+ // 3: Waiting for QILPOR OK andConfigure as server "AT+QISERVER"
+ // 4: Wait for SERVER OK
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //"AT+QILOCIP."
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_QILOCIP);
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ //Not IP storing but the command is necessary.
+ //if(parseQILOCIP_rsp(local_IP, local_IP_Length, resp))
+ // This awful trick saves some RAM bytes
+ char aux[3];
+ aux[0]='\r';aux[1]='\n';aux[2]=0;
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux))
+ {
+ //Response received
+ if(resp)
+ {
+ // Great. Go for the next step
+ // AT+QILPORT
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILPORT=\"TCP\","),false);
+ theGSM3ShieldV1ModemCore.print( theGSM3ShieldV1ModemCore.getPort());
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 3:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ if(resp)
+ {
+ // OK received
+ // Great. Go for the next step
+ // AT+QISERVER
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISERVER=0,"),false);
+ theGSM3ShieldV1ModemCore.print(__NCLIENTS_MAX__);
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 4:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ // OK received, kathapoon, chessespoon
+ if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//QILOCIP parse.
+bool GSM3ShieldV1MultiServerProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp)
+{
+ if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength)))
+ rsp = false;
+ else
+ rsp = true;
+ return true;
+}
+
+//Get IP main function.
+int GSM3ShieldV1MultiServerProvider::getIP(char* LocalIP, int LocalIPlength)
+{
+ theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP);
+ theGSM3ShieldV1ModemCore.setPort(LocalIPlength);
+ theGSM3ShieldV1ModemCore.openCommand(this,GETIP);
+ getIPContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+void GSM3ShieldV1MultiServerProvider::getIPContinue()
+{
+
+ bool resp;
+ // 1: Read Local IP "AT+QILOCIP"
+ // 2: Waiting for IP.
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //AT+QILOCIP
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_QILOCIP);
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp))
+ {
+ if (resp)
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+bool GSM3ShieldV1MultiServerProvider::getSocketAsServerModemStatus(int s)
+{
+ if (socketsAccepted&(0x0001<
+#include
+
+class GSM3ShieldV1MultiServerProvider : public GSM3MobileServerProvider, public GSM3ShieldV1BaseProvider
+{
+ private:
+
+ // Used sockets
+ uint8_t socketsAsServer;
+ uint8_t socketsAccepted;
+
+ /** Continue to connect TCP server function
+ */
+ void connectTCPServerContinue();
+
+ /** Continue to get IP function
+ */
+ void getIPContinue();
+
+ /** Release socket
+ @param socket Socket
+ */
+ void releaseSocket(int socket);
+
+ /** Parse QILOCIP response
+ @param LocalIP Buffer for save local IP address
+ @param LocalIPlength Buffer size
+ @param rsp Returns if expected response exists
+ @return true if command executed correctly
+ */
+ bool parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp);
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1MultiServerProvider();
+
+ /** minSocketAsServer
+ @return 0
+ */
+ int minSocketAsServer(){return 0;};
+
+ /** maxSocketAsServer
+ @return 0
+ */
+ int maxSocketAsServer(){return 4;};
+
+ /** Get modem status
+ @param s
+ @return modem status (true if connected)
+ */
+ bool getSocketAsServerModemStatus(int s);
+
+ /** Get new occupied socket as server
+ @return command error if exists
+ */
+ int getNewOccupiedSocketAsServer();
+
+ /** Connect server to TCP port
+ @param port TCP port
+ @return command error if exists
+ */
+ int connectTCPServer(int port);
+
+ /** Get server IP address
+ @param LocalIP Buffer for copy IP address
+ @param LocalIPlength Length of buffer
+ @return command error if exists
+ */
+ int getIP(char* LocalIP, int LocalIPlength);
+
+// int disconnectTCP(bool client1Server0, int id_socket);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Get socket status as server
+ @param socket Socket to get status
+ @return socket status
+ */
+ bool getStatusSocketAsServer(uint8_t socket);
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ /** Recognize unsolicited event
+ @param oldTail
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte oldTail);
+
+
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1PinManagement.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1PinManagement.cpp
new file mode 100644
index 00000000..0c0c7496
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1PinManagement.cpp
@@ -0,0 +1,201 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+
+#include
+
+// constructor
+GSM3ShieldV1PinManagement::GSM3ShieldV1PinManagement()
+{
+};
+
+// reset the modem for direct access
+void GSM3ShieldV1PinManagement::begin()
+{
+ // reset hardware
+ gsm.HWrestart();
+
+ pin_used = false;
+
+ // check modem response
+ modemAccess.writeModemCommand("AT", 1000);
+ modemAccess.writeModemCommand("ATE0", 1000);
+}
+
+/*
+ Check PIN status
+*/
+int GSM3ShieldV1PinManagement::isPIN()
+{
+ String res = modemAccess.writeModemCommand("AT+CPIN?",1000);
+ // Check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "READY") != NULL)
+ return 0;
+ else if(strstr(res_to_compare, "SIM PIN") != NULL)
+ return 1;
+ else if(strstr(res_to_compare, "SIM PUK") != NULL)
+ return -1;
+ else
+ return -2;
+}
+
+/*
+ Check PIN code
+*/
+int GSM3ShieldV1PinManagement::checkPIN(String pin)
+{
+ String res = modemAccess.writeModemCommand("AT+CPIN=" + pin,1000);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "OK") == NULL)
+ return -1;
+ else
+ return 0;
+}
+
+/*
+ Check PUK code
+*/
+int GSM3ShieldV1PinManagement::checkPUK(String puk, String pin)
+{
+ String res = modemAccess.writeModemCommand("AT+CPIN=\"" + puk + "\",\"" + pin + "\"",1000);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "OK") == NULL)
+ return -1;
+ else
+ return 0;
+}
+
+/*
+ Change PIN code
+*/
+void GSM3ShieldV1PinManagement::changePIN(String old, String pin)
+{
+ String res = modemAccess.writeModemCommand("AT+CPWD=\"SC\",\"" + old + "\",\"" + pin + "\"",2000);
+ Serial.println(res);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "OK") != NULL)
+ Serial.println("Pin changed succesfully.");
+ else
+ Serial.println("ERROR");
+}
+
+/*
+ Switch PIN status
+*/
+void GSM3ShieldV1PinManagement::switchPIN(String pin)
+{
+ String res = modemAccess.writeModemCommand("AT+CLCK=\"SC\",2",1000);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "0") != NULL)
+ {
+ res = modemAccess.writeModemCommand("AT+CLCK=\"SC\",1,\"" + pin + "\"",1000);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "OK") == NULL)
+ {
+ Serial.println("ERROR");
+ pin_used = false;
+ }
+ else
+ {
+ Serial.println("OK. PIN lock on.");
+ pin_used = true;
+ }
+ }
+ else if(strstr(res_to_compare, "1") != NULL)
+ {
+ res = modemAccess.writeModemCommand("AT+CLCK=\"SC\",0,\"" + pin + "\"",1000);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "OK") == NULL)
+ {
+ Serial.println("ERROR");
+ pin_used = true;
+ }
+ else
+ {
+ Serial.println("OK. PIN lock off.");
+ pin_used = false;
+ }
+ }
+ else
+ {
+ Serial.println("ERROR");
+ }
+}
+
+/*
+ Check registrer
+*/
+int GSM3ShieldV1PinManagement::checkReg()
+{
+ delay(5000);
+ String res = modemAccess.writeModemCommand("AT+CREG?",1000);
+ // check response
+ char res_to_compare[res.length()];
+ res.toCharArray(res_to_compare, res.length());
+ if(strstr(res_to_compare, "1") != NULL)
+ return 0;
+ else if(strstr(res_to_compare, "5") != NULL)
+ return 1;
+ else
+ return -1;
+}
+
+/*
+ Return if PIN lock is used
+*/
+bool GSM3ShieldV1PinManagement::getPINUsed()
+{
+ return pin_used;
+}
+
+/*
+ Set if PIN lock is used
+*/
+void GSM3ShieldV1PinManagement::setPINUsed(bool used)
+{
+ pin_used = used;
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1PinManagement.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1PinManagement.h
new file mode 100644
index 00000000..ce43cdd1
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1PinManagement.h
@@ -0,0 +1,103 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3SHIELDV1PINMANAGEMENT_
+#define _GSM3SHIELDV1PINMANAGEMENT_
+
+#include
+#include
+
+class GSM3ShieldV1PinManagement
+{
+
+ private:
+
+ GSM3ShieldV1AccessProvider gsm; // GSM access required for network register with PIN code
+ GSM3ShieldV1DirectModemProvider modemAccess;
+ bool pin_used; // determines if pin lock is activated
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1PinManagement();
+
+ /** Check modem response and restart it
+ */
+ void begin();
+
+ /** Check if PIN lock or PUK lock is activated
+ @return 0 if PIN lock is off, 1 if PIN lock is on, -1 if PUK lock is on, -2 if error exists
+ */
+ int isPIN();
+
+ /** Check if PIN code is correct and valid
+ @param pin PIN code
+ @return 0 if is correct, -1 if is incorrect
+ */
+ int checkPIN(String pin);
+
+ /** Check if PUK code is correct and establish new PIN code
+ @param puk PUK code
+ @param pin New PIN code
+ @return 0 if successful, otherwise return -1
+ */
+ int checkPUK(String puk, String pin);
+
+ /** Change PIN code
+ @param old Old PIN code
+ @param pin New PIN code
+ */
+ void changePIN(String old, String pin);
+
+ /** Change PIN lock status
+ @param pin PIN code
+ */
+ void switchPIN(String pin);
+
+ /** Check if modem was registered in GSM/GPRS network
+ @return 0 if modem was registered, 1 if modem was registered in roaming, -1 if error exists
+ */
+ int checkReg();
+
+ /** Return if PIN lock is used
+ @return true if PIN lock is used, otherwise, return false
+ */
+ bool getPINUsed();
+
+ /** Set PIN lock status
+ @param used New PIN lock status
+ */
+ void setPINUsed(bool used);
+};
+
+#endif;
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1SMSProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1SMSProvider.cpp
new file mode 100644
index 00000000..9ed075e7
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1SMSProvider.cpp
@@ -0,0 +1,293 @@
+#include
+#include
+
+GSM3ShieldV1SMSProvider::GSM3ShieldV1SMSProvider()
+{
+ theGSM3SMSProvider=this;
+};
+
+//Send SMS begin function.
+int GSM3ShieldV1SMSProvider::beginSMS(const char* to)
+{
+ if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY)&&(theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY))
+ return 2;
+
+ theGSM3ShieldV1ModemCore.setPhoneNumber((char*)to);
+ theGSM3ShieldV1ModemCore.openCommand(this,BEGINSMS);
+ beginSMSContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Send SMS continue function.
+void GSM3ShieldV1SMSProvider::beginSMSContinue()
+{
+ bool resp;
+ // 1: Send AT
+ // 2: wait for > and write text
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGS=\""), false);
+ theGSM3ShieldV1ModemCore.print(theGSM3ShieldV1ModemCore.getPhoneNumber());
+ theGSM3ShieldV1ModemCore.print("\"\r");
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, ">"))
+ {
+ if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Send SMS write function.
+void GSM3ShieldV1SMSProvider::writeSMS(char c)
+{
+ theGSM3ShieldV1ModemCore.write(c);
+}
+
+//Send SMS begin function.
+int GSM3ShieldV1SMSProvider::endSMS()
+{
+ theGSM3ShieldV1ModemCore.openCommand(this,ENDSMS);
+ endSMSContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Send SMS continue function.
+void GSM3ShieldV1SMSProvider::endSMSContinue()
+{
+ bool resp;
+ // 1: Send #26
+ // 2: wait for OK
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ theGSM3ShieldV1ModemCore.write(26);
+ theGSM3ShieldV1ModemCore.print("\r");
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if (resp)
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Available SMS main function.
+int GSM3ShieldV1SMSProvider::availableSMS()
+{
+ flagReadingSMS = 0;
+ theGSM3ShieldV1ModemCore.openCommand(this,AVAILABLESMS);
+ availableSMSContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Available SMS continue function.
+void GSM3ShieldV1SMSProvider::availableSMSContinue()
+{
+ // 1: AT+CMGL="REC UNREAD",1
+ // 2: Receive +CMGL: _id_ ... READ","_numero_" ... \n_mensaje_\nOK
+ // 3: Send AT+CMGD= _id_
+ // 4: Receive OK
+ // 5: Remaining SMS text in case full buffer.
+ // This implementation really does not care much if the modem aswers trash to CMGL
+ bool resp;
+ //int msglength_aux;
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGL=\"REC UNREAD\",1"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(parseCMGL_available(resp))
+ {
+ if (!resp) theGSM3ShieldV1ModemCore.closeCommand(4);
+ else theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ break;
+ }
+
+}
+
+//SMS available parse.
+bool GSM3ShieldV1SMSProvider::parseCMGL_available(bool& rsp)
+{
+ fullBufferSMS = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<=4);
+ if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+CMGL:", true)))
+ rsp = false;
+ else
+ rsp = true;
+ idSMS=theGSM3ShieldV1ModemCore.theBuffer().readInt();
+
+ //If there are 2 SMS in buffer, response is ...CRLFCRLF+CMGL
+ twoSMSinBuffer = theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+");
+
+ checkSecondBuffer = 0;
+
+ return true;
+}
+
+//remoteNumber SMS function.
+int GSM3ShieldV1SMSProvider::remoteSMSNumber(char* number, int nlength)
+{
+ theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("READ\",\"", "\"", number, nlength);
+
+ return 1;
+}
+
+//remoteNumber SMS function.
+int GSM3ShieldV1SMSProvider::readSMS()
+{
+ char charSMS;
+ //First char.
+ if (!flagReadingSMS)
+ {
+ flagReadingSMS = 1;
+ theGSM3ShieldV1ModemCore.theBuffer().chopUntil("\n", true);
+ }
+ charSMS = theGSM3ShieldV1ModemCore.theBuffer().read();
+
+ //Second Buffer.
+ if (checkSecondBuffer)
+ {
+ checkSecondBuffer = 0;
+ twoSMSinBuffer = theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+");
+ }
+
+ //Case the last char in buffer.
+ if ((!twoSMSinBuffer)&&fullBufferSMS&&(theGSM3ShieldV1ModemCore.theBuffer().availableBytes()==127))
+ {
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ fullBufferSMS = 0;
+ checkSecondBuffer = 1;
+ theGSM3ShieldV1ModemCore.openCommand(this,XON);
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ delay(10);
+
+ return charSMS;
+ }
+ //Case two SMS in buffer
+ else if (twoSMSinBuffer)
+ {
+ if (theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\n+"))
+ {
+ return charSMS;
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.openCommand(this,XON);
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ delay(10);
+ return 0;
+ }
+ }
+ //Case 1 SMS and buffer not full
+ else if (!fullBufferSMS)
+ {
+ if (theGSM3ShieldV1ModemCore.theBuffer().locate("\r\n\r\nOK"))
+ {
+ return charSMS;
+ }
+ else
+ {
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.openCommand(this,XON);
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ delay(10);
+ return 0;
+ }
+ }
+ //Case to read all the chars in buffer to the end.
+ else
+ {
+ return charSMS;
+ }
+}
+
+//Read socket main function.
+int GSM3ShieldV1SMSProvider::peekSMS()
+{
+ if (!flagReadingSMS)
+ {
+ flagReadingSMS = 1;
+ theGSM3ShieldV1ModemCore.theBuffer().chopUntil("\n", true);
+ }
+
+ return theGSM3ShieldV1ModemCore.theBuffer().peek(0);
+}
+
+//Flush SMS main function.
+void GSM3ShieldV1SMSProvider::flushSMS()
+{
+
+ //With this, sms data can fill up to 2x128+5x128 bytes.
+ for (int aux = 0;aux<5;aux++)
+ {
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ delay(10);
+ }
+
+ theGSM3ShieldV1ModemCore.openCommand(this,FLUSHSMS);
+ flushSMSContinue();
+}
+
+//Send SMS continue function.
+void GSM3ShieldV1SMSProvider::flushSMSContinue()
+{
+ bool resp;
+ // 1: Deleting SMS
+ // 2: wait for OK
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CMGD="), false);
+ theGSM3ShieldV1ModemCore.print(idSMS);
+ theGSM3ShieldV1ModemCore.print("\r");
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+void GSM3ShieldV1SMSProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+/* case XON:
+ if (flagReadingSocket)
+ {
+// flagReadingSocket = 0;
+ fullBufferSocket = (theGSM3ShieldV1ModemCore.theBuffer().availableBytes()<3);
+ }
+ else theGSM3ShieldV1ModemCore.openCommand(this,NONE);
+ break;
+*/ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+ case BEGINSMS:
+ beginSMSContinue();
+ break;
+ case ENDSMS:
+ endSMSContinue();
+ break;
+ case AVAILABLESMS:
+ availableSMSContinue();
+ break;
+ case FLUSHSMS:
+ flushSMSContinue();
+ break;
+ }
+}
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1SMSProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1SMSProvider.h
new file mode 100644
index 00000000..408da338
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1SMSProvider.h
@@ -0,0 +1,130 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_SHIELDV1SMSPROVIDER__
+#define __GSM3_SHIELDV1SMSPROVIDER__
+
+#include
+#include
+#include
+
+
+class GSM3ShieldV1SMSProvider : public GSM3MobileSMSProvider, public GSM3ShieldV1BaseProvider
+{
+ public:
+ GSM3ShieldV1SMSProvider();
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ /** Begin a SMS to send it
+ @param to Destination
+ @return error command if it exists
+ */
+ inline int beginSMS(const char* to);
+
+ /** Write a SMS character by character
+ @param c Character
+ */
+ inline void writeSMS(char c);
+
+ /** End SMS
+ @return error command if it exists
+ */
+ inline int endSMS();
+
+ /** Check if SMS available and prepare it to be read
+ @return number of bytes in a received SMS
+ */
+ int availableSMS();
+
+ /** Read a byte but do not advance the buffer header (circular buffer)
+ @return character
+ */
+ int peekSMS();
+
+ /** Delete the SMS from Modem memory and proccess answer
+ */
+ void flushSMS();
+
+ /** Read sender number phone
+ @param number Buffer for save number phone
+ @param nlength Buffer length
+ @return 1 success, >1 error
+ */
+ int remoteSMSNumber(char* number, int nlength); //Before reading the SMS, read the phone number.
+
+ /** Read one char for SMS buffer (advance circular buffer)
+ @return character
+ */
+ int readSMS();
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ private:
+
+ int idSMS; // Id from current SMS being read.
+ bool flagReadingSMS; // To detect first SMS char if not yet reading.
+ bool fullBufferSMS; // To detect if the SMS being read needs another buffer.
+ bool twoSMSinBuffer; // To detect if the buffer has more than 1 SMS.
+ bool checkSecondBuffer; // Pending to detect if the second buffer has more than 1 SMS.
+
+ /** Continue to begin SMS function
+ */
+ void beginSMSContinue();
+
+ /** Continue to end SMS function
+ */
+ void endSMSContinue();
+
+ /** Continue to available SMS function
+ */
+ void availableSMSContinue();
+
+ /** Continue to flush SMS function
+ */
+ void flushSMSContinue();
+
+ /** Parse CMGL response
+ @param rsp Returns true if expected response exists
+ @return true if command executed correctly
+ */
+ bool parseCMGL_available(bool& rsp);
+};
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ScanNetworks.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ScanNetworks.cpp
new file mode 100644
index 00000000..23da8a6b
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ScanNetworks.cpp
@@ -0,0 +1,126 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+
+#include
+
+GSM3ShieldV1ScanNetworks::GSM3ShieldV1ScanNetworks(bool trace): modem(trace)
+{
+}
+
+GSM3_NetworkStatus_t GSM3ShieldV1ScanNetworks::begin()
+{
+ modem.begin();
+ modem.restartModem();
+ // check modem response
+ modem.writeModemCommand("AT", 1000);
+ modem.writeModemCommand("ATE0", 1000);
+ return IDLE;
+}
+
+String GSM3ShieldV1ScanNetworks::getCurrentCarrier()
+{
+ String modemResponse = modem.writeModemCommand("AT+COPS?", 2000);
+
+ // Parse and check response
+ char res_to_split[modemResponse.length()];
+ modemResponse.toCharArray(res_to_split, modemResponse.length());
+ if(strstr(res_to_split,"ERROR") == NULL){
+ // Tokenizer
+ char *ptr_token;
+ ptr_token = strtok(res_to_split, "\"");
+ ptr_token = strtok(NULL, "\"");
+ String final_result = ptr_token;
+ return final_result;
+ }else{
+ return NULL;
+ }
+}
+
+String GSM3ShieldV1ScanNetworks::getSignalStrength()
+{
+ String modemResponse = modem.writeModemCommand("AT+CSQ", 2000);
+ char res_to_split[modemResponse.length()];
+ modemResponse.toCharArray(res_to_split, modemResponse.length());
+ if((strstr(res_to_split,"ERROR") == NULL) | (strstr(res_to_split,"99") == NULL)){
+ // Tokenizer
+ char *ptr_token;
+ ptr_token = strtok(res_to_split, ":");
+ ptr_token = strtok(NULL, ":");
+ ptr_token = strtok(ptr_token, ",");
+ String final_result = ptr_token;
+ final_result.trim();
+ return final_result;
+ }else{
+ return NULL;
+ }
+}
+
+String GSM3ShieldV1ScanNetworks::readNetworks()
+{
+ String modemResponse = modem.writeModemCommand("AT+COPS=?",20000);
+ String result;
+ bool inQuotes=false;
+ int quoteCounter=0;
+ for(int i=0; i ";
+ }
+ else
+ {
+ inQuotes=false;
+ if(quoteCounter==3)
+ quoteCounter=0;
+ if(quoteCounter==1)
+ result+="\n";
+
+ }
+ }
+ else
+ {
+ if(inQuotes&&(quoteCounter==1))
+ {
+ result+=modemResponse[i];
+ }
+ }
+ }
+ return result;
+}
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ScanNetworks.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ScanNetworks.h
new file mode 100644
index 00000000..f43b1642
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ScanNetworks.h
@@ -0,0 +1,75 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3SHIELDV1SCANNETWORKS__
+#define __GSM3SHIELDV1SCANNETWORKS__
+
+// This class executes band management functions for the ShieldV1
+#include
+#include
+
+class GSM3ShieldV1ScanNetworks
+{
+ private:
+ GSM3ShieldV1DirectModemProvider modem;
+
+ public:
+
+ /** Constructor
+ @param trace if true, dumps all AT dialogue to Serial
+ @return -
+ */
+ GSM3ShieldV1ScanNetworks(bool trace=false);
+
+ /** begin (forces modem hardware restart, so we begin from scratch)
+ @return Always returns IDLE status
+ */
+ GSM3_NetworkStatus_t begin();
+
+ /** Read current carrier
+ @return Current carrier
+ */
+ String getCurrentCarrier();
+
+ /** Obtain signal strength
+ @return Signal Strength
+ */
+ String getSignalStrength();
+
+ /** Search available carriers
+ @return A string with list of networks available
+ */
+ String readNetworks();
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ServerProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ServerProvider.cpp
new file mode 100644
index 00000000..77f54367
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ServerProvider.cpp
@@ -0,0 +1,205 @@
+#include
+#include
+#include
+
+GSM3ShieldV1ServerProvider::GSM3ShieldV1ServerProvider()
+{
+ theGSM3MobileServerProvider=this;
+};
+
+//Response management.
+void GSM3ShieldV1ServerProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case NONE:
+ theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
+ break;
+ case CONNECTSERVER:
+ connectTCPServerContinue();
+ break;
+ /*case GETIP:
+ getIPContinue();
+ break;*/
+ }
+}
+
+//Connect Server main function.
+int GSM3ShieldV1ServerProvider::connectTCPServer(int port)
+{
+ // We forget about LocalIP as it has no real use, the modem does whatever it likes
+ theGSM3ShieldV1ModemCore.setPort(port);
+ theGSM3ShieldV1ModemCore.openCommand(this,CONNECTSERVER);
+ // From this moment on we wait for a call
+ connectTCPServerContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Connect Server continue function.
+void GSM3ShieldV1ServerProvider::connectTCPServerContinue()
+{
+
+ bool resp;
+ // 1: Read Local IP "AT+QILOCIP"
+ // 2: Waiting for IP and Set local port "AT+QILPORT"
+ // 3: Waiting for QILPOR OK andConfigure as server "AT+QISERVER"
+ // 4: Wait for SERVER OK
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //"AT+QILOCIP."
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILOCIP"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ //Not IP storing but the command is necessary.
+ //if(parseQILOCIP_rsp(local_IP, local_IP_Length, resp))
+ // This awful trick saves some RAM bytes
+ char aux[3];
+ aux[0]='\r';aux[1]='\n';aux[2]=0;
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp, aux))
+ {
+ //Response received
+ if(resp)
+ {
+ // Great. Go for the next step
+ // AT+QILPORT
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QILPORT=\"TCP\","),false);
+ theGSM3ShieldV1ModemCore.print( theGSM3ShieldV1ModemCore.getPort());
+ theGSM3ShieldV1ModemCore.print('\r');
+ theGSM3ShieldV1ModemCore.setCommandCounter(3);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 3:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ if(resp)
+ {
+ // OK received
+ // Great. Go for the next step
+ // AT+QISERVER
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QISERVER"),true);
+ theGSM3ShieldV1ModemCore.setCommandCounter(4);
+ }
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ case 4:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ // Response received
+ // OK received, kathapoon, chessespoon
+ if (resp)
+ {
+ theGSM3ShieldV1ModemCore.registerUMProvider(this);
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//QILOCIP parse.
+/*bool GSM3ShieldV1ServerProvider::parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp)
+{
+ if (!(theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("\r\n","\r\n", LocalIP, LocalIPlength)))
+ rsp = false;
+ else
+ rsp = true;
+ return true;
+}
+
+//Get IP main function.
+int GSM3ShieldV1ServerProvider::getIP(char* LocalIP, int LocalIPlength)
+{
+ theGSM3ShieldV1ModemCore.setPhoneNumber(LocalIP);
+ theGSM3ShieldV1ModemCore.setPort(LocalIPlength);
+ theGSM3ShieldV1ModemCore.openCommand(this,GETIP);
+ getIPContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+void GSM3ShieldV1ServerProvider::getIPContinue()
+{
+
+ bool resp;
+ // 1: Read Local IP "AT+QILOCIP"
+ // 2: Waiting for IP.
+
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //AT+QILOCIP
+ theGSM3ShieldV1ModemCore.genericCommand_rq(_command_MonoQILOCIP);
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(parseQILOCIP_rsp(theGSM3ShieldV1ModemCore.getPhoneNumber(), theGSM3ShieldV1ModemCore.getPort(), resp))
+ {
+ if (resp)
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ else
+ theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ break;
+ }
+}*/
+
+bool GSM3ShieldV1ServerProvider::getSocketAsServerModemStatus(int s)
+{
+ if(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED)
+ return true;
+ else
+ return false;
+}
+
+
+//URC recognize.
+bool GSM3ShieldV1ServerProvider::recognizeUnsolicitedEvent(byte oldTail)
+{
+
+ int nlength;
+ char auxLocate [15];
+
+ //REMOTE SOCKET CLOSED.
+ prepareAuxLocate(PSTR("CLOSED\r\n"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate))
+ {
+ //To detect remote socket closed for example inside socket data.
+ theGSM3ShieldV1ModemCore.setStatus(GPRS_READY);
+ }
+
+
+ //REMOTE SOCKET ACCEPTED.
+ prepareAuxLocate(PSTR("CONNECT\r\n"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.gss.cb.locate(auxLocate))
+ {
+ //To detect remote socket closed for example inside socket data.
+ theGSM3ShieldV1ModemCore.theBuffer().chopUntil(auxLocate, true);
+ theGSM3ShieldV1ModemCore.gss.spaceAvailable();
+ theGSM3ShieldV1ModemCore.setStatus(TRANSPARENT_CONNECTED);
+ return true;
+ }
+
+ return false;
+}
+
+bool GSM3ShieldV1ServerProvider::getStatusSocketAsServer(uint8_t socket)
+{
+ return(theGSM3ShieldV1ModemCore.getStatus()==TRANSPARENT_CONNECTED);
+};
+
+void GSM3ShieldV1ServerProvider::releaseSocket(int socket)
+{
+}
+
+int GSM3ShieldV1ServerProvider::getNewOccupiedSocketAsServer()
+{
+ return 0;
+}
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ServerProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ServerProvider.h
new file mode 100644
index 00000000..93fcd89a
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1ServerProvider.h
@@ -0,0 +1,126 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_SHIELDV1SERVERPROVIDER__
+#define __GSM3_SHIELDV1SERVERPROVIDER__
+
+#include
+#include
+
+class GSM3ShieldV1ServerProvider : public GSM3MobileServerProvider, public GSM3ShieldV1BaseProvider
+{
+ private:
+
+ /** Continue to connect to server with TCP protocol function
+ */
+ void connectTCPServerContinue();
+
+ /** Continue to get IP address function
+ */
+ //void getIPContinue();
+
+ /** Parse QILOCIP response
+ @param LocalIP Buffer for save local IP address
+ @param LocalIPlength Buffer size
+ @param rsp Returns if expected response exists
+ @return true if command executed correctly
+ */
+ //bool parseQILOCIP_rsp(char* LocalIP, int LocalIPlength, bool& rsp);
+
+ /** Release socket
+ @param socket Socket
+ */
+ void releaseSocket(int socket);
+
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1ServerProvider();
+
+ /** minSocketAsServer
+ @return 0
+ */
+ int minSocketAsServer(){return 0;};
+
+ /** maxSocketAsServer
+ @return 0
+ */
+ int maxSocketAsServer(){return 0;};
+
+ /** Get modem status
+ @param s Socket
+ @return modem status (true if connected)
+ */
+ bool getSocketAsServerModemStatus(int s);
+
+ /** Get new occupied socket as server
+ @return return -1 if no new socket has been occupied
+ */
+ int getNewOccupiedSocketAsServer();
+
+ /** Connect server to TCP port
+ @param port TCP port
+ @return command error if exists
+ */
+ int connectTCPServer(int port);
+
+ //int getIP(char* LocalIP, int LocalIPlength);
+// int disconnectTCP(bool client1Server0, int id_socket);
+
+ /** Get last command status
+ @return returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Get socket status as server
+ @param socket Socket to get status
+ @return socket status
+ */
+ bool getStatusSocketAsServer(uint8_t socket);
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ /** Recognize unsolicited event
+ @param oldTail
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte oldTail);
+
+
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1VoiceProvider.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1VoiceProvider.cpp
new file mode 100644
index 00000000..98a50b90
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1VoiceProvider.cpp
@@ -0,0 +1,215 @@
+#include
+#include
+
+GSM3ShieldV1VoiceProvider::GSM3ShieldV1VoiceProvider()
+ {
+ phonelength=0;
+ theGSM3MobileVoiceProvider=this;
+ }
+
+ void GSM3ShieldV1VoiceProvider::initialize()
+ {
+ theGSM3ShieldV1ModemCore.registerUMProvider(this);
+ }
+
+//Voice Call main function.
+int GSM3ShieldV1VoiceProvider::voiceCall(const char* to)
+{
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATD"),false);
+ theGSM3ShieldV1ModemCore.print(to);
+ theGSM3ShieldV1ModemCore.print(";\r");
+ setvoiceCallStatus(CALLING);
+ return 1;
+}
+
+//Retrieve calling number main function.
+int GSM3ShieldV1VoiceProvider::retrieveCallingNumber (char* buffer, int bufsize)
+{
+ theGSM3ShieldV1ModemCore.setPhoneNumber(buffer);
+ phonelength = bufsize;
+ theGSM3ShieldV1ModemCore.setCommandError(0);
+ theGSM3ShieldV1ModemCore.setCommandCounter(1);
+ theGSM3ShieldV1ModemCore.openCommand(this,RETRIEVECALLINGNUMBER);
+ retrieveCallingNumberContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Retrieve calling number Continue function.
+void GSM3ShieldV1VoiceProvider::retrieveCallingNumberContinue()
+{
+ // 1: AT+CLCC
+ // 2: Receive +CLCC: 1,1,4,0,0,"num",129,""
+ // This implementation really does not care much if the modem aswers trash to CMGL
+ bool resp;
+ //int msglength_aux;
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+CLCC"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(parseCLCC(theGSM3ShieldV1ModemCore.getPhoneNumber(), phonelength))
+ {
+ theGSM3ShieldV1ModemCore.closeCommand(1);
+ }
+ break;
+ }
+}
+
+//CLCC parse.
+bool GSM3ShieldV1VoiceProvider::parseCLCC(char* number, int nlength)
+{
+ theGSM3ShieldV1ModemCore.theBuffer().extractSubstring("+CLCC: 1,1,4,0,0,\"","\"", number, nlength);
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ return true;
+}
+
+//Answer Call main function.
+int GSM3ShieldV1VoiceProvider::answerCall()
+{
+ theGSM3ShieldV1ModemCore.setCommandError(0);
+ theGSM3ShieldV1ModemCore.setCommandCounter(1);
+ theGSM3ShieldV1ModemCore.openCommand(this,ANSWERCALL);
+ answerCallContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Answer Call continue function.
+void GSM3ShieldV1VoiceProvider::answerCallContinue()
+{
+ // 1: ATA
+ // 2: Waiting for OK
+
+ // This implementation really does not care much if the modem aswers trash to CMGL
+ bool resp;
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ // ATA ;
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATA"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ setvoiceCallStatus(TALKING);
+ if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Hang Call main function.
+int GSM3ShieldV1VoiceProvider::hangCall()
+{
+ theGSM3ShieldV1ModemCore.setCommandError(0);
+ theGSM3ShieldV1ModemCore.setCommandCounter(1);
+ theGSM3ShieldV1ModemCore.openCommand(this,HANGCALL);
+ hangCallContinue();
+ return theGSM3ShieldV1ModemCore.getCommandError();
+}
+
+//Hang Call continue function.
+void GSM3ShieldV1VoiceProvider::hangCallContinue()
+{
+ // 1: ATH
+ // 2: Waiting for OK
+
+ bool resp;
+ switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
+ case 1:
+ //ATH
+ theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("ATH"));
+ theGSM3ShieldV1ModemCore.setCommandCounter(2);
+ break;
+ case 2:
+ if(theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
+ {
+ setvoiceCallStatus(IDLE_CALL);
+ if (resp) theGSM3ShieldV1ModemCore.closeCommand(1);
+ else theGSM3ShieldV1ModemCore.closeCommand(3);
+ }
+ break;
+ }
+}
+
+//Response management.
+void GSM3ShieldV1VoiceProvider::manageResponse(byte from, byte to)
+{
+ switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
+ {
+ case ANSWERCALL:
+ answerCallContinue();
+ break;
+ case HANGCALL:
+ hangCallContinue();
+ break;
+ case RETRIEVECALLINGNUMBER:
+ retrieveCallingNumberContinue();
+ break;
+
+ }
+}
+
+//URC recognize.
+bool GSM3ShieldV1VoiceProvider::recognizeUnsolicitedEvent(byte oldTail)
+{
+
+ int nlength;
+ char auxLocate [15];
+ //RING.
+ prepareAuxLocate(PSTR("RING"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
+ {
+ // RING
+ setvoiceCallStatus(RECEIVINGCALL);
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ return true;
+ }
+
+ //CALL ACEPTED.
+ prepareAuxLocate(PSTR("+COLP:"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
+ {
+ //DEBUG
+ //Serial.println("Call Accepted.");
+ setvoiceCallStatus(TALKING);
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ return true;
+ }
+
+ //NO CARRIER.
+ prepareAuxLocate(PSTR("NO CARRIER"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
+ {
+ //DEBUG
+ //Serial.println("NO CARRIER received.");
+ setvoiceCallStatus(IDLE_CALL);
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ return true;
+ }
+
+ //BUSY.
+ prepareAuxLocate(PSTR("BUSY"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
+ {
+ //DEBUG
+ //Serial.println("BUSY received.");
+ setvoiceCallStatus(IDLE_CALL);
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ return true;
+ }
+
+ //CALL RECEPTION.
+ prepareAuxLocate(PSTR("+CLIP:"), auxLocate);
+ if(theGSM3ShieldV1ModemCore.theBuffer().locate(auxLocate))
+ {
+ theGSM3ShieldV1ModemCore.theBuffer().flush();
+ setvoiceCallStatus(RECEIVINGCALL);
+ return true;
+ }
+
+ return false;
+}
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1VoiceProvider.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1VoiceProvider.h
new file mode 100644
index 00000000..b9613853
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3ShieldV1VoiceProvider.h
@@ -0,0 +1,137 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+
+#ifndef _GSM3SHIELDV1VOICEPROVIDER_
+#define _GSM3SHIELDV1VOICEPROVIDER_
+
+#include
+#include
+#include
+
+class GSM3ShieldV1VoiceProvider : public GSM3MobileVoiceProvider, public GSM3ShieldV1BaseProvider
+{
+ public:
+
+ /** Constructor */
+ GSM3ShieldV1VoiceProvider();
+
+ /** initilizer, links with modem provider */
+ void initialize();
+
+
+ /** Manages modem response
+ @param from Initial byte of buffer
+ @param to Final byte of buffer
+ */
+ void manageResponse(byte from, byte to);
+
+ //Call functions.
+
+ /** Launch a voice call
+ @param number Phone number to be called
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ int voiceCall(const char* number);
+
+ /** Answer a voice call
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ int answerCall();
+
+ /** Hang a voice call
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ int hangCall();
+
+ /** Retrieve phone number of caller
+ @param buffer Buffer for copy phone number
+ @param bufsize Buffer size
+ @return If asynchronous, returns 0. If synchronous, 1 if success, other if error
+ */
+ int retrieveCallingNumber(char* buffer, int bufsize);
+
+ /** Get last command status
+ @return Returns 0 if last command is still executing, 1 success, >1 error
+ */
+ int ready(){return GSM3ShieldV1BaseProvider::ready();};
+
+ /** Recognize URC
+ @param oldTail
+ @return true if successful
+ */
+ bool recognizeUnsolicitedEvent(byte oldTail);
+
+ /** Returns voice call status
+ @return voice call status
+ */
+ GSM3_voiceCall_st getvoiceCallStatus(){ready(); return _voiceCallstatus;};
+
+ /** Set voice call status
+ @param status New status for voice call
+ */
+ void setvoiceCallStatus(GSM3_voiceCall_st status) { _voiceCallstatus = status; };
+
+
+ private:
+
+ int phonelength; // Phone number length
+
+ GSM3_voiceCall_st _voiceCallstatus; // The voiceCall status
+
+ /** Continue to voice call function
+ */
+ void voiceCallContinue();
+
+ /** Continue to answer call function
+ */
+ void answerCallContinue();
+
+ /** Continue to hang call function
+ */
+ void hangCallContinue();
+
+ /** Continue to retrieve calling number function
+ */
+ void retrieveCallingNumberContinue();
+
+ /** Parse CLCC response from buffer
+ @param number Number initial for extract substring of response
+ @param nlength Substring length
+ @return true if successful
+ */
+ bool parseCLCC(char* number, int nlength);
+
+};
+
+#endif
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SoftSerial.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SoftSerial.cpp
new file mode 100644
index 00000000..c0f29eb3
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SoftSerial.cpp
@@ -0,0 +1,537 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include "GSM3SoftSerial.h"
+#include
+#include
+#include "pins_arduino.h"
+#include
+#include
+
+#if defined(__AVR_ATmega328P__)
+#define __TXPIN__ 3
+#define __RXPIN__ 2
+#define __RXINT__ 3
+#elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
+#define __TXPIN__ 3
+#define __RXPIN__ 10
+#define __RXINT__ 4
+#elif defined(__AVR_ATmega32U4__)
+#define __TXPIN__ 3
+#define __RXPIN__ 8
+#define __RXINT__ 3
+#endif
+
+#define __XON__ 0x11
+#define __XOFF__ 0x13
+
+#define _GSMSOFTSERIALFLAGS_ESCAPED_ 0x01
+#define _GSMSOFTSERIALFLAGS_SENTXOFF_ 0x02
+
+//
+// Lookup table
+//
+#define __PARAGRAPHGUARD__ 50
+typedef struct _DELAY_TABLE
+{
+ long baud;
+ unsigned short rx_delay_centering;
+ unsigned short rx_delay_intrabit;
+ unsigned short rx_delay_stopbit;
+ unsigned short tx_delay;
+} DELAY_TABLE;
+
+#if F_CPU == 16000000
+
+static const DELAY_TABLE PROGMEM table[] =
+{
+ // baud rxcenter rxintra rxstop tx
+ { 115200, 1, 17, 17, 12, },
+ { 57600, 10, 37, 37, 33, },
+ { 38400, 25, 57, 57, 54, },
+ { 31250, 31, 70, 70, 68, },
+ { 28800, 34, 77, 77, 74, },
+ { 19200, 54, 117, 117, 114, },
+ { 14400, 74, 156, 156, 153, },
+ { 9600, 114, 236, 236, 233, },
+ { 4800, 233, 474, 474, 471, },
+ { 2400, 471, 950, 950, 947, },
+ { 1200, 947, 1902, 1902, 1899, },
+ { 300, 3804, 7617, 7617, 7614, },
+};
+
+const int XMIT_START_ADJUSTMENT = 5;
+
+#elif F_CPU == 8000000
+
+static const DELAY_TABLE table[] PROGMEM =
+{
+ // baud rxcenter rxintra rxstop tx
+ { 115200, 1, 5, 5, 3, },
+ { 57600, 1, 15, 15, 13, },
+ { 38400, 2, 25, 26, 23, },
+ { 31250, 7, 32, 33, 29, },
+ { 28800, 11, 35, 35, 32, },
+ { 19200, 20, 55, 55, 52, },
+ { 14400, 30, 75, 75, 72, },
+ { 9600, 50, 114, 114, 112, },
+ { 4800, 110, 233, 233, 230, },
+ { 2400, 229, 472, 472, 469, },
+ { 1200, 467, 948, 948, 945, },
+ { 300, 1895, 3805, 3805, 3802, },
+};
+
+const int XMIT_START_ADJUSTMENT = 4;
+
+#elif F_CPU == 20000000
+
+// 20MHz support courtesy of the good people at macegr.com.
+// Thanks, Garrett!
+
+static const DELAY_TABLE PROGMEM table[] =
+{
+ // baud rxcenter rxintra rxstop tx
+ { 115200, 3, 21, 21, 18, },
+ { 57600, 20, 43, 43, 41, },
+ { 38400, 37, 73, 73, 70, },
+ { 31250, 45, 89, 89, 88, },
+ { 28800, 46, 98, 98, 95, },
+ { 19200, 71, 148, 148, 145, },
+ { 14400, 96, 197, 197, 194, },
+ { 9600, 146, 297, 297, 294, },
+ { 4800, 296, 595, 595, 592, },
+ { 2400, 592, 1189, 1189, 1186, },
+ { 1200, 1187, 2379, 2379, 2376, },
+ { 300, 4759, 9523, 9523, 9520, },
+};
+
+const int XMIT_START_ADJUSTMENT = 6;
+
+#else
+
+#error This version of GSM3SoftSerial supports only 20, 16 and 8MHz processors
+
+#endif
+
+GSM3SoftSerial* GSM3SoftSerial::_activeObject=0;
+
+GSM3SoftSerial::GSM3SoftSerial():
+ _rx_delay_centering(0),
+ _rx_delay_intrabit(0),
+ _rx_delay_stopbit(0),
+ _tx_delay(0),
+ cb(this)
+{
+ setTX();
+ setRX();
+ //comStatus=0;
+ //waitingAnswer=false;
+}
+
+int GSM3SoftSerial::begin(long speed)
+{
+ _rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
+
+ for (unsigned i=0; ifinalWrite(0x77);
+ return this->finalWrite(0xEE);
+ }
+
+ if(c==0x13)
+ {
+ this->finalWrite(0x77);
+ return this->finalWrite(0xEC);
+ }
+
+ if(c==0x77)
+ {
+ this->finalWrite(0x77);
+ return this->finalWrite(0x88);
+ }
+
+ return this->finalWrite(c);
+}
+
+size_t GSM3SoftSerial::finalWrite(uint8_t c)
+{
+
+ uint8_t oldSREG = SREG;
+ cli(); // turn off interrupts for a clean txmit
+
+ // Write the start bit
+ tx_pin_write(LOW);
+ tunedDelay(_tx_delay + XMIT_START_ADJUSTMENT);
+
+ // Write each of the 8 bits
+ for (byte mask = 0x01; mask; mask <<= 1)
+ {
+ if (c & mask) // choose bit
+ tx_pin_write(HIGH); // send 1
+ else
+ tx_pin_write(LOW); // send 0
+ tunedDelay(_tx_delay);
+ }
+
+ tx_pin_write(HIGH); // restore pin to natural state
+
+ SREG = oldSREG; // turn interrupts back on
+ tunedDelay(_tx_delay);
+
+ return 1;
+}
+
+/*inline*/ void GSM3SoftSerial::tunedDelay(uint16_t delay) {
+ uint8_t tmp=0;
+
+ asm volatile("sbiw %0, 0x01 \n\t"
+ "ldi %1, 0xFF \n\t"
+ "cpi %A0, 0xFF \n\t"
+ "cpc %B0, %1 \n\t"
+ "brne .-10 \n\t"
+ : "+r" (delay), "+a" (tmp)
+ : "0" (delay)
+ );
+}
+
+void GSM3SoftSerial::tx_pin_write(uint8_t pin_state)
+{
+ // Direct port manipulation is faster than digitalWrite/Read
+ if (pin_state == LOW)
+ *_transmitPortRegister &= ~_transmitBitMask;
+ else
+ *_transmitPortRegister |= _transmitBitMask;
+}
+
+void GSM3SoftSerial::setTX()
+{
+ pinMode(__TXPIN__, OUTPUT);
+ digitalWrite(__TXPIN__, HIGH);
+ // For digital port direct manipulation
+ _transmitBitMask = digitalPinToBitMask(__TXPIN__);
+ uint8_t port = digitalPinToPort(__TXPIN__);
+ _transmitPortRegister = portOutputRegister(port);
+}
+
+void GSM3SoftSerial::setRX()
+{
+ pinMode(__RXPIN__, INPUT);
+ digitalWrite(__RXPIN__, HIGH); // pullup for normal logic!
+ // For digital port direct manipulation
+ _receiveBitMask = digitalPinToBitMask(__RXPIN__);
+ uint8_t port = digitalPinToPort(__RXPIN__);
+ _receivePortRegister = portInputRegister(port);
+
+#ifdef __AVR_ATmega32U4__
+//#define __RXINT__ 1
+ attachInterrupt(__RXINT__, GSM3SoftSerial::handle_interrupt, FALLING);
+#endif
+ // This line comes from the High Middle Ages...
+ // attachInterrupt(__RXINT__, GSM3SoftSerial::handle_interrupt, FALLING);
+}
+
+void GSM3SoftSerial::handle_interrupt()
+{
+ if(_activeObject)
+ _activeObject->recv();
+}
+
+uint8_t GSM3SoftSerial::rx_pin_read()
+{
+ // Digital port manipulation
+ return *_receivePortRegister & _receiveBitMask;
+}
+
+void GSM3SoftSerial::recv()
+{
+
+#if GCC_VERSION < 40302
+// Work-around for avr-gcc 4.3.0 OSX version bug
+// Preserve the registers that the compiler misses
+// (courtesy of Arduino forum user *etracer*)
+ asm volatile(
+ "push r18 \n\t"
+ "push r19 \n\t"
+ "push r20 \n\t"
+ "push r21 \n\t"
+ "push r22 \n\t"
+ "push r23 \n\t"
+ "push r26 \n\t"
+ "push r27 \n\t"
+ ::);
+#endif
+
+ bool firstByte=true;
+ byte thisHead;
+
+ uint8_t d = 0;
+ bool morebytes=false;
+ //bool fullbuffer=(cb.availableBytes()<3);
+ bool fullbuffer;
+ bool capturado_fullbuffer = 0;
+ int i;
+ byte oldTail;
+
+ // If RX line is high, then we don't see any start bit
+ // so interrupt is probably not for us
+ if (!rx_pin_read())
+ {
+ do
+ {
+ oldTail=cb.getTail();
+ // Wait approximately 1/2 of a bit width to "center" the sample
+ tunedDelay(_rx_delay_centering);
+
+ fullbuffer=(cb.availableBytes()<6);
+
+
+ if(fullbuffer&&(!capturado_fullbuffer))
+ tx_pin_write(LOW);
+
+
+ // Read each of the 8 bits
+ for (uint8_t i=0x1; i; i <<= 1)
+ {
+ tunedDelay(_rx_delay_intrabit);
+ uint8_t noti = ~i;
+ if (rx_pin_read())
+ d |= i;
+ else // else clause added to ensure function timing is ~balanced
+ d &= noti;
+
+ if(fullbuffer&&(!capturado_fullbuffer))
+ {
+ if((uint8_t)__XOFF__ & i)
+ tx_pin_write(HIGH);
+ else
+ tx_pin_write(LOW);
+ }
+ }
+
+ if(fullbuffer&&(!capturado_fullbuffer))
+ {
+ tunedDelay(_rx_delay_intrabit);
+ tx_pin_write(HIGH);
+ }
+
+ // So, we know the buffer is full, and we have sent a XOFF
+ if (fullbuffer)
+ {
+ capturado_fullbuffer =1;
+ _flags |=_GSMSOFTSERIALFLAGS_SENTXOFF_;
+ }
+
+
+ // skip the stop bit
+ if (!fullbuffer) tunedDelay(_rx_delay_stopbit);
+
+ if(keepThisChar(&d))
+ {
+ cb.write(d);
+ if(firstByte)
+ {
+ firstByte=false;
+ thisHead=cb.getTail();
+ }
+ }
+
+
+ // This part is new. It is used to detect the end of a "paragraph"
+ // Caveat: the old fashion would let processor a bit of time between bytes,
+ // that here is lost
+ // This active waiting avoids drifting
+ morebytes=false;
+ // TO-DO. This PARAGRAPHGUARD is empyric. We should test it for every speed
+ for(i=0;i<__PARAGRAPHGUARD__;i++)
+ {
+ tunedDelay(1);
+ if(!rx_pin_read())
+ {
+ morebytes=true;
+ break;
+ }
+ }
+ }while(morebytes);
+ // If we find a line feed, we are at the end of a paragraph
+ // check!
+
+ if (fullbuffer)
+ {
+ // And... go handle it!
+ if(mgr)
+ mgr->manageMsg(thisHead, cb.getTail());
+ }
+ else if(d==10)
+ {
+ // And... go handle it!
+ if(mgr)
+ mgr->manageMsg(thisHead, cb.getTail());
+ }
+ else if (d==32)
+ {
+ // And... go handle it!
+ if(mgr)
+ mgr->manageMsg(thisHead, cb.getTail());
+ }
+ }
+
+#if GCC_VERSION < 40302
+// Work-around for avr-gcc 4.3.0 OSX version bug
+// Restore the registers that the compiler misses
+ asm volatile(
+ "pop r27 \n\t"
+ "pop r26 \n\t"
+ "pop r23 \n\t"
+ "pop r22 \n\t"
+ "pop r21 \n\t"
+ "pop r20 \n\t"
+ "pop r19 \n\t"
+ "pop r18 \n\t"
+ ::);
+#endif
+}
+
+bool GSM3SoftSerial::keepThisChar(uint8_t* c)
+{
+ // Horrible things for Quectel XON/XOFF
+ // 255 is the answer to a XOFF
+ // It comes just once
+ if((*c==255)&&(_flags & _GSMSOFTSERIALFLAGS_SENTXOFF_))
+ {
+ _flags ^= _GSMSOFTSERIALFLAGS_SENTXOFF_;
+ return false;
+ }
+
+ // 0x77, w, is the escape character
+ if(*c==0x77)
+ {
+ _flags |= _GSMSOFTSERIALFLAGS_ESCAPED_;
+ return false;
+ }
+
+ // and these are the escaped codes
+ if(_flags & _GSMSOFTSERIALFLAGS_ESCAPED_)
+ {
+ if(*c==0xEE)
+ *c=0x11;
+ else if(*c==0xEC)
+ *c=0x13;
+ else if(*c==0x88)
+ *c=0x77;
+
+ _flags ^= _GSMSOFTSERIALFLAGS_ESCAPED_;
+ return true;
+ }
+
+ return true;
+}
+
+void GSM3SoftSerial::spaceAvailable()
+{
+ // If there is spaceAvailable in the buffer, lets send a XON
+ finalWrite((byte)__XON__);
+}
+
+
+// This is here to avoid problems with Arduino compiler
+void GSM3SoftSerialMgr::manageMsg(byte from, byte to){};
+
+//#define PCINT1_vect _VECTOR(2)
+//#undef PCINT1_vect
+
+#if defined(PCINT0_vect)
+ISR(PCINT0_vect)
+{
+ GSM3SoftSerial::handle_interrupt();
+}
+#endif
+
+#if defined(PCINT1_vect)
+ISR(PCINT1_vect)
+{
+ GSM3SoftSerial::handle_interrupt();
+}
+#endif
+
+#if defined(PCINT2_vect)
+ISR(PCINT2_vect)
+{
+ GSM3SoftSerial::handle_interrupt();
+}
+#endif
+
+#if defined(PCINT3_vect)
+ISR(PCINT3_vect)
+{
+ GSM3SoftSerial::handle_interrupt();
+}
+#endif
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SoftSerial.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SoftSerial.h
new file mode 100644
index 00000000..538f40d0
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3SoftSerial.h
@@ -0,0 +1,174 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef __GSM3_SOFTSERIAL__
+#define __GSM3_SOFTSERIAL__
+
+// An adaptation of NewSoftSerial for Modem Shields
+// Assumes directly that Serial is attached to Pins 2 and 3, not inverse
+// We are implementing it because NewSoftSerial does not deal correctly with floods
+// of data
+#include "GSM3CircularBuffer.h"
+#include
+
+/*
+#define _COMSTATUS_ANSWERRECEIVED_ 0x100
+#define _COMSTATUS_SMSRECEIVED_ 0x80
+#define _COMSTATUS_CALLRECEIVED_ 0x40
+
+// PLEASE, when accessing the sockets use "for" and >> (bitwise operator)
+#define _COMSTATUS_SOCKET6RECEIVED_ 0x20
+#define _COMSTATUS_SOCKET5RECEIVED_ 0x10
+#define _COMSTATUS_SOCKET4RECEIVED_ 0x08
+#define _COMSTATUS_SOCKET3RECEIVED_ 0x04
+#define _COMSTATUS_SOCKET2RECEIVED_ 0x02
+#define _COMSTATUS_SOCKET1RECEIVED_ 0x01
+
+#define __CALLTABLEMASK__ 0x3
+*/
+
+class GSM3SoftSerialMgr
+{
+ public:
+
+ /** Manages soft serial message
+ @param from Initial byte
+ @param to Final byte
+ */
+ virtual void manageMsg(byte from, byte to);
+};
+
+// This class manages software serial communications
+// Changing it so it doesn't know about modems or whatever
+
+class GSM3SoftSerial : public GSM3CircularBufferManager
+{
+ private:
+
+ uint8_t _receiveBitMask;
+ volatile uint8_t *_receivePortRegister;
+ uint8_t _transmitBitMask;
+ volatile uint8_t *_transmitPortRegister;
+
+ static GSM3SoftSerial* _activeObject;
+ GSM3SoftSerialMgr* mgr;
+
+ uint16_t _rx_delay_centering;
+ uint16_t _rx_delay_intrabit;
+ uint16_t _rx_delay_stopbit;
+ uint16_t _tx_delay;
+ uint8_t _flags;
+
+ /** Write in tx_pin
+ @param pin_state Pin state
+ */
+ void tx_pin_write(uint8_t pin_state);
+
+ /** Set transmission
+ */
+ void setTX();
+
+ /** Set receiver
+ */
+ void setRX();
+
+ /** Receive
+ */
+ void recv();
+
+ /** Read from rx_pin
+ @return receive bit mask
+ */
+ uint8_t rx_pin_read();
+
+ void setComsReceived();
+
+ /** Write a character in serial connection, final action after escaping
+ @param c Character
+ @return 1 if succesful, 0 if transmission delay = 0
+ */
+ virtual size_t finalWrite(uint8_t);
+
+ /** Decide, attending to escapes, if the received character should we
+ kept, forgotten, or changed
+ @param c Character, may be changed
+ @return 1 if shall be kept, 0 if forgotten
+ */
+ bool keepThisChar(uint8_t* c);
+
+ // Checks the buffer for well-known events.
+ //bool recognizeUnsolicitedEvent(byte oldTail);
+
+ public:
+
+ /** Tuned delay in microcontroller
+ @param delay Time to delay
+ */
+ static /*inline */void tunedDelay(uint16_t delay);
+
+ GSM3CircularBuffer cb; // Circular buffer
+
+ /** Register serial manager
+ @param manager Serial manager
+ */
+ inline void registerMgr(GSM3SoftSerialMgr* manager){mgr=manager;};
+
+ /** If there is spaceAvailable in the buffer, lets send a XON
+ */
+ void spaceAvailable();
+
+ /** Write a character in serial connection
+ @param c Character
+ @return 1 if succesful, 0 if transmission delay = 0
+ */
+ virtual size_t write(uint8_t);
+
+ /** Constructor */
+ GSM3SoftSerial();
+
+ /** Establish serial connection
+ @param speed Baudrate
+ @return
+ */
+ int begin(long speed);
+
+ /** Manage interruptions
+ */
+ static inline void handle_interrupt();
+
+ /** Close serial connection
+ */
+ void close();
+};
+
+#endif
\ No newline at end of file
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3VoiceCallService.cpp b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3VoiceCallService.cpp
new file mode 100644
index 00000000..d931d183
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3VoiceCallService.cpp
@@ -0,0 +1,144 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#include
+#include
+
+#include
+GSM3ShieldV1VoiceProvider theShieldV1VoiceProvider;
+
+// While there is only a shield (ShieldV1) we will include it by default
+
+#define GSM3VOICECALLSERVICE_SYNCH 0x01 // 1: synchronous 0: asynchronous
+#define __TOUT__ 10000
+
+
+
+
+GSM3VoiceCallService::GSM3VoiceCallService(bool synch)
+{
+ if(synch)
+ flags |= GSM3VOICECALLSERVICE_SYNCH;
+ theGSM3MobileVoiceProvider->initialize();
+}
+
+GSM3_voiceCall_st GSM3VoiceCallService::getvoiceCallStatus()
+{
+ if(theGSM3MobileVoiceProvider==0)
+ return IDLE_CALL;
+
+ return theGSM3MobileVoiceProvider->getvoiceCallStatus();
+}
+
+int GSM3VoiceCallService::ready()
+{
+ if(theGSM3MobileVoiceProvider==0)
+ return 0;
+
+ return theGSM3MobileVoiceProvider->ready();
+}
+
+int GSM3VoiceCallService::voiceCall(const char* to, unsigned long timeout)
+{
+ if(theGSM3MobileVoiceProvider==0)
+ return 0;
+
+ if(flags & GSM3VOICECALLSERVICE_SYNCH )
+ {
+ theGSM3MobileVoiceProvider->voiceCall(to);
+ unsigned long m;
+ m=millis();
+ // Wait an answer for timeout
+ while(((millis()-m)< timeout )&&(getvoiceCallStatus()==CALLING))
+ delay(100);
+
+ if(getvoiceCallStatus()==TALKING)
+ return 1;
+ else
+ return 0;
+ }
+ else
+ {
+ return theGSM3MobileVoiceProvider->voiceCall(to);
+ }
+
+}
+
+int GSM3VoiceCallService::answerCall()
+{
+ if(theGSM3MobileVoiceProvider==0)
+ return 0;
+
+ return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->answerCall());
+}
+
+int GSM3VoiceCallService::hangCall()
+{
+ if(theGSM3MobileVoiceProvider==0)
+ return 0;
+
+ return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->hangCall());
+}
+
+int GSM3VoiceCallService::retrieveCallingNumber(char* buffer, int bufsize)
+{
+ if(theGSM3MobileVoiceProvider==0)
+ return 0;
+
+ return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->retrieveCallingNumber(buffer, bufsize));
+}
+
+int GSM3VoiceCallService::waitForAnswerIfNeeded(int returnvalue)
+{
+ // If synchronous
+ if(flags & GSM3VOICECALLSERVICE_SYNCH )
+ {
+ unsigned long m;
+ m=millis();
+ // Wait for __TOUT__
+ while(((millis()-m)< __TOUT__ )&&(ready()==0))
+ delay(100);
+ // If everything was OK, return 1
+ // else (timeout or error codes) return 0;
+ if(ready()==1)
+ return 1;
+ else
+ return 0;
+ }
+ // If not synchronous just kick ahead the coming result
+ return ready();
+}
+
+
+
+
diff --git a/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3VoiceCallService.h b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3VoiceCallService.h
new file mode 100644
index 00000000..c5486583
--- /dev/null
+++ b/Symfony/src/Codebender/LibraryBundle/Resources/library_files_new/GSM/default/GSM3VoiceCallService.h
@@ -0,0 +1,102 @@
+/*
+This file is part of the GSM3 communications library for Arduino
+-- Multi-transport communications platform
+-- Fully asynchronous
+-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
+-- Voice calls
+-- SMS
+-- TCP/IP connections
+-- HTTP basic clients
+
+This library has been developed by Telefónica Digital - PDI -
+- Physical Internet Lab, as part as its collaboration with
+Arduino and the Open Hardware Community.
+
+September-December 2012
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+The latest version of this library can always be found at
+https://github.com/BlueVia/Official-Arduino
+*/
+#ifndef _GSM3VOICECALLSERVICE_
+#define _GSM3VOICECALLSERVICE_
+
+#include