Skip to content

Commit

Permalink
Arduino library format is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Mar 20, 2016
1 parent 1859fb4 commit 4af03fb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 50 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OS ?= os/linux
DESTDIR ?=
BLD ?= bld

VERSION=0.1.1
VERSION=0.1.2

ifeq ($(TINYCONF), nano)
CONFIG_ENABLE_FCS32 ?= n
Expand Down Expand Up @@ -158,14 +158,15 @@ ARDUINO_BASE_DIR=./src/arduino
ARDUINO_NANO_DIR=./releases/arduino/$(ARDUINO_NANO_LIB)
ARDUINO_MICRO_DIR=./releases/arduino/$(ARDUINO_MICRO_LIB)
ARDUINO_FULL_DIR=./releases/arduino/$(ARDUINO_FULL_LIB)

ARDUINO_BASE_URL=https://github.com/lexus2k/tinyproto/tree/master/releases/arduino

arduino-nano:
@mkdir -p $(ARDUINO_NANO_DIR)
@cp -rf -L $(ARDUINO_BASE_DIR)/* $(ARDUINO_NANO_DIR)/
@echo "#define CONFIG_ENABLE_CHECKSUM" > $(ARDUINO_NANO_DIR)/src/proto/tiny_config.h
@sed -i "s/VERSION/$(VERSION)/" $(ARDUINO_NANO_DIR)/library.properties
@sed -i "s/LIBRARY/$(ARDUINO_NANO_LIB)/" $(ARDUINO_NANO_DIR)/library.properties
@sed -i "s,ADDRESS,$(ARDUINO_BASE_URL)/$(ARDUINO_NANO_LIB),g" $(ARDUINO_NANO_DIR)/library.properties
@mv $(ARDUINO_NANO_DIR)/src/$(ARDUINO_BASE_LIB).h $(ARDUINO_NANO_DIR)/src/$(ARDUINO_NANO_LIB).h
@sed -i "s/$(ARDUINO_BASE_LIB).h/$(ARDUINO_NANO_LIB).h/" $(ARDUINO_NANO_DIR)/src/TinyProtocol.cpp

Expand All @@ -176,6 +177,7 @@ arduino-micro:
@echo "#define CONFIG_ENABLE_FCS16" >> $(ARDUINO_MICRO_DIR)/src/proto/tiny_config.h
@sed -i "s/VERSION/$(VERSION)/" $(ARDUINO_MICRO_DIR)/library.properties
@sed -i "s/LIBRARY/$(ARDUINO_MICRO_LIB)/" $(ARDUINO_MICRO_DIR)/library.properties
@sed -i "s,ADDRESS,$(ARDUINO_BASE_URL)/$(ARDUINO_MICRO_LIB),g" $(ARDUINO_MICRO_DIR)/library.properties
@mv $(ARDUINO_MICRO_DIR)/src/$(ARDUINO_BASE_LIB).h $(ARDUINO_MICRO_DIR)/src/$(ARDUINO_MICRO_LIB).h
@sed -i "s/$(ARDUINO_BASE_LIB).h/$(ARDUINO_MICRO_LIB).h/" $(ARDUINO_MICRO_DIR)/src/TinyProtocol.cpp

Expand All @@ -188,6 +190,7 @@ arduino-full:
@echo "#define CONFIG_ENABLE_STATS" >> $(ARDUINO_FULL_DIR)/src/proto/tiny_config.h
@sed -i "s/VERSION/$(VERSION)/" $(ARDUINO_FULL_DIR)/library.properties
@sed -i "s/LIBRARY/$(ARDUINO_FULL_LIB)/" $(ARDUINO_FULL_DIR)/library.properties
@sed -i "s,ADDRESS,$(ARDUINO_BASE_URL)/$(ARDUINO_FULL_LIB),g" $(ARDUINO_FULL_DIR)/library.properties
@mv $(ARDUINO_FULL_DIR)/src/$(ARDUINO_BASE_LIB).h $(ARDUINO_FULL_DIR)/src/$(ARDUINO_FULL_LIB).h
@sed -i "s/$(ARDUINO_BASE_LIB).h/$(ARDUINO_FULL_LIB).h/" $(ARDUINO_FULL_DIR)/src/TinyProtocol.cpp

Expand Down
4 changes: 2 additions & 2 deletions releases/arduino/TinyProto-Full/library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=TinyProto-Full
version=0.1.1
version=0.1.2
author=Alexey Dynda
maintainer=Alexey Dynda <[email protected]>
sentence=Allows to communicate other boards/PC via any physical connection.
paragraph=Using this library you can easy communicate your Arduino with applications on PC and other boards. You don't need to think about data synchronization between points.
category=Communication
url=https://github.com/lexus2k/tinyproto
url=https://github.com/lexus2k/tinyproto/tree/master/releases/arduino/TinyProto-Full
architectures=*
4 changes: 2 additions & 2 deletions releases/arduino/TinyProto-Micro/library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=TinyProto-Micro
version=0.1.1
version=0.1.2
author=Alexey Dynda
maintainer=Alexey Dynda <[email protected]>
sentence=Allows to communicate other boards/PC via any physical connection.
paragraph=Using this library you can easy communicate your Arduino with applications on PC and other boards. You don't need to think about data synchronization between points.
category=Communication
url=https://github.com/lexus2k/tinyproto
url=https://github.com/lexus2k/tinyproto/tree/master/releases/arduino/TinyProto-Micro
architectures=*
4 changes: 2 additions & 2 deletions releases/arduino/TinyProto-Nano/library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=TinyProto-Nano
version=0.1.1
version=0.1.2
author=Alexey Dynda
maintainer=Alexey Dynda <[email protected]>
sentence=Allows to communicate other boards/PC via any physical connection.
paragraph=Using this library you can easy communicate your Arduino with applications on PC and other boards. You don't need to think about data synchronization between points.
category=Communication
url=https://github.com/lexus2k/tinyproto
url=https://github.com/lexus2k/tinyproto/tree/master/releases/arduino/TinyProto-Nano
architectures=*
2 changes: 1 addition & 1 deletion src/arduino/library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ maintainer=Alexey Dynda <[email protected]>
sentence=Allows to communicate other boards/PC via any physical connection.
paragraph=Using this library you can easy communicate your Arduino with applications on PC and other boards. You don't need to think about data synchronization between points.
category=Communication
url=https://github.com/lexus2k/tinyproto
url=ADDRESS
architectures=*
88 changes: 47 additions & 41 deletions src/lib/tiny_layer2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
*/

#include "tiny_layer2.h"
#include "crc.h"
#include "tiny_layer2.h"

#ifdef CONFIG_ENABLE_STATS
#define STATS(x) x
Expand Down Expand Up @@ -86,7 +86,7 @@ inline static int __check_fcs_field(uint8_t fcs_bits, fcs_t fcs)
#ifdef CONFIG_ENABLE_CHECKSUM
if ((fcs_bits == 8) && (fcs == GOODCHECKSUM)) return 1;
#endif
return 0;
return fcs_bits == 0;
}


Expand Down Expand Up @@ -236,27 +236,21 @@ int tiny_close(STinyData *handle)

int tiny_set_fcs_bits(STinyData *handle, uint8_t bits)
{
int result;
int result = TINY_NO_ERROR;
switch (bits)
{
#ifdef CONFIG_ENABLE_FCS16
case 16:
handle->fcs_bits = bits;
result = TINY_NO_ERROR;
break;
#endif
#ifdef CONFIG_ENABLE_FCS32
case 32:
handle->fcs_bits = bits;
result = TINY_NO_ERROR;
break;
#endif
#ifdef CONFIG_ENABLE_CHECKSUM
case 8:
#endif
case 0:
handle->fcs_bits = bits;
result = TINY_NO_ERROR;
break;
#endif
default:
result = TINY_ERR_FAILED;
break;
Expand Down Expand Up @@ -360,27 +354,37 @@ static int __send_frame_uid_state(STinyData *handle)
}


/**
* This is handler for SEND DATA state. It switches to
* TINY_TX_STATE_END only if all bytes are sent.
* If next byte is successfully sent, it returns 1.
* If switched to other state, it returns 1.
* If no byte is sent during the cycle, it returns 0.
* If error happened, it returns negative value.
* @param handle - pointer to Tiny Protocol structure
*/
static int __send_frame_data_state(STinyData *handle)
{
int result;
uint8_t byte;
if (handle->tx.sentbytes >= handle->tx.framelen)
{
__commit_fcs_field(handle->fcs_bits, &handle->tx.fcs);
#ifdef TINY_FCS_ENABLE
/* sending crc */
handle->tx.inprogress = handle->fcs_bits ? TINY_TX_STATE_SEND_CRC : TINY_TX_STATE_END;
handle->tx.bits = 0;
#else
handle->tx.inprogress = TINY_TX_STATE_END;
#endif
return 1;
}
byte = handle->tx.pframe[handle->tx.sentbytes];
result = __send_byte_state(handle, byte);
if (result > 0)
{
__update_fcs_field(handle->fcs_bits, &handle->tx.fcs, byte);
handle->tx.sentbytes++;
if (handle->tx.sentbytes == handle->tx.framelen)
{
__commit_fcs_field(handle->fcs_bits, &handle->tx.fcs);
#ifdef TINY_FCS_ENABLE
/* sending crc */
handle->tx.inprogress = handle->fcs_bits ? TINY_TX_STATE_SEND_CRC : TINY_TX_STATE_END;
handle->tx.bits = 0;
#else
handle->tx.inprogress = TINY_TX_STATE_END;
#endif
}
}
return result;
}
Expand Down Expand Up @@ -489,7 +493,10 @@ static int __wait_send_complete(STinyData *handle, uint8_t *pbuf, uint8_t flags)
return result;
}
#else
#define __wait_send_complete(handle, pbuf, flags) 0
#define __wait_send_complete(handle, pbuf, flags) \
0; \
handle->tx.pframe = pbuf; \
handle->tx.inprogress = TINY_TX_STATE_START;
#endif


Expand Down Expand Up @@ -526,7 +533,7 @@ int tiny_send(STinyData *handle, uint16_t *uid, uint8_t * pbuf, int len, uint8_t
do
{
result = __tiny_send_data(handle);
if (result != 0)
if ((result != 0) || (handle->tx.inprogress == TINY_TX_STATE_IDLE))
{
/* exit on error and on successful send */
break;
Expand Down Expand Up @@ -692,7 +699,7 @@ static int __tiny_read_data(STinyData *handle, uint16_t *uid, uint8_t *pbuf, int

int tiny_read(STinyData *handle, uint16_t *uid, uint8_t *pbuf, int len, uint8_t flags)
{
int result;
int result = TINY_NO_ERROR;
uint8_t byte;

if (!handle)
Expand All @@ -710,21 +717,8 @@ int tiny_read(STinyData *handle, uint16_t *uid, uint8_t *pbuf, int len, uint8_t
# else
result = handle->read_func(&byte, 1);
# endif
if (result<0)
{
result = TINY_ERR_FAILED;
break;
}
/* if no data on UART, just exit */
if (result == 0)
{
result = TINY_NO_ERROR;
if (!(flags & TINY_FLAG_WAIT_FOREVER))
{
break;
}
}
else /* Byte is received */
/* Byte is received */
if (result > 0)
{
/* New frame must be started with 0x7E char */
if (byte != FLAG_SEQUENCE)
Expand All @@ -739,11 +733,23 @@ int tiny_read(STinyData *handle, uint16_t *uid, uint8_t *pbuf, int len, uint8_t
handle->rx.prevbyte = byte;
__init_fcs_field(handle->fcs_bits, &handle->rx.fcs);
}
else if (result<0)
{
result = TINY_ERR_FAILED;
break;
}
}
/* Some frame is in process of receiving. Continue to parse data */
result = __tiny_read_data(handle, uid, pbuf, len);
if (handle->rx.inprogress != TINY_RX_STATE_IDLE)
{
result = __tiny_read_data(handle, uid, pbuf, len);
}
if (result == 0)
{
if (!(flags & TINY_FLAG_WAIT_FOREVER))
{
break;
}
TASK_YIELD();
}
}
Expand Down

0 comments on commit 4af03fb

Please sign in to comment.