mbed-os
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
TESTS/network/wifi/wifi_set_channel.cpp@0:b74591d5ab33, 2017-12-11 (annotated)
- Committer:
- be_bryan
- Date:
- Mon Dec 11 17:54:04 2017 +0000
- Revision:
- 0:b74591d5ab33
motor ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
be_bryan | 0:b74591d5ab33 | 1 | /* |
be_bryan | 0:b74591d5ab33 | 2 | * Copyright (c) 2017, ARM Limited, All Rights Reserved |
be_bryan | 0:b74591d5ab33 | 3 | * SPDX-License-Identifier: Apache-2.0 |
be_bryan | 0:b74591d5ab33 | 4 | * |
be_bryan | 0:b74591d5ab33 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
be_bryan | 0:b74591d5ab33 | 6 | * not use this file except in compliance with the License. |
be_bryan | 0:b74591d5ab33 | 7 | * You may obtain a copy of the License at |
be_bryan | 0:b74591d5ab33 | 8 | * |
be_bryan | 0:b74591d5ab33 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
be_bryan | 0:b74591d5ab33 | 10 | * |
be_bryan | 0:b74591d5ab33 | 11 | * Unless required by applicable law or agreed to in writing, software |
be_bryan | 0:b74591d5ab33 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
be_bryan | 0:b74591d5ab33 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
be_bryan | 0:b74591d5ab33 | 14 | * See the License for the specific language governing permissions and |
be_bryan | 0:b74591d5ab33 | 15 | * limitations under the License. |
be_bryan | 0:b74591d5ab33 | 16 | */ |
be_bryan | 0:b74591d5ab33 | 17 | |
be_bryan | 0:b74591d5ab33 | 18 | #include "mbed.h" |
be_bryan | 0:b74591d5ab33 | 19 | #include "greentea-client/test_env.h" |
be_bryan | 0:b74591d5ab33 | 20 | #include "unity.h" |
be_bryan | 0:b74591d5ab33 | 21 | #include "utest.h" |
be_bryan | 0:b74591d5ab33 | 22 | #include "wifi_tests.h" |
be_bryan | 0:b74591d5ab33 | 23 | #include <stdbool.h> |
be_bryan | 0:b74591d5ab33 | 24 | |
be_bryan | 0:b74591d5ab33 | 25 | using namespace utest::v1; |
be_bryan | 0:b74591d5ab33 | 26 | |
be_bryan | 0:b74591d5ab33 | 27 | void wifi_set_channel(void) |
be_bryan | 0:b74591d5ab33 | 28 | { |
be_bryan | 0:b74591d5ab33 | 29 | bool is_2Ghz = false; |
be_bryan | 0:b74591d5ab33 | 30 | bool is_5Ghz = false; |
be_bryan | 0:b74591d5ab33 | 31 | |
be_bryan | 0:b74591d5ab33 | 32 | WiFiInterface *wifi = get_interface(); |
be_bryan | 0:b74591d5ab33 | 33 | |
be_bryan | 0:b74591d5ab33 | 34 | if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) { |
be_bryan | 0:b74591d5ab33 | 35 | TEST_IGNORE_MESSAGE("set_channel() not supported"); |
be_bryan | 0:b74591d5ab33 | 36 | return; |
be_bryan | 0:b74591d5ab33 | 37 | } |
be_bryan | 0:b74591d5ab33 | 38 | |
be_bryan | 0:b74591d5ab33 | 39 | nsapi_error_t error; |
be_bryan | 0:b74591d5ab33 | 40 | error = wifi->set_channel(1); |
be_bryan | 0:b74591d5ab33 | 41 | if (error == NSAPI_ERROR_OK) { |
be_bryan | 0:b74591d5ab33 | 42 | is_2Ghz = true; |
be_bryan | 0:b74591d5ab33 | 43 | } |
be_bryan | 0:b74591d5ab33 | 44 | |
be_bryan | 0:b74591d5ab33 | 45 | error = wifi->set_channel(30); |
be_bryan | 0:b74591d5ab33 | 46 | if (error == NSAPI_ERROR_OK) { |
be_bryan | 0:b74591d5ab33 | 47 | is_5Ghz = true; |
be_bryan | 0:b74591d5ab33 | 48 | } |
be_bryan | 0:b74591d5ab33 | 49 | |
be_bryan | 0:b74591d5ab33 | 50 | TEST_ASSERT(is_2Ghz || is_5Ghz); |
be_bryan | 0:b74591d5ab33 | 51 | |
be_bryan | 0:b74591d5ab33 | 52 | if (is_2Ghz) { |
be_bryan | 0:b74591d5ab33 | 53 | error = wifi->set_channel(0); |
be_bryan | 0:b74591d5ab33 | 54 | TEST_ASSERT(error == NSAPI_ERROR_PARAMETER); |
be_bryan | 0:b74591d5ab33 | 55 | error = wifi->set_channel(1); |
be_bryan | 0:b74591d5ab33 | 56 | TEST_ASSERT(error == NSAPI_ERROR_OK); |
be_bryan | 0:b74591d5ab33 | 57 | error = wifi->set_channel(13); |
be_bryan | 0:b74591d5ab33 | 58 | TEST_ASSERT(error == NSAPI_ERROR_OK || error == NSAPI_ERROR_PARAMETER); |
be_bryan | 0:b74591d5ab33 | 59 | error = wifi->set_channel(15); |
be_bryan | 0:b74591d5ab33 | 60 | TEST_ASSERT(error == NSAPI_ERROR_PARAMETER); |
be_bryan | 0:b74591d5ab33 | 61 | } |
be_bryan | 0:b74591d5ab33 | 62 | |
be_bryan | 0:b74591d5ab33 | 63 | if (is_5Ghz) { |
be_bryan | 0:b74591d5ab33 | 64 | error = wifi->set_channel(30); |
be_bryan | 0:b74591d5ab33 | 65 | TEST_ASSERT(error == NSAPI_ERROR_PARAMETER); |
be_bryan | 0:b74591d5ab33 | 66 | error = wifi->set_channel(36); |
be_bryan | 0:b74591d5ab33 | 67 | TEST_ASSERT(error == NSAPI_ERROR_OK); |
be_bryan | 0:b74591d5ab33 | 68 | error = wifi->set_channel(169); |
be_bryan | 0:b74591d5ab33 | 69 | TEST_ASSERT(error == NSAPI_ERROR_PARAMETER); |
be_bryan | 0:b74591d5ab33 | 70 | } |
be_bryan | 0:b74591d5ab33 | 71 | |
be_bryan | 0:b74591d5ab33 | 72 | } |
be_bryan | 0:b74591d5ab33 | 73 |