nakagawa kit emurator (add CR) BaudRate 115200,p20

Dependencies:   mbed NetServicesMin

Files at this revision

API Documentation at this revision

Comitter:
recotana
Date:
Thu Mar 22 14:35:48 2012 +0000
Child:
1:495adf710664
Commit message:

Changed in this revision

NetServicesMin.lib Show annotated file Show diff for this revision Revisions of this file
common/data_models.cpp Show annotated file Show diff for this revision Revisions of this file
common/data_models.h Show annotated file Show diff for this revision Revisions of this file
common/leds.cpp Show annotated file Show diff for this revision Revisions of this file
common/leds.h Show annotated file Show diff for this revision Revisions of this file
common/types.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetServicesMin.lib	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hlipka/code/NetServicesMin/#8b387bed54c2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/data_models.cpp	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,106 @@
+#include "types.h"
+#include "data_models.h"
+#include "EthernetNetIf.h"
+
+
+void initPayload(Payload *_payload)
+{
+    _payload->size=sizeof(Payload);
+    _payload->dummy = 0;
+    _payload->ftype = Ftype_Type_B;
+    
+    Frame *frame=&_payload->frame;
+    
+    for(int i=0 ; i < sizeof(frame->id.personalId) ; i++) frame->id.personalId[i]=0;
+    
+    frame->message.frameNumber=0xFFFF;
+    frame->message.device=SERVER;
+    frame->message.command=PING;
+    
+    for(int i=0 ; i < sizeof(_payload->frame.message.data) ; i++) _payload->frame.message.data[i]=0;
+}
+
+void payloadToNetwork(Payload *_payload)
+{
+    Frame *frame=&_payload->frame;
+    _payload->size                  = htons(_payload->size);
+    frame->id.head               = htons(frame->id.head);
+    frame->message.totalSize     = htons(frame->message.totalSize);
+    frame->message.frameNumber   = htons(frame->message.frameNumber);
+    
+}
+void networkToPayload(Payload *_payload)
+{
+    Frame *frame=&_payload->frame;
+    _payload->size                  = ntohs(_payload->size);
+    frame->id.head               = ntohs(frame->id.head);
+    frame->message.totalSize     = ntohs(frame->message.totalSize);
+    frame->message.frameNumber   = ntohs(frame->message.frameNumber);
+}
+
+void initTestPayloadData(Payload *_payload)
+{
+   Frame *frame=&_payload->frame;
+   
+   initPayload(_payload);
+   _payload->size=sizeof(Payload);
+   
+   frame->id.head=0x0000;
+   uint8_t tmpid[14]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44};
+   for(int i=0;i<sizeof(tmpid);i++) frame->id.personalId[i]=tmpid[i];
+   
+   
+   frame->message.frameNumber=1;
+   frame->message.device=LED_SENDER;
+   frame->message.command=SEND_SINGLE;
+   
+   uint8_t tmpdata[42]={
+    1,2,3,4,5,6,7,8,9,10,
+    11,12,13,14,15,16,17,18,19,20,
+    21,22,23,24,25,26,27,28,29,30,
+    31,32,33,34,35,36,37,38,39,40,
+    41,42};
+   for(int i=0;i<sizeof(tmpdata);i++) frame->message.data[i]=tmpdata[i];
+   
+   frame->message.totalSize=
+     sizeof(frame->message.totalSize)
+    +sizeof(frame->message.frameNumber)
+    +sizeof(frame->message.device)
+    +sizeof(frame->message.command)
+    +sizeof(frame->message.data);
+
+}
+
+
+void dumpPayload(Payload *_payload)
+{
+    Frame *frame=&_payload->frame;
+    printf("\r\n======== dump!!\r\n");
+    printf("payload\nsize:%04X\r\n ",_payload->size);
+    printf("Type:%0X\r\n ",_payload->ftype);
+    
+    printf("Payload id_head:%04X\r\n personal id:",_payload->frame.id.head);  
+    for(int i=0 ; i < sizeof(frame->id.personalId) ; i++){
+        printf("%d:%02X ",i,frame->id.personalId[i]);
+    }
+    
+    printf("\r\n");
+    
+    printf("total size:%d , frame number:%d , divece:%0X , command:%02X\r\n"
+        ,frame->message.totalSize
+        ,frame->message.frameNumber
+        ,frame->message.device
+        ,frame->message.command);
+    
+    printf("message data:\r\n");
+    for(int i=0 ; i < sizeof(frame->message.data) ; i++){
+         printf("%d:%02X ",i,_payload->frame.message.data[i]);
+    }
+    
+    printf("\r\n--- RAW DATA -------\r\n");
+    for(int i=0 ; i < sizeof(Payload) ; i++){
+         printf("%d:%02X ",i,((uint8_t*)_payload)[i]);
+    }
+    printf("\r\n");
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/data_models.h	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,71 @@
+#ifndef _DATA_MODELS_
+#define _DATA_MODELS_
+
+#include "types.h"
+
+//frame type 
+typedef enum{
+    Ftype_NoID  =0,
+    Ftype_Type_A=1,
+    Ftype_Type_B=4
+} Ftype;
+
+typedef enum{
+    SERVER,
+    LED_SENDER,
+    LED_RECIEVER
+} Device;
+
+typedef enum{
+    PING,
+    ACK,
+    RECIEVE,
+    SEND_SINGLE,
+    SEND_CONTINUEOUS,
+    SEND_CONT_STOP,
+    SET_TX_GAIN
+} Command;
+
+//
+//for TCP/IP data structure
+//
+
+//message data  48byte(size fix) 
+typedef struct{
+    uint16_t totalSize;   //2(total size) + 2(frame number) + 1(device) + 1(command) + 42(data:max 42) <--- max 48
+    uint16_t frameNumber;
+    Device   device;
+    Command  command;
+    uint8_t  data[42]; //0 fill,size fix
+} Message;
+
+//payload id  16byte 
+typedef struct{
+    uint16_t head;              //reserve 0x0000
+    uint8_t  personalId[14]; 
+} ID;
+
+typedef struct{
+    ID      id;         // 16 byte
+    Message message;    // 48 byte
+} Frame;
+
+//66byte Payload
+typedef struct{
+    uint16_t    size;     // 2(size) + 1(dummy) + 1(Ftype) + 64(frame) = 68 byte
+    uint8_t     dummy;    //adjust Alignment
+    Ftype       ftype;  
+    Frame       frame;    //64byte
+} Payload;
+
+
+void initPayload(Payload *_payload);
+
+void payloadToNetwork(Payload *_payload);
+void networkToPayload(Payload *_payload);
+
+void initTestPayloadData(Payload *_payload);
+
+void dumpPayload(Payload *_payload);
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/leds.cpp	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#include "leds.h"
+
+Timeout led_ether;
+Timeout led_xbee;
+Timeout led_device;
+
+DigitalOut ledXb(LED1);
+DigitalOut ledDev(LED2);
+DigitalOut ledTcpCon(LED3);
+DigitalOut ledEt(LED4);
+
+void offEther(void){
+    ledEt=0;
+}
+void offXBee(void){
+    ledXb=0;
+}
+void offDevice(void){
+    ledDev=0;
+}
+
+void ledEther(void)
+{
+    ledEt=1;
+    led_ether.attach(&offEther,kLedOnTime);
+}
+void ledXBee(void)
+{
+    ledXb=1;
+    led_xbee.attach(&offXBee,kLedOnTime);
+}
+void ledDevice(void)
+{
+    ledDev=1;
+    led_device.attach(&offDevice,kLedOnTime);
+}
+void onLedDevice(void)
+{
+    ledDev=1;
+}
+
+void ledTcpConnect(bool isConnect)
+{
+    if(isConnect)   ledTcpCon=1;
+    else            ledTcpCon=0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/leds.h	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,14 @@
+#ifndef _LEDS_
+#define _LEDS_
+
+#define kLedOnTime 0.2
+
+void ledEther(void);
+void ledXBee(void);
+void ledDevice(void);
+void ledTcpConnect(bool isConnect);
+
+void offDevice(void);
+void onLedDevice(void);
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/types.h	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,114 @@
+/*----------------------------------------------------------------------------*/
+/* File Information                                                           */
+/*----------------------------------------------------------------------------*/
+/* Name       : types.h                                                       */
+/* Type       : C Programming Language Header                                 */
+/*----------------------------------------------------------------------------*/
+/*----------------------------------------------------------------------------*/
+
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+#include "stdint.h"
+/*
+typedef char                    int8_t;
+typedef unsigned    char        uint8_t;
+typedef signed      short       int16_t;
+typedef unsigned    short       uint16_t;
+typedef signed      int         int32_t;
+typedef unsigned    int         uint32_t;
+typedef signed      long long   int64_t;
+typedef unsigned    long long   uint64_t;
+*/
+//typedef bool                bool_t;
+typedef enum{TRUE, FALSE} bool_t;
+
+//=========================================================================
+//    byte bit access
+//=========================================================================
+typedef union{                    //    BYTE/NIBBLE/BIT access
+    uint8_t byte;                //    Byte access
+    struct{                        //    Nibble access
+        uint8_t lo : 4;        //        lower(Bit0 - 3)
+        uint8_t hi : 4;        //        upper(Bit4 - 7)
+    }nibble;
+    struct{                        //    Bit access
+        uint8_t b0 : 1;        //        Bit0
+        uint8_t b1 : 1;        //        Bit1
+        uint8_t b2 : 1;        //        Bit2
+        uint8_t b3 : 1;        //        Bit3
+        uint8_t b4 : 1;        //        Bit4
+        uint8_t b5 : 1;        //        Bit5
+        uint8_t b6 : 1;        //        Bit6
+        uint8_t b7 : 1;        //        Bit7
+    }bits;
+}byte_t;
+
+//=========================================================================
+//    word bit access
+//=========================================================================
+typedef union{                    //    WORD/BYTE/NIBBLE/BIT access
+    uint16_t word;                //    Word access
+    struct{                        //    Byte access
+        uint8_t b0;            //        upper byte
+        uint8_t b1;            //        lower byte
+    }byte;
+    struct    {                    //    Nibble access
+        uint8_t n0 : 4;        //        lower byte low(Bit 0 -  3)
+        uint8_t n1 : 4;        //        lower byte up (Bit 4 -  7)
+        uint8_t n2 : 4;        //        upper byte low(Bit 8 - 11)
+        uint8_t n3 : 4;        //        upper byte up (Bit12 - 15)
+    }nibble;
+    struct{                        //    Bit acces
+        uint8_t b0 : 1;        //        Bit0
+        uint8_t b1 : 1;        //        Bit1
+        uint8_t b2 : 1;        //        Bit2
+        uint8_t b3 : 1;        //        Bit3
+        uint8_t b4 : 1;        //        Bit4
+        uint8_t b5 : 1;        //        Bit5
+        uint8_t b6 : 1;        //        Bit6
+        uint8_t b7 : 1;        //        Bit7
+        uint8_t b8 : 1;        //        Bit8
+        uint8_t b9 : 1;        //        Bit9
+        uint8_t b10: 1;        //        Bit10
+        uint8_t b11: 1;        //        Bit11
+        uint8_t b12: 1;        //        Bit12
+        uint8_t b13: 1;        //        Bit13
+        uint8_t b14: 1;        //        Bit14
+        uint8_t b15: 1;        //        Bit15
+    }bits;
+}word_t;
+
+
+//=========================================================================
+//    ascii code
+//=========================================================================
+#define Z_NUL (0x00)
+#define Z_SOH (0x01)
+#define Z_STX (0x02)
+#define Z_ETX (0x03)
+#define Z_EOT (0x04)
+#define Z_ENQ (0x05)
+#define Z_ACK (0x06)
+#define Z_BEL (0x07)
+
+#define Z_BS  (0x08)
+#define Z_HT  (0x09)
+#define Z_LF  (0x0A)
+#define Z_HM  (0x0B)
+#define Z_FF  (0x0C)
+#define Z_CR  (0x0D)
+#define Z_SO  (0x0E)
+#define Z_SI  (0x0F)
+
+#define Z_DLE (0x10)
+#define Z_DC1 (0x11)
+#define Z_DC2 (0x12)
+#define Z_DC3 (0x13)
+#define Z_DC4 (0x14)
+#define Z_NAK (0x15)
+#define Z_SYN (0x16)
+#define Z_ETB (0x17)
+
+
+#endif    /* __TYPES_H__*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "data_models.h"
+
+
+Serial serial(USBTX, USBRX);
+DigitalIn din(p20);
+
+void serialInit(void){
+
+    serial.baud(115200);
+    serial.format(8, Serial::None, 1);
+     
+}
+
+void sendPayload(Payload *data){
+
+    uint8_t *d=(uint8_t *)data;
+    
+    for(uint8_t i=0 ; i<68 ; i++){
+    
+       if(d[i]==0x0A)   serial.putc(0x0D); //add LF
+        serial.putc(d[i]);
+        
+    }
+}
+
+int main() {
+
+    din.mode(PullUp);
+    
+    serialInit();
+    
+    Payload payload;
+    
+    initTestPayloadData(&payload);
+    payloadToNetwork(&payload);
+    
+    while(1) {
+        if(!din){
+            sendPayload(&payload);
+            wait(0.2);
+         } 
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 22 14:35:48 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479