demo project
Dependencies: AX-12A Dynamixel mbed iothub_client EthernetInterface NTPClient ConfigFile SDFileSystem iothub_amqp_transport mbed-rtos proton-c-mbed wolfSSL
RobotNode/NodeEmul.cpp@33:8b9dcbf6d8ec, 2016-02-04 (annotated)
- Committer:
- henryrawas
- Date:
- Thu Feb 04 20:10:33 2016 +0000
- Revision:
- 33:8b9dcbf6d8ec
- Parent:
- 19:2f0ec9ac1238
update libs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
henryrawas | 19:2f0ec9ac1238 | 1 | // Copyright (c) Microsoft. All rights reserved. |
henryrawas | 19:2f0ec9ac1238 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
henryrawas | 13:ffeff9b5e513 | 3 | |
henryrawas | 13:ffeff9b5e513 | 4 | #include "mbed.h" |
henryrawas | 13:ffeff9b5e513 | 5 | #include "NodeEmul.h" |
henryrawas | 13:ffeff9b5e513 | 6 | #include "threadapi.h" |
henryrawas | 13:ffeff9b5e513 | 7 | |
henryrawas | 13:ffeff9b5e513 | 8 | // emulated device that does nothing |
henryrawas | 13:ffeff9b5e513 | 9 | |
henryrawas | 13:ffeff9b5e513 | 10 | NodeEmul::NodeEmul(int id) |
henryrawas | 13:ffeff9b5e513 | 11 | { |
henryrawas | 13:ffeff9b5e513 | 12 | _LastPosition= 20.0f + id; |
henryrawas | 13:ffeff9b5e513 | 13 | _LastTemperature = 30 + id; |
henryrawas | 13:ffeff9b5e513 | 14 | _LastVoltage = 12 + ((float)id * 0.1f); |
henryrawas | 13:ffeff9b5e513 | 15 | _LastLoad = 9 + id; |
henryrawas | 13:ffeff9b5e513 | 16 | } |
henryrawas | 13:ffeff9b5e513 | 17 | |
henryrawas | 13:ffeff9b5e513 | 18 | |
henryrawas | 13:ffeff9b5e513 | 19 | bool NodeEmul::HasMeasure(int measureId) |
henryrawas | 13:ffeff9b5e513 | 20 | { |
henryrawas | 13:ffeff9b5e513 | 21 | switch (measureId) |
henryrawas | 13:ffeff9b5e513 | 22 | { |
henryrawas | 13:ffeff9b5e513 | 23 | case NM_Temperature: |
henryrawas | 13:ffeff9b5e513 | 24 | return true; |
henryrawas | 13:ffeff9b5e513 | 25 | |
henryrawas | 13:ffeff9b5e513 | 26 | case NM_Degrees: |
henryrawas | 13:ffeff9b5e513 | 27 | return true; |
henryrawas | 13:ffeff9b5e513 | 28 | |
henryrawas | 13:ffeff9b5e513 | 29 | case NM_Voltage: |
henryrawas | 13:ffeff9b5e513 | 30 | return true; |
henryrawas | 13:ffeff9b5e513 | 31 | |
henryrawas | 13:ffeff9b5e513 | 32 | case NM_Load: |
henryrawas | 13:ffeff9b5e513 | 33 | return true; |
henryrawas | 13:ffeff9b5e513 | 34 | |
henryrawas | 13:ffeff9b5e513 | 35 | default: |
henryrawas | 13:ffeff9b5e513 | 36 | return false; |
henryrawas | 13:ffeff9b5e513 | 37 | } |
henryrawas | 13:ffeff9b5e513 | 38 | } |
henryrawas | 13:ffeff9b5e513 | 39 | |
henryrawas | 15:4bd10f531cdc | 40 | void NodeEmul::ClearMeasureCache() |
henryrawas | 13:ffeff9b5e513 | 41 | { |
henryrawas | 15:4bd10f531cdc | 42 | |
henryrawas | 13:ffeff9b5e513 | 43 | } |
henryrawas | 13:ffeff9b5e513 | 44 | |
henryrawas | 15:4bd10f531cdc | 45 | float NodeEmul::GetMeasure(int measureId) |
henryrawas | 13:ffeff9b5e513 | 46 | { |
henryrawas | 13:ffeff9b5e513 | 47 | switch (measureId) |
henryrawas | 13:ffeff9b5e513 | 48 | { |
henryrawas | 13:ffeff9b5e513 | 49 | case NM_Temperature: |
henryrawas | 13:ffeff9b5e513 | 50 | return (float)_LastTemperature; |
henryrawas | 13:ffeff9b5e513 | 51 | |
henryrawas | 13:ffeff9b5e513 | 52 | case NM_Degrees: |
henryrawas | 13:ffeff9b5e513 | 53 | return _LastPosition; |
henryrawas | 13:ffeff9b5e513 | 54 | |
henryrawas | 13:ffeff9b5e513 | 55 | case NM_Voltage: |
henryrawas | 13:ffeff9b5e513 | 56 | return _LastVoltage; |
henryrawas | 13:ffeff9b5e513 | 57 | |
henryrawas | 13:ffeff9b5e513 | 58 | case NM_Load: |
henryrawas | 13:ffeff9b5e513 | 59 | return _LastLoad; |
henryrawas | 13:ffeff9b5e513 | 60 | |
henryrawas | 13:ffeff9b5e513 | 61 | default: |
henryrawas | 13:ffeff9b5e513 | 62 | return 0.0f; |
henryrawas | 13:ffeff9b5e513 | 63 | } |
henryrawas | 13:ffeff9b5e513 | 64 | } |
henryrawas | 13:ffeff9b5e513 | 65 | |
henryrawas | 13:ffeff9b5e513 | 66 | bool NodeEmul::HasAction(int actionId) |
henryrawas | 13:ffeff9b5e513 | 67 | { |
henryrawas | 13:ffeff9b5e513 | 68 | switch (actionId) |
henryrawas | 13:ffeff9b5e513 | 69 | { |
henryrawas | 13:ffeff9b5e513 | 70 | case NA_Ping: |
henryrawas | 13:ffeff9b5e513 | 71 | return true; |
henryrawas | 13:ffeff9b5e513 | 72 | |
henryrawas | 13:ffeff9b5e513 | 73 | case NA_Init: |
henryrawas | 13:ffeff9b5e513 | 74 | return true; |
henryrawas | 13:ffeff9b5e513 | 75 | |
henryrawas | 13:ffeff9b5e513 | 76 | case NA_Rotate: |
henryrawas | 13:ffeff9b5e513 | 77 | return true; |
henryrawas | 13:ffeff9b5e513 | 78 | |
henryrawas | 13:ffeff9b5e513 | 79 | case NA_ClearError: |
henryrawas | 13:ffeff9b5e513 | 80 | return true; |
henryrawas | 13:ffeff9b5e513 | 81 | |
henryrawas | 13:ffeff9b5e513 | 82 | default: |
henryrawas | 13:ffeff9b5e513 | 83 | return false; |
henryrawas | 13:ffeff9b5e513 | 84 | } |
henryrawas | 13:ffeff9b5e513 | 85 | } |
henryrawas | 13:ffeff9b5e513 | 86 | |
henryrawas | 13:ffeff9b5e513 | 87 | |
henryrawas | 13:ffeff9b5e513 | 88 | bool NodeEmul::DoAction(int actionId, float actionValue) |
henryrawas | 13:ffeff9b5e513 | 89 | { |
henryrawas | 13:ffeff9b5e513 | 90 | switch (actionId) |
henryrawas | 13:ffeff9b5e513 | 91 | { |
henryrawas | 13:ffeff9b5e513 | 92 | case NA_Ping: |
henryrawas | 13:ffeff9b5e513 | 93 | return true; |
henryrawas | 13:ffeff9b5e513 | 94 | |
henryrawas | 13:ffeff9b5e513 | 95 | case NA_Init: |
henryrawas | 13:ffeff9b5e513 | 96 | return true; |
henryrawas | 13:ffeff9b5e513 | 97 | |
henryrawas | 13:ffeff9b5e513 | 98 | case NA_Rotate: |
henryrawas | 13:ffeff9b5e513 | 99 | _LastPosition = actionValue; |
henryrawas | 13:ffeff9b5e513 | 100 | return true; |
henryrawas | 13:ffeff9b5e513 | 101 | |
henryrawas | 13:ffeff9b5e513 | 102 | case NA_ClearError: |
henryrawas | 13:ffeff9b5e513 | 103 | return true; |
henryrawas | 13:ffeff9b5e513 | 104 | |
henryrawas | 13:ffeff9b5e513 | 105 | default: |
henryrawas | 13:ffeff9b5e513 | 106 | return false; |
henryrawas | 13:ffeff9b5e513 | 107 | } |
henryrawas | 13:ffeff9b5e513 | 108 | } |
henryrawas | 13:ffeff9b5e513 | 109 | |
henryrawas | 13:ffeff9b5e513 | 110 | NodePartType NodeEmul::GetNodeType() |
henryrawas | 13:ffeff9b5e513 | 111 | { |
henryrawas | 13:ffeff9b5e513 | 112 | return NT_Emul; |
henryrawas | 13:ffeff9b5e513 | 113 | } |
henryrawas | 13:ffeff9b5e513 | 114 | |
henryrawas | 13:ffeff9b5e513 | 115 | int NodeEmul::GetLastError() |
henryrawas | 13:ffeff9b5e513 | 116 | { |
henryrawas | 13:ffeff9b5e513 | 117 | return 0; |
henryrawas | 13:ffeff9b5e513 | 118 | } |
henryrawas | 13:ffeff9b5e513 | 119 | |
henryrawas | 13:ffeff9b5e513 | 120 | bool NodeEmul::HasError() |
henryrawas | 13:ffeff9b5e513 | 121 | { |
henryrawas | 13:ffeff9b5e513 | 122 | return false; |
henryrawas | 13:ffeff9b5e513 | 123 | } |