Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Baba committed Jul 24, 2016
2 parents 4373a29 + 9d962dd commit d406840
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# candy-board-amt

[![GitHub release](https://img.shields.io/github/release/CANDY-LINE/candy-board-amt.svg)](https://github.com/CANDY-LINE/candy-board-amt/releases/latest)
[![Build Status](https://travis-ci.org/CANDY-LINE/candy-board-amt.svg?branch=master)](https://travis-ci.org/CANDY-LINE/candy-board-amt)
[![License BSD3](https://img.shields.io/github/license/CANDY-LINE/candy-board-amt.svg)](http://opensource.org/licenses/BSD-3-Clause)

Base CANDY LINE boards service for AM Telecom Modules
Expand All @@ -17,13 +18,27 @@ $ pip install candy-board-amt
$ pip candy-board-amt
```

## Local Installation test
## Development

### Prerequisites

* [pandoc](http://pandoc.org)
* [pypandoc](https://pypi.python.org/pypi/pypandoc/1.2.0)

On Mac OS:

```
$ brew install pandoc
$ pip install pypandoc
```

### Local Installation test

```
$ ./setup.py install --record files.txt
```

## Local Uninstallation test
### Local Uninstallation test

```
$ cat files.txt | xargs rm -rf
Expand All @@ -37,6 +52,9 @@ $ ./setup.py test

# Revision history

* 1.0.0
- Initial public release

* 0.1.1-0.1.3
- Fix resolve_modem_port()

Expand Down
49 changes: 39 additions & 10 deletions lib/candy_board_amt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def run(self):

def perform(self, cmd):
try:
if cmd['category'][0] == '_':
raise AttributeError()
m = getattr(self.__class__, "%s_%s" % (cmd['category'], cmd['action']))
return m(self, cmd)
except AttributeError:
Expand All @@ -224,8 +226,6 @@ def send_at(self, cmd):
self.serial.write(line)
time.sleep(0.1)
self.read_line() # echo back
self.read_line() # empty line
self.read_line() # empty line
result = ""
status = None
while not status:
Expand All @@ -240,7 +240,7 @@ def send_at(self, cmd):
print("cmd:[%s] => status:[%s], result:[%s]" % (cmd, status, result))
return (status, result.strip())

def apn_ls(self, cmd):
def _apn_ls(self):
status, result = self.send_at("AT+CGDCONT?")
apn_list = []
if status == "OK":
Expand All @@ -266,7 +266,10 @@ def apn_ls(self, cmd):
'apns': apn_list
}
}
return json.dumps(message)
return message

def apn_ls(self, cmd):
return json.dumps(self._apn_ls())

def apn_set(self, cmd):
(name, user_id, password) = (cmd['name'], cmd['user_id'], cmd['password'])
Expand All @@ -282,16 +285,19 @@ def apn_set(self, cmd):
}
return json.dumps(message)

def apn_del(self, cmd):
apn_id = "1"
if 'apn_id' in cmd:
apn_id = cmd['apn_id']
def _apn_del(self, apn_id):
status, result = self.send_at("AT+CGDCONT=%s" % apn_id) # removes QCPDPP as well
message = {
'status': status,
'result': result
}
return json.dumps(message)
return message

def apn_del(self, cmd):
apn_id = "1"
if 'apn_id' in cmd:
apn_id = cmd['apn_id']
return json.dumps(self._apn_del(apn_id))

def network_show(self, cmd):
status, result = self.send_at("AT+CSQ")
Expand Down Expand Up @@ -380,12 +386,35 @@ def modem_enable_ecm(self, cmd):
}
return json.dumps(message)

def modem_enable_acm(self, cmd):
def _modem_enable_acm(self):
status, result = self.send_at("AT@USBCHG=ACM") # modem will reboot, @AUTOCONN=0
message = {
'status': status,
'result': result
}
return message

def modem_enable_acm(self, cmd):
return json.dumps(self._modem_enable_acm())

def modem_reset(self, cmd):
"""
- Remove all APN
- Change USB mode to ACM
"""
apn_ls_ret = self._apn_ls()
status = apn_ls_ret['status']
result = ''
if apn_ls_ret['status'] == "OK":
apns = apn_ls_ret['result']['apns']
for apn in apns:
self._apn_del(apn['apn_id'])
modem_enable_acm_ret = self._modem_enable_acm()
status = modem_enable_acm_ret['status']
message = {
'status': status,
'result': result
}
return json.dumps(message)

def service_version(self, cmd):
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import os
import sys
import pypandoc
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand

version = "0.1.3"
version = "1.0.0"

class PyTest(TestCommand):
def finalize_options(self):
Expand All @@ -31,13 +32,13 @@ def run_tests(self):
url='http://github.com/CANDY-LINE/candy-board-amt',
download_url='https://github.com/CANDY-LINE/candy-board-amt/tarball/{0}'.format(version),
description='Base CANDY LINE boards service for AM Telecom Modules',
long_description=open('README.md').read() + '\n\n' + open('LICENSE').read(),
long_description=pypandoc.convert('README.md', 'rst'),
packages=find_packages('lib'),
package_dir={'': 'lib'},
license='BSD3',
classifiers=[
'Programming Language :: Python',
'Development Status :: 3 - Alpha',
'Development Status :: 5 - Production/Stable',
'Natural Language :: English',
'Environment :: Console',
'Intended Audience :: System Administrators',
Expand Down
8 changes: 8 additions & 0 deletions tests/sock_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def test_perform_nok(setup_sock_server):
ret = setup_sock_server.perform({'category':'no-such-category', 'action':'no-such-action'})
assert ret == '{"status": "ERROR", "result": "Unknown Command"}'

def test_perform_nok(setup_sock_server):
ret = setup_sock_server.perform({'category':'_apn', 'action':'ls'})
assert ret == '{"status": "ERROR", "result": "Unknown Command"}'

def test_perform_nok2(setup_sock_server):
ret = setup_sock_server.perform({})
assert ret == '{"status": "ERROR", "result": "Invalid Args"}'
Expand Down Expand Up @@ -57,6 +61,10 @@ def test_modem_enable_ecm(setup_sock_server):
ret = setup_sock_server.perform({'category':'modem', 'action':'enable_acm'})
assert ret == '{"status": "OK", "result": ""}'

def test_modem_reset(setup_sock_server):
ret = setup_sock_server.perform({'category':'modem', 'action':'reset'})
assert ret == '{"status": "OK", "result": ""}'

def test_service_version(setup_sock_server):
ret = setup_sock_server.perform({'category':'service', 'action':'version'})
assert ret == '{"status": "OK", "result": {"version": "devel"}}'
Expand Down

0 comments on commit d406840

Please sign in to comment.