![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
nakagawa kit emurator (add CR) BaudRate 115200,p20
Dependencies: mbed NetServicesMin
main.cpp@2:c3f3d783560d, 2012-03-22 (annotated)
- Committer:
- recotana
- Date:
- Thu Mar 22 15:15:10 2012 +0000
- Revision:
- 2:c3f3d783560d
- Parent:
- 1:495adf710664
- Child:
- 3:51e64f5e42b8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
recotana | 2:c3f3d783560d | 1 | #include "mbed.h" |
recotana | 2:c3f3d783560d | 2 | #include "data_models.h" |
recotana | 2:c3f3d783560d | 3 | |
recotana | 2:c3f3d783560d | 4 | |
recotana | 2:c3f3d783560d | 5 | Serial serial(USBTX, USBRX); |
recotana | 2:c3f3d783560d | 6 | DigitalIn din(p20); |
recotana | 2:c3f3d783560d | 7 | |
recotana | 2:c3f3d783560d | 8 | void serialInit(void){ |
recotana | 2:c3f3d783560d | 9 | |
recotana | 2:c3f3d783560d | 10 | serial.baud(115200); |
recotana | 2:c3f3d783560d | 11 | serial.format(8, Serial::None, 1); |
recotana | 2:c3f3d783560d | 12 | |
recotana | 2:c3f3d783560d | 13 | } |
recotana | 2:c3f3d783560d | 14 | |
recotana | 2:c3f3d783560d | 15 | void sendPayload(Payload *data){ |
recotana | 2:c3f3d783560d | 16 | |
recotana | 2:c3f3d783560d | 17 | uint8_t *d=(uint8_t *)&data->ftype; |
recotana | 2:c3f3d783560d | 18 | |
recotana | 2:c3f3d783560d | 19 | for(uint8_t i=0 ; i<65 ; i++){ |
recotana | 2:c3f3d783560d | 20 | |
recotana | 2:c3f3d783560d | 21 | if(d[i]==0x0A) serial.putc(0x0D); //add CR LF |
recotana | 2:c3f3d783560d | 22 | serial.putc(d[i]); |
recotana | 2:c3f3d783560d | 23 | |
recotana | 2:c3f3d783560d | 24 | } |
recotana | 2:c3f3d783560d | 25 | } |
recotana | 2:c3f3d783560d | 26 | |
recotana | 2:c3f3d783560d | 27 | int main() { |
recotana | 2:c3f3d783560d | 28 | |
recotana | 2:c3f3d783560d | 29 | din.mode(PullUp); |
recotana | 2:c3f3d783560d | 30 | |
recotana | 2:c3f3d783560d | 31 | serialInit(); |
recotana | 2:c3f3d783560d | 32 | |
recotana | 2:c3f3d783560d | 33 | Payload payload; |
recotana | 2:c3f3d783560d | 34 | |
recotana | 2:c3f3d783560d | 35 | initTestPayloadData(&payload); |
recotana | 2:c3f3d783560d | 36 | payloadToNetwork(&payload); |
recotana | 2:c3f3d783560d | 37 | |
recotana | 2:c3f3d783560d | 38 | while(1) { |
recotana | 2:c3f3d783560d | 39 | if(!din){ |
recotana | 2:c3f3d783560d | 40 | sendPayload(&payload); |
recotana | 2:c3f3d783560d | 41 | wait(0.2); |
recotana | 2:c3f3d783560d | 42 | } |
recotana | 2:c3f3d783560d | 43 | } |
recotana | 2:c3f3d783560d | 44 | } |