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@13:ffeff9b5e513, 2016-01-15 (annotated)
- Committer:
- henryrawas
- Date:
- Fri Jan 15 22:02:46 2016 +0000
- Revision:
- 13:ffeff9b5e513
- Child:
- 15:4bd10f531cdc
Always test status and send data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
henryrawas | 13:ffeff9b5e513 | 1 | |
henryrawas | 13:ffeff9b5e513 | 2 | #include "mbed.h" |
henryrawas | 13:ffeff9b5e513 | 3 | #include "NodeEmul.h" |
henryrawas | 13:ffeff9b5e513 | 4 | #include "threadapi.h" |
henryrawas | 13:ffeff9b5e513 | 5 | |
henryrawas | 13:ffeff9b5e513 | 6 | // emulated device that does nothing |
henryrawas | 13:ffeff9b5e513 | 7 | |
henryrawas | 13:ffeff9b5e513 | 8 | NodeEmul::NodeEmul(int id) |
henryrawas | 13:ffeff9b5e513 | 9 | { |
henryrawas | 13:ffeff9b5e513 | 10 | _LastPosition= 20.0f + id; |
henryrawas | 13:ffeff9b5e513 | 11 | _LastTemperature = 30 + id; |
henryrawas | 13:ffeff9b5e513 | 12 | _LastVoltage = 12 + ((float)id * 0.1f); |
henryrawas | 13:ffeff9b5e513 | 13 | _LastLoad = 9 + id; |
henryrawas | 13:ffeff9b5e513 | 14 | } |
henryrawas | 13:ffeff9b5e513 | 15 | |
henryrawas | 13:ffeff9b5e513 | 16 | |
henryrawas | 13:ffeff9b5e513 | 17 | bool NodeEmul::HasMeasure(int measureId) |
henryrawas | 13:ffeff9b5e513 | 18 | { |
henryrawas | 13:ffeff9b5e513 | 19 | switch (measureId) |
henryrawas | 13:ffeff9b5e513 | 20 | { |
henryrawas | 13:ffeff9b5e513 | 21 | case NM_Temperature: |
henryrawas | 13:ffeff9b5e513 | 22 | return true; |
henryrawas | 13:ffeff9b5e513 | 23 | |
henryrawas | 13:ffeff9b5e513 | 24 | case NM_Degrees: |
henryrawas | 13:ffeff9b5e513 | 25 | return true; |
henryrawas | 13:ffeff9b5e513 | 26 | |
henryrawas | 13:ffeff9b5e513 | 27 | case NM_Voltage: |
henryrawas | 13:ffeff9b5e513 | 28 | return true; |
henryrawas | 13:ffeff9b5e513 | 29 | |
henryrawas | 13:ffeff9b5e513 | 30 | case NM_Load: |
henryrawas | 13:ffeff9b5e513 | 31 | return true; |
henryrawas | 13:ffeff9b5e513 | 32 | |
henryrawas | 13:ffeff9b5e513 | 33 | default: |
henryrawas | 13:ffeff9b5e513 | 34 | return false; |
henryrawas | 13:ffeff9b5e513 | 35 | } |
henryrawas | 13:ffeff9b5e513 | 36 | } |
henryrawas | 13:ffeff9b5e513 | 37 | |
henryrawas | 13:ffeff9b5e513 | 38 | float NodeEmul::GetMeasure(int measureId) |
henryrawas | 13:ffeff9b5e513 | 39 | { |
henryrawas | 13:ffeff9b5e513 | 40 | return GetLastMeasure(measureId); |
henryrawas | 13:ffeff9b5e513 | 41 | } |
henryrawas | 13:ffeff9b5e513 | 42 | |
henryrawas | 13:ffeff9b5e513 | 43 | float NodeEmul::GetLastMeasure(int measureId) |
henryrawas | 13:ffeff9b5e513 | 44 | { |
henryrawas | 13:ffeff9b5e513 | 45 | switch (measureId) |
henryrawas | 13:ffeff9b5e513 | 46 | { |
henryrawas | 13:ffeff9b5e513 | 47 | case NM_Temperature: |
henryrawas | 13:ffeff9b5e513 | 48 | return (float)_LastTemperature; |
henryrawas | 13:ffeff9b5e513 | 49 | |
henryrawas | 13:ffeff9b5e513 | 50 | case NM_Degrees: |
henryrawas | 13:ffeff9b5e513 | 51 | return _LastPosition; |
henryrawas | 13:ffeff9b5e513 | 52 | |
henryrawas | 13:ffeff9b5e513 | 53 | case NM_Voltage: |
henryrawas | 13:ffeff9b5e513 | 54 | return _LastVoltage; |
henryrawas | 13:ffeff9b5e513 | 55 | |
henryrawas | 13:ffeff9b5e513 | 56 | case NM_Load: |
henryrawas | 13:ffeff9b5e513 | 57 | return _LastLoad; |
henryrawas | 13:ffeff9b5e513 | 58 | |
henryrawas | 13:ffeff9b5e513 | 59 | default: |
henryrawas | 13:ffeff9b5e513 | 60 | return 0.0f; |
henryrawas | 13:ffeff9b5e513 | 61 | } |
henryrawas | 13:ffeff9b5e513 | 62 | } |
henryrawas | 13:ffeff9b5e513 | 63 | |
henryrawas | 13:ffeff9b5e513 | 64 | bool NodeEmul::HasAction(int actionId) |
henryrawas | 13:ffeff9b5e513 | 65 | { |
henryrawas | 13:ffeff9b5e513 | 66 | switch (actionId) |
henryrawas | 13:ffeff9b5e513 | 67 | { |
henryrawas | 13:ffeff9b5e513 | 68 | case NA_Ping: |
henryrawas | 13:ffeff9b5e513 | 69 | return true; |
henryrawas | 13:ffeff9b5e513 | 70 | |
henryrawas | 13:ffeff9b5e513 | 71 | case NA_Init: |
henryrawas | 13:ffeff9b5e513 | 72 | return true; |
henryrawas | 13:ffeff9b5e513 | 73 | |
henryrawas | 13:ffeff9b5e513 | 74 | case NA_Rotate: |
henryrawas | 13:ffeff9b5e513 | 75 | return true; |
henryrawas | 13:ffeff9b5e513 | 76 | |
henryrawas | 13:ffeff9b5e513 | 77 | case NA_ClearError: |
henryrawas | 13:ffeff9b5e513 | 78 | return true; |
henryrawas | 13:ffeff9b5e513 | 79 | |
henryrawas | 13:ffeff9b5e513 | 80 | default: |
henryrawas | 13:ffeff9b5e513 | 81 | return false; |
henryrawas | 13:ffeff9b5e513 | 82 | } |
henryrawas | 13:ffeff9b5e513 | 83 | } |
henryrawas | 13:ffeff9b5e513 | 84 | |
henryrawas | 13:ffeff9b5e513 | 85 | |
henryrawas | 13:ffeff9b5e513 | 86 | bool NodeEmul::DoAction(int actionId, float actionValue) |
henryrawas | 13:ffeff9b5e513 | 87 | { |
henryrawas | 13:ffeff9b5e513 | 88 | switch (actionId) |
henryrawas | 13:ffeff9b5e513 | 89 | { |
henryrawas | 13:ffeff9b5e513 | 90 | case NA_Ping: |
henryrawas | 13:ffeff9b5e513 | 91 | return true; |
henryrawas | 13:ffeff9b5e513 | 92 | |
henryrawas | 13:ffeff9b5e513 | 93 | case NA_Init: |
henryrawas | 13:ffeff9b5e513 | 94 | return true; |
henryrawas | 13:ffeff9b5e513 | 95 | |
henryrawas | 13:ffeff9b5e513 | 96 | case NA_Rotate: |
henryrawas | 13:ffeff9b5e513 | 97 | _LastPosition = actionValue; |
henryrawas | 13:ffeff9b5e513 | 98 | return true; |
henryrawas | 13:ffeff9b5e513 | 99 | |
henryrawas | 13:ffeff9b5e513 | 100 | case NA_ClearError: |
henryrawas | 13:ffeff9b5e513 | 101 | return true; |
henryrawas | 13:ffeff9b5e513 | 102 | |
henryrawas | 13:ffeff9b5e513 | 103 | default: |
henryrawas | 13:ffeff9b5e513 | 104 | return false; |
henryrawas | 13:ffeff9b5e513 | 105 | } |
henryrawas | 13:ffeff9b5e513 | 106 | } |
henryrawas | 13:ffeff9b5e513 | 107 | |
henryrawas | 13:ffeff9b5e513 | 108 | NodePartType NodeEmul::GetNodeType() |
henryrawas | 13:ffeff9b5e513 | 109 | { |
henryrawas | 13:ffeff9b5e513 | 110 | return NT_Emul; |
henryrawas | 13:ffeff9b5e513 | 111 | } |
henryrawas | 13:ffeff9b5e513 | 112 | |
henryrawas | 13:ffeff9b5e513 | 113 | int NodeEmul::GetLastError() |
henryrawas | 13:ffeff9b5e513 | 114 | { |
henryrawas | 13:ffeff9b5e513 | 115 | return 0; |
henryrawas | 13:ffeff9b5e513 | 116 | } |
henryrawas | 13:ffeff9b5e513 | 117 | |
henryrawas | 13:ffeff9b5e513 | 118 | bool NodeEmul::HasError() |
henryrawas | 13:ffeff9b5e513 | 119 | { |
henryrawas | 13:ffeff9b5e513 | 120 | return false; |
henryrawas | 13:ffeff9b5e513 | 121 | } |